| 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/trees/damage_tracker.h" | 5 #include "cc/trees/damage_tracker.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 10 #include "cc/layers/heads_up_display_layer_impl.h" | 10 #include "cc/layers/heads_up_display_layer_impl.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // | 118 // |
| 119 // 3. After the damage rect is computed, the leftover not marked regions | 119 // 3. After the damage rect is computed, the leftover not marked regions |
| 120 // in a map are used to compute are damaged by deleted layers and | 120 // in a map are used to compute are damaged by deleted layers and |
| 121 // erased from map. | 121 // erased from map. |
| 122 // | 122 // |
| 123 | 123 |
| 124 PrepareRectHistoryForUpdate(); | 124 PrepareRectHistoryForUpdate(); |
| 125 // These functions cannot be bypassed with early-exits, even if we know what | 125 // These functions cannot be bypassed with early-exits, even if we know what |
| 126 // the damage will be for this frame, because we need to update the damage | 126 // the damage will be for this frame, because we need to update the damage |
| 127 // tracker state to correctly track the next frame. | 127 // tracker state to correctly track the next frame. |
| 128 gfx::Rect damage_from_active_layers = | 128 gfx::Rect damage_from_active_layers; |
| 129 TrackDamageFromActiveLayers(layer_list, target_surface_layer_id); | 129 TrackDamageFromActiveLayers(layer_list, target_surface_layer_id, |
| 130 &damage_from_active_layers, |
| 131 ¤t_overlay_rect_); |
| 130 gfx::Rect damage_from_surface_mask = | 132 gfx::Rect damage_from_surface_mask = |
| 131 TrackDamageFromSurfaceMask(target_surface_mask_layer); | 133 TrackDamageFromSurfaceMask(target_surface_mask_layer); |
| 132 gfx::Rect damage_from_leftover_rects = TrackDamageFromLeftoverRects(); | 134 gfx::Rect damage_from_leftover_rects = TrackDamageFromLeftoverRects(); |
| 133 | 135 |
| 134 gfx::Rect damage_rect_for_this_update; | 136 gfx::Rect damage_rect_for_this_update; |
| 135 | 137 |
| 136 if (target_surface_property_changed_only_from_descendant) { | 138 if (target_surface_property_changed_only_from_descendant) { |
| 137 damage_rect_for_this_update = target_surface_content_rect; | 139 damage_rect_for_this_update = target_surface_content_rect; |
| 138 } else { | 140 } else { |
| 139 // TODO(shawnsingh): can we clamp this damage to the surface's content rect? | 141 // TODO(shawnsingh): can we clamp this damage to the surface's content rect? |
| (...skipping 26 matching lines...) Expand all Loading... |
| 166 rect_history_.end(), data); | 168 rect_history_.end(), data); |
| 167 | 169 |
| 168 if (it == rect_history_.end() || it->layer_id_ != layer_id) { | 170 if (it == rect_history_.end() || it->layer_id_ != layer_id) { |
| 169 *layer_is_new = true; | 171 *layer_is_new = true; |
| 170 it = rect_history_.insert(it, data); | 172 it = rect_history_.insert(it, data); |
| 171 } | 173 } |
| 172 | 174 |
| 173 return *it; | 175 return *it; |
| 174 } | 176 } |
| 175 | 177 |
| 176 gfx::Rect DamageTracker::TrackDamageFromActiveLayers( | 178 void DamageTracker::TrackDamageFromActiveLayers(const LayerImplList& layer_list, |
| 177 const LayerImplList& layer_list, | 179 int target_surface_layer_id, |
| 178 int target_surface_layer_id) { | 180 gfx::Rect* damage, |
| 181 gfx::Rect* overlay) { |
| 179 gfx::Rect damage_rect; | 182 gfx::Rect damage_rect; |
| 180 | 183 |
| 181 for (size_t layer_index = 0; layer_index < layer_list.size(); ++layer_index) { | 184 for (size_t layer_index = 0; layer_index < layer_list.size(); ++layer_index) { |
| 182 // Visit layers in back-to-front order. | 185 // Visit layers in back-to-front order. |
| 183 LayerImpl* layer = layer_list[layer_index]; | 186 LayerImpl* layer = layer_list[layer_index]; |
| 184 | 187 |
| 185 // We skip damage from the HUD layer because (a) the HUD layer damages the | 188 // We skip damage from the HUD layer because (a) the HUD layer damages the |
| 186 // whole frame and (b) we don't want HUD layer damage to be shown by the | 189 // whole frame and (b) we don't want HUD layer damage to be shown by the |
| 187 // HUD damage rect visualization. | 190 // HUD damage rect visualization. |
| 188 if (layer == layer->layer_tree_impl()->hud_layer()) | 191 if (layer == layer->layer_tree_impl()->hud_layer()) |
| 189 continue; | 192 continue; |
| 190 if (LayerTreeHostCommon::RenderSurfaceContributesToTarget<LayerImpl>( | 193 if (LayerTreeHostCommon::RenderSurfaceContributesToTarget<LayerImpl>( |
| 191 layer, target_surface_layer_id)) | 194 layer, target_surface_layer_id)) |
| 192 ExtendDamageForRenderSurface(layer, &damage_rect); | 195 ExtendDamageForRenderSurface(layer, damage); |
| 193 else | 196 else |
| 194 ExtendDamageForLayer(layer, &damage_rect); | 197 ExtendDamageForLayer(layer, damage, overlay); |
| 195 } | 198 } |
| 196 | |
| 197 return damage_rect; | |
| 198 } | 199 } |
| 199 | 200 |
| 200 gfx::Rect DamageTracker::TrackDamageFromSurfaceMask( | 201 gfx::Rect DamageTracker::TrackDamageFromSurfaceMask( |
| 201 LayerImpl* target_surface_mask_layer) { | 202 LayerImpl* target_surface_mask_layer) { |
| 202 gfx::Rect damage_rect; | 203 gfx::Rect damage_rect; |
| 203 | 204 |
| 204 if (!target_surface_mask_layer) | 205 if (!target_surface_mask_layer) |
| 205 return damage_rect; | 206 return damage_rect; |
| 206 | 207 |
| 207 // Currently, if there is any change to the mask, we choose to damage the | 208 // Currently, if there is any change to the mask, we choose to damage the |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 rect_history_.erase(copy_pos, rect_history_.end()); | 254 rect_history_.erase(copy_pos, rect_history_.end()); |
| 254 | 255 |
| 255 // If the vector has excessive storage, shrink it | 256 // If the vector has excessive storage, shrink it |
| 256 if (rect_history_.capacity() > rect_history_.size() * 4) | 257 if (rect_history_.capacity() > rect_history_.size() * 4) |
| 257 SortedRectMap(rect_history_).swap(rect_history_); | 258 SortedRectMap(rect_history_).swap(rect_history_); |
| 258 | 259 |
| 259 return damage_rect; | 260 return damage_rect; |
| 260 } | 261 } |
| 261 | 262 |
| 262 void DamageTracker::ExtendDamageForLayer(LayerImpl* layer, | 263 void DamageTracker::ExtendDamageForLayer(LayerImpl* layer, |
| 263 gfx::Rect* target_damage_rect) { | 264 gfx::Rect* target_damage_rect, |
| 265 gfx::Rect* target_overlay_rect) { |
| 264 // There are two ways that a layer can damage a region of the target surface: | 266 // There are two ways that a layer can damage a region of the target surface: |
| 265 // 1. Property change (e.g. opacity, position, transforms): | 267 // 1. Property change (e.g. opacity, position, transforms): |
| 266 // - the entire region of the layer itself damages the surface. | 268 // - the entire region of the layer itself damages the surface. |
| 267 // - the old layer region also damages the surface, because this region | 269 // - the old layer region also damages the surface, because this region |
| 268 // is now exposed. | 270 // is now exposed. |
| 269 // - note that in many cases the old and new layer rects may overlap, | 271 // - note that in many cases the old and new layer rects may overlap, |
| 270 // which is fine. | 272 // which is fine. |
| 271 // | 273 // |
| 272 // 2. Repaint/update: If a region of the layer that was repainted/updated, | 274 // 2. Repaint/update: If a region of the layer that was repainted/updated, |
| 273 // that region damages the surface. | 275 // that region damages the surface. |
| 274 // | 276 // |
| 275 // Property changes take priority over update rects. | 277 // Property changes take priority over update rects. |
| 276 // | 278 // |
| 277 // This method is called when we want to consider how a layer contributes to | 279 // This method is called when we want to consider how a layer contributes to |
| 278 // its target RenderSurface, even if that layer owns the target RenderSurface | 280 // its target RenderSurface, even if that layer owns the target RenderSurface |
| 279 // itself. To consider how a layer's target surface contributes to the | 281 // itself. To consider how a layer's target surface contributes to the |
| 280 // ancestor surface, ExtendDamageForRenderSurface() must be called instead. | 282 // ancestor surface, ExtendDamageForRenderSurface() must be called instead. |
| 281 | 283 |
| 282 bool layer_is_new = false; | 284 bool layer_is_new = false; |
| 283 RectMapData& data = RectDataForLayer(layer->id(), &layer_is_new); | 285 RectMapData& data = RectDataForLayer(layer->id(), &layer_is_new); |
| 284 gfx::Rect old_rect_in_target_space = data.rect_; | 286 gfx::Rect old_rect_in_target_space = data.rect_; |
| 285 | 287 |
| 286 gfx::Rect rect_in_target_space = layer->GetEnclosingRectInTargetSpace(); | 288 gfx::Rect rect_in_target_space = layer->GetEnclosingRectInTargetSpace(); |
| 287 data.Update(rect_in_target_space, mailboxId_); | 289 data.Update(rect_in_target_space, mailboxId_); |
| 288 | 290 |
| 289 gfx::RectF damage_rect = | 291 gfx::RectF damage_rect = |
| 290 gfx::UnionRects(layer->update_rect(), layer->damage_rect()); | 292 gfx::UnionRects(layer->update_rect(), layer->damage_rect()); |
| 291 | 293 |
| 294 target_overlay_rect->Union(layer->overlay_update_rect()); |
| 292 if (layer_is_new || layer->LayerPropertyChanged()) { | 295 if (layer_is_new || layer->LayerPropertyChanged()) { |
| 293 // If a layer is new or has changed, then its entire layer rect affects the | 296 // If a layer is new or has changed, then its entire layer rect affects the |
| 294 // target surface. | 297 // target surface. |
| 295 target_damage_rect->Union(rect_in_target_space); | 298 target_damage_rect->Union(rect_in_target_space); |
| 296 | 299 |
| 297 // The layer's old region is now exposed on the target surface, too. | 300 // The layer's old region is now exposed on the target surface, too. |
| 298 // Note old_rect_in_target_space is already in target space. | 301 // Note old_rect_in_target_space is already in target space. |
| 299 target_damage_rect->Union(old_rect_in_target_space); | 302 target_damage_rect->Union(old_rect_in_target_space); |
| 300 } else if (!damage_rect.IsEmpty()) { | 303 } else if (!damage_rect.IsEmpty()) { |
| 301 // If the layer properties haven't changed, then the the target surface is | 304 // If the layer properties haven't changed, then the the target surface is |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 // one in them. This means we need to redraw any pixels in the surface being | 398 // one in them. This means we need to redraw any pixels in the surface being |
| 396 // used for the blur in this layer this frame. | 399 // used for the blur in this layer this frame. |
| 397 if (layer->background_filters().HasFilterThatMovesPixels()) { | 400 if (layer->background_filters().HasFilterThatMovesPixels()) { |
| 398 ExpandDamageRectInsideRectWithFilters(target_damage_rect, | 401 ExpandDamageRectInsideRectWithFilters(target_damage_rect, |
| 399 surface_rect_in_target_space, | 402 surface_rect_in_target_space, |
| 400 layer->background_filters()); | 403 layer->background_filters()); |
| 401 } | 404 } |
| 402 } | 405 } |
| 403 | 406 |
| 404 } // namespace cc | 407 } // namespace cc |
| OLD | NEW |