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 "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/size.h"
22 class FakeLayerUpdater
: public LayerUpdater
{
24 class Resource
: public LayerUpdater::Resource
{
26 Resource(FakeLayerUpdater
* updater
,
27 scoped_ptr
<PrioritizedResource
> resource
);
30 void Update(ResourceUpdateQueue
* queue
,
31 const gfx::Rect
& source_rect
,
32 const gfx::Vector2d
& dest_offset
,
33 bool partial_update
) override
;
36 FakeLayerUpdater
* layer_
;
39 DISALLOW_COPY_AND_ASSIGN(Resource
);
44 scoped_ptr
<LayerUpdater::Resource
> CreateResource(
45 PrioritizedResourceManager
* resource
) override
;
47 void PrepareToUpdate(const gfx::Size
& content_size
,
48 const gfx::Rect
& paint_rect
,
49 const gfx::Size
& tile_size
,
50 float contents_width_scale
,
51 float contents_height_scale
) override
;
52 // Sets the rect to invalidate during the next call to PrepareToUpdate().
53 // After the next call to PrepareToUpdate() the rect is reset.
54 void SetRectToInvalidate(const gfx::Rect
& rect
, FakeTiledLayer
* layer
);
55 // Last rect passed to PrepareToUpdate().
56 gfx::Rect
last_update_rect() const { return last_update_rect_
; }
58 // Value of |contents_width_scale| last passed to PrepareToUpdate().
59 float last_contents_width_scale() const { return last_contents_width_scale_
; }
61 // Number of times PrepareToUpdate has been invoked.
62 int prepare_count() const { return prepare_count_
; }
63 void ClearPrepareCount() { prepare_count_
= 0; }
65 // Number of times Update() has been invoked on a texture.
66 int update_count() const { return update_count_
; }
67 void ClearUpdateCount() { update_count_
= 0; }
68 void Update() { update_count_
++; }
71 ~FakeLayerUpdater() override
;
76 gfx::Rect rect_to_invalidate_
;
77 gfx::Rect last_update_rect_
;
78 float last_contents_width_scale_
;
79 scoped_refptr
<FakeTiledLayer
> layer_
;
81 DISALLOW_COPY_AND_ASSIGN(FakeLayerUpdater
);
84 class FakeTiledLayerImpl
: public TiledLayerImpl
{
86 FakeTiledLayerImpl(LayerTreeImpl
* tree_impl
, int id
);
87 ~FakeTiledLayerImpl() override
;
89 using TiledLayerImpl::HasTileAt
;
90 using TiledLayerImpl::HasResourceIdForTileAt
;
93 class FakeTiledLayer
: public TiledLayer
{
95 explicit FakeTiledLayer(const LayerSettings
& settings
,
96 PrioritizedResourceManager
* resource_manager
);
98 static gfx::Size
tile_size() { return gfx::Size(100, 100); }
100 using TiledLayer::InvalidateContentRect
;
101 using TiledLayer::NeedsIdlePaint
;
102 using TiledLayer::SkipsDraw
;
103 using TiledLayer::NumPaintedTiles
;
104 using TiledLayer::IdlePaintRect
;
106 void SetNeedsDisplayRect(const gfx::Rect
& rect
) override
;
107 const gfx::Rect
& last_needs_display_rect() const {
108 return last_needs_display_rect_
;
111 void SetTexturePriorities(
112 const PriorityCalculator
& priority_calculator
) override
;
114 PrioritizedResourceManager
* ResourceManager() override
;
115 FakeLayerUpdater
* fake_layer_updater() { return fake_updater_
.get(); }
116 gfx::RectF
update_rect() { return update_rect_
; }
118 // Simulate CalcDrawProperties.
119 void UpdateContentsScale(float ideal_contents_scale
);
121 void ResetNumDependentsNeedPushProperties();
124 LayerUpdater
* Updater() const override
;
125 void CreateUpdaterIfNeeded() override
{}
126 ~FakeTiledLayer() override
;
129 scoped_refptr
<FakeLayerUpdater
> fake_updater_
;
130 PrioritizedResourceManager
* resource_manager_
;
131 gfx::Rect last_needs_display_rect_
;
133 DISALLOW_COPY_AND_ASSIGN(FakeTiledLayer
);
136 class FakeTiledLayerWithScaledBounds
: public FakeTiledLayer
{
138 FakeTiledLayerWithScaledBounds(const LayerSettings
& settings
,
139 PrioritizedResourceManager
* resource_manager
);
141 void SetContentBounds(const gfx::Size
& content_bounds
);
142 void CalculateContentsScale(float ideal_contents_scale
,
143 float* contents_scale_x
,
144 float* contents_scale_y
,
145 gfx::Size
* content_bounds
) override
;
148 ~FakeTiledLayerWithScaledBounds() override
;
149 gfx::Size forced_content_bounds_
;
152 DISALLOW_COPY_AND_ASSIGN(FakeTiledLayerWithScaledBounds
);
157 #endif // CC_TEST_TILED_LAYER_TEST_COMMON_H_