| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/layers/surface_layer_impl.h" | 5 #include "cc/layers/surface_layer_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/trace_event/trace_event_argument.h" | 9 #include "base/trace_event/trace_event_argument.h" |
| 10 #include "cc/debug/debug_colors.h" | 10 #include "cc/debug/debug_colors.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 SurfaceLayerImpl::~SurfaceLayerImpl() { | 23 SurfaceLayerImpl::~SurfaceLayerImpl() { |
| 24 layer_tree_impl()->RemoveSurfaceLayer(this); | 24 layer_tree_impl()->RemoveSurfaceLayer(this); |
| 25 } | 25 } |
| 26 | 26 |
| 27 std::unique_ptr<LayerImpl> SurfaceLayerImpl::CreateLayerImpl( | 27 std::unique_ptr<LayerImpl> SurfaceLayerImpl::CreateLayerImpl( |
| 28 LayerTreeImpl* tree_impl) { | 28 LayerTreeImpl* tree_impl) { |
| 29 return SurfaceLayerImpl::Create(tree_impl, id()); | 29 return SurfaceLayerImpl::Create(tree_impl, id()); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void SurfaceLayerImpl::SetSurfaceId(const SurfaceId& surface_id) { | 32 void SurfaceLayerImpl::SetSurfaceInfo(const SurfaceInfo& surface_info) { |
| 33 if (surface_id_ == surface_id) | 33 if (surface_info_ == surface_info) |
| 34 return; | 34 return; |
| 35 | 35 |
| 36 surface_id_ = surface_id; | 36 surface_info_ = surface_info; |
| 37 NoteLayerPropertyChanged(); | 37 NoteLayerPropertyChanged(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void SurfaceLayerImpl::SetSurfaceScale(float scale) { | |
| 41 if (surface_scale_ == scale) | |
| 42 return; | |
| 43 | |
| 44 surface_scale_ = scale; | |
| 45 NoteLayerPropertyChanged(); | |
| 46 } | |
| 47 | |
| 48 void SurfaceLayerImpl::SetSurfaceSize(const gfx::Size& size) { | |
| 49 if (surface_size_ == size) | |
| 50 return; | |
| 51 | |
| 52 surface_size_ = size; | |
| 53 NoteLayerPropertyChanged(); | |
| 54 } | |
| 55 | |
| 56 void SurfaceLayerImpl::SetStretchContentToFillBounds(bool stretch_content) { | 40 void SurfaceLayerImpl::SetStretchContentToFillBounds(bool stretch_content) { |
| 57 if (stretch_content_to_fill_bounds_ == stretch_content) | 41 if (stretch_content_to_fill_bounds_ == stretch_content) |
| 58 return; | 42 return; |
| 59 | 43 |
| 60 stretch_content_to_fill_bounds_ = stretch_content; | 44 stretch_content_to_fill_bounds_ = stretch_content; |
| 61 NoteLayerPropertyChanged(); | 45 NoteLayerPropertyChanged(); |
| 62 } | 46 } |
| 63 | 47 |
| 64 void SurfaceLayerImpl::PushPropertiesTo(LayerImpl* layer) { | 48 void SurfaceLayerImpl::PushPropertiesTo(LayerImpl* layer) { |
| 65 LayerImpl::PushPropertiesTo(layer); | 49 LayerImpl::PushPropertiesTo(layer); |
| 66 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); | 50 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); |
| 67 | 51 layer_impl->SetSurfaceInfo(surface_info_); |
| 68 layer_impl->SetSurfaceId(surface_id_); | |
| 69 layer_impl->SetSurfaceSize(surface_size_); | |
| 70 layer_impl->SetSurfaceScale(surface_scale_); | |
| 71 layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_); | 52 layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_); |
| 72 } | 53 } |
| 73 | 54 |
| 74 void SurfaceLayerImpl::AppendQuads(RenderPass* render_pass, | 55 void SurfaceLayerImpl::AppendQuads(RenderPass* render_pass, |
| 75 AppendQuadsData* append_quads_data) { | 56 AppendQuadsData* append_quads_data) { |
| 76 AppendRainbowDebugBorder(render_pass); | 57 AppendRainbowDebugBorder(render_pass); |
| 77 | 58 |
| 78 SharedQuadState* shared_quad_state = | 59 SharedQuadState* shared_quad_state = |
| 79 render_pass->CreateAndAppendSharedQuadState(); | 60 render_pass->CreateAndAppendSharedQuadState(); |
| 80 | 61 |
| 81 if (stretch_content_to_fill_bounds_) { | 62 if (stretch_content_to_fill_bounds_) { |
| 82 // Strecthes the surface contents to exactly fill the layer bounds, | 63 // Strecthes the surface contents to exactly fill the layer bounds, |
| 83 // regardless of scale or aspect ratio differences. | 64 // regardless of scale or aspect ratio differences. |
| 84 float scale_x = | 65 float scale_x = static_cast<float>(surface_info_.size_in_pixels().width()) / |
| 85 static_cast<float>(surface_size_.width()) / bounds().width(); | 66 bounds().width(); |
| 86 float scale_y = | 67 float scale_y = |
| 87 static_cast<float>(surface_size_.height()) / bounds().height(); | 68 static_cast<float>(surface_info_.size_in_pixels().height()) / |
| 69 bounds().height(); |
| 88 PopulateScaledSharedQuadState(shared_quad_state, scale_x, scale_y); | 70 PopulateScaledSharedQuadState(shared_quad_state, scale_x, scale_y); |
| 89 } else { | 71 } else { |
| 90 PopulateScaledSharedQuadState(shared_quad_state, surface_scale_, | 72 PopulateScaledSharedQuadState(shared_quad_state, |
| 91 surface_scale_); | 73 surface_info_.device_scale_factor(), |
| 74 surface_info_.device_scale_factor()); |
| 92 } | 75 } |
| 93 | 76 |
| 94 if (!surface_id_.is_valid()) | 77 if (!surface_info_.id().is_valid()) |
| 95 return; | 78 return; |
| 96 | 79 |
| 97 gfx::Rect quad_rect(surface_size_); | 80 gfx::Rect quad_rect(surface_info_.size_in_pixels()); |
| 98 gfx::Rect visible_quad_rect = | 81 gfx::Rect visible_quad_rect = |
| 99 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( | 82 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( |
| 100 quad_rect); | 83 quad_rect); |
| 101 | 84 |
| 102 if (visible_quad_rect.IsEmpty()) | 85 if (visible_quad_rect.IsEmpty()) |
| 103 return; | 86 return; |
| 104 SurfaceDrawQuad* quad = | 87 SurfaceDrawQuad* quad = |
| 105 render_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); | 88 render_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); |
| 106 quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, surface_id_); | 89 quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, |
| 90 surface_info_.id()); |
| 107 } | 91 } |
| 108 | 92 |
| 109 void SurfaceLayerImpl::GetDebugBorderProperties(SkColor* color, | 93 void SurfaceLayerImpl::GetDebugBorderProperties(SkColor* color, |
| 110 float* width) const { | 94 float* width) const { |
| 111 *color = DebugColors::SurfaceLayerBorderColor(); | 95 *color = DebugColors::SurfaceLayerBorderColor(); |
| 112 *width = DebugColors::SurfaceLayerBorderWidth(layer_tree_impl()); | 96 *width = DebugColors::SurfaceLayerBorderWidth(layer_tree_impl()); |
| 113 } | 97 } |
| 114 | 98 |
| 115 void SurfaceLayerImpl::AppendRainbowDebugBorder(RenderPass* render_pass) { | 99 void SurfaceLayerImpl::AppendRainbowDebugBorder(RenderPass* render_pass) { |
| 116 if (!ShowDebugBorders()) | 100 if (!ShowDebugBorders()) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 SolidColorDrawQuad* right_quad = | 178 SolidColorDrawQuad* right_quad = |
| 195 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); | 179 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 196 right_quad->SetNew(shared_quad_state, right, right, | 180 right_quad->SetNew(shared_quad_state, right, right, |
| 197 colors[i % kNumColors], force_anti_aliasing_off); | 181 colors[i % kNumColors], force_anti_aliasing_off); |
| 198 } | 182 } |
| 199 } | 183 } |
| 200 } | 184 } |
| 201 | 185 |
| 202 void SurfaceLayerImpl::AsValueInto(base::trace_event::TracedValue* dict) const { | 186 void SurfaceLayerImpl::AsValueInto(base::trace_event::TracedValue* dict) const { |
| 203 LayerImpl::AsValueInto(dict); | 187 LayerImpl::AsValueInto(dict); |
| 204 dict->SetString("surface_id", surface_id_.ToString()); | 188 dict->SetString("surface_id", surface_info_.id().ToString()); |
| 205 } | 189 } |
| 206 | 190 |
| 207 const char* SurfaceLayerImpl::LayerTypeAsString() const { | 191 const char* SurfaceLayerImpl::LayerTypeAsString() const { |
| 208 return "cc::SurfaceLayerImpl"; | 192 return "cc::SurfaceLayerImpl"; |
| 209 } | 193 } |
| 210 | 194 |
| 211 } // namespace cc | 195 } // namespace cc |
| OLD | NEW |