Commit 4e871776 authored by jbroman@chromium.org's avatar jbroman@chromium.org

Put transform tree building in DisplayItemPropertyTreeBuilder.

This lays the groundwork for doing transform and clip tree construction in one
place. It also cleans up the part of the interface which is exposed in the Blink
API, and separates range records from the tree itself.

BUG=470248

Review URL: https://codereview.chromium.org/1296963002

git-svn-id: svn://svn.chromium.org/blink/trunk@200764 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 2e50af68
......@@ -5,7 +5,7 @@
#include "config.h"
#include "core/compositing/DisplayListCompositingBuilder.h"
#include "platform/graphics/paint/DisplayItemTransformTreeBuilder.h"
#include "platform/graphics/paint/DisplayItemPropertyTreeBuilder.h"
namespace blink {
......@@ -14,10 +14,12 @@ void DisplayListCompositingBuilder::build(CompositedDisplayList& compositedDispl
// TODO(pdr): Properly implement simple layer compositing here.
// See: https://docs.google.com/document/d/1qF7wpO_lhuxUO6YXKZ3CJuXi0grcb5gKZJBBgnoTd0k/view
DisplayItemTransformTreeBuilder transformTreeBuilder;
DisplayItemPropertyTreeBuilder treeBuilder;
for (const auto& displayItem : m_displayItemList.displayItems())
transformTreeBuilder.processDisplayItem(displayItem);
compositedDisplayList.transformTree = transformTreeBuilder.releaseTransformTree();
treeBuilder.processDisplayItem(displayItem);
compositedDisplayList.transformTree = treeBuilder.releaseTransformTree();
// TODO(pdr, jbroman): Also release other trees, and use range records to
// construct simple layers.
}
} // namespace blink
......@@ -277,6 +277,7 @@
'exported/WebDataConsumerHandle.cpp',
'exported/WebDeviceMotionData.cpp',
'exported/WebDeviceOrientationData.cpp',
'exported/WebDisplayItemClipTree.cpp',
'exported/WebDisplayItemTransformTree.cpp',
'exported/WebDragData.cpp',
'exported/WebEncryptedMediaClient.cpp',
......@@ -653,10 +654,12 @@
'graphics/paint/DisplayItemClient.h',
'graphics/paint/DisplayItemList.cpp',
'graphics/paint/DisplayItemList.h',
'graphics/paint/DisplayItemClipTree.cpp',
'graphics/paint/DisplayItemClipTree.h',
'graphics/paint/DisplayItemPropertyTreeBuilder.cpp',
'graphics/paint/DisplayItemPropertyTreeBuilder.h',
'graphics/paint/DisplayItemTransformTree.cpp',
'graphics/paint/DisplayItemTransformTree.h',
'graphics/paint/DisplayItemTransformTreeBuilder.cpp',
'graphics/paint/DisplayItemTransformTreeBuilder.h',
'graphics/paint/DrawingDisplayItem.cpp',
'graphics/paint/DrawingDisplayItem.h',
'graphics/paint/DrawingRecorder.cpp',
......@@ -972,9 +975,9 @@
'graphics/filters/FilterOperationsTest.cpp',
'graphics/filters/ImageFilterBuilderTest.cpp',
'graphics/gpu/DrawingBufferTest.cpp',
'graphics/paint/DisplayItemPropertyTreeBuilderTest.cpp',
'graphics/paint/DisplayItemListTest.cpp',
'graphics/paint/DisplayItemTest.cpp',
'graphics/paint/DisplayItemTransformTreeBuilderTest.cpp',
'image-decoders/FastSharedBufferReaderTest.cpp',
'image-decoders/ImageDecoderTest.cpp',
'network/FormDataTest.cpp',
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "public/platform/WebDisplayItemClipTree.h"
#include "platform/graphics/paint/DisplayItemClipTree.h"
namespace blink {
WebDisplayItemClipTree::WebDisplayItemClipTree()
{
}
WebDisplayItemClipTree::WebDisplayItemClipTree(const PassOwnPtr<DisplayItemClipTree>& passImpl)
: m_private(passImpl)
{
}
WebDisplayItemClipTree::~WebDisplayItemClipTree()
{
// WebPrivateOwnPtr requires explicit clearing here.
m_private.reset(nullptr);
}
size_t WebDisplayItemClipTree::nodeCount() const
{
return m_private->nodeCount();
}
const WebDisplayItemClipTree::ClipNode& WebDisplayItemClipTree::nodeAt(size_t index) const
{
return m_private->nodeAt(index);
}
} // namespace blink
......@@ -10,7 +10,6 @@
namespace blink {
WebDisplayItemTransformTree::WebDisplayItemTransformTree()
: m_private(adoptPtr(new DisplayItemTransformTree))
{
}
......@@ -35,19 +34,4 @@ const WebDisplayItemTransformTree::TransformNode& WebDisplayItemTransformTree::n
return m_private->nodeAt(index);
}
const WebDisplayItemTransformTree::TransformNode& WebDisplayItemTransformTree::parentNode(const WebDisplayItemTransformTree::TransformNode& node) const
{
return m_private->parentNode(node);
}
size_t WebDisplayItemTransformTree::rangeRecordCount() const
{
return m_private->rangeRecordCount();
}
const WebDisplayItemTransformTree::RangeRecord& WebDisplayItemTransformTree::rangeRecordAt(size_t index) const
{
return m_private->rangeRecordAt(index);
}
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "platform/graphics/paint/DisplayItemClipTree.h"
#include <limits>
namespace blink {
DisplayItemClipTree::DisplayItemClipTree()
{
// There is always a root node.
// And it's always in the root transform space.
float infinity = std::numeric_limits<float>::infinity();
WebFloatRect infiniteRect(-infinity, -infinity, infinity, infinity);
m_nodes.append(ClipNode(kInvalidIndex, 0 /* root transform node */, infiniteRect));
ASSERT(m_nodes[0].isRoot());
}
DisplayItemClipTree::~DisplayItemClipTree()
{
}
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DisplayItemClipTree_h
#define DisplayItemClipTree_h
#include "platform/PlatformExport.h"
#include "platform/geometry/FloatRect.h"
#include "public/platform/WebDisplayItemClipTree.h"
#include "wtf/Vector.h"
namespace blink {
// Represents a hierarchy of rectangular clips which apply to ranges of a
// display list and may be of interest to the compositor.
//
// This class is also the private implementation of WebDisplayItemClipTree.
// For more detail, see WebDisplayItemClipTree.h.
class PLATFORM_EXPORT DisplayItemClipTree {
public:
using ClipNode = WebDisplayItemClipTree::ClipNode;
enum : size_t { kInvalidIndex = WebDisplayItemClipTree::kInvalidIndex };
DisplayItemClipTree();
~DisplayItemClipTree();
size_t nodeCount() const { return m_nodes.size(); }
ClipNode& nodeAt(size_t index) { return m_nodes[index]; }
const ClipNode& nodeAt(size_t index) const { return m_nodes[index]; }
// Returns the new node index.
size_t createNewNode(size_t parentNodeIndex, size_t transformNodeIndex, const FloatRect& clipRect)
{
ASSERT(parentNodeIndex != kInvalidIndex);
ASSERT(transformNodeIndex != kInvalidIndex);
m_nodes.append(ClipNode(parentNodeIndex, transformNodeIndex, clipRect));
return m_nodes.size() - 1;
}
private:
Vector<ClipNode> m_nodes;
};
} // namespace blink
#endif // DisplayItemClipTree_h
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "platform/graphics/paint/DisplayItemPropertyTreeBuilder.h"
#include "platform/graphics/paint/DisplayItem.h"
#include "platform/graphics/paint/DisplayItemClipTree.h"
#include "platform/graphics/paint/DisplayItemTransformTree.h"
#include "platform/graphics/paint/Transform3DDisplayItem.h"
namespace blink {
DisplayItemPropertyTreeBuilder::DisplayItemPropertyTreeBuilder()
: m_transformTree(adoptPtr(new DisplayItemTransformTree))
, m_clipTree(adoptPtr(new DisplayItemClipTree))
, m_rangeBeginIndex(0)
, m_currentIndex(0)
{
m_stateStack.append(BuilderState());
}
DisplayItemPropertyTreeBuilder::~DisplayItemPropertyTreeBuilder()
{
}
PassOwnPtr<DisplayItemTransformTree> DisplayItemPropertyTreeBuilder::releaseTransformTree()
{
ASSERT(m_stateStack.size() == 1);
ASSERT(currentState().ignoredBeginCount == 0);
finishRange();
return m_transformTree.release();
}
PassOwnPtr<DisplayItemClipTree> DisplayItemPropertyTreeBuilder::releaseClipTree()
{
ASSERT(m_stateStack.size() == 1);
ASSERT(currentState().ignoredBeginCount == 0);
finishRange();
return m_clipTree.release();
}
Vector<DisplayItemPropertyTreeBuilder::RangeRecord> DisplayItemPropertyTreeBuilder::releaseRangeRecords()
{
Vector<RangeRecord> output;
output.swap(m_rangeRecords);
return output;
}
void DisplayItemPropertyTreeBuilder::processDisplayItem(const DisplayItem& displayItem)
{
if (displayItem.isBegin())
processBeginItem(displayItem);
else if (displayItem.isEnd())
processEndItem(displayItem);
m_currentIndex++;
}
namespace {
enum TransformKind { NotATransform = 0, Only2DTranslation, RequiresTransformNode };
enum ClipKind { NotAClip = 0, RequiresClipNode };
struct BeginDisplayItemClassification {
TransformKind transformKind = NotATransform;
TransformationMatrix matrix;
ClipKind clipKind = NotAClip;
FloatRect clipRect;
};
// Classifies a begin display item based on how it affects the property trees.
static BeginDisplayItemClassification classifyBeginItem(const DisplayItem& beginDisplayItem)
{
ASSERT(beginDisplayItem.isBegin());
BeginDisplayItemClassification result;
DisplayItem::Type type = beginDisplayItem.type();
if (DisplayItem::isTransform3DType(type)) {
const auto& begin3D = static_cast<const BeginTransform3DDisplayItem&>(beginDisplayItem);
result.matrix = begin3D.transform();
result.transformKind = result.matrix.isIdentityOr2DTranslation() ? Only2DTranslation : RequiresTransformNode;
}
return result;
}
} // namespace
void DisplayItemPropertyTreeBuilder::processBeginItem(const DisplayItem& displayItem)
{
BeginDisplayItemClassification classification = classifyBeginItem(displayItem);
if (!classification.transformKind && !classification.clipKind) {
currentState().ignoredBeginCount++;
return;
}
finishRange();
BuilderState newState(currentState());
newState.ignoredBeginCount = 0;
switch (classification.transformKind) {
case NotATransform:
break;
case Only2DTranslation:
// Adjust the offset associated with the current transform node.
newState.offset += classification.matrix.to2DTranslation();
break;
case RequiresTransformNode:
// Emit a transform node.
newState.transformNode = m_transformTree->createNewNode(
newState.transformNode, classification.matrix);
newState.offset = FloatSize();
break;
}
switch (classification.clipKind) {
case NotAClip:
break;
case RequiresClipNode:
// Emit a clip node.
FloatRect adjustedClipRect = classification.clipRect;
adjustedClipRect.move(newState.offset);
newState.clipNode = m_clipTree->createNewNode(
newState.clipNode, newState.transformNode, adjustedClipRect);
break;
}
m_stateStack.append(newState);
}
void DisplayItemPropertyTreeBuilder::processEndItem(const DisplayItem& displayItem)
{
if (currentState().ignoredBeginCount) {
// Ignored this end display item.
currentState().ignoredBeginCount--;
} else {
// We've closed the scope of some property.
finishRange();
m_stateStack.removeLast();
ASSERT(!m_stateStack.isEmpty());
}
}
void DisplayItemPropertyTreeBuilder::finishRange()
{
// Don't emit an empty range record.
if (m_rangeBeginIndex < m_currentIndex) {
const auto& current = currentState();
RangeRecord rangeRecord;
rangeRecord.displayListBeginIndex = m_rangeBeginIndex;
rangeRecord.displayListEndIndex = m_currentIndex;
rangeRecord.transformNodeIndex = current.transformNode;
rangeRecord.offset = current.offset;
rangeRecord.clipNodeIndex = current.clipNode;
m_rangeRecords.append(rangeRecord);
}
// The current display item is a boundary.
// The earliest the next range could begin is the next one.
m_rangeBeginIndex = m_currentIndex + 1;
}
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DisplayItemPropertyTreeBuilder_h
#define DisplayItemPropertyTreeBuilder_h
#include "platform/PlatformExport.h"
#include "platform/geometry/FloatSize.h"
#include "wtf/OwnPtr.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/Vector.h"
namespace blink {
class DisplayItem;
class DisplayItemClipTree;
class DisplayItemTransformTree;
// Builds property trees from a sequence of (properly nested) display items.
//
// The produced trees are not independent (for example, the resultant clip tree
// may have indicies into the transform tree's node list). Also produced is a
// vector of "range records", which correspond to non-overlapping ranges of
// display items in the list, in sorted order.
//
// Since the begin/end display items that create transform nodes are not
// included in these ranges, and empty ranges are omitted, these are not a
// partition of the display list. Rather, they constitute a partial map from
// display item indices to property tree data (node indices, plus a content
// offset from the origin of the transform node).
//
// Similarly, there may be property tree nodes with no associated range records.
// This doesn't necessarily mean that they can be ignored. It may be the parent
// of one or more other property nodes.
//
// See also the headers for the particular types of property tree.
class PLATFORM_EXPORT DisplayItemPropertyTreeBuilder {
public:
struct RangeRecord {
// Index of the first affected display item.
size_t displayListBeginIndex;
// Index of the first unaffected display item after |displayListBeginIndex|.
size_t displayListEndIndex;
// Index of the applicable transform node.
size_t transformNodeIndex;
// The offset of this range's drawing in the coordinate space of the
// transform node.
FloatSize offset;
// Index of the applicable clip node.
size_t clipNodeIndex;
};
DisplayItemPropertyTreeBuilder();
~DisplayItemPropertyTreeBuilder();
// Detach the built property trees.
PassOwnPtr<DisplayItemTransformTree> releaseTransformTree();
PassOwnPtr<DisplayItemClipTree> releaseClipTree();
Vector<RangeRecord> releaseRangeRecords();
// Process another display item from the list.
void processDisplayItem(const DisplayItem&);
private:
struct BuilderState {
// Initial state (root nodes, no display items seen).
BuilderState() : transformNode(0), clipNode(0), ignoredBeginCount(0) { }
// Index of the current transform node.
size_t transformNode;
// Offset from the current origin (i.e. where a drawing at (0, 0) would
// be) from the transform node's origin.
FloatSize offset;
// Index of the current clip node.
size_t clipNode;
// Number of "begin" display items that have been ignored, whose
// corresponding "end" display items should be skipped.
unsigned ignoredBeginCount;
};
// Used to manipulate the current transform node stack.
BuilderState& currentState() { return m_stateStack.last(); }
// Handle a begin display item.
void processBeginItem(const DisplayItem&);
// Handle an end display item.
void processEndItem(const DisplayItem&);
// Emit a range record, unless it would be empty.
void finishRange();
OwnPtr<DisplayItemTransformTree> m_transformTree;
OwnPtr<DisplayItemClipTree> m_clipTree;
Vector<RangeRecord> m_rangeRecords;
// TODO(jbroman): Experimentally select a less arbitrary inline capacity.
Vector<BuilderState, 40> m_stateStack;
size_t m_rangeBeginIndex;
size_t m_currentIndex;
};
} // namespace blink
#endif // DisplayItemPropertyTreeBuilder_h
......@@ -20,7 +20,6 @@ namespace blink {
class PLATFORM_EXPORT DisplayItemTransformTree {
public:
using TransformNode = WebDisplayItemTransformTree::TransformNode;
using RangeRecord = WebDisplayItemTransformTree::RangeRecord;
enum : size_t { kInvalidIndex = WebDisplayItemTransformTree::kInvalidIndex };
DisplayItemTransformTree();
......@@ -30,21 +29,6 @@ public:
TransformNode& nodeAt(size_t index) { return m_nodes[index]; }
const TransformNode& nodeAt(size_t index) const { return m_nodes[index]; }
size_t rangeRecordCount() const { return m_rangeRecords.size(); }
RangeRecord& rangeRecordAt(size_t index) { return m_rangeRecords[index]; }
const RangeRecord& rangeRecordAt(size_t index) const { return m_rangeRecords[index]; }
TransformNode& parentNode(const TransformNode& node)
{
ASSERT(!node.isRoot());
return nodeAt(node.parentNodeIndex);
}
const TransformNode& parentNode(const TransformNode& node) const
{
ASSERT(!node.isRoot());
return nodeAt(node.parentNodeIndex);
}
// Returns the new node index.
size_t createNewNode(size_t parentNodeIndex, const TransformationMatrix& matrix)
{
......@@ -55,14 +39,8 @@ public:
return m_nodes.size() - 1;
}
void appendRangeRecord(size_t beginIndex, size_t endIndex, size_t nodeIndex, const FloatSize& offset)
{
m_rangeRecords.append(RangeRecord(beginIndex, endIndex, nodeIndex, offset));
}
private:
Vector<TransformNode> m_nodes;
Vector<RangeRecord> m_rangeRecords;
};
} // namespace blink
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "platform/graphics/paint/DisplayItemTransformTreeBuilder.h"
#include "platform/graphics/paint/DisplayItem.h"
#include "platform/graphics/paint/DisplayItemTransformTree.h"
#include "platform/graphics/paint/Transform3DDisplayItem.h"
namespace blink {
DisplayItemTransformTreeBuilder::DisplayItemTransformTreeBuilder()
: m_transformTree(adoptPtr(new DisplayItemTransformTree))
, m_rangeBeginIndex(0)
, m_currentIndex(0)
{
pushCurrentTransformNode(0 /* root node */, FloatSize());
}
DisplayItemTransformTreeBuilder::~DisplayItemTransformTreeBuilder()
{
}
PassOwnPtr<DisplayItemTransformTree> DisplayItemTransformTreeBuilder::releaseTransformTree()
{
ASSERT(m_currentTransformNodeStack.size() == 1);
ASSERT(currentTransformNodeData().ignoredBeginCount == 0);
finishRange();
return m_transformTree.release();
}
namespace {
enum BeginDisplayItemClassification { NotATransform = 0, Only2DTranslation, RequiresTransformNode };
// Classifies a display item based on whether it is a transform, and if so,
// whether it should be get a transform node.
// If it is a transform (including a translation), the TransformationMatrix
// will be copied to output parameter.
static BeginDisplayItemClassification classifyBeginItem(const DisplayItem& beginDisplayItem, TransformationMatrix* transform)
{
ASSERT(beginDisplayItem.isBegin());
if (DisplayItem::isTransform3DType(beginDisplayItem.type())) {
const auto& begin3D = static_cast<const BeginTransform3DDisplayItem&>(beginDisplayItem);
*transform = begin3D.transform();
if (transform->isIdentityOr2DTranslation())
return Only2DTranslation;
return RequiresTransformNode;
}
return NotATransform;
}
} // namespace
void DisplayItemTransformTreeBuilder::processDisplayItem(const DisplayItem& displayItem)
{
if (displayItem.isBegin()) {
TransformationMatrix matrix;
switch (classifyBeginItem(displayItem, &matrix)) {
case NotATransform:
// Remember to ignore this begin later on.
currentTransformNodeData().ignoredBeginCount++;
break;
case Only2DTranslation:
// Adjust the offset associated with the current transform node.
finishRange();
pushCurrentTransformNode(
currentTransformNodeData().transformNode,
currentTransformNodeData().offset + matrix.to2DTranslation());
break;
case RequiresTransformNode:
// Emit a transform node.
finishRange();
size_t newNode = m_transformTree->createNewNode(
currentTransformNodeData().transformNode,
matrix);
pushCurrentTransformNode(newNode, FloatSize());
break;
}
} else if (displayItem.isEnd()) {
if (currentTransformNodeData().ignoredBeginCount) {
// Ignored this end display item.
currentTransformNodeData().ignoredBeginCount--;
} else {
// We've closed the scope of a transform.
finishRange();
popCurrentTransformNode();
ASSERT(!m_currentTransformNodeStack.isEmpty());
}
}
m_currentIndex++;
}
void DisplayItemTransformTreeBuilder::finishRange()
{
// Don't emit an empty range record.
if (m_rangeBeginIndex != m_currentIndex) {
const auto& current = currentTransformNodeData();
m_transformTree->appendRangeRecord(m_rangeBeginIndex, m_currentIndex, current.transformNode, current.offset);
}
// The current display item is a boundary.
// The earliest the next range could begin is the next one.
m_rangeBeginIndex = m_currentIndex + 1;
}
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DisplayItemTransformTreeBuilder_h
#define DisplayItemTransformTreeBuilder_h
#include "platform/PlatformExport.h"
#include "platform/geometry/FloatSize.h"
#include "wtf/OwnPtr.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/Vector.h"
namespace blink {
class DisplayItem;
class DisplayItemTransformTree;
class PLATFORM_EXPORT DisplayItemTransformTreeBuilder {
public:
DisplayItemTransformTreeBuilder();
~DisplayItemTransformTreeBuilder();
// Detach the built transform tree.
// This can be used to construct a WebDisplayItemTransformTree.
PassOwnPtr<DisplayItemTransformTree> releaseTransformTree();
// Process another display item from the list.
void processDisplayItem(const DisplayItem&);
private:
struct CurrentTransformNodeData {
CurrentTransformNodeData(size_t nodeIndex, const FloatSize& offsetFromOrigin)
: transformNode(nodeIndex), offset(offsetFromOrigin), ignoredBeginCount(0) { }
// Index of the current transform node.
size_t transformNode;
// Offset of the current origin (i.e. where a drawing at (0, 0) would
// be) from that node's origin.
FloatSize offset;
// Number of "begin" display items that have been ignored, whose
// corresponding "end" display items should be skipped.
unsigned ignoredBeginCount;
};
// Emit a range record, unless it would be empty.
void finishRange();
// Used to manipulate the current transform node stack.
CurrentTransformNodeData& currentTransformNodeData() { return m_currentTransformNodeStack.last(); }
void pushCurrentTransformNode(size_t nodeIndex, const FloatSize& offsetFromOrigin)
{
m_currentTransformNodeStack.append(CurrentTransformNodeData(nodeIndex, offsetFromOrigin));
}
void popCurrentTransformNode() { m_currentTransformNodeStack.removeLast(); }
OwnPtr<DisplayItemTransformTree> m_transformTree;
Vector<CurrentTransformNodeData, 16> m_currentTransformNodeStack;
size_t m_rangeBeginIndex;
size_t m_currentIndex;
};
} // namespace
#endif // DisplayItemTransformTreeBuilder_h
......@@ -276,6 +276,7 @@ source_set("blink_headers") {
"platform/WebRTCDataChannelHandler.h",
"platform/WebGestureCurveTarget.h",
"platform/WebBlendMode.h",
"platform/WebDisplayItemClipTree.h",
"platform/WebDisplayItemTransformTree.h",
"platform/WebConvertableToTraceFormat.h",
"platform/WebCryptoAlgorithm.h",
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WebDisplayItemClipTree_h
#define WebDisplayItemClipTree_h
#include "public/platform/WebCommon.h"
#include "public/platform/WebFloatRect.h"
#include "public/platform/WebPrivateOwnPtr.h"
namespace blink {
class DisplayItemClipTree;
// Represents a hierarchy of rectangular clips which apply to ranges of a
// display list and may be of interest to the compositor.
//
// It consists of a tree of "transform nodes", stored in a flattened
// representation in which their order is not guaranteed. Each node has a
// parent (whose clip, and those of its ancestors, also apply to content),
// a transform node index (into an associated |WebDisplayItemTransformTree|
// which defines the coordinate space in which this clip is interpreted),
// and a rectangle representing the clip.
//
// Rounded-rect clips are represented here by their bounding rect; the rounded
// clip should be represented outside the clip tree (e.g. as a mask).
class BLINK_PLATFORM_EXPORT WebDisplayItemClipTree {
public:
enum : size_t { kInvalidIndex = static_cast<size_t>(-1) };
struct ClipNode {
ClipNode(size_t parent, size_t transformNodeIndex, const WebFloatRect& clipRect)
: parentNodeIndex(parent)
, transformNodeIndex(transformNodeIndex)
, clipRect(clipRect)
{
}
bool isRoot() const { return parentNodeIndex == kInvalidIndex; }
// Index of parent in m_nodes (kInvalidIndex for root).
size_t parentNodeIndex;
// Index of transform node in which this clip should be interpreted.
// Cannot be WebDisplayItemTransformTree::kInvalidIndex.
size_t transformNodeIndex;
// Rectangular clip in the space of the transform node.
WebFloatRect clipRect;
};
WebDisplayItemClipTree();
#if INSIDE_BLINK
WebDisplayItemClipTree(const WTF::PassOwnPtr<DisplayItemClipTree>&);
#endif
~WebDisplayItemClipTree();
// Returns the number of nodes in the clip tree.
size_t nodeCount() const;
// Returns a node in the clip tree by its index (from 0 to nodeCount() - 1).
const ClipNode& nodeAt(size_t index) const;
private:
WebPrivateOwnPtr<const DisplayItemClipTree> m_private;
};
} // namespace blink
#endif // WebDisplayItemClipTree_h
......@@ -22,18 +22,7 @@ class DisplayItemTransformTree;
// parent, relative to whom its transform should be interpreted (i.e. the
// total transform at a node is the product of its transform and its parent's
// total transform).
//
// These nodes are associated with a display item list through the associated
// "range records", which correspond to non-overlapping ranges of display items
// in the list, in sorted order. Since the begin/end display items that create
// transform nodes are not included in these ranges, and empty ranges are
// omitted, these ranges are not a partition. Rather, they constitute a partial
// map from display item indices to transform node indices.
//
// Similarly, there may be transform nodes with no associated range records.
// This doesn't necessarily mean that it can be ignored -- it may be the parent
// of one or more other transform nodes.
class WebDisplayItemTransformTree {
class BLINK_PLATFORM_EXPORT WebDisplayItemTransformTree {
public:
enum : size_t { kInvalidIndex = static_cast<size_t>(-1) };
......@@ -53,62 +42,18 @@ public:
SkMatrix44 matrix;
};
struct RangeRecord {
RangeRecord(size_t beginIndex, size_t endIndex, size_t nodeIndex, const WebFloatSize& drawingOffset = WebFloatSize())
: displayListBeginIndex(beginIndex)
, displayListEndIndex(endIndex)
, transformNodeIndex(nodeIndex)
, offset(drawingOffset)
{
}
bool operator==(const RangeRecord& other) const
{
return displayListBeginIndex == other.displayListBeginIndex
&& displayListEndIndex == other.displayListEndIndex
&& transformNodeIndex == other.transformNodeIndex
&& offset == other.offset;
}
bool operator!=(const RangeRecord& other) const { return !(*this == other); }
// Index of first affected display item.
size_t displayListBeginIndex;
// Index of first unaffected display item after |displayListBeginIndex|.
size_t displayListEndIndex;
// Index of a the applicable transform node (in |m_nodes|).
size_t transformNodeIndex;
// The offset of this range's drawing in the coordinate space of the
// transform node.
WebFloatSize offset;
};
BLINK_PLATFORM_EXPORT WebDisplayItemTransformTree();
WebDisplayItemTransformTree();
#if INSIDE_BLINK
BLINK_PLATFORM_EXPORT WebDisplayItemTransformTree(
const WTF::PassOwnPtr<DisplayItemTransformTree>&);
WebDisplayItemTransformTree(const WTF::PassOwnPtr<DisplayItemTransformTree>&);
#endif
BLINK_PLATFORM_EXPORT ~WebDisplayItemTransformTree();
~WebDisplayItemTransformTree();
// Returns the number of nodes in the transform tree.
BLINK_PLATFORM_EXPORT size_t nodeCount() const;
size_t nodeCount() const;
// Returns a node in the transform tree by its index (from 0 to nodeCount() - 1).
BLINK_PLATFORM_EXPORT const TransformNode& nodeAt(size_t index) const;
// Returns the parent of the given node.
// Do not call this with the root node.
BLINK_PLATFORM_EXPORT const TransformNode& parentNode(const TransformNode&) const;
// Returns the number of display item ranges.
BLINK_PLATFORM_EXPORT size_t rangeRecordCount() const;
// Returns the requested display item range, sorted by position in the
// display item list.
BLINK_PLATFORM_EXPORT const RangeRecord& rangeRecordAt(size_t index) const;
const TransformNode& nodeAt(size_t index) const;
private:
WebPrivateOwnPtr<const DisplayItemTransformTree> m_private;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment