Bug 1306083 - 1. Use AndroidCompositorWidget to access GeckoLayerClient; r=kats
authorJim Chen <nchen@mozilla.com>
Mon, 03 Oct 2016 12:26:00 -0400
changeset 359092 da5048d1f778638937d5d30b08d40b14ecbf68fc
parent 359091 1adfbab318a6de4b40e1e88751c06f5b354bb1b0
child 359093 c8bc3190f954648126d0be55e2af3b60e94fa1ef
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-beta@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1306083
milestone52.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 1306083 - 1. Use AndroidCompositorWidget to access GeckoLayerClient; r=kats Add AndroidCompositorWidget to act as the intermediary between gfx code and GeckoLayerClient, in place of AndroidBridge. AndroidCompositorWidget currently inherits from InProcessCompositorWidget, but when Android eventually supports OOP compositing, it will be made to inherit from CompositorWidget directly.
gfx/layers/composite/AsyncCompositionManager.cpp
widget/CompositorWidget.h
widget/InProcessCompositorWidget.cpp
widget/android/AndroidCompositorWidget.cpp
widget/android/AndroidCompositorWidget.h
widget/android/moz.build
widget/android/nsWindow.cpp
widget/android/nsWindow.h
--- a/gfx/layers/composite/AsyncCompositionManager.cpp
+++ b/gfx/layers/composite/AsyncCompositionManager.cpp
@@ -36,17 +36,17 @@
 #include "nsRect.h"                     // for mozilla::gfx::IntRect
 #include "nsRegion.h"                   // for nsIntRegion
 #include "nsTArray.h"                   // for nsTArray, nsTArray_Impl, etc
 #include "nsTArrayForwardDeclare.h"     // for InfallibleTArray
 #include "UnitTransforms.h"             // for TransformTo
 #include "gfxPrefs.h"
 #if defined(MOZ_WIDGET_ANDROID)
 # include <android/log.h>
-# include "AndroidBridge.h"
+# include "mozilla/widget/AndroidCompositorWidget.h"
 #endif
 #include "GeckoProfiler.h"
 #include "FrameUniformityData.h"
 #include "TreeTraversal.h"              // for ForEachNode, BreadthFirstSearch
 #include "VsyncSource.h"
 
 struct nsCSSValueSharedList;
 
@@ -1613,60 +1613,75 @@ AsyncCompositionManager::TransformShadow
 }
 
 void
 AsyncCompositionManager::SetFirstPaintViewport(const LayerIntPoint& aOffset,
                                                const CSSToLayerScale& aZoom,
                                                const CSSRect& aCssPageRect)
 {
 #ifdef MOZ_WIDGET_ANDROID
-  AndroidBridge::Bridge()->SetFirstPaintViewport(aOffset, aZoom, aCssPageRect);
+  widget::AndroidCompositorWidget* widget =
+      mLayerManager->GetCompositor()->GetWidget()->AsAndroid();
+  if (!widget) {
+    return;
+  }
+  widget->SetFirstPaintViewport(aOffset, aZoom, aCssPageRect);
 #endif
 }
 
 void
 AsyncCompositionManager::SetPageRect(const CSSRect& aCssPageRect)
 {
 #ifdef MOZ_WIDGET_ANDROID
-  AndroidBridge::Bridge()->SetPageRect(aCssPageRect);
+  widget::AndroidCompositorWidget* widget =
+      mLayerManager->GetCompositor()->GetWidget()->AsAndroid();
+  if (!widget) {
+    return;
+  }
+  widget->SetPageRect(aCssPageRect);
 #endif
 }
 
 void
 AsyncCompositionManager::SyncViewportInfo(const LayerIntRect& aDisplayPort,
                                           const CSSToLayerScale& aDisplayResolution,
                                           bool aLayersUpdated,
                                           int32_t aPaintSyncId,
                                           ParentLayerRect& aScrollRect,
                                           CSSToParentLayerScale& aScale,
                                           ScreenMargin& aFixedLayerMargins)
 {
 #ifdef MOZ_WIDGET_ANDROID
-  AndroidBridge::Bridge()->SyncViewportInfo(aDisplayPort,
-                                            aDisplayResolution,
-                                            aLayersUpdated,
-                                            aPaintSyncId,
-                                            aScrollRect,
-                                            aScale,
-                                            aFixedLayerMargins);
+  widget::AndroidCompositorWidget* widget =
+      mLayerManager->GetCompositor()->GetWidget()->AsAndroid();
+  if (!widget) {
+    return;
+  }
+  widget->SyncViewportInfo(
+      aDisplayPort, aDisplayResolution, aLayersUpdated, aPaintSyncId,
+      aScrollRect, aScale, aFixedLayerMargins);
 #endif
 }
 
 void
 AsyncCompositionManager::SyncFrameMetrics(const ParentLayerPoint& aScrollOffset,
                                           const CSSToParentLayerScale& aZoom,
                                           const CSSRect& aCssPageRect,
                                           const CSSRect& aDisplayPort,
                                           const CSSToLayerScale& aPaintedResolution,
                                           bool aLayersUpdated,
                                           int32_t aPaintSyncId,
                                           ScreenMargin& aFixedLayerMargins)
 {
 #ifdef MOZ_WIDGET_ANDROID
-  AndroidBridge::Bridge()->SyncFrameMetrics(aScrollOffset, aZoom, aCssPageRect,
-                                            aDisplayPort, aPaintedResolution,
-                                            aLayersUpdated, aPaintSyncId,
-                                            aFixedLayerMargins);
+  widget::AndroidCompositorWidget* widget =
+      mLayerManager->GetCompositor()->GetWidget()->AsAndroid();
+  if (!widget) {
+    return;
+  }
+  widget->SyncFrameMetrics(
+      aScrollOffset, aZoom, aCssPageRect, aDisplayPort, aPaintedResolution,
+      aLayersUpdated, aPaintSyncId, aFixedLayerMargins);
 #endif
 }
 
 } // namespace layers
 } // namespace mozilla
--- a/widget/CompositorWidget.h
+++ b/widget/CompositorWidget.h
@@ -25,16 +25,17 @@ class Composer2D;
 namespace gfx {
 class DrawTarget;
 class SourceSurface;
 } // namespace gfx
 namespace widget {
 
 class WinCompositorWidget;
 class X11CompositorWidget;
+class AndroidCompositorWidget;
 class CompositorWidgetInitData;
 
 // Gecko widgets usually need to communicate with the CompositorWidget with
 // platform-specific messages (for example to update the window size or
 // transparency). This functionality is controlled through a "host". Since
 // this functionality is platform-dependent, it is only forward declared
 // here.
 class CompositorWidgetDelegate;
@@ -244,16 +245,19 @@ public:
   virtual RefPtr<VsyncObserver> GetVsyncObserver() const;
 
   virtual WinCompositorWidget* AsWindows() {
     return nullptr;
   }
   virtual X11CompositorWidget* AsX11() {
     return nullptr;
   }
+  virtual AndroidCompositorWidget* AsAndroid() {
+    return nullptr;
+  }
 
   /**
    * Return the platform-specific delegate for the widget, if any.
    */
   virtual CompositorWidgetDelegate* AsDelegate() {
     return nullptr;
   }
 
--- a/widget/InProcessCompositorWidget.cpp
+++ b/widget/InProcessCompositorWidget.cpp
@@ -1,26 +1,34 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "InProcessCompositorWidget.h"
 #include "nsBaseWidget.h"
 
+#if defined(MOZ_WIDGET_ANDROID) && !defined(MOZ_WIDGET_SUPPORTS_OOP_COMPOSITING)
+#include "mozilla/widget/AndroidCompositorWidget.h"
+#endif
+
 namespace mozilla {
 namespace widget {
 
 // Platforms with no OOP compositor process support use
 // InProcessCompositorWidget by default.
 #if !defined(MOZ_WIDGET_SUPPORTS_OOP_COMPOSITING)
 /* static */ RefPtr<CompositorWidget>
 CompositorWidget::CreateLocal(const CompositorWidgetInitData& aInitData, nsIWidget* aWidget)
 {
   MOZ_ASSERT(aWidget);
+#ifdef MOZ_WIDGET_ANDROID
+  return new AndroidCompositorWidget(static_cast<nsBaseWidget*>(aWidget));
+#else
   return new InProcessCompositorWidget(static_cast<nsBaseWidget*>(aWidget));
+#endif
 }
 #endif
 
 InProcessCompositorWidget::InProcessCompositorWidget(nsBaseWidget* aWidget)
  : mWidget(aWidget)
 {
 }
 
new file mode 100644
--- /dev/null
+++ b/widget/android/AndroidCompositorWidget.cpp
@@ -0,0 +1,108 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set sw=2 ts=2 et tw=80 : */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "AndroidCompositorWidget.h"
+#include "nsWindow.h"
+
+namespace mozilla {
+namespace widget {
+
+void
+AndroidCompositorWidget::SetFirstPaintViewport(const LayerIntPoint& aOffset,
+                                               const CSSToLayerScale& aZoom,
+                                               const CSSRect& aCssPageRect)
+{
+    auto layerClient = static_cast<nsWindow*>(RealWidget())->GetLayerClient();
+    if (!layerClient) {
+        return;
+    }
+
+    layerClient->SetFirstPaintViewport(
+            float(aOffset.x), float(aOffset.y), aZoom.scale, aCssPageRect.x,
+            aCssPageRect.y, aCssPageRect.XMost(), aCssPageRect.YMost());
+}
+
+void
+AndroidCompositorWidget::SetPageRect(const CSSRect& aCssPageRect)
+{
+    auto layerClient = static_cast<nsWindow*>(RealWidget())->GetLayerClient();
+    if (!layerClient) {
+        return;
+    }
+
+    layerClient->SetPageRect(aCssPageRect.x, aCssPageRect.y,
+                             aCssPageRect.XMost(), aCssPageRect.YMost());
+}
+
+void
+AndroidCompositorWidget::SyncViewportInfo(const LayerIntRect& aDisplayPort,
+                                          const CSSToLayerScale& aDisplayResolution,
+                                          bool aLayersUpdated,
+                                          int32_t aPaintSyncId,
+                                          ParentLayerRect& aScrollRect,
+                                          CSSToParentLayerScale& aScale,
+                                          ScreenMargin& aFixedLayerMargins)
+{
+    auto layerClient = static_cast<nsWindow*>(RealWidget())->GetLayerClient();
+    if (!layerClient) {
+        return;
+    }
+
+    java::ViewTransform::LocalRef viewTransform = layerClient->SyncViewportInfo(
+            aDisplayPort.x, aDisplayPort.y, aDisplayPort.width,
+            aDisplayPort.height, aDisplayResolution.scale, aLayersUpdated,
+            aPaintSyncId);
+
+    MOZ_ASSERT(viewTransform, "No view transform object!");
+
+    aScrollRect = ParentLayerRect(
+        viewTransform->X(), viewTransform->Y(),
+        viewTransform->Width(), viewTransform->Height());
+
+    aScale.scale = viewTransform->Scale();
+
+    aFixedLayerMargins.top = viewTransform->FixedLayerMarginTop();
+    aFixedLayerMargins.right = viewTransform->FixedLayerMarginRight();
+    aFixedLayerMargins.bottom = viewTransform->FixedLayerMarginBottom();
+    aFixedLayerMargins.left = viewTransform->FixedLayerMarginLeft();
+}
+
+void
+AndroidCompositorWidget::SyncFrameMetrics(const ParentLayerPoint& aScrollOffset,
+                                          const CSSToParentLayerScale& aZoom,
+                                          const CSSRect& aCssPageRect,
+                                          const CSSRect& aDisplayPort,
+                                          const CSSToLayerScale& aPaintedResolution,
+                                          bool aLayersUpdated,
+                                          int32_t aPaintSyncId,
+                                          ScreenMargin& aFixedLayerMargins)
+{
+    auto layerClient = static_cast<nsWindow*>(RealWidget())->GetLayerClient();
+    if (!layerClient) {
+        return;
+    }
+
+    // convert the displayport rect from document-relative CSS pixels to
+    // document-relative device pixels
+    LayerIntRect dp = gfx::RoundedToInt(aDisplayPort * aPaintedResolution);
+
+    java::ViewTransform::LocalRef viewTransform = layerClient->SyncFrameMetrics(
+            aScrollOffset.x, aScrollOffset.y, aZoom.scale,
+            aCssPageRect.x, aCssPageRect.y,
+            aCssPageRect.XMost(), aCssPageRect.YMost(),
+            dp.x, dp.y, dp.width, dp.height,
+            aPaintedResolution.scale, aLayersUpdated, aPaintSyncId);
+
+    MOZ_ASSERT(viewTransform, "No view transform object!");
+
+    aFixedLayerMargins.top = viewTransform->FixedLayerMarginTop();
+    aFixedLayerMargins.right = viewTransform->FixedLayerMarginRight();
+    aFixedLayerMargins.bottom = viewTransform->FixedLayerMarginBottom();
+    aFixedLayerMargins.left = viewTransform->FixedLayerMarginLeft();
+}
+
+} // namespace widget
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/widget/android/AndroidCompositorWidget.h
@@ -0,0 +1,54 @@
+/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_widget_AndroidCompositorWidget_h
+#define mozilla_widget_AndroidCompositorWidget_h
+
+#include "mozilla/widget/InProcessCompositorWidget.h"
+
+namespace mozilla {
+namespace widget {
+
+/**
+ * AndroidCompositorWidget inherits from InProcessCompositorWidget because
+ * Android does not support OOP compositing yet. Once it does,
+ * AndroidCompositorWidget will be made to inherit from CompositorWidget
+ * instead.
+ */
+class AndroidCompositorWidget final : public InProcessCompositorWidget
+{
+public:
+    using InProcessCompositorWidget::InProcessCompositorWidget;
+
+    AndroidCompositorWidget* AsAndroid() override { return this; }
+
+    void SetFirstPaintViewport(const LayerIntPoint& aOffset,
+                               const CSSToLayerScale& aZoom,
+                               const CSSRect& aCssPageRect);
+
+    void SetPageRect(const CSSRect& aCssPageRect);
+
+    void SyncViewportInfo(const LayerIntRect& aDisplayPort,
+                          const CSSToLayerScale& aDisplayResolution,
+                          bool aLayersUpdated,
+                          int32_t aPaintSyncId,
+                          ParentLayerRect& aScrollRect,
+                          CSSToParentLayerScale& aScale,
+                          ScreenMargin& aFixedLayerMargins);
+
+    void SyncFrameMetrics(const ParentLayerPoint& aScrollOffset,
+                          const CSSToParentLayerScale& aZoom,
+                          const CSSRect& aCssPageRect,
+                          const CSSRect& aDisplayPort,
+                          const CSSToLayerScale& aPaintedResolution,
+                          bool aLayersUpdated,
+                          int32_t aPaintSyncId,
+                          ScreenMargin& aFixedLayerMargins);
+};
+
+} // namespace widget
+} // namespace mozilla
+
+#endif // mozilla_widget_AndroidCompositorWidget_h
--- a/widget/android/moz.build
+++ b/widget/android/moz.build
@@ -19,19 +19,24 @@ XPIDL_MODULE = 'widget_android'
 EXPORTS += [
     'AndroidBridge.h',
     'AndroidJavaWrappers.h',
     'AndroidJNIWrapper.h',
     'GeneratedJNINatives.h',
     'GeneratedJNIWrappers.h',
 ]
 
+EXPORTS.mozilla.widget += [
+    'AndroidCompositorWidget.h',
+]
+
 UNIFIED_SOURCES += [
     'AndroidAlerts.cpp',
     'AndroidBridge.cpp',
+    'AndroidCompositorWidget.cpp',
     'AndroidContentController.cpp',
     'AndroidJavaWrappers.cpp',
     'AndroidJNI.cpp',
     'AndroidJNIWrapper.cpp',
     'ANRReporter.cpp',
     'GeneratedJNIWrappers.cpp',
     'GfxInfo.cpp',
     'NativeJSContainer.cpp',
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -3614,8 +3614,17 @@ nsWindow::UpdateZoomConstraints(const ui
     nsBaseWidget::UpdateZoomConstraints(aPresShellId, aViewId, aConstraints);
 }
 
 CompositorBridgeParent*
 nsWindow::GetCompositorBridgeParent() const
 {
   return mCompositorSession ? mCompositorSession->GetInProcessBridge() : nullptr;
 }
+
+jni::DependentRef<java::GeckoLayerClient>
+nsWindow::GetLayerClient()
+{
+    if (NativePtr<LayerViewSupport>::Locked lvs{mLayerViewSupport}) {
+        return lvs->GetLayerClient().Get();
+    }
+    return nullptr;
+}
--- a/widget/android/nsWindow.h
+++ b/widget/android/nsWindow.h
@@ -221,16 +221,18 @@ public:
                                         uint32_t aNativeMessage,
                                         uint32_t aModifierFlags,
                                         nsIObserver* aObserver) override;
     nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
                                        nsIObserver* aObserver) override;
 
     CompositorBridgeParent* GetCompositorBridgeParent() const;
 
+    mozilla::jni::DependentRef<mozilla::java::GeckoLayerClient> GetLayerClient();
+
 protected:
     void BringToFront();
     nsWindow *FindTopLevel();
     bool IsTopLevel();
 
     RefPtr<mozilla::TextComposition> GetIMEComposition();
     void RemoveIMEComposition();