| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/occlusion_tracker.h" | 7 #include "cc/occlusion_tracker.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "FloatRect.h" | |
| 12 #include "cc/layer.h" | 11 #include "cc/layer.h" |
| 13 #include "cc/layer_impl.h" | 12 #include "cc/layer_impl.h" |
| 14 #include "cc/math_util.h" | 13 #include "cc/math_util.h" |
| 15 #include "cc/overdraw_metrics.h" | 14 #include "cc/overdraw_metrics.h" |
| 16 #include "ui/gfx/quad_f.h" | 15 #include "ui/gfx/quad_f.h" |
| 17 #include "ui/gfx/rect_conversions.h" | 16 #include "ui/gfx/rect_conversions.h" |
| 18 | 17 |
| 19 using namespace std; | 18 using namespace std; |
| 20 using WebKit::WebTransformationMatrix; | 19 using WebKit::WebTransformationMatrix; |
| 21 | 20 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 // apply |transform| to each rect within |region| in order to transform the
entire Region. | 123 // apply |transform| to each rect within |region| in order to transform the
entire Region. |
| 125 | 124 |
| 126 bool clipped; | 125 bool clipped; |
| 127 gfx::QuadF transformedBoundsQuad = MathUtil::mapQuad(transform, gfx::QuadF(r
egion.bounds()), clipped); | 126 gfx::QuadF transformedBoundsQuad = MathUtil::mapQuad(transform, gfx::QuadF(r
egion.bounds()), clipped); |
| 128 // FIXME: Find a rect interior to each transformed quad. | 127 // FIXME: Find a rect interior to each transformed quad. |
| 129 if (clipped || !transformedBoundsQuad.IsRectilinear()) | 128 if (clipped || !transformedBoundsQuad.IsRectilinear()) |
| 130 return Region(); | 129 return Region(); |
| 131 | 130 |
| 132 Region transformedRegion; | 131 Region transformedRegion; |
| 133 | 132 |
| 134 Vector<WebCore::IntRect> rects = region.rects(); | 133 for (Region::Iterator rects(region); rects.has_rect(); rects.next()) { |
| 135 for (size_t i = 0; i < rects.size(); ++i) { | |
| 136 // We've already checked for clipping in the mapQuad call above, these c
alls should not clip anything further. | 134 // We've already checked for clipping in the mapQuad call above, these c
alls should not clip anything further. |
| 137 gfx::Rect transformedRect = gfx::ToEnclosedRect(MathUtil::mapClippedRect
(transform, cc::FloatRect(rects[i]))); | 135 gfx::Rect transformedRect = gfx::ToEnclosedRect(MathUtil::mapClippedRect
(transform, gfx::RectF(rects.rect()))); |
| 138 if (!surface->clipRect().IsEmpty()) | 136 if (!surface->clipRect().IsEmpty()) |
| 139 transformedRect.Intersect(surface->clipRect()); | 137 transformedRect.Intersect(surface->clipRect()); |
| 140 transformedRegion.Union(transformedRect); | 138 transformedRegion.Union(transformedRect); |
| 141 } | 139 } |
| 142 return transformedRegion; | 140 return transformedRegion; |
| 143 } | 141 } |
| 144 | 142 |
| 145 static inline void reduceOcclusion(const gfx::Rect& affectedArea, const gfx::Rec
t& expandedPixel, Region& occlusion) | 143 static inline void reduceOcclusion(const gfx::Rect& affectedArea, const gfx::Rec
t& expandedPixel, Region& occlusion) |
| 146 { | 144 { |
| 147 if (affectedArea.IsEmpty()) | 145 if (affectedArea.IsEmpty()) |
| 148 return; | 146 return; |
| 149 | 147 |
| 150 Region affectedOcclusion = intersect(occlusion, affectedArea); | 148 Region affectedOcclusion = intersect(occlusion, affectedArea); |
| 151 Vector<WebCore::IntRect> affectedOcclusionRects = affectedOcclusion.rects(); | 149 Region::Iterator affectedOcclusionRects(affectedOcclusion); |
| 152 | 150 |
| 153 occlusion.Subtract(affectedArea); | 151 occlusion.Subtract(affectedArea); |
| 154 for (size_t j = 0; j < affectedOcclusionRects.size(); ++j) { | 152 for (; affectedOcclusionRects.has_rect(); affectedOcclusionRects.next()) { |
| 155 WebCore::IntRect& occlusionRect = affectedOcclusionRects[j]; | 153 gfx::Rect occlusionRect = affectedOcclusionRects.rect(); |
| 156 | 154 |
| 157 // Shrink the rect by expanding the non-opaque pixels outside the rect. | 155 // Shrink the rect by expanding the non-opaque pixels outside the rect. |
| 158 | 156 |
| 159 // The expandedPixel is the Rect for a single pixel after being | 157 // The expandedPixel is the Rect for a single pixel after being |
| 160 // expanded by filters on the layer. The original pixel would be | 158 // expanded by filters on the layer. The original pixel would be |
| 161 // Rect(0, 0, 1, 1), and the expanded pixel is the rect, relative | 159 // Rect(0, 0, 1, 1), and the expanded pixel is the rect, relative |
| 162 // to this original rect, that the original pixel can influence after | 160 // to this original rect, that the original pixel can influence after |
| 163 // being filtered. | 161 // being filtered. |
| 164 // To convert the expandedPixel Rect back to filter outsets: | 162 // To convert the expandedPixel Rect back to filter outsets: |
| 165 // x = -leftOutset | 163 // x = -leftOutset |
| 166 // width = leftOutset + rightOutset | 164 // width = leftOutset + rightOutset |
| 167 // right = x + width = -leftOutset + leftOutset + rightOutset = rightOut
set | 165 // right = x + width = -leftOutset + leftOutset + rightOutset = rightOut
set |
| 168 | 166 |
| 169 // The leftOutset of the filters moves pixels on the right side of | 167 // The leftOutset of the filters moves pixels on the right side of |
| 170 // the occlusionRect into it, shrinking its right edge. | 168 // the occlusionRect into it, shrinking its right edge. |
| 171 int shrinkLeft = occlusionRect.x() == affectedArea.x() ? 0 : expandedPix
el.right(); | 169 int shrinkLeft = occlusionRect.x() == affectedArea.x() ? 0 : expandedPix
el.right(); |
| 172 int shrinkTop = occlusionRect.y() == affectedArea.y() ? 0 : expandedPixe
l.bottom(); | 170 int shrinkTop = occlusionRect.y() == affectedArea.y() ? 0 : expandedPixe
l.bottom(); |
| 173 int shrinkRight = occlusionRect.maxX() == affectedArea.right() ? 0 : -ex
pandedPixel.x(); | 171 int shrinkRight = occlusionRect.right() == affectedArea.right() ? 0 : -e
xpandedPixel.x(); |
| 174 int shrinkBottom = occlusionRect.maxY() == affectedArea.bottom() ? 0 : -
expandedPixel.y(); | 172 int shrinkBottom = occlusionRect.bottom() == affectedArea.bottom() ? 0 :
-expandedPixel.y(); |
| 175 | 173 |
| 176 occlusionRect.move(shrinkLeft, shrinkTop); | 174 occlusionRect.Inset(shrinkLeft, shrinkTop, shrinkRight, shrinkBottom); |
| 177 occlusionRect.contract(shrinkLeft + shrinkRight, shrinkTop + shrinkBotto
m); | |
| 178 | 175 |
| 179 occlusion.Union(occlusionRect); | 176 occlusion.Union(occlusionRect); |
| 180 } | 177 } |
| 181 } | 178 } |
| 182 | 179 |
| 183 template<typename LayerType> | 180 template<typename LayerType> |
| 184 static void reduceOcclusionBelowSurface(LayerType* contributingLayer, const gfx:
:Rect& surfaceRect, const WebTransformationMatrix& surfaceTransform, LayerType*
renderTarget, Region& occlusionInTarget, Region& occlusionInScreen) | 181 static void reduceOcclusionBelowSurface(LayerType* contributingLayer, const gfx:
:Rect& surfaceRect, const WebTransformationMatrix& surfaceTransform, LayerType*
renderTarget, Region& occlusionInTarget, Region& occlusionInScreen) |
| 185 { | 182 { |
| 186 if (surfaceRect.IsEmpty()) | 183 if (surfaceRect.IsEmpty()) |
| 187 return; | 184 return; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 static inline void addOcclusionBehindLayer(Region& region, const LayerType* laye
r, const WebTransformationMatrix& transform, const Region& opaqueContents, const
gfx::Rect& clipRectInTarget, const gfx::Size& minimumTrackingSize, std::vector<
gfx::Rect>* occludingScreenSpaceRects) | 248 static inline void addOcclusionBehindLayer(Region& region, const LayerType* laye
r, const WebTransformationMatrix& transform, const Region& opaqueContents, const
gfx::Rect& clipRectInTarget, const gfx::Size& minimumTrackingSize, std::vector<
gfx::Rect>* occludingScreenSpaceRects) |
| 252 { | 249 { |
| 253 DCHECK(layer->visibleContentRect().Contains(opaqueContents.bounds())); | 250 DCHECK(layer->visibleContentRect().Contains(opaqueContents.bounds())); |
| 254 | 251 |
| 255 bool clipped; | 252 bool clipped; |
| 256 gfx::QuadF visibleTransformedQuad = MathUtil::mapQuad(transform, gfx::QuadF(
layer->visibleContentRect()), clipped); | 253 gfx::QuadF visibleTransformedQuad = MathUtil::mapQuad(transform, gfx::QuadF(
layer->visibleContentRect()), clipped); |
| 257 // FIXME: Find a rect interior to each transformed quad. | 254 // FIXME: Find a rect interior to each transformed quad. |
| 258 if (clipped || !visibleTransformedQuad.IsRectilinear()) | 255 if (clipped || !visibleTransformedQuad.IsRectilinear()) |
| 259 return; | 256 return; |
| 260 | 257 |
| 261 Vector<WebCore::IntRect> contentRects = opaqueContents.rects(); | 258 for (Region::Iterator opaqueContentRects(opaqueContents); opaqueContentRects
.has_rect(); opaqueContentRects.next()) { |
| 262 for (size_t i = 0; i < contentRects.size(); ++i) { | |
| 263 // We've already checked for clipping in the mapQuad call above, these c
alls should not clip anything further. | 259 // We've already checked for clipping in the mapQuad call above, these c
alls should not clip anything further. |
| 264 gfx::Rect transformedRect = gfx::ToEnclosedRect(MathUtil::mapClippedRect
(transform, cc::FloatRect(contentRects[i]))); | 260 gfx::Rect transformedRect = gfx::ToEnclosedRect(MathUtil::mapClippedRect
(transform, gfx::RectF(opaqueContentRects.rect()))); |
| 265 transformedRect.Intersect(clipRectInTarget); | 261 transformedRect.Intersect(clipRectInTarget); |
| 266 if (transformedRect.width() >= minimumTrackingSize.width() || transforme
dRect.height() >= minimumTrackingSize.height()) { | 262 if (transformedRect.width() >= minimumTrackingSize.width() || transforme
dRect.height() >= minimumTrackingSize.height()) { |
| 267 if (occludingScreenSpaceRects) | 263 if (occludingScreenSpaceRects) |
| 268 occludingScreenSpaceRects->push_back(transformedRect); | 264 occludingScreenSpaceRects->push_back(transformedRect); |
| 269 region.Union(transformedRect); | 265 region.Union(transformedRect); |
| 270 } | 266 } |
| 271 } | 267 } |
| 272 } | 268 } |
| 273 | 269 |
| 274 template<typename LayerType, typename RenderSurfaceType> | 270 template<typename LayerType, typename RenderSurfaceType> |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 template void OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::finishedRender
Target(const LayerImpl* finishedTarget); | 475 template void OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::finishedRender
Target(const LayerImpl* finishedTarget); |
| 480 template void OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::leaveToRenderT
arget(const LayerImpl* newTarget); | 476 template void OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::leaveToRenderT
arget(const LayerImpl* newTarget); |
| 481 template void OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::markOccludedBe
hindLayer(const LayerImpl*); | 477 template void OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::markOccludedBe
hindLayer(const LayerImpl*); |
| 482 template bool OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::occluded(const
LayerImpl*, const gfx::Rect& contentRect, const WebKit::WebTransformationMatrix
& drawTransform, bool implDrawTransformIsUnknown, const gfx::Rect& clippedRectIn
Target, bool* hasOcclusionFromOutsideTargetSurface) const; | 478 template bool OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::occluded(const
LayerImpl*, const gfx::Rect& contentRect, const WebKit::WebTransformationMatrix
& drawTransform, bool implDrawTransformIsUnknown, const gfx::Rect& clippedRectIn
Target, bool* hasOcclusionFromOutsideTargetSurface) const; |
| 483 template gfx::Rect OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::unocclude
dContentRect(const LayerImpl*, const gfx::Rect& contentRect, const WebKit::WebTr
ansformationMatrix& drawTransform, bool implDrawTransformIsUnknown, const gfx::R
ect& clippedRectInTarget, bool* hasOcclusionFromOutsideTargetSurface) const; | 479 template gfx::Rect OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::unocclude
dContentRect(const LayerImpl*, const gfx::Rect& contentRect, const WebKit::WebTr
ansformationMatrix& drawTransform, bool implDrawTransformIsUnknown, const gfx::R
ect& clippedRectInTarget, bool* hasOcclusionFromOutsideTargetSurface) const; |
| 484 template gfx::Rect OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::unocclude
dContributingSurfaceContentRect(const LayerImpl*, bool forReplica, const gfx::Re
ct& contentRect, bool* hasOcclusionFromOutsideTargetSurface) const; | 480 template gfx::Rect OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::unocclude
dContributingSurfaceContentRect(const LayerImpl*, bool forReplica, const gfx::Re
ct& contentRect, bool* hasOcclusionFromOutsideTargetSurface) const; |
| 485 template gfx::Rect OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::layerClip
RectInTarget(const LayerImpl*) const; | 481 template gfx::Rect OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::layerClip
RectInTarget(const LayerImpl*) const; |
| 486 | 482 |
| 487 | 483 |
| 488 } // namespace cc | 484 } // namespace cc |
| OLD | NEW |