Skip to content

Commit ea4701c

Browse files
authored
Auto merge of servo#29938 - mrobinson:remove-domtotexture, r=jdm
Remove the DOMToTexture feature This relies on WebRender's frame output API, `set_output_image_handler`, which has been removed from the latest upstream [1]. It's sad to remove this feature, which was probably a lot of work to implement, but it seems difficult to patch WebRender to restore this functionality. Fixes servo#29936. 1. https://hg.mozilla.org/mozilla-central/rev/361521e3c52324809553c555fb066d50f023d9bf <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix servo#29936. - [x] These changes do not require tests because they remove functionality. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
2 parents 1ca74a3 + ec3b282 commit ea4701c

File tree

10 files changed

+33
-301
lines changed

10 files changed

+33
-301
lines changed

Cargo.lock

Lines changed: 26 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/canvas/webgl_mode/inprocess.rs

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ use canvas_traits::webgl::webgl_channel;
77
use canvas_traits::webgl::{WebGLContextId, WebGLMsg, WebGLThreads};
88
use euclid::default::Size2D;
99
use fnv::FnvHashMap;
10-
use gleam;
11-
use servo_config::pref;
12-
use sparkle::gl;
1310
use sparkle::gl::GlType;
1411
use std::default::Default;
15-
use std::rc::Rc;
1612
use std::sync::{Arc, Mutex};
1713
use surfman::Device;
1814
use surfman::SurfaceInfo;
@@ -30,15 +26,13 @@ use webxr_api::LayerGrandManager as WebXRLayerGrandManager;
3026
pub struct WebGLComm {
3127
pub webgl_threads: WebGLThreads,
3228
pub image_handler: Box<dyn WebrenderExternalImageApi>,
33-
pub output_handler: Option<Box<dyn webrender_api::OutputImageHandler>>,
3429
pub webxr_layer_grand_manager: WebXRLayerGrandManager<WebXRSurfman>,
3530
}
3631

3732
impl WebGLComm {
3833
/// Creates a new `WebGLComm` object.
3934
pub fn new(
4035
surfman: WebrenderSurfman,
41-
webrender_gl: Rc<dyn gleam::gl::Gl>,
4236
webrender_api_sender: webrender_api::RenderApiSender,
4337
webrender_doc: webrender_api::DocumentId,
4438
external_images: Arc<Mutex<WebrenderExternalImageRegistry>>,
@@ -64,20 +58,13 @@ impl WebGLComm {
6458
webxr_init,
6559
};
6660

67-
let output_handler = if pref!(dom.webgl.dom_to_texture.enabled) {
68-
Some(Box::new(OutputHandler::new(webrender_gl.clone())))
69-
} else {
70-
None
71-
};
72-
7361
let external = WebGLExternalImages::new(surfman, webrender_swap_chains);
7462

7563
WebGLThread::run_on_own_thread(init);
7664

7765
WebGLComm {
7866
webgl_threads: WebGLThreads(sender),
7967
image_handler: Box::new(external),
80-
output_handler: output_handler.map(|b| b as Box<_>),
8168
webxr_layer_grand_manager: webxr_layer_grand_manager,
8269
}
8370
}
@@ -144,43 +131,3 @@ impl WebrenderExternalImageApi for WebGLExternalImages {
144131
self.unlock_swap_chain(id);
145132
}
146133
}
147-
148-
/// struct used to implement DOMToTexture feature and webrender::OutputImageHandler trait.
149-
struct OutputHandler {
150-
webrender_gl: Rc<dyn gleam::gl::Gl>,
151-
sync_objects: FnvHashMap<webrender_api::PipelineId, gleam::gl::GLsync>,
152-
}
153-
154-
impl OutputHandler {
155-
fn new(webrender_gl: Rc<dyn gleam::gl::Gl>) -> Self {
156-
OutputHandler {
157-
webrender_gl,
158-
sync_objects: Default::default(),
159-
}
160-
}
161-
}
162-
163-
/// Bridge between the WR frame outputs and WebGL to implement DOMToTexture synchronization.
164-
impl webrender_api::OutputImageHandler for OutputHandler {
165-
fn lock(
166-
&mut self,
167-
id: webrender_api::PipelineId,
168-
) -> Option<(u32, webrender_api::units::FramebufferIntSize)> {
169-
// Insert a fence in the WR command queue
170-
let gl_sync = self
171-
.webrender_gl
172-
.fence_sync(gl::SYNC_GPU_COMMANDS_COMPLETE, 0);
173-
self.sync_objects.insert(id, gl_sync);
174-
// https://github.com/servo/servo/issues/24615
175-
None
176-
}
177-
178-
fn unlock(&mut self, id: webrender_api::PipelineId) {
179-
if let Some(gl_sync) = self.sync_objects.remove(&id) {
180-
// Flush the Sync object into the GPU's command queue to guarantee that it it's signaled.
181-
self.webrender_gl.flush();
182-
// Mark the sync object for deletion.
183-
self.webrender_gl.delete_sync(gl_sync);
184-
}
185-
}
186-
}

