Skip to content

Commit

Permalink
Update toolchain and cfg_aliases to match servo
Browse files Browse the repository at this point in the history
* Update cfg_aliases to fix the new unexpected_cfgs lint
* Update the rust_toolchain to match servo and prevent warning
   about -Zcheck-cfg

Signed-off-by: Jonathan Schwender <[email protected]>
  • Loading branch information
jschwe committed Aug 23, 2024
1 parent 3a82fef commit 79fe6d5
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "surfman"
license = "MIT OR Apache-2.0 OR MPL-2.0"
edition = "2018"
version = "0.9.7"
version = "0.9.8"
authors = [
"Patrick Walton <[email protected]>",
"Emilio Cobos Álvarez <[email protected]>",
Expand All @@ -15,7 +15,7 @@ readme = "README.md"

[build-dependencies]
gl_generator = "0.14"
cfg_aliases = "0.1.0"
cfg_aliases = "0.2.1"

[features]
chains = ["fnv", "sparkle"]
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.76"
channel = "1.80.1"
components = [ "rustfmt" ]
profile = "minimal"
139 changes: 134 additions & 5 deletions src/platform/egl/surface/ohos_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ use euclid::default::Size2D;
use log::info;

use crate::egl;
use crate::egl::types::EGLSurface;
use crate::egl::types::{EGLAttrib, EGLConfig, EGLContext, EGLDisplay, EGLSurface, EGLint};
use crate::gl;
use crate::gl::types::{GLenum, GLuint};
use crate::gl::types::{GLenum, GLint, GLuint};
use crate::gl_utils;
use crate::platform::generic::egl::device::EGL_FUNCTIONS;
use crate::platform::generic::egl::ffi::EGL_EXTENSION_FUNCTIONS;
use crate::platform::generic::egl::ffi::EGL_NO_IMAGE_KHR;
use crate::platform::generic::egl::ffi::EGLClientBuffer;
use crate::platform::generic::egl::ffi::EGLImageKHR;
use crate::platform::generic::egl::ffi::EGL_GL_TEXTURE_2D_KHR;
use crate::platform::generic::egl::ffi::EGL_IMAGE_PRESERVED_KHR;
use crate::renderbuffers::Renderbuffers;
use crate::{Error, SurfaceAccess, SurfaceID, SurfaceInfo, SurfaceType};

use super::super::context::{Context, GL_FUNCTIONS};
Expand All @@ -27,7 +33,19 @@ use super::{Surface, SurfaceTexture};

const SURFACE_GL_TEXTURE_TARGET: GLenum = gl::TEXTURE_2D;

#[repr(C)]
pub struct AHardwareBuffer {
_opaque: [u8; 0],
}

pub(crate) enum SurfaceObjects {
HardwareBuffer {
hardware_buffer: *mut AHardwareBuffer,
egl_image: EGLImageKHR,
framebuffer_object: GLuint,
texture_object: GLuint,
renderbuffers: Renderbuffers,
},
Window { egl_surface: EGLSurface },
}

Expand Down Expand Up @@ -58,10 +76,90 @@ impl Device {

fn create_generic_surface(
&mut self,
_context: &Context,
_size: &Size2D<i32>,
context: &Context,
size: &Size2D<i32>,
) -> Result<Surface, Error> {
Err(Error::Unimplemented)
let _guard = self.temporarily_make_context_current(context)?;

GL_FUNCTIONS.with(|gl| {
let egl_image_attribs = [
EGL_IMAGE_PRESERVED_KHR as EGLint,
egl::FALSE as EGLint,
egl::NONE as EGLint,
0,
];
unsafe {
// Create our texture.
let mut texture_object = 0;
gl.GenTextures(1, &mut texture_object);
// Save the current texture binding
let mut old_texture_object = 0;
gl.GetIntegerv(gl::TEXTURE_BINDING_2D, &mut old_texture_object);
gl.BindTexture(gl::TEXTURE_2D, texture_object);
// Unbind PIXEL_UNPACK_BUFFER, because if it is bound,
// it can cause errors in glTexImage2D.
// TODO: should this be inside a check for GL 2.0?
let mut unpack_buffer = 0;
gl.GetIntegerv(gl::PIXEL_UNPACK_BUFFER_BINDING, &mut unpack_buffer);
if unpack_buffer != 0 {
gl.BindBuffer(gl::PIXEL_UNPACK_BUFFER, 0);
}
gl.TexImage2D(
gl::TEXTURE_2D,
0,
gl::RGBA as GLint,
size.width,
size.height,
0,
gl::RGBA,
gl::UNSIGNED_BYTE,
ptr::null(),
);
// Restore the old bindings
gl.BindTexture(gl::TEXTURE_2D, old_texture_object as _);
if unpack_buffer != 0 {
gl.BindBuffer(gl::PIXEL_UNPACK_BUFFER, unpack_buffer as _);
}

// Create our image.
let egl_client_buffer = texture_object as usize as EGLClientBuffer;
let egl_image = (EGL_EXTENSION_FUNCTIONS.CreateImageKHR)(
self.egl_display,
context.egl_context,
EGL_GL_TEXTURE_2D_KHR,
egl_client_buffer,
egl_image_attribs.as_ptr(),
);

// Create the framebuffer, and bind the texture to it.
let framebuffer_object =
gl_utils::create_and_bind_framebuffer(gl, gl::TEXTURE_2D, texture_object);

// Bind renderbuffers as appropriate.
let context_descriptor = self.context_descriptor(context);
let context_attributes = self.context_descriptor_attributes(&context_descriptor);
let renderbuffers = Renderbuffers::new(gl, size, &context_attributes);
renderbuffers.bind_to_current_framebuffer(gl);

debug_assert_eq!(
gl.CheckFramebufferStatus(gl::FRAMEBUFFER),
gl::FRAMEBUFFER_COMPLETE
);

Ok(Surface {
size: *size,
context_id: context.id,
objects: SurfaceObjects::HardwareBuffer {
hardware_buffer: std::ptr::null_mut(),
egl_image,
framebuffer_object,
texture_object,
renderbuffers,
},
destroyed: false,
})
}
})
}

unsafe fn create_window_surface(
Expand Down Expand Up @@ -138,6 +236,7 @@ impl Device {
egl.SwapBuffers(self.egl_display, egl_surface);
Ok(())
}
SurfaceObjects::HardwareBuffer { .. } => Err(Error::NoWidgetAttached),
}
})
}
Expand Down Expand Up @@ -171,6 +270,32 @@ impl Device {

unsafe {
match surface.objects {
SurfaceObjects::HardwareBuffer {
ref mut hardware_buffer,
ref mut egl_image,
ref mut framebuffer_object,
ref mut texture_object,
ref mut renderbuffers,
} => {
GL_FUNCTIONS.with(|gl| {
gl.BindFramebuffer(gl::FRAMEBUFFER, 0);
gl.DeleteFramebuffers(1, framebuffer_object);
*framebuffer_object = 0;

renderbuffers.destroy(gl);

gl.DeleteTextures(1, texture_object);
*texture_object = 0;

let egl_display = self.egl_display;
let result =
(EGL_EXTENSION_FUNCTIONS.DestroyImageKHR)(egl_display, *egl_image);
assert_ne!(result, egl::FALSE);
*egl_image = EGL_NO_IMAGE_KHR;

*hardware_buffer = ptr::null_mut();
});
}
SurfaceObjects::Window {
ref mut egl_surface,
} => EGL_FUNCTIONS.with(|egl| {
Expand Down Expand Up @@ -242,6 +367,9 @@ impl Device {
id: surface.id(),
context_id: surface.context_id,
framebuffer_object: match surface.objects {
SurfaceObjects::HardwareBuffer {
framebuffer_object, ..
} => framebuffer_object,
SurfaceObjects::Window { .. } => 0,
},
}
Expand All @@ -267,6 +395,7 @@ impl NativeWidget {
impl Surface {
pub(super) fn id(&self) -> SurfaceID {
match self.objects {
SurfaceObjects::HardwareBuffer { egl_image, .. } => SurfaceID(egl_image as usize),
SurfaceObjects::Window { egl_surface } => SurfaceID(egl_surface as usize),
}
}
Expand Down

0 comments on commit 79fe6d5

Please sign in to comment.