Bug 1956124 - Rename GeckoViewMetrics to CompositorScrollUpdate. r=hiro

This makes it clearer that the CompositorScrollDelegate API implementation
is using this type to represent an *update* to the relevant metrics,
of which there may be more than one per composite (in future patches).

The patch also moves the type to its own header, to help minimize
header dependencies.

Differential Revision: https://phabricator.services.mozilla.com/D242834
This commit is contained in:
Botond Ballo
2025-04-07 23:04:06 +00:00
parent 29e88562b1
commit 0a5b2b58d5
9 changed files with 59 additions and 35 deletions

View File

@@ -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

View File

@@ -896,8 +896,8 @@ void APZCTreeManager::SampleForWebRender(const Maybe<VsyncId>& aVsyncId,
RefPtr<UiCompositorControllerParent> uiController =
UiCompositorControllerParent::GetFromRootLayerTreeId(mRootLayersId);
if (uiController &&
apzc->UpdateRootFrameMetricsIfChanged(mLastRootMetrics)) {
uiController->NotifyUpdateScreenMetrics(mLastRootMetrics);
apzc->UpdateRootFrameMetricsIfChanged(mLastCompositorScrollUpdate)) {
uiController->NotifyCompositorScrollUpdate(mLastCompositorScrollUpdate);
}
#endif
}

View File

@@ -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)
};

View File

@@ -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 {
/**

View File

@@ -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;

View File

@@ -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;

View File

@@ -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<ScreenPixel>(
aMetrics.mZoom, PixelCastJustification::ScreenIsParentLayerForRoot);
ScreenPoint scrollOffset = aMetrics.mVisualScrollOffset * scale;
aUpdate.mZoom, PixelCastJustification::ScreenIsParentLayerForRoot);
ScreenPoint scrollOffset = aUpdate.mVisualScrollOffset * scale;
CompositorThread()->Dispatch(NewRunnableMethod<ScreenPoint, CSSToScreenScale>(
"UiCompositorControllerParent::SendRootFrameMetrics", this,
&UiCompositorControllerParent::SendRootFrameMetrics, scrollOffset,

View File

@@ -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);

View File

@@ -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",