Bug 1507333 - Route WebRender pref changes through the RenderBackend. r=jrmuizel
authorBobby Holley <bobbyholley@gmail.com>
Wed, 14 Nov 2018 15:10:57 -0800
changeset 503522 73e025041c50a4ccc3078dd97971d119269f3e0e
parent 503521 f949c4870f0267c86506199a8bbcedda82129c54
child 503523 def3a4c1f23be5a622cf2ec132cc8c385ce4b60e
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1507333
milestone65.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 1507333 - Route WebRender pref changes through the RenderBackend. r=jrmuizel The overlap between debug flags and debug commands is a bit of a mess, and this patch does not entirely clean it up. But this at least means that the RenderBackend can react to pref changes in Firefox. Differential Revision: https://phabricator.services.mozilla.com/D11958
gfx/webrender_bindings/RendererOGL.cpp
gfx/webrender_bindings/RendererOGL.h
gfx/webrender_bindings/WebRenderAPI.cpp
gfx/webrender_bindings/WebRenderAPI.h
gfx/webrender_bindings/src/bindings.rs
gfx/webrender_bindings/webrender_ffi_generated.h
--- a/gfx/webrender_bindings/RendererOGL.cpp
+++ b/gfx/webrender_bindings/RendererOGL.cpp
@@ -51,17 +51,16 @@ RendererOGL::RendererOGL(RefPtr<RenderTh
                          wr::WindowId aWindowId,
                          wr::Renderer* aRenderer,
                          layers::CompositorBridgeParent* aBridge)
   : mThread(aThread)
   , mCompositor(std::move(aCompositor))
   , mRenderer(aRenderer)
   , mBridge(aBridge)
   , mWindowId(aWindowId)
-  , mDebugFlags({ 0 })
 {
   MOZ_ASSERT(mThread);
   MOZ_ASSERT(mCompositor);
   MOZ_ASSERT(mRenderer);
   MOZ_ASSERT(mBridge);
   MOZ_COUNT_CTOR(RendererOGL);
 }
 
@@ -84,22 +83,16 @@ RendererOGL::GetExternalImageHandler()
     LockExternalImage,
     UnlockExternalImage,
   };
 }
 
 void
 RendererOGL::Update()
 {
-  uint32_t flags = gfx::gfxVars::WebRenderDebugFlags();
-  if (mDebugFlags.mBits != flags) {
-    mDebugFlags.mBits = flags;
-    wr_renderer_set_debug_flags(mRenderer, mDebugFlags);
-  }
-
   if (mCompositor->MakeCurrent()) {
     wr_renderer_update(mRenderer);
   }
 }
 
 static void
 DoNotifyWebRenderContextPurge(layers::CompositorBridgeParent* aBridge)
 {
@@ -107,27 +100,16 @@ DoNotifyWebRenderContextPurge(layers::Co
 }
 
 bool
 RendererOGL::UpdateAndRender(const Maybe<gfx::IntSize>& aReadbackSize,
                              const Maybe<Range<uint8_t>>& aReadbackBuffer,
                              bool aHadSlowFrame,
                              RendererStats* aOutStats)
 {
-  uint32_t flags = gfx::gfxVars::WebRenderDebugFlags();
-  // Disable debug flags during readback
-  if (aReadbackBuffer.isSome()) {
-    flags = 0;
-  }
-
-  if (mDebugFlags.mBits != flags) {
-    mDebugFlags.mBits = flags;
-    wr_renderer_set_debug_flags(mRenderer, mDebugFlags);
-  }
-
   mozilla::widget::WidgetRenderingContext widgetContext;
 
 #if defined(XP_MACOSX)
   widgetContext.mGL = mCompositor->gl();
 // TODO: we don't have a notion of compositor here.
 //#elif defined(MOZ_WIDGET_ANDROID)
 //  widgetContext.mCompositor = mCompositor;
 #endif
--- a/gfx/webrender_bindings/RendererOGL.h
+++ b/gfx/webrender_bindings/RendererOGL.h
@@ -108,15 +108,14 @@ protected:
   void NotifyWebRenderError(WebRenderError aError);
 
   RefPtr<RenderThread> mThread;
   UniquePtr<RenderCompositor> mCompositor;
   wr::Renderer* mRenderer;
   layers::CompositorBridgeParent* mBridge;
   wr::WindowId mWindowId;
   TimeStamp mFrameStartTime;
-  wr::DebugFlags mDebugFlags;
 };
 
 } // namespace wr
 } // namespace mozilla
 
 #endif
--- a/gfx/webrender_bindings/WebRenderAPI.cpp
+++ b/gfx/webrender_bindings/WebRenderAPI.cpp
@@ -376,18 +376,28 @@ WebRenderAPI::~WebRenderAPI()
 
     wr_api_shut_down(mDocHandle);
   }
 
   wr_api_delete(mDocHandle);
 }
 
 void
