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/base/region.h"
9 #include "cc/layers/tiled_layer.h"
10 #include "cc/layers/tiled_layer_impl.h"
11 #include "cc/resources/layer_updater.h"
12 #include "cc/resources/prioritized_resource.h"
13 #include "cc/resources/resource_provider.h"
14 #include "cc/resources/resource_update_queue.h"
15 #include "cc/scheduler/texture_uploader.h"
16 #include "ui/gfx/rect.h"
17 #include "ui/gfx/size.h"
23 class FakeLayerUpdater
: public LayerUpdater
{
25 class Resource
: public LayerUpdater::Resource
{
27 Resource(FakeLayerUpdater
* updater
,
28 scoped_ptr
<PrioritizedResource
> resource
);
31 virtual void Update(ResourceUpdateQueue
* queue
,
32 gfx::Rect source_rect
,
33 gfx::Vector2d dest_offset
,
34 bool partial_update
) OVERRIDE
;
37 FakeLayerUpdater
* layer_
;
40 DISALLOW_COPY_AND_ASSIGN(Resource
);
45 virtual scoped_ptr
<LayerUpdater::Resource
> CreateResource(
46 PrioritizedResourceManager
* resource
) OVERRIDE
;
48 virtual void PrepareToUpdate(gfx::Rect content_rect
,
50 float contents_width_scale
,
51 float contents_height_scale
,
52 gfx::Rect
* resulting_opaque_rect
) OVERRIDE
;
53 // Sets the rect to invalidate during the next call to PrepareToUpdate().
54 // After the next call to PrepareToUpdate() the rect is reset.
55 void SetRectToInvalidate(gfx::Rect rect
, FakeTiledLayer
* layer
);
56 // Last rect passed to PrepareToUpdate().
57 gfx::Rect
last_update_rect() const { return last_update_rect_
; }
59 // Number of times PrepareToUpdate has been invoked.
60 int prepare_count() const { return prepare_count_
; }
61 void ClearPrepareCount() { prepare_count_
= 0; }
63 // Number of times Update() has been invoked on a texture.
64 int update_count() const { return update_count_
; }
65 void ClearUpdateCount() { update_count_
= 0; }
66 void Update() { update_count_
++; }
68 void SetOpaquePaintRect(gfx::Rect opaque_paint_rect
) {
69 opaque_paint_rect_
= opaque_paint_rect
;
73 virtual ~FakeLayerUpdater();
78 gfx::Rect rect_to_invalidate_
;
79 gfx::Rect last_update_rect_
;
80 gfx::Rect opaque_paint_rect_
;
81 scoped_refptr
<FakeTiledLayer
> layer_
;
83 DISALLOW_COPY_AND_ASSIGN(FakeLayerUpdater
);
86 class FakeTiledLayerImpl
: public TiledLayerImpl
{
88 FakeTiledLayerImpl(LayerTreeImpl
* tree_impl
, int id
);
89 virtual ~FakeTiledLayerImpl();
91 using TiledLayerImpl::HasTileAt
;
92 using TiledLayerImpl::HasResourceIdForTileAt
;
95 class FakeTiledLayer
: public TiledLayer
{
97 explicit FakeTiledLayer(PrioritizedResourceManager
* resource_manager
);
99 static gfx::Size
tile_size() { return gfx::Size(100, 100); }
101 using TiledLayer::InvalidateContentRect
;
102 using TiledLayer::NeedsIdlePaint
;
103 using TiledLayer::SkipsDraw
;
104 using TiledLayer::NumPaintedTiles
;
105 using TiledLayer::IdlePaintRect
;
107 virtual void SetNeedsDisplayRect(const gfx::RectF
& rect
) OVERRIDE
;
108 const gfx::RectF
& last_needs_display_rect() const {
109 return last_needs_display_rect_
;
112 virtual void SetTexturePriorities(
113 const PriorityCalculator
& priority_calculator
) OVERRIDE
;
115 virtual PrioritizedResourceManager
* ResourceManager() OVERRIDE
;
116 FakeLayerUpdater
* fake_layer_updater() { return fake_updater_
.get(); }
117 gfx::RectF
update_rect() { return update_rect_
; }
119 // Simulate CalcDrawProperties.
120 void UpdateContentsScale(float ideal_contents_scale
);
122 void ResetNumDependentsNeedPushProperties();
125 virtual LayerUpdater
* Updater() const OVERRIDE
;
126 virtual void CreateUpdaterIfNeeded() OVERRIDE
{}
127 virtual ~FakeTiledLayer();
130 scoped_refptr
<FakeLayerUpdater
> fake_updater_
;
131 PrioritizedResourceManager
* resource_manager_
;
132 gfx::RectF last_needs_display_rect_
;
134 DISALLOW_COPY_AND_ASSIGN(FakeTiledLayer
);
137 class FakeTiledLayerWithScaledBounds
: public FakeTiledLayer
{
139 explicit FakeTiledLayerWithScaledBounds(
140 PrioritizedResourceManager
* resource_manager
);
142 void SetContentBounds(gfx::Size content_bounds
);
143 virtual void CalculateContentsScale(float ideal_contents_scale
,
144 float device_scale_factor
,
145 float page_scale_factor
,
146 bool animating_transform_to_screen
,
147 float* contents_scale_x
,
148 float* contents_scale_y
,
149 gfx::Size
* content_bounds
) OVERRIDE
;
152 virtual ~FakeTiledLayerWithScaledBounds();
153 gfx::Size forced_content_bounds_
;
156 DISALLOW_COPY_AND_ASSIGN(FakeTiledLayerWithScaledBounds
);
161 #endif // CC_TEST_TILED_LAYER_TEST_COMMON_H_