servo: Merge #11750 - canvas: Deallocate WebRender images on canvas (from emilio:canvas-leaks); r=glennw
authorEmilio Cobos Álvarez <me@emiliocobos.me>
Sun, 10 Jul 2016 20:09:48 -0700
changeset 339260 dc704a5b6f360f16601ed4e43a4aafc811380e36
parent 339259 491fa0189d2f2fdc3c7adebcd33ad34b7a1e03c4
child 339261 219897364e938a9fff090c792d8c214020aac0fd
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglennw
servo: Merge #11750 - canvas: Deallocate WebRender images on canvas (from emilio:canvas-leaks); r=glennw canvas: Deallocate WebRender images on canvas <!-- 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 #11062. - [x] These changes do not require tests because it's wr-only. <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> r? @glennw Source-Repo: https://github.com/servo/servo Source-Revision: 1ff8d875dddb81c2697e155cc954d106c5433055
servo/components/canvas/canvas_paint_thread.rs
servo/components/canvas/webgl_paint_thread.rs
--- a/servo/components/canvas/canvas_paint_thread.rs
+++ b/servo/components/canvas/canvas_paint_thread.rs
@@ -701,16 +701,24 @@ impl<'a> CanvasPaintThread<'a> {
                                                  &self.state.shadow_color,
                                                  &Point2D::new(self.state.shadow_offset_x as AzFloat,
                                                                self.state.shadow_offset_y as AzFloat),
                                                  (self.state.shadow_blur / 2.0f64) as AzFloat,
                                                  self.state.draw_options.composition);
     }
 }
 
+impl<'a> Drop for CanvasPaintThread<'a> {
+    fn drop(&mut self) {
+        if let Some(ref mut wr) = self.webrender_api {
+            wr.delete_image(self.webrender_image_key.unwrap());
+        }
+    }
+}
+
 /// Used by drawImage to get rid of the extra pixels of the image data that
 /// won't be copied to the canvas
 /// image_data: Color pixel data of the image
 /// image_size: Image dimensions
 /// crop_rect: It determines the area of the image we want to keep
 fn crop_image(image_data: Vec<u8>,
               image_size: Size2D<f64>,
               crop_rect: Rect<f64>) -> Vec<u8>{
--- a/servo/components/canvas/webgl_paint_thread.rs
+++ b/servo/components/canvas/webgl_paint_thread.rs
@@ -190,8 +190,16 @@ impl WebGLPaintThread {
     }
 
     fn init(&mut self) {
         if let WebGLPaintTaskData::Readback(ref context, _) = self.data {
             context.make_current().unwrap();
         }
     }
 }
+
+impl Drop for WebGLPaintThread {
+    fn drop(&mut self) {
+        if let WebGLPaintTaskData::Readback(_, Some((ref mut wr, image_key))) = self.data {
+            wr.delete_image(image_key);
+        }
+    }
+}