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