components/canvas/webgl_thread.rs

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use canvas_traits::webgl::ActiveAttribInfo;
1010
use canvas_traits::webgl::ActiveUniformBlockInfo;
1111
use canvas_traits::webgl::ActiveUniformInfo;
1212
use canvas_traits::webgl::AlphaTreatment;
13-
use canvas_traits::webgl::DOMToTextureCommand;
1413
use canvas_traits::webgl::GLContextAttributes;
1514
use canvas_traits::webgl::GLLimits;
1615
use canvas_traits::webgl::GlType;
@@ -239,8 +238,6 @@ pub(crate) struct WebGLThread {
239238
cached_context_info: FnvHashMap<WebGLContextId, WebGLContextInfo>,
240239
/// Current bound context.
241240
bound_context_id: Option<WebGLContextId>,
242-
/// Texture ids and sizes used in DOM to texture outputs.
243-
dom_outputs: FnvHashMap<webrender_api::PipelineId, DOMToTextureData>,
244241
/// List of registered webrender external images.
245242
/// We use it to get an unique ID for new WebGLContexts.
246243
external_images: Arc<Mutex<WebrenderExternalImageRegistry>>,
@@ -298,7 +295,6 @@ impl WebGLThread {
298295
contexts: Default::default(),
299296
cached_context_info: Default::default(),
300297
bound_context_id: None,
301-
dom_outputs: Default::default(),
302298
external_images,
303299
sender,
304300
receiver: receiver.into_inner(),
@@ -410,9 +406,6 @@ impl WebGLThread {
410406
WebGLMsg::SwapBuffers(swap_ids, sender, sent_time) => {
411407
self.handle_swap_buffers(swap_ids, sender, sent_time);
412408
},
413-
WebGLMsg::DOMToTextureCommand(command) => {
414-
self.handle_dom_to_texture(command);
415-
},
416409
WebGLMsg::Exit => {
417410
return true;
418411
},
@@ -890,88 +883,6 @@ impl WebGLThread {
890883
SurfaceAccess::GPUOnly
891884
}
892885

893-
fn handle_dom_to_texture(&mut self, command: DOMToTextureCommand) {
894-
match command {
895-
DOMToTextureCommand::Attach(context_id, texture_id, document_id, pipeline_id, size) => {
896-
let data = Self::make_current_if_needed(
897-
&self.device,
898-
context_id,
899-
&self.contexts,
900-
&mut self.bound_context_id,
901-
)
902-
.expect("WebGLContext not found in a WebGL DOMToTextureCommand::Attach command");
903-
// Initialize the texture that WR will use for frame outputs.
904-
data.gl.tex_image_2d(
905-
gl::TEXTURE_2D,
906-
0,
907-
gl::RGBA as gl::GLint,
908-
size.width,
909-
size.height,
910-
0,
911-
gl::RGBA,
912-
gl::UNSIGNED_BYTE,
913-
gl::TexImageSource::Pixels(None),
914-
);
915-
self.dom_outputs.insert(
916-
pipeline_id,
917-
DOMToTextureData {
918-
context_id,
919-
texture_id,
920-
document_id,
921-
size,
922-
},
923-
);
924-
let mut txn = webrender_api::Transaction::new();
925-
txn.enable_frame_output(pipeline_id, true);
926-
self.webrender_api.send_transaction(document_id, txn);
927-
},
928-
DOMToTextureCommand::Lock(pipeline_id, gl_sync, sender) => {
929-
let result = self.handle_dom_to_texture_lock(pipeline_id, gl_sync);
930-
// Send the texture id and size to WR.
931-
sender.send(result).unwrap();
932-
},
933-
DOMToTextureCommand::Detach(texture_id) => {
934-
if let Some((pipeline_id, document_id)) = self
935-
.dom_outputs
936-
.iter()
937-
.find(|&(_, v)| v.texture_id == texture_id)
938-
.map(|(k, v)| (*k, v.document_id))
939-
{
940-
let mut txn = webrender_api::Transaction::new();
941-
txn.enable_frame_output(pipeline_id, false);
942-
self.webrender_api.send_transaction(document_id, txn);
943-
self.dom_outputs.remove(&pipeline_id);
944-
}
945-
},
946-
}
947-
}
948-
949-
pub(crate) fn handle_dom_to_texture_lock(
950-
&mut self,
951-
pipeline_id: webrender_api::PipelineId,
952-
gl_sync: usize,
953-
) -> Option<(u32, Size2D<i32>)> {
954-
let device = &self.device;
955-
let contexts = &self.contexts;
956-
let bound_context_id = &mut self.bound_context_id;
957-
self.dom_outputs.get(&pipeline_id).and_then(|dom_data| {
958-
let data = Self::make_current_if_needed(
959-
device,
960-
dom_data.context_id,
961-
contexts,
962-
bound_context_id,
963-
);
964-
data.and_then(|data| {
965-
// The next glWaitSync call is used to synchronize the two flows of
966-
// OpenGL commands (WR and WebGL) in order to avoid using semi-ready WR textures.
967-
// glWaitSync doesn't block WebGL CPU thread.
968-
data.gl
969-
.wait_sync(gl_sync as gl::GLsync, 0, gl::TIMEOUT_IGNORED);
970-
Some((dom_data.texture_id.get(), dom_data.size))
971-
})
972-
})
973-
}
974-
975886
/// Gets a reference to a Context for a given WebGLContextId and makes it current if required.
976887
fn make_current_if_needed<'a>(
977888
device: &Device,
@@ -1106,14 +1017,6 @@ fn current_wr_texture_target(device: &Device) -> webrender_api::TextureTarget {
11061017
}
11071018
}
11081019

1109-
/// Data about the linked DOM<->WebGLTexture elements.
1110-
struct DOMToTextureData {
1111-
context_id: WebGLContextId,
1112-
texture_id: WebGLTextureId,
1113-
document_id: webrender_api::DocumentId,
1114-
size: Size2D<i32>,
1115-
}
1116-
11171020
/// WebGL Commands Implementation
11181021
pub struct WebGLImpl;
11191022

0 commit comments

Comments
 (0)