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