[email protected] | 5e5648a | 2013-11-18 00:39:33 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors. All rights reserved. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 5 | #include "cc/layers/layer_impl.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
| 9 | |
vollick | 83fbfc8 | 2016-03-22 18:33:27 | [diff] [blame] | 10 | #include <algorithm> |
dcheng | f9c838e | 2015-12-18 08:10:12 | [diff] [blame] | 11 | #include <utility> |
| 12 | |
[email protected] | 9f3be43 | 2013-12-03 03:53:22 | [diff] [blame] | 13 | #include "base/json/json_reader.h" |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 14 | #include "base/memory/ptr_util.h" |
vmpstr | 91e2309 | 2015-06-08 22:24:16 | [diff] [blame] | 15 | #include "base/numerics/safe_conversions.h" |
[email protected] | 8e61d4b | 2013-06-10 22:11:48 | [diff] [blame] | 16 | #include "base/strings/stringprintf.h" |
primiano | c06e238 | 2015-01-28 04:21:49 | [diff] [blame] | 17 | #include "base/trace_event/trace_event.h" |
| 18 | #include "base/trace_event/trace_event_argument.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 19 | #include "cc/base/math_util.h" |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 20 | #include "cc/base/simple_enclosed_region.h" |
chrishtr | 82b5d950 | 2017-03-20 18:25:33 | [diff] [blame] | 21 | #include "cc/benchmarks/micro_benchmark_impl.h" |
[email protected] | 6e84de2 | 2013-03-18 06:54:27 | [diff] [blame] | 22 | #include "cc/debug/debug_colors.h" |
| 23 | #include "cc/debug/layer_tree_debug_state.h" |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 24 | #include "cc/input/main_thread_scrolling_reason.h" |
tdresser | d9e20147 | 2015-07-31 13:15:07 | [diff] [blame] | 25 | #include "cc/input/scroll_state.h" |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 26 | #include "cc/layers/layer.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 27 | #include "cc/trees/clip_node.h" |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 28 | #include "cc/trees/draw_property_utils.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 29 | #include "cc/trees/effect_node.h" |
[email protected] | 3d86dd7a | 2014-01-24 01:33:11 | [diff] [blame] | 30 | #include "cc/trees/layer_tree_host_common.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 31 | #include "cc/trees/layer_tree_impl.h" |
| 32 | #include "cc/trees/layer_tree_settings.h" |
loyso | 6bd8b61 | 2016-11-11 07:00:02 | [diff] [blame] | 33 | #include "cc/trees/mutable_properties.h" |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 34 | #include "cc/trees/mutator_host.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 35 | #include "cc/trees/proxy.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 36 | #include "cc/trees/scroll_node.h" |
| 37 | #include "cc/trees/transform_node.h" |
danakj | f20f450 | 2017-09-26 17:13:31 | [diff] [blame^] | 38 | #include "components/viz/common/frame_sinks/copy_output_request.h" |
danakj | e5805be | 2017-09-15 19:24:55 | [diff] [blame] | 39 | #include "components/viz/common/quads/debug_border_draw_quad.h" |
| 40 | #include "components/viz/common/quads/render_pass.h" |
Alex Zhang | dd188a1 | 2017-08-14 18:48:44 | [diff] [blame] | 41 | #include "components/viz/common/traced_value.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 42 | #include "ui/gfx/geometry/point_conversions.h" |
| 43 | #include "ui/gfx/geometry/quad_f.h" |
| 44 | #include "ui/gfx/geometry/rect_conversions.h" |
| 45 | #include "ui/gfx/geometry/size_conversions.h" |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 46 | #include "ui/gfx/geometry/vector2d_conversions.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 47 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 48 | namespace cc { |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 49 | LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, int id) |
jaydasika | f419bf7 | 2016-06-15 10:21:21 | [diff] [blame] | 50 | : layer_id_(id), |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 51 | layer_tree_impl_(tree_impl), |
jaydasika | 38be7a82 | 2016-04-21 16:07:06 | [diff] [blame] | 52 | test_properties_(nullptr), |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 53 | main_thread_scrolling_reasons_( |
| 54 | MainThreadScrollingReason::kNotScrollingOnMain), |
pdr | bf2f6faf | 2017-06-06 18:00:40 | [diff] [blame] | 55 | scrollable_(false), |
enne | e95b154 | 2015-04-20 20:35:50 | [diff] [blame] | 56 | should_flatten_transform_from_property_tree_(false), |
wutao | bb1af5a | 2017-08-16 17:35:35 | [diff] [blame] | 57 | layer_property_changed_not_from_property_trees_(false), |
| 58 | layer_property_changed_from_property_trees_(false), |
sadrul | 32d1097 | 2016-07-30 05:26:21 | [diff] [blame] | 59 | may_contain_video_(false), |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 60 | masks_to_bounds_(false), |
| 61 | contents_opaque_(false), |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 62 | use_parent_backface_visibility_(false), |
jaydasika | 62bd3dd | 2016-02-04 18:52:55 | [diff] [blame] | 63 | should_check_backface_visibility_(false), |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 64 | draws_content_(false), |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 65 | contributes_to_drawn_render_surface_(false), |
Hayley Ferr | 7bfdda3 | 2017-06-19 18:55:46 | [diff] [blame] | 66 | should_hit_test_(false), |
David Bokan | ff56333 | 2017-08-15 21:19:19 | [diff] [blame] | 67 | is_resized_by_browser_controls_(false), |
pdr | 6280cc1 | 2017-05-10 23:22:47 | [diff] [blame] | 68 | viewport_layer_type_(NOT_VIEWPORT_LAYER), |
[email protected] | c55f3fc | 2013-12-10 05:48:48 | [diff] [blame] | 69 | background_color_(0), |
jaydasika | c6326bb | 2016-03-03 03:46:14 | [diff] [blame] | 70 | safe_opaque_background_color_(0), |
jaydasika | dba9f75 | 2016-07-26 20:35:34 | [diff] [blame] | 71 | transform_tree_index_(TransformTree::kInvalidNodeId), |
| 72 | effect_tree_index_(EffectTree::kInvalidNodeId), |
| 73 | clip_tree_index_(ClipTree::kInvalidNodeId), |
| 74 | scroll_tree_index_(ScrollTree::kInvalidNodeId), |
vmpstr | 3d1d72c | 2015-01-26 18:27:40 | [diff] [blame] | 75 | current_draw_mode_(DRAW_MODE_NONE), |
vollick | fd6e4f4a | 2016-01-22 19:13:29 | [diff] [blame] | 76 | mutable_properties_(MutableProperty::kNone), |
primiano | cb1afb3 | 2016-02-29 20:46:05 | [diff] [blame] | 77 | debug_info_(nullptr), |
vmpstr | 6e8dd7c | 2016-06-21 00:59:58 | [diff] [blame] | 78 | has_will_change_transform_hint_(false), |
David Reveman | 0d133634 | 2017-09-12 17:05:40 | [diff] [blame] | 79 | trilinear_filtering_(false), |
bokan | 169f5ad | 2016-10-30 16:32:48 | [diff] [blame] | 80 | needs_push_properties_(false), |
skobes | 56451775d | 2017-03-28 18:46:38 | [diff] [blame] | 81 | scrollbars_hidden_(false), |
jaydasika | af0dcd17 | 2017-05-01 17:37:17 | [diff] [blame] | 82 | needs_show_scrollbars_(false), |
Chris Harrelson | daececa4 | 2017-06-16 20:42:02 | [diff] [blame] | 83 | raster_even_if_not_drawn_(false), |
| 84 | has_transform_node_(false) { |
[email protected] | bf691c2 | 2013-03-26 21:15:06 | [diff] [blame] | 85 | DCHECK_GT(layer_id_, 0); |
loyso | 9556c73 | 2016-03-11 07:54:58 | [diff] [blame] | 86 | |
bokan | e1aab12 | 2017-03-09 20:03:57 | [diff] [blame] | 87 | DCHECK(layer_tree_impl_); |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 88 | layer_tree_impl_->RegisterLayer(this); |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 89 | layer_tree_impl_->AddToElementMap(this); |
vollick | 9c7f6d0 | 2016-01-08 04:36:38 | [diff] [blame] | 90 | |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 91 | SetNeedsPushProperties(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 92 | } |
| 93 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 94 | LayerImpl::~LayerImpl() { |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 95 | DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_); |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 96 | layer_tree_impl_->UnregisterLayer(this); |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 97 | layer_tree_impl_->RemoveFromElementMap(this); |
[email protected] | f5ad428 | 2014-02-15 14:23:16 | [diff] [blame] | 98 | TRACE_EVENT_OBJECT_DELETED_WITH_ID( |
[email protected] | b4dc3647 | 2014-02-26 02:48:25 | [diff] [blame] | 99 | TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 100 | } |
| 101 | |
vmpstr | d6dce260 | 2016-05-18 20:19:04 | [diff] [blame] | 102 | void LayerImpl::SetHasWillChangeTransformHint(bool has_will_change) { |
vmpstr | d6dce260 | 2016-05-18 20:19:04 | [diff] [blame] | 103 | has_will_change_transform_hint_ = has_will_change; |
vmpstr | d6dce260 | 2016-05-18 20:19:04 | [diff] [blame] | 104 | } |
| 105 | |
David Reveman | 0d133634 | 2017-09-12 17:05:40 | [diff] [blame] | 106 | void LayerImpl::SetTrilinearFiltering(bool trilinear_filtering) { |
| 107 | trilinear_filtering_ = trilinear_filtering; |
| 108 | } |
chrishtr | cde557b6 | 2016-10-19 19:04:01 | [diff] [blame] | 109 | |
loyso | 6d6356e | 2016-11-02 23:41:08 | [diff] [blame] | 110 | MutatorHost* LayerImpl::GetMutatorHost() const { |
| 111 | return layer_tree_impl_ ? layer_tree_impl_->mutator_host() : nullptr; |
khushalsagar | af222d9 | 2016-07-08 21:19:32 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | ElementListType LayerImpl::GetElementTypeForAnimation() const { |
| 115 | return IsActive() ? ElementListType::ACTIVE : ElementListType::PENDING; |
| 116 | } |
| 117 | |
[email protected] | 9f3be43 | 2013-12-03 03:53:22 | [diff] [blame] | 118 | void LayerImpl::SetDebugInfo( |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 119 | std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info) { |
primiano | cb1afb3 | 2016-02-29 20:46:05 | [diff] [blame] | 120 | owned_debug_info_ = std::move(debug_info); |
| 121 | debug_info_ = owned_debug_info_.get(); |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 122 | SetNeedsPushProperties(); |
[email protected] | 9f3be43 | 2013-12-03 03:53:22 | [diff] [blame] | 123 | } |
| 124 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 125 | void LayerImpl::SetTransformTreeIndex(int index) { |
| 126 | transform_tree_index_ = index; |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | void LayerImpl::SetClipTreeIndex(int index) { |
| 130 | clip_tree_index_ = index; |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 131 | } |
| 132 | |
weiliangc | 6a52f30 | 2015-08-18 16:29:35 | [diff] [blame] | 133 | void LayerImpl::SetEffectTreeIndex(int index) { |
| 134 | effect_tree_index_ = index; |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 135 | } |
| 136 | |
sunxd | 47c2a0e3 | 2016-07-25 15:34:10 | [diff] [blame] | 137 | int LayerImpl::render_target_effect_tree_index() const { |
wkorman | 5a126a5 | 2017-01-06 18:41:13 | [diff] [blame] | 138 | EffectNode* effect_node = GetEffectTree().Node(effect_tree_index_); |
ajuma | 6b96f4cc4 | 2017-02-23 14:07:12 | [diff] [blame] | 139 | |
| 140 | return GetEffectTree().GetRenderSurface(effect_tree_index_) |
| 141 | ? effect_node->id |
| 142 | : effect_node->target_id; |
sunxd | 47c2a0e3 | 2016-07-25 15:34:10 | [diff] [blame] | 143 | } |
| 144 | |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 145 | void LayerImpl::SetScrollTreeIndex(int index) { |
| 146 | scroll_tree_index_ = index; |
sunxd | ea1df78 | 2016-01-28 00:12:33 | [diff] [blame] | 147 | } |
| 148 | |
yiyix | 10141eca | 2017-09-05 20:36:52 | [diff] [blame] | 149 | void LayerImpl::PopulateSharedQuadState(viz::SharedQuadState* state, |
| 150 | bool contents_opaque) const { |
sunxd | f086659 | 2017-04-21 17:01:57 | [diff] [blame] | 151 | state->SetAll(draw_properties_.target_space_transform, gfx::Rect(bounds()), |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 152 | draw_properties_.visible_layer_rect, draw_properties_.clip_rect, |
yiyix | 10141eca | 2017-09-05 20:36:52 | [diff] [blame] | 153 | draw_properties_.is_clipped, contents_opaque, |
| 154 | draw_properties_.opacity, SkBlendMode::kSrcOver, |
| 155 | GetSortingContextId()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 156 | } |
| 157 | |
yiyix | 10141eca | 2017-09-05 20:36:52 | [diff] [blame] | 158 | void LayerImpl::PopulateScaledSharedQuadState(viz::SharedQuadState* state, |
| 159 | float layer_to_content_scale_x, |
| 160 | float layer_to_content_scale_y, |
| 161 | bool contents_opaque) const { |
enne | 467829b | 2015-02-13 02:39:34 | [diff] [blame] | 162 | gfx::Transform scaled_draw_transform = |
| 163 | draw_properties_.target_space_transform; |
xlai | 5e87e71 | 2016-12-16 02:10:25 | [diff] [blame] | 164 | scaled_draw_transform.Scale(SK_MScalar1 / layer_to_content_scale_x, |
| 165 | SK_MScalar1 / layer_to_content_scale_y); |
| 166 | gfx::Size scaled_bounds = gfx::ScaleToCeiledSize( |
| 167 | bounds(), layer_to_content_scale_x, layer_to_content_scale_y); |
| 168 | gfx::Rect scaled_visible_layer_rect = gfx::ScaleToEnclosingRect( |
| 169 | visible_layer_rect(), layer_to_content_scale_x, layer_to_content_scale_y); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 170 | scaled_visible_layer_rect.Intersect(gfx::Rect(scaled_bounds)); |
enne | 467829b | 2015-02-13 02:39:34 | [diff] [blame] | 171 | |
sunxd | f086659 | 2017-04-21 17:01:57 | [diff] [blame] | 172 | state->SetAll(scaled_draw_transform, gfx::Rect(scaled_bounds), |
| 173 | scaled_visible_layer_rect, draw_properties().clip_rect, |
yiyix | 10141eca | 2017-09-05 20:36:52 | [diff] [blame] | 174 | draw_properties().is_clipped, contents_opaque, |
| 175 | draw_properties().opacity, SkBlendMode::kSrcOver, |
| 176 | GetSortingContextId()); |
enne | 467829b | 2015-02-13 02:39:34 | [diff] [blame] | 177 | } |
| 178 | |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 179 | bool LayerImpl::WillDraw(DrawMode draw_mode, |
| 180 | ResourceProvider* resource_provider) { |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 181 | // WillDraw/DidDraw must be matched. |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 182 | DCHECK_NE(DRAW_MODE_NONE, draw_mode); |
| 183 | DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_); |
| 184 | current_draw_mode_ = draw_mode; |
| 185 | return true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 186 | } |
| 187 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 188 | void LayerImpl::DidDraw(ResourceProvider* resource_provider) { |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 189 | DCHECK_NE(DRAW_MODE_NONE, current_draw_mode_); |
| 190 | current_draw_mode_ = DRAW_MODE_NONE; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 191 | } |
| 192 | |
reveman | 5be07ac8 | 2017-04-14 01:06:05 | [diff] [blame] | 193 | bool LayerImpl::ShowDebugBorders(DebugBorderType type) const { |
| 194 | return layer_tree_impl()->debug_state().show_debug_borders.test(type); |
[email protected] | 3dce3723 | 2012-11-15 01:47:44 | [diff] [blame] | 195 | } |
| 196 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 197 | void LayerImpl::GetDebugBorderProperties(SkColor* color, float* width) const { |
chrishtr | ac41ff9 | 2017-03-17 05:07:30 | [diff] [blame] | 198 | float device_scale_factor = |
| 199 | layer_tree_impl() ? layer_tree_impl()->device_scale_factor() : 1; |
| 200 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 201 | if (draws_content_) { |
| 202 | *color = DebugColors::ContentLayerBorderColor(); |
chrishtr | ac41ff9 | 2017-03-17 05:07:30 | [diff] [blame] | 203 | *width = DebugColors::ContentLayerBorderWidth(device_scale_factor); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 204 | return; |
| 205 | } |
| 206 | |
| 207 | if (masks_to_bounds_) { |
| 208 | *color = DebugColors::MaskingLayerBorderColor(); |
chrishtr | ac41ff9 | 2017-03-17 05:07:30 | [diff] [blame] | 209 | *width = DebugColors::MaskingLayerBorderWidth(device_scale_factor); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 210 | return; |
| 211 | } |
| 212 | |
| 213 | *color = DebugColors::ContainerLayerBorderColor(); |
chrishtr | ac41ff9 | 2017-03-17 05:07:30 | [diff] [blame] | 214 | *width = DebugColors::ContainerLayerBorderWidth(device_scale_factor); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | void LayerImpl::AppendDebugBorderQuad( |
danakj | e5805be | 2017-09-15 19:24:55 | [diff] [blame] | 218 | viz::RenderPass* render_pass, |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 219 | const gfx::Size& bounds, |
Alex Zhang | abad229 | 2017-08-23 21:55:19 | [diff] [blame] | 220 | const viz::SharedQuadState* shared_quad_state, |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 221 | AppendQuadsData* append_quads_data) const { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 222 | SkColor color; |
| 223 | float width; |
| 224 | GetDebugBorderProperties(&color, &width); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 225 | AppendDebugBorderQuad(render_pass, bounds, shared_quad_state, |
| 226 | append_quads_data, color, width); |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 227 | } |
| 228 | |
Alex Zhang | abad229 | 2017-08-23 21:55:19 | [diff] [blame] | 229 | void LayerImpl::AppendDebugBorderQuad( |
danakj | e5805be | 2017-09-15 19:24:55 | [diff] [blame] | 230 | viz::RenderPass* render_pass, |
Alex Zhang | abad229 | 2017-08-23 21:55:19 | [diff] [blame] | 231 | const gfx::Size& bounds, |
| 232 | const viz::SharedQuadState* shared_quad_state, |
| 233 | AppendQuadsData* append_quads_data, |
| 234 | SkColor color, |
| 235 | float width) const { |
reveman | 5be07ac8 | 2017-04-14 01:06:05 | [diff] [blame] | 236 | if (!ShowDebugBorders(DebugBorderType::LAYER)) |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 237 | return; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 238 | |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 239 | gfx::Rect quad_rect(bounds); |
[email protected] | 9bf06c7 | 2014-03-07 18:16:24 | [diff] [blame] | 240 | gfx::Rect visible_quad_rect(quad_rect); |
danakj | e5805be | 2017-09-15 19:24:55 | [diff] [blame] | 241 | auto* debug_border_quad = |
| 242 | render_pass->CreateAndAppendDrawQuad<viz::DebugBorderDrawQuad>(); |
[email protected] | 9bf06c7 | 2014-03-07 18:16:24 | [diff] [blame] | 243 | debug_border_quad->SetNew( |
| 244 | shared_quad_state, quad_rect, visible_quad_rect, color, width); |
danakj | 069ac12 | 2015-02-12 00:59:22 | [diff] [blame] | 245 | if (contents_opaque()) { |
| 246 | // When opaque, draw a second inner border that is thicker than the outer |
| 247 | // border, but more transparent. |
| 248 | static const float kFillOpacity = 0.3f; |
| 249 | SkColor fill_color = SkColorSetA( |
| 250 | color, static_cast<uint8_t>(SkColorGetA(color) * kFillOpacity)); |
| 251 | float fill_width = width * 3; |
| 252 | gfx::Rect fill_rect = quad_rect; |
| 253 | fill_rect.Inset(fill_width / 2.f, fill_width / 2.f); |
enne | b79d5f14 | 2015-04-23 19:59:55 | [diff] [blame] | 254 | if (fill_rect.IsEmpty()) |
| 255 | return; |
danakj | 069ac12 | 2015-02-12 00:59:22 | [diff] [blame] | 256 | gfx::Rect visible_fill_rect = |
| 257 | gfx::IntersectRects(visible_quad_rect, fill_rect); |
danakj | e5805be | 2017-09-15 19:24:55 | [diff] [blame] | 258 | auto* fill_quad = |
| 259 | render_pass->CreateAndAppendDrawQuad<viz::DebugBorderDrawQuad>(); |
danakj | 069ac12 | 2015-02-12 00:59:22 | [diff] [blame] | 260 | fill_quad->SetNew(shared_quad_state, fill_rect, visible_fill_rect, |
| 261 | fill_color, fill_width); |
| 262 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 263 | } |
| 264 | |
Fady Samuel | c80a4a86 | 2017-07-28 10:23:36 | [diff] [blame] | 265 | void LayerImpl::GetContentsResourceId(viz::ResourceId* resource_id, |
ericrk | 664405a | 2017-05-04 20:58:37 | [diff] [blame] | 266 | gfx::Size* resource_size, |
| 267 | gfx::SizeF* resource_uv_size) const { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 268 | NOTREACHED(); |
enne | f6f3fbba4 | 2014-10-16 18:16:49 | [diff] [blame] | 269 | *resource_id = 0; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 270 | } |
| 271 | |
[email protected] | 3244c913 | 2014-01-23 10:39:12 | [diff] [blame] | 272 | gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) { |
wkorman | 5a126a5 | 2017-01-06 18:41:13 | [diff] [blame] | 273 | ScrollTree& scroll_tree = GetScrollTree(); |
sunxd | 2668bea6 | 2016-03-17 00:49:47 | [diff] [blame] | 274 | ScrollNode* scroll_node = scroll_tree.Node(scroll_tree_index()); |
| 275 | return scroll_tree.ScrollBy(scroll_node, scroll, layer_tree_impl()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 276 | } |
| 277 | |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 278 | void LayerImpl::SetScrollable(const gfx::Size& bounds) { |
| 279 | if (scrollable_ && scroll_container_bounds_ == bounds) |
aelias | a57c40d12 | 2015-10-08 00:20:09 | [diff] [blame] | 280 | return; |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 281 | scrollable_ = true; |
| 282 | scroll_container_bounds_ = bounds; |
Philip Rogers | 5e56378 | 2017-06-02 01:37:20 | [diff] [blame] | 283 | |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 284 | // Scrollbar positions depend on the bounds. |
Philip Rogers | 5e56378 | 2017-06-02 01:37:20 | [diff] [blame] | 285 | layer_tree_impl()->SetScrollbarGeometriesNeedUpdate(); |
pdr | bf2f6faf | 2017-06-06 18:00:40 | [diff] [blame] | 286 | |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 287 | if (layer_tree_impl()->settings().scrollbar_animator == |
| 288 | LayerTreeSettings::AURA_OVERLAY) { |
pdr | 74b07a1 | 2017-06-09 17:19:06 | [diff] [blame] | 289 | set_needs_show_scrollbars(true); |
| 290 | } |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 291 | |
| 292 | NoteLayerPropertyChanged(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 293 | } |
| 294 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 295 | std::unique_ptr<LayerImpl> LayerImpl::CreateLayerImpl( |
| 296 | LayerTreeImpl* tree_impl) { |
sunxd | c36713a | 2016-03-03 22:31:10 | [diff] [blame] | 297 | return LayerImpl::Create(tree_impl, layer_id_); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 298 | } |
| 299 | |
jaydasika | 2a1718b | 2016-10-26 22:58:02 | [diff] [blame] | 300 | bool LayerImpl::IsSnapped() { |
| 301 | return scrollable(); |
| 302 | } |
| 303 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 304 | void LayerImpl::PushPropertiesTo(LayerImpl* layer) { |
vmpstr | e2672aa5 | 2016-06-20 21:05:06 | [diff] [blame] | 305 | DCHECK(layer->IsActive()); |
| 306 | |
Walter Korman | 2f71605 | 2017-07-28 04:58:48 | [diff] [blame] | 307 | // The element id should be set first because other setters may |
| 308 | // depend on it. Referencing element id on a layer is |
| 309 | // deprecated. http://crbug.com/709137 |
pdr | faf2ee22 | 2017-04-19 03:11:04 | [diff] [blame] | 310 | layer->SetElementId(element_id_); |
| 311 | |
Chris Harrelson | daececa4 | 2017-06-16 20:42:02 | [diff] [blame] | 312 | layer->has_transform_node_ = has_transform_node_; |
vmpstr | e2672aa5 | 2016-06-20 21:05:06 | [diff] [blame] | 313 | layer->offset_to_transform_parent_ = offset_to_transform_parent_; |
| 314 | layer->main_thread_scrolling_reasons_ = main_thread_scrolling_reasons_; |
vmpstr | e2672aa5 | 2016-06-20 21:05:06 | [diff] [blame] | 315 | layer->should_flatten_transform_from_property_tree_ = |
| 316 | should_flatten_transform_from_property_tree_; |
| 317 | layer->masks_to_bounds_ = masks_to_bounds_; |
| 318 | layer->contents_opaque_ = contents_opaque_; |
sadrul | 32d1097 | 2016-07-30 05:26:21 | [diff] [blame] | 319 | layer->may_contain_video_ = may_contain_video_; |
vmpstr | e2672aa5 | 2016-06-20 21:05:06 | [diff] [blame] | 320 | layer->use_parent_backface_visibility_ = use_parent_backface_visibility_; |
vmpstr | e2672aa5 | 2016-06-20 21:05:06 | [diff] [blame] | 321 | layer->should_check_backface_visibility_ = should_check_backface_visibility_; |
| 322 | layer->draws_content_ = draws_content_; |
Hayley Ferr | 7bfdda3 | 2017-06-19 18:55:46 | [diff] [blame] | 323 | layer->should_hit_test_ = should_hit_test_; |
vmpstr | e2672aa5 | 2016-06-20 21:05:06 | [diff] [blame] | 324 | layer->non_fast_scrollable_region_ = non_fast_scrollable_region_; |
Hayley Ferr | d9ee3a7 | 2017-06-16 14:16:09 | [diff] [blame] | 325 | layer->touch_action_region_ = touch_action_region_; |
vmpstr | e2672aa5 | 2016-06-20 21:05:06 | [diff] [blame] | 326 | layer->background_color_ = background_color_; |
| 327 | layer->safe_opaque_background_color_ = safe_opaque_background_color_; |
vmpstr | e2672aa5 | 2016-06-20 21:05:06 | [diff] [blame] | 328 | layer->position_ = position_; |
vmpstr | e2672aa5 | 2016-06-20 21:05:06 | [diff] [blame] | 329 | layer->transform_tree_index_ = transform_tree_index_; |
| 330 | layer->effect_tree_index_ = effect_tree_index_; |
| 331 | layer->clip_tree_index_ = clip_tree_index_; |
| 332 | layer->scroll_tree_index_ = scroll_tree_index_; |
vmpstr | e2672aa5 | 2016-06-20 21:05:06 | [diff] [blame] | 333 | layer->has_will_change_transform_hint_ = has_will_change_transform_hint_; |
David Reveman | 0d133634 | 2017-09-12 17:05:40 | [diff] [blame] | 334 | layer->trilinear_filtering_ = trilinear_filtering_; |
bokan | 169f5ad | 2016-10-30 16:32:48 | [diff] [blame] | 335 | layer->scrollbars_hidden_ = scrollbars_hidden_; |
chaopeng | fe2cab76 | 2017-07-17 15:35:10 | [diff] [blame] | 336 | if (needs_show_scrollbars_) |
| 337 | layer->needs_show_scrollbars_ = needs_show_scrollbars_; |
vmpstr | e2672aa5 | 2016-06-20 21:05:06 | [diff] [blame] | 338 | |
wutao | bb1af5a | 2017-08-16 17:35:35 | [diff] [blame] | 339 | if (layer_property_changed_not_from_property_trees_ || |
| 340 | layer_property_changed_from_property_trees_) |
vmpstr | e2672aa5 | 2016-06-20 21:05:06 | [diff] [blame] | 341 | layer->layer_tree_impl()->set_needs_update_draw_properties(); |
wutao | bb1af5a | 2017-08-16 17:35:35 | [diff] [blame] | 342 | if (layer_property_changed_not_from_property_trees_) |
| 343 | layer->layer_property_changed_not_from_property_trees_ = true; |
| 344 | if (layer_property_changed_from_property_trees_) |
| 345 | layer->layer_property_changed_from_property_trees_ = true; |
vmpstr | e2672aa5 | 2016-06-20 21:05:06 | [diff] [blame] | 346 | |
vmpstr | e2672aa5 | 2016-06-20 21:05:06 | [diff] [blame] | 347 | layer->SetBounds(bounds_); |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 348 | if (scrollable_) |
| 349 | layer->SetScrollable(scroll_container_bounds_); |
vollick | 933f496e | 2015-12-08 04:22:05 | [diff] [blame] | 350 | layer->SetMutableProperties(mutable_properties_); |
enne | e95b154 | 2015-04-20 20:35:50 | [diff] [blame] | 351 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 352 | // If the main thread commits multiple times before the impl thread actually |
| 353 | // draws, then damage tracking will become incorrect if we simply clobber the |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 354 | // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 355 | // union) any update changes that have occurred on the main thread. |
| 356 | update_rect_.Union(layer->update_rect()); |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 357 | layer->SetUpdateRect(update_rect_); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 358 | |
primiano | cb1afb3 | 2016-02-29 20:46:05 | [diff] [blame] | 359 | if (owned_debug_info_) |
| 360 | layer->SetDebugInfo(std::move(owned_debug_info_)); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 361 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 362 | // Reset any state that should be cleared for the next update. |
skobes | 56451775d | 2017-03-28 18:46:38 | [diff] [blame] | 363 | needs_show_scrollbars_ = false; |
wutao | bb1af5a | 2017-08-16 17:35:35 | [diff] [blame] | 364 | layer_property_changed_not_from_property_trees_ = false; |
| 365 | layer_property_changed_from_property_trees_ = false; |
vmpstr | 6e8dd7c | 2016-06-21 00:59:58 | [diff] [blame] | 366 | needs_push_properties_ = false; |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 367 | update_rect_ = gfx::Rect(); |
jaydasika | bb0409e5 | 2016-03-08 04:05:19 | [diff] [blame] | 368 | layer_tree_impl()->RemoveLayerShouldPushProperties(this); |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 369 | } |
| 370 | |
sunxd | f6623755 | 2016-01-06 21:36:37 | [diff] [blame] | 371 | bool LayerImpl::IsAffectedByPageScale() const { |
wkorman | 5a126a5 | 2017-01-06 18:41:13 | [diff] [blame] | 372 | TransformTree& transform_tree = GetTransformTree(); |
sunxd | f6623755 | 2016-01-06 21:36:37 | [diff] [blame] | 373 | return transform_tree.Node(transform_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 374 | ->in_subtree_of_page_scale_layer; |
sunxd | f6623755 | 2016-01-06 21:36:37 | [diff] [blame] | 375 | } |
| 376 | |
David Bokan | ff56333 | 2017-08-15 21:19:19 | [diff] [blame] | 377 | bool LayerImpl::IsResizedByBrowserControls() const { |
| 378 | return is_resized_by_browser_controls_; |
| 379 | } |
| 380 | |
| 381 | void LayerImpl::SetIsResizedByBrowserControls(bool resized) { |
| 382 | is_resized_by_browser_controls_ = resized; |
| 383 | } |
| 384 | |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 385 | std::unique_ptr<base::DictionaryValue> LayerImpl::LayerTreeAsJson() { |
dcheng | 6223240a | 2016-05-31 19:48:01 | [diff] [blame] | 386 | std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue); |
r.kasibhatla | fd17d0e | 2015-05-17 11:12:07 | [diff] [blame] | 387 | result->SetInteger("LayerId", id()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 388 | result->SetString("LayerType", LayerTypeAsString()); |
| 389 | |
Jeremy Roman | 909d927b | 2017-08-27 18:34:09 | [diff] [blame] | 390 | auto list = std::make_unique<base::ListValue>(); |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 391 | list->AppendInteger(bounds().width()); |
| 392 | list->AppendInteger(bounds().height()); |
vabr | bce355c | 2017-03-23 18:52:43 | [diff] [blame] | 393 | result->Set("Bounds", std::move(list)); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 394 | |
Jeremy Roman | 909d927b | 2017-08-27 18:34:09 | [diff] [blame] | 395 | list = std::make_unique<base::ListValue>(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 396 | list->AppendDouble(position_.x()); |
| 397 | list->AppendDouble(position_.y()); |
vabr | bce355c | 2017-03-23 18:52:43 | [diff] [blame] | 398 | result->Set("Position", std::move(list)); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 399 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 400 | const gfx::Transform& gfx_transform = test_properties()->transform; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 401 | double transform[16]; |
| 402 | gfx_transform.matrix().asColMajord(transform); |
Jeremy Roman | 909d927b | 2017-08-27 18:34:09 | [diff] [blame] | 403 | list = std::make_unique<base::ListValue>(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 404 | for (int i = 0; i < 16; ++i) |
| 405 | list->AppendDouble(transform[i]); |
vabr | bce355c | 2017-03-23 18:52:43 | [diff] [blame] | 406 | result->Set("Transform", std::move(list)); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 407 | |
| 408 | result->SetBoolean("DrawsContent", draws_content_); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 409 | result->SetBoolean("Is3dSorted", Is3dSorted()); |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 410 | result->SetDouble("OPACITY", Opacity()); |
[email protected] | 46c7695 | 2013-07-10 00:21:45 | [diff] [blame] | 411 | result->SetBoolean("ContentsOpaque", contents_opaque_); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 412 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 413 | if (scrollable()) |
| 414 | result->SetBoolean("Scrollable", true); |
[email protected] | d993e03 | 2013-06-07 00:16:16 | [diff] [blame] | 415 | |
Hayley Ferr | d9ee3a7 | 2017-06-16 14:16:09 | [diff] [blame] | 416 | if (!touch_action_region_.region().IsEmpty()) { |
| 417 | std::unique_ptr<base::Value> region = |
| 418 | touch_action_region_.region().AsValue(); |
vabr | bce355c | 2017-03-23 18:52:43 | [diff] [blame] | 419 | result->Set("TouchRegion", std::move(region)); |
[email protected] | 9d161d2 | 2013-10-29 20:54:10 | [diff] [blame] | 420 | } |
| 421 | |
Jeremy Roman | 909d927b | 2017-08-27 18:34:09 | [diff] [blame] | 422 | list = std::make_unique<base::ListValue>(); |
jaydasika | fc66cfb | 2016-06-10 04:34:22 | [diff] [blame] | 423 | for (size_t i = 0; i < test_properties()->children.size(); ++i) |
| 424 | list->Append(test_properties()->children[i]->LayerTreeAsJson()); |
vabr | bce355c | 2017-03-23 18:52:43 | [diff] [blame] | 425 | result->Set("Children", std::move(list)); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 426 | |
| 427 | return result; |
[email protected] | b9dcf43a | 2013-01-09 00:15:29 | [diff] [blame] | 428 | } |
| 429 | |
jaydasika | adfec8e | 2016-02-17 02:46:11 | [diff] [blame] | 430 | bool LayerImpl::LayerPropertyChanged() const { |
wutao | bb1af5a | 2017-08-16 17:35:35 | [diff] [blame] | 431 | return layer_property_changed_not_from_property_trees_ || |
| 432 | LayerPropertyChangedFromPropertyTrees(); |
| 433 | } |
| 434 | |
| 435 | bool LayerImpl::LayerPropertyChangedFromPropertyTrees() const { |
| 436 | if (layer_property_changed_from_property_trees_ || |
| 437 | GetPropertyTrees()->full_tree_damaged) |
jaydasika | adfec8e | 2016-02-17 02:46:11 | [diff] [blame] | 438 | return true; |
jaydasika | dba9f75 | 2016-07-26 20:35:34 | [diff] [blame] | 439 | if (transform_tree_index() == TransformTree::kInvalidNodeId) |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 440 | return false; |
| 441 | TransformNode* transform_node = |
wkorman | 5a126a5 | 2017-01-06 18:41:13 | [diff] [blame] | 442 | GetTransformTree().Node(transform_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 443 | if (transform_node && transform_node->transform_changed) |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 444 | return true; |
jaydasika | dba9f75 | 2016-07-26 20:35:34 | [diff] [blame] | 445 | if (effect_tree_index() == EffectTree::kInvalidNodeId) |
jaydasika | 16515f5 | 2016-03-01 00:28:35 | [diff] [blame] | 446 | return false; |
wkorman | 5a126a5 | 2017-01-06 18:41:13 | [diff] [blame] | 447 | EffectNode* effect_node = GetEffectTree().Node(effect_tree_index()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 448 | if (effect_node && effect_node->effect_changed) |
jaydasika | adfec8e | 2016-02-17 02:46:11 | [diff] [blame] | 449 | return true; |
| 450 | return false; |
| 451 | } |
| 452 | |
wutao | 3685073 | 2017-07-29 20:24:07 | [diff] [blame] | 453 | bool LayerImpl::LayerPropertyChangedNotFromPropertyTrees() const { |
wutao | bb1af5a | 2017-08-16 17:35:35 | [diff] [blame] | 454 | return layer_property_changed_not_from_property_trees_; |
wutao | 3685073 | 2017-07-29 20:24:07 | [diff] [blame] | 455 | } |
| 456 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 457 | void LayerImpl::NoteLayerPropertyChanged() { |
wutao | bb1af5a | 2017-08-16 17:35:35 | [diff] [blame] | 458 | layer_property_changed_not_from_property_trees_ = true; |
| 459 | layer_tree_impl()->set_needs_update_draw_properties(); |
| 460 | SetNeedsPushProperties(); |
| 461 | } |
| 462 | |
| 463 | void LayerImpl::NoteLayerPropertyChangedFromPropertyTrees() { |
| 464 | layer_property_changed_from_property_trees_ = true; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 465 | layer_tree_impl()->set_needs_update_draw_properties(); |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 466 | SetNeedsPushProperties(); |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 467 | } |
| 468 | |
danakj | 1a01068 | 2017-09-07 20:08:19 | [diff] [blame] | 469 | void LayerImpl::ValidateQuadResourcesInternal(viz::DrawQuad* quad) const { |
danakj | f942757 | 2015-04-24 22:19:02 | [diff] [blame] | 470 | #if DCHECK_IS_ON() |
vmpstr | 0eca2e8 | 2015-06-02 22:14:46 | [diff] [blame] | 471 | const ResourceProvider* resource_provider = |
| 472 | layer_tree_impl_->resource_provider(); |
Fady Samuel | c80a4a86 | 2017-07-28 10:23:36 | [diff] [blame] | 473 | for (viz::ResourceId resource_id : quad->resources) |
vmpstr | 0eca2e8 | 2015-06-02 22:14:46 | [diff] [blame] | 474 | resource_provider->ValidateResource(resource_id); |
danakj | f942757 | 2015-04-24 22:19:02 | [diff] [blame] | 475 | #endif |
| 476 | } |
| 477 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 478 | const char* LayerImpl::LayerTypeAsString() const { |
[email protected] | f256b7fd | 2013-05-15 01:49:30 | [diff] [blame] | 479 | return "cc::LayerImpl"; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 480 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 481 | |
jaydasika | ef64f9e4 | 2016-03-12 01:08:18 | [diff] [blame] | 482 | void LayerImpl::ResetChangeTracking() { |
wutao | bb1af5a | 2017-08-16 17:35:35 | [diff] [blame] | 483 | layer_property_changed_not_from_property_trees_ = false; |
| 484 | layer_property_changed_from_property_trees_ = false; |
vmpstr | 6e8dd7c | 2016-06-21 00:59:58 | [diff] [blame] | 485 | needs_push_properties_ = false; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 486 | |
danakj | d344ab9 | 2015-08-28 19:25:51 | [diff] [blame] | 487 | update_rect_.SetRect(0, 0, 0, 0); |
| 488 | damage_rect_.SetRect(0, 0, 0, 0); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 489 | } |
| 490 | |
jaydasika | ebc9428 | 2017-04-24 20:34:01 | [diff] [blame] | 491 | bool LayerImpl::has_copy_requests_in_target_subtree() { |
| 492 | return GetEffectTree().Node(effect_tree_index())->subtree_has_copy_request; |
sunxd | ed58688e | 2016-01-11 21:01:02 | [diff] [blame] | 493 | } |
| 494 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 495 | bool LayerImpl::IsActive() const { |
| 496 | return layer_tree_impl_->IsActiveTree(); |
| 497 | } |
| 498 | |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 499 | gfx::Size LayerImpl::bounds() const { |
pdr | 23d381fd | 2017-04-25 21:06:31 | [diff] [blame] | 500 | auto viewport_bounds_delta = gfx::ToCeiledVector2d(ViewportBoundsDelta()); |
| 501 | return gfx::Size(bounds_.width() + viewport_bounds_delta.x(), |
| 502 | bounds_.height() + viewport_bounds_delta.y()); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | gfx::SizeF LayerImpl::BoundsForScrolling() const { |
pdr | 23d381fd | 2017-04-25 21:06:31 | [diff] [blame] | 506 | auto viewport_bounds_delta = ViewportBoundsDelta(); |
| 507 | return gfx::SizeF(bounds_.width() + viewport_bounds_delta.x(), |
| 508 | bounds_.height() + viewport_bounds_delta.y()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 509 | } |
| 510 | |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 511 | void LayerImpl::SetBounds(const gfx::Size& bounds) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 512 | if (bounds_ == bounds) |
| 513 | return; |
| 514 | |
| 515 | bounds_ = bounds; |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 516 | |
pdr | bbfd882 | 2017-06-27 22:44:52 | [diff] [blame] | 517 | // Scrollbar positions depend on the scrolling layer bounds. |
| 518 | if (scrollable()) |
| 519 | layer_tree_impl()->SetScrollbarGeometriesNeedUpdate(); |
sunxd | cfccd1b3 | 2016-02-11 00:54:20 | [diff] [blame] | 520 | |
jaydasika | b311c9a | 2016-03-02 20:49:09 | [diff] [blame] | 521 | NoteLayerPropertyChanged(); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 522 | } |
| 523 | |
pdr | 23d381fd | 2017-04-25 21:06:31 | [diff] [blame] | 524 | void LayerImpl::SetViewportBoundsDelta(const gfx::Vector2dF& bounds_delta) { |
ajuma | 6b46da2 | 2015-06-25 21:53:02 | [diff] [blame] | 525 | DCHECK(IsActive()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 526 | |
pdr | 23d381fd | 2017-04-25 21:06:31 | [diff] [blame] | 527 | if (bounds_delta == ViewportBoundsDelta()) |
| 528 | return; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 529 | |
wkorman | 5a126a5 | 2017-01-06 18:41:13 | [diff] [blame] | 530 | PropertyTrees* property_trees = GetPropertyTrees(); |
pdr | 6280cc1 | 2017-05-10 23:22:47 | [diff] [blame] | 531 | switch (viewport_layer_type_) { |
| 532 | case (INNER_VIEWPORT_CONTAINER): |
| 533 | property_trees->SetInnerViewportContainerBoundsDelta(bounds_delta); |
| 534 | break; |
| 535 | case (OUTER_VIEWPORT_CONTAINER): |
| 536 | property_trees->SetOuterViewportContainerBoundsDelta(bounds_delta); |
| 537 | break; |
| 538 | case (INNER_VIEWPORT_SCROLL): |
| 539 | property_trees->SetInnerViewportScrollBoundsDelta(bounds_delta); |
| 540 | break; |
| 541 | case (OUTER_VIEWPORT_SCROLL): |
| 542 | // OUTER_VIEWPORT_SCROLL should not have viewport bounds deltas. |
| 543 | NOTREACHED(); |
| 544 | } |
ajuma | 6b46da2 | 2015-06-25 21:53:02 | [diff] [blame] | 545 | |
Philip Rogers | 5e56378 | 2017-06-02 01:37:20 | [diff] [blame] | 546 | // Viewport scrollbar positions are determined using the viewport bounds |
| 547 | // delta. |
| 548 | layer_tree_impl()->SetScrollbarGeometriesNeedUpdate(); |
miletus | 8bd08a62 | 2015-06-16 18:44:52 | [diff] [blame] | 549 | |
| 550 | if (masks_to_bounds()) { |
| 551 | // If layer is clipping, then update the clip node using the new bounds. |
Chris Harrelson | 0f075b2 | 2017-06-14 23:45:36 | [diff] [blame] | 552 | ClipNode* clip_node = property_trees->clip_tree.Node(clip_tree_index()); |
| 553 | CHECK(clip_node); |
| 554 | DCHECK_EQ(clip_node->id, clip_tree_index()); |
| 555 | clip_node->clip = gfx::RectF(gfx::PointF() + offset_to_transform_parent(), |
| 556 | gfx::SizeF(bounds())); |
| 557 | property_trees->clip_tree.set_needs_update(true); |
| 558 | |
jaydasika | b311c9a | 2016-03-02 20:49:09 | [diff] [blame] | 559 | property_trees->full_tree_damaged = true; |
| 560 | layer_tree_impl()->set_needs_update_draw_properties(); |
miletus | 8bd08a62 | 2015-06-16 18:44:52 | [diff] [blame] | 561 | } else { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 562 | NoteLayerPropertyChanged(); |
miletus | 8bd08a62 | 2015-06-16 18:44:52 | [diff] [blame] | 563 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 564 | } |
| 565 | |
pdr | 23d381fd | 2017-04-25 21:06:31 | [diff] [blame] | 566 | gfx::Vector2dF LayerImpl::ViewportBoundsDelta() const { |
pdr | 6280cc1 | 2017-05-10 23:22:47 | [diff] [blame] | 567 | switch (viewport_layer_type_) { |
| 568 | case (INNER_VIEWPORT_CONTAINER): |
| 569 | return GetPropertyTrees()->inner_viewport_container_bounds_delta(); |
| 570 | case (OUTER_VIEWPORT_CONTAINER): |
| 571 | return GetPropertyTrees()->outer_viewport_container_bounds_delta(); |
| 572 | case (INNER_VIEWPORT_SCROLL): |
| 573 | return GetPropertyTrees()->inner_viewport_scroll_bounds_delta(); |
| 574 | default: |
| 575 | return gfx::Vector2dF(); |
| 576 | } |
pdr | 23d381fd | 2017-04-25 21:06:31 | [diff] [blame] | 577 | } |
| 578 | |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 579 | ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() { |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 580 | return nullptr; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | void LayerImpl::SetDrawsContent(bool draws_content) { |
| 584 | if (draws_content_ == draws_content) |
| 585 | return; |
| 586 | |
| 587 | draws_content_ = draws_content; |
Hayley Ferr | 7bfdda3 | 2017-06-19 18:55:46 | [diff] [blame] | 588 | if (draws_content) |
| 589 | SetShouldHitTest(true); |
| 590 | NoteLayerPropertyChanged(); |
| 591 | } |
| 592 | |
| 593 | void LayerImpl::SetShouldHitTest(bool should_hit_test) { |
| 594 | if (should_hit_test_ == should_hit_test) |
| 595 | return; |
| 596 | |
| 597 | should_hit_test_ = should_hit_test; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 598 | NoteLayerPropertyChanged(); |
| 599 | } |
| 600 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 601 | void LayerImpl::SetBackgroundColor(SkColor background_color) { |
| 602 | if (background_color_ == background_color) |
| 603 | return; |
| 604 | |
| 605 | background_color_ = background_color; |
| 606 | NoteLayerPropertyChanged(); |
| 607 | } |
| 608 | |
jaydasika | c6326bb | 2016-03-03 03:46:14 | [diff] [blame] | 609 | void LayerImpl::SetSafeOpaqueBackgroundColor(SkColor background_color) { |
jaydasika | c6326bb | 2016-03-03 03:46:14 | [diff] [blame] | 610 | safe_opaque_background_color_ = background_color; |
jaydasika | c6326bb | 2016-03-03 03:46:14 | [diff] [blame] | 611 | } |
| 612 | |
[email protected] | 2c4cbec | 2013-06-04 21:14:50 | [diff] [blame] | 613 | SkColor LayerImpl::SafeOpaqueBackgroundColor() const { |
jaydasika | c6326bb | 2016-03-03 03:46:14 | [diff] [blame] | 614 | if (contents_opaque()) |
| 615 | return safe_opaque_background_color_; |
[email protected] | 2c4cbec | 2013-06-04 21:14:50 | [diff] [blame] | 616 | SkColor color = background_color(); |
jaydasika | c6326bb | 2016-03-03 03:46:14 | [diff] [blame] | 617 | if (SkColorGetA(color) == 255) |
[email protected] | 2c4cbec | 2013-06-04 21:14:50 | [diff] [blame] | 618 | color = SK_ColorTRANSPARENT; |
[email protected] | 2c4cbec | 2013-06-04 21:14:50 | [diff] [blame] | 619 | return color; |
| 620 | } |
| 621 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 622 | void LayerImpl::SetMasksToBounds(bool masks_to_bounds) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 623 | masks_to_bounds_ = masks_to_bounds; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | void LayerImpl::SetContentsOpaque(bool opaque) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 627 | contents_opaque_ = opaque; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 628 | } |
| 629 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 630 | float LayerImpl::Opacity() const { |
Chris Harrelson | 84670c9 | 2017-06-06 05:39:06 | [diff] [blame] | 631 | if (const EffectNode* node = GetEffectTree().Node(effect_tree_index())) |
weiliangc | 42c074f | 2017-03-17 19:28:30 | [diff] [blame] | 632 | return node->opacity; |
| 633 | else |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 634 | return 1.f; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 635 | } |
| 636 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 637 | const gfx::Transform& LayerImpl::Transform() const { |
Chris Harrelson | dfd95a1 | 2017-06-13 17:13:56 | [diff] [blame] | 638 | return GetTransformTree().Node(transform_tree_index())->local; |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 639 | } |
| 640 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 641 | void LayerImpl::SetElementId(ElementId element_id) { |
vollick | 933f496e | 2015-12-08 04:22:05 | [diff] [blame] | 642 | if (element_id == element_id_) |
| 643 | return; |
| 644 | |
| 645 | TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 646 | "LayerImpl::SetElementId", "element", |
| 647 | element_id.AsValue().release()); |
vollick | 933f496e | 2015-12-08 04:22:05 | [diff] [blame] | 648 | |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 649 | layer_tree_impl_->RemoveFromElementMap(this); |
vollick | 933f496e | 2015-12-08 04:22:05 | [diff] [blame] | 650 | element_id_ = element_id; |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 651 | layer_tree_impl_->AddToElementMap(this); |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 652 | |
| 653 | SetNeedsPushProperties(); |
vollick | 933f496e | 2015-12-08 04:22:05 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | void LayerImpl::SetMutableProperties(uint32_t properties) { |
| 657 | if (mutable_properties_ == properties) |
| 658 | return; |
| 659 | |
| 660 | TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), |
| 661 | "LayerImpl::SetMutableProperties", "properties", properties); |
| 662 | |
| 663 | mutable_properties_ = properties; |
vollick | 9c7f6d0 | 2016-01-08 04:36:38 | [diff] [blame] | 664 | // If this layer is already in the element map, update its properties. |
vollick | cb3f6b1 | 2016-03-01 23:44:10 | [diff] [blame] | 665 | layer_tree_impl_->AddToElementMap(this); |
vollick | 933f496e | 2015-12-08 04:22:05 | [diff] [blame] | 666 | } |
| 667 | |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 668 | void LayerImpl::SetPosition(const gfx::PointF& position) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 669 | position_ = position; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 670 | } |
| 671 | |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 672 | void LayerImpl::SetUpdateRect(const gfx::Rect& update_rect) { |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 673 | update_rect_ = update_rect; |
| 674 | SetNeedsPushProperties(); |
| 675 | } |
| 676 | |
danakj | d344ab9 | 2015-08-28 19:25:51 | [diff] [blame] | 677 | void LayerImpl::AddDamageRect(const gfx::Rect& damage_rect) { |
| 678 | damage_rect_.Union(damage_rect); |
[email protected] | cfa7fd92 | 2014-04-29 11:50:03 | [diff] [blame] | 679 | } |
| 680 | |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 681 | void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) { |
| 682 | DCHECK(IsActive()); |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 683 | if (GetScrollTree().SetScrollOffset(element_id(), scroll_offset)) |
| 684 | layer_tree_impl()->DidUpdateScrollOffset(element_id()); |
boliu | 7d5dbab | 2014-10-10 20:05:47 | [diff] [blame] | 685 | } |
| 686 | |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 687 | gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const { |
pdr | 54d03819 | 2017-06-08 22:44:13 | [diff] [blame] | 688 | return GetScrollTree().current_scroll_offset(element_id()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 689 | } |
| 690 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 691 | SimpleEnclosedRegion LayerImpl::VisibleOpaqueRegion() const { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 692 | if (contents_opaque()) |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 693 | return SimpleEnclosedRegion(visible_layer_rect()); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 694 | return SimpleEnclosedRegion(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 695 | } |
| 696 | |
[email protected] | 37349bc | 2013-06-04 01:31:52 | [diff] [blame] | 697 | void LayerImpl::DidBeginTracing() {} |
| 698 | |
[email protected] | 9db2446 | 2014-01-14 02:25:50 | [diff] [blame] | 699 | void LayerImpl::ReleaseResources() {} |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 700 | |
ericrk | 7cedb54 | 2016-11-02 19:03:44 | [diff] [blame] | 701 | void LayerImpl::ReleaseTileResources() {} |
| 702 | |
| 703 | void LayerImpl::RecreateTileResources() {} |
vmpstr | 9ce5c66 | 2015-02-05 23:29:26 | [diff] [blame] | 704 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 705 | gfx::ScrollOffset LayerImpl::MaxScrollOffset() const { |
wkorman | 5a126a5 | 2017-01-06 18:41:13 | [diff] [blame] | 706 | return GetScrollTree().MaxScrollOffset(scroll_tree_index()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 707 | } |
| 708 | |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 709 | gfx::ScrollOffset LayerImpl::ClampScrollOffsetToLimits( |
| 710 | gfx::ScrollOffset offset) const { |
| 711 | offset.SetToMin(MaxScrollOffset()); |
| 712 | offset.SetToMax(gfx::ScrollOffset()); |
| 713 | return offset; |
| 714 | } |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 715 | |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 716 | gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() { |
| 717 | gfx::ScrollOffset old_offset = CurrentScrollOffset(); |
| 718 | gfx::ScrollOffset clamped_offset = ClampScrollOffsetToLimits(old_offset); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 719 | gfx::Vector2dF delta = clamped_offset.DeltaFrom(old_offset); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 720 | if (!delta.IsZero()) |
| 721 | ScrollBy(delta); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 722 | return delta; |
| 723 | } |
| 724 | |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 725 | void LayerImpl::SetNeedsPushProperties() { |
Philip Rogers | c8cb200 | 2017-05-31 02:14:36 | [diff] [blame] | 726 | // There's no need to push layer properties on the active tree. |
| 727 | if (!needs_push_properties_ && !layer_tree_impl()->IsActiveTree()) { |
vmpstr | 6e8dd7c | 2016-06-21 00:59:58 | [diff] [blame] | 728 | needs_push_properties_ = true; |
jaydasika | bb0409e5 | 2016-03-08 04:05:19 | [diff] [blame] | 729 | layer_tree_impl()->AddLayerShouldPushProperties(this); |
vmpstr | 6e8dd7c | 2016-06-21 00:59:58 | [diff] [blame] | 730 | } |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 731 | } |
| 732 | |
hendrikw | c5e91585 | 2015-05-13 01:29:03 | [diff] [blame] | 733 | void LayerImpl::GetAllPrioritizedTilesForTracing( |
| 734 | std::vector<PrioritizedTile>* prioritized_tiles) const { |
vmpstr | d7de03c | 2014-08-27 18:11:01 | [diff] [blame] | 735 | } |
| 736 | |
ssid | 911e40e | 2015-02-09 17:55:20 | [diff] [blame] | 737 | void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const { |
Alex Zhang | dd188a1 | 2017-08-14 18:48:44 | [diff] [blame] | 738 | viz::TracedValue::MakeDictIntoImplicitSnapshotWithCategory( |
| 739 | TRACE_DISABLED_BY_DEFAULT("cc.debug"), state, "cc::LayerImpl", |
| 740 | LayerTypeAsString(), this); |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 741 | state->SetInteger("layer_id", id()); |
jungjik.lee | 50f9c8e | 2015-01-21 14:06:16 | [diff] [blame] | 742 | MathUtil::AddToTracedValue("bounds", bounds_, state); |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 743 | |
jaydasika | ab317e0 | 2016-06-01 00:53:18 | [diff] [blame] | 744 | state->SetDouble("opacity", Opacity()); |
danakj | 3895556 | 2014-09-13 02:56:43 | [diff] [blame] | 745 | |
jungjik.lee | 50f9c8e | 2015-01-21 14:06:16 | [diff] [blame] | 746 | MathUtil::AddToTracedValue("position", position_, state); |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 747 | |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 748 | state->SetInteger("draws_content", DrawsContent()); |
vmpstr | 91e2309 | 2015-06-08 22:24:16 | [diff] [blame] | 749 | state->SetInteger("gpu_memory_usage", |
| 750 | base::saturated_cast<int>(GPUMemoryUsageInBytes())); |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 751 | |
vollick | ef2ae92 | 2016-06-29 17:54:27 | [diff] [blame] | 752 | if (element_id_) |
| 753 | element_id_.AddToTracedValue(state); |
| 754 | |
| 755 | if (mutable_properties_ != MutableProperty::kNone) |
vollick | 933f496e | 2015-12-08 04:22:05 | [diff] [blame] | 756 | state->SetInteger("mutable_properties", mutable_properties_); |
vollick | 933f496e | 2015-12-08 04:22:05 | [diff] [blame] | 757 | |
sunxd | c044b11a | 2016-03-16 16:23:20 | [diff] [blame] | 758 | MathUtil::AddToTracedValue("scroll_offset", CurrentScrollOffset(), state); |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 759 | |
jaydasika | 10d43fc | 2016-08-18 04:06:04 | [diff] [blame] | 760 | if (!ScreenSpaceTransform().IsIdentity()) |
| 761 | MathUtil::AddToTracedValue("screen_space_transform", ScreenSpaceTransform(), |
| 762 | state); |
vollick | 96b33a5 | 2016-03-30 20:11:53 | [diff] [blame] | 763 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 764 | bool clipped; |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 765 | gfx::QuadF layer_quad = |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 766 | MathUtil::MapQuad(ScreenSpaceTransform(), |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 767 | gfx::QuadF(gfx::RectF(gfx::Rect(bounds()))), &clipped); |
jungjik.lee | 50f9c8e | 2015-01-21 14:06:16 | [diff] [blame] | 768 | MathUtil::AddToTracedValue("layer_quad", layer_quad, state); |
Hayley Ferr | d9ee3a7 | 2017-06-16 14:16:09 | [diff] [blame] | 769 | if (!touch_action_region_.region().IsEmpty()) { |
| 770 | state->BeginArray("touch_action_region_region"); |
| 771 | touch_action_region_.region().AsValueInto(state); |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 772 | state->EndArray(); |
[email protected] | 78d7861 | 2013-09-12 18:04:04 | [diff] [blame] | 773 | } |
[email protected] | 78d7861 | 2013-09-12 18:04:04 | [diff] [blame] | 774 | if (!non_fast_scrollable_region_.IsEmpty()) { |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 775 | state->BeginArray("non_fast_scrollable_region"); |
| 776 | non_fast_scrollable_region_.AsValueInto(state); |
| 777 | state->EndArray(); |
[email protected] | 78d7861 | 2013-09-12 18:04:04 | [diff] [blame] | 778 | } |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 779 | |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 780 | state->SetBoolean("can_use_lcd_text", CanUseLCDText()); |
[email protected] | c2a56ff | 2013-10-14 19:32:51 | [diff] [blame] | 781 | state->SetBoolean("contents_opaque", contents_opaque()); |
[email protected] | a128674 | 2013-11-13 17:11:40 | [diff] [blame] | 782 | |
vmpstr | d6dce260 | 2016-05-18 20:19:04 | [diff] [blame] | 783 | state->SetBoolean("has_will_change_transform_hint", |
| 784 | has_will_change_transform_hint()); |
| 785 | |
David Reveman | 0d133634 | 2017-09-12 17:05:40 | [diff] [blame] | 786 | state->SetBoolean("trilinear_filtering", trilinear_filtering()); |
| 787 | |
primiano | cb1afb3 | 2016-02-29 20:46:05 | [diff] [blame] | 788 | if (debug_info_) { |
[email protected] | 9f3be43 | 2013-12-03 03:53:22 | [diff] [blame] | 789 | std::string str; |
| 790 | debug_info_->AppendAsTraceFormat(&str); |
| 791 | base::JSONReader json_reader; |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 792 | std::unique_ptr<base::Value> debug_info_value(json_reader.ReadToValue(str)); |
[email protected] | 685de6b1 | 2014-01-09 12:25:05 | [diff] [blame] | 793 | |
jdoerrie | dc72ee94 | 2016-12-07 15:43:28 | [diff] [blame] | 794 | if (debug_info_value->IsType(base::Value::Type::DICTIONARY)) { |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 795 | base::DictionaryValue* dictionary_value = nullptr; |
[email protected] | 685de6b1 | 2014-01-09 12:25:05 | [diff] [blame] | 796 | bool converted_to_dictionary = |
| 797 | debug_info_value->GetAsDictionary(&dictionary_value); |
| 798 | DCHECK(converted_to_dictionary); |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 799 | for (base::DictionaryValue::Iterator it(*dictionary_value); !it.IsAtEnd(); |
| 800 | it.Advance()) { |
estade | 7bc801fb | 2015-05-07 01:53:08 | [diff] [blame] | 801 | state->SetValue(it.key().data(), it.value().CreateDeepCopy()); |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 802 | } |
[email protected] | 685de6b1 | 2014-01-09 12:25:05 | [diff] [blame] | 803 | } else { |
| 804 | NOTREACHED(); |
| 805 | } |
[email protected] | 9f3be43 | 2013-12-03 03:53:22 | [diff] [blame] | 806 | } |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 807 | } |
| 808 | |
[email protected] | cdf5b95 | 2013-05-15 15:39:29 | [diff] [blame] | 809 | size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; } |
| 810 | |
[email protected] | 5e5648a | 2013-11-18 00:39:33 | [diff] [blame] | 811 | void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { |
| 812 | benchmark->RunOnLayer(this); |
| 813 | } |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 814 | |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 815 | gfx::Transform LayerImpl::DrawTransform() const { |
weiliangc | 15346d2c | 2016-02-19 01:38:49 | [diff] [blame] | 816 | // Only drawn layers have up-to-date draw properties. |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 817 | if (!contributes_to_drawn_render_surface()) { |
wkorman | 5a126a5 | 2017-01-06 18:41:13 | [diff] [blame] | 818 | return draw_property_utils::DrawTransform(this, GetTransformTree(), |
| 819 | GetEffectTree()); |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | return draw_properties().target_space_transform; |
| 823 | } |
| 824 | |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 825 | gfx::Transform LayerImpl::ScreenSpaceTransform() const { |
weiliangc | 15346d2c | 2016-02-19 01:38:49 | [diff] [blame] | 826 | // Only drawn layers have up-to-date draw properties. |
ajuma | 651848a | 2017-05-01 21:23:45 | [diff] [blame] | 827 | if (!contributes_to_drawn_render_surface()) { |
wkorman | 5a126a5 | 2017-01-06 18:41:13 | [diff] [blame] | 828 | return draw_property_utils::ScreenSpaceTransform(this, GetTransformTree()); |
ajuma | b6aa1c6 | 2015-12-01 21:01:10 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | return draw_properties().screen_space_transform; |
| 832 | } |
| 833 | |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 834 | bool LayerImpl::CanUseLCDText() const { |
| 835 | if (layer_tree_impl()->settings().layers_always_allowed_lcd_text) |
| 836 | return true; |
| 837 | if (!layer_tree_impl()->settings().can_use_lcd_text) |
| 838 | return false; |
| 839 | if (!contents_opaque()) |
| 840 | return false; |
| 841 | |
wkorman | 5a126a5 | 2017-01-06 18:41:13 | [diff] [blame] | 842 | if (GetEffectTree().Node(effect_tree_index())->screen_space_opacity != 1.f) |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 843 | return false; |
wkorman | 5a126a5 | 2017-01-06 18:41:13 | [diff] [blame] | 844 | if (!GetTransformTree() |
| 845 | .Node(transform_tree_index()) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame] | 846 | ->node_and_ancestors_have_only_integer_translation) |
sunxd | 5a7a403 | 2016-06-01 18:49:22 | [diff] [blame] | 847 | return false; |
| 848 | if (static_cast<int>(offset_to_transform_parent().x()) != |
| 849 | offset_to_transform_parent().x()) |
| 850 | return false; |
| 851 | if (static_cast<int>(offset_to_transform_parent().y()) != |
| 852 | offset_to_transform_parent().y()) |
| 853 | return false; |
| 854 | return true; |
| 855 | } |
| 856 | |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 857 | int LayerImpl::GetSortingContextId() const { |
wkorman | 52602dd | 2017-01-10 03:14:47 | [diff] [blame] | 858 | return GetTransformTree().Node(transform_tree_index())->sorting_context_id; |
wkorman | f09921d | 2017-01-07 01:01:20 | [diff] [blame] | 859 | } |
| 860 | |
chrishtr | c41aca7b | 2016-03-18 15:44:29 | [diff] [blame] | 861 | Region LayerImpl::GetInvalidationRegionForDebugging() { |
daplatz | 350219e | 2015-03-04 19:04:41 | [diff] [blame] | 862 | return Region(update_rect_); |
| 863 | } |
| 864 | |
vmpstr | d46a7ac | 2015-03-18 01:11:12 | [diff] [blame] | 865 | gfx::Rect LayerImpl::GetEnclosingRectInTargetSpace() const { |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 866 | return MathUtil::MapEnclosingClippedRect(DrawTransform(), |
| 867 | gfx::Rect(bounds())); |
vmpstr | d46a7ac | 2015-03-18 01:11:12 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const { |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 871 | gfx::Transform scaled_draw_transform = DrawTransform(); |
vmpstr | d46a7ac | 2015-03-18 01:11:12 | [diff] [blame] | 872 | scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale); |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 873 | gfx::Size scaled_bounds = gfx::ScaleToCeiledSize(bounds(), scale); |
vmpstr | d46a7ac | 2015-03-18 01:11:12 | [diff] [blame] | 874 | return MathUtil::MapEnclosingClippedRect(scaled_draw_transform, |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 875 | gfx::Rect(scaled_bounds)); |
vmpstr | d46a7ac | 2015-03-18 01:11:12 | [diff] [blame] | 876 | } |
| 877 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 878 | RenderSurfaceImpl* LayerImpl::render_target() { |
ajuma | 6b96f4cc4 | 2017-02-23 14:07:12 | [diff] [blame] | 879 | return GetEffectTree().GetRenderSurface(render_target_effect_tree_index()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | const RenderSurfaceImpl* LayerImpl::render_target() const { |
ajuma | 6b96f4cc4 | 2017-02-23 14:07:12 | [diff] [blame] | 883 | return GetEffectTree().GetRenderSurface(render_target_effect_tree_index()); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 884 | } |
| 885 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 886 | float LayerImpl::GetIdealContentsScale() const { |
| 887 | float page_scale = IsAffectedByPageScale() |
| 888 | ? layer_tree_impl()->current_page_scale_factor() |
| 889 | : 1.f; |
| 890 | float device_scale = layer_tree_impl()->device_scale_factor(); |
| 891 | |
| 892 | float default_scale = page_scale * device_scale; |
| 893 | if (!layer_tree_impl() |
| 894 | ->settings() |
| 895 | .layer_transforms_should_scale_layer_contents) { |
| 896 | return default_scale; |
| 897 | } |
| 898 | |
vmpstr | dc5e1af | 2017-05-15 19:59:52 | [diff] [blame] | 899 | const auto& transform = ScreenSpaceTransform(); |
| 900 | if (transform.HasPerspective()) { |
| 901 | float scale = MathUtil::ComputeApproximateMaxScale(transform); |
Vladimir Levin | 4b44a05 | 2017-08-08 19:29:07 | [diff] [blame] | 902 | |
| 903 | const int kMaxTilesToCoverLayerDimension = 5; |
| 904 | // Cap the scale in a way that it should be covered by at most |
| 905 | // |kMaxTilesToCoverLayerDimension|^2 default tile sizes. If this is left |
| 906 | // uncapped, then we can fairly easily use too much memory (or too many |
| 907 | // tiles). See crbug.com/752382 for an example of such a page. Note that |
| 908 | // because this is an approximation anyway, it's fine to use a smaller scale |
| 909 | // that desired. On top of this, the layer has a perspective transform so |
| 910 | // technically it could all be within the viewport, so it's important for us |
| 911 | // to have a reasonable scale here. The scale we use would also be at least |
| 912 | // |default_scale|, as checked below. |
| 913 | float scale_cap = std::min( |
| 914 | (layer_tree_impl()->settings().default_tile_size.width() - 2) * |
| 915 | kMaxTilesToCoverLayerDimension / |
| 916 | static_cast<float>(bounds().width()), |
| 917 | (layer_tree_impl()->settings().default_tile_size.height() - 2) * |
| 918 | kMaxTilesToCoverLayerDimension / |
| 919 | static_cast<float>(bounds().height())); |
| 920 | scale = std::min(scale, scale_cap); |
| 921 | |
vmpstr | dc5e1af | 2017-05-15 19:59:52 | [diff] [blame] | 922 | // Since we're approximating the scale anyway, round it to the nearest |
| 923 | // integer to prevent jitter when animating the transform. |
| 924 | scale = std::round(scale); |
Vladimir Levin | 4b44a05 | 2017-08-08 19:29:07 | [diff] [blame] | 925 | |
vmpstr | dc5e1af | 2017-05-15 19:59:52 | [diff] [blame] | 926 | // Don't let the scale fall below the default scale. |
| 927 | return std::max(scale, default_scale); |
| 928 | } |
| 929 | |
| 930 | gfx::Vector2dF transform_scales = |
| 931 | MathUtil::ComputeTransform2dScaleComponents(transform, default_scale); |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 932 | return std::max(transform_scales.x(), transform_scales.y()); |
| 933 | } |
| 934 | |
wkorman | 5a126a5 | 2017-01-06 18:41:13 | [diff] [blame] | 935 | PropertyTrees* LayerImpl::GetPropertyTrees() const { |
| 936 | return layer_tree_impl_->property_trees(); |
| 937 | } |
| 938 | |
weiliangc | 42c074f | 2017-03-17 19:28:30 | [diff] [blame] | 939 | ClipTree& LayerImpl::GetClipTree() const { |
| 940 | return GetPropertyTrees()->clip_tree; |
| 941 | } |
| 942 | |
wkorman | 5a126a5 | 2017-01-06 18:41:13 | [diff] [blame] | 943 | EffectTree& LayerImpl::GetEffectTree() const { |
| 944 | return GetPropertyTrees()->effect_tree; |
| 945 | } |
| 946 | |
| 947 | ScrollTree& LayerImpl::GetScrollTree() const { |
| 948 | return GetPropertyTrees()->scroll_tree; |
| 949 | } |
| 950 | |
| 951 | TransformTree& LayerImpl::GetTransformTree() const { |
| 952 | return GetPropertyTrees()->transform_tree; |
| 953 | } |
| 954 | |
Khushal | b5b55e3f | 2017-07-19 00:24:31 | [diff] [blame] | 955 | void LayerImpl::EnsureValidPropertyTreeIndices() const { |
| 956 | DCHECK(GetTransformTree().Node(transform_tree_index())); |
| 957 | DCHECK(GetEffectTree().Node(effect_tree_index())); |
| 958 | DCHECK(GetClipTree().Node(clip_tree_index())); |
| 959 | DCHECK(GetScrollTree().Node(scroll_tree_index())); |
khushalsagar | 5867068 | 2017-06-02 22:11:04 | [diff] [blame] | 960 | } |
| 961 | |
[email protected] | bc5e77c | 2012-11-05 20:00:49 | [diff] [blame] | 962 | } // namespace cc |