// Copyright 2013 The Servo Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms.
// Rust bindings to the IOSurface framework on macOS.
use core_foundation::base::{CFRelease, CFRetain, CFTypeID, CFTypeRef, CFType, TCFType}; use core_foundation::dictionary::{CFDictionary, CFDictionaryRef}; use core_foundation::string::{CFString, CFStringRef}; use cgl::{kCGLNoError, CGLGetCurrentContext, CGLTexImageIOSurface2D, CGLErrorString, GLenum}; use libc::{c_int, size_t}; use std::os::raw::c_void; use leaky_cow::LeakyCow; use std::slice; use std::ffi::CStr;
/// Looks up an `IOSurface` by its global ID. /// /// FIXME(pcwalton): This should return an `Option`. pubfn lookup(csid: IOSurfaceID) -> IOSurface { unsafe {
TCFType::wrap_under_create_rule(IOSurfaceLookup(csid))
}
}
/// Binds to the current GL texture. pubfn bind_to_gl_texture(&self, width: i32, height: i32, has_alpha: bool) { unsafe { let context = CGLGetCurrentContext(); let gl_error = CGLTexImageIOSurface2D(context,
TEXTURE_RECTANGLE_ARB, if has_alpha { RGBA as GLenum } else { RGB as GLenum },
width,
height,
BGRA as GLenum,
UNSIGNED_INT_8_8_8_8_REV, self.as_concrete_TypeRef() as *mut libc::c_void, 0);
if gl_error != kCGLNoError { let error_msg = CStr::from_ptr(CGLErrorString(gl_error)); let error_msg = error_msg.to_string_lossy(); // This will only actually leak memory if error_msg is a `Cow::Owned`, which // will only happen if the platform gives us invalid unicode.
panic!(error_msg.leak());
}
}
}
let height = IOSurfaceGetHeight(surface); let stride = IOSurfaceGetBytesPerRow(surface); let size = (height * stride) as usize; let address = IOSurfaceGetBaseAddress(surface) as *mut u8; let dest: &mut [u8] = slice::from_raw_parts_mut(address, size);
dest.clone_from_slice(data);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.