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