+WebRenderAPI::UpdateDebugFlags(uint32_t aFlags)
+{
+  if (mDebugFlags.mBits != aFlags) {
+    mDebugFlags.mBits = aFlags;
+    wr_api_set_debug_flags(mDocHandle, mDebugFlags);
+  }
+}
+
+void
 WebRenderAPI::SendTransaction(TransactionBuilder& aTxn)
 {
+  UpdateDebugFlags(gfx::gfxVars::WebRenderDebugFlags());
   wr_api_send_transaction(mDocHandle, aTxn.Raw(), aTxn.UseSceneBuilderThread());
 }
 
 bool
 WebRenderAPI::HitTest(const wr::WorldPoint& aPoint,
                       wr::WrPipelineId& aOutPipelineId,
                       layers::ScrollableLayerGuid::ViewID& aOutScrollId,
                       gfx::CompositorHitTestInfo& aOutHitInfo)
@@ -436,25 +446,30 @@ WebRenderAPI::Readback(const TimeStamp& 
             }
 
             layers::SynchronousTask* mTask;
             TimeStamp mStartTime;
             gfx::IntSize mSize;
             const Range<uint8_t>& mBuffer;
     };
 
+    // Disable debug flags during readback. See bug 1436020.
+    UpdateDebugFlags(0);
+
     layers::SynchronousTask task("Readback");
     auto event = MakeUnique<Readback>(&task, aStartTime, size, buffer);
     // This event will be passed from wr_backend thread to renderer thread. That
     // implies that all frame data have been processed when the renderer runs this
     // read-back event. Then, we could make sure this read-back event gets the
     // latest result.
     RunOnRenderThread(std::move(event));
 
     task.Wait();
+
+    UpdateDebugFlags(gfx::gfxVars::WebRenderDebugFlags());
 }
 
 void
 WebRenderAPI::ClearAllCaches()
 {
   wr_api_clear_all_caches(mDocHandle);
 }
 
--- a/gfx/webrender_bindings/WebRenderAPI.h
+++ b/gfx/webrender_bindings/WebRenderAPI.h
@@ -241,29 +241,33 @@ protected:
   WebRenderAPI(wr::DocumentHandle* aHandle, wr::WindowId aId, int32_t aMaxTextureSize, bool aUseANGLE, bool aUseDComp, bool aUseTripleBuffering, layers::SyncHandle aSyncHandle)
     : mDocHandle(aHandle)
     , mId(aId)
     , mMaxTextureSize(aMaxTextureSize)
     , mUseANGLE(aUseANGLE)
     , mUseDComp(aUseDComp)
     , mUseTripleBuffering(aUseTripleBuffering)
     , mSyncHandle(aSyncHandle)
+    , mDebugFlags({ 0 })
   {}
 
   ~WebRenderAPI();
   // Should be used only for shutdown handling
   void WaitFlushed();
 
+  void UpdateDebugFlags(uint32_t aFlags);
+
   wr::DocumentHandle* mDocHandle;
   wr::WindowId mId;
   int32_t mMaxTextureSize;
   bool mUseANGLE;
   bool mUseDComp;
   bool mUseTripleBuffering;
   layers::SyncHandle mSyncHandle;
+  wr::DebugFlags mDebugFlags;
 
   // We maintain alive the root api to know when to shut the render backend down,
   // and the root api for the document to know when to delete the document.
   // mRootApi is null for the api object that owns the channel (and is responsible
   // for shutting it down), and mRootDocumentApi is null for the api object owning
   // (and responsible for destroying) a given document.
   // All api objects in the same window use the same channel, and some api objects
   // write to the same document (but there is only one owner for each channel and
--- a/gfx/webrender_bindings/src/bindings.rs
+++ b/gfx/webrender_bindings/src/bindings.rs
@@ -644,34 +644,16 @@ pub unsafe extern "C" fn wr_renderer_rea
     let mut slice = make_slice_mut(dst_buffer, buffer_size);
     renderer.read_pixels_into(DeviceIntRect::new(
                                 DeviceIntPoint::new(0, 0),
                                 DeviceIntSize::new(width, height)),
                               ReadPixelsFormat::Standard(ImageFormat::BGRA8),
                               &mut slice);
 }
 
