canvas: Make GetImageData simple and only IPC message to obtain pixels (#38274)

Currently we had `GetImageData` and `SendPixels` to obtain pixels from
script thread. This PR unifies those into single `GetImageData` that
does not need canvas size and has optional rect (for obtaining sub
image).

Testing: Existing WPT tests

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
sagudev 2025-07-26 04:28:52 +02:00 committed by GitHub
parent 77f85f390e
commit 8b2a5fca54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 26 additions and 63 deletions

View file

@ -2,12 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use canvas_traits::canvas::{Canvas2dMsg, CanvasId, CanvasMsg, FromScriptMsg};
use canvas_traits::canvas::{Canvas2dMsg, CanvasId, CanvasMsg};
use dom_struct::dom_struct;
use euclid::default::Size2D;
use ipc_channel::ipc::IpcSender;
use ipc_channel::ipc::{self, IpcSender};
use pixels::Snapshot;
use profile_traits::ipc;
use script_bindings::inheritance::Castable;
use servo_url::ServoUrl;
use webrender_api::ImageKey;
@ -162,10 +161,9 @@ impl CanvasContext for CanvasRenderingContext2D {
return None;
}
let (sender, receiver) = ipc::channel(self.global().time_profiler_chan().clone()).unwrap();
let msg = CanvasMsg::FromScript(FromScriptMsg::SendPixels(sender), self.get_canvas_id());
self.canvas_state.get_ipc_renderer().send(msg).unwrap();
let (sender, receiver) = ipc::channel().unwrap();
self.canvas_state
.send_canvas_2d_msg(Canvas2dMsg::GetImageData(None, sender));
Some(receiver.recv().unwrap().to_owned())
}