Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: cc/occlusion_tracker.cc

Issue 11264056: cc: Use gfx:: Geometry types for positions, bounds, and related things. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ScaleAsVector Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/math_util_unittest.cc ('k') | cc/occlusion_tracker_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 // FIXME: Find a rect interior to each transformed quad. 126 // FIXME: Find a rect interior to each transformed quad.
127 if (clipped || !transformedBoundsQuad.isRectilinear()) 127 if (clipped || !transformedBoundsQuad.isRectilinear())
128 return Region(); 128 return Region();
129 129
130 Region transformedRegion; 130 Region transformedRegion;
131 131
132 Vector<WebCore::IntRect> rects = region.rects(); 132 Vector<WebCore::IntRect> rects = region.rects();
133 for (size_t i = 0; i < rects.size(); ++i) { 133 for (size_t i = 0; i < rects.size(); ++i) {
134 // 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.
135 gfx::Rect transformedRect = gfx::ToEnclosedRect(MathUtil::mapClippedRect (transform, cc::FloatRect(rects[i]))); 135 gfx::Rect transformedRect = gfx::ToEnclosedRect(MathUtil::mapClippedRect (transform, cc::FloatRect(rects[i])));
136 if (!surface->clipRect().isEmpty()) 136 if (!surface->clipRect().IsEmpty())
137 transformedRect.Intersect(surface->clipRect()); 137 transformedRect.Intersect(surface->clipRect());
138 transformedRegion.unite(cc::IntRect(transformedRect)); 138 transformedRegion.unite(cc::IntRect(transformedRect));
139 } 139 }
140 return transformedRegion; 140 return transformedRegion;
141 } 141 }
142 142
143 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)
144 { 144 {
145 if (affectedArea.IsEmpty()) 145 if (affectedArea.IsEmpty())
146 return; 146 return;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 178 }
179 } 179 }
180 180
181 template<typename LayerType> 181 template<typename LayerType>
182 static void reduceOcclusionBelowSurface(LayerType* contributingLayer, const gfx: :Rect& surfaceRect, const WebTransformationMatrix& surfaceTransform, LayerType* renderTarget, Region& occlusionInTarget, Region& occlusionInScreen) 182 static void reduceOcclusionBelowSurface(LayerType* contributingLayer, const gfx: :Rect& surfaceRect, const WebTransformationMatrix& surfaceTransform, LayerType* renderTarget, Region& occlusionInTarget, Region& occlusionInScreen)
183 { 183 {
184 if (surfaceRect.IsEmpty()) 184 if (surfaceRect.IsEmpty())
185 return; 185 return;
186 186
187 gfx::Rect boundsInTarget = gfx::ToEnclosingRect(MathUtil::mapClippedRect(sur faceTransform, cc::FloatRect(surfaceRect))); 187 gfx::Rect boundsInTarget = gfx::ToEnclosingRect(MathUtil::mapClippedRect(sur faceTransform, cc::FloatRect(surfaceRect)));
188 if (!contributingLayer->renderSurface()->clipRect().isEmpty()) 188 if (!contributingLayer->renderSurface()->clipRect().IsEmpty())
189 boundsInTarget.Intersect(contributingLayer->renderSurface()->clipRect()) ; 189 boundsInTarget.Intersect(contributingLayer->renderSurface()->clipRect()) ;
190 190
191 int outsetTop, outsetRight, outsetBottom, outsetLeft; 191 int outsetTop, outsetRight, outsetBottom, outsetLeft;
192 contributingLayer->backgroundFilters().getOutsets(outsetTop, outsetRight, ou tsetBottom, outsetLeft); 192 contributingLayer->backgroundFilters().getOutsets(outsetTop, outsetRight, ou tsetBottom, outsetLeft);
193 193
194 // The filter can move pixels from outside of the clip, so allow affectedAre a to expand outside the clip. 194 // The filter can move pixels from outside of the clip, so allow affectedAre a to expand outside the clip.
195 boundsInTarget.Inset(-outsetLeft, -outsetTop, -outsetRight, -outsetBottom); 195 boundsInTarget.Inset(-outsetLeft, -outsetTop, -outsetRight, -outsetBottom);
196 196
197 gfx::Rect boundsInScreen = gfx::ToEnclosingRect(MathUtil::mapClippedRect(ren derTarget->renderSurface()->screenSpaceTransform(), cc::FloatRect(boundsInTarget ))); 197 gfx::Rect boundsInScreen = gfx::ToEnclosingRect(MathUtil::mapClippedRect(ren derTarget->renderSurface()->screenSpaceTransform(), cc::FloatRect(boundsInTarget )));
198 198
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 reduceOcclusionBelowSurface(oldTarget, unoccludedSurfaceRect, oldSurface ->drawTransform(), newTarget, m_stack.last().occlusionInTarget, m_stack.last().o cclusionInScreen); 241 reduceOcclusionBelowSurface(oldTarget, unoccludedSurfaceRect, oldSurface ->drawTransform(), newTarget, m_stack.last().occlusionInTarget, m_stack.last().o cclusionInScreen);
242 if (oldTarget->hasReplica()) 242 if (oldTarget->hasReplica())
243 reduceOcclusionBelowSurface(oldTarget, unoccludedReplicaRect, oldSur face->replicaDrawTransform(), newTarget, m_stack.last().occlusionInTarget, m_sta ck.last().occlusionInScreen); 243 reduceOcclusionBelowSurface(oldTarget, unoccludedReplicaRect, oldSur face->replicaDrawTransform(), newTarget, m_stack.last().occlusionInTarget, m_sta ck.last().occlusionInScreen);
244 } 244 }
245 } 245 }
246 246
247 // FIXME: Remove usePaintTracking when paint tracking is on for paint culling. 247 // FIXME: Remove usePaintTracking when paint tracking is on for paint culling.
248 template<typename LayerType> 248 template<typename LayerType>
249 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) 249 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)
250 { 250 {
251 DCHECK(layer->visibleContentRect().contains(opaqueContents.bounds())); 251 DCHECK(layer->visibleContentRect().Contains(cc::IntRect(opaqueContents.bound s())));
252 252
253 bool clipped; 253 bool clipped;
254 FloatQuad visibleTransformedQuad = MathUtil::mapQuad(transform, FloatQuad(la yer->visibleContentRect()), clipped); 254 FloatQuad visibleTransformedQuad = MathUtil::mapQuad(transform, FloatQuad(la yer->visibleContentRect()), clipped);
255 // FIXME: Find a rect interior to each transformed quad. 255 // FIXME: Find a rect interior to each transformed quad.
256 if (clipped || !visibleTransformedQuad.isRectilinear()) 256 if (clipped || !visibleTransformedQuad.isRectilinear())
257 return; 257 return;
258 258
259 Vector<WebCore::IntRect> contentRects = opaqueContents.rects(); 259 Vector<WebCore::IntRect> contentRects = opaqueContents.rects();
260 for (size_t i = 0; i < contentRects.size(); ++i) { 260 for (size_t i = 0; i < contentRects.size(); ++i) {
261 // We've already checked for clipping in the mapQuad call above, these c alls should not clip anything further. 261 // We've already checked for clipping in the mapQuad call above, these c alls should not clip anything further.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 // FIXME: Find a rect interior to the transformed clip quad. 301 // FIXME: Find a rect interior to the transformed clip quad.
302 if (clipped || !clipQuadInScreen.isRectilinear()) 302 if (clipped || !clipQuadInScreen.isRectilinear())
303 return; 303 return;
304 gfx::Rect clipRectInScreen = gfx::IntersectRects(m_rootTargetRect, gfx:: ToEnclosedRect(clipQuadInScreen.boundingBox())); 304 gfx::Rect clipRectInScreen = gfx::IntersectRects(m_rootTargetRect, gfx:: ToEnclosedRect(clipQuadInScreen.boundingBox()));
305 addOcclusionBehindLayer<LayerType>(m_stack.last().occlusionInScreen, lay er, layer->screenSpaceTransform(), opaqueContents, clipRectInScreen, m_minimumTr ackingSize, m_occludingScreenSpaceRects); 305 addOcclusionBehindLayer<LayerType>(m_stack.last().occlusionInScreen, lay er, layer->screenSpaceTransform(), opaqueContents, clipRectInScreen, m_minimumTr ackingSize, m_occludingScreenSpaceRects);
306 } 306 }
307 } 307 }
308 308
309 static inline bool testContentRectOccluded(const gfx::Rect& contentRect, const W ebTransformationMatrix& contentSpaceTransform, const gfx::Rect& clipRectInTarget , const Region& occlusion) 309 static inline bool testContentRectOccluded(const gfx::Rect& contentRect, const W ebTransformationMatrix& contentSpaceTransform, const gfx::Rect& clipRectInTarget , const Region& occlusion)
310 { 310 {
311 gfx::RectF transformedRect = MathUtil::mapClippedRect(contentSpaceTransform, cc::FloatRect(contentRect)); 311 gfx::RectF transformedRect = MathUtil::mapClippedRect(contentSpaceTransform, gfx::RectF(contentRect));
312 // Take the gfx::ToEnclosingRect, as we want to include partial pixels in th e test. 312 // Take the gfx::ToEnclosingRect, as we want to include partial pixels in th e test.
313 gfx::Rect targetRect = gfx::IntersectRects(gfx::ToEnclosingRect(transformedR ect), clipRectInTarget); 313 gfx::Rect targetRect = gfx::IntersectRects(gfx::ToEnclosingRect(transformedR ect), clipRectInTarget);
314 return targetRect.IsEmpty() || occlusion.contains(cc::IntRect(targetRect)); 314 return targetRect.IsEmpty() || occlusion.contains(cc::IntRect(targetRect));
315 } 315 }
316 316
317 template<typename LayerType, typename RenderSurfaceType> 317 template<typename LayerType, typename RenderSurfaceType>
318 bool OcclusionTrackerBase<LayerType, RenderSurfaceType>::occluded(const LayerTyp e* renderTarget, const gfx::Rect& contentRect, const WebKit::WebTransformationMa trix& drawTransform, bool implDrawTransformIsUnknown, const gfx::Rect& clippedRe ctInTarget, bool* hasOcclusionFromOutsideTargetSurface) const 318 bool OcclusionTrackerBase<LayerType, RenderSurfaceType>::occluded(const LayerTyp e* renderTarget, const gfx::Rect& contentRect, const WebKit::WebTransformationMa trix& drawTransform, bool implDrawTransformIsUnknown, const gfx::Rect& clippedRe ctInTarget, bool* hasOcclusionFromOutsideTargetSurface) const
319 { 319 {
320 if (hasOcclusionFromOutsideTargetSurface) 320 if (hasOcclusionFromOutsideTargetSurface)
321 *hasOcclusionFromOutsideTargetSurface = false; 321 *hasOcclusionFromOutsideTargetSurface = false;
(...skipping 29 matching lines...) Expand all
351 rectRegion.subtract(region); 351 rectRegion.subtract(region);
352 return cc::IntRect(rectRegion.bounds()); 352 return cc::IntRect(rectRegion.bounds());
353 } 353 }
354 354
355 static inline gfx::Rect computeUnoccludedContentRect(const gfx::Rect& contentRec t, const WebTransformationMatrix& contentSpaceTransform, const gfx::Rect& clipRe ctInTarget, const Region& occlusion) 355 static inline gfx::Rect computeUnoccludedContentRect(const gfx::Rect& contentRec t, const WebTransformationMatrix& contentSpaceTransform, const gfx::Rect& clipRe ctInTarget, const Region& occlusion)
356 { 356 {
357 if (!contentSpaceTransform.isInvertible()) 357 if (!contentSpaceTransform.isInvertible())
358 return contentRect; 358 return contentRect;
359 359
360 // Take the ToEnclosingRect at each step, as we want to contain any unocclud ed partial pixels in the resulting Rect. 360 // Take the ToEnclosingRect at each step, as we want to contain any unocclud ed partial pixels in the resulting Rect.
361 FloatRect transformedRect = MathUtil::mapClippedRect(contentSpaceTransform, cc::FloatRect(contentRect)); 361 gfx::RectF transformedRect = MathUtil::mapClippedRect(contentSpaceTransform, gfx::RectF(contentRect));
362 gfx::Rect shrunkRect = rectSubtractRegion(gfx::IntersectRects(gfx::ToEnclosi ngRect(transformedRect), clipRectInTarget), occlusion); 362 gfx::Rect shrunkRect = rectSubtractRegion(gfx::IntersectRects(gfx::ToEnclosi ngRect(transformedRect), clipRectInTarget), occlusion);
363 gfx::Rect unoccludedRect = gfx::ToEnclosingRect(MathUtil::projectClippedRect (contentSpaceTransform.inverse(), cc::FloatRect(shrunkRect))); 363 gfx::Rect unoccludedRect = gfx::ToEnclosingRect(MathUtil::projectClippedRect (contentSpaceTransform.inverse(), gfx::RectF(shrunkRect)));
364 // The rect back in content space is a bounding box and may extend outside o f the original contentRect, so clamp it to the contentRectBounds. 364 // The rect back in content space is a bounding box and may extend outside o f the original contentRect, so clamp it to the contentRectBounds.
365 return gfx::IntersectRects(unoccludedRect, contentRect); 365 return gfx::IntersectRects(unoccludedRect, contentRect);
366 } 366 }
367 367
368 template<typename LayerType, typename RenderSurfaceType> 368 template<typename LayerType, typename RenderSurfaceType>
369 gfx::Rect OcclusionTrackerBase<LayerType, RenderSurfaceType>::unoccludedContentR ect(const LayerType* renderTarget, const gfx::Rect& contentRect, const WebKit::W ebTransformationMatrix& drawTransform, bool implDrawTransformIsUnknown, const gf x::Rect& clippedRectInTarget, bool* hasOcclusionFromOutsideTargetSurface) const 369 gfx::Rect OcclusionTrackerBase<LayerType, RenderSurfaceType>::unoccludedContentR ect(const LayerType* renderTarget, const gfx::Rect& contentRect, const WebKit::W ebTransformationMatrix& drawTransform, bool implDrawTransformIsUnknown, const gf x::Rect& clippedRectInTarget, bool* hasOcclusionFromOutsideTargetSurface) const
370 { 370 {
371 DCHECK(!m_stack.isEmpty()); 371 DCHECK(!m_stack.isEmpty());
372 if (m_stack.isEmpty()) 372 if (m_stack.isEmpty())
373 return contentRect; 373 return contentRect;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 template void OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::finishedRender Target(const LayerImpl* finishedTarget); 478 template void OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::finishedRender Target(const LayerImpl* finishedTarget);
479 template void OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::leaveToRenderT arget(const LayerImpl* newTarget); 479 template void OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::leaveToRenderT arget(const LayerImpl* newTarget);
480 template void OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::markOccludedBe hindLayer(const LayerImpl*); 480 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; 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;
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; 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;
483 template gfx::Rect OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::unocclude dContributingSurfaceContentRect(const LayerImpl*, bool forReplica, const gfx::Re ct& contentRect, bool* hasOcclusionFromOutsideTargetSurface) const; 483 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; 484 template gfx::Rect OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>::layerClip RectInTarget(const LayerImpl*) const;
485 485
486 486
487 } // namespace cc 487 } // namespace cc
OLDNEW
« no previous file with comments | « cc/math_util_unittest.cc ('k') | cc/occlusion_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698