OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/layers/solid_color_layer_impl.h" | 5 #include "cc/layers/solid_color_layer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "cc/quads/solid_color_draw_quad.h" | 9 #include "cc/quads/solid_color_draw_quad.h" |
10 #include "cc/trees/occlusion_tracker.h" | 10 #include "cc/trees/occlusion_tracker.h" |
11 | 11 |
12 namespace cc { | 12 namespace cc { |
13 | 13 |
| 14 namespace { |
| 15 const int kSolidQuadTileSize = 256; |
| 16 } |
| 17 |
14 SolidColorLayerImpl::SolidColorLayerImpl(LayerTreeImpl* tree_impl, int id) | 18 SolidColorLayerImpl::SolidColorLayerImpl(LayerTreeImpl* tree_impl, int id) |
15 : LayerImpl(tree_impl, id), | 19 : LayerImpl(tree_impl, id) { |
16 tile_size_(256) {} | 20 } |
17 | 21 |
18 SolidColorLayerImpl::~SolidColorLayerImpl() {} | 22 SolidColorLayerImpl::~SolidColorLayerImpl() {} |
19 | 23 |
20 scoped_ptr<LayerImpl> SolidColorLayerImpl::CreateLayerImpl( | 24 scoped_ptr<LayerImpl> SolidColorLayerImpl::CreateLayerImpl( |
21 LayerTreeImpl* tree_impl) { | 25 LayerTreeImpl* tree_impl) { |
22 return SolidColorLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); | 26 return SolidColorLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); |
23 } | 27 } |
24 | 28 |
| 29 void SolidColorLayerImpl::AppendSolidQuads( |
| 30 RenderPass* render_pass, |
| 31 const OcclusionTracker<LayerImpl>& occlusion_tracker, |
| 32 AppendQuadsData* append_quads_data, |
| 33 SharedQuadState* shared_quad_state, |
| 34 const gfx::Size& content_bounds, |
| 35 const gfx::Transform& target_space_transform, |
| 36 SkColor color) { |
| 37 // We create a series of smaller quads instead of just one large one so that |
| 38 // the culler can reduce the total pixels drawn. |
| 39 int width = content_bounds.width(); |
| 40 int height = content_bounds.height(); |
| 41 for (int x = 0; x < width; x += kSolidQuadTileSize) { |
| 42 for (int y = 0; y < height; y += kSolidQuadTileSize) { |
| 43 gfx::Rect quad_rect(x, |
| 44 y, |
| 45 std::min(width - x, kSolidQuadTileSize), |
| 46 std::min(height - y, kSolidQuadTileSize)); |
| 47 gfx::Rect visible_quad_rect = occlusion_tracker.UnoccludedContentRect( |
| 48 quad_rect, target_space_transform); |
| 49 if (visible_quad_rect.IsEmpty()) |
| 50 continue; |
| 51 |
| 52 SolidColorDrawQuad* quad = |
| 53 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 54 quad->SetNew( |
| 55 shared_quad_state, quad_rect, visible_quad_rect, color, false); |
| 56 } |
| 57 } |
| 58 } |
| 59 |
25 void SolidColorLayerImpl::AppendQuads( | 60 void SolidColorLayerImpl::AppendQuads( |
26 RenderPass* render_pass, | 61 RenderPass* render_pass, |
27 const OcclusionTracker<LayerImpl>& occlusion_tracker, | 62 const OcclusionTracker<LayerImpl>& occlusion_tracker, |
28 AppendQuadsData* append_quads_data) { | 63 AppendQuadsData* append_quads_data) { |
29 SharedQuadState* shared_quad_state = | 64 SharedQuadState* shared_quad_state = |
30 render_pass->CreateAndAppendSharedQuadState(); | 65 render_pass->CreateAndAppendSharedQuadState(); |
31 PopulateSharedQuadState(shared_quad_state); | 66 PopulateSharedQuadState(shared_quad_state); |
32 | 67 |
33 AppendDebugBorderQuad( | 68 AppendDebugBorderQuad( |
34 render_pass, content_bounds(), shared_quad_state, append_quads_data); | 69 render_pass, content_bounds(), shared_quad_state, append_quads_data); |
35 | 70 |
36 // We create a series of smaller quads instead of just one large one so that | 71 AppendSolidQuads(render_pass, |
37 // the culler can reduce the total pixels drawn. | 72 occlusion_tracker, |
38 int width = content_bounds().width(); | 73 append_quads_data, |
39 int height = content_bounds().height(); | 74 shared_quad_state, |
40 for (int x = 0; x < width; x += tile_size_) { | 75 content_bounds(), |
41 for (int y = 0; y < height; y += tile_size_) { | 76 draw_properties().target_space_transform, |
42 gfx::Rect quad_rect(x, | 77 background_color()); |
43 y, | |
44 std::min(width - x, tile_size_), | |
45 std::min(height - y, tile_size_)); | |
46 gfx::Rect visible_quad_rect = occlusion_tracker.UnoccludedContentRect( | |
47 quad_rect, draw_properties().target_space_transform); | |
48 if (visible_quad_rect.IsEmpty()) | |
49 continue; | |
50 | |
51 SolidColorDrawQuad* quad = | |
52 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); | |
53 quad->SetNew(shared_quad_state, | |
54 quad_rect, | |
55 visible_quad_rect, | |
56 background_color(), | |
57 false); | |
58 } | |
59 } | |
60 } | 78 } |
61 | 79 |
62 const char* SolidColorLayerImpl::LayerTypeAsString() const { | 80 const char* SolidColorLayerImpl::LayerTypeAsString() const { |
63 return "cc::SolidColorLayerImpl"; | 81 return "cc::SolidColorLayerImpl"; |
64 } | 82 } |
65 | 83 |
66 } // namespace cc | 84 } // namespace cc |
OLD | NEW |