diff options
author | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-08 02:41:47 +0000 |
---|---|---|
committer | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-08 02:41:47 +0000 |
commit | be3925eecc44210e61b47de19858d45c28b3e361 (patch) | |
tree | d3737b8931ffa18e56a03bd2797ac32e032f4dee /cc/damage_tracker.cc | |
parent | 34bb3ace821d6a370d023fa7b6b8cd6114e85746 (diff) | |
download | chromium_src-be3925eecc44210e61b47de19858d45c28b3e361.zip chromium_src-be3925eecc44210e61b47de19858d45c28b3e361.tar.gz chromium_src-be3925eecc44210e61b47de19858d45c28b3e361.tar.bz2 |
cc: Chromify DamageTracker class.
Style-only change. Make the DamageTracker class use chromium style.
R=jamesr,enne
Review URL: https://chromiumcodereview.appspot.com/12631007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186864 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/damage_tracker.cc')
-rw-r--r-- | cc/damage_tracker.cc | 620 |
1 files changed, 336 insertions, 284 deletions
diff --git a/cc/damage_tracker.cc b/cc/damage_tracker.cc index ad433e9..1693af8 100644 --- a/cc/damage_tracker.cc +++ b/cc/damage_tracker.cc @@ -12,330 +12,382 @@ namespace cc { -scoped_ptr<DamageTracker> DamageTracker::create() -{ - return make_scoped_ptr(new DamageTracker()); +scoped_ptr<DamageTracker> DamageTracker::Create() { + return make_scoped_ptr(new DamageTracker()); } DamageTracker::DamageTracker() - : m_forceFullDamageNextUpdate(false), - m_currentRectHistory(new RectMap), - m_nextRectHistory(new RectMap) -{ -} + : force_full_damage_next_update_(false), + current_rect_history_(new RectMap), + next_rect_history_(new RectMap) {} -DamageTracker::~DamageTracker() -{ -} +DamageTracker::~DamageTracker() {} -static inline void expandRectWithFilters(gfx::RectF& rect, const WebKit::WebFilterOperations& filters) -{ - int top, right, bottom, left; - filters.getOutsets(top, right, bottom, left); - rect.Inset(-left, -top, -right, -bottom); +static inline void ExpandRectWithFilters( + gfx::RectF* rect, const WebKit::WebFilterOperations& filters) { + int top, right, bottom, left; + filters.getOutsets(top, right, bottom, left); + rect->Inset(-left, -top, -right, -bottom); } -static inline void expandDamageRectInsideRectWithFilters(gfx::RectF& damageRect, const gfx::RectF& preFilterRect, const WebKit::WebFilterOperations& filters) -{ - gfx::RectF expandedDamageRect = damageRect; - expandRectWithFilters(expandedDamageRect, filters); - gfx::RectF filterRect = preFilterRect; - expandRectWithFilters(filterRect, filters); - - expandedDamageRect.Intersect(filterRect); - damageRect.Union(expandedDamageRect); +static inline void ExpandDamageRectInsideRectWithFilters( + gfx::RectF* damage_rect, + const gfx::RectF& pre_filter_rect, + const WebKit::WebFilterOperations& filters) { + gfx::RectF expanded_damage_rect = *damage_rect; + ExpandRectWithFilters(&expanded_damage_rect, filters); + gfx::RectF filter_rect = pre_filter_rect; + ExpandRectWithFilters(&filter_rect, filters); + + expanded_damage_rect.Intersect(filter_rect); + damage_rect->Union(expanded_damage_rect); } -void DamageTracker::updateDamageTrackingState(const std::vector<LayerImpl*>& layerList, int targetSurfaceLayerID, bool targetSurfacePropertyChangedOnlyFromDescendant, const gfx::Rect& targetSurfaceContentRect, LayerImpl* targetSurfaceMaskLayer, const WebKit::WebFilterOperations& filters, SkImageFilter* filter) -{ - // - // This function computes the "damage rect" of a target surface, and updates the state - // that is used to correctly track damage across frames. The damage rect is the region - // of the surface that may have changed and needs to be redrawn. This can be used to - // scissor what is actually drawn, to save GPU computation and bandwidth. - // - // The surface's damage rect is computed as the union of all possible changes that - // have happened to the surface since the last frame was drawn. This includes: - // - any changes for existing layers/surfaces that contribute to the target surface - // - layers/surfaces that existed in the previous frame, but no longer exist. - // - // The basic algorithm for computing the damage region is as follows: - // - // 1. compute damage caused by changes in active/new layers - // for each layer in the layerList: - // if the layer is actually a renderSurface: - // add the surface's damage to our target surface. - // else - // add the layer's damage to the target surface. - // - // 2. compute damage caused by the target surface's mask, if it exists. - // - // 3. compute damage caused by old layers/surfaces that no longer exist - // for each leftover layer: - // add the old layer/surface bounds to the target surface damage. - // - // 4. combine all partial damage rects to get the full damage rect. - // - // Additional important points: - // - // - This algorithm is implicitly recursive; it assumes that descendant surfaces have - // already computed their damage. - // - // - Changes to layers/surfaces indicate "damage" to the target surface; If a layer is - // not changed, it does NOT mean that the layer can skip drawing. All layers that - // overlap the damaged region still need to be drawn. For example, if a layer - // changed its opacity, then layers underneath must be re-drawn as well, even if - // they did not change. - // - // - If a layer/surface property changed, the old bounds and new bounds may overlap... - // i.e. some of the exposed region may not actually be exposing anything. But this - // does not artificially inflate the damage rect. If the layer changed, its entire - // old bounds would always need to be redrawn, regardless of how much it overlaps - // with the layer's new bounds, which also need to be entirely redrawn. - // - // - See comments in the rest of the code to see what exactly is considered a "change" - // in a layer/surface. - // - // - To correctly manage exposed rects, two RectMaps are maintained: - // - // 1. The "current" map contains all the layer bounds that contributed to the - // previous frame (even outside the previous damaged area). If a layer changes - // or does not exist anymore, those regions are then exposed and damage the - // target surface. As the algorithm progresses, entries are removed from the - // map until it has only leftover layers that no longer exist. - // - // 2. The "next" map starts out empty, and as the algorithm progresses, every - // layer/surface that contributes to the surface is added to the map. - // - // 3. After the damage rect is computed, the two maps are swapped, so that the - // damage tracker is ready for the next frame. - // - - // These functions cannot be bypassed with early-exits, even if we know what the - // damage will be for this frame, because we need to update the damage tracker state - // to correctly track the next frame. - gfx::RectF damageFromActiveLayers = trackDamageFromActiveLayers(layerList, targetSurfaceLayerID); - gfx::RectF damageFromSurfaceMask = trackDamageFromSurfaceMask(targetSurfaceMaskLayer); - gfx::RectF damageFromLeftoverRects = trackDamageFromLeftoverRects(); - - gfx::RectF damageRectForThisUpdate; - - if (m_forceFullDamageNextUpdate || targetSurfacePropertyChangedOnlyFromDescendant) { - damageRectForThisUpdate = targetSurfaceContentRect; - m_forceFullDamageNextUpdate = false; - } else { - // FIXME: can we clamp this damage to the surface's content rect? (affects performance, but not correctness) - damageRectForThisUpdate = damageFromActiveLayers; - damageRectForThisUpdate.Union(damageFromSurfaceMask); - damageRectForThisUpdate.Union(damageFromLeftoverRects); - - if (filters.hasFilterThatMovesPixels()) { - expandRectWithFilters(damageRectForThisUpdate, filters); - } else if (filter) { - // TODO(senorblanco): Once SkImageFilter reports its outsets, use - // those here to limit damage. - damageRectForThisUpdate = targetSurfaceContentRect; - } +void DamageTracker::UpdateDamageTrackingState( + const std::vector<LayerImpl*>& layer_list, + int target_surface_layer_id, + bool target_surface_property_changed_only_from_descendant, + gfx::Rect target_surface_content_rect, + LayerImpl* target_surface_mask_layer, + const WebKit::WebFilterOperations& filters, + SkImageFilter* filter) { + // + // This function computes the "damage rect" of a target surface, and updates + // the state that is used to correctly track damage across frames. The damage + // rect is the region of the surface that may have changed and needs to be + // redrawn. This can be used to scissor what is actually drawn, to save GPU + // computation and bandwidth. + // + // The surface's damage rect is computed as the union of all possible changes + // that have happened to the surface since the last frame was drawn. This + // includes: + // - any changes for existing layers/surfaces that contribute to the target + // surface + // - layers/surfaces that existed in the previous frame, but no longer exist + // + // The basic algorithm for computing the damage region is as follows: + // + // 1. compute damage caused by changes in active/new layers + // for each layer in the layer_list: + // if the layer is actually a render_surface: + // add the surface's damage to our target surface. + // else + // add the layer's damage to the target surface. + // + // 2. compute damage caused by the target surface's mask, if it exists. + // + // 3. compute damage caused by old layers/surfaces that no longer exist + // for each leftover layer: + // add the old layer/surface bounds to the target surface damage. + // + // 4. combine all partial damage rects to get the full damage rect. + // + // Additional important points: + // + // - This algorithm is implicitly recursive; it assumes that descendant + // surfaces have already computed their damage. + // + // - Changes to layers/surfaces indicate "damage" to the target surface; If a + // layer is not changed, it does NOT mean that the layer can skip drawing. + // All layers that overlap the damaged region still need to be drawn. For + // example, if a layer changed its opacity, then layers underneath must be + // re-drawn as well, even if they did not change. + // + // - If a layer/surface property changed, the old bounds and new bounds may + // overlap... i.e. some of the exposed region may not actually be exposing + // anything. But this does not artificially inflate the damage rect. If the + // layer changed, its entire old bounds would always need to be redrawn, + // regardless of how much it overlaps with the layer's new bounds, which + // also need to be entirely redrawn. + // + // - See comments in the rest of the code to see what exactly is considered a + // "change" in a layer/surface. + // + // - To correctly manage exposed rects, two RectMaps are maintained: + // + // 1. The "current" map contains all the layer bounds that contributed to + // the previous frame (even outside the previous damaged area). If a + // layer changes or does not exist anymore, those regions are then + // exposed and damage the target surface. As the algorithm progresses, + // entries are removed from the map until it has only leftover layers + // that no longer exist. + // + // 2. The "next" map starts out empty, and as the algorithm progresses, + // every layer/surface that contributes to the surface is added to the + // map. + // + // 3. After the damage rect is computed, the two maps are swapped, so + // that the damage tracker is ready for the next frame. + // + + // These functions cannot be bypassed with early-exits, even if we know what + // the damage will be for this frame, because we need to update the damage + // tracker state to correctly track the next frame. + gfx::RectF damage_from_active_layers = + TrackDamageFromActiveLayers(layer_list, target_surface_layer_id); + gfx::RectF damage_from_surface_mask = + TrackDamageFromSurfaceMask(target_surface_mask_layer); + gfx::RectF damage_from_leftover_rects = TrackDamageFromLeftoverRects(); + + gfx::RectF damage_rect_for_this_update; + + if (force_full_damage_next_update_ || + target_surface_property_changed_only_from_descendant) { + damage_rect_for_this_update = target_surface_content_rect; + force_full_damage_next_update_ = false; + } else { + // TODO(shawnsingh): can we clamp this damage to the surface's content rect? + // (affects performance, but not correctness) + damage_rect_for_this_update = damage_from_active_layers; + damage_rect_for_this_update.Union(damage_from_surface_mask); + damage_rect_for_this_update.Union(damage_from_leftover_rects); + + if (filters.hasFilterThatMovesPixels()) { + ExpandRectWithFilters(&damage_rect_for_this_update, filters); + } else if (filter) { + // TODO(senorblanco): Once SkImageFilter reports its outsets, use + // those here to limit damage. + damage_rect_for_this_update = target_surface_content_rect; } + } - // Damage accumulates until we are notified that we actually did draw on that frame. - m_currentDamageRect.Union(damageRectForThisUpdate); + // Damage accumulates until we are notified that we actually did draw on that + // frame. + current_damage_rect_.Union(damage_rect_for_this_update); - // The next history map becomes the current map for the next frame. Note this must - // happen every frame to correctly track changes, even if damage accumulates over - // multiple frames before actually being drawn. - swap(m_currentRectHistory, m_nextRectHistory); + // The next history map becomes the current map for the next frame. Note this + // must happen every frame to correctly track changes, even if damage + // accumulates over multiple frames before actually being drawn. + swap(current_rect_history_, next_rect_history_); } -gfx::RectF DamageTracker::removeRectFromCurrentFrame(int layerID, bool& layerIsNew) -{ - RectMap::iterator iter = m_currentRectHistory->find(layerID); - layerIsNew = iter == m_currentRectHistory->end(); - if (layerIsNew) - return gfx::RectF(); +gfx::RectF DamageTracker::RemoveRectFromCurrentFrame(int layer_id, + bool* layer_is_new) { + RectMap::iterator iter = current_rect_history_->find(layer_id); + *layer_is_new = iter == current_rect_history_->end(); + if (*layer_is_new) + return gfx::RectF(); - gfx::RectF ret = iter->second; - m_currentRectHistory->erase(iter); - return ret; + gfx::RectF ret = iter->second; + current_rect_history_->erase(iter); + return ret; } -void DamageTracker::saveRectForNextFrame(int layerID, const gfx::RectF& targetSpaceRect) -{ - // This layer should not yet exist in next frame's history. - DCHECK(layerID > 0); - DCHECK(m_nextRectHistory->find(layerID) == m_nextRectHistory->end()); - (*m_nextRectHistory)[layerID] = targetSpaceRect; +void DamageTracker::SaveRectForNextFrame(int layer_id, + const gfx::RectF& target_space_rect) { + // This layer should not yet exist in next frame's history. + DCHECK_GT(layer_id, 0); + DCHECK(next_rect_history_->find(layer_id) == next_rect_history_->end()); + (*next_rect_history_)[layer_id] = target_space_rect; } -gfx::RectF DamageTracker::trackDamageFromActiveLayers(const std::vector<LayerImpl*>& layerList, int targetSurfaceLayerID) -{ - gfx::RectF damageRect = gfx::RectF(); +gfx::RectF DamageTracker::TrackDamageFromActiveLayers( + const std::vector<LayerImpl*>& layer_list, + int target_surface_layer_id) { + gfx::RectF damage_rect = gfx::RectF(); - for (unsigned layerIndex = 0; layerIndex < layerList.size(); ++layerIndex) { - // Visit layers in back-to-front order. - LayerImpl* layer = layerList[layerIndex]; + for (unsigned layerIndex = 0; layerIndex < layer_list.size(); ++layerIndex) { + // Visit layers in back-to-front order. + LayerImpl* layer = layer_list[layerIndex]; - if (LayerTreeHostCommon::renderSurfaceContributesToTarget<LayerImpl>(layer, targetSurfaceLayerID)) - extendDamageForRenderSurface(layer, damageRect); - else - extendDamageForLayer(layer, damageRect); - } + if (LayerTreeHostCommon::renderSurfaceContributesToTarget<LayerImpl>( + layer, target_surface_layer_id)) + ExtendDamageForRenderSurface(layer, &damage_rect); + else + ExtendDamageForLayer(layer, &damage_rect); + } - return damageRect; + return damage_rect; } -gfx::RectF DamageTracker::trackDamageFromSurfaceMask(LayerImpl* targetSurfaceMaskLayer) -{ - gfx::RectF damageRect = gfx::RectF(); +gfx::RectF DamageTracker::TrackDamageFromSurfaceMask( + LayerImpl* target_surface_mask_layer) { + gfx::RectF damage_rect = gfx::RectF(); - if (!targetSurfaceMaskLayer) - return damageRect; + if (!target_surface_mask_layer) + return damage_rect; - // Currently, if there is any change to the mask, we choose to damage the entire - // surface. This could potentially be optimized later, but it is not expected to be a - // common case. - if (targetSurfaceMaskLayer->layerPropertyChanged() || !targetSurfaceMaskLayer->updateRect().IsEmpty()) - damageRect = gfx::RectF(gfx::PointF(), targetSurfaceMaskLayer->bounds()); + // Currently, if there is any change to the mask, we choose to damage the + // entire surface. This could potentially be optimized later, but it is not + // expected to be a common case. + if (target_surface_mask_layer->layerPropertyChanged() || + !target_surface_mask_layer->updateRect().IsEmpty()) { + damage_rect = gfx::RectF(gfx::PointF(), + target_surface_mask_layer->bounds()); + } - return damageRect; + return damage_rect; } -gfx::RectF DamageTracker::trackDamageFromLeftoverRects() -{ - // After computing damage for all active layers, any leftover items in the current - // rect history correspond to layers/surfaces that no longer exist. So, these regions - // are now exposed on the target surface. +gfx::RectF DamageTracker::TrackDamageFromLeftoverRects() { + // After computing damage for all active layers, any leftover items in the + // current rect history correspond to layers/surfaces that no longer exist. + // So, these regions are now exposed on the target surface. - gfx::RectF damageRect = gfx::RectF(); + gfx::RectF damage_rect = gfx::RectF(); - for (RectMap::iterator it = m_currentRectHistory->begin(); it != m_currentRectHistory->end(); ++it) - damageRect.Union(it->second); + for (RectMap::iterator it = current_rect_history_->begin(); + it != current_rect_history_->end(); + ++it) + damage_rect.Union(it->second); - m_currentRectHistory->clear(); + current_rect_history_->clear(); - return damageRect; + return damage_rect; } -static bool layerNeedsToRedrawOntoItsTargetSurface(LayerImpl* layer) -{ - // If the layer does NOT own a surface but has SurfacePropertyChanged, - // this means that its target surface is affected and needs to be redrawn. - // However, if the layer DOES own a surface, then the SurfacePropertyChanged - // flag should not be used here, because that flag represents whether the - // layer's surface has changed. - if (layer->renderSurface()) - return layer->layerPropertyChanged(); - return layer->layerPropertyChanged() || layer->layerSurfacePropertyChanged(); +static bool LayerNeedsToRedrawOntoItsTargetSurface(LayerImpl* layer) { + // If the layer does NOT own a surface but has SurfacePropertyChanged, + // this means that its target surface is affected and needs to be redrawn. + // However, if the layer DOES own a surface, then the SurfacePropertyChanged + // flag should not be used here, because that flag represents whether the + // layer's surface has changed. + if (layer->renderSurface()) + return layer->layerPropertyChanged(); + return layer->layerPropertyChanged() || layer->layerSurfacePropertyChanged(); } -void DamageTracker::extendDamageForLayer(LayerImpl* layer, gfx::RectF& targetDamageRect) -{ - // There are two ways that a layer can damage a region of the target surface: - // 1. Property change (e.g. opacity, position, transforms): - // - the entire region of the layer itself damages the surface. - // - the old layer region also damages the surface, because this region is now exposed. - // - note that in many cases the old and new layer rects may overlap, which is fine. - // - // 2. Repaint/update: If a region of the layer that was repainted/updated, that - // region damages the surface. - // - // Property changes take priority over update rects. - // - // This method is called when we want to consider how a layer contributes to its - // targetRenderSurface, even if that layer owns the targetRenderSurface itself. - // To consider how a layer's targetSurface contributes to the ancestorSurface, - // extendDamageForRenderSurface() must be called instead. - - bool layerIsNew = false; - gfx::RectF oldRectInTargetSpace = removeRectFromCurrentFrame(layer->id(), layerIsNew); - - gfx::RectF rectInTargetSpace = MathUtil::mapClippedRect(layer->drawTransform(), gfx::RectF(gfx::PointF(), layer->contentBounds())); - saveRectForNextFrame(layer->id(), rectInTargetSpace); - - if (layerIsNew || layerNeedsToRedrawOntoItsTargetSurface(layer)) { - // If a layer is new or has changed, then its entire layer rect affects the target surface. - targetDamageRect.Union(rectInTargetSpace); - - // The layer's old region is now exposed on the target surface, too. - // Note oldRectInTargetSpace is already in target space. - targetDamageRect.Union(oldRectInTargetSpace); - } else if (!layer->updateRect().IsEmpty()) { - // If the layer properties haven't changed, then the the target surface is only - // affected by the layer's update area, which could be empty. - gfx::RectF updateContentRect = layer->layerRectToContentRect(layer->updateRect()); - gfx::RectF updateRectInTargetSpace = MathUtil::mapClippedRect(layer->drawTransform(), updateContentRect); - targetDamageRect.Union(updateRectInTargetSpace); - } +void DamageTracker::ExtendDamageForLayer(LayerImpl* layer, + gfx::RectF* target_damage_rect) { + // There are two ways that a layer can damage a region of the target surface: + // 1. Property change (e.g. opacity, position, transforms): + // - the entire region of the layer itself damages the surface. + // - the old layer region also damages the surface, because this region + // is now exposed. + // - note that in many cases the old and new layer rects may overlap, + // which is fine. + // + // 2. Repaint/update: If a region of the layer that was repainted/updated, + // that region damages the surface. + // + // Property changes take priority over update rects. + // + // This method is called when we want to consider how a layer contributes to + // its targetRenderSurface, even if that layer owns the targetRenderSurface + // itself. To consider how a layer's targetSurface contributes to the + // ancestorSurface, ExtendDamageForRenderSurface() must be called instead. + + bool layer_is_new = false; + gfx::RectF old_rect_in_target_space = + RemoveRectFromCurrentFrame(layer->id(), &layer_is_new); + + gfx::RectF rect_in_target_space = MathUtil::mapClippedRect( + layer->drawTransform(), + gfx::RectF(gfx::PointF(), layer->contentBounds())); + SaveRectForNextFrame(layer->id(), rect_in_target_space); + + if (layer_is_new || LayerNeedsToRedrawOntoItsTargetSurface(layer)) { + // If a layer is new or has changed, then its entire layer rect affects the + // target surface. + target_damage_rect->Union(rect_in_target_space); + + // The layer's old region is now exposed on the target surface, too. + // Note old_rect_in_target_space is already in target space. + target_damage_rect->Union(old_rect_in_target_space); + } else if (!layer->updateRect().IsEmpty()) { + // If the layer properties haven't changed, then the the target surface is + // only affected by the layer's update area, which could be empty. + gfx::RectF update_content_rect = + layer->layerRectToContentRect(layer->updateRect()); + gfx::RectF update_rect_in_target_space = + MathUtil::mapClippedRect(layer->drawTransform(), update_content_rect); + target_damage_rect->Union(update_rect_in_target_space); + } } -void DamageTracker::extendDamageForRenderSurface(LayerImpl* layer, gfx::RectF& targetDamageRect) -{ - // There are two ways a "descendant surface" can damage regions of the "target surface": - // 1. Property change: - // - a surface's geometry can change because of - // - changes to descendants (i.e. the subtree) that affect the surface's content rect - // - changes to ancestor layers that propagate their property changes to their entire subtree. - // - just like layers, both the old surface rect and new surface rect will - // damage the target surface in this case. - // - // 2. Damage rect: This surface may have been damaged by its own layerList as well, and that damage - // should propagate to the target surface. - // - - RenderSurfaceImpl* renderSurface = layer->renderSurface(); - - bool surfaceIsNew = false; - gfx::RectF oldSurfaceRect = removeRectFromCurrentFrame(layer->id(), surfaceIsNew); - - gfx::RectF surfaceRectInTargetSpace = renderSurface->drawableContentRect(); // already includes replica if it exists. - saveRectForNextFrame(layer->id(), surfaceRectInTargetSpace); - - gfx::RectF damageRectInLocalSpace; - if (surfaceIsNew || renderSurface->surfacePropertyChanged() || layer->layerSurfacePropertyChanged()) { - // The entire surface contributes damage. - damageRectInLocalSpace = renderSurface->contentRect(); - - // The surface's old region is now exposed on the target surface, too. - targetDamageRect.Union(oldSurfaceRect); - } else { - // Only the surface's damageRect will damage the target surface. - damageRectInLocalSpace = renderSurface->damageTracker()->currentDamageRect(); - } - - // If there was damage, transform it to target space, and possibly contribute its reflection if needed. - if (!damageRectInLocalSpace.IsEmpty()) { - const gfx::Transform& drawTransform = renderSurface->drawTransform(); - gfx::RectF damageRectInTargetSpace = MathUtil::mapClippedRect(drawTransform, damageRectInLocalSpace); - targetDamageRect.Union(damageRectInTargetSpace); - - if (layer->replicaLayer()) { - const gfx::Transform& replicaDrawTransform = renderSurface->replicaDrawTransform(); - targetDamageRect.Union(MathUtil::mapClippedRect(replicaDrawTransform, damageRectInLocalSpace)); - } +void DamageTracker::ExtendDamageForRenderSurface( + LayerImpl* layer, gfx::RectF* target_damage_rect) { + // There are two ways a "descendant surface" can damage regions of the "target + // surface": + // 1. Property change: + // - a surface's geometry can change because of + // - changes to descendants (i.e. the subtree) that affect the + // surface's content rect + // - changes to ancestor layers that propagate their property + // changes to their entire subtree. + // - just like layers, both the old surface rect and new surface rect + // will damage the target surface in this case. + // + // 2. Damage rect: This surface may have been damaged by its own layer_list + // as well, and that damage should propagate to the target surface. + // + + RenderSurfaceImpl* render_surface = layer->renderSurface(); + + bool surface_is_new = false; + gfx::RectF old_surface_rect = RemoveRectFromCurrentFrame(layer->id(), + &surface_is_new); + + // The drawableContextRect() already includes the replica if it exists. + gfx::RectF surface_rect_in_target_space = + render_surface->drawableContentRect(); + SaveRectForNextFrame(layer->id(), surface_rect_in_target_space); + + gfx::RectF damage_rect_in_local_space; + if (surface_is_new || + render_surface->surfacePropertyChanged() || + layer->layerSurfacePropertyChanged()) { + // The entire surface contributes damage. + damage_rect_in_local_space = render_surface->contentRect(); + + // The surface's old region is now exposed on the target surface, too. + target_damage_rect->Union(old_surface_rect); + } else { + // Only the surface's damage_rect will damage the target surface. + damage_rect_in_local_space = + render_surface->damageTracker()->current_damage_rect(); + } + + // If there was damage, transform it to target space, and possibly contribute + // its reflection if needed. + if (!damage_rect_in_local_space.IsEmpty()) { + const gfx::Transform& draw_transform = render_surface->drawTransform(); + gfx::RectF damage_rect_in_target_space = + MathUtil::mapClippedRect(draw_transform, damage_rect_in_local_space); + target_damage_rect->Union(damage_rect_in_target_space); + + if (layer->replicaLayer()) { + const gfx::Transform& replica_draw_transform = + render_surface->replicaDrawTransform(); + target_damage_rect->Union(MathUtil::mapClippedRect( + replica_draw_transform, damage_rect_in_local_space)); } - - // If there was damage on the replica's mask, then the target surface receives that damage as well. - if (layer->replicaLayer() && layer->replicaLayer()->maskLayer()) { - LayerImpl* replicaMaskLayer = layer->replicaLayer()->maskLayer(); - - bool replicaIsNew = false; - removeRectFromCurrentFrame(replicaMaskLayer->id(), replicaIsNew); - - const gfx::Transform& replicaDrawTransform = renderSurface->replicaDrawTransform(); - gfx::RectF replicaMaskLayerRect = MathUtil::mapClippedRect(replicaDrawTransform, gfx::RectF(gfx::PointF(), replicaMaskLayer->bounds())); - saveRectForNextFrame(replicaMaskLayer->id(), replicaMaskLayerRect); - - // In the current implementation, a change in the replica mask damages the entire replica region. - if (replicaIsNew || replicaMaskLayer->layerPropertyChanged() || !replicaMaskLayer->updateRect().IsEmpty()) - targetDamageRect.Union(replicaMaskLayerRect); - } - - // If the layer has a background filter, this may cause pixels in our surface to be expanded, so we will need to expand any damage - // at or below this layer. We expand the damage from this layer too, as we need to readback those pixels from the surface with only - // the contents of layers below this one in them. This means we need to redraw any pixels in the surface being used for the blur in - // this layer this frame. - if (layer->backgroundFilters().hasFilterThatMovesPixels()) - expandDamageRectInsideRectWithFilters(targetDamageRect, surfaceRectInTargetSpace, layer->backgroundFilters()); + } + + // If there was damage on the replica's mask, then the target surface receives + // that damage as well. + if (layer->replicaLayer() && layer->replicaLayer()->maskLayer()) { + LayerImpl* replica_mask_layer = layer->replicaLayer()->maskLayer(); + + bool replica_is_new = false; + RemoveRectFromCurrentFrame(replica_mask_layer->id(), &replica_is_new); + + const gfx::Transform& replica_draw_transform = + render_surface->replicaDrawTransform(); + gfx::RectF replica_mask_layer_rect = MathUtil::mapClippedRect( + replica_draw_transform, + gfx::RectF(gfx::PointF(), replica_mask_layer->bounds())); + SaveRectForNextFrame(replica_mask_layer->id(), replica_mask_layer_rect); + + // In the current implementation, a change in the replica mask damages the + // entire replica region. + if (replica_is_new || + replica_mask_layer->layerPropertyChanged() || + !replica_mask_layer->updateRect().IsEmpty()) + target_damage_rect->Union(replica_mask_layer_rect); + } + + // If the layer has a background filter, this may cause pixels in our surface + // to be expanded, so we will need to expand any damage at or below this + // layer. We expand the damage from this layer too, as we need to readback + // those pixels from the surface with only the contents of layers below this + // one in them. This means we need to redraw any pixels in the surface being + // used for the blur in this layer this frame. + if (layer->backgroundFilters().hasFilterThatMovesPixels()) { + ExpandDamageRectInsideRectWithFilters(target_damage_rect, + surface_rect_in_target_space, + layer->backgroundFilters()); + } } } // namespace cc |