Bug 1357754 - Add WebRenderScrollDataWrapper. r=botond
This adds the WebRenderScrollDataWrapper class which is
template-compatible with LayerMetricsWrapper. While the
LayerMetricsWrapper operates on an underlying layer tree, the
WebRenderScrollDataWrapper will simulate a layer tree based on an
underlying WebRenderScrollData object. The class is stubbed out here,
functions will be implemented in subsequent patches.
MozReview-Commit-ID: 9exnFRI6tOW
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -17,16 +17,17 @@
#include "mozilla/gfx/GPUParent.h" // for GPUParent
#include "mozilla/gfx/Logging.h" // for gfx::TreeLog
#include "mozilla/gfx/Point.h" // for Point
#include "mozilla/layers/APZThreadUtils.h" // for AssertOnCompositorThread, etc
#include "mozilla/layers/AsyncCompositionManager.h" // for ViewTransform
#include "mozilla/layers/AsyncDragMetrics.h" // for AsyncDragMetrics
#include "mozilla/layers/CompositorBridgeParent.h" // for CompositorBridgeParent, etc
#include "mozilla/layers/LayerMetricsWrapper.h"
+#include "mozilla/layers/WebRenderScrollDataWrapper.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/mozalloc.h" // for operator new
#include "mozilla/TouchEvents.h"
#include "mozilla/Preferences.h" // for Preferences
#include "mozilla/EventStateManager.h" // for WheelPrefs
#include "nsDebug.h" // for NS_WARNING
#include "nsPoint.h" // for nsIntPoint
#include "nsThreadUtils.h" // for NS_IsMainThread
@@ -208,17 +209,17 @@ APZCTreeManager::GetFrameTime()
void
APZCTreeManager::SetAllowedTouchBehavior(uint64_t aInputBlockId,
const nsTArray<TouchBehaviorFlags> &aValues)
{
mInputQueue->SetAllowedTouchBehavior(aInputBlockId, aValues);
}
-template<class ScrollNode> void // ScrollNode is a LayerMetricsWrapper
+template<class ScrollNode> void // ScrollNode is a LayerMetricsWrapper or a WebRenderScrollDataWrapper
APZCTreeManager::UpdateHitTestingTreeImpl(uint64_t aRootLayerTreeId,
const ScrollNode& aRoot,
bool aIsFirstPaint,
uint64_t aOriginatingLayersId,
uint32_t aPaintSequenceNumber)
{
APZThreadUtils::AssertOnCompositorThread();
@@ -343,16 +344,28 @@ APZCTreeManager::UpdateHitTestingTree(ui
uint64_t aOriginatingLayersId,
uint32_t aPaintSequenceNumber)
{
LayerMetricsWrapper root(aRoot);
UpdateHitTestingTreeImpl(aRootLayerTreeId, root, aIsFirstPaint,
aOriginatingLayersId, aPaintSequenceNumber);
}
+void
+APZCTreeManager::UpdateHitTestingTree(uint64_t aRootLayerTreeId,
+ const WebRenderScrollData& aScrollData,
+ bool aIsFirstPaint,
+ uint64_t aOriginatingLayersId,
+ uint32_t aPaintSequenceNumber)
+{
+ WebRenderScrollDataWrapper wrapper(&aScrollData);
+ UpdateHitTestingTreeImpl(aRootLayerTreeId, wrapper, aIsFirstPaint,
+ aOriginatingLayersId, aPaintSequenceNumber);
+}
+
// Compute the clip region to be used for a layer with an APZC. This function
// is only called for layers which actually have scrollable metrics and an APZC.
template<class ScrollNode> static ParentLayerIntRegion
ComputeClipRegion(GeckoContentController* aController,
const ScrollNode& aLayer)
{
ParentLayerIntRegion clipRegion;
if (aLayer.GetClipRect()) {
--- a/gfx/layers/apz/src/APZCTreeManager.h
+++ b/gfx/layers/apz/src/APZCTreeManager.h
@@ -31,16 +31,17 @@ class APZCTreeManagerParent;
class CompositorBridgeParent;
class OverscrollHandoffChain;
struct OverscrollHandoffState;
struct FlingHandoffState;
class LayerMetricsWrapper;
class InputQueue;
class GeckoContentController;
class HitTestingTreeNode;
+class WebRenderScrollData;
/**
* ****************** NOTE ON LOCK ORDERING IN APZ **************************
*
* There are two kinds of locks used by APZ: APZCTreeManager::mTreeLock
* ("the tree lock") and AsyncPanZoomController::mMonitor ("APZC locks").
*
* To avoid deadlock, we impose a lock ordering between these locks, which is:
@@ -123,16 +124,28 @@ public:
*/
void UpdateHitTestingTree(uint64_t aRootLayerTreeId,
Layer* aRoot,
bool aIsFirstPaint,
uint64_t aOriginatingLayersId,
uint32_t aPaintSequenceNumber);
/**
+ * Same as the above UpdateHitTestingTree, except slightly modified to take
+ * the scrolling data passed over PWebRenderBridge instead of the raw layer
+ * tree. This version is used when WebRender is enabled because we don't have
+ * shadow layers in that scenario.
+ */
+ void UpdateHitTestingTree(uint64_t aRootLayerTreeId,
+ const WebRenderScrollData& aScrollData,
+ bool aIsFirstPaint,
+ uint64_t aOriginatingLayersId,
+ uint32_t aPaintSequenceNumber);
+
+ /**
* Walk the tree of APZCs and flushes the repaint requests for all the APZCS
* corresponding to the given layers id. Finally, sends a flush complete
* notification to the GeckoContentController for the layers id.
*/
void FlushApzRepaints(uint64_t aLayersId);
/**
* General handler for incoming input events. Manipulates the frame metrics
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -202,16 +202,17 @@ EXPORTS.mozilla.layers += [
'wr/WebRenderBridgeParent.h',
'wr/WebRenderCompositableHolder.h',
'wr/WebRenderDisplayItemLayer.h',
'wr/WebRenderImageHost.h',
'wr/WebRenderLayerManager.h',
'wr/WebRenderLayersLogging.h',
'wr/WebRenderMessageUtils.h',
'wr/WebRenderScrollData.h',
+ 'wr/WebRenderScrollDataWrapper.h',
'wr/WebRenderTextureHost.h',
]
if CONFIG['MOZ_X11']:
EXPORTS.mozilla.layers += [
'basic/TextureClientX11.h',
'basic/X11TextureSourceBasic.h',
'composite/X11TextureHost.h',
new file mode 100644
--- /dev/null
+++ b/gfx/layers/wr/WebRenderScrollDataWrapper.h
@@ -0,0 +1,173 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * 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 GFX_WEBRENDERSCROLLDATAWRAPPER_H
+#define GFX_WEBRENDERSCROLLDATAWRAPPER_H
+
+#include "FrameMetrics.h"
+#include "mozilla/layers/WebRenderScrollData.h"
+
+namespace mozilla {
+namespace layers {
+
+/*
+ * This class is a wrapper to walk through a WebRenderScrollData object, with
+ * an exposed API that is template-compatible to LayerMetricsWrapper. This allows
+ * APZ to walk through both layer trees and WebRender scroll metadata structures
+ * without a lot of code duplication.
+ * (Note that not all functions from LayerMetricsWrapper are implemented here,
+ * only the ones we've needed in APZ code so far.)
+ *
+ * One important note here is that this class holds a pointer to the "owning"
+ * WebRenderScrollData. The caller must ensure that this class does not outlive
+ * the owning WebRenderScrollData, or this may result in use-after-free errors.
+ * This class being declared a MOZ_STACK_CLASS should help with that.
+ *
+ * Refer to LayerMetricsWrapper.h for actual documentation on the exposed API.
+ */
+class MOZ_STACK_CLASS WebRenderScrollDataWrapper {
+public:
+ explicit WebRenderScrollDataWrapper(const WebRenderScrollData* aData)
+ : mData(aData)
+ {
+ }
+
+ explicit operator bool() const
+ {
+ // TODO
+ return false;
+ }
+
+ bool IsScrollInfoLayer() const
+ {
+ // TODO
+ return false;
+ }
+
+ WebRenderScrollDataWrapper GetLastChild() const
+ {
+ // TODO
+ return WebRenderScrollDataWrapper(nullptr);
+ }
+
+ WebRenderScrollDataWrapper GetPrevSibling() const
+ {
+ // TODO
+ return WebRenderScrollDataWrapper(nullptr);
+ }
+
+ const ScrollMetadata& Metadata() const
+ {
+ // TODO
+ return *ScrollMetadata::sNullMetadata;
+ }
+
+ const FrameMetrics& Metrics() const
+ {
+ return Metadata().GetMetrics();
+ }
+
+ AsyncPanZoomController* GetApzc() const
+ {
+ // TODO
+ return nullptr;
+ }
+
+ void SetApzc(AsyncPanZoomController* aApzc) const
+ {
+ // TODO
+ }
+
+ const char* Name() const
+ {
+ // TODO
+ return nullptr;
+ }
+
+ gfx::Matrix4x4 GetTransform() const
+ {
+ // TODO
+ return gfx::Matrix4x4();
+ }
+
+ CSSTransformMatrix GetTransformTyped() const
+ {
+ return ViewAs<CSSTransformMatrix>(GetTransform());
+ }
+
+ bool TransformIsPerspective() const
+ {
+ // TODO
+ return false;
+ }
+
+ EventRegions GetEventRegions() const
+ {
+ // TODO
+ return EventRegions();
+ }
+
+ Maybe<uint64_t> GetReferentId() const
+ {
+ // TODO
+ return Nothing();
+ }
+
+ Maybe<ParentLayerIntRect> GetClipRect() const
+ {
+ // TODO
+ return Nothing();
+ }
+
+ EventRegionsOverride GetEventRegionsOverride() const
+ {
+ // TODO
+ return EventRegionsOverride::NoOverride;
+ }
+
+ ScrollDirection GetScrollbarDirection() const
+ {
+ // TODO
+ return ScrollDirection::NONE;
+ }
+
+ FrameMetrics::ViewID GetScrollbarTargetContainerId() const
+ {
+ // TODO
+ return 0;
+ }
+
+ int32_t GetScrollThumbLength() const
+ {
+ // TODO
+ return 0;
+ }
+
+ bool IsScrollbarContainer() const
+ {
+ // TODO
+ return false;
+ }
+
+ FrameMetrics::ViewID GetFixedPositionScrollContainerId() const
+ {
+ // TODO
+ return 0;
+ }
+
+ const void* GetLayer() const
+ {
+ // TODO
+ return nullptr;
+ }
+
+private:
+ const WebRenderScrollData* mData;
+};
+
+} // namespace layers
+} // namespace mozilla
+
+#endif /* GFX_WEBRENDERSCROLLDATAWRAPPER_H */