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 #include "cc/test/tiled_layer_test_common.h"
9 FakeLayerUpdater::Resource::Resource(FakeLayerUpdater
* layer
,
10 scoped_ptr
<PrioritizedResource
> texture
)
11 : LayerUpdater::Resource(texture
.Pass()), layer_(layer
) {
12 bitmap_
.allocN32Pixels(10, 10);
15 FakeLayerUpdater::Resource::~Resource() {}
17 void FakeLayerUpdater::Resource::Update(ResourceUpdateQueue
* queue
,
18 const gfx::Rect
& source_rect
,
19 const gfx::Vector2d
& dest_offset
,
20 bool partial_update
) {
21 const gfx::Rect
kRect(0, 0, 10, 10);
22 ResourceUpdate upload
= ResourceUpdate::Create(
23 texture(), &bitmap_
, kRect
, kRect
, gfx::Vector2d());
25 queue
->AppendPartialUpload(upload
);
27 queue
->AppendFullUpload(upload
);
32 FakeLayerUpdater::FakeLayerUpdater()
33 : prepare_count_(0), update_count_(0), last_contents_width_scale_(0.f
) {
36 FakeLayerUpdater::~FakeLayerUpdater() {}
38 void FakeLayerUpdater::PrepareToUpdate(const gfx::Size
& content_size
,
39 const gfx::Rect
& paint_rect
,
40 const gfx::Size
& tile_size
,
41 float contents_width_scale
,
42 float contents_height_scale
) {
44 last_update_rect_
= paint_rect
;
45 last_contents_width_scale_
= contents_width_scale
;
46 if (!rect_to_invalidate_
.IsEmpty()) {
47 layer_
->InvalidateContentRect(rect_to_invalidate_
);
48 rect_to_invalidate_
= gfx::Rect();
53 void FakeLayerUpdater::SetRectToInvalidate(const gfx::Rect
& rect
,
54 FakeTiledLayer
* layer
) {
55 rect_to_invalidate_
= rect
;
59 scoped_ptr
<LayerUpdater::Resource
> FakeLayerUpdater::CreateResource(
60 PrioritizedResourceManager
* manager
) {
61 return make_scoped_ptr(
62 new Resource(this, PrioritizedResource::Create(manager
)));
65 FakeTiledLayerImpl::FakeTiledLayerImpl(LayerTreeImpl
* tree_impl
, int id
)
66 : TiledLayerImpl(tree_impl
, id
) {}
68 FakeTiledLayerImpl::~FakeTiledLayerImpl() {}
70 FakeTiledLayer::FakeTiledLayer(PrioritizedResourceManager
* resource_manager
)
72 fake_updater_(make_scoped_refptr(new FakeLayerUpdater
)),
73 resource_manager_(resource_manager
) {
74 SetTileSize(tile_size());
75 SetTextureFormat(RGBA_8888
);
76 SetBorderTexelOption(LayerTilingData::NO_BORDER_TEXELS
);
77 // So that we don't get false positives if any of these
78 // tests expect to return false from DrawsContent() for other reasons.
82 FakeTiledLayerWithScaledBounds::FakeTiledLayerWithScaledBounds(
83 PrioritizedResourceManager
* resource_manager
)
84 : FakeTiledLayer(resource_manager
) {}
86 FakeTiledLayerWithScaledBounds::~FakeTiledLayerWithScaledBounds() {}
88 FakeTiledLayer::~FakeTiledLayer() {}
90 void FakeTiledLayer::SetNeedsDisplayRect(const gfx::Rect
& rect
) {
91 last_needs_display_rect_
= rect
;
92 TiledLayer::SetNeedsDisplayRect(rect
);
95 void FakeTiledLayer::SetTexturePriorities(
96 const PriorityCalculator
& calculator
) {
97 // Ensure there is always a target render surface available. If none has been
98 // set (the layer is an orphan for the test), then just set a surface on
100 bool missing_target_render_surface
= !render_target();
102 if (missing_target_render_surface
) {
103 CreateRenderSurface();
104 draw_properties().render_target
= this;
107 TiledLayer::SetTexturePriorities(calculator
);
109 if (missing_target_render_surface
) {
110 ClearRenderSurface();
111 draw_properties().render_target
= 0;
115 PrioritizedResourceManager
* FakeTiledLayer::ResourceManager() {
116 return resource_manager_
;
119 void FakeTiledLayer::UpdateContentsScale(float ideal_contents_scale
) {
120 CalculateContentsScale(ideal_contents_scale
,
121 &draw_properties().contents_scale_x
,
122 &draw_properties().contents_scale_y
,
123 &draw_properties().content_bounds
);
126 void FakeTiledLayer::ResetNumDependentsNeedPushProperties() {
129 if (mask_layer()->needs_push_properties() ||
130 mask_layer()->descendant_needs_push_properties())
133 if (replica_layer()) {
134 if (replica_layer()->needs_push_properties() ||
135 replica_layer()->descendant_needs_push_properties())
138 for (size_t i
= 0; i
< children().size(); ++i
) {
139 if (children()[i
]->needs_push_properties() ||
140 children()[i
]->descendant_needs_push_properties())
143 num_dependents_need_push_properties_
= num
;
146 LayerUpdater
* FakeTiledLayer::Updater() const {
147 return fake_updater_
.get();
150 void FakeTiledLayerWithScaledBounds::SetContentBounds(
151 const gfx::Size
& content_bounds
) {
152 forced_content_bounds_
= content_bounds
;
153 draw_properties().content_bounds
= forced_content_bounds_
;
156 void FakeTiledLayerWithScaledBounds::CalculateContentsScale(
157 float ideal_contents_scale
,
158 float* contents_scale_x
,
159 float* contents_scale_y
,
160 gfx::Size
* content_bounds
) {
162 static_cast<float>(forced_content_bounds_
.width()) / bounds().width();
164 static_cast<float>(forced_content_bounds_
.height()) / bounds().height();
165 *content_bounds
= forced_content_bounds_
;