blob: 9990f2e3ee36ab21f080ea12bdb83c6525e29762 [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// 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
16using WebKit::WebTransformationMatrix;
17
18namespace WebCore {
19
20PassOwnPtr<CCRenderPass> CCRenderPass::create(int id, IntRect outputRect, const WebKit::WebTransformationMatrix& transformToRootTarget)
21{
22 return adoptPtr(new CCRenderPass(id, outputRect, transformToRootTarget));
23}
24
25CCRenderPass::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]89228202012-08-29 03:20:3035void CCRenderPass::appendQuadsForLayer(CCLayerImpl* layer, CCOcclusionTrackerImpl* occlusionTracker, CCAppendQuadsData& appendQuadsData)
[email protected]94f206c12012-08-25 00:09:1436{
37 const bool forSurface = false;
38 CCQuadCuller quadCuller(m_quadList, m_sharedQuadStateList, layer, occlusionTracker, layer->hasDebugBorders(), forSurface);
39
[email protected]89228202012-08-29 03:20:3040 layer->appendQuads(quadCuller, appendQuadsData);
[email protected]94f206c12012-08-25 00:09:1441}
42
[email protected]89228202012-08-29 03:20:3043void CCRenderPass::appendQuadsForRenderSurfaceLayer(CCLayerImpl* layer, const CCRenderPass* contributingRenderPass, CCOcclusionTrackerImpl* occlusionTracker, CCAppendQuadsData& appendQuadsData)
[email protected]94f206c12012-08-25 00:09:1444{
45 const bool forSurface = true;
46 CCQuadCuller quadCuller(m_quadList, m_sharedQuadStateList, layer, occlusionTracker, layer->hasDebugBorders(), forSurface);
47
48 bool isReplica = false;
[email protected]89228202012-08-29 03:20:3049 layer->renderSurface()->appendQuads(quadCuller, appendQuadsData, isReplica, contributingRenderPass->id());
[email protected]94f206c12012-08-25 00:09:1450
51 // Add replica after the surface so that it appears below the surface.
52 if (layer->hasReplica()) {
53 isReplica = true;
[email protected]89228202012-08-29 03:20:3054 layer->renderSurface()->appendQuads(quadCuller, appendQuadsData, isReplica, contributingRenderPass->id());
[email protected]94f206c12012-08-25 00:09:1455 }
[email protected]94f206c12012-08-25 00:09:1456}
57
58void 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}