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