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

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 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 surface_scale_(0.f),
danakj 2016/11/28 22:26:22 can you move both of these to the .h
xlai (Olivia) 2016/12/13 17:29:18 Done.
21 scale_layer_bounds_with_surface_size_(false) {
20 layer_tree_impl()->AddSurfaceLayer(this); 22 layer_tree_impl()->AddSurfaceLayer(this);
21 } 23 }
22 24
23 SurfaceLayerImpl::~SurfaceLayerImpl() { 25 SurfaceLayerImpl::~SurfaceLayerImpl() {
24 layer_tree_impl()->RemoveSurfaceLayer(this); 26 layer_tree_impl()->RemoveSurfaceLayer(this);
25 } 27 }
26 28
27 std::unique_ptr<LayerImpl> SurfaceLayerImpl::CreateLayerImpl( 29 std::unique_ptr<LayerImpl> SurfaceLayerImpl::CreateLayerImpl(
28 LayerTreeImpl* tree_impl) { 30 LayerTreeImpl* tree_impl) {
29 return SurfaceLayerImpl::Create(tree_impl, id()); 31 return SurfaceLayerImpl::Create(tree_impl, id());
(...skipping 16 matching lines...) Expand all
46 } 48 }
47 49
48 void SurfaceLayerImpl::SetSurfaceSize(const gfx::Size& size) { 50 void SurfaceLayerImpl::SetSurfaceSize(const gfx::Size& size) {
49 if (surface_size_ == size) 51 if (surface_size_ == size)
50 return; 52 return;
51 53
52 surface_size_ = size; 54 surface_size_ = size;
53 NoteLayerPropertyChanged(); 55 NoteLayerPropertyChanged();
54 } 56 }
55 57
58 void SurfaceLayerImpl::SetScaleLayerBoundsWithSurfaceSize(
59 bool is_scaling_needed) {
60 if (scale_layer_bounds_with_surface_size_ == is_scaling_needed)
61 return;
62
63 scale_layer_bounds_with_surface_size_ = is_scaling_needed;
danakj 2016/11/28 22:26:22 You should NoteLayerPropertyChanged() when somethi
xlai (Olivia) 2016/12/13 17:29:18 Done.
64 }
65
56 void SurfaceLayerImpl::PushPropertiesTo(LayerImpl* layer) { 66 void SurfaceLayerImpl::PushPropertiesTo(LayerImpl* layer) {
57 LayerImpl::PushPropertiesTo(layer); 67 LayerImpl::PushPropertiesTo(layer);
58 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); 68 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer);
59 69
60 layer_impl->SetSurfaceId(surface_id_); 70 layer_impl->SetSurfaceId(surface_id_);
61 layer_impl->SetSurfaceSize(surface_size_); 71 layer_impl->SetSurfaceSize(surface_size_);
62 layer_impl->SetSurfaceScale(surface_scale_); 72 layer_impl->SetSurfaceScale(surface_scale_);
73 layer_impl->SetScaleLayerBoundsWithSurfaceSize(
74 scale_layer_bounds_with_surface_size_);
63 } 75 }
64 76
65 void SurfaceLayerImpl::AppendQuads(RenderPass* render_pass, 77 void SurfaceLayerImpl::AppendQuads(RenderPass* render_pass,
66 AppendQuadsData* append_quads_data) { 78 AppendQuadsData* append_quads_data) {
67 AppendRainbowDebugBorder(render_pass); 79 AppendRainbowDebugBorder(render_pass);
68 80
69 SharedQuadState* shared_quad_state = 81 SharedQuadState* shared_quad_state =
70 render_pass->CreateAndAppendSharedQuadState(); 82 render_pass->CreateAndAppendSharedQuadState();
71 PopulateScaledSharedQuadState(shared_quad_state, surface_scale_); 83
84 if (scale_layer_bounds_with_surface_size_) {
85 // When a DOM element's size in CSS style is changed and it is using
danakj 2016/11/28 22:26:22 DOM and CSS are foreign concepts to cc/ so can you
xlai (Olivia) 2016/12/13 17:29:18 Done.
86 // SurfaceLayer, it is possible that its layer bounds and surface_size
87 // are changed differently on width and height. In this case, we apply a
88 // corresponding transform on the shared_quad_state.
89 float scale_x = ((float)surface_size_.width()) / bounds().width();
danakj 2016/11/28 22:26:22 static_cast, not c-style cast
xlai (Olivia) 2016/12/13 17:29:18 Done.
90 float scale_y = ((float)surface_size_.height()) / bounds().height();
91 PopulateScaledSharedQuadState(shared_quad_state, scale_x, scale_y);
92 } else {
93 PopulateScaledSharedQuadState(shared_quad_state, surface_scale_);
94 }
72 95
73 if (!surface_id_.is_valid()) 96 if (!surface_id_.is_valid())
74 return; 97 return;
75 98
76 gfx::Rect quad_rect(surface_size_); 99 gfx::Rect quad_rect(surface_size_);
77 gfx::Rect visible_quad_rect = 100 gfx::Rect visible_quad_rect =
78 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( 101 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect(
79 quad_rect); 102 quad_rect);
103
80 if (visible_quad_rect.IsEmpty()) 104 if (visible_quad_rect.IsEmpty())
81 return; 105 return;
82 SurfaceDrawQuad* quad = 106 SurfaceDrawQuad* quad =
83 render_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); 107 render_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
84 quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, surface_id_); 108 quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, surface_id_);
85 } 109 }
86 110
87 void SurfaceLayerImpl::GetDebugBorderProperties(SkColor* color, 111 void SurfaceLayerImpl::GetDebugBorderProperties(SkColor* color,
88 float* width) const { 112 float* width) const {
89 *color = DebugColors::SurfaceLayerBorderColor(); 113 *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 { 204 void SurfaceLayerImpl::AsValueInto(base::trace_event::TracedValue* dict) const {
181 LayerImpl::AsValueInto(dict); 205 LayerImpl::AsValueInto(dict);
182 dict->SetString("surface_id", surface_id_.ToString()); 206 dict->SetString("surface_id", surface_id_.ToString());
183 } 207 }
184 208
185 const char* SurfaceLayerImpl::LayerTypeAsString() const { 209 const char* SurfaceLayerImpl::LayerTypeAsString() const {
186 return "cc::SurfaceLayerImpl"; 210 return "cc::SurfaceLayerImpl";
187 } 211 }
188 212
189 } // namespace cc 213 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698