mirror of
https://github.com/servo/servo.git
synced 2025-07-15 19:33:46 +01:00
pixels: Ensure expected formats when accesing bytes of snapshot (#37767)
I introduced snapshot in #36119 to pack raw bytes and metadata together, now we take the next step and require for user to always specify what kind of byte data they want when calling `as_bytes` or `to_vec` (basically joining transform and data). There are also valid usages when one might require just one property of bytes (textures can generally handle both RGBA and BGRA). There are also valid usages of using just raw bytes (when cropping). This PR tries to make such usages more obvious. This will make it easier to fix stuff around 2d canvas (we do not want to assume any bytes properties in abstraction). Testing: Code is covered by WPT tests. --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
e3baec4807
commit
a631b42e60
7 changed files with 142 additions and 94 deletions
|
@ -17,7 +17,7 @@ use ipc_channel::ipc::{self, IpcSender};
|
|||
use ipc_channel::router::ROUTER;
|
||||
use log::warn;
|
||||
use net_traits::ResourceThreads;
|
||||
use pixels::Snapshot;
|
||||
use pixels::{Snapshot, SnapshotPixelFormat};
|
||||
use style::color::AbsoluteColor;
|
||||
use style::properties::style_structs::Font as FontStyleStruct;
|
||||
use webrender_api::ImageKey;
|
||||
|
@ -175,14 +175,17 @@ impl<'a> CanvasPaintThread<'a> {
|
|||
.canvas(canvas_id)
|
||||
.is_point_in_path_(&path[..], x, y, fill_rule, chan),
|
||||
Canvas2dMsg::DrawImage(snapshot, dest_rect, source_rect, smoothing_enabled) => {
|
||||
let snapshot = snapshot.to_owned();
|
||||
let mut snapshot = snapshot.to_owned();
|
||||
let size = snapshot.size();
|
||||
let (data, alpha_mode, _) =
|
||||
snapshot.as_bytes(None, Some(SnapshotPixelFormat::BGRA));
|
||||
self.canvas(canvas_id).draw_image(
|
||||
snapshot.data(),
|
||||
snapshot.size(),
|
||||
data,
|
||||
size,
|
||||
dest_rect,
|
||||
source_rect,
|
||||
smoothing_enabled,
|
||||
!snapshot.alpha_mode().is_premultiplied(),
|
||||
alpha_mode.alpha().needs_alpha_multiplication(),
|
||||
)
|
||||
},
|
||||
Canvas2dMsg::DrawEmptyImage(image_size, dest_rect, source_rect) => {
|
||||
|
@ -202,16 +205,18 @@ impl<'a> CanvasPaintThread<'a> {
|
|||
source_rect,
|
||||
smoothing,
|
||||
) => {
|
||||
let image_data = self
|
||||
let mut snapshot = self
|
||||
.canvas(canvas_id)
|
||||
.read_pixels(Some(source_rect.to_u32()), Some(image_size));
|
||||
let (data, alpha_mode, _) =
|
||||
snapshot.as_bytes(None, Some(SnapshotPixelFormat::BGRA));
|
||||
self.canvas(other_canvas_id).draw_image(
|
||||
image_data.data(),
|
||||
data,
|
||||
source_rect.size.to_u32(),
|
||||
dest_rect,
|
||||
source_rect,
|
||||
smoothing,
|
||||
false,
|
||||
alpha_mode.alpha().needs_alpha_multiplication(),
|
||||
);
|
||||
},
|
||||
Canvas2dMsg::MoveTo(ref point) => self.canvas(canvas_id).move_to(point),
|
||||
|
@ -403,7 +408,7 @@ impl Canvas<'_> {
|
|||
dest_rect: Rect<f64>,
|
||||
source_rect: Rect<f64>,
|
||||
smoothing_enabled: bool,
|
||||
is_premultiplied: bool,
|
||||
premultiply: bool,
|
||||
) {
|
||||
match self {
|
||||
Canvas::Raqote(canvas_data) => canvas_data.draw_image(
|
||||
|
@ -412,7 +417,7 @@ impl Canvas<'_> {
|
|||
dest_rect,
|
||||
source_rect,
|
||||
smoothing_enabled,
|
||||
is_premultiplied,
|
||||
premultiply,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue