• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "cc/test/tiled_layer_test_common.h"
6 
7 namespace cc {
8 
Resource(FakeLayerUpdater * layer,scoped_ptr<PrioritizedResource> texture)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();
14 }
15 
~Resource()16 FakeLayerUpdater::Resource::~Resource() {}
17 
Update(ResourceUpdateQueue * queue,gfx::Rect source_rect,gfx::Vector2d dest_offset,bool partial_update)18 void FakeLayerUpdater::Resource::Update(ResourceUpdateQueue* queue,
19                                         gfx::Rect source_rect,
20                                         gfx::Vector2d dest_offset,
21                                         bool partial_update) {
22   const gfx::Rect kRect(0, 0, 10, 10);
23   ResourceUpdate upload = ResourceUpdate::Create(
24       texture(), &bitmap_, kRect, kRect, gfx::Vector2d());
25   if (partial_update)
26     queue->AppendPartialUpload(upload);
27   else
28     queue->AppendFullUpload(upload);
29 
30   layer_->Update();
31 }
32 
FakeLayerUpdater()33 FakeLayerUpdater::FakeLayerUpdater() : prepare_count_(0), update_count_(0) {}
34 
~FakeLayerUpdater()35 FakeLayerUpdater::~FakeLayerUpdater() {}
36 
PrepareToUpdate(gfx::Rect content_rect,gfx::Size tile_size,float contents_width_scale,float contents_height_scale,gfx::Rect * resulting_opaque_rect)37 void FakeLayerUpdater::PrepareToUpdate(gfx::Rect content_rect,
38                                        gfx::Size tile_size,
39                                        float contents_width_scale,
40                                        float contents_height_scale,
41                                        gfx::Rect* resulting_opaque_rect) {
42   prepare_count_++;
43   last_update_rect_ = content_rect;
44   if (!rect_to_invalidate_.IsEmpty()) {
45     layer_->InvalidateContentRect(rect_to_invalidate_);
46     rect_to_invalidate_ = gfx::Rect();
47     layer_ = NULL;
48   }
49   *resulting_opaque_rect = opaque_paint_rect_;
50 }
51 
SetRectToInvalidate(gfx::Rect rect,FakeTiledLayer * layer)52 void FakeLayerUpdater::SetRectToInvalidate(gfx::Rect rect,
53                                            FakeTiledLayer* layer) {
54   rect_to_invalidate_ = rect;
55   layer_ = layer;
56 }
57 
CreateResource(PrioritizedResourceManager * manager)58 scoped_ptr<LayerUpdater::Resource> FakeLayerUpdater::CreateResource(
59     PrioritizedResourceManager* manager) {
60   return scoped_ptr<LayerUpdater::Resource>(
61       new Resource(this, PrioritizedResource::Create(manager)));
62 }
63 
FakeTiledLayerImpl(LayerTreeImpl * tree_impl,int id)64 FakeTiledLayerImpl::FakeTiledLayerImpl(LayerTreeImpl* tree_impl, int id)
65     : TiledLayerImpl(tree_impl, id) {}
66 
~FakeTiledLayerImpl()67 FakeTiledLayerImpl::~FakeTiledLayerImpl() {}
68 
FakeTiledLayer(PrioritizedResourceManager * resource_manager)69 FakeTiledLayer::FakeTiledLayer(PrioritizedResourceManager* resource_manager)
70     : TiledLayer(),
71       fake_updater_(make_scoped_refptr(new FakeLayerUpdater)),
72       resource_manager_(resource_manager) {
73   SetTileSize(tile_size());
74   SetTextureFormat(RGBA_8888);
75   SetBorderTexelOption(LayerTilingData::NO_BORDER_TEXELS);
76   // So that we don't get false positives if any of these
77   // tests expect to return false from DrawsContent() for other reasons.
78   SetIsDrawable(true);
79 }
80 
FakeTiledLayerWithScaledBounds(PrioritizedResourceManager * resource_manager)81 FakeTiledLayerWithScaledBounds::FakeTiledLayerWithScaledBounds(
82     PrioritizedResourceManager* resource_manager)
83     : FakeTiledLayer(resource_manager) {}
84 
~FakeTiledLayerWithScaledBounds()85 FakeTiledLayerWithScaledBounds::~FakeTiledLayerWithScaledBounds() {}
86 
~FakeTiledLayer()87 FakeTiledLayer::~FakeTiledLayer() {}
88 
SetNeedsDisplayRect(const gfx::RectF & rect)89 void FakeTiledLayer::SetNeedsDisplayRect(const gfx::RectF& rect) {
90   last_needs_display_rect_ = rect;
91   TiledLayer::SetNeedsDisplayRect(rect);
92 }
93 
SetTexturePriorities(const PriorityCalculator & calculator)94 void FakeTiledLayer::SetTexturePriorities(
95     const PriorityCalculator& calculator) {
96   // Ensure there is always a target render surface available. If none has been
97   // set (the layer is an orphan for the test), then just set a surface on
98   // itself.
99   bool missing_target_render_surface = !render_target();
100 
101   if (missing_target_render_surface)
102     CreateRenderSurface();
103 
104   TiledLayer::SetTexturePriorities(calculator);
105 
106   if (missing_target_render_surface) {
107     ClearRenderSurface();
108     draw_properties().render_target = 0;
109   }
110 }
111 
ResourceManager()112 PrioritizedResourceManager* FakeTiledLayer::ResourceManager() {
113   return resource_manager_;
114 }
115 
UpdateContentsScale(float ideal_contents_scale)116 void FakeTiledLayer::UpdateContentsScale(float ideal_contents_scale) {
117   CalculateContentsScale(ideal_contents_scale,
118                          1.f,
119                          1.f,
120                          false,  // animating_transform_to_screen
121                          &draw_properties().contents_scale_x,
122                          &draw_properties().contents_scale_y,
123                          &draw_properties().content_bounds);
124 }
125 
ResetNumDependentsNeedPushProperties()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;
132   }
133   if (replica_layer()) {
134     if (replica_layer()->needs_push_properties() ||
135         replica_layer()->descendant_needs_push_properties())
136       ++num;
137   }
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;
142   }
143   num_dependents_need_push_properties_ = num;
144 }
145 
Updater() const146 LayerUpdater* FakeTiledLayer::Updater() const {
147   return fake_updater_.get();
148 }
149 
SetContentBounds(gfx::Size content_bounds)150 void FakeTiledLayerWithScaledBounds::SetContentBounds(
151     gfx::Size content_bounds) {
152   forced_content_bounds_ = content_bounds;
153   draw_properties().content_bounds = forced_content_bounds_;
154 }
155 
CalculateContentsScale(float ideal_contents_scale,float device_scale_factor,float page_scale_factor,bool animating_transform_to_screen,float * contents_scale_x,float * contents_scale_y,gfx::Size * content_bounds)156 void FakeTiledLayerWithScaledBounds::CalculateContentsScale(
157     float ideal_contents_scale,
158     float device_scale_factor,
159     float page_scale_factor,
160     bool animating_transform_to_screen,
161     float* contents_scale_x,
162     float* contents_scale_y,
163     gfx::Size* content_bounds) {
164   *contents_scale_x =
165       static_cast<float>(forced_content_bounds_.width()) / bounds().width();
166   *contents_scale_y =
167       static_cast<float>(forced_content_bounds_.height()) / bounds().height();
168   *content_bounds = forced_content_bounds_;
169 }
170 
171 }  // namespace cc
172