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

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 basedd on feedback 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 is_scaling_needed) {
danakj 2016/12/15 16:13:14 nitto
57 if (stretch_content_to_fill_bounds_ == is_scaling_needed)
58 return;
59
60 stretch_content_to_fill_bounds_ = is_scaling_needed;
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 // It is possible that the surface size and its layer bounds are changed
danakj 2016/12/15 16:13:14 I think this could be more clear on its intent. Wh
danakj 2016/12/16 14:30:44 "Strecthes" => "Stretches"
83 // changed differently on width and height. In this case, we apply a
84 // corresponding transform on the shared_quad_state.
85 float scale_x =
86 static_cast<float>(surface_size_.width()) / bounds().width();
87 float scale_y =
88 static_cast<float>(surface_size_.height()) / bounds().height();
89 PopulateScaledSharedQuadState(shared_quad_state, scale_x, scale_y);
90 } else {
91 PopulateScaledSharedQuadState(shared_quad_state, surface_scale_,
92 surface_scale_);
93 }
72 94
73 if (!surface_id_.is_valid()) 95 if (!surface_id_.is_valid())
74 return; 96 return;
75 97
76 gfx::Rect quad_rect(surface_size_); 98 gfx::Rect quad_rect(surface_size_);
77 gfx::Rect visible_quad_rect = 99 gfx::Rect visible_quad_rect =
78 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( 100 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect(
79 quad_rect); 101 quad_rect);
102
80 if (visible_quad_rect.IsEmpty()) 103 if (visible_quad_rect.IsEmpty())
81 return; 104 return;
82 SurfaceDrawQuad* quad = 105 SurfaceDrawQuad* quad =
83 render_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); 106 render_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
84 quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, surface_id_); 107 quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, surface_id_);
85 } 108 }
86 109
87 void SurfaceLayerImpl::GetDebugBorderProperties(SkColor* color, 110 void SurfaceLayerImpl::GetDebugBorderProperties(SkColor* color,
88 float* width) const { 111 float* width) const {
89 *color = DebugColors::SurfaceLayerBorderColor(); 112 *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 { 203 void SurfaceLayerImpl::AsValueInto(base::trace_event::TracedValue* dict) const {
181 LayerImpl::AsValueInto(dict); 204 LayerImpl::AsValueInto(dict);
182 dict->SetString("surface_id", surface_id_.ToString()); 205 dict->SetString("surface_id", surface_id_.ToString());
183 } 206 }
184 207
185 const char* SurfaceLayerImpl::LayerTypeAsString() const { 208 const char* SurfaceLayerImpl::LayerTypeAsString() const {
186 return "cc::SurfaceLayerImpl"; 209 return "cc::SurfaceLayerImpl";
187 } 210 }
188 211
189 } // namespace cc 212 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698