1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "CCDelegatedRendererLayerImpl.h"
#include "CCAppendQuadsData.h"
#include "CCQuadSink.h"
#include "CCMathUtil.h"
#include "CCRenderPassDrawQuad.h"
#include "CCRenderPassSink.h"
namespace cc {
CCDelegatedRendererLayerImpl::CCDelegatedRendererLayerImpl(int id)
: CCLayerImpl(id)
{
}
CCDelegatedRendererLayerImpl::~CCDelegatedRendererLayerImpl()
{
clearRenderPasses();
}
bool CCDelegatedRendererLayerImpl::descendantDrawsContent()
{
// FIXME: This could possibly return false even though there are some
// quads present as they could all be from a single layer (or set of
// layers without children). If this happens, then make a test that
// ensures the opacity is being changed on quads in the root RenderPass
// when this layer doesn't own a RenderSurface.
return !m_renderPassesInDrawOrder.isEmpty();
}
bool CCDelegatedRendererLayerImpl::hasContributingDelegatedRenderPasses() const
{
// The root RenderPass for the layer is merged with its target
// RenderPass in each frame. So we only have extra RenderPasses
// to merge when we have a non-root RenderPass present.
return m_renderPassesInDrawOrder.size() > 1;
}
void CCDelegatedRendererLayerImpl::setRenderPasses(ScopedPtrVector<CCRenderPass>& renderPassesInDrawOrder)
{
FloatRect oldRootDamage;
if (!m_renderPassesInDrawOrder.isEmpty())
oldRootDamage = m_renderPassesInDrawOrder.last()->damageRect();
clearRenderPasses();
for (size_t i = 0; i < renderPassesInDrawOrder.size(); ++i) {
m_renderPassesIndexById.insert(std::pair<CCRenderPass::Id, int>(renderPassesInDrawOrder[i]->id(), i));
m_renderPassesInDrawOrder.append(renderPassesInDrawOrder.take(i));
}
renderPassesInDrawOrder.clear();
if (!m_renderPassesInDrawOrder.isEmpty()) {
FloatRect newRootDamage = m_renderPassesInDrawOrder.last()->damageRect();
m_renderPassesInDrawOrder.last()->setDamageRect(unionRect(oldRootDamage, newRootDamage));
}
}
void CCDelegatedRendererLayerImpl::clearRenderPasses()
{
// FIXME: Release the resources back to the nested compositor.
m_renderPassesIndexById.clear();
m_renderPassesInDrawOrder.clear();
}
void CCDelegatedRendererLayerImpl::didLoseContext()
{
clearRenderPasses();
}
static inline int indexToId(int index) { return index + 1; }
static inline int idToIndex(int id) { return id - 1; }
CCRenderPass::Id CCDelegatedRendererLayerImpl::firstContributingRenderPassId() const
{
return CCRenderPass::Id(id(), indexToId(0));
}
CCRenderPass::Id CCDelegatedRendererLayerImpl::nextContributingRenderPassId(CCRenderPass::Id previous) const
{
return CCRenderPass::Id(previous.layerId, previous.index + 1);
}
CCRenderPass::Id CCDelegatedRendererLayerImpl::convertDelegatedRenderPassId(CCRenderPass::Id delegatedRenderPassId) const
{
base::hash_map<CCRenderPass::Id, int>::const_iterator it = m_renderPassesIndexById.find(delegatedRenderPassId);
ASSERT(it != m_renderPassesIndexById.end());
unsigned delegatedRenderPassIndex = it->second;
return CCRenderPass::Id(id(), indexToId(delegatedRenderPassIndex));
}
void CCDelegatedRendererLayerImpl::appendContributingRenderPasses(CCRenderPassSink& renderPassSink)
{
ASSERT(hasContributingDelegatedRenderPasses());
for (size_t i = 0; i < m_renderPassesInDrawOrder.size() - 1; ++i) {
CCRenderPass::Id outputRenderPassId = convertDelegatedRenderPassId(m_renderPassesInDrawOrder[i]->id());
// Don't clash with the RenderPass we generate if we own a RenderSurface.
ASSERT(outputRenderPassId.index > 0);
renderPassSink.appendRenderPass(m_renderPassesInDrawOrder[i]->copy(outputRenderPassId));
}
}
void CCDelegatedRendererLayerImpl::appendQuads(CCQuadSink& quadSink, CCAppendQuadsData& appendQuadsData)
{
if (m_renderPassesInDrawOrder.isEmpty())
return;
CCRenderPass::Id targetRenderPassId = appendQuadsData.renderPassId;
// If the index of the renderPassId is 0, then it is a renderPass generated for a layer
// in this compositor, not the delegated renderer. Then we want to merge our root renderPass with
// the target renderPass. Otherwise, it is some renderPass which we added from the delegated
// renderer.
bool shouldMergeRootRenderPassWithTarget = !targetRenderPassId.index;
if (shouldMergeRootRenderPassWithTarget) {
// Verify that the renderPass we are appending to is created our renderTarget.
ASSERT(targetRenderPassId.layerId == renderTarget()->id());
CCRenderPass* rootDelegatedRenderPass = m_renderPassesInDrawOrder.last();
appendRenderPassQuads(quadSink, appendQuadsData, rootDelegatedRenderPass);
} else {
// Verify that the renderPass we are appending to was created by us.
ASSERT(targetRenderPassId.layerId == id());
int renderPassIndex = idToIndex(targetRenderPassId.index);
CCRenderPass* delegatedRenderPass = m_renderPassesInDrawOrder[renderPassIndex];
appendRenderPassQuads(quadSink, appendQuadsData, delegatedRenderPass);
}
}
void CCDelegatedRendererLayerImpl::appendRenderPassQuads(CCQuadSink& quadSink, CCAppendQuadsData& appendQuadsData, CCRenderPass* delegatedRenderPass) const
{
const CCSharedQuadState* currentSharedQuadState = 0;
CCSharedQuadState* copiedSharedQuadState = 0;
for (size_t i = 0; i < delegatedRenderPass->quadList().size(); ++i) {
CCDrawQuad* quad = delegatedRenderPass->quadList()[i];
if (quad->sharedQuadState() != currentSharedQuadState) {
currentSharedQuadState = quad->sharedQuadState();
copiedSharedQuadState = quadSink.useSharedQuadState(currentSharedQuadState->copy());
bool targetIsFromDelegatedRendererLayer = appendQuadsData.renderPassId.layerId == id();
if (!targetIsFromDelegatedRendererLayer) {
// Should be the root render pass.
ASSERT(delegatedRenderPass == m_renderPassesInDrawOrder.last());
// This layer must be drawing to a renderTarget other than itself.
ASSERT(renderTarget() != this);
copiedSharedQuadState->clippedRectInTarget = CCMathUtil::mapClippedRect(drawTransform(), copiedSharedQuadState->clippedRectInTarget);
copiedSharedQuadState->quadTransform = copiedSharedQuadState->quadTransform * drawTransform();
copiedSharedQuadState->opacity *= drawOpacity();
}
}
ASSERT(copiedSharedQuadState);
scoped_ptr<CCDrawQuad> copyQuad;
if (quad->material() != CCDrawQuad::RenderPass)
copyQuad = quad->copy(copiedSharedQuadState);
else {
CCRenderPass::Id contributingDelegatedRenderPassId = CCRenderPassDrawQuad::materialCast(quad)->renderPassId();
CCRenderPass::Id contributingRenderPassId = convertDelegatedRenderPassId(contributingDelegatedRenderPassId);
ASSERT(contributingRenderPassId != appendQuadsData.renderPassId);
copyQuad = CCRenderPassDrawQuad::materialCast(quad)->copy(copiedSharedQuadState, contributingRenderPassId).PassAs<CCDrawQuad>();
}
ASSERT(copyQuad.get());
quadSink.append(copyQuad.Pass(), appendQuadsData);
}
}
const char* CCDelegatedRendererLayerImpl::layerTypeAsString() const
{
return "DelegatedRendererLayer";
}
}
|