[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
| 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/render_surface_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 | |
[email protected] | ac7c7f5 | 2012-11-08 06:26:50 | [diff] [blame] | 9 | #include <algorithm> |
| 10 | |
[email protected] | 4456eee2 | 2012-10-19 18:16:38 | [diff] [blame] | 11 | #include "base/logging.h" |
[email protected] | 8e61d4b | 2013-06-10 22:11:48 | [diff] [blame] | 12 | #include "base/strings/stringprintf.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 13 | #include "cc/base/math_util.h" |
[email protected] | 6e84de2 | 2013-03-18 06:54:27 | [diff] [blame] | 14 | #include "cc/debug/debug_colors.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 15 | #include "cc/layers/layer_impl.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 16 | #include "cc/layers/render_pass_sink.h" |
ajuma | 50bce7e | 2016-06-24 20:56:04 | [diff] [blame] | 17 | #include "cc/output/filter_operations.h" |
[email protected] | 89e8267a | 2013-03-18 07:50:56 | [diff] [blame] | 18 | #include "cc/quads/debug_border_draw_quad.h" |
| 19 | #include "cc/quads/render_pass.h" |
| 20 | #include "cc/quads/render_pass_draw_quad.h" |
| 21 | #include "cc/quads/shared_quad_state.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 22 | #include "cc/trees/damage_tracker.h" |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 23 | #include "cc/trees/draw_property_utils.h" |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame^] | 24 | #include "cc/trees/effect_node.h" |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 25 | #include "cc/trees/layer_tree_impl.h" |
danakj | a1b92e4 | 2015-02-11 21:07:47 | [diff] [blame] | 26 | #include "cc/trees/occlusion.h" |
[email protected] | 55761e6 | 2012-11-21 18:55:58 | [diff] [blame] | 27 | #include "third_party/skia/include/core/SkImageFilter.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 28 | #include "ui/gfx/geometry/rect_conversions.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 29 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 30 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 31 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 32 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 33 | RenderSurfaceImpl::RenderSurfaceImpl(LayerImpl* owning_layer) |
| 34 | : owning_layer_(owning_layer), |
| 35 | surface_property_changed_(false), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 36 | contributes_to_drawn_surface_(false), |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 37 | nearest_occlusion_immune_ancestor_(nullptr), |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 38 | target_render_surface_layer_index_history_(0), |
| 39 | current_layer_index_history_(0) { |
| 40 | damage_tracker_ = DamageTracker::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 41 | } |
| 42 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 43 | RenderSurfaceImpl::~RenderSurfaceImpl() {} |
| 44 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 45 | RenderSurfaceImpl* RenderSurfaceImpl::render_target() { |
| 46 | EffectTree& effect_tree = |
| 47 | owning_layer_->layer_tree_impl()->property_trees()->effect_tree; |
| 48 | EffectNode* node = effect_tree.Node(EffectTreeIndex()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame^] | 49 | EffectNode* target_node = effect_tree.Node(node->target_id); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 50 | if (target_node->id != 0) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame^] | 51 | return target_node->render_surface; |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 52 | else |
| 53 | return this; |
| 54 | } |
| 55 | |
| 56 | const RenderSurfaceImpl* RenderSurfaceImpl::render_target() const { |
| 57 | const EffectTree& effect_tree = |
| 58 | owning_layer_->layer_tree_impl()->property_trees()->effect_tree; |
| 59 | const EffectNode* node = effect_tree.Node(EffectTreeIndex()); |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame^] | 60 | const EffectNode* target_node = effect_tree.Node(node->target_id); |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 61 | if (target_node->id != 0) |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame^] | 62 | return target_node->render_surface; |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 63 | else |
| 64 | return this; |
| 65 | } |
| 66 | |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 67 | RenderSurfaceImpl::DrawProperties::DrawProperties() { |
| 68 | draw_opacity = 1.f; |
| 69 | is_clipped = false; |
| 70 | } |
| 71 | |
| 72 | RenderSurfaceImpl::DrawProperties::~DrawProperties() {} |
| 73 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 74 | gfx::RectF RenderSurfaceImpl::DrawableContentRect() const { |
weiliangc | d68cf71 | 2016-05-02 23:29:07 | [diff] [blame] | 75 | if (content_rect().IsEmpty()) |
| 76 | return gfx::RectF(); |
| 77 | |
| 78 | gfx::Rect surface_content_rect = content_rect(); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 79 | if (!owning_layer_->filters().IsEmpty()) { |
jbroman | 1c44d5b5 | 2016-06-06 21:19:30 | [diff] [blame] | 80 | const gfx::Transform& owning_layer_draw_transform = |
| 81 | owning_layer_->DrawTransform(); |
| 82 | DCHECK(owning_layer_draw_transform.IsScale2d()); |
| 83 | surface_content_rect = owning_layer_->filters().MapRect( |
| 84 | surface_content_rect, owning_layer_draw_transform.matrix()); |
weiliangc | d68cf71 | 2016-05-02 23:29:07 | [diff] [blame] | 85 | } |
| 86 | gfx::RectF drawable_content_rect = MathUtil::MapClippedRect( |
| 87 | draw_transform(), gfx::RectF(surface_content_rect)); |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 88 | if (HasReplica()) { |
weiliangc | d68cf71 | 2016-05-02 23:29:07 | [diff] [blame] | 89 | drawable_content_rect.Union(MathUtil::MapClippedRect( |
| 90 | replica_draw_transform(), gfx::RectF(surface_content_rect))); |
| 91 | } else if (!owning_layer_->filters().IsEmpty() && is_clipped()) { |
| 92 | // Filter could move pixels around, but still need to be clipped. |
| 93 | drawable_content_rect.Intersect(gfx::RectF(clip_rect())); |
senorblanco | 38858c5 | 2016-01-20 23:15:00 | [diff] [blame] | 94 | } |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 95 | |
jaydasika | 5160e67 | 2015-10-15 15:25:14 | [diff] [blame] | 96 | // If the rect has a NaN coordinate, we return empty rect to avoid crashes in |
| 97 | // functions (for example, gfx::ToEnclosedRect) that are called on this rect. |
| 98 | if (std::isnan(drawable_content_rect.x()) || |
| 99 | std::isnan(drawable_content_rect.y()) || |
| 100 | std::isnan(drawable_content_rect.right()) || |
| 101 | std::isnan(drawable_content_rect.bottom())) |
| 102 | return gfx::RectF(); |
| 103 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 104 | return drawable_content_rect; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 105 | } |
| 106 | |
danakj | a1b92e4 | 2015-02-11 21:07:47 | [diff] [blame] | 107 | SkColor RenderSurfaceImpl::GetDebugBorderColor() const { |
| 108 | return DebugColors::SurfaceBorderColor(); |
| 109 | } |
| 110 | |
| 111 | SkColor RenderSurfaceImpl::GetReplicaDebugBorderColor() const { |
| 112 | return DebugColors::SurfaceReplicaBorderColor(); |
| 113 | } |
| 114 | |
| 115 | float RenderSurfaceImpl::GetDebugBorderWidth() const { |
| 116 | return DebugColors::SurfaceBorderWidth(owning_layer_->layer_tree_impl()); |
| 117 | } |
| 118 | |
| 119 | float RenderSurfaceImpl::GetReplicaDebugBorderWidth() const { |
| 120 | return DebugColors::SurfaceReplicaBorderWidth( |
| 121 | owning_layer_->layer_tree_impl()); |
| 122 | } |
| 123 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 124 | int RenderSurfaceImpl::OwningLayerId() const { |
| 125 | return owning_layer_ ? owning_layer_->id() : 0; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 126 | } |
| 127 | |
jaydasika | 7ba8f92 | 2015-08-21 05:39:42 | [diff] [blame] | 128 | bool RenderSurfaceImpl::HasReplica() const { |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame^] | 129 | return OwningEffectNode()->replica_layer_id != -1; |
jaydasika | 7ba8f92 | 2015-08-21 05:39:42 | [diff] [blame] | 130 | } |
| 131 | |
jaydasika | 23fb382 | 2015-08-25 03:22:59 | [diff] [blame] | 132 | const LayerImpl* RenderSurfaceImpl::ReplicaLayer() const { |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame^] | 133 | int replica_layer_id = OwningEffectNode()->replica_layer_id; |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 134 | return owning_layer_->layer_tree_impl()->LayerById(replica_layer_id); |
| 135 | } |
| 136 | |
| 137 | LayerImpl* RenderSurfaceImpl::ReplicaLayer() { |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame^] | 138 | int replica_layer_id = OwningEffectNode()->replica_layer_id; |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 139 | return owning_layer_->layer_tree_impl()->LayerById(replica_layer_id); |
| 140 | } |
| 141 | |
| 142 | LayerImpl* RenderSurfaceImpl::MaskLayer() { |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame^] | 143 | int mask_layer_id = OwningEffectNode()->mask_layer_id; |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 144 | return owning_layer_->layer_tree_impl()->LayerById(mask_layer_id); |
| 145 | } |
| 146 | |
| 147 | bool RenderSurfaceImpl::HasMask() const { |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame^] | 148 | return OwningEffectNode()->mask_layer_id != -1; |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | LayerImpl* RenderSurfaceImpl::ReplicaMaskLayer() { |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame^] | 152 | int replica_mask_layer_id = OwningEffectNode()->replica_mask_layer_id; |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 153 | return owning_layer_->layer_tree_impl()->LayerById(replica_mask_layer_id); |
| 154 | } |
| 155 | |
| 156 | bool RenderSurfaceImpl::HasReplicaMask() const { |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame^] | 157 | return OwningEffectNode()->replica_mask_layer_id != -1; |
jaydasika | 23fb382 | 2015-08-25 03:22:59 | [diff] [blame] | 158 | } |
| 159 | |
ajuma | 50bce7e | 2016-06-24 20:56:04 | [diff] [blame] | 160 | const FilterOperations& RenderSurfaceImpl::BackgroundFilters() const { |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame^] | 161 | return OwningEffectNode()->background_filters; |
ajuma | 50bce7e | 2016-06-24 20:56:04 | [diff] [blame] | 162 | } |
| 163 | |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 164 | bool RenderSurfaceImpl::HasCopyRequest() const { |
trchen | dba8b150 | 2016-07-08 09:47:01 | [diff] [blame^] | 165 | return OwningEffectNode()->has_copy_request; |
ajuma | e6f541b | 2016-05-31 16:50:50 | [diff] [blame] | 166 | } |
| 167 | |
jaydasika | 504a050 | 2015-07-23 19:25:44 | [diff] [blame] | 168 | int RenderSurfaceImpl::TransformTreeIndex() const { |
| 169 | return owning_layer_->transform_tree_index(); |
| 170 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 171 | |
jaydasika | ebf9e4ea | 2015-08-14 21:29:12 | [diff] [blame] | 172 | int RenderSurfaceImpl::ClipTreeIndex() const { |
| 173 | return owning_layer_->clip_tree_index(); |
| 174 | } |
| 175 | |
jaydasika | 0f4b1a9 | 2015-08-18 23:19:02 | [diff] [blame] | 176 | int RenderSurfaceImpl::EffectTreeIndex() const { |
| 177 | return owning_layer_->effect_tree_index(); |
| 178 | } |
| 179 | |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 180 | const EffectNode* RenderSurfaceImpl::OwningEffectNode() const { |
| 181 | return owning_layer_->layer_tree_impl()->property_trees()->effect_tree.Node( |
| 182 | EffectTreeIndex()); |
| 183 | } |
| 184 | |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 185 | void RenderSurfaceImpl::SetClipRect(const gfx::Rect& clip_rect) { |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 186 | if (clip_rect == draw_properties_.clip_rect) |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 187 | return; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 188 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 189 | surface_property_changed_ = true; |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 190 | draw_properties_.clip_rect = clip_rect; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 191 | } |
| 192 | |
[email protected] | 0023fc7 | 2014-01-10 20:05:06 | [diff] [blame] | 193 | void RenderSurfaceImpl::SetContentRect(const gfx::Rect& content_rect) { |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 194 | if (content_rect == draw_properties_.content_rect) |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 195 | return; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 196 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 197 | surface_property_changed_ = true; |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 198 | draw_properties_.content_rect = content_rect; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 199 | } |
| 200 | |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 201 | void RenderSurfaceImpl::SetContentRectForTesting(const gfx::Rect& rect) { |
| 202 | SetContentRect(rect); |
| 203 | } |
| 204 | |
| 205 | gfx::Rect RenderSurfaceImpl::CalculateClippedAccumulatedContentRect() { |
ajuma | 1d4026a3 | 2016-06-14 13:18:50 | [diff] [blame] | 206 | if (ReplicaLayer() || HasCopyRequest() || !is_clipped()) |
weiliangc | 6da3286 | 2016-04-20 16:40:11 | [diff] [blame] | 207 | return accumulated_content_rect(); |
| 208 | |
| 209 | if (accumulated_content_rect().IsEmpty()) |
| 210 | return gfx::Rect(); |
| 211 | |
| 212 | // Calculate projection from the target surface rect to local |
| 213 | // space. Non-invertible draw transforms means no able to bring clipped rect |
| 214 | // in target space back to local space, early out without clip. |
| 215 | gfx::Transform target_to_surface(gfx::Transform::kSkipInitialization); |
| 216 | if (!draw_transform().GetInverse(&target_to_surface)) |
| 217 | return accumulated_content_rect(); |
| 218 | |
| 219 | // Clip rect is in target space. Bring accumulated content rect to |
| 220 | // target space in preparation for clipping. |
| 221 | gfx::Rect accumulated_rect_in_target_space = |
| 222 | MathUtil::MapEnclosingClippedRect(draw_transform(), |
| 223 | accumulated_content_rect()); |
| 224 | // If accumulated content rect is contained within clip rect, early out |
| 225 | // without clipping. |
| 226 | if (clip_rect().Contains(accumulated_rect_in_target_space)) |
| 227 | return accumulated_content_rect(); |
| 228 | |
| 229 | gfx::Rect clipped_accumulated_rect_in_target_space = clip_rect(); |
| 230 | clipped_accumulated_rect_in_target_space.Intersect( |
| 231 | accumulated_rect_in_target_space); |
| 232 | |
| 233 | if (clipped_accumulated_rect_in_target_space.IsEmpty()) |
| 234 | return gfx::Rect(); |
| 235 | |
| 236 | gfx::Rect clipped_accumulated_rect_in_local_space = |
| 237 | MathUtil::ProjectEnclosingClippedRect( |
| 238 | target_to_surface, clipped_accumulated_rect_in_target_space); |
| 239 | // Bringing clipped accumulated rect back to local space may result |
| 240 | // in inflation due to axis-alignment. |
| 241 | clipped_accumulated_rect_in_local_space.Intersect(accumulated_content_rect()); |
| 242 | return clipped_accumulated_rect_in_local_space; |
| 243 | } |
| 244 | |
| 245 | void RenderSurfaceImpl::CalculateContentRectFromAccumulatedContentRect( |
| 246 | int max_texture_size) { |
| 247 | // Root render surface use viewport, and does not calculate content rect. |
| 248 | DCHECK_NE(render_target(), this); |
| 249 | |
| 250 | // Surface's content rect is the clipped accumulated content rect. By default |
| 251 | // use accumulated content rect, and then try to clip it. |
| 252 | gfx::Rect surface_content_rect = CalculateClippedAccumulatedContentRect(); |
| 253 | |
| 254 | // The RenderSurfaceImpl backing texture cannot exceed the maximum |
| 255 | // supported texture size. |
| 256 | surface_content_rect.set_width( |
| 257 | std::min(surface_content_rect.width(), max_texture_size)); |
| 258 | surface_content_rect.set_height( |
| 259 | std::min(surface_content_rect.height(), max_texture_size)); |
| 260 | |
| 261 | SetContentRect(surface_content_rect); |
| 262 | } |
| 263 | |
| 264 | void RenderSurfaceImpl::SetContentRectToViewport() { |
| 265 | // Only root render surface use viewport as content rect. |
| 266 | DCHECK_EQ(render_target(), this); |
| 267 | gfx::Rect viewport = gfx::ToEnclosingRect(owning_layer_->layer_tree_impl() |
| 268 | ->property_trees() |
| 269 | ->clip_tree.ViewportClip()); |
| 270 | SetContentRect(viewport); |
| 271 | } |
| 272 | |
weiliangc | 189c1a1 | 2016-04-11 16:16:25 | [diff] [blame] | 273 | void RenderSurfaceImpl::ClearAccumulatedContentRect() { |
| 274 | accumulated_content_rect_ = gfx::Rect(); |
| 275 | } |
| 276 | |
| 277 | void RenderSurfaceImpl::AccumulateContentRectFromContributingLayer( |
| 278 | LayerImpl* layer) { |
| 279 | DCHECK(layer->DrawsContent()); |
| 280 | DCHECK_EQ(this, layer->render_target()); |
| 281 | |
| 282 | // Root render surface doesn't accumulate content rect, it always uses |
| 283 | // viewport for content rect. |
| 284 | if (render_target() == this) |
| 285 | return; |
| 286 | |
| 287 | accumulated_content_rect_.Union(layer->drawable_content_rect()); |
| 288 | } |
| 289 | |
| 290 | void RenderSurfaceImpl::AccumulateContentRectFromContributingRenderSurface( |
| 291 | RenderSurfaceImpl* contributing_surface) { |
| 292 | DCHECK_NE(this, contributing_surface); |
| 293 | DCHECK_EQ(this, contributing_surface->render_target()); |
| 294 | |
| 295 | // Root render surface doesn't accumulate content rect, it always uses |
| 296 | // viewport for content rect. |
| 297 | if (render_target() == this) |
| 298 | return; |
| 299 | |
| 300 | // The content rect of contributing surface is in its own space. Instead, we |
| 301 | // will use contributing surface's DrawableContentRect which is in target |
| 302 | // space (local space for this render surface) as required. |
| 303 | accumulated_content_rect_.Union( |
| 304 | gfx::ToEnclosedRect(contributing_surface->DrawableContentRect())); |
jaydasika | 7ba8f92 | 2015-08-21 05:39:42 | [diff] [blame] | 305 | } |
| 306 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 307 | bool RenderSurfaceImpl::SurfacePropertyChanged() const { |
| 308 | // Surface property changes are tracked as follows: |
| 309 | // |
| 310 | // - surface_property_changed_ is flagged when the clip_rect or content_rect |
| 311 | // change. As of now, these are the only two properties that can be affected |
| 312 | // by descendant layers. |
| 313 | // |
| 314 | // - all other property changes come from the owning layer (or some ancestor |
| 315 | // layer that propagates its change to the owning layer). |
| 316 | // |
| 317 | DCHECK(owning_layer_); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 318 | return surface_property_changed_ || owning_layer_->LayerPropertyChanged(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 319 | } |
| 320 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 321 | bool RenderSurfaceImpl::SurfacePropertyChangedOnlyFromDescendant() const { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 322 | return surface_property_changed_ && !owning_layer_->LayerPropertyChanged(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 323 | } |
| 324 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 325 | void RenderSurfaceImpl::ClearLayerLists() { |
| 326 | layer_list_.clear(); |
[email protected] | 7d929c0 | 2012-09-20 17:26:57 | [diff] [blame] | 327 | } |
| 328 | |
[email protected] | 0cd7d6f7 | 2014-08-22 14:50:51 | [diff] [blame] | 329 | RenderPassId RenderSurfaceImpl::GetRenderPassId() { |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 330 | int layer_id = owning_layer_->id(); |
| 331 | int sub_id = 0; |
| 332 | DCHECK_GT(layer_id, 0); |
[email protected] | 0cd7d6f7 | 2014-08-22 14:50:51 | [diff] [blame] | 333 | return RenderPassId(layer_id, sub_id); |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 334 | } |
| 335 | |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 336 | void RenderSurfaceImpl::AppendRenderPasses(RenderPassSink* pass_sink) { |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 337 | std::unique_ptr<RenderPass> pass = RenderPass::Create(layer_list_.size()); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 338 | pass->SetNew(GetRenderPassId(), content_rect(), |
| 339 | gfx::IntersectRects(content_rect(), |
[email protected] | b4ead7b | 2014-04-07 18:12:18 | [diff] [blame] | 340 | damage_tracker_->current_damage_rect()), |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 341 | draw_properties_.screen_space_transform); |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 342 | pass_sink->AppendRenderPass(std::move(pass)); |
[email protected] | 467b361 | 2012-08-28 07:41:16 | [diff] [blame] | 343 | } |
| 344 | |
danakj | a1b92e4 | 2015-02-11 21:07:47 | [diff] [blame] | 345 | void RenderSurfaceImpl::AppendQuads(RenderPass* render_pass, |
| 346 | const gfx::Transform& draw_transform, |
| 347 | const Occlusion& occlusion_in_content_space, |
| 348 | SkColor debug_border_color, |
| 349 | float debug_border_width, |
| 350 | LayerImpl* mask_layer, |
| 351 | AppendQuadsData* append_quads_data, |
| 352 | RenderPassId render_pass_id) { |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 353 | gfx::Rect visible_layer_rect = |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 354 | occlusion_in_content_space.GetUnoccludedContentRect(content_rect()); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 355 | if (visible_layer_rect.IsEmpty()) |
[email protected] | ba0f8d9 | 2014-03-21 18:41:10 | [diff] [blame] | 356 | return; |
| 357 | |
[email protected] | c6707fd | 2014-06-23 05:50:36 | [diff] [blame] | 358 | SharedQuadState* shared_quad_state = |
| 359 | render_pass->CreateAndAppendSharedQuadState(); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 360 | shared_quad_state->SetAll( |
| 361 | draw_transform, content_rect().size(), content_rect(), |
| 362 | draw_properties_.clip_rect, draw_properties_.is_clipped, |
| 363 | draw_properties_.draw_opacity, owning_layer_->blend_mode(), |
| 364 | owning_layer_->sorting_context_id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 365 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 366 | if (owning_layer_->ShowDebugBorders()) { |
[email protected] | f7030c3 | 2014-07-03 18:54:34 | [diff] [blame] | 367 | DebugBorderDrawQuad* debug_border_quad = |
| 368 | render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>(); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 369 | debug_border_quad->SetNew(shared_quad_state, content_rect(), |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 370 | visible_layer_rect, debug_border_color, |
danakj | a1b92e4 | 2015-02-11 21:07:47 | [diff] [blame] | 371 | debug_border_width); |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 372 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 373 | |
jbauman | bbd425e | 2015-05-19 00:33:35 | [diff] [blame] | 374 | ResourceId mask_resource_id = 0; |
enne | f6f3fbba4 | 2014-10-16 18:16:49 | [diff] [blame] | 375 | gfx::Size mask_texture_size; |
| 376 | gfx::Vector2dF mask_uv_scale; |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 377 | gfx::Transform owning_layer_draw_transform = owning_layer_->DrawTransform(); |
danakj | a1b92e4 | 2015-02-11 21:07:47 | [diff] [blame] | 378 | if (mask_layer && mask_layer->DrawsContent() && |
| 379 | !mask_layer->bounds().IsEmpty()) { |
enne | f6f3fbba4 | 2014-10-16 18:16:49 | [diff] [blame] | 380 | mask_layer->GetContentsResourceId(&mask_resource_id, &mask_texture_size); |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 381 | gfx::Vector2dF owning_layer_draw_scale = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 382 | MathUtil::ComputeTransform2dScaleComponents(owning_layer_draw_transform, |
| 383 | 1.f); |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 384 | gfx::SizeF unclipped_mask_target_size = gfx::ScaleSize( |
| 385 | gfx::SizeF(owning_layer_->bounds()), owning_layer_draw_scale.x(), |
| 386 | owning_layer_draw_scale.y()); |
senorblanco | dfcb362 | 2016-01-27 21:48:01 | [diff] [blame] | 387 | mask_uv_scale = gfx::Vector2dF(1.0f / unclipped_mask_target_size.width(), |
| 388 | 1.0f / unclipped_mask_target_size.height()); |
[email protected] | d2d915aa | 2013-03-08 20:18:12 | [diff] [blame] | 389 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 390 | |
robertn | ce99907 | 2016-01-05 15:06:13 | [diff] [blame] | 391 | DCHECK(owning_layer_draw_transform.IsScale2d()); |
[email protected] | 7ac3d49 | 2014-08-08 21:25:32 | [diff] [blame] | 392 | gfx::Vector2dF owning_layer_to_target_scale = |
ajuma | d9432e3 | 2015-11-30 19:43:44 | [diff] [blame] | 393 | owning_layer_draw_transform.Scale2d(); |
[email protected] | 7ac3d49 | 2014-08-08 21:25:32 | [diff] [blame] | 394 | |
[email protected] | f7030c3 | 2014-07-03 18:54:34 | [diff] [blame] | 395 | RenderPassDrawQuad* quad = |
| 396 | render_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); |
weiliangc | c97575c | 2016-03-03 18:34:27 | [diff] [blame] | 397 | quad->SetNew(shared_quad_state, content_rect(), visible_layer_rect, |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 398 | render_pass_id, mask_resource_id, mask_uv_scale, |
| 399 | mask_texture_size, owning_layer_->filters(), |
ajuma | 50bce7e | 2016-06-24 20:56:04 | [diff] [blame] | 400 | owning_layer_to_target_scale, BackgroundFilters()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 401 | } |
| 402 | |
[email protected] | bc5e77c | 2012-11-05 20:00:49 | [diff] [blame] | 403 | } // namespace cc |