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 "cc/occlusion_tracker.h" | 5 #include "cc/occlusion_tracker.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "cc/layer.h" | 9 #include "cc/layer.h" |
10 #include "cc/layer_impl.h" | 10 #include "cc/layer_impl.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 if (layerIterator.representsItself) | 48 if (layerIterator.representsItself) |
49 markOccludedBehindLayer(layerIterator.currentLayer); | 49 markOccludedBehindLayer(layerIterator.currentLayer); |
50 else if (layerIterator.representsContributingRenderSurface) | 50 else if (layerIterator.representsContributingRenderSurface) |
51 leaveToRenderTarget(renderTarget); | 51 leaveToRenderTarget(renderTarget); |
52 } | 52 } |
53 | 53 |
54 template<typename RenderSurfaceType> | 54 template<typename RenderSurfaceType> |
55 static gfx::Rect screenSpaceClipRectInTargetSurface(const RenderSurfaceType* tar
getSurface, gfx::Rect screenSpaceClipRect) | 55 static gfx::Rect screenSpaceClipRectInTargetSurface(const RenderSurfaceType* tar
getSurface, gfx::Rect screenSpaceClipRect) |
56 { | 56 { |
57 gfx::Transform inverseScreenSpaceTransform; | 57 gfx::Transform inverseScreenSpaceTransform(gfx::Transform::kSkipInitializati
on); |
58 if (!targetSurface->screenSpaceTransform().GetInverse(&inverseScreenSpaceTra
nsform)) | 58 if (!targetSurface->screenSpaceTransform().GetInverse(&inverseScreenSpaceTra
nsform)) |
59 return targetSurface->contentRect(); | 59 return targetSurface->contentRect(); |
60 | 60 |
61 return gfx::ToEnclosingRect(MathUtil::projectClippedRect(inverseScreenSpaceT
ransform, screenSpaceClipRect)); | 61 return gfx::ToEnclosingRect(MathUtil::projectClippedRect(inverseScreenSpaceT
ransform, screenSpaceClipRect)); |
62 } | 62 } |
63 | 63 |
64 template<typename RenderSurfaceType> | 64 template<typename RenderSurfaceType> |
65 static Region transformSurfaceOpaqueRegion(const Region& region, bool haveClipRe
ct, gfx::Rect clipRectInNewTarget, const gfx::Transform& transform) | 65 static Region transformSurfaceOpaqueRegion(const Region& region, bool haveClipRe
ct, gfx::Rect clipRectInNewTarget, const gfx::Transform& transform) |
66 { | 66 { |
67 if (region.IsEmpty()) | 67 if (region.IsEmpty()) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 // We copy the screen occlusion into the new RenderSurface subtree, but we n
ever copy in the | 118 // We copy the screen occlusion into the new RenderSurface subtree, but we n
ever copy in the |
119 // occlusion from inside the target, since we are looking at a new RenderSur
face target. | 119 // occlusion from inside the target, since we are looking at a new RenderSur
face target. |
120 | 120 |
121 // If we are entering a subtree that is going to move pixels around, then th
e occlusion we've computed | 121 // If we are entering a subtree that is going to move pixels around, then th
e occlusion we've computed |
122 // so far won't apply to the pixels we're drawing here in the same way. We d
iscard the occlusion thus | 122 // so far won't apply to the pixels we're drawing here in the same way. We d
iscard the occlusion thus |
123 // far to be safe, and ensure we don't cull any pixels that are moved such t
hat they become visible. | 123 // far to be safe, and ensure we don't cull any pixels that are moved such t
hat they become visible. |
124 bool enteringSubtreeThatMovesPixels = newAncestorThatMovesPixels && newAnces
torThatMovesPixels != oldAncestorThatMovesPixels; | 124 bool enteringSubtreeThatMovesPixels = newAncestorThatMovesPixels && newAnces
torThatMovesPixels != oldAncestorThatMovesPixels; |
125 | 125 |
126 bool haveTransformFromScreenToNewTarget = false; | 126 bool haveTransformFromScreenToNewTarget = false; |
127 gfx::Transform inverseNewTargetScreenSpaceTransform; | 127 gfx::Transform inverseNewTargetScreenSpaceTransform(gfx::Transform::kSkipIni
tialization); // Note carefully, not used if screen space transform is uninverti
ble. |
128 if (surfaceTransformsToScreenKnown(newTarget->renderSurface())) | 128 if (surfaceTransformsToScreenKnown(newTarget->renderSurface())) |
129 haveTransformFromScreenToNewTarget = newTarget->renderSurface()->screenS
paceTransform().GetInverse(&inverseNewTargetScreenSpaceTransform); | 129 haveTransformFromScreenToNewTarget = newTarget->renderSurface()->screenS
paceTransform().GetInverse(&inverseNewTargetScreenSpaceTransform); |
130 | 130 |
131 bool enteringRootTarget = newTarget->parent() == NULL; | 131 bool enteringRootTarget = newTarget->parent() == NULL; |
132 | 132 |
133 bool copyOutsideOcclusionForward = m_stack.size() > 1 && !enteringSubtreeTha
tMovesPixels && haveTransformFromScreenToNewTarget && !enteringRootTarget; | 133 bool copyOutsideOcclusionForward = m_stack.size() > 1 && !enteringSubtreeTha
tMovesPixels && haveTransformFromScreenToNewTarget && !enteringRootTarget; |
134 if (!copyOutsideOcclusionForward) | 134 if (!copyOutsideOcclusionForward) |
135 return; | 135 return; |
136 | 136 |
137 int lastIndex = m_stack.size() - 1; | 137 int lastIndex = m_stack.size() - 1; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 return false; | 346 return false; |
347 | 347 |
348 // For tests with no render target. | 348 // For tests with no render target. |
349 if (!renderTarget) | 349 if (!renderTarget) |
350 return false; | 350 return false; |
351 | 351 |
352 DCHECK(renderTarget->renderTarget() == renderTarget); | 352 DCHECK(renderTarget->renderTarget() == renderTarget); |
353 DCHECK(renderTarget->renderSurface()); | 353 DCHECK(renderTarget->renderSurface()); |
354 DCHECK(renderTarget == m_stack.back().target); | 354 DCHECK(renderTarget == m_stack.back().target); |
355 | 355 |
356 gfx::Transform inverseDrawTransform; | 356 gfx::Transform inverseDrawTransform(gfx::Transform::kSkipInitialization); |
357 if (!drawTransform.GetInverse(&inverseDrawTransform)) | 357 if (!drawTransform.GetInverse(&inverseDrawTransform)) |
358 return false; | 358 return false; |
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 gfx::Rect contentRectInTargetSurface = gfx::ToEnclosingRect(MathUtil::mapCli
ppedRect(drawTransform, gfx::RectF(contentRect))); | 361 gfx::Rect contentRectInTargetSurface = gfx::ToEnclosingRect(MathUtil::mapCli
ppedRect(drawTransform, gfx::RectF(contentRect))); |
362 contentRectInTargetSurface.Intersect(clippedRectInTarget); | 362 contentRectInTargetSurface.Intersect(clippedRectInTarget); |
363 contentRectInTargetSurface.Intersect(screenSpaceClipRectInTargetSurface(rend
erTarget->renderSurface(), m_screenSpaceClipRect)); | 363 contentRectInTargetSurface.Intersect(screenSpaceClipRectInTargetSurface(rend
erTarget->renderSurface(), m_screenSpaceClipRect)); |
364 | 364 |
365 Region unoccludedRegionInTargetSurface = contentRectInTargetSurface; | 365 Region unoccludedRegionInTargetSurface = contentRectInTargetSurface; |
366 unoccludedRegionInTargetSurface.Subtract(m_stack.back().occlusionFromInsideT
arget); | 366 unoccludedRegionInTargetSurface.Subtract(m_stack.back().occlusionFromInsideT
arget); |
(...skipping 22 matching lines...) Expand all Loading... |
389 return contentRect; | 389 return contentRect; |
390 | 390 |
391 // For tests with no render target. | 391 // For tests with no render target. |
392 if (!renderTarget) | 392 if (!renderTarget) |
393 return contentRect; | 393 return contentRect; |
394 | 394 |
395 DCHECK(renderTarget->renderTarget() == renderTarget); | 395 DCHECK(renderTarget->renderTarget() == renderTarget); |
396 DCHECK(renderTarget->renderSurface()); | 396 DCHECK(renderTarget->renderSurface()); |
397 DCHECK(renderTarget == m_stack.back().target); | 397 DCHECK(renderTarget == m_stack.back().target); |
398 | 398 |
399 gfx::Transform inverseDrawTransform; | 399 gfx::Transform inverseDrawTransform(gfx::Transform::kSkipInitialization); |
400 if (!drawTransform.GetInverse(&inverseDrawTransform)) | 400 if (!drawTransform.GetInverse(&inverseDrawTransform)) |
401 return contentRect; | 401 return contentRect; |
402 | 402 |
403 // Take the ToEnclosingRect at each step, as we want to contain any unocclud
ed partial pixels in the resulting Rect. | 403 // Take the ToEnclosingRect at each step, as we want to contain any unocclud
ed partial pixels in the resulting Rect. |
404 gfx::Rect contentRectInTargetSurface = gfx::ToEnclosingRect(MathUtil::mapCli
ppedRect(drawTransform, gfx::RectF(contentRect))); | 404 gfx::Rect contentRectInTargetSurface = gfx::ToEnclosingRect(MathUtil::mapCli
ppedRect(drawTransform, gfx::RectF(contentRect))); |
405 contentRectInTargetSurface.Intersect(clippedRectInTarget); | 405 contentRectInTargetSurface.Intersect(clippedRectInTarget); |
406 contentRectInTargetSurface.Intersect(screenSpaceClipRectInTargetSurface(rend
erTarget->renderSurface(), m_screenSpaceClipRect)); | 406 contentRectInTargetSurface.Intersect(screenSpaceClipRectInTargetSurface(rend
erTarget->renderSurface(), m_screenSpaceClipRect)); |
407 | 407 |
408 Region unoccludedRegionInTargetSurface = contentRectInTargetSurface; | 408 Region unoccludedRegionInTargetSurface = contentRectInTargetSurface; |
409 unoccludedRegionInTargetSurface.Subtract(m_stack.back().occlusionFromInsideT
arget); | 409 unoccludedRegionInTargetSurface.Subtract(m_stack.back().occlusionFromInsideT
arget); |
(...skipping 28 matching lines...) Expand all Loading... |
438 if (contentRect.IsEmpty()) | 438 if (contentRect.IsEmpty()) |
439 return contentRect; | 439 return contentRect; |
440 | 440 |
441 const RenderSurfaceType* surface = layer->renderSurface(); | 441 const RenderSurfaceType* surface = layer->renderSurface(); |
442 const LayerType* contributingSurfaceRenderTarget = layer->parent()->renderTa
rget(); | 442 const LayerType* contributingSurfaceRenderTarget = layer->parent()->renderTa
rget(); |
443 | 443 |
444 if (!surfaceTransformsToTargetKnown(surface)) | 444 if (!surfaceTransformsToTargetKnown(surface)) |
445 return contentRect; | 445 return contentRect; |
446 | 446 |
447 gfx::Transform drawTransform = forReplica ? surface->replicaDrawTransform()
: surface->drawTransform(); | 447 gfx::Transform drawTransform = forReplica ? surface->replicaDrawTransform()
: surface->drawTransform(); |
448 gfx::Transform inverseDrawTransform; | 448 gfx::Transform inverseDrawTransform(gfx::Transform::kSkipInitialization); |
449 if (!drawTransform.GetInverse(&inverseDrawTransform)) | 449 if (!drawTransform.GetInverse(&inverseDrawTransform)) |
450 return contentRect; | 450 return contentRect; |
451 | 451 |
452 // Take the ToEnclosingRect at each step, as we want to contain any unocclud
ed partial pixels in the resulting Rect. | 452 // Take the ToEnclosingRect at each step, as we want to contain any unocclud
ed partial pixels in the resulting Rect. |
453 gfx::Rect contentRectInTargetSurface = gfx::ToEnclosingRect(MathUtil::mapCli
ppedRect(drawTransform, gfx::RectF(contentRect))); | 453 gfx::Rect contentRectInTargetSurface = gfx::ToEnclosingRect(MathUtil::mapCli
ppedRect(drawTransform, gfx::RectF(contentRect))); |
454 if (surface->isClipped()) { | 454 if (surface->isClipped()) { |
455 contentRectInTargetSurface.Intersect(surface->clipRect()); | 455 contentRectInTargetSurface.Intersect(surface->clipRect()); |
456 } else { | 456 } else { |
457 contentRectInTargetSurface.Intersect(contributingSurfaceRenderTarget->re
nderSurface()->contentRect()); | 457 contentRectInTargetSurface.Intersect(contributingSurfaceRenderTarget->re
nderSurface()->contentRect()); |
458 contentRectInTargetSurface.Intersect(gfx::ToEnclosingRect(surface->drawa
bleContentRect())); | 458 contentRectInTargetSurface.Intersect(gfx::ToEnclosingRect(surface->drawa
bleContentRect())); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 { | 494 { |
495 // TODO(danakj): Can we remove this use of drawableContentRect and just use
the clipRect() and target surface contentRect? | 495 // TODO(danakj): Can we remove this use of drawableContentRect and just use
the clipRect() and target surface contentRect? |
496 return layer->drawableContentRect(); | 496 return layer->drawableContentRect(); |
497 } | 497 } |
498 | 498 |
499 // Instantiate (and export) templates here for the linker. | 499 // Instantiate (and export) templates here for the linker. |
500 template class OcclusionTrackerBase<Layer, RenderSurface>; | 500 template class OcclusionTrackerBase<Layer, RenderSurface>; |
501 template class OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>; | 501 template class OcclusionTrackerBase<LayerImpl, RenderSurfaceImpl>; |
502 | 502 |
503 } // namespace cc | 503 } // namespace cc |
OLD | NEW |