• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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/surface_layer_impl.h"
6 
7 #include "cc/debug/debug_colors.h"
8 #include "cc/layers/quad_sink.h"
9 #include "cc/quads/surface_draw_quad.h"
10 
11 namespace cc {
12 
SurfaceLayerImpl(LayerTreeImpl * tree_impl,int id)13 SurfaceLayerImpl::SurfaceLayerImpl(LayerTreeImpl* tree_impl, int id)
14     : LayerImpl(tree_impl, id) {
15 }
16 
~SurfaceLayerImpl()17 SurfaceLayerImpl::~SurfaceLayerImpl() {}
18 
CreateLayerImpl(LayerTreeImpl * tree_impl)19 scoped_ptr<LayerImpl> SurfaceLayerImpl::CreateLayerImpl(
20     LayerTreeImpl* tree_impl) {
21   return SurfaceLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
22 }
23 
SetSurfaceId(SurfaceId surface_id)24 void SurfaceLayerImpl::SetSurfaceId(SurfaceId surface_id) {
25   if (surface_id_ == surface_id)
26     return;
27 
28   surface_id_ = surface_id;
29   NoteLayerPropertyChanged();
30 }
31 
PushPropertiesTo(LayerImpl * layer)32 void SurfaceLayerImpl::PushPropertiesTo(LayerImpl* layer) {
33   LayerImpl::PushPropertiesTo(layer);
34   SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer);
35 
36   layer_impl->SetSurfaceId(surface_id_);
37 }
38 
AppendQuads(QuadSink * quad_sink,AppendQuadsData * append_quads_data)39 void SurfaceLayerImpl::AppendQuads(QuadSink* quad_sink,
40                                    AppendQuadsData* append_quads_data) {
41   SharedQuadState* shared_quad_state = quad_sink->CreateSharedQuadState();
42   PopulateSharedQuadState(shared_quad_state);
43 
44   AppendDebugBorderQuad(
45       quad_sink, content_bounds(), shared_quad_state, append_quads_data);
46 
47   if (surface_id_.is_null())
48     return;
49 
50   scoped_ptr<SurfaceDrawQuad> quad = SurfaceDrawQuad::Create();
51   gfx::Rect quad_rect(content_bounds());
52   gfx::Rect visible_quad_rect = quad_sink->UnoccludedContentRect(
53       quad_rect, draw_properties().target_space_transform);
54   if (visible_quad_rect.IsEmpty())
55     return;
56   quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, surface_id_);
57   quad_sink->Append(quad.PassAs<DrawQuad>());
58 }
59 
GetDebugBorderProperties(SkColor * color,float * width) const60 void SurfaceLayerImpl::GetDebugBorderProperties(SkColor* color,
61                                                 float* width) const {
62   *color = DebugColors::SurfaceLayerBorderColor();
63   *width = DebugColors::SurfaceLayerBorderWidth(layer_tree_impl());
64 }
65 
AsValueInto(base::DictionaryValue * dict) const66 void SurfaceLayerImpl::AsValueInto(base::DictionaryValue* dict) const {
67   LayerImpl::AsValueInto(dict);
68   dict->SetInteger("surface_id", surface_id_.id);
69 }
70 
LayerTypeAsString() const71 const char* SurfaceLayerImpl::LayerTypeAsString() const {
72   return "cc::SurfaceLayerImpl";
73 }
74 
75 }  // namespace cc
76