diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..3f29654313 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "skia-c"] + path = skia-c + url = https://github.com/DiamondLovesYou/skia-c.git diff --git a/Cargo.toml b/Cargo.toml index 2b58bd2107..e56329d9ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [package] -name = "servo-skia" -version = "0.20130412.3" +name = "skia-sys" +version = "0.20130412.4" authors = ["The Skia Project Developers and The Servo Project Developers"] -description = "2D graphic library for drawing Text, Geometries, and Images" +description = "2D graphic library for drawing Text, Geometries, and Images. FFI bindings only." license = "BSD-3-Clause" repository ="https://github.com/servo/skia/" homepage = "https://skia.org/" @@ -18,48 +18,38 @@ exclude = [ ] [lib] -name = "skia" +name = "skia_sys" [dependencies] -euclid = "0.4" -gleam = "0.2" libc = "0.2" -servo-glutin = "0.4" expat-sys = "2.1.0" [target.i686-unknown-linux-gnu.dependencies] -servo-fontconfig = "0.2" +servo-fontconfig-sys = "2.11" servo-freetype-sys = "2.4.11" -x11 = { version = "2.0.0", features = ["xlib"] } -glx = "0.1.0" - [target.x86_64-unknown-linux-gnu.dependencies] -servo-fontconfig = "0.2" +servo-fontconfig-sys = "2.11" servo-freetype-sys = "2.4.11" -x11 = { version = "2.0.0", features = ["xlib"] } -glx = "0.1.0" - [target.arm-unknown-linux-gnueabihf.dependencies] -servo-fontconfig = "0.2" +servo-fontconfig-sys = "2.11" servo-freetype-sys = "2.4.11" -x11 = { version = "2.0.0", features = ["xlib"] } -glx = "0.1.0" - [target.aarch64-unknown-linux-gnu.dependencies] -servo-fontconfig = "0.2" +servo-fontconfig-sys = "2.11" servo-freetype-sys = "2.4.11" -x11 = { version = "2.0.0", features = ["xlib"] } -glx = "0.1.0" [target.arm-linux-androideabi.dependencies] -servo-fontconfig = "0.2" +servo-fontconfig-sys = "2.11" +servo-freetype-sys = "2.4.11" +[target.aarch64-linux-android.dependencies] +servo-fontconfig-sys = "2.11" +servo-freetype-sys = "2.4.11" +[target.i686-linux-android.dependencies] +servo-fontconfig-sys = "2.11" +servo-freetype-sys = "2.4.11" +[target.x86_64-linux-android.dependencies] +servo-fontconfig-sys = "2.11" servo-freetype-sys = "2.4.11" -servo-egl = "0.2" [target.x86_64-pc-windows-gnu.dependencies] -servo-fontconfig = "0.2" +servo-fontconfig-sys = "2.11" servo-freetype-sys = "2.4.11" - -[target.x86_64-apple-darwin.dependencies] -cgl = "0.1" -io-surface = "0.1.0" diff --git a/makefile.cargo b/makefile.cargo index a07df7a2a4..c55ad4bea4 100644 --- a/makefile.cargo +++ b/makefile.cargo @@ -36,6 +36,7 @@ endif CXXFLAGS += \ -DSK_A32_SHIFT=24 -DSK_R32_SHIFT=16 -DSK_G32_SHIFT=8 -DSK_B32_SHIFT=0 \ -DGR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE=1 \ + -I"$(DEP_FONTCONFIG_INCDIR)" \ -I"$(DEP_FREETYPE_OUTDIR)/include" \ -I"$(DEP_EXPAT_OUTDIR)/include" \ -Iinclude/config \ @@ -55,8 +56,7 @@ CXXFLAGS += \ -Isrc/utils \ -Ithird_party/etc1 \ -Ithird_party/ktx \ - -iquote src/gpu \ - -I/usr/include/freetype2 + -iquote src/gpu USE_CLANG = $(shell $(CXX) --version|grep -c 'clang') ifeq ($(USE_CLANG),1) @@ -557,7 +557,7 @@ SKIA_UTILS_CXX_SRC += \ ) endif -ifeq (androideabi,$(findstring androideabi,$(TARGET))) +ifeq (android,$(findstring android,$(TARGET))) CXXFLAGS += \ -DSK_BUILD_FOR_ANDROID \ -DEGL_EGLEXT_PROTOTYPES \ @@ -687,6 +687,7 @@ endif SKIA_SRC = \ src/skia-c.cpp \ + skia-c/src/skia.cpp \ $(SKIA_CORE_CXX_SRC) \ $(SKIA_EFFECTS_CXX_SRC) \ $(SKIA_FONTS_CXX_SRC) \ @@ -764,19 +765,19 @@ $(OUT_DIR)/%opts_check_x86.o: %opts_check_x86.cpp $(OUT_DIR)/src/ports/SkAtomics # those extensions for all processors. We only enable those extensions when compiling # that file. Skia will not call the code if it does not detect SSE3 support # at runtime. -$(OUT_DIR)/%SSE3.o: %SSE3.cpp $(OUT_DIR)/src/ports/SkAtomics_sync.h +$(OUT_DIR)/%SSE3.o: %SSE3.cpp $(OUT_DIR)/src/ports/SkAtomics_sync.h makefile.cargo mkdir -p `dirname $@` && $(CXX) -c $(CXXFLAGS) $(PROCESSOR_EXTENSION_CXXFLAGS) -mssse3 -o $@ $< -$(OUT_DIR)/%.o: %.cpp $(OUT_DIR)/src/ports/SkAtomics_sync.h +$(OUT_DIR)/%.o: %.cpp $(OUT_DIR)/src/ports/SkAtomics_sync.h makefile.cargo mkdir -p `dirname $@` && $(CXX) -c $(CXXFLAGS) $(PROCESSOR_EXTENSION_CXXFLAGS) -o $@ $< -$(OUT_DIR)/%.o: %.c $(OUT_DIR)/src/ports/SkAtomics_sync.h +$(OUT_DIR)/%.o: %.c $(OUT_DIR)/src/ports/SkAtomics_sync.h makefile.cargo mkdir -p `dirname $@` && $(CC) -c $(CXXFLAGS) $(PROCESSOR_EXTENSION_CXXFLAGS) -o $@ $< -$(OUT_DIR)/%.o: %.S $(OUT_DIR)/src/ports/SkAtomics_sync.h +$(OUT_DIR)/%.o: %.S $(OUT_DIR)/src/ports/SkAtomics_sync.h makefile.cargo mkdir -p `dirname $@` && $(CXX) -c $(CXXFLAGS) $(PROCESSOR_EXTENSION_CXXFLAGS) -o $@ $< -$(OUT_DIR)/libskia.a: $(SKIA_OBJS) src/skia-c.h +$(OUT_DIR)/libskia.a: $(SKIA_OBJS) src/skia-c.h makefile.cargo cp -R include $(OUT_DIR) cp src/skia-c.h $(OUT_DIR)/include cd $(OUT_DIR) && $(AR) rcs $(subst $(OUT_DIR)/,,$@) $(subst $(OUT_DIR)/,,$(SKIA_OBJS)) diff --git a/skia-c b/skia-c new file mode 160000 index 0000000000..911d8de74e --- /dev/null +++ b/skia-c @@ -0,0 +1 @@ +Subproject commit 911d8de74e46549fc9f3bf39c1e7f3fe78b5ef23 diff --git a/src/gl_context.rs b/src/gl_context.rs deleted file mode 100644 index eda772f20f..0000000000 --- a/src/gl_context.rs +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2015 The Servo Project Developers - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -use skia; - -use euclid::size::Size2D; -use gleam::gl; -use std::ptr; -use std::sync::Arc; - -#[cfg(target_os="macos")] -pub use gl_context_cgl::GLPlatformContext; -#[cfg(target_os="macos")] -pub use gl_context_cgl::PlatformDisplayData; - -#[cfg(target_os="linux")] -pub use gl_context_glx::GLPlatformContext; -#[cfg(target_os="linux")] -pub use gl_context_glx::PlatformDisplayData; -#[cfg(target_os="linux")] -pub use gl_rasterization_context::GLRasterizationContext; - -#[cfg(target_os="android")] -pub use gl_context_android::GLPlatformContext; -#[cfg(target_os="android")] -pub use gl_context_android::PlatformDisplayData; - -#[cfg(target_os="windows")] -pub use gl_context_wgl::GLPlatformContext; -#[cfg(target_os="windows")] -pub use gl_context_wgl::PlatformDisplayData; - -pub struct GLContext { - pub platform_context: GLPlatformContext, - pub gr_context: skia::SkiaGrContextRef, - pub gl_interface: skia::SkiaGrGLInterfaceRef, - pub size: Size2D, -} - -impl Drop for GLContext { - fn drop(&mut self) { - self.platform_context.make_current(); - - unsafe { - skia::SkiaGrContextRelease(self.gr_context); - skia::SkiaGrGLInterfaceRelease(self.gl_interface); - } - } -} - -impl GLContext { - pub fn new(platform_display_data: PlatformDisplayData, - size: Size2D) - -> Option> { - let platform_context = GLPlatformContext::new(platform_display_data, size); - let platform_context = match platform_context { - Some(platform_context) => platform_context, - None => return None, - }; - - // The Skia GL interface needs to be created while the context is active, so we - // do that immediately after setting the context as the current one. - platform_context.make_current(); - - unsafe { - let gl_interface = skia::SkiaGrGLCreateNativeInterface(); - if gl_interface == ptr::null_mut() { - platform_context.drop_current_context(); - return None; - } - - let gr_context = skia::SkiaGrContextCreate(gl_interface); - if gr_context == ptr::null_mut() { - platform_context.drop_current_context(); - return None; - } - - Some(Arc::new(GLContext { - platform_context: platform_context, - gr_context: gr_context, - gl_interface: gl_interface, - size: size, - })) - } - } - - pub fn flush(&self) { - self.make_current(); - gl::flush(); - } - - pub fn make_current(&self) { - self.platform_context.make_current(); - } - - pub fn drop_current_context(&self) { - self.platform_context.drop_current_context(); - } -} diff --git a/src/gl_context_android.rs b/src/gl_context_android.rs deleted file mode 100644 index 737f1ae5c7..0000000000 --- a/src/gl_context_android.rs +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2015 The Servo Project Developers - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -use euclid::size::Size2D; -use egl::egl; -use std::ptr; - -pub struct PlatformDisplayData { - pub display: egl::EGLDisplay, -} - -pub struct GLPlatformContext { - pub display: egl::EGLDisplay, - pub egl_context: egl::EGLContext, - egl_surface: egl::EGLSurface, -} - -impl Drop for GLPlatformContext { - fn drop(&mut self) { - self.drop_current_context(); - egl::DestroyContext(self.display, self.egl_context); - egl::DestroySurface(self.display, self.egl_surface); - } -} - -impl GLPlatformContext { - pub fn new(platform_display_data: PlatformDisplayData, - size: Size2D) - -> Option { - let config_attributes = [ - egl::EGL_SURFACE_TYPE as i32, egl::EGL_PBUFFER_BIT as i32, - egl::EGL_RENDERABLE_TYPE as i32, egl::EGL_OPENGL_ES2_BIT as i32, - egl::EGL_RED_SIZE as i32, 8, - egl::EGL_BLUE_SIZE as i32, 8, - egl::EGL_ALPHA_SIZE as i32, 8, - egl::EGL_NONE as i32, - ]; - - let display = platform_display_data.display; - let mut surface_config = ptr::null_mut(); - let mut number_of_configs = 0; - egl::ChooseConfig(display, - config_attributes.as_ptr(), - &mut surface_config, 1, &mut number_of_configs); - if number_of_configs == 0 { - return None; - } - - let context_attributes = [ - egl::EGL_CONTEXT_CLIENT_VERSION as i32, 2, - egl::EGL_NONE as i32 - ]; - let egl_context = egl::CreateContext(display, - surface_config, - egl::EGL_NO_CONTEXT as egl::EGLContext, - context_attributes.as_ptr()); - if egl_context == egl::EGL_NO_CONTEXT as egl::EGLContext { - return None; - } - - let mut surface_attributes = [ - egl::EGL_WIDTH as i32, size.width, - egl::EGL_HEIGHT as i32, size.height, - egl::EGL_NONE as i32, - ]; - let egl_surface = egl::CreatePbufferSurface(display, - surface_config, - &mut surface_attributes[0]); - if egl_surface == egl::EGL_NO_SURFACE as egl::EGLSurface { - egl::DestroyContext(display, egl_context); - return None; - } - - - Some(GLPlatformContext { - display: display, - egl_context: egl_context, - egl_surface: egl_surface, - }) - } - - pub fn drop_current_context(&self) { - egl::MakeCurrent(self.display, ptr::null_mut(), ptr::null_mut(), ptr::null_mut()); - } - - pub fn make_current(&self) { - egl::MakeCurrent(self.display, self.egl_surface, self.egl_surface, self.egl_context); - } -} diff --git a/src/gl_context_cgl.rs b/src/gl_context_cgl.rs deleted file mode 100644 index 18ecd2fbd0..0000000000 --- a/src/gl_context_cgl.rs +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2015 The Servo Project Developers - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -use gl_rasterization_context; -use skia; - -use euclid::size::Size2D; -use cgl; -use gleam::gl; -use std::ptr; - -pub struct PlatformDisplayData { - pub pixel_format: cgl::CGLPixelFormatObj, -} - -pub struct GLPlatformContext { - pub cgl_context: cgl::CGLContextObj, - - pub framebuffer_id: gl::GLuint, - texture_id: gl::GLuint, - depth_stencil_renderbuffer_id: gl::GLuint, -} - -impl Drop for GLPlatformContext { - fn drop(&mut self) { - self.make_current(); - gl_rasterization_context::destroy_framebuffer(self.framebuffer_id, - self.texture_id, - self.depth_stencil_renderbuffer_id); - - unsafe { - cgl::CGLDestroyContext(self.cgl_context); - } - } -} - -impl GLPlatformContext { - pub fn new(platform_display_data: PlatformDisplayData, - size: Size2D) - -> Option { - unsafe { - let mut cgl_context = ptr::null_mut(); - let _ = cgl::CGLCreateContext(platform_display_data.pixel_format, - ptr::null_mut(), - &mut cgl_context); - if ptr::null_mut() == cgl_context { - return None; - } - - cgl::CGLSetCurrentContext(cgl_context); - gl::enable(gl::TEXTURE_RECTANGLE_ARB); - - let gl_interface = skia::SkiaGrGLCreateNativeInterface(); - if gl_interface == ptr::null_mut() { - cgl::CGLDestroyContext(cgl_context); - return None - } - - // We only start the framebuffer setup here, since we cannot complete it until - // we have a texture image. That will be provided by the IOSurface in the - // GLRasterizationContext. - let (framebuffer_id, texture_id, depth_stencil_renderbuffer_id) = - gl_rasterization_context::start_framebuffer_setup(gl::TEXTURE_RECTANGLE_ARB, - size, - gl_interface); - skia::SkiaGrGLInterfaceRelease(gl_interface); - Some(GLPlatformContext { - cgl_context: cgl_context, - framebuffer_id: framebuffer_id, - texture_id: texture_id, - depth_stencil_renderbuffer_id: depth_stencil_renderbuffer_id, - }) - } - } - - pub fn drop_current_context(&self) { - unsafe { - cgl::CGLSetCurrentContext(ptr::null_mut()); - } - } - - pub fn make_current(&self) { - unsafe { - cgl::CGLSetCurrentContext(self.cgl_context); - } - } -} diff --git a/src/gl_context_glx.rs b/src/gl_context_glx.rs deleted file mode 100644 index cc1b692cf8..0000000000 --- a/src/gl_context_glx.rs +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 2015 The Servo Project Developers - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -use gl_rasterization_context; -use skia; - -use euclid::size::Size2D; -use glx; -use std::ptr; -use x11::xlib; - -use gleam::gl; - -pub struct PlatformDisplayData { - pub display: *mut xlib::Display, - pub visual_info: *mut xlib::XVisualInfo, -} - -pub struct GLPlatformContext { - pub display: *mut xlib::Display, - glx_context: xlib::XID, - pub glx_pixmap: xlib::XID, - pub pixmap: xlib::XID, - - pub framebuffer_id: gl::GLuint, - pub texture_id: gl::GLuint, - pub depth_stencil_renderbuffer_id: gl::GLuint, -} - -impl Drop for GLPlatformContext { - fn drop(&mut self) { - // We need this thread to grab the GLX context before we can make - // OpenGL calls. But glXMakeCurrent() will flush the old context, - // which might have been uninitialized. Dropping the current context - // first solves this problem somehow. - self.drop_current_context(); - self.make_current(); - - gl_rasterization_context::destroy_framebuffer(self.framebuffer_id, - self.texture_id, - self.depth_stencil_renderbuffer_id); - - unsafe { - let glx_display = self.display as *mut glx::types::Display; - glx::MakeCurrent(glx_display, 0 /* None */, ptr::null_mut()); - glx::DestroyContext(glx_display, self.glx_context as glx::types::GLXContext); - glx::DestroyGLXPixmap(glx_display, self.glx_pixmap); - xlib::XFreePixmap(self.display, self.pixmap); - } - } -} - -impl GLPlatformContext { - pub fn new(platform_display_data: PlatformDisplayData, - size: Size2D) - -> Option { - unsafe { - let display = platform_display_data.display; - let visual_info = platform_display_data.visual_info; - let glx_display = display as *mut glx::types::Display; - let glx_visual_info = visual_info as *mut glx::types::XVisualInfo; - - let root_window = xlib::XRootWindow(display, xlib::XDefaultScreen(display)); - let pixmap = xlib::XCreatePixmap(display, - root_window, - size.width as u32, - size.height as u32, - (*visual_info).depth as u32); - let glx_pixmap = glx::CreateGLXPixmap(glx_display, - glx_visual_info, - pixmap); - - let glx_context = glx::CreateContext(glx_display, - glx_visual_info, - ptr::null_mut(), - 1); - - if glx_context == ptr::null() { - glx::DestroyGLXPixmap(glx_display, glx_pixmap); - } - - glx::MakeCurrent(display as *mut glx::types::Display, - glx_pixmap, - glx_context as glx::types::GLXContext); - - let gl_interface = skia::SkiaGrGLCreateNativeInterface(); - if gl_interface == ptr::null_mut() { - glx::MakeCurrent(display as *mut glx::types::Display, - 0 /* None */, - ptr::null_mut()); - return None; - } - - if let Some((framebuffer_id, texture_id, depth_stencil_renderbuffer_id)) = - gl_rasterization_context::setup_framebuffer(gl::TEXTURE_2D, - size, - gl_interface, - || { - gl::tex_image_2d(gl::TEXTURE_2D, 0, - gl::RGBA as gl::GLint, - size.width, size.height, 0, - gl::RGBA, gl::UNSIGNED_BYTE, None); - }) { - skia::SkiaGrGLInterfaceRelease(gl_interface); - return Some(GLPlatformContext { - display: display, - glx_context: glx_context as xlib::XID, - pixmap: pixmap, - glx_pixmap: glx_pixmap as xlib::XID, - framebuffer_id: framebuffer_id, - texture_id: texture_id, - depth_stencil_renderbuffer_id: depth_stencil_renderbuffer_id, - }) - } - skia::SkiaGrGLInterfaceRelease(gl_interface); - None - } - } - - pub fn drop_current_context(&self) { - unsafe { - glx::MakeCurrent(self.display as *mut glx::types::Display, - 0 /* None */, - ptr::null_mut()); - } - } - - pub fn make_current(&self) { - unsafe { - glx::MakeCurrent(self.display as *mut glx::types::Display, - self.glx_pixmap, - self.glx_context as glx::types::GLXContext); - } - } -} diff --git a/src/gl_context_wgl.rs b/src/gl_context_wgl.rs deleted file mode 100644 index c15bc8b3e3..0000000000 --- a/src/gl_context_wgl.rs +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2015 The Servo Project Developers - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -extern crate glutin; - -use gl_rasterization_context; -use skia; - -use euclid::size::Size2D; -use gleam::gl; -use std::ptr; - -pub struct PlatformDisplayData; - -impl PlatformDisplayData { - pub fn new() -> PlatformDisplayData { - PlatformDisplayData - } -} - -pub struct GLPlatformContext { - pub context: glutin::HeadlessContext, - - pub framebuffer_id: gl::GLuint, - texture_id: gl::GLuint, - depth_stencil_renderbuffer_id: gl::GLuint, -} - -impl Drop for GLPlatformContext { - fn drop(&mut self) { - self.make_current(); - gl_rasterization_context::destroy_framebuffer(self.framebuffer_id, - self.texture_id, - self.depth_stencil_renderbuffer_id); - self.destroy(); - } -} - -impl GLPlatformContext { - pub fn new(_: PlatformDisplayData, - size: Size2D) - -> Option { - unsafe { - // 32x32 is just the size of the dummy underlying context; the real - // size is used below when we create the FBO - let cx = glutin::HeadlessRendererBuilder::new(32, 32).build().unwrap(); - cx.make_current(); - - let gl_interface = skia::SkiaGrGLCreateNativeInterface(); - if gl_interface == ptr::null_mut() { - //cx.destroy(); - return None - } - - let (framebuffer_id, texture_id, depth_stencil_renderbuffer_id) = - gl_rasterization_context::setup_framebuffer(gl::TEXTURE_2D, - size, - gl_interface, - || { - gl::tex_image_2d(gl::TEXTURE_2D, 0, - gl::RGBA as gl::GLint, - size.width, size.height, 0, - gl::RGBA, gl::UNSIGNED_BYTE, None); - }).unwrap(); - - skia::SkiaGrGLInterfaceRelease(gl_interface); - Some(GLPlatformContext { - context: cx, - framebuffer_id: framebuffer_id, - texture_id: texture_id, - depth_stencil_renderbuffer_id: depth_stencil_renderbuffer_id, - }) - } - } - - pub fn drop_current_context(&self) { - // TODO; should not be necessary - } - - pub fn destroy(&self) { - // TODO; need to extend glutin - } - - pub fn make_current(&self) { - unsafe { - self.context.make_current(); - } - } -} diff --git a/src/gl_rasterization_context.rs b/src/gl_rasterization_context.rs deleted file mode 100644 index 4cd8610c73..0000000000 --- a/src/gl_rasterization_context.rs +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright 2013, 2015 The Servo Project Developers - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -use skia; - -use euclid::size::Size2D; -use gleam::gl; -use std::ffi::CString; - -#[cfg(target_os="macos")] -pub use gl_rasterization_context_cgl::GLRasterizationContext; -#[cfg(target_os="linux")] -pub use gl_rasterization_context_glx::GLRasterizationContext; -#[cfg(target_os="android")] -pub use gl_rasterization_context_android::GLRasterizationContext; -#[cfg(target_os="windows")] -pub use gl_rasterization_context_wgl::GLRasterizationContext; - -fn clear_gl_errors() { - let mut error = gl::get_error(); - while error != gl::NO_ERROR { - error = gl::get_error(); - } -} - -#[cfg(not(target_os = "android"))] -fn create_and_bind_depth_stencil_buffer(gl_interface: skia::SkiaGrGLInterfaceRef, - size: Size2D) - -> gl::GLuint { - unsafe { - let ext_extension_string = CString::new("GL_EXT_packed_depth_stencil").unwrap(); - let arb_extension_string = CString::new("GL_ARB_framebuffer_object").unwrap(); - let supports_depth_stencil = - skia::SkiaGrGLInterfaceGLVersionGreaterThanOrEqualTo(gl_interface, 3, 0) || - skia::SkiaGrGLInterfaceHasExtension(gl_interface, ext_extension_string.as_ptr()) || - skia::SkiaGrGLInterfaceHasExtension(gl_interface, arb_extension_string.as_ptr()); - create_and_bind_depth_stencil_buffer_with_formats(supports_depth_stencil, - gl::DEPTH_STENCIL, - gl::STENCIL_INDEX, - size) - } -} - -#[cfg(target_os = "android")] -fn create_and_bind_depth_stencil_buffer(gl_interface: skia::SkiaGrGLInterfaceRef, - size: Size2D) - -> gl::GLuint { - unsafe { - let oes_extension_string = CString::new("GL_OES_packed_depth_stencil").unwrap(); - let supports_depth_stencil = - skia::SkiaGrGLInterfaceHasExtension(gl_interface, oes_extension_string.as_ptr()); - const GL_DEPTH24_STENCIL8_OES: u32 = 0x88F0; - create_and_bind_depth_stencil_buffer_with_formats(supports_depth_stencil, - GL_DEPTH24_STENCIL8_OES, - gl::STENCIL_INDEX8, - size) - } -} - -fn create_and_bind_depth_stencil_buffer_with_formats(supports_depth_stencil: bool, - depth_stencil_format: gl::GLenum, - stencil_format: gl::GLenum, - size: Size2D) - -> gl::GLuint { - let depth_stencil_renderbuffer_id = gl::gen_renderbuffers(1)[0]; - gl::bind_renderbuffer(gl::RENDERBUFFER, depth_stencil_renderbuffer_id); - - unsafe { - if supports_depth_stencil { - gl::RenderbufferStorage(gl::RENDERBUFFER, - depth_stencil_format, - size.width, - size.height); - gl::FramebufferRenderbuffer(gl::FRAMEBUFFER, - gl::DEPTH_ATTACHMENT, - gl::RENDERBUFFER, - depth_stencil_renderbuffer_id); - } else { - gl::RenderbufferStorage(gl::RENDERBUFFER, stencil_format, size.width, size.height); - } - - gl::FramebufferRenderbuffer(gl::FRAMEBUFFER, - gl::STENCIL_ATTACHMENT, - gl::RENDERBUFFER, - depth_stencil_renderbuffer_id); - } - - depth_stencil_renderbuffer_id -} - -pub fn setup_framebuffer(texture_target: gl::GLenum, - size: Size2D, - gl_interface: skia::SkiaGrGLInterfaceRef, - set_texture_image: F) - -> Option<(gl::GLuint, gl::GLuint, gl::GLuint)> - where F: Fn() { - - let (framebuffer_id, texture_id, depth_stencil_renderbuffer_id) = - start_framebuffer_setup(texture_target, size, gl_interface); - - if !finish_framebuffer_setup(size, set_texture_image) { - destroy_framebuffer(framebuffer_id, texture_id, depth_stencil_renderbuffer_id); - return None; - } - - Some((framebuffer_id, texture_id, depth_stencil_renderbuffer_id)) -} - -pub fn start_framebuffer_setup(texture_target: gl::GLenum, - size: Size2D, - gl_interface: skia::SkiaGrGLInterfaceRef) - -> (gl::GLuint, gl::GLuint, gl::GLuint) { - clear_gl_errors(); - - let framebuffer_id = gl::gen_framebuffers(1)[0]; - gl::bind_framebuffer(gl::FRAMEBUFFER, framebuffer_id); - - let texture_id = gl::gen_textures(1)[0]; - gl::bind_texture(texture_target, texture_id); - - gl::tex_parameter_i(texture_target, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE as gl::GLint); - gl::tex_parameter_i(texture_target, gl::TEXTURE_WRAP_T, gl::CLAMP_TO_EDGE as gl::GLint); - gl::tex_parameter_i(texture_target, gl::TEXTURE_MAG_FILTER, gl::NEAREST as gl::GLint); - gl::tex_parameter_i(texture_target, gl::TEXTURE_MIN_FILTER, gl::NEAREST as gl::GLint); - gl::framebuffer_texture_2d(gl::FRAMEBUFFER, - gl::COLOR_ATTACHMENT0, - texture_target, - texture_id, 0); - - let depth_stencil_renderbuffer_id = create_and_bind_depth_stencil_buffer(gl_interface, - size); - - (framebuffer_id, texture_id, depth_stencil_renderbuffer_id) -} - -pub fn finish_framebuffer_setup(size: Size2D, - set_texture_image: F) - -> bool - where F: Fn() { - set_texture_image(); - - gl::viewport(0, 0, size.width, size.height); - - unsafe { - gl::get_error() == gl::NO_ERROR && - gl::CheckFramebufferStatus(gl::FRAMEBUFFER) == gl::FRAMEBUFFER_COMPLETE - } -} - -pub fn destroy_framebuffer(framebuffer_id: gl::GLuint, - texture_id: gl::GLuint, - depth_stencil_renderbuffer_id: gl::GLuint) { - gl::delete_framebuffers(&[framebuffer_id]); - gl::delete_textures(&[texture_id]); - gl::delete_renderbuffers(&[depth_stencil_renderbuffer_id]); -} diff --git a/src/gl_rasterization_context_android.rs b/src/gl_rasterization_context_android.rs deleted file mode 100644 index 2a02d83e48..0000000000 --- a/src/gl_rasterization_context_android.rs +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2013, 2015 The Servo Project Developers - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -use gl_context::GLContext; -use gl_rasterization_context; - -use euclid::size::Size2D; -use egl::egl; -use egl::eglext; -use gleam::gl; -use std::sync::Arc; - -pub struct GLRasterizationContext { - pub gl_context: Arc, - pub egl_image: eglext::EGLImageKHR, - pub size: Size2D, - pub framebuffer_id: gl::GLuint, - texture_id: gl::GLuint, - depth_stencil_renderbuffer_id: gl::GLuint, -} - -impl Drop for GLRasterizationContext { - fn drop(&mut self) { - self.make_current(); - - gl_rasterization_context::destroy_framebuffer(self.framebuffer_id, - self.texture_id, - self.depth_stencil_renderbuffer_id); - } -} - -impl GLRasterizationContext { - pub fn new(gl_context: Arc, - size: Size2D) - -> Option { - gl_context.make_current(); - - if let Some((framebuffer_id, texture_id, depth_stencil_renderbuffer_id)) = - gl_rasterization_context::setup_framebuffer(gl::TEXTURE_2D, - size, - gl_context.gl_interface, - || { - gl::tex_image_2d(gl::TEXTURE_2D, 0, - gl::RGBA as gl::GLint, - size.width, size.height, 0, - gl::RGBA, gl::UNSIGNED_BYTE, None); - }) { - let egl_image_attributes = [ - eglext::EGL_IMAGE_PRESERVED_KHR as i32, egl::EGL_TRUE as i32, - egl::EGL_NONE as i32, egl::EGL_NONE as i32, - ]; - let egl_image = eglext::CreateImageKHR(gl_context.platform_context.display, - gl_context.platform_context.egl_context, - eglext::EGL_GL_TEXTURE_2D_KHR, - texture_id as egl::EGLClientBuffer, - egl_image_attributes.as_ptr()); - - return Some(GLRasterizationContext { - gl_context: gl_context, - egl_image: egl_image, - size: size, - framebuffer_id: framebuffer_id, - texture_id: texture_id, - depth_stencil_renderbuffer_id: depth_stencil_renderbuffer_id, - }); - } - - None - } - - pub fn make_current(&self) { - self.gl_context.make_current(); - } - - pub fn flush(&self) { - self.make_current(); - gl::flush(); - } - - pub fn flush_to_surface(&self) { - gl::bind_framebuffer(0x8CA8 as gl::GLenum, self.framebuffer_id); - gl::framebuffer_texture_2d(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D, 0, 0); - } -} diff --git a/src/gl_rasterization_context_cgl.rs b/src/gl_rasterization_context_cgl.rs deleted file mode 100644 index 0f882b229d..0000000000 --- a/src/gl_rasterization_context_cgl.rs +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2013, 2015 The Servo Project Developers - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -use gl_context::GLContext; -use gl_rasterization_context; - -use cgl; -use euclid::size::Size2D; -use gleam::gl; -use io_surface; -use libc; -use std::sync::Arc; - -pub struct GLRasterizationContext { - pub gl_context: Arc, - pub size: Size2D, - pub framebuffer_id: gl::GLuint, -} - -impl GLRasterizationContext { - pub fn new(gl_context: Arc, - io_surface: io_surface::IOSurfaceRef, - size: Size2D) - -> Option { - if !gl_rasterization_context::finish_framebuffer_setup(size, || { - unsafe { - cgl::CGLTexImageIOSurface2D(gl_context.platform_context.cgl_context, - gl::TEXTURE_RECTANGLE_ARB, gl::RGBA, - size.width, size.height, - gl::BGRA, gl::UNSIGNED_INT_8_8_8_8_REV, - io_surface as *mut libc::c_void, - 0); - } - }) { - return None; - } - - Some(GLRasterizationContext { - gl_context: gl_context.clone(), - size: size, - framebuffer_id: gl_context.platform_context.framebuffer_id, - }) - } - - pub fn make_current(&self) { - self.gl_context.make_current(); - } - - pub fn flush(&self) { - self.make_current(); - gl::flush(); - } - - pub fn flush_to_surface(&self) { - gl::bind_framebuffer(gl::FRAMEBUFFER, self.framebuffer_id); - } -} diff --git a/src/gl_rasterization_context_glx.rs b/src/gl_rasterization_context_glx.rs deleted file mode 100644 index 00ba18f772..0000000000 --- a/src/gl_rasterization_context_glx.rs +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2013, 2015 The Servo Project Developers - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -use gl_context::GLContext; - -use euclid::size::Size2D; -use gleam::gl; -use std::ptr; -use std::sync::Arc; -use x11::xlib; - -pub struct GLRasterizationContext { - pub gl_context: Arc, - pub size: Size2D, - pub framebuffer_id: gl::GLuint, - - pixmap: xlib::XID, -} - -impl GLRasterizationContext { - pub fn new(gl_context: Arc, - pixmap: xlib::Pixmap, - size: Size2D) - -> Option { - Some(GLRasterizationContext { - gl_context: gl_context.clone(), - size: size, - framebuffer_id: gl_context.platform_context.framebuffer_id, - pixmap: pixmap, - }) - } - - pub fn make_current(&self) { - self.gl_context.make_current(); - } - - pub fn flush(&self) { - self.make_current(); - gl::flush(); - } - - pub fn flush_to_surface(&self) { - gl::bind_framebuffer(gl::READ_FRAMEBUFFER, self.framebuffer_id); - gl::bind_framebuffer(gl::DRAW_FRAMEBUFFER, 0); - - unsafe { - gl::BlitFramebuffer(0, 0, - self.size.width, self.size.height, - 0, 0, - self.size.width, self.size.height, - gl::COLOR_BUFFER_BIT, gl::NEAREST); - } - - gl::finish(); - self.gl_context.drop_current_context(); - - // Since the GLRasterizationContext renders to a Pixmap that is owned by the - // GLContext, we now need to copy the results to the target Pixmap. This means - // we do an extra hardware copy, but allows us to reuse the same GLContext. - let display = self.gl_context.platform_context.display; - let source_pixmap = self.gl_context.platform_context.pixmap; - unsafe { - let gc = xlib::XCreateGC(display, self.pixmap, 0, ptr::null_mut()); - xlib::XCopyArea(display, source_pixmap, - self.pixmap, - gc, - 0, (self.gl_context.size.height - self.size.height), - self.size.width as u32, self.size.height as u32, - 0, 0); - xlib::XFreeGC(display, gc); - } - } -} diff --git a/src/gl_rasterization_context_wgl.rs b/src/gl_rasterization_context_wgl.rs deleted file mode 100644 index 7feaff59b0..0000000000 --- a/src/gl_rasterization_context_wgl.rs +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2013, 2015 The Servo Project Developers - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -use gl_context::GLContext; -use gl_rasterization_context; - -use euclid::size::Size2D; -use gleam::gl; -use std::sync::Arc; - -pub struct GLRasterizationContext { - pub gl_context: Arc, - pub size: Size2D, - pub framebuffer_id: gl::GLuint, - texture_id: gl::GLuint, - depth_stencil_renderbuffer_id: gl::GLuint, -} - -impl Drop for GLRasterizationContext { - fn drop(&mut self) { - self.make_current(); - - gl_rasterization_context::destroy_framebuffer(self.framebuffer_id, - self.texture_id, - self.depth_stencil_renderbuffer_id); - } -} - -impl GLRasterizationContext { - pub fn new(gl_context: Arc, - size: Size2D) - -> Option { - None - } - - pub fn make_current(&self) { - self.gl_context.make_current(); - } - - pub fn flush(&self) { - self.make_current(); - gl::flush(); - } - - pub fn flush_to_surface(&self) { - gl::bind_framebuffer(gl::READ_FRAMEBUFFER, self.framebuffer_id); - gl::framebuffer_texture_2d(gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D, 0, 0); - } -} diff --git a/src/lib.rs b/src/lib.rs index ad490c2d4f..cb3f0a8c5a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,63 +1,413 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. -extern crate euclid; -extern crate gleam; -extern crate libc; - -#[cfg(target_os="macos")] -extern crate cgl; -#[cfg(target_os="macos")] -extern crate io_surface; +//! TODO: use bindgen and modify skia-c so we can avoid allocations. -#[cfg(target_os="linux")] -extern crate x11; -#[cfg(target_os="linux")] -extern crate glx; +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] -#[cfg(target_os="android")] -extern crate egl; +extern crate libc; #[cfg(any(target_os="linux", target_os="android", target_os="windows"))] extern crate freetype_sys; -#[cfg(any(target_os="windows"))] -extern crate fontconfig; - -pub use skia::{ - SkiaGrContextRef, - SkiaGrGLInterfaceRef, - SkiaGrGLCreateNativeInterface, - SkiaGrGLInterfaceRetain, - SkiaGrGLInterfaceRelease, - SkiaGrGLInterfaceHasExtension, - SkiaGrGLInterfaceGLVersionGreaterThanOrEqualTo, - SkiaGrContextCreate, - SkiaGrContextRetain, - SkiaGrContextRelease, -}; - -pub mod gl_context; -pub mod gl_rasterization_context; -pub mod skia; - -#[cfg(target_os="linux")] -pub mod gl_context_glx; -#[cfg(target_os="linux")] -pub mod gl_rasterization_context_glx; - -#[cfg(target_os="macos")] -pub mod gl_context_cgl; -#[cfg(target_os="macos")] -pub mod gl_rasterization_context_cgl; - -#[cfg(target_os="android")] -pub mod gl_context_android; -#[cfg(target_os="android")] -pub mod gl_rasterization_context_android; - -#[cfg(target_os="windows")] -pub mod gl_context_wgl; -#[cfg(target_os="windows")] -pub mod gl_rasterization_context_wgl; +#[cfg(any(target_os="linux", target_os="android", target_os="windows"))] +extern crate fontconfig_sys; + +use libc::*; + +pub type SkiaGrContextRef = *mut c_void; +pub type SkiaGrGLInterfaceRef = *const c_void; + +extern { + +pub fn SkiaGrGLCreateNativeInterface() -> SkiaGrGLInterfaceRef; +pub fn SkiaGrGLInterfaceRetain(anInterface: SkiaGrGLInterfaceRef); +pub fn SkiaGrGLInterfaceRelease(anInterface: SkiaGrGLInterfaceRef); +pub fn SkiaGrGLInterfaceHasExtension(anInterface: SkiaGrGLInterfaceRef, extension: *const c_char) -> bool; +pub fn SkiaGrGLInterfaceGLVersionGreaterThanOrEqualTo(anInterface: SkiaGrGLInterfaceRef, major: i32, minor: i32) -> bool; + +pub fn SkiaGrContextCreate(anInterface: SkiaGrGLInterfaceRef) -> SkiaGrContextRef; +pub fn SkiaGrContextRetain(aContext: SkiaGrContextRef); +pub fn SkiaGrContextRelease(aContext: SkiaGrContextRef); + +} + +pub type Bitmap = *mut c_void; +pub type ColorTable = *mut c_void; +pub type Surface = *mut c_void; +pub type Image = *mut c_void; +pub type Data = *mut c_void; +pub type Path = *mut c_void; +pub type PathEffect = *mut c_void; +pub type Paint = *mut c_void; +pub type Typeface = *mut c_void; +pub type GrContext = *mut c_void; +pub type StrokeRec = [u8; 4 + 4 + 4 + 4 + 1]; + +pub type Color = libc::uint32_t; + +#[repr(C)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] +pub enum ColorType { + Unknown = 0, + Alpha8 = 1, + Rgb565 = 2, + Argb4444 = 3, + Rgba8888 = 4, + Bgra8888 = 5, + Index8 = 6, + Gray8 = 7, +} + +#[cfg(target_endian = "big")] +pub const NATIVE_COLOR_TYPE: ColorType = ColorType::Rgba8888; +#[cfg(target_endian = "little")] +pub const NATIVE_COLOR_TYPE: ColorType = ColorType::Bgra8888; + +impl Default for ColorType { + fn default() -> ColorType { + NATIVE_COLOR_TYPE + } +} + +#[repr(C)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] +pub enum AlphaType { + Unknown = 0, + Opaque = 1, + Premul = 2, + Unpremul = 3, +} + +#[repr(C)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] +pub enum ColorProfile { + Linear = 0, + Srgb = 1, +} + +#[repr(C)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] +pub enum Error { + Ok = 0, + Other = 1, + BadArg = 2, +} + +#[repr(C)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] +pub enum PointMode { + Points = 0, + Lines = 1, + Polygon = 2, +} + +#[repr(C)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] +pub enum PathFillType { + Winding = 0, + EvenOdd = 1, + InverseWinding = 2, + InverseEvenOdd = 3, +} + +#[repr(C)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] +pub enum SrcRectConstraint { + Strict = 0, + Fast = 1, +} +impl Default for SrcRectConstraint { + fn default() -> SrcRectConstraint { + SrcRectConstraint::Strict + } +} + +#[repr(C)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] +pub enum CacheManagement { + Unbudgeted = 0, + Budgeted = 1, +} + +#[repr(C)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] +pub enum TypefaceStyle { + Normal = 0x00, + Bold = 0x01, + Italic = 0x02, + BoldItalic = 0x03, +} +impl Default for TypefaceStyle { + fn default() -> TypefaceStyle { + TypefaceStyle::Normal + } +} + +#[repr(C)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] +pub enum Align { + Left, + Center, + Right, +} + +#[repr(C)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] +pub enum TextEncoding { + Utf8, + Utf16, + Utf32, + GlyphId, +} + +#[repr(C)] +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +pub struct ImageInfo { + pub width: libc::c_int, + pub height: libc::c_int, + pub color_type: ColorType, + pub alpha_type: AlphaType, + pub color_profile: ColorProfile, +} +impl Default for ImageInfo { + fn default() -> ImageInfo { + unsafe { sk_default_image_info() } + } +} + +#[repr(C)] +#[derive(Copy, Clone, PartialEq, Debug)] +pub struct Rect { + pub left: libc::c_float, + pub top: libc::c_float, + pub right: libc::c_float, + pub bottom: libc::c_float, +} +impl Default for Rect { + fn default() -> Rect { + Rect { + left: 0.0f32, + top: 0.0f32, + right: 0.0f32, + bottom: 0.0f32, + } + } +} +#[repr(C)] +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +pub struct IRect { + pub left: libc::int32_t, + pub top: libc::int32_t, + pub right: libc::int32_t, + pub bottom: libc::int32_t, +} +impl Default for IRect { + fn default() -> IRect { + IRect { + left: 0, + top: 0, + right: 0, + bottom: 0, + } + } +} + +#[repr(C)] +#[derive(Copy, Clone, PartialEq, Debug)] +pub struct Size { + pub width: libc::c_float, + pub height: libc::c_float, +} +impl Default for Size { + fn default() -> Size { + Size { + width: 0.0f32, + height: 0.0f32, + } + } +} +#[repr(C)] +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +pub struct ISize { + pub width: libc::int32_t, + pub height: libc::int32_t +} +impl Default for ISize { + fn default() -> ISize { + ISize { + width: 0, + height: 0, + } + } +} + +#[repr(C)] +#[derive(Copy, Clone, PartialEq, Debug)] +pub struct Point { + pub x: libc::c_float, + pub y: libc::c_float, +} +impl Default for Point { + fn default() -> Point { + Point { + x: 0.0f32, + y: 0.0f32, + } + } +} + +#[repr(C)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] +pub enum GrContextFlushFlags { + None = 0, + Discard = 0x2, +} +#[repr(C)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] +pub enum PaintStyle { + Fill, + Stroke, + StrokeAndFill, +} + +extern { + pub fn sk_default_image_info() -> ImageInfo; + pub fn sk_color_from_argb(a: libc::uint8_t, r: libc::uint8_t, + g: libc::uint8_t, b: libc::uint8_t) -> Color; + pub fn sk_color_get_a(c: Color) -> libc::uint8_t; + pub fn sk_color_get_r(c: Color) -> libc::uint8_t; + pub fn sk_color_get_g(c: Color) -> libc::uint8_t; + pub fn sk_color_get_b(c: Color) -> libc::uint8_t; + pub fn sk_color_premul(c: Color) -> Color; + + pub fn sk_color_table_ref(ct: ColorTable); + pub fn sk_color_table_unref(ct: ColorTable); + pub fn sk_path_effect_ref(e: PathEffect); + pub fn sk_path_effect_unref(e: PathEffect); + pub fn sk_surface_ref(s: Surface) -> Error; + pub fn sk_surface_unref(s: Surface) -> Error; + pub fn sk_image_ref(i: Image) -> Error; + pub fn sk_image_unref(i: Image) -> Error; + pub fn sk_data_ref(d: Data) -> Error; + pub fn sk_data_unref(d: Data) -> Error; + pub fn sk_paint_ref(p: Paint) -> Error; + pub fn sk_paint_unref(p: Paint) -> Error; + pub fn sk_typeface_ref(p: Typeface); + pub fn sk_typeface_unref(p: Typeface); + + pub fn sk_image_get_size(i: Image, size: *mut ISize) -> Error; + pub fn sk_image_get_gr_backing_handle(i: Image) -> libc::intptr_t; + + pub fn sk_typeface_create_from_name(family_name: *const libc::c_char, + family_name_len: libc::size_t, + style: TypefaceStyle) -> Typeface; + pub fn sk_typeface_create_from_typeface(family: Typeface, + style: TypefaceStyle) -> Typeface; + pub fn sk_typeface_create_from_path(path: *const libc::c_char, + path_len: libc::size_t) -> Typeface; + + pub fn sk_new_corner_path_effect(radius: libc::c_float) -> PathEffect; + pub fn sk_path_effect_filter_path(effect: PathEffect, dest: Path, src: Path, + stroke: *const StrokeRec, cull: *const Rect) -> bool; + + pub fn sk_new_color_table(colors: *const Color, len: libc::size_t, + alpha_type: AlphaType) -> ColorTable; + + pub fn sk_new_empty_bitmap() -> Bitmap; + pub fn sk_reset_bitmap(bm: Bitmap); + pub fn sk_delete_bitmap(bm: Bitmap); + pub fn sk_bitmap_draws_nothing(bm: Bitmap) -> bool; + pub fn sk_bitmap_get_immutable(bm: Bitmap) -> bool; + pub fn sk_bitmap_set_immutable(bm: Bitmap); + pub fn sk_bitmap_row_bytes(bm: Bitmap) -> libc::size_t; + pub fn sk_bitmap_get_image_info(bm: Bitmap) -> ImageInfo; + pub fn sk_bitmap_set_image_info(bm: Bitmap, info: ImageInfo, row_bytes: libc::size_t) -> bool; + pub fn sk_bitmap_get_pixels(bm: Bitmap) -> *mut libc::c_void; + pub fn sk_bitmap_set_pixels(bm: Bitmap, pixels: *mut libc::c_void, ctable: ColorTable); + + pub fn sk_new_paint() -> Paint; + pub fn sk_copy_paint(p: Paint) -> Paint; + pub fn sk_paint_reset(p: Paint) -> Error; + pub fn sk_paint_get_color(p: Paint) -> Color; + pub fn sk_paint_set_color(p: Paint, c: Color); + pub fn sk_paint_get_typeface(p: Paint) -> Typeface; + pub fn sk_paint_set_typeface(p: Paint, tf: Typeface); + pub fn sk_paint_get_anti_alias(p: Paint) -> bool; + pub fn sk_paint_set_anti_alias(p: Paint, v: bool); + pub fn sk_paint_get_subpixel_text(p: Paint) -> bool; + pub fn sk_paint_set_subpixel_text(p: Paint, v: bool); + pub fn sk_paint_get_lcd_render_text(p: Paint) -> bool; + pub fn sk_paint_set_lcd_render_text(p: Paint, v: bool); + pub fn sk_paint_get_text_size(p: Paint) -> libc::c_float; + pub fn sk_paint_set_text_size(p: Paint, size: libc::c_float); + pub fn sk_paint_get_text_x_scale(p: Paint) -> libc::c_float; + pub fn sk_paint_set_text_x_scale(p: Paint, scale: libc::c_float); + pub fn sk_paint_get_text_align(p: Paint) -> Align; + pub fn sk_paint_set_text_align(p: Paint, align: Align); + pub fn sk_paint_get_text_encoding(p: Paint) -> TextEncoding; + pub fn sk_paint_set_text_encoding(p: Paint, encoding: TextEncoding); + pub fn sk_paint_get_style(p: Paint) -> PaintStyle; + pub fn sk_paint_set_style(p: Paint, s: PaintStyle); + pub fn sk_paint_get_path_effect(p: Paint) -> PathEffect; + pub fn sk_paint_set_path_effect(p: Paint, effect: PathEffect); + pub fn sk_paint_measure_text(p: Paint, text: *const libc::c_void, length: libc::size_t, + bounds: *mut Rect, scale: libc::c_float) -> libc::c_float; + + pub fn sk_new_render_target_surface(gr: GrContext, + budget: CacheManagement, + info: ImageInfo) -> Surface; + pub fn sk_new_raster_direct_surface(info: ImageInfo, dest: *mut libc::c_void, + row_bytes: libc::size_t) -> Surface; + + pub fn sk_new_image_snapshot(s: Surface) -> Image; + pub fn sk_surface_get_size(s: Surface, size: *mut ISize) -> Error; + pub fn sk_surface_get_image_info(s: Surface) -> ImageInfo; + + pub fn sk_flush(s: Surface) -> Error; + pub fn sk_save(s: Surface, save_count: *mut libc::c_int) -> Error; + pub fn sk_restore(s: Surface) -> Error; + pub fn sk_restore_to_count(s: Surface, count: libc::c_int) -> Error; + + pub fn sk_translate(s: Surface, dx: libc::c_float, dy: libc::c_float) -> Error; + pub fn sk_scale(s: Surface, sx: libc::c_float, sy: libc::c_float) -> Error; + pub fn sk_rotate(s: Surface, degrees: libc::c_float) -> Error; + + pub fn sk_surface_discard(s: Surface); + pub fn sk_surface_save_layer_alpha(s: Surface, bounds: *const Rect, alpha: u8) -> libc::c_int; + + pub fn sk_surface_clear(s: Surface, c: Color); + + pub fn sk_clip_rect(s: Surface, rect: Rect) -> Error; + pub fn sk_draw_paint(s: Surface, paint: Paint) -> Error; + pub fn sk_surface_draw_line(s: Surface, paint: Paint, start: Point, end: Point); + pub fn sk_draw_points(s: Surface, paint: Paint, mode: PointMode, + points: *const Point, count: libc::size_t) -> Error; + pub fn sk_draw_path(s: Surface, paint: Paint, path: Path) -> Error; + pub fn sk_draw_bitmap_rect_to_rect(s: Surface, paint: Paint, + bm: Bitmap, src: *const Rect, + dest: Rect, bleed: bool); + //pub fn sk_draw_image_rect(s: Surface, paint: Paint, src: *const Rect, + // dest: Rect, img: Image, constraint: SrcRectConstraint) -> Error; + pub fn sk_draw_text(s: Surface, paint: Paint, pos: Point, text: *const libc::c_void, + len: libc::size_t) -> Error; + + pub fn sk_new_path() -> Path; + pub fn sk_clone_path(p: Path) -> Path; + pub fn sk_del_path(p: Path); + pub fn sk_path_reset(p: Path) -> Error; + pub fn sk_path_set_fill_type(p: Path, ft: PathFillType) -> Error; + pub fn sk_path_get_fill_type(p: Path) -> PathFillType; + pub fn sk_path_move_to(p: Path, to: Point, relative: bool); + pub fn sk_path_line_to(p: Path, point: Point, relative: bool) -> Error; + pub fn sk_path_quad_to(p: Path, p1: Point, p2: Point, relative: bool) -> Error; + pub fn sk_path_cubic_to(p: Path, p1: Point, p2: Point, p3: Point, relative: bool) -> Error; + pub fn sk_path_close(p: Path); + pub fn sk_path_count_points(p: Path) -> libc::c_int; + pub fn sk_path_get_point(p: Path, index: libc::c_int) -> Point; + + pub fn gr_context_flush(context: GrContext, flags: GrContextFlushFlags); +} diff --git a/src/skia.rs b/src/skia.rs deleted file mode 100644 index 6902ebedaf..0000000000 --- a/src/skia.rs +++ /dev/null @@ -1,26 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#![allow(non_upper_case_globals)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] - -use libc::*; - -pub type SkiaGrContextRef = *mut c_void; -pub type SkiaGrGLInterfaceRef = *const c_void; - -extern { - -pub fn SkiaGrGLCreateNativeInterface() -> SkiaGrGLInterfaceRef; -pub fn SkiaGrGLInterfaceRetain(anInterface: SkiaGrGLInterfaceRef); -pub fn SkiaGrGLInterfaceRelease(anInterface: SkiaGrGLInterfaceRef); -pub fn SkiaGrGLInterfaceHasExtension(anInterface: SkiaGrGLInterfaceRef, extension: *const c_char) -> bool; -pub fn SkiaGrGLInterfaceGLVersionGreaterThanOrEqualTo(anInterface: SkiaGrGLInterfaceRef, major: i32, minor: i32) -> bool; - -pub fn SkiaGrContextCreate(anInterface: SkiaGrGLInterfaceRef) -> SkiaGrContextRef; -pub fn SkiaGrContextRetain(aContext: SkiaGrContextRef); -pub fn SkiaGrContextRelease(aContext: SkiaGrContextRef); - -}