• 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 "base/debug/trace_event_argument.h"
8 #include "cc/debug/debug_colors.h"
9 #include "cc/quads/surface_draw_quad.h"
10 #include "cc/trees/occlusion_tracker.h"
11 
12 namespace cc {
13 
SurfaceLayerImpl(LayerTreeImpl * tree_impl,int id)14 SurfaceLayerImpl::SurfaceLayerImpl(LayerTreeImpl* tree_impl, int id)
15     : LayerImpl(tree_impl, id) {
16 }
17 
~SurfaceLayerImpl()18 SurfaceLayerImpl::~SurfaceLayerImpl() {}
19 
CreateLayerImpl(LayerTreeImpl * tree_impl)20 scoped_ptr<LayerImpl> SurfaceLayerImpl::CreateLayerImpl(
21     LayerTreeImpl* tree_impl) {
22   return SurfaceLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
23 }
24 
SetSurfaceId(SurfaceId surface_id)25 void SurfaceLayerImpl::SetSurfaceId(SurfaceId surface_id) {
26   if (surface_id_ == surface_id)
27     return;
28 
29   surface_id_ = surface_id;
30   NoteLayerPropertyChanged();
31 }
32 
PushPropertiesTo(LayerImpl * layer)33 void SurfaceLayerImpl::PushPropertiesTo(LayerImpl* layer) {
34   LayerImpl::PushPropertiesTo(layer);
35   SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer);
36 
37   layer_impl->SetSurfaceId(surface_id_);
38 }
39 
AppendQuads(RenderPass * render_pass,const OcclusionTracker<LayerImpl> & occlusion_tracker,AppendQuadsData * append_quads_data)40 void SurfaceLayerImpl::AppendQuads(
41     RenderPass* render_pass,
42     const OcclusionTracker<LayerImpl>& occlusion_tracker,
43     AppendQuadsData* append_quads_data) {
44   SharedQuadState* shared_quad_state =
45       render_pass->CreateAndAppendSharedQuadState();
46   PopulateSharedQuadState(shared_quad_state);
47 
48   AppendDebugBorderQuad(
49       render_pass, content_bounds(), shared_quad_state, append_quads_data);
50 
51   if (surface_id_.is_null())
52     return;
53 
54   gfx::Rect quad_rect(content_bounds());
55   gfx::Rect visible_quad_rect =
56       occlusion_tracker.GetCurrentOcclusionForLayer(
57                             draw_properties().target_space_transform)
58           .GetUnoccludedContentRect(quad_rect);
59   if (visible_quad_rect.IsEmpty())
60     return;
61   SurfaceDrawQuad* quad =
62       render_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
63   quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, surface_id_);
64 }
65 
GetDebugBorderProperties(SkColor * color,float * width) const66 void SurfaceLayerImpl::GetDebugBorderProperties(SkColor* color,
67                                                 float* width) const {
68   *color = DebugColors::SurfaceLayerBorderColor();
69   *width = DebugColors::SurfaceLayerBorderWidth(layer_tree_impl());
70 }
71 
AsValueInto(base::debug::TracedValue * dict) const72 void SurfaceLayerImpl::AsValueInto(base::debug::TracedValue* dict) const {
73   LayerImpl::AsValueInto(dict);
74   dict->SetInteger("surface_id", surface_id_.id);
75 }
76 
LayerTypeAsString() const77 const char* SurfaceLayerImpl::LayerTypeAsString() const {
78   return "cc::SurfaceLayerImpl";
79 }
80 
81 }  // namespace cc
82