diff options
author | George Roman <george.roman.99@gmail.com> | 2019-08-09 20:30:56 +0300 |
---|---|---|
committer | George Roman <george.roman.99@gmail.com> | 2019-08-20 00:52:46 +0300 |
commit | d3696baf27fb77d67b012a90403b6c699ca40484 (patch) | |
tree | c88883dd1e912a51c1b9a0752c1d5b8b78a96007 /components/compositing/compositor.rs | |
parent | a084997afee23bb541e89a807905ff1c815a649e (diff) | |
download | servo-d3696baf27fb77d67b012a90403b6c699ca40484.tar.gz servo-d3696baf27fb77d67b012a90403b6c699ca40484.zip |
Implement TakeElementScreenshot WebDriver command
Diffstat (limited to 'components/compositing/compositor.rs')
-rw-r--r-- | components/compositing/compositor.rs | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 7ac80ee4832..f0474363fa4 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -14,7 +14,7 @@ use crate::CompositionPipeline; use crate::SendableFrameTree; use crossbeam_channel::Sender; use embedder_traits::Cursor; -use euclid::{Point2D, Scale, Vector2D}; +use euclid::{Point2D, Rect, Scale, Vector2D}; use gfx_traits::Epoch; #[cfg(feature = "gl")] use image::{DynamicImage, ImageFormat}; @@ -442,8 +442,8 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> { self.touch_handler.on_event_processed(result); }, - (Msg::CreatePng(reply), ShutdownState::NotShuttingDown) => { - let res = self.composite_specific_target(CompositeTarget::WindowAndPng); + (Msg::CreatePng(rect, reply), ShutdownState::NotShuttingDown) => { + let res = self.composite_specific_target(CompositeTarget::WindowAndPng, rect); if let Err(ref e) = res { info!("Error retrieving PNG: {:?}", e); } @@ -1229,7 +1229,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> { pub fn composite(&mut self) { let target = self.composite_target; - match self.composite_specific_target(target) { + match self.composite_specific_target(target, None) { Ok(_) => { if self.output_file.is_some() || self.exit_after_load { println!("Shutting down the Constellation after generating an output file or exit flag specified"); @@ -1256,6 +1256,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> { fn composite_specific_target( &mut self, target: CompositeTarget, + rect: Option<Rect<f32, CSSPixel>>, ) -> Result<Option<Image>, UnableToComposite> { let size = self.embedder_coordinates.framebuffer.to_u32(); @@ -1347,6 +1348,22 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> { } } + let (x, y, width, height) = match rect { + Some(rect) => { + let rect = self.device_pixels_per_page_px().transform_rect(&rect); + + let x = rect.origin.x as i32; + // We need to convert to the bottom-left origin coordinate + // system used by OpenGL + let y = (size.height as f32 - rect.origin.y - rect.size.height) as i32; + let w = rect.size.width as u32; + let h = rect.size.height as u32; + + (x, y, w, h) + }, + None => (0, 0, size.width, size.height), + }; + let rv = match target { CompositeTarget::Window => None, #[cfg(feature = "gl")] @@ -1354,8 +1371,10 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> { let img = gl::draw_img( &*self.window.gl(), rt_info, - FramebufferUintLength::new(size.width), - FramebufferUintLength::new(size.height), + x, + y, + FramebufferUintLength::new(width), + FramebufferUintLength::new(height), ); Some(Image { width: img.width(), @@ -1378,8 +1397,10 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> { let img = gl::draw_img( gl, rt_info, - FramebufferUintLength::new(size.width), - FramebufferUintLength::new(size.height), + x, + y, + FramebufferUintLength::new(width), + FramebufferUintLength::new(height), ); let dynamic_image = DynamicImage::ImageRgb8(img); if let Err(e) = dynamic_image.write_to(&mut file, ImageFormat::PNG) |