| 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" | 
| 11 #include "cc/layers/layer_impl.h" | 11 #include "cc/layers/layer_impl.h" | 
| 12 #include "cc/layers/render_surface_impl.h" | 12 #include "cc/layers/render_surface_impl.h" | 
|  | 13 #include "cc/output/filter_operations.h" | 
| 13 #include "cc/trees/layer_tree_host_common.h" | 14 #include "cc/trees/layer_tree_host_common.h" | 
| 14 #include "cc/trees/layer_tree_impl.h" | 15 #include "cc/trees/layer_tree_impl.h" | 
| 15 #include "third_party/WebKit/public/platform/WebFilterOperations.h" |  | 
| 16 | 16 | 
| 17 namespace cc { | 17 namespace cc { | 
| 18 | 18 | 
| 19 scoped_ptr<DamageTracker> DamageTracker::Create() { | 19 scoped_ptr<DamageTracker> DamageTracker::Create() { | 
| 20   return make_scoped_ptr(new DamageTracker()); | 20   return make_scoped_ptr(new DamageTracker()); | 
| 21 } | 21 } | 
| 22 | 22 | 
| 23 DamageTracker::DamageTracker() | 23 DamageTracker::DamageTracker() | 
| 24     : current_rect_history_(new RectMap), | 24     : current_rect_history_(new RectMap), | 
| 25       next_rect_history_(new RectMap) {} | 25       next_rect_history_(new RectMap) {} | 
| 26 | 26 | 
| 27 DamageTracker::~DamageTracker() {} | 27 DamageTracker::~DamageTracker() {} | 
| 28 | 28 | 
| 29 static inline void ExpandRectWithFilters( | 29 static inline void ExpandRectWithFilters( | 
| 30     gfx::RectF* rect, const WebKit::WebFilterOperations& filters) { | 30     gfx::RectF* rect, const FilterOperations& filters) { | 
| 31   int top, right, bottom, left; | 31   int top, right, bottom, left; | 
| 32   filters.getOutsets(top, right, bottom, left); | 32   filters.GetOutsets(&top, &right, &bottom, &left); | 
| 33   rect->Inset(-left, -top, -right, -bottom); | 33   rect->Inset(-left, -top, -right, -bottom); | 
| 34 } | 34 } | 
| 35 | 35 | 
| 36 static inline void ExpandDamageRectInsideRectWithFilters( | 36 static inline void ExpandDamageRectInsideRectWithFilters( | 
| 37     gfx::RectF* damage_rect, | 37     gfx::RectF* damage_rect, | 
| 38     const gfx::RectF& pre_filter_rect, | 38     const gfx::RectF& pre_filter_rect, | 
| 39     const WebKit::WebFilterOperations& filters) { | 39     const FilterOperations& filters) { | 
| 40   gfx::RectF expanded_damage_rect = *damage_rect; | 40   gfx::RectF expanded_damage_rect = *damage_rect; | 
| 41   ExpandRectWithFilters(&expanded_damage_rect, filters); | 41   ExpandRectWithFilters(&expanded_damage_rect, filters); | 
| 42   gfx::RectF filter_rect = pre_filter_rect; | 42   gfx::RectF filter_rect = pre_filter_rect; | 
| 43   ExpandRectWithFilters(&filter_rect, filters); | 43   ExpandRectWithFilters(&filter_rect, filters); | 
| 44 | 44 | 
| 45   expanded_damage_rect.Intersect(filter_rect); | 45   expanded_damage_rect.Intersect(filter_rect); | 
| 46   damage_rect->Union(expanded_damage_rect); | 46   damage_rect->Union(expanded_damage_rect); | 
| 47 } | 47 } | 
| 48 | 48 | 
| 49 void DamageTracker::UpdateDamageTrackingState( | 49 void DamageTracker::UpdateDamageTrackingState( | 
| 50     const LayerImplList& layer_list, | 50     const LayerImplList& layer_list, | 
| 51     int target_surface_layer_id, | 51     int target_surface_layer_id, | 
| 52     bool target_surface_property_changed_only_from_descendant, | 52     bool target_surface_property_changed_only_from_descendant, | 
| 53     gfx::Rect target_surface_content_rect, | 53     gfx::Rect target_surface_content_rect, | 
| 54     LayerImpl* target_surface_mask_layer, | 54     LayerImpl* target_surface_mask_layer, | 
| 55     const WebKit::WebFilterOperations& filters, | 55     const FilterOperations& filters, | 
| 56     SkImageFilter* filter) { | 56     SkImageFilter* filter) { | 
| 57   // | 57   // | 
| 58   // This function computes the "damage rect" of a target surface, and updates | 58   // This function computes the "damage rect" of a target surface, and updates | 
| 59   // the state that is used to correctly track damage across frames. The damage | 59   // the state that is used to correctly track damage across frames. The damage | 
| 60   // rect is the region of the surface that may have changed and needs to be | 60   // rect is the region of the surface that may have changed and needs to be | 
| 61   // redrawn. This can be used to scissor what is actually drawn, to save GPU | 61   // redrawn. This can be used to scissor what is actually drawn, to save GPU | 
| 62   // computation and bandwidth. | 62   // computation and bandwidth. | 
| 63   // | 63   // | 
| 64   // The surface's damage rect is computed as the union of all possible changes | 64   // The surface's damage rect is computed as the union of all possible changes | 
| 65   // that have happened to the surface since the last frame was drawn. This | 65   // that have happened to the surface since the last frame was drawn. This | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 136 | 136 | 
| 137   if (target_surface_property_changed_only_from_descendant) { | 137   if (target_surface_property_changed_only_from_descendant) { | 
| 138     damage_rect_for_this_update = target_surface_content_rect; | 138     damage_rect_for_this_update = target_surface_content_rect; | 
| 139   } else { | 139   } else { | 
| 140     // TODO(shawnsingh): can we clamp this damage to the surface's content rect? | 140     // TODO(shawnsingh): can we clamp this damage to the surface's content rect? | 
| 141     // (affects performance, but not correctness) | 141     // (affects performance, but not correctness) | 
| 142     damage_rect_for_this_update = damage_from_active_layers; | 142     damage_rect_for_this_update = damage_from_active_layers; | 
| 143     damage_rect_for_this_update.Union(damage_from_surface_mask); | 143     damage_rect_for_this_update.Union(damage_from_surface_mask); | 
| 144     damage_rect_for_this_update.Union(damage_from_leftover_rects); | 144     damage_rect_for_this_update.Union(damage_from_leftover_rects); | 
| 145 | 145 | 
| 146     if (filters.hasFilterThatMovesPixels()) { | 146     if (filters.HasFilterThatMovesPixels()) { | 
| 147       ExpandRectWithFilters(&damage_rect_for_this_update, filters); | 147       ExpandRectWithFilters(&damage_rect_for_this_update, filters); | 
| 148     } else if (filter) { | 148     } else if (filter) { | 
| 149       // TODO(senorblanco):  Once SkImageFilter reports its outsets, use | 149       // TODO(senorblanco):  Once SkImageFilter reports its outsets, use | 
| 150       // those here to limit damage. | 150       // those here to limit damage. | 
| 151       damage_rect_for_this_update = target_surface_content_rect; | 151       damage_rect_for_this_update = target_surface_content_rect; | 
| 152     } | 152     } | 
| 153   } | 153   } | 
| 154 | 154 | 
| 155   // Damage accumulates until we are notified that we actually did draw on that | 155   // Damage accumulates until we are notified that we actually did draw on that | 
| 156   // frame. | 156   // frame. | 
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 383         !replica_mask_layer->update_rect().IsEmpty()) | 383         !replica_mask_layer->update_rect().IsEmpty()) | 
| 384       target_damage_rect->Union(replica_mask_layer_rect); | 384       target_damage_rect->Union(replica_mask_layer_rect); | 
| 385   } | 385   } | 
| 386 | 386 | 
| 387   // If the layer has a background filter, this may cause pixels in our surface | 387   // If the layer has a background filter, this may cause pixels in our surface | 
| 388   // to be expanded, so we will need to expand any damage at or below this | 388   // to be expanded, so we will need to expand any damage at or below this | 
| 389   // layer. We expand the damage from this layer too, as we need to readback | 389   // layer. We expand the damage from this layer too, as we need to readback | 
| 390   // those pixels from the surface with only the contents of layers below this | 390   // those pixels from the surface with only the contents of layers below this | 
| 391   // one in them. This means we need to redraw any pixels in the surface being | 391   // one in them. This means we need to redraw any pixels in the surface being | 
| 392   // used for the blur in this layer this frame. | 392   // used for the blur in this layer this frame. | 
| 393   if (layer->background_filters().hasFilterThatMovesPixels()) { | 393   if (layer->background_filters().HasFilterThatMovesPixels()) { | 
| 394     ExpandDamageRectInsideRectWithFilters(target_damage_rect, | 394     ExpandDamageRectInsideRectWithFilters(target_damage_rect, | 
| 395                                           surface_rect_in_target_space, | 395                                           surface_rect_in_target_space, | 
| 396                                           layer->background_filters()); | 396                                           layer->background_filters()); | 
| 397   } | 397   } | 
| 398 } | 398 } | 
| 399 | 399 | 
| 400 }  // namespace cc | 400 }  // namespace cc | 
| OLD | NEW | 
|---|