aboutsummaryrefslogtreecommitdiffstats
path: root/components/shared
diff options
context:
space:
mode:
Diffstat (limited to 'components/shared')
-rw-r--r--components/shared/canvas/webgl.rs16
-rw-r--r--components/shared/webrender/rendering_context.rs14
-rw-r--r--components/shared/webxr/layer.rs6
3 files changed, 19 insertions, 17 deletions
diff --git a/components/shared/canvas/webgl.rs b/components/shared/canvas/webgl.rs
index 8bd1d9cd440..eaa934fc145 100644
--- a/components/shared/canvas/webgl.rs
+++ b/components/shared/canvas/webgl.rs
@@ -570,15 +570,9 @@ macro_rules! define_resource_id {
pub struct $name(nonzero_type!($type));
impl $name {
- #[allow(unsafe_code)]
#[inline]
- /// Create a new $name.
- ///
- /// # Safety
- ///
- /// Using an invalid OpenGL id may result in undefined behavior.
- pub unsafe fn new(id: $type) -> Self {
- $name(<nonzero_type!($type)>::new_unchecked(id))
+ pub fn new(id: nonzero_type!($type)) -> Self {
+ Self(id)
}
#[inline]
@@ -599,10 +593,10 @@ macro_rules! define_resource_id {
D: ::serde::Deserializer<'de>,
{
let id = <$type>::deserialize(deserializer)?;
- if id == 0 {
- Err(::serde::de::Error::custom("expected a non-zero value"))
+ if let Some(id) = <nonzero_type!($type)>::new(id) {
+ Ok($name(id))
} else {
- Ok(unsafe { $name::new(id) })
+ Err(::serde::de::Error::custom("expected a non-zero value"))
}
}
}
diff --git a/components/shared/webrender/rendering_context.rs b/components/shared/webrender/rendering_context.rs
index 21669fe4556..6c8c2803c9c 100644
--- a/components/shared/webrender/rendering_context.rs
+++ b/components/shared/webrender/rendering_context.rs
@@ -135,7 +135,8 @@ impl RenderingContext for SurfmanRenderingContext {
fn framebuffer_object(&self) -> u32 {
self.context_surface_info()
.unwrap_or(None)
- .map(|info| info.framebuffer_object)
+ .and_then(|info| info.framebuffer_object)
+ .map(|fbo| fbo.0.get())
.unwrap_or(0)
}
#[allow(unsafe_code)]
@@ -187,7 +188,11 @@ impl RenderingContext for SurfmanRenderingContext {
debug!("... getting texture for surface {:?}", front_buffer_id);
let surface_texture = device.create_surface_texture(context, surface).unwrap();
let gl_texture = device.surface_texture_object(&surface_texture);
- (surface_texture, gl_texture, size)
+ (
+ surface_texture,
+ gl_texture.map(|tex| tex.0.get()).unwrap_or(0),
+ size,
+ )
}
fn destroy_texture(&self, surface_texture: SurfaceTexture) -> Surface {
@@ -390,7 +395,10 @@ impl SurfmanRenderingContext {
pub fn surface_texture_object(&self, surface: &SurfaceTexture) -> u32 {
let device = &self.0.device.borrow();
- device.surface_texture_object(surface)
+ device
+ .surface_texture_object(surface)
+ .map(|t| t.0.get())
+ .unwrap_or_default()
}
pub fn get_proc_address(&self, name: &str) -> *const c_void {
diff --git a/components/shared/webxr/layer.rs b/components/shared/webxr/layer.rs
index d98a8b83893..904091f930f 100644
--- a/components/shared/webxr/layer.rs
+++ b/components/shared/webxr/layer.rs
@@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::fmt::Debug;
+use std::num::NonZeroU32;
use std::sync::atomic::{AtomicUsize, Ordering};
use euclid::{Rect, Size2D};
@@ -286,9 +287,8 @@ pub struct SubImages {
#[derive(Clone, Debug)]
#[cfg_attr(feature = "ipc", derive(Deserialize, Serialize))]
pub struct SubImage {
- pub color_texture: u32,
- // TODO: make this Option<NonZeroU32>
- pub depth_stencil_texture: Option<u32>,
+ pub color_texture: Option<NonZeroU32>,
+ pub depth_stencil_texture: Option<NonZeroU32>,
pub texture_array_index: Option<u32>,
pub viewport: Rect<i32, Viewport>,
}