mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Canvas rendering for layout 2020
Update test expectations with layout 2020 canvas support
This commit is contained in:
parent
0bd794aed7
commit
f0e30f5b0c
26 changed files with 116 additions and 61 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2889,6 +2889,7 @@ version = "0.0.1"
|
|||
dependencies = [
|
||||
"app_units",
|
||||
"atomic_refcell",
|
||||
"canvas_traits",
|
||||
"cssparser",
|
||||
"embedder_traits",
|
||||
"euclid",
|
||||
|
|
|
@ -15,6 +15,7 @@ doctest = false
|
|||
[dependencies]
|
||||
app_units = "0.7"
|
||||
atomic_refcell = "0.1"
|
||||
canvas_traits = {path = "../canvas_traits"}
|
||||
cssparser = "0.27"
|
||||
embedder_traits = {path = "../embedder_traits"}
|
||||
euclid = "0.20"
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use crate::context::LayoutContext;
|
||||
use crate::element_data::{LayoutBox, LayoutDataForElement};
|
||||
use crate::geom::PhysicalSize;
|
||||
use crate::replaced::ReplacedContent;
|
||||
use crate::replaced::{CanvasInfo, CanvasSource, ReplacedContent};
|
||||
use crate::style_ext::{Display, DisplayGeneratingBox, DisplayInside, DisplayOutside};
|
||||
use crate::wrapper::GetRawData;
|
||||
use atomic_refcell::{AtomicRefCell, AtomicRefMut};
|
||||
|
@ -14,9 +14,10 @@ use net_traits::image::base::Image as NetImage;
|
|||
use script_layout_interface::wrapper_traits::{
|
||||
LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode,
|
||||
};
|
||||
use script_layout_interface::HTMLCanvasDataSource;
|
||||
use servo_arc::Arc as ServoArc;
|
||||
use std::marker::PhantomData as marker;
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use style::dom::{OpaqueNode, TNode};
|
||||
use style::properties::ComputedValues;
|
||||
use style::selector_parser::PseudoElement;
|
||||
|
@ -354,6 +355,7 @@ pub(crate) trait NodeExt<'dom>: 'dom + Copy + LayoutNode + Send + Sync {
|
|||
/// Returns the image if it’s loaded, and its size in image pixels
|
||||
/// adjusted for `image_density`.
|
||||
fn as_image(self) -> Option<(Option<Arc<NetImage>>, PhysicalSize<f64>)>;
|
||||
fn as_canvas(self) -> Option<(CanvasInfo, PhysicalSize<f64>)>;
|
||||
fn first_child(self) -> Option<Self>;
|
||||
fn next_sibling(self) -> Option<Self>;
|
||||
fn parent_node(self) -> Option<Self>;
|
||||
|
@ -399,6 +401,24 @@ where
|
|||
Some((resource, PhysicalSize::new(width, height)))
|
||||
}
|
||||
|
||||
fn as_canvas(self) -> Option<(CanvasInfo, PhysicalSize<f64>)> {
|
||||
let node = self.to_threadsafe();
|
||||
let canvas_data = node.canvas_data()?;
|
||||
let source = match canvas_data.source {
|
||||
HTMLCanvasDataSource::WebGL(texture_id) => CanvasSource::WebGL(texture_id),
|
||||
HTMLCanvasDataSource::Image(ipc_sender) => {
|
||||
CanvasSource::Image(ipc_sender.map(|renderer| Arc::new(Mutex::new(renderer))))
|
||||
},
|
||||
};
|
||||
Some((
|
||||
CanvasInfo {
|
||||
source,
|
||||
canvas_id: canvas_data.canvas_id,
|
||||
},
|
||||
PhysicalSize::new(canvas_data.width.into(), canvas_data.height.into()),
|
||||
))
|
||||
}
|
||||
|
||||
fn first_child(self) -> Option<Self> {
|
||||
TNode::first_child(&self)
|
||||
}
|
||||
|
|
|
@ -10,15 +10,19 @@ use crate::geom::PhysicalSize;
|
|||
use crate::sizing::ContentSizes;
|
||||
use crate::style_ext::ComputedValuesExt;
|
||||
use crate::ContainingBlock;
|
||||
use canvas_traits::canvas::{CanvasId, CanvasMsg, FromLayoutMsg};
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use net_traits::image::base::Image;
|
||||
use net_traits::image_cache::{ImageOrMetadataAvailable, UsePlaceholder};
|
||||
use servo_arc::Arc as ServoArc;
|
||||
use std::sync::Arc;
|
||||
use std::fmt;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use style::properties::ComputedValues;
|
||||
use style::servo::url::ComputedUrl;
|
||||
use style::values::computed::{Length, LengthOrAuto};
|
||||
use style::values::CSSFloat;
|
||||
use style::Zero;
|
||||
use webrender_api::ImageKey;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub(crate) struct ReplacedContent {
|
||||
|
@ -44,14 +48,52 @@ pub(crate) struct IntrinsicSizes {
|
|||
pub ratio: Option<CSSFloat>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub(crate) enum CanvasSource {
|
||||
WebGL(ImageKey),
|
||||
Image(Option<Arc<Mutex<IpcSender<CanvasMsg>>>>),
|
||||
}
|
||||
|
||||
impl fmt::Debug for CanvasSource {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
match *self {
|
||||
CanvasSource::WebGL(_) => "WebGL",
|
||||
CanvasSource::Image(_) => "Image",
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub(crate) struct CanvasInfo {
|
||||
pub source: CanvasSource,
|
||||
pub canvas_id: CanvasId,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub(crate) enum ReplacedContentKind {
|
||||
Image(Option<Arc<Image>>),
|
||||
Canvas(CanvasInfo),
|
||||
}
|
||||
|
||||
impl ReplacedContent {
|
||||
pub fn for_element<'dom>(element: impl NodeExt<'dom>) -> Option<Self> {
|
||||
let (kind, intrinsic_size_in_dots) = {
|
||||
if let Some((image, intrinsic_size_in_dots)) = element.as_image() {
|
||||
(ReplacedContentKind::Image(image), intrinsic_size_in_dots)
|
||||
} else if let Some((canvas_info, intrinsic_size_in_dots)) = element.as_canvas() {
|
||||
(
|
||||
ReplacedContentKind::Canvas(canvas_info),
|
||||
intrinsic_size_in_dots,
|
||||
)
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
// FIXME: should 'image-resolution' (when implemented) be used *instead* of
|
||||
// `script::dom::htmlimageelement::ImageRequest::current_pixel_density`?
|
||||
|
||||
|
@ -61,7 +103,7 @@ impl ReplacedContent {
|
|||
let width = (intrinsic_size_in_dots.width as CSSFloat) / dppx;
|
||||
let height = (intrinsic_size_in_dots.height as CSSFloat) / dppx;
|
||||
return Some(Self {
|
||||
kind: ReplacedContentKind::Image(image),
|
||||
kind,
|
||||
intrinsic: IntrinsicSizes {
|
||||
width: Some(Length::new(width)),
|
||||
height: Some(Length::new(height)),
|
||||
|
@ -70,8 +112,6 @@ impl ReplacedContent {
|
|||
},
|
||||
});
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn from_image_url<'dom>(
|
||||
element: impl NodeExt<'dom>,
|
||||
|
@ -160,6 +200,34 @@ impl ReplacedContent {
|
|||
})
|
||||
.into_iter()
|
||||
.collect(),
|
||||
ReplacedContentKind::Canvas(canvas_info) => {
|
||||
let image_key = match canvas_info.source {
|
||||
CanvasSource::WebGL(image_key) => image_key,
|
||||
CanvasSource::Image(ref ipc_renderer) => match *ipc_renderer {
|
||||
Some(ref ipc_renderer) => {
|
||||
let ipc_renderer = ipc_renderer.lock().unwrap();
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
ipc_renderer
|
||||
.send(CanvasMsg::FromLayout(
|
||||
FromLayoutMsg::SendData(sender),
|
||||
canvas_info.canvas_id,
|
||||
))
|
||||
.unwrap();
|
||||
receiver.recv().unwrap().image_key
|
||||
},
|
||||
None => return vec![],
|
||||
},
|
||||
};
|
||||
vec![Fragment::Image(ImageFragment {
|
||||
debug_id: DebugId::new(),
|
||||
style: style.clone(),
|
||||
rect: Rect {
|
||||
start_corner: Vec2::zero(),
|
||||
size,
|
||||
},
|
||||
image_key,
|
||||
})]
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
[canvas_complexshapes_arcto_001.htm]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[canvas_complexshapes_beziercurveto_001.htm]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[canvas_compositing_globalcompositeoperation_001.htm]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[drawImage-from-bitmap-orientation-none.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[drawImage-from-bitmap.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[drawImage-from-element-orientation-none.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[drawImage-from-element-swap-width-height-orientation-none.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[drawImage-from-element.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[canvas_linestyles_linecap_001.htm]
|
||||
expected: FAIL
|
|
@ -0,0 +1,2 @@
|
|||
[canvas_shadows_002.htm]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[canvas_state_restore_001.htm]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[canvas_transformations_scale_001.htm]
|
||||
expected: FAIL
|
|
@ -17,3 +17,6 @@
|
|||
[test the top of layer]
|
||||
expected: FAIL
|
||||
|
||||
[test some point of the element: top left corner]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
[canvas_as_block_element_a.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[canvas_over_area.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[max_inline_block_size_canvas.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[clearcolor.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[draw_arrays_simple.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[tex_image_2d_abv.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[tex_image_2d_canvas2d.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[tex_image_2d_mipmap.html]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[tex_image_2d_simple.html]
|
||||
expected: FAIL
|
Loading…
Add table
Add a link
Reference in a new issue