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/layers/solid_color_layer_impl.h"
9 #include "cc/quads/solid_color_draw_quad.h"
10 #include "cc/trees/occlusion_tracker.h"
15 const int kSolidQuadTileSize = 256;
18 SolidColorLayerImpl::SolidColorLayerImpl(LayerTreeImpl* tree_impl, int id)
19 : LayerImpl(tree_impl, id) {
22 SolidColorLayerImpl::~SolidColorLayerImpl() {}
24 scoped_ptr<LayerImpl> SolidColorLayerImpl::CreateLayerImpl(
25 LayerTreeImpl* tree_impl) {
26 return SolidColorLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
29 void SolidColorLayerImpl::AppendSolidQuads(
30 RenderPass* render_pass,
31 const OcclusionTracker<LayerImpl>& occlusion_tracker,
32 SharedQuadState* shared_quad_state,
33 const gfx::Size& content_bounds,
34 const gfx::Transform& target_space_transform,
37 occlusion_tracker.GetCurrentOcclusionForLayer(target_space_transform);
39 // We create a series of smaller quads instead of just one large one so that
40 // the culler can reduce the total pixels drawn.
41 int width = content_bounds.width();
42 int height = content_bounds.height();
43 for (int x = 0; x < width; x += kSolidQuadTileSize) {
44 for (int y = 0; y < height; y += kSolidQuadTileSize) {
45 gfx::Rect quad_rect(x,
47 std::min(width - x, kSolidQuadTileSize),
48 std::min(height - y, kSolidQuadTileSize));
49 gfx::Rect visible_quad_rect =
50 occlusion.GetUnoccludedContentRect(quad_rect);
51 if (visible_quad_rect.IsEmpty())
54 SolidColorDrawQuad* quad =
55 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
57 shared_quad_state, quad_rect, visible_quad_rect, color, false);
62 void SolidColorLayerImpl::AppendQuads(
63 RenderPass* render_pass,
64 const OcclusionTracker<LayerImpl>& occlusion_tracker,
65 AppendQuadsData* append_quads_data) {
66 SharedQuadState* shared_quad_state =
67 render_pass->CreateAndAppendSharedQuadState();
68 PopulateSharedQuadState(shared_quad_state);
70 AppendDebugBorderQuad(
71 render_pass, content_bounds(), shared_quad_state, append_quads_data);
73 AppendSolidQuads(render_pass,
77 draw_properties().target_space_transform,
81 const char* SolidColorLayerImpl::LayerTypeAsString() const {
82 return "cc::SolidColorLayerImpl";