mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
script: Add CanvasContext
trait (#35448)
* trait `CanvasContext` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * fixup most stuff Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * explain and limit crown `allow(crown::unrooted_must_root)` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
084006abb6
commit
a6f19c0092
12 changed files with 317 additions and 210 deletions
|
@ -11,8 +11,8 @@ use std::rc::Rc;
|
|||
use bitflags::bitflags;
|
||||
use canvas_traits::webgl::WebGLError::*;
|
||||
use canvas_traits::webgl::{
|
||||
webgl_channel, GLContextAttributes, InternalFormatParameter, WebGLCommand, WebGLResult,
|
||||
WebGLVersion,
|
||||
webgl_channel, GLContextAttributes, InternalFormatParameter, WebGLCommand, WebGLContextId,
|
||||
WebGLResult, WebGLVersion,
|
||||
};
|
||||
use dom_struct::dom_struct;
|
||||
use euclid::default::{Point2D, Rect, Size2D};
|
||||
|
@ -25,6 +25,7 @@ use script_layout_interface::HTMLCanvasDataSource;
|
|||
use servo_config::pref;
|
||||
use url::Host;
|
||||
|
||||
use crate::canvas_context::CanvasContext;
|
||||
use crate::dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::{
|
||||
WebGL2RenderingContextConstants as constants, WebGL2RenderingContextMethods,
|
||||
};
|
||||
|
@ -205,10 +206,6 @@ impl WebGL2RenderingContext {
|
|||
static WEBGL2_ORIGINS: &[&str] = &["www.servoexperiments.com"];
|
||||
|
||||
impl WebGL2RenderingContext {
|
||||
pub(crate) fn recreate(&self, size: Size2D<u32>) {
|
||||
self.base.recreate(size)
|
||||
}
|
||||
|
||||
pub(crate) fn current_vao(&self) -> DomRoot<WebGLVertexArrayObject> {
|
||||
self.base.current_vao_webgl2()
|
||||
}
|
||||
|
@ -903,6 +900,35 @@ impl WebGL2RenderingContext {
|
|||
}
|
||||
}
|
||||
|
||||
impl CanvasContext for WebGL2RenderingContext {
|
||||
type ID = WebGLContextId;
|
||||
|
||||
#[cfg_attr(crown, allow(crown::unrooted_must_root))] // Crown is wrong here #35570
|
||||
fn context_id(&self) -> Self::ID {
|
||||
self.base.context_id()
|
||||
}
|
||||
|
||||
fn canvas(&self) -> HTMLCanvasElementOrOffscreenCanvas {
|
||||
self.base.canvas().clone()
|
||||
}
|
||||
|
||||
fn resize(&self) {
|
||||
self.base.resize();
|
||||
}
|
||||
|
||||
fn get_image_data_as_shared_memory(&self) -> Option<IpcSharedMemory> {
|
||||
self.base.get_image_data_as_shared_memory()
|
||||
}
|
||||
|
||||
fn get_image_data(&self) -> Option<Vec<u8>> {
|
||||
self.base.get_image_data()
|
||||
}
|
||||
|
||||
fn mark_as_dirty(&self) {
|
||||
self.base.mark_as_dirty()
|
||||
}
|
||||
}
|
||||
|
||||
impl WebGL2RenderingContextMethods<crate::DomTypeHolder> for WebGL2RenderingContext {
|
||||
/// <https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.1>
|
||||
fn Canvas(&self) -> HTMLCanvasElementOrOffscreenCanvas {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue