| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/damage_tracker.h" | 5 #include "cc/damage_tracker.h" |
| 6 | 6 |
| 7 #include "cc/layer_impl.h" | 7 #include "cc/layer_impl.h" |
| 8 #include "cc/layer_tree_host_common.h" | 8 #include "cc/layer_tree_host_common.h" |
| 9 #include "cc/math_util.h" | 9 #include "cc/math_util.h" |
| 10 #include "cc/render_surface_impl.h" | 10 #include "cc/render_surface_impl.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 gfx::RectF DamageTracker::TrackDamageFromSurfaceMask( | 203 gfx::RectF DamageTracker::TrackDamageFromSurfaceMask( |
| 204 LayerImpl* target_surface_mask_layer) { | 204 LayerImpl* target_surface_mask_layer) { |
| 205 gfx::RectF damage_rect = gfx::RectF(); | 205 gfx::RectF damage_rect = gfx::RectF(); |
| 206 | 206 |
| 207 if (!target_surface_mask_layer) | 207 if (!target_surface_mask_layer) |
| 208 return damage_rect; | 208 return damage_rect; |
| 209 | 209 |
| 210 // Currently, if there is any change to the mask, we choose to damage the | 210 // Currently, if there is any change to the mask, we choose to damage the |
| 211 // entire surface. This could potentially be optimized later, but it is not | 211 // entire surface. This could potentially be optimized later, but it is not |
| 212 // expected to be a common case. | 212 // expected to be a common case. |
| 213 if (target_surface_mask_layer->layerPropertyChanged() || | 213 if (target_surface_mask_layer->LayerPropertyChanged() || |
| 214 !target_surface_mask_layer->updateRect().IsEmpty()) { | 214 !target_surface_mask_layer->update_rect().IsEmpty()) { |
| 215 damage_rect = gfx::RectF(gfx::PointF(), | 215 damage_rect = gfx::RectF(gfx::PointF(), |
| 216 target_surface_mask_layer->bounds()); | 216 target_surface_mask_layer->bounds()); |
| 217 } | 217 } |
| 218 | 218 |
| 219 return damage_rect; | 219 return damage_rect; |
| 220 } | 220 } |
| 221 | 221 |
| 222 gfx::RectF DamageTracker::TrackDamageFromLeftoverRects() { | 222 gfx::RectF DamageTracker::TrackDamageFromLeftoverRects() { |
| 223 // After computing damage for all active layers, any leftover items in the | 223 // After computing damage for all active layers, any leftover items in the |
| 224 // current rect history correspond to layers/surfaces that no longer exist. | 224 // current rect history correspond to layers/surfaces that no longer exist. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 235 | 235 |
| 236 return damage_rect; | 236 return damage_rect; |
| 237 } | 237 } |
| 238 | 238 |
| 239 static bool LayerNeedsToRedrawOntoItsTargetSurface(LayerImpl* layer) { | 239 static bool LayerNeedsToRedrawOntoItsTargetSurface(LayerImpl* layer) { |
| 240 // If the layer does NOT own a surface but has SurfacePropertyChanged, | 240 // If the layer does NOT own a surface but has SurfacePropertyChanged, |
| 241 // this means that its target surface is affected and needs to be redrawn. | 241 // this means that its target surface is affected and needs to be redrawn. |
| 242 // However, if the layer DOES own a surface, then the SurfacePropertyChanged | 242 // However, if the layer DOES own a surface, then the SurfacePropertyChanged |
| 243 // flag should not be used here, because that flag represents whether the | 243 // flag should not be used here, because that flag represents whether the |
| 244 // layer's surface has changed. | 244 // layer's surface has changed. |
| 245 if (layer->renderSurface()) | 245 if (layer->render_surface()) |
| 246 return layer->layerPropertyChanged(); | 246 return layer->LayerPropertyChanged(); |
| 247 return layer->layerPropertyChanged() || layer->layerSurfacePropertyChanged(); | 247 return layer->LayerPropertyChanged() || layer->LayerSurfacePropertyChanged(); |
| 248 } | 248 } |
| 249 | 249 |
| 250 void DamageTracker::ExtendDamageForLayer(LayerImpl* layer, | 250 void DamageTracker::ExtendDamageForLayer(LayerImpl* layer, |
| 251 gfx::RectF* target_damage_rect) { | 251 gfx::RectF* target_damage_rect) { |
| 252 // There are two ways that a layer can damage a region of the target surface: | 252 // There are two ways that a layer can damage a region of the target surface: |
| 253 // 1. Property change (e.g. opacity, position, transforms): | 253 // 1. Property change (e.g. opacity, position, transforms): |
| 254 // - the entire region of the layer itself damages the surface. | 254 // - the entire region of the layer itself damages the surface. |
| 255 // - the old layer region also damages the surface, because this region | 255 // - the old layer region also damages the surface, because this region |
| 256 // is now exposed. | 256 // is now exposed. |
| 257 // - note that in many cases the old and new layer rects may overlap, | 257 // - note that in many cases the old and new layer rects may overlap, |
| 258 // which is fine. | 258 // which is fine. |
| 259 // | 259 // |
| 260 // 2. Repaint/update: If a region of the layer that was repainted/updated, | 260 // 2. Repaint/update: If a region of the layer that was repainted/updated, |
| 261 // that region damages the surface. | 261 // that region damages the surface. |
| 262 // | 262 // |
| 263 // Property changes take priority over update rects. | 263 // Property changes take priority over update rects. |
| 264 // | 264 // |
| 265 // This method is called when we want to consider how a layer contributes to | 265 // This method is called when we want to consider how a layer contributes to |
| 266 // its targetRenderSurface, even if that layer owns the targetRenderSurface | 266 // its targetRenderSurface, even if that layer owns the targetRenderSurface |
| 267 // itself. To consider how a layer's targetSurface contributes to the | 267 // itself. To consider how a layer's targetSurface contributes to the |
| 268 // ancestorSurface, ExtendDamageForRenderSurface() must be called instead. | 268 // ancestorSurface, ExtendDamageForRenderSurface() must be called instead. |
| 269 | 269 |
| 270 bool layer_is_new = false; | 270 bool layer_is_new = false; |
| 271 gfx::RectF old_rect_in_target_space = | 271 gfx::RectF old_rect_in_target_space = |
| 272 RemoveRectFromCurrentFrame(layer->id(), &layer_is_new); | 272 RemoveRectFromCurrentFrame(layer->id(), &layer_is_new); |
| 273 | 273 |
| 274 gfx::RectF rect_in_target_space = MathUtil::mapClippedRect( | 274 gfx::RectF rect_in_target_space = MathUtil::mapClippedRect( |
| 275 layer->drawTransform(), | 275 layer->draw_transform(), |
| 276 gfx::RectF(gfx::PointF(), layer->contentBounds())); | 276 gfx::RectF(gfx::PointF(), layer->content_bounds())); |
| 277 SaveRectForNextFrame(layer->id(), rect_in_target_space); | 277 SaveRectForNextFrame(layer->id(), rect_in_target_space); |
| 278 | 278 |
| 279 if (layer_is_new || LayerNeedsToRedrawOntoItsTargetSurface(layer)) { | 279 if (layer_is_new || LayerNeedsToRedrawOntoItsTargetSurface(layer)) { |
| 280 // If a layer is new or has changed, then its entire layer rect affects the | 280 // If a layer is new or has changed, then its entire layer rect affects the |
| 281 // target surface. | 281 // target surface. |
| 282 target_damage_rect->Union(rect_in_target_space); | 282 target_damage_rect->Union(rect_in_target_space); |
| 283 | 283 |
| 284 // The layer's old region is now exposed on the target surface, too. | 284 // The layer's old region is now exposed on the target surface, too. |
| 285 // Note old_rect_in_target_space is already in target space. | 285 // Note old_rect_in_target_space is already in target space. |
| 286 target_damage_rect->Union(old_rect_in_target_space); | 286 target_damage_rect->Union(old_rect_in_target_space); |
| 287 } else if (!layer->updateRect().IsEmpty()) { | 287 } else if (!layer->update_rect().IsEmpty()) { |
| 288 // If the layer properties haven't changed, then the the target surface is | 288 // If the layer properties haven't changed, then the the target surface is |
| 289 // only affected by the layer's update area, which could be empty. | 289 // only affected by the layer's update area, which could be empty. |
| 290 gfx::RectF update_content_rect = | 290 gfx::RectF update_content_rect = |
| 291 layer->layerRectToContentRect(layer->updateRect()); | 291 layer->LayerRectToContentRect(layer->update_rect()); |
| 292 gfx::RectF update_rect_in_target_space = | 292 gfx::RectF update_rect_in_target_space = |
| 293 MathUtil::mapClippedRect(layer->drawTransform(), update_content_rect); | 293 MathUtil::mapClippedRect(layer->draw_transform(), update_content_rect); |
| 294 target_damage_rect->Union(update_rect_in_target_space); | 294 target_damage_rect->Union(update_rect_in_target_space); |
| 295 } | 295 } |
| 296 } | 296 } |
| 297 | 297 |
| 298 void DamageTracker::ExtendDamageForRenderSurface( | 298 void DamageTracker::ExtendDamageForRenderSurface( |
| 299 LayerImpl* layer, gfx::RectF* target_damage_rect) { | 299 LayerImpl* layer, gfx::RectF* target_damage_rect) { |
| 300 // There are two ways a "descendant surface" can damage regions of the "target | 300 // There are two ways a "descendant surface" can damage regions of the "target |
| 301 // surface": | 301 // surface": |
| 302 // 1. Property change: | 302 // 1. Property change: |
| 303 // - a surface's geometry can change because of | 303 // - a surface's geometry can change because of |
| 304 // - changes to descendants (i.e. the subtree) that affect the | 304 // - changes to descendants (i.e. the subtree) that affect the |
| 305 // surface's content rect | 305 // surface's content rect |
| 306 // - changes to ancestor layers that propagate their property | 306 // - changes to ancestor layers that propagate their property |
| 307 // changes to their entire subtree. | 307 // changes to their entire subtree. |
| 308 // - just like layers, both the old surface rect and new surface rect | 308 // - just like layers, both the old surface rect and new surface rect |
| 309 // will damage the target surface in this case. | 309 // will damage the target surface in this case. |
| 310 // | 310 // |
| 311 // 2. Damage rect: This surface may have been damaged by its own layer_list | 311 // 2. Damage rect: This surface may have been damaged by its own layer_list |
| 312 // as well, and that damage should propagate to the target surface. | 312 // as well, and that damage should propagate to the target surface. |
| 313 // | 313 // |
| 314 | 314 |
| 315 RenderSurfaceImpl* render_surface = layer->renderSurface(); | 315 RenderSurfaceImpl* render_surface = layer->render_surface(); |
| 316 | 316 |
| 317 bool surface_is_new = false; | 317 bool surface_is_new = false; |
| 318 gfx::RectF old_surface_rect = RemoveRectFromCurrentFrame(layer->id(), | 318 gfx::RectF old_surface_rect = RemoveRectFromCurrentFrame(layer->id(), |
| 319 &surface_is_new); | 319 &surface_is_new); |
| 320 | 320 |
| 321 // The drawableContextRect() already includes the replica if it exists. | 321 // The drawableContextRect() already includes the replica if it exists. |
| 322 gfx::RectF surface_rect_in_target_space = | 322 gfx::RectF surface_rect_in_target_space = |
| 323 render_surface->DrawableContentRect(); | 323 render_surface->DrawableContentRect(); |
| 324 SaveRectForNextFrame(layer->id(), surface_rect_in_target_space); | 324 SaveRectForNextFrame(layer->id(), surface_rect_in_target_space); |
| 325 | 325 |
| 326 gfx::RectF damage_rect_in_local_space; | 326 gfx::RectF damage_rect_in_local_space; |
| 327 if (surface_is_new || | 327 if (surface_is_new || |
| 328 render_surface->SurfacePropertyChanged() || | 328 render_surface->SurfacePropertyChanged() || |
| 329 layer->layerSurfacePropertyChanged()) { | 329 layer->LayerSurfacePropertyChanged()) { |
| 330 // The entire surface contributes damage. | 330 // The entire surface contributes damage. |
| 331 damage_rect_in_local_space = render_surface->content_rect(); | 331 damage_rect_in_local_space = render_surface->content_rect(); |
| 332 | 332 |
| 333 // The surface's old region is now exposed on the target surface, too. | 333 // The surface's old region is now exposed on the target surface, too. |
| 334 target_damage_rect->Union(old_surface_rect); | 334 target_damage_rect->Union(old_surface_rect); |
| 335 } else { | 335 } else { |
| 336 // Only the surface's damage_rect will damage the target surface. | 336 // Only the surface's damage_rect will damage the target surface. |
| 337 damage_rect_in_local_space = | 337 damage_rect_in_local_space = |
| 338 render_surface->damage_tracker()->current_damage_rect(); | 338 render_surface->damage_tracker()->current_damage_rect(); |
| 339 } | 339 } |
| 340 | 340 |
| 341 // If there was damage, transform it to target space, and possibly contribute | 341 // If there was damage, transform it to target space, and possibly contribute |
| 342 // its reflection if needed. | 342 // its reflection if needed. |
| 343 if (!damage_rect_in_local_space.IsEmpty()) { | 343 if (!damage_rect_in_local_space.IsEmpty()) { |
| 344 const gfx::Transform& draw_transform = render_surface->draw_transform(); | 344 const gfx::Transform& draw_transform = render_surface->draw_transform(); |
| 345 gfx::RectF damage_rect_in_target_space = | 345 gfx::RectF damage_rect_in_target_space = |
| 346 MathUtil::mapClippedRect(draw_transform, damage_rect_in_local_space); | 346 MathUtil::mapClippedRect(draw_transform, damage_rect_in_local_space); |
| 347 target_damage_rect->Union(damage_rect_in_target_space); | 347 target_damage_rect->Union(damage_rect_in_target_space); |
| 348 | 348 |
| 349 if (layer->replicaLayer()) { | 349 if (layer->replica_layer()) { |
| 350 const gfx::Transform& replica_draw_transform = | 350 const gfx::Transform& replica_draw_transform = |
| 351 render_surface->replica_draw_transform(); | 351 render_surface->replica_draw_transform(); |
| 352 target_damage_rect->Union(MathUtil::mapClippedRect( | 352 target_damage_rect->Union(MathUtil::mapClippedRect( |
| 353 replica_draw_transform, damage_rect_in_local_space)); | 353 replica_draw_transform, damage_rect_in_local_space)); |
| 354 } | 354 } |
| 355 } | 355 } |
| 356 | 356 |
| 357 // If there was damage on the replica's mask, then the target surface receives | 357 // If there was damage on the replica's mask, then the target surface receives |
| 358 // that damage as well. | 358 // that damage as well. |
| 359 if (layer->replicaLayer() && layer->replicaLayer()->maskLayer()) { | 359 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) { |
| 360 LayerImpl* replica_mask_layer = layer->replicaLayer()->maskLayer(); | 360 LayerImpl* replica_mask_layer = layer->replica_layer()->mask_layer(); |
| 361 | 361 |
| 362 bool replica_is_new = false; | 362 bool replica_is_new = false; |
| 363 RemoveRectFromCurrentFrame(replica_mask_layer->id(), &replica_is_new); | 363 RemoveRectFromCurrentFrame(replica_mask_layer->id(), &replica_is_new); |
| 364 | 364 |
| 365 const gfx::Transform& replica_draw_transform = | 365 const gfx::Transform& replica_draw_transform = |
| 366 render_surface->replica_draw_transform(); | 366 render_surface->replica_draw_transform(); |
| 367 gfx::RectF replica_mask_layer_rect = MathUtil::mapClippedRect( | 367 gfx::RectF replica_mask_layer_rect = MathUtil::mapClippedRect( |
| 368 replica_draw_transform, | 368 replica_draw_transform, |
| 369 gfx::RectF(gfx::PointF(), replica_mask_layer->bounds())); | 369 gfx::RectF(gfx::PointF(), replica_mask_layer->bounds())); |
| 370 SaveRectForNextFrame(replica_mask_layer->id(), replica_mask_layer_rect); | 370 SaveRectForNextFrame(replica_mask_layer->id(), replica_mask_layer_rect); |
| 371 | 371 |
| 372 // In the current implementation, a change in the replica mask damages the | 372 // In the current implementation, a change in the replica mask damages the |
| 373 // entire replica region. | 373 // entire replica region. |
| 374 if (replica_is_new || | 374 if (replica_is_new || |
| 375 replica_mask_layer->layerPropertyChanged() || | 375 replica_mask_layer->LayerPropertyChanged() || |
| 376 !replica_mask_layer->updateRect().IsEmpty()) | 376 !replica_mask_layer->update_rect().IsEmpty()) |
| 377 target_damage_rect->Union(replica_mask_layer_rect); | 377 target_damage_rect->Union(replica_mask_layer_rect); |
| 378 } | 378 } |
| 379 | 379 |
| 380 // If the layer has a background filter, this may cause pixels in our surface | 380 // If the layer has a background filter, this may cause pixels in our surface |
| 381 // to be expanded, so we will need to expand any damage at or below this | 381 // to be expanded, so we will need to expand any damage at or below this |
| 382 // layer. We expand the damage from this layer too, as we need to readback | 382 // layer. We expand the damage from this layer too, as we need to readback |
| 383 // those pixels from the surface with only the contents of layers below this | 383 // those pixels from the surface with only the contents of layers below this |
| 384 // one in them. This means we need to redraw any pixels in the surface being | 384 // one in them. This means we need to redraw any pixels in the surface being |
| 385 // used for the blur in this layer this frame. | 385 // used for the blur in this layer this frame. |
| 386 if (layer->backgroundFilters().hasFilterThatMovesPixels()) { | 386 if (layer->background_filters().hasFilterThatMovesPixels()) { |
| 387 ExpandDamageRectInsideRectWithFilters(target_damage_rect, | 387 ExpandDamageRectInsideRectWithFilters(target_damage_rect, |
| 388 surface_rect_in_target_space, | 388 surface_rect_in_target_space, |
| 389 layer->backgroundFilters()); | 389 layer->background_filters()); |
| 390 } | 390 } |
| 391 } | 391 } |
| 392 | 392 |
| 393 } // namespace cc | 393 } // namespace cc |
| OLD | NEW |