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.
5 #include "cc/layers/surface_layer_impl.h"
7 #include "base/trace_event/trace_event_argument.h"
8 #include "cc/debug/debug_colors.h"
9 #include "cc/quads/surface_draw_quad.h"
10 #include "cc/trees/occlusion.h"
14 SurfaceLayerImpl::SurfaceLayerImpl(LayerTreeImpl
* tree_impl
, int id
)
15 : LayerImpl(tree_impl
, id
), surface_scale_(0.f
) {
18 SurfaceLayerImpl::~SurfaceLayerImpl() {}
20 scoped_ptr
<LayerImpl
> SurfaceLayerImpl::CreateLayerImpl(
21 LayerTreeImpl
* tree_impl
) {
22 return SurfaceLayerImpl::Create(tree_impl
, id());
25 void SurfaceLayerImpl::SetSurfaceId(SurfaceId surface_id
) {
26 if (surface_id_
== surface_id
)
29 surface_id_
= surface_id
;
30 NoteLayerPropertyChanged();
33 void SurfaceLayerImpl::SetSurfaceScale(float scale
) {
34 if (surface_scale_
== scale
)
37 surface_scale_
= scale
;
38 NoteLayerPropertyChanged();
41 void SurfaceLayerImpl::SetSurfaceSize(const gfx::Size
& size
) {
42 if (surface_size_
== size
)
46 NoteLayerPropertyChanged();
49 void SurfaceLayerImpl::PushPropertiesTo(LayerImpl
* layer
) {
50 LayerImpl::PushPropertiesTo(layer
);
51 SurfaceLayerImpl
* layer_impl
= static_cast<SurfaceLayerImpl
*>(layer
);
53 layer_impl
->SetSurfaceId(surface_id_
);
54 layer_impl
->SetSurfaceSize(surface_size_
);
55 layer_impl
->SetSurfaceScale(surface_scale_
);
58 void SurfaceLayerImpl::AppendQuads(RenderPass
* render_pass
,
59 AppendQuadsData
* append_quads_data
) {
60 SharedQuadState
* shared_quad_state
=
61 render_pass
->CreateAndAppendSharedQuadState();
62 PopulateScaledSharedQuadState(shared_quad_state
, surface_scale_
);
64 AppendDebugBorderQuad(render_pass
, surface_size_
, shared_quad_state
,
67 if (surface_id_
.is_null())
70 gfx::Rect
quad_rect(surface_size_
);
71 gfx::Rect visible_quad_rect
=
72 draw_properties().occlusion_in_content_space
.GetUnoccludedContentRect(
74 if (visible_quad_rect
.IsEmpty())
76 SurfaceDrawQuad
* quad
=
77 render_pass
->CreateAndAppendDrawQuad
<SurfaceDrawQuad
>();
78 quad
->SetNew(shared_quad_state
, quad_rect
, visible_quad_rect
, surface_id_
);
79 render_pass
->referenced_surfaces
.push_back(surface_id_
);
82 void SurfaceLayerImpl::GetDebugBorderProperties(SkColor
* color
,
84 *color
= DebugColors::SurfaceLayerBorderColor();
85 *width
= DebugColors::SurfaceLayerBorderWidth(layer_tree_impl());
88 void SurfaceLayerImpl::AsValueInto(base::trace_event::TracedValue
* dict
) const {
89 LayerImpl::AsValueInto(dict
);
90 dict
->SetInteger("surface_id", surface_id_
.id
);
93 const char* SurfaceLayerImpl::LayerTypeAsString() const {
94 return "cc::SurfaceLayerImpl";