Fix IPC fuzzer build.
[chromium-blink-merge.git] / cc / test / tiled_layer_test_common.cc
blob324feb9d321af0269b4af8c6784067d1b8405cc0
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"
7 namespace cc {
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());
24 if (partial_update)
25 queue->AppendPartialUpload(upload);
26 else
27 queue->AppendFullUpload(upload);
29 layer_->Update();
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) {
43 prepare_count_++;
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();
49 layer_ = NULL;
53 void FakeLayerUpdater::SetRectToInvalidate(const gfx::Rect& rect,
54 FakeTiledLayer* layer) {
55 rect_to_invalidate_ = rect;
56 layer_ = layer;
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)
71 : TiledLayer(),
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.
79 SetIsDrawable(true);
82 FakeTiledLayerWithScaledBounds::FakeTiledLayerWithScaledBounds(
83 PrioritizedResourceManager* resource_manager)
84 : FakeTiledLayer(resource_manager) {}
86 FakeTiledLayerWithScaledBounds::~FakeTiledLayerWithScaledBounds() {}
88 FakeTiledLayer::~FakeTiledLayer() {}
90 void FakeTiledLayer::SetNeedsDisplayRect(const gfx::RectF& 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
99 // itself.
100 bool missing_target_render_surface = !render_target();
102 if (missing_target_render_surface)
103 CreateRenderSurface();
105 TiledLayer::SetTexturePriorities(calculator);
107 if (missing_target_render_surface) {
108 ClearRenderSurface();
109 draw_properties().render_target = 0;
113 PrioritizedResourceManager* FakeTiledLayer::ResourceManager() {
114 return resource_manager_;
117 void FakeTiledLayer::UpdateContentsScale(float ideal_contents_scale) {
118 CalculateContentsScale(ideal_contents_scale,
119 &draw_properties().contents_scale_x,
120 &draw_properties().contents_scale_y,
121 &draw_properties().content_bounds);
124 void FakeTiledLayer::ResetNumDependentsNeedPushProperties() {
125 size_t num = 0;
126 if (mask_layer()) {
127 if (mask_layer()->needs_push_properties() ||
128 mask_layer()->descendant_needs_push_properties())
129 ++num;
131 if (replica_layer()) {
132 if (replica_layer()->needs_push_properties() ||
133 replica_layer()->descendant_needs_push_properties())
134 ++num;
136 for (size_t i = 0; i < children().size(); ++i) {
137 if (children()[i]->needs_push_properties() ||
138 children()[i]->descendant_needs_push_properties())
139 ++num;
141 num_dependents_need_push_properties_ = num;
144 LayerUpdater* FakeTiledLayer::Updater() const {
145 return fake_updater_.get();
148 void FakeTiledLayerWithScaledBounds::SetContentBounds(
149 const gfx::Size& content_bounds) {
150 forced_content_bounds_ = content_bounds;
151 draw_properties().content_bounds = forced_content_bounds_;
154 void FakeTiledLayerWithScaledBounds::CalculateContentsScale(
155 float ideal_contents_scale,
156 float* contents_scale_x,
157 float* contents_scale_y,
158 gfx::Size* content_bounds) {
159 *contents_scale_x =
160 static_cast<float>(forced_content_bounds_.width()) / bounds().width();
161 *contents_scale_y =
162 static_cast<float>(forced_content_bounds_.height()) / bounds().height();
163 *content_bounds = forced_content_bounds_;
166 } // namespace cc