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 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // 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. |
124 | 124 |
125 bool clipped; | 125 bool clipped; |
126 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); |
127 // FIXME: Find a rect interior to each transformed quad. | 127 // FIXME: Find a rect interior to each transformed quad. |
128 if (clipped || !transformedBoundsQuad.IsRectilinear()) | 128 if (clipped || !transformedBoundsQuad.IsRectilinear()) |
129 return Region(); | 129 return Region(); |
130 | 130 |
131 Region transformedRegion; | 131 Region transformedRegion; |
132 | 132 |
133 Vector<WebCore::IntRect> rects = region.rects(); | 133 for (Region::Iterator rects(region); rects.has_rect(); rects.next()) { |
134 for (size_t i = 0; i < rects.size(); ++i) { | |
135 // 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. |
136 gfx::Rect transformedRect = gfx::ToEnclosedRect(MathUtil::mapClippedRect
(transform, gfx::RectF(gfx::Rect(cc::IntRect(rects[i]))))); | 135 gfx::Rect transformedRect = gfx::ToEnclosedRect(MathUtil::mapClippedRect
(transform, gfx::RectF(rects.rect()))); |
137 if (!surface->clipRect().IsEmpty()) | 136 if (!surface->clipRect().IsEmpty()) |
138 transformedRect.Intersect(surface->clipRect()); | 137 transformedRect.Intersect(surface->clipRect()); |
139 transformedRegion.Union(transformedRect); | 138 transformedRegion.Union(transformedRect); |
140 } | 139 } |
141 return transformedRegion; | 140 return transformedRegion; |
142 } | 141 } |
143 | 142 |
144 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) |
145 { | 144 { |
146 if (affectedArea.IsEmpty()) | 145 if (affectedArea.IsEmpty()) |
147 return; | 146 return; |
148 | 147 |
149 Region affectedOcclusion = intersect(occlusion, affectedArea); | 148 Region affectedOcclusion = intersect(occlusion, affectedArea); |
150 Vector<WebCore::IntRect> affectedOcclusionRects = affectedOcclusion.rects(); | 149 Region::Iterator affectedOcclusionRects(affectedOcclusion); |
151 | 150 |
152 occlusion.Subtract(affectedArea); | 151 occlusion.Subtract(affectedArea); |
153 for (size_t j = 0; j < affectedOcclusionRects.size(); ++j) { | 152 for (; affectedOcclusionRects.has_rect(); affectedOcclusionRects.next()) { |
154 WebCore::IntRect& occlusionRect = affectedOcclusionRects[j]; | 153 gfx::Rect occlusionRect = affectedOcclusionRects.rect(); |
155 | 154 |
156 // 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. |
157 | 156 |
158 // The expandedPixel is the Rect for a single pixel after being | 157 // The expandedPixel is the Rect for a single pixel after being |
159 // expanded by filters on the layer. The original pixel would be | 158 // expanded by filters on the layer. The original pixel would be |
160 // 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 |
161 // to this original rect, that the original pixel can influence after | 160 // to this original rect, that the original pixel can influence after |
162 // being filtered. | 161 // being filtered. |
163 // To convert the expandedPixel Rect back to filter outsets: | 162 // To convert the expandedPixel Rect back to filter outsets: |
164 // x = -leftOutset | 163 // x = -leftOutset |
165 // width = leftOutset + rightOutset | 164 // width = leftOutset + rightOutset |
166 // right = x + width = -leftOutset + leftOutset + rightOutset = rightOut
set | 165 // right = x + width = -leftOutset + leftOutset + rightOutset = rightOut
set |
167 | 166 |
168 // 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 |
169 // the occlusionRect into it, shrinking its right edge. | 168 // the occlusionRect into it, shrinking its right edge. |
170 int shrinkLeft = occlusionRect.x() == affectedArea.x() ? 0 : expandedPix
el.right(); | 169 int shrinkLeft = occlusionRect.x() == affectedArea.x() ? 0 : expandedPix
el.right(); |
171 int shrinkTop = occlusionRect.y() == affectedArea.y() ? 0 : expandedPixe
l.bottom(); | 170 int shrinkTop = occlusionRect.y() == affectedArea.y() ? 0 : expandedPixe
l.bottom(); |
172 int shrinkRight = occlusionRect.maxX() == affectedArea.right() ? 0 : -ex
pandedPixel.x(); | 171 int shrinkRight = occlusionRect.right() == affectedArea.right() ? 0 : -e
xpandedPixel.x(); |
173 int shrinkBottom = occlusionRect.maxY() == affectedArea.bottom() ? 0 : -
expandedPixel.y(); | 172 int shrinkBottom = occlusionRect.bottom() == affectedArea.bottom() ? 0 :
-expandedPixel.y(); |
174 | 173 |
175 occlusionRect.move(shrinkLeft, shrinkTop); | 174 occlusionRect.Inset(shrinkLeft, shrinkTop, shrinkRight, shrinkBottom); |
176 occlusionRect.contract(shrinkLeft + shrinkRight, shrinkTop + shrinkBotto
m); | |
177 | 175 |
178 occlusion.Union(occlusionRect); | 176 occlusion.Union(occlusionRect); |
179 } | 177 } |
180 } | 178 } |
181 | 179 |
182 template<typename LayerType> | 180 template<typename LayerType> |
183 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) |
184 { | 182 { |
185 if (surfaceRect.IsEmpty()) | 183 if (surfaceRect.IsEmpty()) |
186 return; | 184 return; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 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) |
251 { | 249 { |
252 DCHECK(layer->visibleContentRect().Contains(opaqueContents.bounds())); | 250 DCHECK(layer->visibleContentRect().Contains(opaqueContents.bounds())); |
253 | 251 |
254 bool clipped; | 252 bool clipped; |
255 gfx::QuadF visibleTransformedQuad = MathUtil::mapQuad(transform, gfx::QuadF(
layer->visibleContentRect()), clipped); | 253 gfx::QuadF visibleTransformedQuad = MathUtil::mapQuad(transform, gfx::QuadF(
layer->visibleContentRect()), clipped); |
256 // FIXME: Find a rect interior to each transformed quad. | 254 // FIXME: Find a rect interior to each transformed quad. |
257 if (clipped || !visibleTransformedQuad.IsRectilinear()) | 255 if (clipped || !visibleTransformedQuad.IsRectilinear()) |
258 return; | 256 return; |
259 | 257 |
260 Vector<WebCore::IntRect> contentRects = opaqueContents.rects(); | 258 for (Region::Iterator opaqueContentRects(opaqueContents); opaqueContentRects
.has_rect(); opaqueContentRects.next()) { |
261 for (size_t i = 0; i < contentRects.size(); ++i) { | |
262 // 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. |
263 gfx::Rect transformedRect = gfx::ToEnclosedRect(MathUtil::mapClippedRect
(transform, gfx::RectF(gfx::Rect(cc::IntRect(contentRects[i]))))); | 260 gfx::Rect transformedRect = gfx::ToEnclosedRect(MathUtil::mapClippedRect
(transform, gfx::RectF(opaqueContentRects.rect()))); |
264 transformedRect.Intersect(clipRectInTarget); | 261 transformedRect.Intersect(clipRectInTarget); |
265 if (transformedRect.width() >= minimumTrackingSize.width() || transforme
dRect.height() >= minimumTrackingSize.height()) { | 262 if (transformedRect.width() >= minimumTrackingSize.width() || transforme
dRect.height() >= minimumTrackingSize.height()) { |
266 if (occludingScreenSpaceRects) | 263 if (occludingScreenSpaceRects) |
267 occludingScreenSpaceRects->push_back(transformedRect); | 264 occludingScreenSpaceRects->push_back(transformedRect); |
268 region.Union(transformedRect); | 265 region.Union(transformedRect); |
269 } | 266 } |
270 } | 267 } |
271 } | 268 } |
272 | 269 |
273 template<typename LayerType, typename RenderSurfaceType> | 270 template<typename LayerType, typename RenderSurfaceType> |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 template void OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::finishedRender
Target(const LayerImpl* finishedTarget); | 475 template void OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::finishedRender
Target(const LayerImpl* finishedTarget); |
479 template void OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::leaveToRenderT
arget(const LayerImpl* newTarget); | 476 template void OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::leaveToRenderT
arget(const LayerImpl* newTarget); |
480 template void OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::markOccludedBe
hindLayer(const LayerImpl*); | 477 template void OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::markOccludedBe
hindLayer(const LayerImpl*); |
481 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; |
482 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; |
483 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; |
484 template gfx::Rect OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::layerClip
RectInTarget(const LayerImpl*) const; | 481 template gfx::Rect OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::layerClip
RectInTarget(const LayerImpl*) const; |
485 | 482 |
486 | 483 |
487 } // namespace cc | 484 } // namespace cc |
OLD | NEW |