OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CCLayerTreeHostCommon_h |
| 6 #define CCLayerTreeHostCommon_h |
| 7 |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "cc/scoped_ptr_vector.h" |
| 10 #include "IntRect.h" |
| 11 #include "IntSize.h" |
| 12 #include <public/WebTransformationMatrix.h> |
| 13 #include <wtf/Vector.h> |
| 14 |
| 15 namespace cc { |
| 16 |
| 17 class CCLayerImpl; |
| 18 class CCLayerSorter; |
| 19 class LayerChromium; |
| 20 |
| 21 class CCLayerTreeHostCommon { |
| 22 public: |
| 23 static IntRect calculateVisibleRect(const IntRect& targetSurfaceRect, const
IntRect& layerBoundRect, const WebKit::WebTransformationMatrix&); |
| 24 |
| 25 static void calculateDrawTransforms(LayerChromium* rootLayer, const IntSize&
deviceViewportSize, float deviceScaleFactor, int maxTextureSize, std::vector<sc
oped_refptr<LayerChromium> >& renderSurfaceLayerList); |
| 26 static void calculateDrawTransforms(CCLayerImpl* rootLayer, const IntSize& d
eviceViewportSize, float deviceScaleFactor, CCLayerSorter*, int maxTextureSize,
std::vector<CCLayerImpl*>& renderSurfaceLayerList); |
| 27 |
| 28 // Performs hit testing for a given renderSurfaceLayerList. |
| 29 static CCLayerImpl* findLayerThatIsHitByPoint(const IntPoint& viewportPoint,
std::vector<CCLayerImpl*>& renderSurfaceLayerList); |
| 30 |
| 31 template<typename LayerType> static bool renderSurfaceContributesToTarget(La
yerType*, int targetSurfaceLayerID); |
| 32 |
| 33 // Returns a layer with the given id if one exists in the subtree starting |
| 34 // from the given root layer (including mask and replica layers). |
| 35 template<typename LayerType> static LayerType* findLayerInSubtree(LayerType*
rootLayer, int layerId); |
| 36 |
| 37 static LayerChromium* getChildAsRawPtr(const std::vector<scoped_refptr<Layer
Chromium> >& children, size_t index) |
| 38 { |
| 39 return children[index].get(); |
| 40 } |
| 41 |
| 42 static CCLayerImpl* getChildAsRawPtr(const ScopedPtrVector<CCLayerImpl>& chi
ldren, size_t index) |
| 43 { |
| 44 return children[index]; |
| 45 } |
| 46 |
| 47 struct ScrollUpdateInfo { |
| 48 int layerId; |
| 49 IntSize scrollDelta; |
| 50 }; |
| 51 }; |
| 52 |
| 53 struct CCScrollAndScaleSet { |
| 54 CCScrollAndScaleSet(); |
| 55 ~CCScrollAndScaleSet(); |
| 56 |
| 57 Vector<CCLayerTreeHostCommon::ScrollUpdateInfo> scrolls; |
| 58 float pageScaleDelta; |
| 59 }; |
| 60 |
| 61 template<typename LayerType> |
| 62 bool CCLayerTreeHostCommon::renderSurfaceContributesToTarget(LayerType* layer, i
nt targetSurfaceLayerID) |
| 63 { |
| 64 // A layer will either contribute its own content, or its render surface's c
ontent, to |
| 65 // the target surface. The layer contributes its surface's content when both
the |
| 66 // following are true: |
| 67 // (1) The layer actually has a renderSurface, and |
| 68 // (2) The layer's renderSurface is not the same as the targetSurface. |
| 69 // |
| 70 // Otherwise, the layer just contributes itself to the target surface. |
| 71 |
| 72 return layer->renderSurface() && layer->id() != targetSurfaceLayerID; |
| 73 } |
| 74 |
| 75 template<typename LayerType> |
| 76 LayerType* CCLayerTreeHostCommon::findLayerInSubtree(LayerType* rootLayer, int l
ayerId) |
| 77 { |
| 78 if (rootLayer->id() == layerId) |
| 79 return rootLayer; |
| 80 |
| 81 if (rootLayer->maskLayer() && rootLayer->maskLayer()->id() == layerId) |
| 82 return rootLayer->maskLayer(); |
| 83 |
| 84 if (rootLayer->replicaLayer() && rootLayer->replicaLayer()->id() == layerId) |
| 85 return rootLayer->replicaLayer(); |
| 86 |
| 87 for (size_t i = 0; i < rootLayer->children().size(); ++i) { |
| 88 if (LayerType* found = findLayerInSubtree(getChildAsRawPtr(rootLayer->ch
ildren(), i), layerId)) |
| 89 return found; |
| 90 } |
| 91 return 0; |
| 92 } |
| 93 |
| 94 } // namespace cc |
| 95 |
| 96 #endif |
OLD | NEW |