[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "config.h" |
| 6 | |
| 7 | #include "CCRenderPass.h" |
| 8 | |
| 9 | #include "CCLayerImpl.h" |
| 10 | #include "CCMathUtil.h" |
| 11 | #include "CCOcclusionTracker.h" |
| 12 | #include "CCQuadCuller.h" |
| 13 | #include "CCSharedQuadState.h" |
| 14 | #include "CCSolidColorDrawQuad.h" |
| 15 | |
| 16 | using WebKit::WebTransformationMatrix; |
| 17 | |
| 18 | namespace WebCore { |
| 19 | |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame^] | 20 | PassOwnPtr<CCRenderPass> CCRenderPass::create(Id id, IntRect outputRect, const WebKit::WebTransformationMatrix& transformToRootTarget) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 21 | { |
| 22 | return adoptPtr(new CCRenderPass(id, outputRect, transformToRootTarget)); |
| 23 | } |
| 24 | |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame^] | 25 | CCRenderPass::CCRenderPass(Id id, IntRect outputRect, const WebKit::WebTransformationMatrix& transformToRootTarget) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 26 | : m_id(id) |
| 27 | , m_transformToRootTarget(transformToRootTarget) |
| 28 | , m_outputRect(outputRect) |
| 29 | , m_hasTransparentBackground(true) |
| 30 | , m_hasOcclusionFromOutsideTargetSurface(false) |
| 31 | { |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame^] | 32 | ASSERT(id.layerId > 0); |
| 33 | ASSERT(id.index >= 0); |
| 34 | } |
| 35 | |
| 36 | PassOwnPtr<CCRenderPass> CCRenderPass::copy(Id newId) const |
| 37 | { |
| 38 | ASSERT(newId != m_id); |
| 39 | |
| 40 | OwnPtr<CCRenderPass> copyPass(create(newId, m_outputRect, m_transformToRootTarget)); |
| 41 | copyPass->setDamageRect(m_damageRect); |
| 42 | copyPass->setHasTransparentBackground(m_hasTransparentBackground); |
| 43 | copyPass->setHasOcclusionFromOutsideTargetSurface(m_hasOcclusionFromOutsideTargetSurface); |
| 44 | copyPass->setFilters(m_filters); |
| 45 | copyPass->setBackgroundFilters(m_backgroundFilters); |
| 46 | return copyPass.release(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 47 | } |
| 48 | |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 49 | void CCRenderPass::appendQuadsForLayer(CCLayerImpl* layer, CCOcclusionTrackerImpl* occlusionTracker, CCAppendQuadsData& appendQuadsData) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 50 | { |
| 51 | const bool forSurface = false; |
| 52 | CCQuadCuller quadCuller(m_quadList, m_sharedQuadStateList, layer, occlusionTracker, layer->hasDebugBorders(), forSurface); |
| 53 | |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 54 | layer->appendQuads(quadCuller, appendQuadsData); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 55 | } |
| 56 | |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 57 | void CCRenderPass::appendQuadsForRenderSurfaceLayer(CCLayerImpl* layer, const CCRenderPass* contributingRenderPass, CCOcclusionTrackerImpl* occlusionTracker, CCAppendQuadsData& appendQuadsData) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 58 | { |
| 59 | const bool forSurface = true; |
| 60 | CCQuadCuller quadCuller(m_quadList, m_sharedQuadStateList, layer, occlusionTracker, layer->hasDebugBorders(), forSurface); |
| 61 | |
| 62 | bool isReplica = false; |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 63 | layer->renderSurface()->appendQuads(quadCuller, appendQuadsData, isReplica, contributingRenderPass->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 64 | |
| 65 | // Add replica after the surface so that it appears below the surface. |
| 66 | if (layer->hasReplica()) { |
| 67 | isReplica = true; |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame] | 68 | layer->renderSurface()->appendQuads(quadCuller, appendQuadsData, isReplica, contributingRenderPass->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 69 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void CCRenderPass::appendQuadsToFillScreen(CCLayerImpl* rootLayer, SkColor screenBackgroundColor, const CCOcclusionTrackerImpl& occlusionTracker) |
| 73 | { |
| 74 | if (!rootLayer || !screenBackgroundColor) |
| 75 | return; |
| 76 | |
| 77 | Region fillRegion = occlusionTracker.computeVisibleRegionInScreen(); |
| 78 | if (fillRegion.isEmpty()) |
| 79 | return; |
| 80 | |
| 81 | bool forSurface = false; |
| 82 | CCQuadCuller quadCuller(m_quadList, m_sharedQuadStateList, rootLayer, &occlusionTracker, rootLayer->hasDebugBorders(), forSurface); |
| 83 | |
| 84 | // Manually create the quad state for the gutter quads, as the root layer |
| 85 | // doesn't have any bounds and so can't generate this itself. |
| 86 | // FIXME: Make the gutter quads generated by the solid color layer (make it smarter about generating quads to fill unoccluded areas). |
| 87 | IntRect rootTargetRect = rootLayer->renderSurface()->contentRect(); |
| 88 | float opacity = 1; |
| 89 | bool opaque = true; |
| 90 | CCSharedQuadState* sharedQuadState = quadCuller.useSharedQuadState(CCSharedQuadState::create(rootLayer->drawTransform(), rootTargetRect, rootTargetRect, opacity, opaque)); |
| 91 | ASSERT(rootLayer->screenSpaceTransform().isInvertible()); |
| 92 | WebTransformationMatrix transformToLayerSpace = rootLayer->screenSpaceTransform().inverse(); |
| 93 | Vector<IntRect> fillRects = fillRegion.rects(); |
| 94 | for (size_t i = 0; i < fillRects.size(); ++i) { |
| 95 | // The root layer transform is composed of translations and scales only, no perspective, so mapping is sufficient. |
| 96 | IntRect layerRect = CCMathUtil::mapClippedRect(transformToLayerSpace, fillRects[i]); |
| 97 | // Skip the quad culler and just append the quads directly to avoid occlusion checks. |
| 98 | m_quadList.append(CCSolidColorDrawQuad::create(sharedQuadState, layerRect, screenBackgroundColor)); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | } |