surface_layer_impl.cc revision 5f1c94371a64b3196d4be9466099bb892df9b88e
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
12namespace cc {
13
14SurfaceLayerImpl::SurfaceLayerImpl(LayerTreeImpl* tree_impl, int id)
15    : LayerImpl(tree_impl, id) {
16}
17
18SurfaceLayerImpl::~SurfaceLayerImpl() {}
19
20scoped_ptr<LayerImpl> SurfaceLayerImpl::CreateLayerImpl(
21    LayerTreeImpl* tree_impl) {
22  return SurfaceLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
23}
24
25void SurfaceLayerImpl::SetSurfaceId(SurfaceId surface_id) {
26  if (surface_id_ == surface_id)
27    return;
28
29  surface_id_ = surface_id;
30  NoteLayerPropertyChanged();
31}
32
33void 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
40void 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 = occlusion_tracker.UnoccludedContentRect(
56      quad_rect, draw_properties().target_space_transform);
57  if (visible_quad_rect.IsEmpty())
58    return;
59  SurfaceDrawQuad* quad =
60      render_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
61  quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, surface_id_);
62}
63
64void SurfaceLayerImpl::GetDebugBorderProperties(SkColor* color,
65                                                float* width) const {
66  *color = DebugColors::SurfaceLayerBorderColor();
67  *width = DebugColors::SurfaceLayerBorderWidth(layer_tree_impl());
68}
69
70void SurfaceLayerImpl::AsValueInto(base::debug::TracedValue* dict) const {
71  LayerImpl::AsValueInto(dict);
72  dict->SetInteger("surface_id", surface_id_.id);
73}
74
75const char* SurfaceLayerImpl::LayerTypeAsString() const {
76  return "cc::SurfaceLayerImpl";
77}
78
79}  // namespace cc
80