Upstream version 11.39.250.0
[platform/framework/web/crosswalk.git] / src / cc / layers / solid_color_layer_impl.cc
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/layers/solid_color_layer_impl.h"
6
7 #include <algorithm>
8
9 #include "cc/quads/solid_color_draw_quad.h"
10 #include "cc/trees/occlusion_tracker.h"
11
12 namespace cc {
13
14 namespace {
15 const int kSolidQuadTileSize = 256;
16 }
17
18 SolidColorLayerImpl::SolidColorLayerImpl(LayerTreeImpl* tree_impl, int id)
19     : LayerImpl(tree_impl, id) {
20 }
21
22 SolidColorLayerImpl::~SolidColorLayerImpl() {}
23
24 scoped_ptr<LayerImpl> SolidColorLayerImpl::CreateLayerImpl(
25     LayerTreeImpl* tree_impl) {
26   return SolidColorLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
27 }
28
29 void SolidColorLayerImpl::AppendSolidQuads(
30     RenderPass* render_pass,
31     const OcclusionTracker<LayerImpl>& occlusion_tracker,
32     SharedQuadState* shared_quad_state,
33     const gfx::Rect& visible_content_rect,
34     const gfx::Transform& target_space_transform,
35     SkColor color) {
36   Occlusion occlusion =
37       occlusion_tracker.GetCurrentOcclusionForLayer(target_space_transform);
38
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 right = visible_content_rect.right();
42   int bottom = visible_content_rect.bottom();
43   for (int x = visible_content_rect.x(); x < visible_content_rect.right();
44        x += kSolidQuadTileSize) {
45     for (int y = visible_content_rect.y(); y < visible_content_rect.bottom();
46          y += kSolidQuadTileSize) {
47       gfx::Rect quad_rect(x,
48                           y,
49                           std::min(right - x, kSolidQuadTileSize),
50                           std::min(bottom - y, kSolidQuadTileSize));
51       gfx::Rect visible_quad_rect =
52           occlusion.GetUnoccludedContentRect(quad_rect);
53       if (visible_quad_rect.IsEmpty())
54         continue;
55
56       SolidColorDrawQuad* quad =
57           render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
58       quad->SetNew(
59           shared_quad_state, quad_rect, visible_quad_rect, color, false);
60     }
61   }
62 }
63
64 void SolidColorLayerImpl::AppendQuads(
65     RenderPass* render_pass,
66     const OcclusionTracker<LayerImpl>& occlusion_tracker,
67     AppendQuadsData* append_quads_data) {
68   SharedQuadState* shared_quad_state =
69       render_pass->CreateAndAppendSharedQuadState();
70   PopulateSharedQuadState(shared_quad_state);
71
72   AppendDebugBorderQuad(
73       render_pass, content_bounds(), shared_quad_state, append_quads_data);
74
75   // TODO(hendrikw): We need to pass the visible content rect rather than
76   // |content_bounds()| here.
77   AppendSolidQuads(render_pass,
78                    occlusion_tracker,
79                    shared_quad_state,
80                    gfx::Rect(content_bounds()),
81                    draw_properties().target_space_transform,
82                    background_color());
83 }
84
85 const char* SolidColorLayerImpl::LayerTypeAsString() const {
86   return "cc::SolidColorLayerImpl";
87 }
88
89 }  // namespace cc