Bug 1444434 - Free the Gecko profiler screenshots structures in the WebRender renderer when profiling stops r=kvark
☠☠ backed out by 9ac40c5bc008 ☠ ☠
authorBarret Rennie <barret@brennie.ca>
Thu, 21 Mar 2019 19:30:34 +0000
changeset 466228 13c0d857bf3c7cb5b21f25e2c35e1f2f3a57a4e2
parent 466227 d2c85db549ea25fb84c832df0a9654d084779736
child 466229 0808c449b0156fc7adbdddba77f4a1d2eff11040
push id35762
push usercsabou@mozilla.com
push dateWed, 27 Mar 2019 04:44:00 +0000
treeherdermozilla-central@bc572aee49b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskvark
bugs1444434
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1444434 - Free the Gecko profiler screenshots structures in the WebRender renderer when profiling stops r=kvark Differential Revision: https://phabricator.services.mozilla.com/D23964
gfx/webrender_bindings/RendererScreenshotGrabber.cpp
gfx/webrender_bindings/RendererScreenshotGrabber.h
gfx/webrender_bindings/src/bindings.rs
gfx/wr/webrender/src/renderer.rs
--- a/gfx/webrender_bindings/RendererScreenshotGrabber.cpp
+++ b/gfx/webrender_bindings/RendererScreenshotGrabber.cpp
@@ -13,36 +13,38 @@ void RendererScreenshotGrabber::MaybeGra
     Renderer* aRenderer, const gfx::IntSize& aWindowSize) {
   if (ProfilerScreenshots::IsEnabled()) {
     if (!mProfilerScreenshots) {
       mProfilerScreenshots = MakeUnique<ProfilerScreenshots>();
     }
 
     GrabScreenshot(aRenderer, aWindowSize);
   } else if (mProfilerScreenshots) {
-    Destroy();
+    Destroy(aRenderer);
   }
 }
 
 void RendererScreenshotGrabber::MaybeProcessQueue(Renderer* aRenderer) {
   if (ProfilerScreenshots::IsEnabled()) {
     if (!mProfilerScreenshots) {
       mProfilerScreenshots = MakeUnique<ProfilerScreenshots>();
     }
 
     ProcessQueue(aRenderer);
   } else if (mProfilerScreenshots) {
-    Destroy();
+    Destroy(aRenderer);
   }
 }
 
-void RendererScreenshotGrabber::Destroy() {
+void RendererScreenshotGrabber::Destroy(Renderer* aRenderer) {
   mQueue.Clear();
   mCurrentFrameQueueItem = Nothing();
   mProfilerScreenshots = nullptr;
+
+  wr_renderer_release_profiler_structures(aRenderer);
 }
 
 void RendererScreenshotGrabber::GrabScreenshot(
     Renderer* aRenderer, const gfx::IntSize& aWindowSize) {
   gfx::IntSize screenshotSize;
 
   AsyncScreenshotHandle handle = wr_renderer_get_screenshot_async(
       aRenderer, 0, 0, aWindowSize.width, aWindowSize.height,
--- a/gfx/webrender_bindings/RendererScreenshotGrabber.h
+++ b/gfx/webrender_bindings/RendererScreenshotGrabber.h
@@ -39,18 +39,21 @@ class RendererScreenshotGrabber final {
    * Process the screenshots pending in the queue if we are profiling and
    * screenshots are enabled.
    */
   void MaybeProcessQueue(Renderer* aRenderer);
 
  private:
   /**
    * Drop all our allocated memory when we are no longer profiling.
+   *
+   * This will also instruct WebRender to drop all its Gecko profiler
+   * associated memory.
    */
-  void Destroy();
+  void Destroy(Renderer* aRenderer);
 
   /**
    * Actually grab a screenshot from WebRender.
    */
   void GrabScreenshot(Renderer* aRenderer, const gfx::IntSize& aWindowSize);
 
   /**
    * Process the screenshots pending in the queue.
--- a/gfx/webrender_bindings/src/bindings.rs
+++ b/gfx/webrender_bindings/src/bindings.rs
@@ -710,16 +710,21 @@ pub extern "C" fn wr_renderer_map_and_re
 ) -> bool {
     renderer.map_and_recycle_screenshot(
         handle,
         make_slice_mut(dst_buffer, dst_buffer_len),
         dst_stride,
     )
 }
 
+#[no_mangle]
+pub extern "C" fn wr_renderer_release_profiler_structures(renderer: &mut Renderer) {
+    renderer.release_profiler_structures();
+}
+
 // Call wr_renderer_render() before calling this function.
 #[no_mangle]
 pub unsafe extern "C" fn wr_renderer_readback(renderer: &mut Renderer,
                                               width: i32,
                                               height: i32,
                                               dst_buffer: *mut u8,
                                               buffer_size: usize) {
     assert!(is_in_render_thread());
--- a/gfx/wr/webrender/src/renderer.rs
+++ b/gfx/wr/webrender/src/renderer.rs
@@ -2627,16 +2627,24 @@ impl Renderer {
                 dst_buffer,
                 dst_stride,
             )
         } else {
             false
         }
     }
 
+    pub fn release_profiler_structures(&mut self) {
+        if let Some(async_screenshots) = self.async_screenshots.take() {
+            self.device.begin_frame();
+            async_screenshots.deinit(&mut self.device);
+            self.device.end_frame();
+        }
+    }
+
     #[cfg(not(feature = "debugger"))]
     fn get_screenshot_for_debugger(&mut self) -> String {
         // Avoid unused param warning.
         let _ = &self.debug_server;
         String::new()
     }
 
     #[cfg(feature = "debugger")]