diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-18 08:03:04 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-18 08:03:04 +0000 |
commit | 556fd29842f0ad999d8d3b302636bcafc46792de (patch) | |
tree | bca322141170ab48c18539ed5257c14774ec8531 /cc/trees/layer_tree_host_common.h | |
parent | 89e8267acd40726861cbe9eef803534000286c70 (diff) | |
download | chromium_src-556fd29842f0ad999d8d3b302636bcafc46792de.zip chromium_src-556fd29842f0ad999d8d3b302636bcafc46792de.tar.gz chromium_src-556fd29842f0ad999d8d3b302636bcafc46792de.tar.bz2 |
Part 7 of cc/ directory shuffles: trees
Continuation of https://src.chromium.org/viewvc/chrome?view=rev&revision=188681
BUG=190824
TBR=enne@chromium.org, piman@chromium.org
Review URL: https://codereview.chromium.org/12722007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188694 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/trees/layer_tree_host_common.h')
-rw-r--r-- | cc/trees/layer_tree_host_common.h | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/cc/trees/layer_tree_host_common.h b/cc/trees/layer_tree_host_common.h new file mode 100644 index 0000000..1e33c65 --- /dev/null +++ b/cc/trees/layer_tree_host_common.h @@ -0,0 +1,118 @@ +// Copyright 2011 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 CC_TREES_LAYER_TREE_HOST_COMMON_H_ +#define CC_TREES_LAYER_TREE_HOST_COMMON_H_ + +#include "base/memory/ref_counted.h" +#include "cc/base/cc_export.h" +#include "cc/base/scoped_ptr_vector.h" +#include "ui/gfx/rect.h" +#include "ui/gfx/transform.h" +#include "ui/gfx/vector2d.h" + +namespace cc { + +class LayerImpl; +class Layer; + +class CC_EXPORT LayerTreeHostCommon { +public: + static gfx::Rect calculateVisibleRect(const gfx::Rect& targetSurfaceRect, const gfx::Rect& layerBoundRect, const gfx::Transform&); + + static void calculateDrawProperties(Layer* rootLayer, const gfx::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int maxTextureSize, bool canUseLCDText, std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList); + static void calculateDrawProperties(LayerImpl* rootLayer, const gfx::Size& deviceViewportSize, float deviceScaleFactor, float pageScaleFactor, int maxTextureSize, bool canUseLCDText, std::vector<LayerImpl*>& renderSurfaceLayerList, bool updateTilePriorities); + + // Performs hit testing for a given renderSurfaceLayerList. + static LayerImpl* findLayerThatIsHitByPoint(const gfx::PointF& screenSpacePoint, const std::vector<LayerImpl*>& renderSurfaceLayerList); + + static LayerImpl* findLayerThatIsHitByPointInTouchHandlerRegion(const gfx::PointF& screenSpacePoint, const std::vector<LayerImpl*>& renderSurfaceLayerList); + + static bool layerHasTouchEventHandlersAt(const gfx::PointF& screenSpacePoint, LayerImpl* layerImpl); + + template<typename LayerType> static bool renderSurfaceContributesToTarget(LayerType*, int targetSurfaceLayerID); + + template<class Function, typename LayerType> static void callFunctionForSubtree(LayerType* rootLayer); + + // Returns a layer with the given id if one exists in the subtree starting + // from the given root layer (including mask and replica layers). + template<typename LayerType> static LayerType* findLayerInSubtree(LayerType* rootLayer, int layerId); + + static Layer* getChildAsRawPtr(const std::vector<scoped_refptr<Layer> >& children, size_t index) + { + return children[index].get(); + } + + static LayerImpl* getChildAsRawPtr(const ScopedPtrVector<LayerImpl>& children, size_t index) + { + return children[index]; + } + + struct ScrollUpdateInfo { + int layerId; + gfx::Vector2d scrollDelta; + }; +}; + +struct CC_EXPORT ScrollAndScaleSet { + ScrollAndScaleSet(); + ~ScrollAndScaleSet(); + + std::vector<LayerTreeHostCommon::ScrollUpdateInfo> scrolls; + float pageScaleDelta; +}; + +template<typename LayerType> +bool LayerTreeHostCommon::renderSurfaceContributesToTarget(LayerType* layer, int targetSurfaceLayerID) +{ + // A layer will either contribute its own content, or its render surface's content, to + // the target surface. The layer contributes its surface's content when both the + // following are true: + // (1) The layer actually has a renderSurface, and + // (2) The layer's renderSurface is not the same as the targetSurface. + // + // Otherwise, the layer just contributes itself to the target surface. + + return layer->render_surface() && layer->id() != targetSurfaceLayerID; +} + +template<typename LayerType> +LayerType* LayerTreeHostCommon::findLayerInSubtree(LayerType* rootLayer, int layerId) +{ + if (rootLayer->id() == layerId) + return rootLayer; + + if (rootLayer->mask_layer() && rootLayer->mask_layer()->id() == layerId) + return rootLayer->mask_layer(); + + if (rootLayer->replica_layer() && rootLayer->replica_layer()->id() == layerId) + return rootLayer->replica_layer(); + + for (size_t i = 0; i < rootLayer->children().size(); ++i) { + if (LayerType* found = findLayerInSubtree(getChildAsRawPtr(rootLayer->children(), i), layerId)) + return found; + } + return 0; +} + +template<class Function, typename LayerType> +void LayerTreeHostCommon::callFunctionForSubtree(LayerType* rootLayer) +{ + Function()(rootLayer); + + if (LayerType* maskLayer = rootLayer->mask_layer()) + Function()(maskLayer); + if (LayerType* replicaLayer = rootLayer->replica_layer()) { + Function()(replicaLayer); + if (LayerType* maskLayer = replicaLayer->mask_layer()) + Function()(maskLayer); + } + + for (size_t i = 0; i < rootLayer->children().size(); ++i) + callFunctionForSubtree<Function>(getChildAsRawPtr(rootLayer->children(), i)); +} + +} // namespace cc + +#endif // CC_TREES_LAYER_TREE_HOST_COMMON_H_ |