Remove HTMLCanvasDataSource and CanvasSource (#36794)

All canvases return `Option<ImageKey>`.

Testing: Just refactor without behavior changes

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
sagudev 2025-05-01 19:49:59 +02:00 committed by GitHub
parent 1a3f10bba4
commit 3648525fe8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 28 additions and 71 deletions

View file

@ -7,9 +7,9 @@ use dom_struct::dom_struct;
use euclid::default::Size2D;
use profile_traits::ipc;
use script_bindings::inheritance::Castable;
use script_layout_interface::HTMLCanvasDataSource;
use servo_url::ServoUrl;
use snapshot::Snapshot;
use webrender_api::ImageKey;
use crate::canvas_context::{CanvasContext, CanvasHelpers, LayoutCanvasRenderingContextHelpers};
use crate::canvas_state::CanvasState;
@ -98,13 +98,13 @@ impl CanvasRenderingContext2D {
}
impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, CanvasRenderingContext2D> {
fn canvas_data_source(self) -> HTMLCanvasDataSource {
fn canvas_data_source(self) -> Option<ImageKey> {
let canvas_state = &self.unsafe_get().canvas_state;
if canvas_state.is_paintable() {
HTMLCanvasDataSource::Image(canvas_state.image_key())
Some(canvas_state.image_key())
} else {
HTMLCanvasDataSource::Empty
None
}
}
}

View file

@ -3,7 +3,6 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use dom_struct::dom_struct;
use script_layout_interface::HTMLCanvasDataSource;
use crate::dom::bindings::codegen::Bindings::GPUCanvasContextBinding::GPUCanvasContextMethods;
use crate::dom::bindings::codegen::UnionTypes;
@ -31,7 +30,7 @@ impl GPUCanvasContextMethods<crate::DomTypeHolder> for GPUCanvasContext {
}
impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, GPUCanvasContext> {
fn canvas_data_source(self) -> HTMLCanvasDataSource {
fn canvas_data_source(self) -> Option<ImageKey> {
unimplemented!()
}
}

View file

@ -21,7 +21,7 @@ use image::{ColorType, ImageEncoder};
use ipc_channel::ipc::{self as ipcchan};
use js::error::throw_type_error;
use js::rust::{HandleObject, HandleValue};
use script_layout_interface::{HTMLCanvasData, HTMLCanvasDataSource};
use script_layout_interface::HTMLCanvasData;
use servo_media::streams::MediaStreamType;
use servo_media::streams::registry::MediaStreamId;
use snapshot::Snapshot;
@ -201,7 +201,7 @@ impl LayoutHTMLCanvasElementHelpers for LayoutDom<'_, HTMLCanvasElement> {
Some(RenderingContext::WebGL2(context)) => context.to_layout().canvas_data_source(),
#[cfg(feature = "webgpu")]
Some(RenderingContext::WebGPU(context)) => context.to_layout().canvas_data_source(),
Some(RenderingContext::Placeholder(_)) | None => HTMLCanvasDataSource::Empty,
Some(RenderingContext::Placeholder(_)) | None => None,
}
};

View file

@ -22,10 +22,10 @@ use js::jsval::{BooleanValue, DoubleValue, Int32Value, NullValue, ObjectValue, U
use js::rust::{CustomAutoRooterGuard, HandleObject, MutableHandleValue};
use js::typedarray::{ArrayBufferView, CreateWith, Float32, Int32Array, Uint32, Uint32Array};
use script_bindings::interfaces::WebGL2RenderingContextHelpers;
use script_layout_interface::HTMLCanvasDataSource;
use servo_config::pref;
use snapshot::Snapshot;
use url::Host;
use webrender_api::ImageKey;
use crate::canvas_context::CanvasContext;
use crate::dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::{
@ -4702,7 +4702,7 @@ impl WebGL2RenderingContextMethods<crate::DomTypeHolder> for WebGL2RenderingCont
impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, WebGL2RenderingContext> {
#[allow(unsafe_code)]
fn canvas_data_source(self) -> HTMLCanvasDataSource {
fn canvas_data_source(self) -> Option<ImageKey> {
let this = self.unsafe_get();
unsafe { (*this.base.to_layout().unsafe_get()).layout_handle() }
}

View file

@ -31,7 +31,6 @@ use js::typedarray::{
};
use net_traits::image_cache::ImageResponse;
use pixels::{self, PixelFormat};
use script_layout_interface::HTMLCanvasDataSource;
use serde::{Deserialize, Serialize};
use servo_config::pref;
use snapshot::Snapshot;
@ -875,9 +874,8 @@ impl WebGLRenderingContext {
receiver.recv().unwrap()
}
pub(crate) fn layout_handle(&self) -> HTMLCanvasDataSource {
let image_key = self.webrender_image;
HTMLCanvasDataSource::WebGL(image_key)
pub(crate) fn layout_handle(&self) -> Option<ImageKey> {
Some(self.webrender_image)
}
// https://www.khronos.org/registry/webgl/extensions/ANGLE_instanced_arrays/
@ -4829,7 +4827,7 @@ impl WebGLRenderingContextMethods<crate::DomTypeHolder> for WebGLRenderingContex
}
impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, WebGLRenderingContext> {
fn canvas_data_source(self) -> HTMLCanvasDataSource {
fn canvas_data_source(self) -> Option<ImageKey> {
(*self.unsafe_get()).layout_handle()
}
}

View file

@ -8,7 +8,6 @@ use std::cell::RefCell;
use arrayvec::ArrayVec;
use dom_struct::dom_struct;
use ipc_channel::ipc::{self};
use script_layout_interface::HTMLCanvasDataSource;
use snapshot::Snapshot;
use webgpu_traits::{
ContextConfiguration, PRESENTATION_BUFFER_COUNT, WebGPU, WebGPUContextId, WebGPURequest,
@ -227,11 +226,11 @@ impl GPUCanvasContext {
// Internal helper methods
impl GPUCanvasContext {
fn layout_handle(&self) -> HTMLCanvasDataSource {
fn layout_handle(&self) -> Option<ImageKey> {
if self.drawing_buffer.borrow().cleared {
HTMLCanvasDataSource::Empty
None
} else {
HTMLCanvasDataSource::WebGPU(self.webrender_image)
Some(self.webrender_image)
}
}
@ -301,7 +300,7 @@ impl CanvasContext for GPUCanvasContext {
}
impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, GPUCanvasContext> {
fn canvas_data_source(self) -> HTMLCanvasDataSource {
fn canvas_data_source(self) -> Option<ImageKey> {
(*self.unsafe_get()).layout_handle()
}
}