[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 | |
| 20 | PassOwnPtr<CCRenderPass> CCRenderPass::create(int id, IntRect outputRect, const WebKit::WebTransformationMatrix& transformToRootTarget) |
| 21 | { |
| 22 | return adoptPtr(new CCRenderPass(id, outputRect, transformToRootTarget)); |
| 23 | } |
| 24 | |
| 25 | CCRenderPass::CCRenderPass(int id, IntRect outputRect, const WebKit::WebTransformationMatrix& transformToRootTarget) |
| 26 | : m_id(id) |
| 27 | , m_transformToRootTarget(transformToRootTarget) |
| 28 | , m_outputRect(outputRect) |
| 29 | , m_hasTransparentBackground(true) |
| 30 | , m_hasOcclusionFromOutsideTargetSurface(false) |
| 31 | { |
| 32 | ASSERT(id > 0); |
| 33 | } |
| 34 | |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame^] | 35 | void CCRenderPass::appendQuadsForLayer(CCLayerImpl* layer, CCOcclusionTrackerImpl* occlusionTracker, CCAppendQuadsData& appendQuadsData) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 36 | { |
| 37 | const bool forSurface = false; |
| 38 | CCQuadCuller quadCuller(m_quadList, m_sharedQuadStateList, layer, occlusionTracker, layer->hasDebugBorders(), forSurface); |
| 39 | |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame^] | 40 | layer->appendQuads(quadCuller, appendQuadsData); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 41 | } |
| 42 | |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame^] | 43 | void CCRenderPass::appendQuadsForRenderSurfaceLayer(CCLayerImpl* layer, const CCRenderPass* contributingRenderPass, CCOcclusionTrackerImpl* occlusionTracker, CCAppendQuadsData& appendQuadsData) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 44 | { |
| 45 | const bool forSurface = true; |
| 46 | CCQuadCuller quadCuller(m_quadList, m_sharedQuadStateList, layer, occlusionTracker, layer->hasDebugBorders(), forSurface); |
| 47 | |
| 48 | bool isReplica = false; |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame^] | 49 | layer->renderSurface()->appendQuads(quadCuller, appendQuadsData, isReplica, contributingRenderPass->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 50 | |
| 51 | // Add replica after the surface so that it appears below the surface. |
| 52 | if (layer->hasReplica()) { |
| 53 | isReplica = true; |
[email protected] | 8922820 | 2012-08-29 03:20:30 | [diff] [blame^] | 54 | layer->renderSurface()->appendQuads(quadCuller, appendQuadsData, isReplica, contributingRenderPass->id()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 55 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void CCRenderPass::appendQuadsToFillScreen(CCLayerImpl* rootLayer, SkColor screenBackgroundColor, const CCOcclusionTrackerImpl& occlusionTracker) |
| 59 | { |
| 60 | if (!rootLayer || !screenBackgroundColor) |
| 61 | return; |
| 62 | |
| 63 | Region fillRegion = occlusionTracker.computeVisibleRegionInScreen(); |
| 64 | if (fillRegion.isEmpty()) |
| 65 | return; |
| 66 | |
| 67 | bool forSurface = false; |
| 68 | CCQuadCuller quadCuller(m_quadList, m_sharedQuadStateList, rootLayer, &occlusionTracker, rootLayer->hasDebugBorders(), forSurface); |
| 69 | |
| 70 | // Manually create the quad state for the gutter quads, as the root layer |
| 71 | // doesn't have any bounds and so can't generate this itself. |
| 72 | // FIXME: Make the gutter quads generated by the solid color layer (make it smarter about generating quads to fill unoccluded areas). |
| 73 | IntRect rootTargetRect = rootLayer->renderSurface()->contentRect(); |
| 74 | float opacity = 1; |
| 75 | bool opaque = true; |
| 76 | CCSharedQuadState* sharedQuadState = quadCuller.useSharedQuadState(CCSharedQuadState::create(rootLayer->drawTransform(), rootTargetRect, rootTargetRect, opacity, opaque)); |
| 77 | ASSERT(rootLayer->screenSpaceTransform().isInvertible()); |
| 78 | WebTransformationMatrix transformToLayerSpace = rootLayer->screenSpaceTransform().inverse(); |
| 79 | Vector<IntRect> fillRects = fillRegion.rects(); |
| 80 | for (size_t i = 0; i < fillRects.size(); ++i) { |
| 81 | // The root layer transform is composed of translations and scales only, no perspective, so mapping is sufficient. |
| 82 | IntRect layerRect = CCMathUtil::mapClippedRect(transformToLayerSpace, fillRects[i]); |
| 83 | // Skip the quad culler and just append the quads directly to avoid occlusion checks. |
| 84 | m_quadList.append(CCSolidColorDrawQuad::create(sharedQuadState, layerRect, screenBackgroundColor)); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | } |