Bug 1509271 - Ensure that `UpdateRootFrameMetrics` is called even if the GeckoView embedding app is not using the `AndroidDynamicToolbarAnimator`. r=kats, a=RyanVM
authorEmily Toop <etoop@mozilla.com>
Tue, 08 Jan 2019 18:04:16 +0000
changeset 506651 9a0b078546bd21aabdc056dfb6a08e8594565d88
parent 506650 35180dd24536b073adc5fb42946a80c556f6a5d0
child 506652 694ef5b65db8c5e3570e6e1a9bee47608b4d3ba9
push id10499
push userryanvm@gmail.com
push dateSat, 12 Jan 2019 20:11:30 +0000
treeherdermozilla-beta@da0b07a8386c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats, RyanVM
bugs1509271
milestone65.0
Bug 1509271 - Ensure that `UpdateRootFrameMetrics` is called even if the GeckoView embedding app is not using the `AndroidDynamicToolbarAnimator`. r=kats, a=RyanVM When selected text in `geckoview_example`, the text selection toolbar was always positioned in the top left corner of the screen, regardless of where in the page the text was selected. The cause of the bug was that UpdateRootFrameMetrics was being called only if the app utilised the `AndroidDynamicToolbar`. This caused the `mViewportZoom` value inside `GeckoSession` to always be 0. When using the `clientToFrameMatrix` function to place the text selection toolbar on screen, the generated matrix was incorrect as the zoom value was 0, causing the resulting frame to be offset by the zoom value. By ensuring that `UpdateRootFrameMetrics` is called inside `AsyncCompositionManager`even when there is no `AndroidDynamicToolbarAnimator` this zoom value is correctly set and the resulting frame for the text selection toolbar is correctly placed. Differential Revision: https://phabricator.services.mozilla.com/D15941
gfx/layers/composite/AsyncCompositionManager.cpp
gfx/layers/ipc/UiCompositorControllerParent.cpp
gfx/layers/ipc/UiCompositorControllerParent.h
--- a/gfx/layers/composite/AsyncCompositionManager.cpp
+++ b/gfx/layers/composite/AsyncCompositionManager.cpp
@@ -992,16 +992,19 @@ bool AsyncCompositionManager::ApplyAsync
                     if (animator) {
                       animator->UpdateRootFrameMetrics(metrics);
                       animator->FirstPaint();
                     }
                     LayersId rootLayerTreeId = bridge->RootLayerTreeId();
                     if (RefPtr<UiCompositorControllerParent> uiController =
                             UiCompositorControllerParent::
                                 GetFromRootLayerTreeId(rootLayerTreeId)) {
+                      if (!animator) {
+                        uiController->NotifyUpdateScreenMetrics(metrics);
+                      }
                       uiController->NotifyFirstPaint();
                     }
                     mIsFirstPaint = false;
                   }
                   if (mLayersUpdated) {
                     LayersId rootLayerTreeId = bridge->RootLayerTreeId();
                     if (RefPtr<UiCompositorControllerParent> uiController =
                             UiCompositorControllerParent::
--- a/gfx/layers/ipc/UiCompositorControllerParent.cpp
+++ b/gfx/layers/ipc/UiCompositorControllerParent.cpp
@@ -11,16 +11,18 @@
 #include "mozilla/layers/Compositor.h"
 #include "mozilla/layers/CompositorBridgeParent.h"
 #include "mozilla/layers/CompositorThread.h"
 #include "mozilla/layers/LayerManagerComposite.h"
 #include "mozilla/gfx/Types.h"
 #include "mozilla/Move.h"
 #include "mozilla/Unused.h"
 
+#include "FrameMetrics.h"
+
 namespace mozilla {
 namespace layers {
 
 typedef CompositorBridgeParent::LayerTreeState LayerTreeState;
 
 /* static */ RefPtr<UiCompositorControllerParent>
 UiCompositorControllerParent::GetFromRootLayerTreeId(
     const LayersId& aRootLayerTreeId) {
@@ -235,16 +237,31 @@ void UiCompositorControllerParent::Notif
   }
 #endif
 }
 
 void UiCompositorControllerParent::NotifyFirstPaint() {
   ToolbarAnimatorMessageFromCompositor(FIRST_PAINT);
 }
 
+void UiCompositorControllerParent::NotifyUpdateScreenMetrics(
+    const FrameMetrics& aMetrics) {
+#if defined(MOZ_WIDGET_ANDROID)
+  CSSToScreenScale scale = ViewTargetAs<ScreenPixel>(
+      aMetrics.GetZoom().ToScaleFactor(),
+      PixelCastJustification::ScreenIsParentLayerForRoot);
+  ScreenPoint scrollOffset = aMetrics.GetScrollOffset() * scale;
+  CompositorThreadHolder::Loop()->PostTask(
+      NewRunnableMethod<ScreenPoint, CSSToScreenScale>(
+          "UiCompositorControllerParent::SendRootFrameMetrics", this,
+          &UiCompositorControllerParent::SendRootFrameMetrics, scrollOffset,
+          scale));
+#endif
+}
+
 UiCompositorControllerParent::UiCompositorControllerParent(
     const LayersId& aRootLayerTreeId)
     : mRootLayerTreeId(aRootLayerTreeId)
 #ifdef MOZ_WIDGET_ANDROID
       ,
       mCompositorLayersUpdateEnabled(false)
 #endif
       ,
--- a/gfx/layers/ipc/UiCompositorControllerParent.h
+++ b/gfx/layers/ipc/UiCompositorControllerParent.h
@@ -11,16 +11,18 @@
 #include "mozilla/layers/AndroidDynamicToolbarAnimator.h"
 #endif  // defined(MOZ_WIDGET_ANDROID)
 #include "mozilla/ipc/Shmem.h"
 #include "mozilla/RefPtr.h"
 
 namespace mozilla {
 namespace layers {
 
+struct FrameMetrics;
+
 class UiCompositorControllerParent final
     : public PUiCompositorControllerParent {
   // UiCompositorControllerChild needs to call the private constructor when
   // running in process.
   friend class UiCompositorControllerChild;
 
  public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(UiCompositorControllerParent)
@@ -61,16 +63,17 @@ class UiCompositorControllerParent final
 #endif  // MOZ_WIDGET_ANDROID
   void ToolbarAnimatorMessageFromCompositor(int32_t aMessage);
   bool AllocPixelBuffer(const int32_t aSize, Shmem* aMem);
 
   // Called when a layer has been updated so the UI thread may be notified if
   // necessary.
   void NotifyLayersUpdated();
   void NotifyFirstPaint();
+  void NotifyUpdateScreenMetrics(const FrameMetrics& aMetrics);
 
  private:
   explicit UiCompositorControllerParent(const LayersId& aRootLayerTreeId);
   ~UiCompositorControllerParent();
   void InitializeForSameProcess();
   void InitializeForOutOfProcess();
   void Initialize();
   void Open(Endpoint<PUiCompositorControllerParent>&& aEndpoint);