1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_TEST_TILED_LAYER_TEST_COMMON_H_
6 #define CC_TEST_TILED_LAYER_TEST_COMMON_H_
8 #include "cc/layer_updater.h"
9 #include "cc/prioritized_resource.h"
10 #include "cc/region.h"
11 #include "cc/resource_provider.h"
12 #include "cc/resource_update_queue.h"
13 #include "cc/texture_copier.h"
14 #include "cc/texture_uploader.h"
15 #include "cc/tiled_layer.h"
16 #include "cc/tiled_layer_impl.h"
17 #include "ui/gfx/rect.h"
18 #include "ui/gfx/size.h"
24 class FakeLayerUpdater
: public cc::LayerUpdater
{
26 class Resource
: public cc::LayerUpdater::Resource
{
28 Resource(FakeLayerUpdater
*, scoped_ptr
<cc::PrioritizedResource
>);
31 virtual void update(cc::ResourceUpdateQueue
&, const gfx::Rect
&, const gfx::Vector2d
&, bool, cc::RenderingStats
*) OVERRIDE
;
34 FakeLayerUpdater
* m_layer
;
40 virtual scoped_ptr
<cc::LayerUpdater::Resource
> createResource(cc::PrioritizedResourceManager
*) OVERRIDE
;
42 virtual void prepareToUpdate(const gfx::Rect
& contentRect
, const gfx::Size
&, float, float, gfx::Rect
& resultingOpaqueRect
, cc::RenderingStats
*) OVERRIDE
;
43 // Sets the rect to invalidate during the next call to prepareToUpdate(). After the next
44 // call to prepareToUpdate() the rect is reset.
45 void setRectToInvalidate(const gfx::Rect
&, FakeTiledLayer
*);
46 // Last rect passed to prepareToUpdate().
47 const gfx::Rect
& lastUpdateRect() const { return m_lastUpdateRect
; }
49 // Number of times prepareToUpdate has been invoked.
50 int prepareCount() const { return m_prepareCount
; }
51 void clearPrepareCount() { m_prepareCount
= 0; }
53 // Number of times update() has been invoked on a texture.
54 int updateCount() const { return m_updateCount
; }
55 void clearUpdateCount() { m_updateCount
= 0; }
56 void update() { m_updateCount
++; }
58 void setOpaquePaintRect(const gfx::Rect
& opaquePaintRect
) { m_opaquePaintRect
= opaquePaintRect
; }
61 virtual ~FakeLayerUpdater();
66 gfx::Rect m_rectToInvalidate
;
67 gfx::Rect m_lastUpdateRect
;
68 gfx::Rect m_opaquePaintRect
;
69 scoped_refptr
<FakeTiledLayer
> m_layer
;
72 class FakeTiledLayerImpl
: public cc::TiledLayerImpl
{
74 FakeTiledLayerImpl(LayerTreeImpl
* treeImpl
, int id
);
75 virtual ~FakeTiledLayerImpl();
77 using cc::TiledLayerImpl::hasTileAt
;
78 using cc::TiledLayerImpl::hasResourceIdForTileAt
;
81 class FakeTiledLayer
: public cc::TiledLayer
{
83 explicit FakeTiledLayer(cc::PrioritizedResourceManager
*);
85 static gfx::Size
tileSize() { return gfx::Size(100, 100); }
87 using cc::TiledLayer::invalidateContentRect
;
88 using cc::TiledLayer::needsIdlePaint
;
89 using cc::TiledLayer::skipsDraw
;
90 using cc::TiledLayer::numPaintedTiles
;
91 using cc::TiledLayer::idlePaintRect
;
93 virtual void setNeedsDisplayRect(const gfx::RectF
&) OVERRIDE
;
94 const gfx::RectF
& lastNeedsDisplayRect() const { return m_lastNeedsDisplayRect
; }
96 virtual void setTexturePriorities(const cc::PriorityCalculator
&) OVERRIDE
;
98 virtual cc::PrioritizedResourceManager
* resourceManager() const OVERRIDE
;
99 FakeLayerUpdater
* fakeLayerUpdater() { return m_fakeUpdater
.get(); }
100 gfx::RectF
updateRect() { return m_updateRect
; }
102 // Simulate calcDrawProperties.
103 void updateContentsScale(float idealContentsScale
);
106 virtual cc::LayerUpdater
* updater() const OVERRIDE
;
107 virtual void createUpdaterIfNeeded() OVERRIDE
{ }
108 virtual ~FakeTiledLayer();
111 scoped_refptr
<FakeLayerUpdater
> m_fakeUpdater
;
112 cc::PrioritizedResourceManager
* m_resourceManager
;
113 gfx::RectF m_lastNeedsDisplayRect
;
116 class FakeTiledLayerWithScaledBounds
: public FakeTiledLayer
{
118 explicit FakeTiledLayerWithScaledBounds(cc::PrioritizedResourceManager
*);
120 void setContentBounds(const gfx::Size
& contentBounds
);
121 virtual void calculateContentsScale(
122 float idealContentsScale
,
123 bool animatingTransformToScreen
,
124 float* contentsScaleX
,
125 float* contentsScaleY
,
126 gfx::Size
* contentBounds
) OVERRIDE
;
127 virtual void didUpdateBounds() OVERRIDE
;
130 virtual ~FakeTiledLayerWithScaledBounds();
131 gfx::Size m_forcedContentBounds
;
136 #endif // CC_TEST_TILED_LAYER_TEST_COMMON_H_