Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: cc/layers/surface_layer_impl.cc

Issue 2495373003: Match html canvas which is transferred to OffscreenCanvas to CSS style (Closed)
Patch Set: fix compilation error Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "cc/quads/solid_color_draw_quad.h" 11 #include "cc/quads/solid_color_draw_quad.h"
12 #include "cc/quads/surface_draw_quad.h" 12 #include "cc/quads/surface_draw_quad.h"
13 #include "cc/trees/layer_tree_impl.h" 13 #include "cc/trees/layer_tree_impl.h"
14 #include "cc/trees/occlusion.h" 14 #include "cc/trees/occlusion.h"
15 15
16 namespace cc { 16 namespace cc {
17 17
18 SurfaceLayerImpl::SurfaceLayerImpl(LayerTreeImpl* tree_impl, int id) 18 SurfaceLayerImpl::SurfaceLayerImpl(LayerTreeImpl* tree_impl, int id)
19 : LayerImpl(tree_impl, id), surface_scale_(0.f) { 19 : LayerImpl(tree_impl, id) {
20 layer_tree_impl()->AddSurfaceLayer(this); 20 layer_tree_impl()->AddSurfaceLayer(this);
21 } 21 }
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());
(...skipping 16 matching lines...) Expand all
46 } 46 }
47 47
48 void SurfaceLayerImpl::SetSurfaceSize(const gfx::Size& size) { 48 void SurfaceLayerImpl::SetSurfaceSize(const gfx::Size& size) {
49 if (surface_size_ == size) 49 if (surface_size_ == size)
50 return; 50 return;
51 51
52 surface_size_ = size; 52 surface_size_ = size;
53 NoteLayerPropertyChanged(); 53 NoteLayerPropertyChanged();
54 } 54 }
55 55
56 void SurfaceLayerImpl::SetStretchContentToFillBounds(bool stretch_content) {
57 if (stretch_content_to_fill_bounds_ == stretch_content)
58 return;
59
60 stretch_content_to_fill_bounds_ = stretch_content;
61 NoteLayerPropertyChanged();
62 }
63
56 void SurfaceLayerImpl::PushPropertiesTo(LayerImpl* layer) { 64 void SurfaceLayerImpl::PushPropertiesTo(LayerImpl* layer) {
57 LayerImpl::PushPropertiesTo(layer); 65 LayerImpl::PushPropertiesTo(layer);
58 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); 66 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer);
59 67
60 layer_impl->SetSurfaceId(surface_id_); 68 layer_impl->SetSurfaceId(surface_id_);
61 layer_impl->SetSurfaceSize(surface_size_); 69 layer_impl->SetSurfaceSize(surface_size_);
62 layer_impl->SetSurfaceScale(surface_scale_); 70 layer_impl->SetSurfaceScale(surface_scale_);
71 layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_);
63 } 72 }
64 73
65 void SurfaceLayerImpl::AppendQuads(RenderPass* render_pass, 74 void SurfaceLayerImpl::AppendQuads(RenderPass* render_pass,
66 AppendQuadsData* append_quads_data) { 75 AppendQuadsData* append_quads_data) {
67 AppendRainbowDebugBorder(render_pass); 76 AppendRainbowDebugBorder(render_pass);
68 77
69 SharedQuadState* shared_quad_state = 78 SharedQuadState* shared_quad_state =
70 render_pass->CreateAndAppendSharedQuadState(); 79 render_pass->CreateAndAppendSharedQuadState();
71 PopulateScaledSharedQuadState(shared_quad_state, surface_scale_); 80
81 if (stretch_content_to_fill_bounds_) {
82 // Strecthes the surface contents to exactly fill the layer bounds,
83 // regardless of scale or aspect ratio differences.
84 float scale_x =
85 static_cast<float>(surface_size_.width()) / bounds().width();
86 float scale_y =
87 static_cast<float>(surface_size_.height()) / bounds().height();
88 PopulateScaledSharedQuadState(shared_quad_state, scale_x, scale_y);
89 } else {
90 PopulateScaledSharedQuadState(shared_quad_state, surface_scale_,
91 surface_scale_);
92 }
72 93
73 if (!surface_id_.is_valid()) 94 if (!surface_id_.is_valid())
74 return; 95 return;
75 96
76 gfx::Rect quad_rect(surface_size_); 97 gfx::Rect quad_rect(surface_size_);
77 gfx::Rect visible_quad_rect = 98 gfx::Rect visible_quad_rect =
78 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( 99 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect(
79 quad_rect); 100 quad_rect);
101
80 if (visible_quad_rect.IsEmpty()) 102 if (visible_quad_rect.IsEmpty())
81 return; 103 return;
82 SurfaceDrawQuad* quad = 104 SurfaceDrawQuad* quad =
83 render_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); 105 render_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
84 quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, surface_id_); 106 quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, surface_id_);
85 } 107 }
86 108
87 void SurfaceLayerImpl::GetDebugBorderProperties(SkColor* color, 109 void SurfaceLayerImpl::GetDebugBorderProperties(SkColor* color,
88 float* width) const { 110 float* width) const {
89 *color = DebugColors::SurfaceLayerBorderColor(); 111 *color = DebugColors::SurfaceLayerBorderColor();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 void SurfaceLayerImpl::AsValueInto(base::trace_event::TracedValue* dict) const { 202 void SurfaceLayerImpl::AsValueInto(base::trace_event::TracedValue* dict) const {
181 LayerImpl::AsValueInto(dict); 203 LayerImpl::AsValueInto(dict);
182 dict->SetString("surface_id", surface_id_.ToString()); 204 dict->SetString("surface_id", surface_id_.ToString());
183 } 205 }
184 206
185 const char* SurfaceLayerImpl::LayerTypeAsString() const { 207 const char* SurfaceLayerImpl::LayerTypeAsString() const {
186 return "cc::SurfaceLayerImpl"; 208 return "cc::SurfaceLayerImpl";
187 } 209 }
188 210
189 } // namespace cc 211 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698