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:
sagudev 2025-07-03 17:02:41 +02:00 committed by GitHub
parent e3baec4807
commit a631b42e60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 142 additions and 94 deletions

View file

@ -21,7 +21,7 @@ use js::jsapi::{JSObject, Type};
use js::jsval::{BooleanValue, DoubleValue, Int32Value, NullValue, ObjectValue, UInt32Value};
use js::rust::{CustomAutoRooterGuard, HandleObject, MutableHandleValue};
use js::typedarray::{ArrayBufferView, CreateWith, Float32, Int32Array, Uint32, Uint32Array};
use pixels::Snapshot;
use pixels::{Alpha, Snapshot};
use script_bindings::interfaces::WebGL2RenderingContextHelpers;
use servo_config::pref;
use url::Host;
@ -3257,7 +3257,8 @@ impl WebGL2RenderingContextMethods<crate::DomTypeHolder> for WebGL2RenderingCont
let size = Size2D::new(width, height);
let (alpha_treatment, y_axis_treatment) = self.base.get_current_unpack_state(false);
let (alpha_treatment, y_axis_treatment) =
self.base.get_current_unpack_state(Alpha::NotPremultiplied);
self.base.tex_image_2d(
&texture,