WebKit merge 128969:128981
[chromium-blink-merge.git] / cc / CCRenderPass.cpp
blob0d98a3af03f52ffd8d4c24ae269782d035fc7fe2
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.
5 #include "config.h"
7 #include "CCRenderPass.h"
9 #include "CCLayerImpl.h"
10 #include "CCMathUtil.h"
11 #include "CCOcclusionTracker.h"
12 #include "CCQuadCuller.h"
13 #include "CCSharedQuadState.h"
14 #include "CCSolidColorDrawQuad.h"
16 using WebKit::WebTransformationMatrix;
18 namespace cc {
20 PassOwnPtr<CCRenderPass> CCRenderPass::create(Id id, IntRect outputRect, const WebKit::WebTransformationMatrix& transformToRootTarget)
22 return adoptPtr(new CCRenderPass(id, outputRect, transformToRootTarget));
25 CCRenderPass::CCRenderPass(Id 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)
32 ASSERT(id.layerId > 0);
33 ASSERT(id.index >= 0);
36 PassOwnPtr<CCRenderPass> CCRenderPass::copy(Id newId) const
38 ASSERT(newId != m_id);
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();
49 void CCRenderPass::appendQuadsForLayer(CCLayerImpl* layer, CCOcclusionTrackerImpl* occlusionTracker, CCAppendQuadsData& appendQuadsData)
51 const bool forSurface = false;
52 CCQuadCuller quadCuller(m_quadList, m_sharedQuadStateList, layer, occlusionTracker, layer->hasDebugBorders(), forSurface);
54 layer->appendQuads(quadCuller, appendQuadsData);
57 void CCRenderPass::appendQuadsForRenderSurfaceLayer(CCLayerImpl* layer, const CCRenderPass* contributingRenderPass, CCOcclusionTrackerImpl* occlusionTracker, CCAppendQuadsData& appendQuadsData)
59 const bool forSurface = true;
60 CCQuadCuller quadCuller(m_quadList, m_sharedQuadStateList, layer, occlusionTracker, layer->hasDebugBorders(), forSurface);
62 bool isReplica = false;
63 layer->renderSurface()->appendQuads(quadCuller, appendQuadsData, isReplica, contributingRenderPass->id());
65 // Add replica after the surface so that it appears below the surface.
66 if (layer->hasReplica()) {
67 isReplica = true;
68 layer->renderSurface()->appendQuads(quadCuller, appendQuadsData, isReplica, contributingRenderPass->id());
72 void CCRenderPass::appendQuadsToFillScreen(CCLayerImpl* rootLayer, SkColor screenBackgroundColor, const CCOcclusionTrackerImpl& occlusionTracker)
74 if (!rootLayer || !screenBackgroundColor)
75 return;
77 Region fillRegion = occlusionTracker.computeVisibleRegionInScreen();
78 if (fillRegion.isEmpty())
79 return;
81 bool forSurface = false;
82 CCQuadCuller quadCuller(m_quadList, m_sharedQuadStateList, rootLayer, &occlusionTracker, rootLayer->hasDebugBorders(), forSurface);
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<WebCore::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, cc::IntRect(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));