mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Do not assume OffscreenCanvasContext
to be 2d (#35629)
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
6062995636
commit
e887e621f8
3 changed files with 30 additions and 18 deletions
|
@ -524,13 +524,19 @@ impl CanvasState {
|
|||
));
|
||||
},
|
||||
CanvasContext::Placeholder(ref context) => {
|
||||
context.send_canvas_2d_msg(Canvas2dMsg::DrawImageInOther(
|
||||
self.get_canvas_id(),
|
||||
image_size,
|
||||
dest_rect,
|
||||
source_rect,
|
||||
smoothing_enabled,
|
||||
));
|
||||
let Some(context) = context.context() else {
|
||||
return Err(Error::InvalidState);
|
||||
};
|
||||
match *context {
|
||||
OffscreenCanvasContext::OffscreenContext2d(ref context) => context
|
||||
.send_canvas_2d_msg(Canvas2dMsg::DrawImageInOther(
|
||||
self.get_canvas_id(),
|
||||
image_size,
|
||||
dest_rect,
|
||||
source_rect,
|
||||
smoothing_enabled,
|
||||
)),
|
||||
}
|
||||
},
|
||||
_ => return Err(Error::InvalidState),
|
||||
}
|
||||
|
|
|
@ -60,7 +60,6 @@ use crate::dom::mediastream::MediaStream;
|
|||
use crate::dom::mediastreamtrack::MediaStreamTrack;
|
||||
use crate::dom::node::{Node, NodeTraits};
|
||||
use crate::dom::offscreencanvas::OffscreenCanvas;
|
||||
use crate::dom::offscreencanvasrenderingcontext2d::OffscreenCanvasRenderingContext2D;
|
||||
use crate::dom::values::UNSIGNED_LONG_MAX;
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
use crate::dom::webgl2renderingcontext::WebGL2RenderingContext;
|
||||
|
@ -109,7 +108,7 @@ impl EncodedImageType {
|
|||
#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)]
|
||||
#[derive(Clone, JSTraceable, MallocSizeOf)]
|
||||
pub(crate) enum CanvasContext {
|
||||
Placeholder(Dom<OffscreenCanvasRenderingContext2D>),
|
||||
Placeholder(Dom<OffscreenCanvas>),
|
||||
Context2d(Dom<CanvasRenderingContext2D>),
|
||||
WebGL(Dom<WebGLRenderingContext>),
|
||||
WebGL2(Dom<WebGL2RenderingContext>),
|
||||
|
@ -167,9 +166,7 @@ impl HTMLCanvasElement {
|
|||
CanvasContext::WebGL2(ref context) => context.resize(),
|
||||
#[cfg(feature = "webgpu")]
|
||||
CanvasContext::WebGPU(ref context) => context.resize(),
|
||||
CanvasContext::Placeholder(ref context) => {
|
||||
context.set_canvas_bitmap_dimensions(self.get_size().to_u64())
|
||||
},
|
||||
CanvasContext::Placeholder(ref context) => context.resize(self.get_size().cast()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -400,7 +397,7 @@ impl HTMLCanvasElement {
|
|||
},
|
||||
#[cfg(feature = "webgpu")]
|
||||
Some(CanvasContext::WebGPU(context)) => context.get_image_data_as_shared_memory(),
|
||||
Some(CanvasContext::Placeholder(context)) => context.get_image_data_as_shared_memory(),
|
||||
Some(CanvasContext::Placeholder(context)) => return context.fetch_all_data(),
|
||||
None => None,
|
||||
};
|
||||
|
||||
|
@ -674,11 +671,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
|
|||
CanGc::note(),
|
||||
);
|
||||
// Step 4. Set this canvas element's context mode to placeholder.
|
||||
if let Some(ctx) = offscreen_canvas.get_or_init_2d_context() {
|
||||
*self.context.borrow_mut() = Some(CanvasContext::Placeholder(ctx.as_traced()));
|
||||
} else {
|
||||
return Err(Error::InvalidState);
|
||||
}
|
||||
*self.context.borrow_mut() = Some(CanvasContext::Placeholder(offscreen_canvas.as_traced()));
|
||||
|
||||
// Step 5. Return offscreenCanvas.
|
||||
Ok(offscreen_canvas)
|
||||
|
|
|
@ -127,6 +127,19 @@ impl OffscreenCanvas {
|
|||
pub(crate) fn placeholder(&self) -> Option<&HTMLCanvasElement> {
|
||||
self.placeholder.as_deref()
|
||||
}
|
||||
|
||||
pub(crate) fn resize(&self, size: Size2D<u64>) {
|
||||
self.width.set(size.width);
|
||||
self.height.set(size.height);
|
||||
|
||||
if let Some(canvas_context) = self.context() {
|
||||
match &*canvas_context {
|
||||
OffscreenCanvasContext::OffscreenContext2d(rendering_context) => {
|
||||
rendering_context.set_canvas_bitmap_dimensions(self.get_size());
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl OffscreenCanvasMethods<crate::DomTypeHolder> for OffscreenCanvas {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue