Fix a type mismatch on Windows caused by r201738.
[chromium-blink-merge.git] / cc / test / tiled_layer_test_common.cc
blob0d84090c50428ac9c53a7e8b3dedfd808cd56bc1
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_.setConfig(SkBitmap::kARGB_8888_Config, 10, 10);
13 bitmap_.allocPixels();
16 FakeLayerUpdater::Resource::~Resource() {}
18 void FakeLayerUpdater::Resource::Update(ResourceUpdateQueue* queue,
19 gfx::Rect source_rect,
20 gfx::Vector2d dest_offset,
21 bool partial_update,
22 RenderingStats* stats) {
23 const gfx::Rect kRect(0, 0, 10, 10);
24 ResourceUpdate upload = ResourceUpdate::Create(
25 texture(), &bitmap_, kRect, kRect, gfx::Vector2d());
26 if (partial_update)
27 queue->AppendPartialUpload(upload);
28 else
29 queue->AppendFullUpload(upload);
31 layer_->Update();
34 FakeLayerUpdater::FakeLayerUpdater() : prepare_count_(0), update_count_(0) {}
36 FakeLayerUpdater::~FakeLayerUpdater() {}
38 void FakeLayerUpdater::PrepareToUpdate(gfx::Rect content_rect,
39 gfx::Size tile_size,
40 float contents_width_scale,
41 float contents_height_scale,
42 gfx::Rect* resulting_opaque_rect,
43 RenderingStats* stats) {
44 prepare_count_++;
45 last_update_rect_ = content_rect;
46 if (!rect_to_invalidate_.IsEmpty()) {
47 layer_->InvalidateContentRect(rect_to_invalidate_);
48 rect_to_invalidate_ = gfx::Rect();
49 layer_ = NULL;
51 *resulting_opaque_rect = opaque_paint_rect_;
54 void FakeLayerUpdater::SetRectToInvalidate(gfx::Rect rect,
55 FakeTiledLayer* layer) {
56 rect_to_invalidate_ = rect;
57 layer_ = layer;
60 scoped_ptr<LayerUpdater::Resource> FakeLayerUpdater::CreateResource(
61 PrioritizedResourceManager* manager) {
62 return scoped_ptr<LayerUpdater::Resource>(
63 new Resource(this, PrioritizedResource::Create(manager)));
66 FakeTiledLayerImpl::FakeTiledLayerImpl(LayerTreeImpl* tree_impl, int id)
67 : TiledLayerImpl(tree_impl, id) {}
69 FakeTiledLayerImpl::~FakeTiledLayerImpl() {}
71 FakeTiledLayer::FakeTiledLayer(PrioritizedResourceManager* resource_manager)
72 : TiledLayer(),
73 fake_updater_(make_scoped_refptr(new FakeLayerUpdater)),
74 resource_manager_(resource_manager) {
75 SetTileSize(tile_size());
76 SetTextureFormat(GL_RGBA);
77 SetBorderTexelOption(LayerTilingData::NO_BORDER_TEXELS);
78 // So that we don't get false positives if any of these
79 // tests expect to return false from DrawsContent() for other reasons.
80 SetIsDrawable(true);
83 FakeTiledLayerWithScaledBounds::FakeTiledLayerWithScaledBounds(
84 PrioritizedResourceManager* resource_manager)
85 : FakeTiledLayer(resource_manager) {}
87 FakeTiledLayerWithScaledBounds::~FakeTiledLayerWithScaledBounds() {}
89 FakeTiledLayer::~FakeTiledLayer() {}
91 void FakeTiledLayer::SetNeedsDisplayRect(const gfx::RectF& rect) {
92 last_needs_display_rect_ = rect;
93 TiledLayer::SetNeedsDisplayRect(rect);
96 void FakeTiledLayer::SetTexturePriorities(
97 const PriorityCalculator& calculator) {
98 // Ensure there is always a target render surface available. If none has been
99 // set (the layer is an orphan for the test), then just set a surface on
100 // itself.
101 bool missing_target_render_surface = !render_target();
103 if (missing_target_render_surface)
104 CreateRenderSurface();
106 TiledLayer::SetTexturePriorities(calculator);
108 if (missing_target_render_surface) {
109 ClearRenderSurface();
110 draw_properties().render_target = 0;
114 PrioritizedResourceManager* FakeTiledLayer::ResourceManager() const {
115 return resource_manager_;
118 void FakeTiledLayer::UpdateContentsScale(float ideal_contents_scale) {
119 CalculateContentsScale(ideal_contents_scale,
120 1.f,
121 1.f,
122 false, // animating_transform_to_screen
123 &draw_properties().contents_scale_x,
124 &draw_properties().contents_scale_y,
125 &draw_properties().content_bounds);
128 LayerUpdater* FakeTiledLayer::Updater() const {
129 return fake_updater_.get();
132 void FakeTiledLayerWithScaledBounds::SetContentBounds(
133 gfx::Size content_bounds) {
134 forced_content_bounds_ = content_bounds;
135 draw_properties().content_bounds = forced_content_bounds_;
138 void FakeTiledLayerWithScaledBounds::CalculateContentsScale(
139 float ideal_contents_scale,
140 float device_scale_factor,
141 float page_scale_factor,
142 bool animating_transform_to_screen,
143 float* contents_scale_x,
144 float* contents_scale_y,
145 gfx::Size* content_bounds) {
146 *contents_scale_x =
147 static_cast<float>(forced_content_bounds_.width()) / bounds().width();
148 *contents_scale_y =
149 static_cast<float>(forced_content_bounds_.height()) / bounds().height();
150 *content_bounds = forced_content_bounds_;
153 } // namespace cc