1 // Copyright 2013 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_FAKE_PICTURE_LAYER_IMPL_H_
6 #define CC_TEST_FAKE_PICTURE_LAYER_IMPL_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "cc/layers/picture_layer_impl.h"
13 class FakePictureLayerImpl
: public PictureLayerImpl
{
15 static scoped_ptr
<FakePictureLayerImpl
> Create(
16 LayerTreeImpl
* tree_impl
, int id
) {
18 return make_scoped_ptr(new FakePictureLayerImpl(tree_impl
, id
, is_mask
));
21 static scoped_ptr
<FakePictureLayerImpl
> CreateMask(LayerTreeImpl
* tree_impl
,
24 return make_scoped_ptr(new FakePictureLayerImpl(tree_impl
, id
, is_mask
));
27 // Create layer from a raster source that covers the entire layer.
28 static scoped_ptr
<FakePictureLayerImpl
> CreateWithRasterSource(
29 LayerTreeImpl
* tree_impl
,
31 scoped_refptr
<RasterSource
> raster_source
) {
33 return make_scoped_ptr(
34 new FakePictureLayerImpl(tree_impl
, id
, raster_source
, is_mask
));
37 // Create layer from a raster source that only covers part of the layer.
38 static scoped_ptr
<FakePictureLayerImpl
> CreateWithPartialRasterSource(
39 LayerTreeImpl
* tree_impl
,
41 scoped_refptr
<RasterSource
> raster_source
,
42 const gfx::Size
& layer_bounds
) {
44 return make_scoped_ptr(new FakePictureLayerImpl(
45 tree_impl
, id
, raster_source
, is_mask
, layer_bounds
));
48 // Create layer from a raster source that covers the entire layer and is a
50 static scoped_ptr
<FakePictureLayerImpl
> CreateMaskWithRasterSource(
51 LayerTreeImpl
* tree_impl
,
53 scoped_refptr
<RasterSource
> raster_source
) {
55 return make_scoped_ptr(
56 new FakePictureLayerImpl(tree_impl
, id
, raster_source
, is_mask
));
59 scoped_ptr
<LayerImpl
> CreateLayerImpl(LayerTreeImpl
* tree_impl
) override
;
60 void PushPropertiesTo(LayerImpl
* layer_impl
) override
;
61 void AppendQuads(RenderPass
* render_pass
,
62 AppendQuadsData
* append_quads_data
) override
;
63 gfx::Size
CalculateTileSize(const gfx::Size
& content_bounds
) const override
;
65 void DidBecomeActive() override
;
66 size_t did_become_active_call_count() {
67 return did_become_active_call_count_
;
70 bool HasValidTilePriorities() const override
;
71 void set_has_valid_tile_priorities(bool has_valid_priorities
) {
72 has_valid_tile_priorities_
= has_valid_priorities
;
73 use_set_valid_tile_priorities_flag_
= true;
76 size_t CountTilesRequired(
77 TileRequirementCheck is_tile_required_callback
) const;
78 size_t CountTilesRequiredForActivation() const;
79 size_t CountTilesRequiredForDraw() const;
81 using PictureLayerImpl::AddTiling
;
82 using PictureLayerImpl::CleanUpTilingsOnActiveLayer
;
83 using PictureLayerImpl::CanHaveTilings
;
84 using PictureLayerImpl::MinimumContentsScale
;
85 using PictureLayerImpl::SanityCheckTilingState
;
86 using PictureLayerImpl::GetRecycledTwinLayer
;
87 using PictureLayerImpl::UpdateRasterSource
;
89 using PictureLayerImpl::UpdateIdealScales
;
90 using PictureLayerImpl::MaximumTilingContentsScale
;
92 void AddTilingUntilNextDraw(float scale
) {
93 last_append_quads_tilings_
.push_back(AddTiling(scale
));
96 float raster_page_scale() const { return raster_page_scale_
; }
97 void set_raster_page_scale(float scale
) { raster_page_scale_
= scale
; }
99 float ideal_contents_scale() const { return ideal_contents_scale_
; }
100 float raster_contents_scale() const { return raster_contents_scale_
; }
102 PictureLayerTiling
* HighResTiling() const;
103 PictureLayerTiling
* LowResTiling() const;
104 size_t num_tilings() const { return tilings_
->num_tilings(); }
106 PictureLayerTilingSet
* tilings() { return tilings_
.get(); }
107 RasterSource
* raster_source() { return raster_source_
.get(); }
108 void SetRasterSourceOnPending(scoped_refptr
<RasterSource
> raster_source
,
109 const Region
& invalidation
);
110 size_t append_quads_count() { return append_quads_count_
; }
112 const Region
& invalidation() const { return invalidation_
; }
113 void set_invalidation(const Region
& region
) { invalidation_
= region
; }
115 gfx::Rect
visible_rect_for_tile_priority() {
116 return visible_rect_for_tile_priority_
;
119 gfx::Rect
viewport_rect_for_tile_priority_in_content_space() {
120 return viewport_rect_for_tile_priority_in_content_space_
;
123 void set_fixed_tile_size(const gfx::Size
& size
) { fixed_tile_size_
= size
; }
125 void SetIsDrawnRenderSurfaceLayerListMember(bool is
);
127 void CreateAllTiles();
128 void SetAllTilesVisible();
129 void SetAllTilesReady();
130 void SetAllTilesReadyInTiling(PictureLayerTiling
* tiling
);
131 void SetTileReady(Tile
* tile
);
132 void ResetAllTilesPriorities();
133 PictureLayerTilingSet
* GetTilings() { return tilings_
.get(); }
135 // Add the given tiling as a "used" tiling during AppendQuads. This ensures
136 // that future calls to UpdateTiles don't delete the tiling.
137 void MarkAllTilingsUsed() {
138 last_append_quads_tilings_
.clear();
139 for (size_t i
= 0; i
< tilings_
->num_tilings(); ++i
)
140 last_append_quads_tilings_
.push_back(tilings_
->tiling_at(i
));
143 size_t release_resources_count() const { return release_resources_count_
; }
144 void reset_release_resources_count() { release_resources_count_
= 0; }
146 void ReleaseResources() override
;
148 bool only_used_low_res_last_append_quads() const {
149 return only_used_low_res_last_append_quads_
;
153 FakePictureLayerImpl(LayerTreeImpl
* tree_impl
,
155 scoped_refptr
<RasterSource
> raster_source
,
157 FakePictureLayerImpl(LayerTreeImpl
* tree_impl
,
159 scoped_refptr
<RasterSource
> raster_source
,
161 const gfx::Size
& layer_bounds
);
162 FakePictureLayerImpl(LayerTreeImpl
* tree_impl
, int id
, bool is_mask
);
163 FakePictureLayerImpl(
164 LayerTreeImpl
* tree_impl
,
167 scoped_refptr
<LayerImpl::SyncedScrollOffset
> synced_scroll_offset
);
170 gfx::Size fixed_tile_size_
;
172 size_t append_quads_count_
;
173 size_t did_become_active_call_count_
;
174 bool has_valid_tile_priorities_
;
175 bool use_set_valid_tile_priorities_flag_
;
176 size_t release_resources_count_
;
181 #endif // CC_TEST_FAKE_PICTURE_LAYER_IMPL_H_