From a7ceb05392bfb87ba2973224328efcaba734fc91 Mon Sep 17 00:00:00 2001 From: ngohara Date: Mon, 30 Nov 2015 20:45:57 -0500 Subject: [PATCH 01/30] crate egl for both android/linux, add pub mod egl {} --- src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 83b37af..e9dc618 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,7 +37,7 @@ extern crate x11; #[cfg(target_os="linux")] extern crate glx; -#[cfg(target_os="android")] +#[cfg(any(target_os = "linux", target_os = "android"))] extern crate egl; pub mod color; @@ -62,10 +62,13 @@ pub mod platform { pub mod android { pub mod surface; } + #[cfg(any(target_os="android",target_os="linux"))] + pub mod egl { + pub mod surface; + } #[cfg(target_os="windows")] pub mod windows { pub mod surface; } pub mod surface; } - From 92828159b58c6f29754c98b1edeb2742d8cde880 Mon Sep 17 00:00:00 2001 From: ngohara Date: Mon, 30 Nov 2015 20:46:43 -0500 Subject: [PATCH 02/30] use egl::surface instead of android surface --- src/platform/surface.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/platform/surface.rs b/src/platform/surface.rs index 7a70691..b84a1e2 100644 --- a/src/platform/surface.rs +++ b/src/platform/surface.rs @@ -32,8 +32,7 @@ pub use platform::linux::surface::{NativeDisplay, use std::ptr; #[cfg(target_os="android")] -pub use platform::android::surface::{NativeDisplay, - EGLImageNativeSurface}; +pub use platform::egl::surface::{EGLImageNativeSurface}; #[cfg(target_os="windows")] pub use platform::windows::surface::NativeDisplay; From bdc7a466c35985b86d74bf670dfb95a09328bfb1 Mon Sep 17 00:00:00 2001 From: ngohara Date: Mon, 30 Nov 2015 20:48:37 -0500 Subject: [PATCH 03/30] make egl for struct and EGLImageNativeSurface --- src/platform/egl/surface.rs | 151 ++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 src/platform/egl/surface.rs diff --git a/src/platform/egl/surface.rs b/src/platform/egl/surface.rs new file mode 100644 index 0000000..d777f30 --- /dev/null +++ b/src/platform/egl/surface.rs @@ -0,0 +1,151 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Implementation of cross-process surfaces implementing EGL surface. + +use texturegl::Texture; + +use egl::egl::{EGLDisplay, GetCurrentDisplay}; +use egl::eglext::{EGLImageKHR, DestroyImageKHR}; +use euclid::size::Size2D; +//use gleam::gl::{egl_image_target_texture2d_oes, TEXTURE_2D}; //, TexImage2D, BGRA_EXT, UNSIGNED_BYTE}; +use libc::c_void; +use skia::gl_context::{GLContext, PlatformDisplayData}; +use skia::gl_rasterization_context::GLRasterizationContext; +use std::iter::repeat; +use std::mem; +use std::sync::Arc; +use std::vec::Vec; + + +#[derive(Clone, Copy)] +pub struct NativeDisplay { + pub display: EGLDisplay, +} + + +pub struct EGLImageNativeSurface { + /// An EGLImage for the case of GPU rendering. + image: Option, + + /// A heap-allocated bitmap for the case of CPU rendering. + bitmap: Option>, + + /// Whether this pixmap will leak if the destructor runs. This is for debugging purposes. + will_leak: bool, + + /// The size of this surface. + pub size: Size2D, +} + +unsafe impl Send for EGLImageNativeSurface {} + +impl EGLImageNativeSurface { + pub fn new(_: &NativeDisplay, size: Size2D) -> EGLImageNativeSurface { + let len = size.width * size.height * 4; + let bitmap: Vec = repeat(0).take(len as usize).collect(); + + EGLImageNativeSurface { + image: None, + bitmap: Some(bitmap), + will_leak: true, + size: size, + } + } + + /// This may only be called on the compositor side. + pub fn bind_to_texture(&self, _: &NativeDisplay, texture: &Texture) { + let _bound = texture.bind(); + match self.image { + None => match self.bitmap { + Some(ref bitmap) => { + let data = bitmap.as_ptr() as *const c_void; + unsafe { + + panic!("TO DO TexImage2D "); + /* + TexImage2D(TEXTURE_2D, + 0, + BGRA_EXT as i32, + self.size.width as i32, + self.size.height as i32, + 0, + BGRA_EXT as u32, + UNSIGNED_BYTE, + data); + */ + } + } + None => { + debug!("Cannot bind the buffer(CPU rendering), there is no bitmap"); + } + }, + Some(image_khr) => { + panic!("TO DO egl_image_target_texture2d_oes"); + //egl_image_target_texture2d_oes(TEXTURE_2D, image_khr as *const c_void); + } + } + } + + /// This may only be called on the painting side. + pub fn upload(&mut self, _: &NativeDisplay, data: &[u8]) { + match self.bitmap { + Some(ref mut bitmap) => { + bitmap.clear(); + bitmap.push_all(data); + } + None => { + debug!("Cannot upload the buffer(CPU rendering), there is no bitmap"); + } + } + } + + pub fn get_id(&self) -> isize { + match self.image { + None => 0, + Some(image_khr) => image_khr as isize, + } + } + + pub fn destroy(&mut self, graphics_context: &NativeDisplay) { + match self.image { + None => {}, + Some(image_khr) => { + DestroyImageKHR(graphics_context.display, image_khr); + mem::replace(&mut self.image, None); + } + } + self.mark_wont_leak() + } + + pub fn mark_will_leak(&mut self) { + self.will_leak = true + } + + pub fn mark_wont_leak(&mut self) { + self.will_leak = false + } + + pub fn gl_rasterization_context(&mut self, + gl_context: Arc) + -> Option { + // TODO: Eventually we should preserve the previous GLRasterizationContext, + // so that we don't have to keep destroying and recreating the image. + if let Some(egl_image) = self.image.take() { + DestroyImageKHR(gl_context.platform_context.display, egl_image); + } + + let gl_rasterization_context = GLRasterizationContext::new(gl_context, self.size); + if let Some(ref gl_rasterization_context) = gl_rasterization_context { + self.bitmap = None; + self.image = Some(gl_rasterization_context.egl_image); + } + gl_rasterization_context + } +} From 60e75e72a78f1b0627cddd983d890e40224d4281 Mon Sep 17 00:00:00 2001 From: ngohara Date: Mon, 30 Nov 2015 20:53:11 -0500 Subject: [PATCH 04/30] add egl dependencies for linux --- Cargo.toml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 735fa42..3767b3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "layers" -version = "0.1.0" +version = "0.1.1" authors = ["The Servo Project Developers"] [features] @@ -58,3 +58,15 @@ features = ["xlib"] [target.arm-linux-androideabi.dependencies.egl] git = "https://github.com/servo/rust-egl" + +[target.i686-unknown-linux-gnu.dependencies.egl] +git = "https://github.com/servo/rust-egl" + +[target.x86_64-unknown-linux-gnu.dependencies.egl] +git = "https://github.com/servo/rust-egl" + +[target.arm-unknown-linux-gnueabihf.dependencies.egl] +git = "https://github.com/servo/rust-egl" + +[target.aarch64-unknown-linux-gnu.dependencies.egl] +git = "https://github.com/servo/rust-egl" From bfa31b471fa06c01ea8fa34d0caef8fa208e461e Mon Sep 17 00:00:00 2001 From: ngohara Date: Mon, 30 Nov 2015 22:11:40 -0500 Subject: [PATCH 05/30] more stubs --- src/platform/egl/surface.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/platform/egl/surface.rs b/src/platform/egl/surface.rs index d777f30..89a4c12 100644 --- a/src/platform/egl/surface.rs +++ b/src/platform/egl/surface.rs @@ -138,14 +138,17 @@ impl EGLImageNativeSurface { // TODO: Eventually we should preserve the previous GLRasterizationContext, // so that we don't have to keep destroying and recreating the image. if let Some(egl_image) = self.image.take() { - DestroyImageKHR(gl_context.platform_context.display, egl_image); + panic!("TO DO, DestroyImageKHR typecast "); + //DestroyImageKHR(gl_context.platform_context.display, egl_image); } - let gl_rasterization_context = GLRasterizationContext::new(gl_context, self.size); + panic!("TO DO, num params in GLRasterizationContext.new() "); + /* let gl_rasterization_context = GLRasterizationContext::new(gl_context, self.size); if let Some(ref gl_rasterization_context) = gl_rasterization_context { self.bitmap = None; self.image = Some(gl_rasterization_context.egl_image); } gl_rasterization_context + */ } } From 2252ee1c391adf026230b5e1ee7c85f0050f2f58 Mon Sep 17 00:00:00 2001 From: Prashant Gupta Date: Wed, 2 Dec 2015 18:29:56 -0500 Subject: [PATCH 06/30] created a blank from_es2() function for ES2 render api function call --- src/platform/linux/surface.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/platform/linux/surface.rs b/src/platform/linux/surface.rs index bb4a215..a818f0b 100644 --- a/src/platform/linux/surface.rs +++ b/src/platform/linux/surface.rs @@ -57,6 +57,13 @@ impl NativeDisplay { } } + pub fn from_es2(display: *mut xlib::Display) -> NativeDisplay { + // FIXME(pcwalton): It would be more robust to actually have the compositor pass the + // visual. + panic!("TODO"); + } + + /// Chooses the compositor visual info using the same algorithm that the compositor uses. /// /// FIXME(pcwalton): It would be more robust to actually have the compositor pass the visual. From 49ea03c4d6b0ff5e21a3a27a91f47d77eba6ea95 Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 19:13:56 -0500 Subject: [PATCH 07/30] NativeDisplay to GlxDisplayInfo, new enum NativeDisplay, new struct EglDisplayInfo --- src/platform/linux/surface.rs | 46 ++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/platform/linux/surface.rs b/src/platform/linux/surface.rs index a818f0b..7671e18 100644 --- a/src/platform/linux/surface.rs +++ b/src/platform/linux/surface.rs @@ -26,6 +26,8 @@ use std::str; use std::sync::Arc; use x11::xlib; +use egl::egl::{EGLDisplay}; + /// The display, visual info, and framebuffer configuration. This is needed in order to bind to a /// texture on the compositor side. This holds only a *weak* reference to the display and does not /// close it. @@ -34,36 +36,42 @@ use x11::xlib; /// to fix because the Display is given to us by the native windowing system, but we should fix it /// someday. /// FIXME(pcwalton): Mark nonsendable. + #[derive(Copy, Clone)] -pub struct NativeDisplay { + struct GlxDisplayInfo { pub display: *mut xlib::Display, visual_info: *mut xlib::XVisualInfo, framebuffer_configuration: Option, } +#[derive(Copy, Clone)] + struct EglDisplayInfo { + pub display: EGLDisplay, +} + +#[derive(Copy, Clone)] +pub enum NativeDisplay { + Egl(EglDisplayInfo), + Glx(GlxDisplayInfo), +} -unsafe impl Send for NativeDisplay {} -impl NativeDisplay { - pub fn new(display: *mut xlib::Display) -> NativeDisplay { + +unsafe impl Send for GlxDisplayInfo {} + +impl GlxDisplayInfo { + pub fn new(display: *mut xlib::Display) -> GlxDisplayInfo { // FIXME(pcwalton): It would be more robust to actually have the compositor pass the // visual. let (compositor_visual_info, frambuffer_configuration) = - NativeDisplay::compositor_visual_info(display); + GlxDisplayInfo::compositor_visual_info(display); - NativeDisplay { + GlxDisplayInfo { display: display, visual_info: compositor_visual_info, framebuffer_configuration: frambuffer_configuration, } } - pub fn from_es2(display: *mut xlib::Display) -> NativeDisplay { - // FIXME(pcwalton): It would be more robust to actually have the compositor pass the - // visual. - panic!("TODO"); - } - - /// Chooses the compositor visual info using the same algorithm that the compositor uses. /// /// FIXME(pcwalton): It would be more robust to actually have the compositor pass the visual. @@ -91,7 +99,7 @@ impl NativeDisplay { screen, fbconfig_attributes.as_ptr(), &mut number_of_configs); - NativeDisplay::get_compatible_configuration(display, configs, number_of_configs) + GlxDisplayInfo::get_compatible_configuration(display, configs, number_of_configs) } } @@ -104,7 +112,7 @@ impl NativeDisplay { panic!("glx::ChooseFBConfig returned no configurations."); } - if !NativeDisplay::need_to_find_32_bit_depth_visual(display) { + if !GlxDisplayInfo::need_to_find_32_bit_depth_visual(display) { let config = *configs.offset(0); let visual = glx::GetVisualFromFBConfig(mem::transmute(display), config); @@ -177,7 +185,7 @@ impl Drop for PixmapNativeSurface { } impl PixmapNativeSurface { - pub fn new(display: &NativeDisplay, size: Size2D) -> PixmapNativeSurface { + pub fn new(display: &GlxDisplayInfo, size: Size2D) -> PixmapNativeSurface { unsafe { // Create the pixmap. let screen = xlib::XDefaultScreen(display.display); @@ -199,7 +207,7 @@ impl PixmapNativeSurface { } /// This may only be called on the compositor side. - pub fn bind_to_texture(&self, display: &NativeDisplay, texture: &Texture) { + pub fn bind_to_texture(&self, display: &GlxDisplayInfo, texture: &Texture) { // Create the GLX pixmap. // // FIXME(pcwalton): RAII for exception safety? @@ -233,7 +241,7 @@ impl PixmapNativeSurface { } /// This may only be called on the painting side. - pub fn upload(&mut self, display: &NativeDisplay, data: &[u8]) { + pub fn upload(&mut self, display: &GlxDisplayInfo, data: &[u8]) { unsafe { let image = xlib::XCreateImage(display.display, (*display.visual_info).visual, @@ -264,7 +272,7 @@ impl PixmapNativeSurface { self.pixmap as isize } - pub fn destroy(&mut self, display: &NativeDisplay) { + pub fn destroy(&mut self, display: &GlxDisplayInfo) { unsafe { assert!(self.pixmap != 0); xlib::XFreePixmap(display.display, self.pixmap); From b4225a53ca64c3a0d4407ce93c143624c4fe1eb4 Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 19:15:59 -0500 Subject: [PATCH 08/30] NativeDislpay --- src/platform/surface.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/platform/surface.rs b/src/platform/surface.rs index b84a1e2..fb27a44 100644 --- a/src/platform/surface.rs +++ b/src/platform/surface.rs @@ -267,4 +267,3 @@ impl MemoryBufferNativeSurface { None } } - From 1a1b2cf01fb0e4a20b499e521000236d129cc49c Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 19:18:52 -0500 Subject: [PATCH 09/30] new NativeDislpay --- src/platform/surface.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/platform/surface.rs b/src/platform/surface.rs index fb27a44..a955e9a 100644 --- a/src/platform/surface.rs +++ b/src/platform/surface.rs @@ -51,12 +51,19 @@ pub enum NativeSurface { impl NativeSurface { /// Creates a new native surface with uninitialized data. pub fn new(display: &NativeDisplay, size: Size2D) -> NativeSurface { - if display.display == ptr::null_mut() { - NativeSurface::MemoryBuffer(MemoryBufferNativeSurface::new(display, size)) - } else { - NativeSurface::Pixmap(PixmapNativeSurface::new(display, size)) + match display { + &NativeDisplay::Egl(info) => { + NativeSurface::EGLImage(EGLImageNativeSurface::new(size)) + } + &NativeDisplay::Glx(info) => { + if info.display == ptr::null_mut() { + NativeSurface::MemoryBuffer(MemoryBufferNativeSurface::new(display, size)) + } else { + NativeSurface:ixmap(PixmapNativeSurface::new(&info, size)) + } + } } - } + } } #[cfg(target_os="macos")] From 4ae78fa4b1112cc6f5b62ecf5a83a7b29f8f41c1 Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 19:23:12 -0500 Subject: [PATCH 10/30] fix typo --- src/platform/surface.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/surface.rs b/src/platform/surface.rs index a955e9a..f38c450 100644 --- a/src/platform/surface.rs +++ b/src/platform/surface.rs @@ -59,7 +59,7 @@ impl NativeSurface { if info.display == ptr::null_mut() { NativeSurface::MemoryBuffer(MemoryBufferNativeSurface::new(display, size)) } else { - NativeSurface:ixmap(PixmapNativeSurface::new(&info, size)) + NativeSurface::Pixmap(PixmapNativeSurface::new(&info, size)) } } } From 0fa761213d6d07db0ac5985b6d3c0330c7a6bd9f Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 19:42:39 -0500 Subject: [PATCH 11/30] fixed import isssue --- src/platform/surface.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platform/surface.rs b/src/platform/surface.rs index f38c450..29bcdac 100644 --- a/src/platform/surface.rs +++ b/src/platform/surface.rs @@ -31,7 +31,7 @@ pub use platform::linux::surface::{NativeDisplay, #[cfg(target_os="linux")] use std::ptr; -#[cfg(target_os="android")] +#[cfg(any(target_os="android",target_os="linux"))] pub use platform::egl::surface::{EGLImageNativeSurface}; #[cfg(target_os="windows")] @@ -43,7 +43,7 @@ pub enum NativeSurface { Pixmap(PixmapNativeSurface), #[cfg(target_os="macos")] IOSurface(IOSurfaceNativeSurface), -#[cfg(target_os="android")] +#[cfg(any(target_os="android",target_os="linux"))] EGLImage(EGLImageNativeSurface), } @@ -53,7 +53,7 @@ impl NativeSurface { pub fn new(display: &NativeDisplay, size: Size2D) -> NativeSurface { match display { &NativeDisplay::Egl(info) => { - NativeSurface::EGLImage(EGLImageNativeSurface::new(size)) + NativeSurface::EGLImage(EGLImageNativeSurface::new(display,size)) } &NativeDisplay::Glx(info) => { if info.display == ptr::null_mut() { From 41c2a66a833f0aae05619dcc184648f67717285f Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 20:00:39 -0500 Subject: [PATCH 12/30] changed NativeDisplay to import from linux and android, panic DestroyImageKHR --- src/platform/egl/surface.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/platform/egl/surface.rs b/src/platform/egl/surface.rs index 89a4c12..fafb28c 100644 --- a/src/platform/egl/surface.rs +++ b/src/platform/egl/surface.rs @@ -24,11 +24,11 @@ use std::sync::Arc; use std::vec::Vec; -#[derive(Clone, Copy)] -pub struct NativeDisplay { - pub display: EGLDisplay, -} +#[cfg(target_os="linux")] +pub use platform::linux::surface::NativeDisplay; +#[cfg(target_os="android")] +pub use platform::android::surface::NativeDisplay; pub struct EGLImageNativeSurface { /// An EGLImage for the case of GPU rendering. @@ -67,8 +67,8 @@ impl EGLImageNativeSurface { Some(ref bitmap) => { let data = bitmap.as_ptr() as *const c_void; unsafe { - - panic!("TO DO TexImage2D "); + + panic!("TO DO TexImage2D "); /* TexImage2D(TEXTURE_2D, 0, @@ -80,7 +80,7 @@ impl EGLImageNativeSurface { UNSIGNED_BYTE, data); */ - } + } } None => { debug!("Cannot bind the buffer(CPU rendering), there is no bitmap"); @@ -117,7 +117,8 @@ impl EGLImageNativeSurface { match self.image { None => {}, Some(image_khr) => { - DestroyImageKHR(graphics_context.display, image_khr); + panic!("TO DO, DestroyImageKHR"); + //DestroyImageKHR(graphics_context.display, image_khr); mem::replace(&mut self.image, None); } } From 2006c190944332ac8cd1fb0208915708b631728f Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 20:11:41 -0500 Subject: [PATCH 13/30] fixed paramater types of several functions to NativeDisplay --- src/platform/linux/surface.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/platform/linux/surface.rs b/src/platform/linux/surface.rs index 7671e18..5ee0989 100644 --- a/src/platform/linux/surface.rs +++ b/src/platform/linux/surface.rs @@ -56,16 +56,16 @@ pub enum NativeDisplay { -unsafe impl Send for GlxDisplayInfo {} +unsafe impl Send for NativeDisplay {} -impl GlxDisplayInfo { - pub fn new(display: *mut xlib::Display) -> GlxDisplayInfo { +impl NativeDisplay { + pub fn new(display: *mut xlib::Display) -> NativeDisplay { // FIXME(pcwalton): It would be more robust to actually have the compositor pass the // visual. let (compositor_visual_info, frambuffer_configuration) = - GlxDisplayInfo::compositor_visual_info(display); + NativeDisplay::compositor_visual_info(display); - GlxDisplayInfo { + NativeDisplay { display: display, visual_info: compositor_visual_info, framebuffer_configuration: frambuffer_configuration, @@ -99,7 +99,7 @@ impl GlxDisplayInfo { screen, fbconfig_attributes.as_ptr(), &mut number_of_configs); - GlxDisplayInfo::get_compatible_configuration(display, configs, number_of_configs) + NativeDisplay::get_compatible_configuration(display, configs, number_of_configs) } } @@ -112,7 +112,7 @@ impl GlxDisplayInfo { panic!("glx::ChooseFBConfig returned no configurations."); } - if !GlxDisplayInfo::need_to_find_32_bit_depth_visual(display) { + if !NativeDisplay::need_to_find_32_bit_depth_visual(display) { let config = *configs.offset(0); let visual = glx::GetVisualFromFBConfig(mem::transmute(display), config); @@ -207,11 +207,16 @@ impl PixmapNativeSurface { } /// This may only be called on the compositor side. - pub fn bind_to_texture(&self, display: &GlxDisplayInfo, texture: &Texture) { + pub fn bind_to_texture(&self, display: &NativeDisplay, texture: &Texture) { // Create the GLX pixmap. // // FIXME(pcwalton): RAII for exception safety? unsafe { + let display = match display { + &NativeDisplay::Glx(info) => info, + &NativeDisplay::Egl(_) => unreachable!(), + }; + let pixmap_attributes = [ glx::TEXTURE_TARGET_EXT as i32, glx::TEXTURE_2D_EXT as i32, glx::TEXTURE_FORMAT_EXT as i32, glx::TEXTURE_FORMAT_RGBA_EXT as i32, @@ -241,7 +246,7 @@ impl PixmapNativeSurface { } /// This may only be called on the painting side. - pub fn upload(&mut self, display: &GlxDisplayInfo, data: &[u8]) { + pub fn upload(&mut self, display: &NativeDisplay, data: &[u8]) { unsafe { let image = xlib::XCreateImage(display.display, (*display.visual_info).visual, @@ -272,7 +277,7 @@ impl PixmapNativeSurface { self.pixmap as isize } - pub fn destroy(&mut self, display: &GlxDisplayInfo) { + pub fn destroy(&mut self, display: &NativeDisplay) { unsafe { assert!(self.pixmap != 0); xlib::XFreePixmap(display.display, self.pixmap); From 5c004f9803f2956be7a3e98327cf76d8abdb194b Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 20:14:09 -0500 Subject: [PATCH 14/30] fixed struct GlxDisplayInfo impl --- src/platform/linux/surface.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/platform/linux/surface.rs b/src/platform/linux/surface.rs index 5ee0989..0320b03 100644 --- a/src/platform/linux/surface.rs +++ b/src/platform/linux/surface.rs @@ -58,14 +58,14 @@ pub enum NativeDisplay { unsafe impl Send for NativeDisplay {} -impl NativeDisplay { - pub fn new(display: *mut xlib::Display) -> NativeDisplay { +impl GlxDisplayInfo { + pub fn new(display: *mut xlib::Display) -> GlxDisplayInfo { // FIXME(pcwalton): It would be more robust to actually have the compositor pass the // visual. let (compositor_visual_info, frambuffer_configuration) = - NativeDisplay::compositor_visual_info(display); + GlxDisplayInfo::compositor_visual_info(display); - NativeDisplay { + GlxDisplayInfo { display: display, visual_info: compositor_visual_info, framebuffer_configuration: frambuffer_configuration, @@ -99,7 +99,7 @@ impl NativeDisplay { screen, fbconfig_attributes.as_ptr(), &mut number_of_configs); - NativeDisplay::get_compatible_configuration(display, configs, number_of_configs) + GlxDisplayInfo::get_compatible_configuration(display, configs, number_of_configs) } } @@ -112,7 +112,7 @@ impl NativeDisplay { panic!("glx::ChooseFBConfig returned no configurations."); } - if !NativeDisplay::need_to_find_32_bit_depth_visual(display) { + if !GlxDisplayInfo::need_to_find_32_bit_depth_visual(display) { let config = *configs.offset(0); let visual = glx::GetVisualFromFBConfig(mem::transmute(display), config); From 57fc5732b9c349836bf5fa090448aa3cce87c1b0 Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 20:17:38 -0500 Subject: [PATCH 15/30] added GlxDisplay breakout to upload and destroy --- src/platform/linux/surface.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/platform/linux/surface.rs b/src/platform/linux/surface.rs index 0320b03..70135a4 100644 --- a/src/platform/linux/surface.rs +++ b/src/platform/linux/surface.rs @@ -248,6 +248,11 @@ impl PixmapNativeSurface { /// This may only be called on the painting side. pub fn upload(&mut self, display: &NativeDisplay, data: &[u8]) { unsafe { + let display = match display { + &NativeDisplay::Glx(info) => info, + &NativeDisplay::Egl(_) => unreachable!(), + }; + let image = xlib::XCreateImage(display.display, (*display.visual_info).visual, 32, @@ -279,6 +284,11 @@ impl PixmapNativeSurface { pub fn destroy(&mut self, display: &NativeDisplay) { unsafe { + let display = match display { + &NativeDisplay::Glx(info) => info, + &NativeDisplay::Egl(_) => unreachable!(), + }; + assert!(self.pixmap != 0); xlib::XFreePixmap(display.display, self.pixmap); self.mark_wont_leak() From 9a6e271e01566ac872bc6d5f7802f48c289539b8 Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 20:22:07 -0500 Subject: [PATCH 16/30] pub structs --- src/platform/linux/surface.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platform/linux/surface.rs b/src/platform/linux/surface.rs index 70135a4..5a5e850 100644 --- a/src/platform/linux/surface.rs +++ b/src/platform/linux/surface.rs @@ -38,13 +38,13 @@ use egl::egl::{EGLDisplay}; /// FIXME(pcwalton): Mark nonsendable. #[derive(Copy, Clone)] - struct GlxDisplayInfo { +pub struct GlxDisplayInfo { pub display: *mut xlib::Display, visual_info: *mut xlib::XVisualInfo, framebuffer_configuration: Option, } #[derive(Copy, Clone)] - struct EglDisplayInfo { +pub struct EglDisplayInfo { pub display: EGLDisplay, } @@ -288,7 +288,7 @@ impl PixmapNativeSurface { &NativeDisplay::Glx(info) => info, &NativeDisplay::Egl(_) => unreachable!(), }; - + assert!(self.pixmap != 0); xlib::XFreePixmap(display.display, self.pixmap); self.mark_wont_leak() From 3d16dfdb9328881cad150a032f21c07e178321ec Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 20:27:44 -0500 Subject: [PATCH 17/30] EGLImage for both linux/android --- src/platform/surface.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/surface.rs b/src/platform/surface.rs index 29bcdac..2a8cd8c 100644 --- a/src/platform/surface.rs +++ b/src/platform/surface.rs @@ -101,7 +101,7 @@ macro_rules! native_surface_method_with_mutability { #[cfg(target_os="macos")] NativeSurface::IOSurface($pattern) => $surface.$function_name($($argument), *), - #[cfg(target_os="android")] + #[cfg(any(target_os="android",target_os="linux"))] NativeSurface::EGLImage($pattern) => $surface.$function_name($($argument), *), } From fbc96d6e67f68d0bbd1f23d4a67da827dac59945 Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 20:30:48 -0500 Subject: [PATCH 18/30] native_surface_property linux or android for EGLImage --- src/platform/surface.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/surface.rs b/src/platform/surface.rs index 2a8cd8c..44b9a94 100644 --- a/src/platform/surface.rs +++ b/src/platform/surface.rs @@ -138,7 +138,7 @@ macro_rules! native_surface_property { NativeSurface::Pixmap(ref surface) => surface.$property_name, #[cfg(target_os="macos")] NativeSurface::IOSurface(ref surface) => surface.$property_name, - #[cfg(target_os="android")] + #[cfg(any(target_os="android",target_os="linux"))] NativeSurface::EGLImage(ref surface) => surface.$property_name, } }; From b0e44303de7bbd5f9eaa0df25b1c2f227e340de2 Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 20:40:59 -0500 Subject: [PATCH 19/30] NativeDisplay struct GlxDisplayInfo bindings fixed --- src/platform/linux/surface.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/platform/linux/surface.rs b/src/platform/linux/surface.rs index 5a5e850..08bff88 100644 --- a/src/platform/linux/surface.rs +++ b/src/platform/linux/surface.rs @@ -58,14 +58,14 @@ pub enum NativeDisplay { unsafe impl Send for NativeDisplay {} -impl GlxDisplayInfo { - pub fn new(display: *mut xlib::Display) -> GlxDisplayInfo { +impl NativeDisplay { + pub fn new(display: *mut xlib::Display) -> NativeDisplay::Glx(GlxDisplayInfo) { // FIXME(pcwalton): It would be more robust to actually have the compositor pass the // visual. let (compositor_visual_info, frambuffer_configuration) = - GlxDisplayInfo::compositor_visual_info(display); + NativeDisplay::compositor_visual_info(display); - GlxDisplayInfo { + NativeDisplay::Glx(GlxDisplayInfo) { display: display, visual_info: compositor_visual_info, framebuffer_configuration: frambuffer_configuration, @@ -99,7 +99,7 @@ impl GlxDisplayInfo { screen, fbconfig_attributes.as_ptr(), &mut number_of_configs); - GlxDisplayInfo::get_compatible_configuration(display, configs, number_of_configs) + NativeDisplay::get_compatible_configuration(display, configs, number_of_configs) } } @@ -112,7 +112,7 @@ impl GlxDisplayInfo { panic!("glx::ChooseFBConfig returned no configurations."); } - if !GlxDisplayInfo::need_to_find_32_bit_depth_visual(display) { + if !NativeDisplay::need_to_find_32_bit_depth_visual(display) { let config = *configs.offset(0); let visual = glx::GetVisualFromFBConfig(mem::transmute(display), config); From dff0f8721307a7b856e34c9174eb4f9879ed6dd2 Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 20:49:22 -0500 Subject: [PATCH 20/30] fixed typo on line 69 --- src/platform/linux/surface.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform/linux/surface.rs b/src/platform/linux/surface.rs index 08bff88..24f4ebd 100644 --- a/src/platform/linux/surface.rs +++ b/src/platform/linux/surface.rs @@ -65,11 +65,11 @@ impl NativeDisplay { let (compositor_visual_info, frambuffer_configuration) = NativeDisplay::compositor_visual_info(display); - NativeDisplay::Glx(GlxDisplayInfo) { + NativeDisplay::Glx(GlxDisplayInfo { display: display, visual_info: compositor_visual_info, framebuffer_configuration: frambuffer_configuration, - } + }) } /// Chooses the compositor visual info using the same algorithm that the compositor uses. From d2fa780763c3ef42da9e0c4e5c1928f76f0cf039 Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 20:50:04 -0500 Subject: [PATCH 21/30] fixed typo on line 62 --- src/platform/linux/surface.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/linux/surface.rs b/src/platform/linux/surface.rs index 24f4ebd..e581bc2 100644 --- a/src/platform/linux/surface.rs +++ b/src/platform/linux/surface.rs @@ -59,7 +59,7 @@ pub enum NativeDisplay { unsafe impl Send for NativeDisplay {} impl NativeDisplay { - pub fn new(display: *mut xlib::Display) -> NativeDisplay::Glx(GlxDisplayInfo) { + pub fn new(display: *mut xlib::Display) -> NativeDisplay { // FIXME(pcwalton): It would be more robust to actually have the compositor pass the // visual. let (compositor_visual_info, frambuffer_configuration) = From 5dea68a4336f47ceb6f160aa55c904f334cd1da0 Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 21:02:18 -0500 Subject: [PATCH 22/30] fixed platform_display_data to unwrapped NativeDisplay enum --- src/platform/linux/surface.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/platform/linux/surface.rs b/src/platform/linux/surface.rs index e581bc2..a0c7b93 100644 --- a/src/platform/linux/surface.rs +++ b/src/platform/linux/surface.rs @@ -156,6 +156,17 @@ impl NativeDisplay { } pub fn platform_display_data(&self) -> PlatformDisplayData { + match *self { + NativeDisplay::Glx(info) => { + PlatformDisplayData { + display: info.display, + visual_info: info.visual_info, + } + } + NativeDisplay::Egl(_) => { + unreachable!(); + } + } PlatformDisplayData { display: self.display, visual_info: self.visual_info, From b50d1ce63c1bedb789cce7873656d4c61ba7469d Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 21:04:41 -0500 Subject: [PATCH 23/30] fixed redunt code and typo --- src/platform/linux/surface.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/platform/linux/surface.rs b/src/platform/linux/surface.rs index a0c7b93..81bd14d 100644 --- a/src/platform/linux/surface.rs +++ b/src/platform/linux/surface.rs @@ -167,10 +167,6 @@ impl NativeDisplay { unreachable!(); } } - PlatformDisplayData { - display: self.display, - visual_info: self.visual_info, - } } } From 0443786f367e411450c3cb4ca634eea6021bc5e4 Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 21:12:52 -0500 Subject: [PATCH 24/30] added from_es2 --- src/platform/linux/surface.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/platform/linux/surface.rs b/src/platform/linux/surface.rs index 81bd14d..893fc37 100644 --- a/src/platform/linux/surface.rs +++ b/src/platform/linux/surface.rs @@ -26,7 +26,7 @@ use std::str; use std::sync::Arc; use x11::xlib; -use egl::egl::{EGLDisplay}; +use egl::egl::{EGLDisplay, GetCurrentDisplay}; /// The display, visual info, and framebuffer configuration. This is needed in order to bind to a /// texture on the compositor side. This holds only a *weak* reference to the display and does not @@ -168,6 +168,12 @@ impl NativeDisplay { } } } + + pub fn from_es2() -> NativeDisplay { + NativeDisplay::Egl(EglDisplayInfo { + display: GetCurrentDisplay() + }) + } } #[derive(RustcDecodable, RustcEncodable)] From 132c7ccae7cdeb7c0c65e8deb26afd1d5ed57aa5 Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 21:31:02 -0500 Subject: [PATCH 25/30] tricking linker with link extern... --- src/platform/linux/surface.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/platform/linux/surface.rs b/src/platform/linux/surface.rs index 893fc37..d9b67ad 100644 --- a/src/platform/linux/surface.rs +++ b/src/platform/linux/surface.rs @@ -11,6 +11,9 @@ #![allow(non_snake_case)] +#[link(name = "EGL")] + extern {} + use texturegl::Texture; use euclid::size::Size2D; From bdc5d12b764066b33b3f8030096275fae9a72450 Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 22:33:29 -0500 Subject: [PATCH 26/30] unpanicked TexImage2D --- src/platform/egl/surface.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/platform/egl/surface.rs b/src/platform/egl/surface.rs index fafb28c..30b28df 100644 --- a/src/platform/egl/surface.rs +++ b/src/platform/egl/surface.rs @@ -14,7 +14,7 @@ use texturegl::Texture; use egl::egl::{EGLDisplay, GetCurrentDisplay}; use egl::eglext::{EGLImageKHR, DestroyImageKHR}; use euclid::size::Size2D; -//use gleam::gl::{egl_image_target_texture2d_oes, TEXTURE_2D}; //, TexImage2D, BGRA_EXT, UNSIGNED_BYTE}; +use gleam::gl::{/*egl_image_target_texture2d_oes,*/ TEXTURE_2D, TexImage2D, BGRA_EXT, UNSIGNED_BYTE}; use libc::c_void; use skia::gl_context::{GLContext, PlatformDisplayData}; use skia::gl_rasterization_context::GLRasterizationContext; @@ -67,9 +67,6 @@ impl EGLImageNativeSurface { Some(ref bitmap) => { let data = bitmap.as_ptr() as *const c_void; unsafe { - - panic!("TO DO TexImage2D "); - /* TexImage2D(TEXTURE_2D, 0, BGRA_EXT as i32, @@ -79,7 +76,6 @@ impl EGLImageNativeSurface { BGRA_EXT as u32, UNSIGNED_BYTE, data); - */ } } None => { From 5b3363f56b7900c6b94e5afce0239f960814c518 Mon Sep 17 00:00:00 2001 From: ngohara Date: Wed, 2 Dec 2015 22:37:10 -0500 Subject: [PATCH 27/30] fixed import BGRA --- src/platform/egl/surface.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platform/egl/surface.rs b/src/platform/egl/surface.rs index 30b28df..140996c 100644 --- a/src/platform/egl/surface.rs +++ b/src/platform/egl/surface.rs @@ -14,7 +14,7 @@ use texturegl::Texture; use egl::egl::{EGLDisplay, GetCurrentDisplay}; use egl::eglext::{EGLImageKHR, DestroyImageKHR}; use euclid::size::Size2D; -use gleam::gl::{/*egl_image_target_texture2d_oes,*/ TEXTURE_2D, TexImage2D, BGRA_EXT, UNSIGNED_BYTE}; +use gleam::gl::{/*egl_image_target_texture2d_oes,*/ TEXTURE_2D, TexImage2D, BGRA, /*BGRA_EXT,*/ UNSIGNED_BYTE}; use libc::c_void; use skia::gl_context::{GLContext, PlatformDisplayData}; use skia::gl_rasterization_context::GLRasterizationContext; @@ -69,11 +69,11 @@ impl EGLImageNativeSurface { unsafe { TexImage2D(TEXTURE_2D, 0, - BGRA_EXT as i32, + BGRA as i32, self.size.width as i32, self.size.height as i32, 0, - BGRA_EXT as u32, + BGRA as u32, UNSIGNED_BYTE, data); } From 3ee9c4806995f5ad0e65bf65a09baa32947bda08 Mon Sep 17 00:00:00 2001 From: Prashant Gupta Date: Sun, 6 Dec 2015 23:22:28 -0500 Subject: [PATCH 28/30] made review comments --- src/platform/egl/surface.rs | 27 +++++---------------------- src/platform/linux/surface.rs | 25 ++++++++++++------------- src/platform/surface.rs | 5 ++++- 3 files changed, 21 insertions(+), 36 deletions(-) diff --git a/src/platform/egl/surface.rs b/src/platform/egl/surface.rs index 140996c..3f74744 100644 --- a/src/platform/egl/surface.rs +++ b/src/platform/egl/surface.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Servo Project Developers. See the COPYRIGHT +// Copyright 2015 The Servo Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 { - panic!("TO DO egl_image_target_texture2d_oes"); - //egl_image_target_texture2d_oes(TEXTURE_2D, image_khr as *const c_void); + panic!("TODO: Support GPU rasterizer path on EGL"); } } } @@ -113,8 +111,7 @@ impl EGLImageNativeSurface { match self.image { None => {}, Some(image_khr) => { - panic!("TO DO, DestroyImageKHR"); - //DestroyImageKHR(graphics_context.display, image_khr); + panic!("TODO: Support GPU rendering path on Android"); mem::replace(&mut self.image, None); } } @@ -132,20 +129,6 @@ impl EGLImageNativeSurface { pub fn gl_rasterization_context(&mut self, gl_context: Arc) -> Option { - // TODO: Eventually we should preserve the previous GLRasterizationContext, - // so that we don't have to keep destroying and recreating the image. - if let Some(egl_image) = self.image.take() { - panic!("TO DO, DestroyImageKHR typecast "); - //DestroyImageKHR(gl_context.platform_context.display, egl_image); - } - - panic!("TO DO, num params in GLRasterizationContext.new() "); - /* let gl_rasterization_context = GLRasterizationContext::new(gl_context, self.size); - if let Some(ref gl_rasterization_context) = gl_rasterization_context { - self.bitmap = None; - self.image = Some(gl_rasterization_context.egl_image); - } - gl_rasterization_context - */ + panic!("TODO: Support GL context on EGL"); } } diff --git a/src/platform/linux/surface.rs b/src/platform/linux/surface.rs index d9b67ad..e1e2b05 100644 --- a/src/platform/linux/surface.rs +++ b/src/platform/linux/surface.rs @@ -11,8 +11,9 @@ #![allow(non_snake_case)] +//TODO: Linking EGL here is probably wrong - should it be done in gleam / glutin etc? #[link(name = "EGL")] - extern {} +extern {} use texturegl::Texture; @@ -41,20 +42,20 @@ use egl::egl::{EGLDisplay, GetCurrentDisplay}; /// FIXME(pcwalton): Mark nonsendable. #[derive(Copy, Clone)] -pub struct GlxDisplayInfo { +pub struct GLXDisplayInfo { pub display: *mut xlib::Display, visual_info: *mut xlib::XVisualInfo, framebuffer_configuration: Option, } #[derive(Copy, Clone)] -pub struct EglDisplayInfo { +pub struct EGLDisplayInfo { pub display: EGLDisplay, } #[derive(Copy, Clone)] pub enum NativeDisplay { - Egl(EglDisplayInfo), - Glx(GlxDisplayInfo), + Egl(EGLDisplayInfo), + Glx(GLXDisplayInfo), } @@ -68,7 +69,7 @@ impl NativeDisplay { let (compositor_visual_info, frambuffer_configuration) = NativeDisplay::compositor_visual_info(display); - NativeDisplay::Glx(GlxDisplayInfo { + NativeDisplay::Glx(GLXDisplayInfo { display: display, visual_info: compositor_visual_info, framebuffer_configuration: frambuffer_configuration, @@ -162,18 +163,16 @@ impl NativeDisplay { match *self { NativeDisplay::Glx(info) => { PlatformDisplayData { - display: info.display, - visual_info: info.visual_info, + display: info.display, + visual_info: info.visual_info, } } - NativeDisplay::Egl(_) => { - unreachable!(); - } + NativeDisplay::Egl(_) => unreachable!(), } } pub fn from_es2() -> NativeDisplay { - NativeDisplay::Egl(EglDisplayInfo { + NativeDisplay::Egl(EGLDisplayInfo { display: GetCurrentDisplay() }) } @@ -201,7 +200,7 @@ impl Drop for PixmapNativeSurface { } impl PixmapNativeSurface { - pub fn new(display: &GlxDisplayInfo, size: Size2D) -> PixmapNativeSurface { + pub fn new(display: &GLXDisplayInfo, size: Size2D) -> PixmapNativeSurface { unsafe { // Create the pixmap. let screen = xlib::XDefaultScreen(display.display); diff --git a/src/platform/surface.rs b/src/platform/surface.rs index 44b9a94..3abe8ce 100644 --- a/src/platform/surface.rs +++ b/src/platform/surface.rs @@ -34,6 +34,9 @@ use std::ptr; #[cfg(any(target_os="android",target_os="linux"))] pub use platform::egl::surface::{EGLImageNativeSurface}; +#[cfg(target_os="android")] +pub use platform::android::surface::NativeDisplay; + #[cfg(target_os="windows")] pub use platform::windows::surface::NativeDisplay; @@ -53,7 +56,7 @@ impl NativeSurface { pub fn new(display: &NativeDisplay, size: Size2D) -> NativeSurface { match display { &NativeDisplay::Egl(info) => { - NativeSurface::EGLImage(EGLImageNativeSurface::new(display,size)) + NativeSurface::EGLImage(EGLImageNativeSurface::new(display, size)) } &NativeDisplay::Glx(info) => { if info.display == ptr::null_mut() { From cd78d85621b15a5e6056e3dd3504b82d074ed741 Mon Sep 17 00:00:00 2001 From: Prashant Gupta Date: Sun, 6 Dec 2015 23:32:34 -0500 Subject: [PATCH 29/30] Fixed extra spaces --- src/platform/egl/surface.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/egl/surface.rs b/src/platform/egl/surface.rs index 3f74744..3ce3b41 100644 --- a/src/platform/egl/surface.rs +++ b/src/platform/egl/surface.rs @@ -82,7 +82,7 @@ impl EGLImageNativeSurface { } }, Some(image_khr) => { - panic!("TODO: Support GPU rasterizer path on EGL"); + panic!("TODO: Support GPU rasterizer path on EGL"); } } } From c32236f95c053561a722bc1248fb8726362a2217 Mon Sep 17 00:00:00 2001 From: ngohara Date: Tue, 8 Dec 2015 22:09:26 -0500 Subject: [PATCH 30/30] fixed BGRA/BGRA_EXT for Linux/Android --- src/platform/egl/surface.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/platform/egl/surface.rs b/src/platform/egl/surface.rs index 3ce3b41..cb691c6 100644 --- a/src/platform/egl/surface.rs +++ b/src/platform/egl/surface.rs @@ -23,6 +23,14 @@ use std::mem; use std::sync::Arc; use std::vec::Vec; +use gleam::gl; + +#[cfg(target_os = "linux")] +const GL_FORMAT_BGRA: gl::GLuint = gl::BGRA; + +#[cfg(any(target_os = "android", target_os = "gonk"))] +const GL_FORMAT_BGRA: gl::GLuint = gl::BGRA_EXT; + #[cfg(target_os="linux")] pub use platform::linux::surface::NativeDisplay; @@ -68,11 +76,11 @@ impl EGLImageNativeSurface { unsafe { TexImage2D(TEXTURE_2D, 0, - BGRA as i32, + GL_FORMAT_BGRA as i32, self.size.width as i32, self.size.height as i32, 0, - BGRA as u32, + GL_FORMAT_BGRA as u32, UNSIGNED_BYTE, data); } @@ -82,7 +90,7 @@ impl EGLImageNativeSurface { } }, Some(image_khr) => { - panic!("TODO: Support GPU rasterizer path on EGL"); + panic!("TODO: Support GPU rasterizer path on EGL"); } } }