Revert of xp: copy dbghelp.dll to output dir and have base.isolate use it there ...
[chromium-blink-merge.git] / cc / test / tiled_layer_test_common.cc
blob7d810d1ecfbca8bb52a12e59dbe21686d681ba89
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::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
99 // itself.
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() {
127 size_t num = 0;
128 if (mask_layer()) {
129 if (mask_layer()->needs_push_properties() ||
130 mask_layer()->descendant_needs_push_properties())
131 ++num;
133 if (replica_layer()) {
134 if (replica_layer()->needs_push_properties() ||
135 replica_layer()->descendant_needs_push_properties())
136 ++num;
138 for (size_t i = 0; i < children().size(); ++i) {
139 if (children()[i]->needs_push_properties() ||
140 children()[i]->descendant_needs_push_properties())
141 ++num;
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) {
161 *contents_scale_x =
162 static_cast<float>(forced_content_bounds_.width()) / bounds().width();
163 *contents_scale_y =
164 static_cast<float>(forced_content_bounds_.height()) / bounds().height();
165 *content_bounds = forced_content_bounds_;
168 } // namespace cc