Bug 1509271 - Ensure that `UpdateRootFrameMetrics` is called even if the GeckoView embedding app is not using the `AndroidDynamicToolbarAnimator`. r=kats
authorEmily Toop <etoop@mozilla.com>
Tue, 08 Jan 2019 18:04:16 +0000
changeset 510127 0d74f8dc47e858d1f2c4de93c0324003a1405060
parent 510126 5b5648fde79119e3d4f9dc68b1bbc3714dd1e8a2
child 510128 00b712b8f2833be2aa40b574a1ff6c573f2e188d
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1509271
milestone66.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 1509271 - Ensure that `UpdateRootFrameMetrics` is called even if the GeckoView embedding app is not using the `AndroidDynamicToolbarAnimator`. r=kats 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
@@ -999,16 +999,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);