-/// cbindgen:field-names=[mBits]
-#[repr(C)]
-pub struct WrDebugFlags {
-    bits: u32,
-}
-
-#[no_mangle]
-pub extern "C" fn wr_renderer_get_debug_flags(renderer: &mut Renderer) -> WrDebugFlags {
-    WrDebugFlags { bits: renderer.get_debug_flags().bits() }
-}
-
-#[no_mangle]
-pub extern "C" fn wr_renderer_set_debug_flags(renderer: &mut Renderer, flags: WrDebugFlags) {
-    if let Some(dbg_flags) = DebugFlags::from_bits(flags.bits) {
-        renderer.set_debug_flags(dbg_flags);
-    }
-}
-
 #[no_mangle]
 pub extern "C" fn wr_renderer_current_epoch(renderer: &mut Renderer,
                                             pipeline_id: WrPipelineId,
                                             out_epoch: &mut WrEpoch)
                                             -> bool {
     if let Some(epoch) = renderer.current_epoch(pipeline_id) {
         *out_epoch = epoch;
         return true;
@@ -1171,16 +1153,29 @@ pub unsafe extern "C" fn wr_api_shut_dow
     dh.api.shut_down();
 }
 
 #[no_mangle]
 pub unsafe extern "C" fn wr_api_notify_memory_pressure(dh: &mut DocumentHandle) {
     dh.api.notify_memory_pressure();
 }
 
+/// cbindgen:field-names=[mBits]
+#[repr(C)]
+pub struct WrDebugFlags {
+    bits: u32,
+}
+
+#[no_mangle]
+pub extern "C" fn wr_api_set_debug_flags(dh: &mut DocumentHandle, flags: WrDebugFlags) {
+    if let Some(dbg_flags) = DebugFlags::from_bits(flags.bits) {
+        dh.api.set_debug_flags(dbg_flags);
+    }
+}
+
 #[no_mangle]
 pub unsafe extern "C" fn wr_api_accumulate_memory_report(
     dh: &mut DocumentHandle,
     report: &mut MemoryReport
 ) {
     *report += dh.api.report_memory();
 }
 
--- a/gfx/webrender_bindings/webrender_ffi_generated.h
+++ b/gfx/webrender_bindings/webrender_ffi_generated.h
@@ -629,16 +629,24 @@ struct TypedPoint2D {
   bool operator==(const TypedPoint2D& aOther) const {
     return x == aOther.x &&
            y == aOther.y;
   }
 };
 
 using WorldPoint = TypedPoint2D<float, WorldPixel>;
 
+struct WrDebugFlags {
+  uint32_t mBits;
+
+  bool operator==(const WrDebugFlags& aOther) const {
+    return mBits == aOther.mBits;
+  }
+};
+
 // A 2d Rectangle optionally tagged with a unit.
 template<typename T, typename U>
 struct TypedRect {
   TypedPoint2D<T, U> origin;
   TypedSize2D<T, U> size;
 
   bool operator==(const TypedRect& aOther) const {
     return origin == aOther.origin &&
@@ -988,24 +996,16 @@ struct MutByteSlice {
   uintptr_t len;
 
   bool operator==(const MutByteSlice& aOther) const {
     return buffer == aOther.buffer &&
            len == aOther.len;
   }
 };
 
-struct WrDebugFlags {
-  uint32_t mBits;
-
-  bool operator==(const WrDebugFlags& aOther) const {
-    return mBits == aOther.mBits;
-  }
-};
-
 struct RendererStats {
   uintptr_t total_draw_calls;
   uintptr_t alpha_target_count;
   uintptr_t color_target_count;
   uintptr_t texture_upload_kb;
   uint64_t resource_upload_time;
   uint64_t gpu_cache_upload_time;
 
@@ -1258,16 +1258,21 @@ WR_DESTRUCTOR_SAFE_FUNC;
 
 WR_INLINE
 void wr_api_send_transaction(DocumentHandle *aDh,
                              Transaction *aTransaction,
                              bool aIsAsync)
 WR_FUNC;
 
 WR_INLINE
+void wr_api_set_debug_flags(DocumentHandle *aDh,
+                            WrDebugFlags aFlags)
+WR_FUNC;
+
+WR_INLINE
 void wr_api_shut_down(DocumentHandle *aDh)
 WR_DESTRUCTOR_SAFE_FUNC;
 
 WR_INLINE
 void wr_api_wake_scene_builder(DocumentHandle *aDh)
 WR_FUNC;
 
 WR_INLINE
@@ -1646,41 +1651,32 @@ WR_INLINE
 void wr_renderer_delete(Renderer *aRenderer)
 WR_DESTRUCTOR_SAFE_FUNC;
 
 WR_INLINE
 WrPipelineInfo wr_renderer_flush_pipeline_info(Renderer *aRenderer)
 WR_FUNC;
 
 WR_INLINE
-WrDebugFlags wr_renderer_get_debug_flags(Renderer *aRenderer)
-WR_FUNC;
-
-WR_INLINE
 void wr_renderer_readback(Renderer *aRenderer,
                           int32_t aWidth,
                           int32_t aHeight,
                           uint8_t *aDstBuffer,
                           uintptr_t aBufferSize)
 WR_FUNC;
 
 WR_INLINE
 bool wr_renderer_render(Renderer *aRenderer,
                         int32_t aWidth,
                         int32_t aHeight,
                         bool aHadSlowFrame,
                         RendererStats *aOutStats)
 WR_FUNC;
 
 WR_INLINE
-void wr_renderer_set_debug_flags(Renderer *aRenderer,
-                                 WrDebugFlags aFlags)
-WR_FUNC;
-
-WR_INLINE
 void wr_renderer_set_external_image_handler(Renderer *aRenderer,
                                             WrExternalImageHandler *aExternalImageHandler)
 WR_FUNC;
 
 WR_INLINE
 void wr_renderer_update(Renderer *aRenderer)
 WR_FUNC;