mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
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:
parent
1a3f10bba4
commit
3648525fe8
10 changed files with 28 additions and 71 deletions
|
@ -15,8 +15,7 @@ use script_layout_interface::wrapper_traits::{
|
||||||
LayoutDataTrait, LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode,
|
LayoutDataTrait, LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode,
|
||||||
};
|
};
|
||||||
use script_layout_interface::{
|
use script_layout_interface::{
|
||||||
GenericLayoutDataTrait, HTMLCanvasDataSource, LayoutElementType,
|
GenericLayoutDataTrait, LayoutElementType, LayoutNodeType as ScriptLayoutNodeType,
|
||||||
LayoutNodeType as ScriptLayoutNodeType,
|
|
||||||
};
|
};
|
||||||
use servo_arc::Arc as ServoArc;
|
use servo_arc::Arc as ServoArc;
|
||||||
use style::properties::ComputedValues;
|
use style::properties::ComputedValues;
|
||||||
|
@ -29,7 +28,7 @@ use crate::flow::BlockLevelBox;
|
||||||
use crate::flow::inline::InlineItem;
|
use crate::flow::inline::InlineItem;
|
||||||
use crate::fragment_tree::Fragment;
|
use crate::fragment_tree::Fragment;
|
||||||
use crate::geom::PhysicalSize;
|
use crate::geom::PhysicalSize;
|
||||||
use crate::replaced::{CanvasInfo, CanvasSource};
|
use crate::replaced::CanvasInfo;
|
||||||
use crate::table::TableLevelBox;
|
use crate::table::TableLevelBox;
|
||||||
use crate::taffy::TaffyItemBox;
|
use crate::taffy::TaffyItemBox;
|
||||||
|
|
||||||
|
@ -220,12 +219,7 @@ where
|
||||||
fn as_canvas(self) -> Option<(CanvasInfo, PhysicalSize<f64>)> {
|
fn as_canvas(self) -> Option<(CanvasInfo, PhysicalSize<f64>)> {
|
||||||
let node = self.to_threadsafe();
|
let node = self.to_threadsafe();
|
||||||
let canvas_data = node.canvas_data()?;
|
let canvas_data = node.canvas_data()?;
|
||||||
let source = match canvas_data.source {
|
let source = canvas_data.source;
|
||||||
HTMLCanvasDataSource::WebGL(texture_id) => CanvasSource::WebGL(texture_id),
|
|
||||||
HTMLCanvasDataSource::Image(image_key) => CanvasSource::Image(image_key),
|
|
||||||
HTMLCanvasDataSource::WebGPU(image_key) => CanvasSource::WebGPU(image_key),
|
|
||||||
HTMLCanvasDataSource::Empty => CanvasSource::Empty,
|
|
||||||
};
|
|
||||||
Some((
|
Some((
|
||||||
CanvasInfo { source },
|
CanvasInfo { source },
|
||||||
PhysicalSize::new(canvas_data.width.into(), canvas_data.height.into()),
|
PhysicalSize::new(canvas_data.width.into(), canvas_data.height.into()),
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use std::cell::LazyCell;
|
use std::cell::LazyCell;
|
||||||
use std::fmt;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
|
@ -96,33 +95,9 @@ impl NaturalSizes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(MallocSizeOf)]
|
|
||||||
pub(crate) enum CanvasSource {
|
|
||||||
WebGL(ImageKey),
|
|
||||||
Image(ImageKey),
|
|
||||||
WebGPU(ImageKey),
|
|
||||||
/// transparent black
|
|
||||||
Empty,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for CanvasSource {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"{}",
|
|
||||||
match *self {
|
|
||||||
CanvasSource::WebGL(_) => "WebGL",
|
|
||||||
CanvasSource::Image(_) => "Image",
|
|
||||||
CanvasSource::WebGPU(_) => "WebGPU",
|
|
||||||
CanvasSource::Empty => "Empty",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, MallocSizeOf)]
|
#[derive(Debug, MallocSizeOf)]
|
||||||
pub(crate) struct CanvasInfo {
|
pub(crate) struct CanvasInfo {
|
||||||
pub source: CanvasSource,
|
pub source: Option<ImageKey>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, MallocSizeOf)]
|
#[derive(Debug, MallocSizeOf)]
|
||||||
|
@ -388,12 +363,10 @@ impl ReplacedContents {
|
||||||
return vec![];
|
return vec![];
|
||||||
}
|
}
|
||||||
|
|
||||||
let image_key = match canvas_info.source {
|
let Some(image_key) = canvas_info.source else {
|
||||||
CanvasSource::WebGL(image_key) => image_key,
|
return vec![];
|
||||||
CanvasSource::WebGPU(image_key) => image_key,
|
|
||||||
CanvasSource::Image(image_key) => image_key,
|
|
||||||
CanvasSource::Empty => return vec![],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
vec![Fragment::Image(ArcRefCell::new(ImageFragment {
|
vec![Fragment::Image(ArcRefCell::new(ImageFragment {
|
||||||
base: self.base_fragment_info.into(),
|
base: self.base_fragment_info.into(),
|
||||||
style: style.clone(),
|
style: style.clone(),
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
|
|
||||||
use euclid::default::Size2D;
|
use euclid::default::Size2D;
|
||||||
use script_bindings::root::Dom;
|
use script_bindings::root::Dom;
|
||||||
use script_layout_interface::{HTMLCanvasData, HTMLCanvasDataSource};
|
use script_layout_interface::HTMLCanvasData;
|
||||||
use snapshot::Snapshot;
|
use snapshot::Snapshot;
|
||||||
|
use webrender_api::ImageKey;
|
||||||
|
|
||||||
use crate::dom::bindings::codegen::UnionTypes::HTMLCanvasElementOrOffscreenCanvas;
|
use crate::dom::bindings::codegen::UnionTypes::HTMLCanvasElementOrOffscreenCanvas;
|
||||||
use crate::dom::bindings::inheritance::Castable;
|
use crate::dom::bindings::inheritance::Castable;
|
||||||
|
@ -19,7 +20,8 @@ use crate::dom::types::{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) trait LayoutCanvasRenderingContextHelpers {
|
pub(crate) trait LayoutCanvasRenderingContextHelpers {
|
||||||
fn canvas_data_source(self) -> HTMLCanvasDataSource;
|
/// `None` is rendered as transparent black (cleared canvas)
|
||||||
|
fn canvas_data_source(self) -> Option<ImageKey>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait LayoutHTMLCanvasElementHelpers {
|
pub(crate) trait LayoutHTMLCanvasElementHelpers {
|
||||||
|
|
|
@ -7,9 +7,9 @@ use dom_struct::dom_struct;
|
||||||
use euclid::default::Size2D;
|
use euclid::default::Size2D;
|
||||||
use profile_traits::ipc;
|
use profile_traits::ipc;
|
||||||
use script_bindings::inheritance::Castable;
|
use script_bindings::inheritance::Castable;
|
||||||
use script_layout_interface::HTMLCanvasDataSource;
|
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use snapshot::Snapshot;
|
use snapshot::Snapshot;
|
||||||
|
use webrender_api::ImageKey;
|
||||||
|
|
||||||
use crate::canvas_context::{CanvasContext, CanvasHelpers, LayoutCanvasRenderingContextHelpers};
|
use crate::canvas_context::{CanvasContext, CanvasHelpers, LayoutCanvasRenderingContextHelpers};
|
||||||
use crate::canvas_state::CanvasState;
|
use crate::canvas_state::CanvasState;
|
||||||
|
@ -98,13 +98,13 @@ impl CanvasRenderingContext2D {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, 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;
|
let canvas_state = &self.unsafe_get().canvas_state;
|
||||||
|
|
||||||
if canvas_state.is_paintable() {
|
if canvas_state.is_paintable() {
|
||||||
HTMLCanvasDataSource::Image(canvas_state.image_key())
|
Some(canvas_state.image_key())
|
||||||
} else {
|
} else {
|
||||||
HTMLCanvasDataSource::Empty
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use script_layout_interface::HTMLCanvasDataSource;
|
|
||||||
|
|
||||||
use crate::dom::bindings::codegen::Bindings::GPUCanvasContextBinding::GPUCanvasContextMethods;
|
use crate::dom::bindings::codegen::Bindings::GPUCanvasContextBinding::GPUCanvasContextMethods;
|
||||||
use crate::dom::bindings::codegen::UnionTypes;
|
use crate::dom::bindings::codegen::UnionTypes;
|
||||||
|
@ -31,7 +30,7 @@ impl GPUCanvasContextMethods<crate::DomTypeHolder> for GPUCanvasContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, GPUCanvasContext> {
|
impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, GPUCanvasContext> {
|
||||||
fn canvas_data_source(self) -> HTMLCanvasDataSource {
|
fn canvas_data_source(self) -> Option<ImageKey> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ use image::{ColorType, ImageEncoder};
|
||||||
use ipc_channel::ipc::{self as ipcchan};
|
use ipc_channel::ipc::{self as ipcchan};
|
||||||
use js::error::throw_type_error;
|
use js::error::throw_type_error;
|
||||||
use js::rust::{HandleObject, HandleValue};
|
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::MediaStreamType;
|
||||||
use servo_media::streams::registry::MediaStreamId;
|
use servo_media::streams::registry::MediaStreamId;
|
||||||
use snapshot::Snapshot;
|
use snapshot::Snapshot;
|
||||||
|
@ -201,7 +201,7 @@ impl LayoutHTMLCanvasElementHelpers for LayoutDom<'_, HTMLCanvasElement> {
|
||||||
Some(RenderingContext::WebGL2(context)) => context.to_layout().canvas_data_source(),
|
Some(RenderingContext::WebGL2(context)) => context.to_layout().canvas_data_source(),
|
||||||
#[cfg(feature = "webgpu")]
|
#[cfg(feature = "webgpu")]
|
||||||
Some(RenderingContext::WebGPU(context)) => context.to_layout().canvas_data_source(),
|
Some(RenderingContext::WebGPU(context)) => context.to_layout().canvas_data_source(),
|
||||||
Some(RenderingContext::Placeholder(_)) | None => HTMLCanvasDataSource::Empty,
|
Some(RenderingContext::Placeholder(_)) | None => None,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,10 @@ use js::jsval::{BooleanValue, DoubleValue, Int32Value, NullValue, ObjectValue, U
|
||||||
use js::rust::{CustomAutoRooterGuard, HandleObject, MutableHandleValue};
|
use js::rust::{CustomAutoRooterGuard, HandleObject, MutableHandleValue};
|
||||||
use js::typedarray::{ArrayBufferView, CreateWith, Float32, Int32Array, Uint32, Uint32Array};
|
use js::typedarray::{ArrayBufferView, CreateWith, Float32, Int32Array, Uint32, Uint32Array};
|
||||||
use script_bindings::interfaces::WebGL2RenderingContextHelpers;
|
use script_bindings::interfaces::WebGL2RenderingContextHelpers;
|
||||||
use script_layout_interface::HTMLCanvasDataSource;
|
|
||||||
use servo_config::pref;
|
use servo_config::pref;
|
||||||
use snapshot::Snapshot;
|
use snapshot::Snapshot;
|
||||||
use url::Host;
|
use url::Host;
|
||||||
|
use webrender_api::ImageKey;
|
||||||
|
|
||||||
use crate::canvas_context::CanvasContext;
|
use crate::canvas_context::CanvasContext;
|
||||||
use crate::dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::{
|
use crate::dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::{
|
||||||
|
@ -4702,7 +4702,7 @@ impl WebGL2RenderingContextMethods<crate::DomTypeHolder> for WebGL2RenderingCont
|
||||||
|
|
||||||
impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, WebGL2RenderingContext> {
|
impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, WebGL2RenderingContext> {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn canvas_data_source(self) -> HTMLCanvasDataSource {
|
fn canvas_data_source(self) -> Option<ImageKey> {
|
||||||
let this = self.unsafe_get();
|
let this = self.unsafe_get();
|
||||||
unsafe { (*this.base.to_layout().unsafe_get()).layout_handle() }
|
unsafe { (*this.base.to_layout().unsafe_get()).layout_handle() }
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@ use js::typedarray::{
|
||||||
};
|
};
|
||||||
use net_traits::image_cache::ImageResponse;
|
use net_traits::image_cache::ImageResponse;
|
||||||
use pixels::{self, PixelFormat};
|
use pixels::{self, PixelFormat};
|
||||||
use script_layout_interface::HTMLCanvasDataSource;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use servo_config::pref;
|
use servo_config::pref;
|
||||||
use snapshot::Snapshot;
|
use snapshot::Snapshot;
|
||||||
|
@ -875,9 +874,8 @@ impl WebGLRenderingContext {
|
||||||
receiver.recv().unwrap()
|
receiver.recv().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn layout_handle(&self) -> HTMLCanvasDataSource {
|
pub(crate) fn layout_handle(&self) -> Option<ImageKey> {
|
||||||
let image_key = self.webrender_image;
|
Some(self.webrender_image)
|
||||||
HTMLCanvasDataSource::WebGL(image_key)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/extensions/ANGLE_instanced_arrays/
|
// 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> {
|
impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, WebGLRenderingContext> {
|
||||||
fn canvas_data_source(self) -> HTMLCanvasDataSource {
|
fn canvas_data_source(self) -> Option<ImageKey> {
|
||||||
(*self.unsafe_get()).layout_handle()
|
(*self.unsafe_get()).layout_handle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ use std::cell::RefCell;
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use ipc_channel::ipc::{self};
|
use ipc_channel::ipc::{self};
|
||||||
use script_layout_interface::HTMLCanvasDataSource;
|
|
||||||
use snapshot::Snapshot;
|
use snapshot::Snapshot;
|
||||||
use webgpu_traits::{
|
use webgpu_traits::{
|
||||||
ContextConfiguration, PRESENTATION_BUFFER_COUNT, WebGPU, WebGPUContextId, WebGPURequest,
|
ContextConfiguration, PRESENTATION_BUFFER_COUNT, WebGPU, WebGPUContextId, WebGPURequest,
|
||||||
|
@ -227,11 +226,11 @@ impl GPUCanvasContext {
|
||||||
|
|
||||||
// Internal helper methods
|
// Internal helper methods
|
||||||
impl GPUCanvasContext {
|
impl GPUCanvasContext {
|
||||||
fn layout_handle(&self) -> HTMLCanvasDataSource {
|
fn layout_handle(&self) -> Option<ImageKey> {
|
||||||
if self.drawing_buffer.borrow().cleared {
|
if self.drawing_buffer.borrow().cleared {
|
||||||
HTMLCanvasDataSource::Empty
|
None
|
||||||
} else {
|
} else {
|
||||||
HTMLCanvasDataSource::WebGPU(self.webrender_image)
|
Some(self.webrender_image)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,7 +300,7 @@ impl CanvasContext for GPUCanvasContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, GPUCanvasContext> {
|
impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, GPUCanvasContext> {
|
||||||
fn canvas_data_source(self) -> HTMLCanvasDataSource {
|
fn canvas_data_source(self) -> Option<ImageKey> {
|
||||||
(*self.unsafe_get()).layout_handle()
|
(*self.unsafe_get()).layout_handle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,16 +117,8 @@ pub enum LayoutElementType {
|
||||||
SVGSVGElement,
|
SVGSVGElement,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum HTMLCanvasDataSource {
|
|
||||||
WebGL(ImageKey),
|
|
||||||
Image(ImageKey),
|
|
||||||
WebGPU(ImageKey),
|
|
||||||
/// transparent black
|
|
||||||
Empty,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct HTMLCanvasData {
|
pub struct HTMLCanvasData {
|
||||||
pub source: HTMLCanvasDataSource,
|
pub source: Option<ImageKey>,
|
||||||
pub width: u32,
|
pub width: u32,
|
||||||
pub height: u32,
|
pub height: u32,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue