diff --git a/gfx/layers/apz/public/CompositorScrollUpdate.h b/gfx/layers/apz/public/CompositorScrollUpdate.h new file mode 100644 index 000000000000..a0a116bda9de --- /dev/null +++ b/gfx/layers/apz/public/CompositorScrollUpdate.h @@ -0,0 +1,29 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 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/. */ + +#ifndef mozilla_layers_CompositorScrollUpdate_h +#define mozilla_layers_CompositorScrollUpdate_h + +#include "Units.h" + +namespace mozilla { +namespace layers { + +/** + * An update sent by APZ to interesting consumers (e.g. GeckoView) + * to inform them, on every composite, about the effective visual + * scroll offset and zoom level of the root content APZC at + * composition time. + */ +struct CompositorScrollUpdate { + CSSPoint mVisualScrollOffset; + CSSToParentLayerScale mZoom; +}; + +} // namespace layers +} // namespace mozilla + +#endif // mozilla_layers_CompositorScrollUpdate_h diff --git a/gfx/layers/apz/src/APZCTreeManager.cpp b/gfx/layers/apz/src/APZCTreeManager.cpp index 4927ea875a1a..9813dd772011 100644 --- a/gfx/layers/apz/src/APZCTreeManager.cpp +++ b/gfx/layers/apz/src/APZCTreeManager.cpp @@ -896,8 +896,8 @@ void APZCTreeManager::SampleForWebRender(const Maybe& aVsyncId, RefPtr uiController = UiCompositorControllerParent::GetFromRootLayerTreeId(mRootLayersId); if (uiController && - apzc->UpdateRootFrameMetricsIfChanged(mLastRootMetrics)) { - uiController->NotifyUpdateScreenMetrics(mLastRootMetrics); + apzc->UpdateRootFrameMetricsIfChanged(mLastCompositorScrollUpdate)) { + uiController->NotifyCompositorScrollUpdate(mLastCompositorScrollUpdate); } #endif } diff --git a/gfx/layers/apz/src/APZCTreeManager.h b/gfx/layers/apz/src/APZCTreeManager.h index 4e4232f111f4..978faa9984bd 100644 --- a/gfx/layers/apz/src/APZCTreeManager.h +++ b/gfx/layers/apz/src/APZCTreeManager.h @@ -16,12 +16,13 @@ #include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2 #include "mozilla/DataMutex.h" // for DataMutex #include "mozilla/gfx/CompositorHitTestInfo.h" -#include "mozilla/gfx/Logging.h" // for gfx::TreeLog -#include "mozilla/gfx/Matrix.h" // for Matrix4x4 -#include "mozilla/layers/APZInputBridge.h" // for APZInputBridge -#include "mozilla/layers/APZTestData.h" // for APZTestData -#include "mozilla/layers/APZUtils.h" // for GeckoViewMetrics -#include "mozilla/layers/IAPZCTreeManager.h" // for IAPZCTreeManager +#include "mozilla/gfx/Logging.h" // for gfx::TreeLog +#include "mozilla/gfx/Matrix.h" // for Matrix4x4 +#include "mozilla/layers/APZInputBridge.h" // for APZInputBridge +#include "mozilla/layers/APZTestData.h" // for APZTestData +#include "mozilla/layers/APZUtils.h" // for AsyncTransformComponents +#include "mozilla/layers/CompositorScrollUpdate.h" // for CompositorScrollUpdate +#include "mozilla/layers/IAPZCTreeManager.h" // for IAPZCTreeManager #include "mozilla/layers/ScrollbarData.h" #include "mozilla/layers/LayersTypes.h" #include "mozilla/layers/KeyboardMap.h" // for KeyboardMap @@ -1147,8 +1148,8 @@ class APZCTreeManager : public IAPZCTreeManager, public APZInputBridge { #if defined(MOZ_WIDGET_ANDROID) private: - // Last Frame metrics sent to java through UIController. - GeckoViewMetrics mLastRootMetrics; + // Last compositor scroll update sent to java through UIController. + CompositorScrollUpdate mLastCompositorScrollUpdate; #endif // defined(MOZ_WIDGET_ANDROID) }; diff --git a/gfx/layers/apz/src/APZUtils.h b/gfx/layers/apz/src/APZUtils.h index edd789d90c4a..ff9f54999aff 100644 --- a/gfx/layers/apz/src/APZUtils.h +++ b/gfx/layers/apz/src/APZUtils.h @@ -181,16 +181,6 @@ enum class AsyncTransformConsumer { */ enum class HandoffConsumer { Scrolling, PullToRefresh }; -/** - * Metrics that GeckoView wants to know at every composite. - * These are the effective visual scroll offset and zoom level of - * the root content APZC at composition time. - */ -struct GeckoViewMetrics { - CSSPoint mVisualScrollOffset; - CSSToParentLayerScale mZoom; -}; - namespace apz { /** diff --git a/gfx/layers/apz/src/AsyncPanZoomController.cpp b/gfx/layers/apz/src/AsyncPanZoomController.cpp index 65570e2346de..22a9c71852eb 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.cpp +++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp @@ -6091,10 +6091,11 @@ const FrameMetrics& AsyncPanZoomController::Metrics() const { return mScrollMetadata.GetMetrics(); } -GeckoViewMetrics AsyncPanZoomController::GetGeckoViewMetrics() const { +CompositorScrollUpdate AsyncPanZoomController::GetCompositorScrollUpdate() + const { RecursiveMutexAutoLock lock(mRecursiveMutex); - return GeckoViewMetrics{GetEffectiveScrollOffset(eForCompositing, lock), - GetEffectiveZoom(eForCompositing, lock)}; + return CompositorScrollUpdate{GetEffectiveScrollOffset(eForCompositing, lock), + GetEffectiveZoom(eForCompositing, lock)}; } wr::MinimapData AsyncPanZoomController::GetMinimapData() const { @@ -6122,14 +6123,14 @@ wr::MinimapData AsyncPanZoomController::GetMinimapData() const { } bool AsyncPanZoomController::UpdateRootFrameMetricsIfChanged( - GeckoViewMetrics& aMetrics) { + CompositorScrollUpdate& aMetrics) { RecursiveMutexAutoLock lock(mRecursiveMutex); if (!Metrics().IsRootContent()) { return false; } - GeckoViewMetrics newMetrics = GetGeckoViewMetrics(); + CompositorScrollUpdate newMetrics = GetCompositorScrollUpdate(); bool hasChanged = RoundedToInt(aMetrics.mVisualScrollOffset) != RoundedToInt(newMetrics.mVisualScrollOffset) || aMetrics.mZoom != newMetrics.mZoom; diff --git a/gfx/layers/apz/src/AsyncPanZoomController.h b/gfx/layers/apz/src/AsyncPanZoomController.h index e6709539fa92..7d3335f120f3 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.h +++ b/gfx/layers/apz/src/AsyncPanZoomController.h @@ -8,6 +8,7 @@ #define mozilla_layers_AsyncPanZoomController_h #include "Units.h" +#include "mozilla/layers/CompositorScrollUpdate.h" #include "mozilla/layers/GeckoContentController.h" #include "mozilla/layers/RepaintRequest.h" #include "mozilla/layers/SampleTime.h" @@ -592,15 +593,16 @@ class AsyncPanZoomController { FrameMetrics& Metrics(); /** - * Get the GeckoViewMetrics to be sent to Gecko for the current composite. + * Get the CompositorScrollUpdate to be sent to consumers for the current + * composite. */ - GeckoViewMetrics GetGeckoViewMetrics() const; + CompositorScrollUpdate GetCompositorScrollUpdate() const; wr::MinimapData GetMinimapData() const; // Helper function to compare root frame metrics and update them // Returns true when the metrics have changed and were updated. - bool UpdateRootFrameMetricsIfChanged(GeckoViewMetrics& aMetrics); + bool UpdateRootFrameMetricsIfChanged(CompositorScrollUpdate& aMetrics); // Returns the cached current frame time. SampleTime GetFrameTime() const; diff --git a/gfx/layers/ipc/UiCompositorControllerParent.cpp b/gfx/layers/ipc/UiCompositorControllerParent.cpp index 97c9b73844a7..27ac92f597c5 100644 --- a/gfx/layers/ipc/UiCompositorControllerParent.cpp +++ b/gfx/layers/ipc/UiCompositorControllerParent.cpp @@ -205,13 +205,12 @@ void UiCompositorControllerParent::NotifyFirstPaint() { ToolbarAnimatorMessageFromCompositor(FIRST_PAINT); } -void UiCompositorControllerParent::NotifyUpdateScreenMetrics( - const GeckoViewMetrics& aMetrics) { +void UiCompositorControllerParent::NotifyCompositorScrollUpdate( + const CompositorScrollUpdate& aUpdate) { #if defined(MOZ_WIDGET_ANDROID) - // TODO: Need to handle different x-and y-scales. CSSToScreenScale scale = ViewTargetAs( - aMetrics.mZoom, PixelCastJustification::ScreenIsParentLayerForRoot); - ScreenPoint scrollOffset = aMetrics.mVisualScrollOffset * scale; + aUpdate.mZoom, PixelCastJustification::ScreenIsParentLayerForRoot); + ScreenPoint scrollOffset = aUpdate.mVisualScrollOffset * scale; CompositorThread()->Dispatch(NewRunnableMethod( "UiCompositorControllerParent::SendRootFrameMetrics", this, &UiCompositorControllerParent::SendRootFrameMetrics, scrollOffset, diff --git a/gfx/layers/ipc/UiCompositorControllerParent.h b/gfx/layers/ipc/UiCompositorControllerParent.h index e6284e7dfb79..88ce66dc8124 100644 --- a/gfx/layers/ipc/UiCompositorControllerParent.h +++ b/gfx/layers/ipc/UiCompositorControllerParent.h @@ -7,7 +7,8 @@ #define include_gfx_ipc_UiCompositorControllerParent_h #include "mozilla/layers/PUiCompositorControllerParent.h" -#include "mozilla/layers/APZUtils.h" +#include "mozilla/layers/CompositorScrollUpdate.h" +#include "mozilla/layers/LayersTypes.h" #include "mozilla/ipc/Shmem.h" #include "mozilla/RefPtr.h" @@ -56,7 +57,7 @@ class UiCompositorControllerParent final // necessary. void NotifyLayersUpdated(); void NotifyFirstPaint(); - void NotifyUpdateScreenMetrics(const GeckoViewMetrics& aMetrics); + void NotifyCompositorScrollUpdate(const CompositorScrollUpdate& aUpdate); private: explicit UiCompositorControllerParent(const LayersId& aRootLayerTreeId); diff --git a/gfx/layers/moz.build b/gfx/layers/moz.build index 83fee8add9b5..43dfb81cf5b7 100644 --- a/gfx/layers/moz.build +++ b/gfx/layers/moz.build @@ -89,6 +89,7 @@ EXPORTS.mozilla.layers += [ "apz/public/APZSampler.h", "apz/public/APZUpdater.h", "apz/public/CompositorController.h", + "apz/public/CompositorScrollUpdate.h", "apz/public/GeckoContentController.h", "apz/public/GeckoContentControllerTypes.h", "apz/public/IAPZCTreeManager.h",