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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
// 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 "cc/delegated_renderer_layer_impl.h"
#include "cc/append_quads_data.h"
#include "cc/math_util.h"
#include "cc/quad_sink.h"
#include "cc/render_pass_draw_quad.h"
#include "cc/render_pass_sink.h"
namespace cc {
DelegatedRendererLayerImpl::DelegatedRendererLayerImpl(LayerTreeImpl* treeImpl, int id)
: LayerImpl(treeImpl, id)
{
}
DelegatedRendererLayerImpl::~DelegatedRendererLayerImpl()
{
clearRenderPasses();
}
bool DelegatedRendererLayerImpl::hasDelegatedContent() const
{
return !m_renderPassesInDrawOrder.empty();
}
bool DelegatedRendererLayerImpl::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 DelegatedRendererLayerImpl::setRenderPasses(ScopedPtrVector<RenderPass>& renderPassesInDrawOrder)
{
gfx::RectF oldRootDamage;
if (!m_renderPassesInDrawOrder.empty())
oldRootDamage = m_renderPassesInDrawOrder.back()->damage_rect;
clearRenderPasses();
for (size_t i = 0; i < renderPassesInDrawOrder.size(); ++i) {
m_renderPassesIndexById.insert(std::pair<RenderPass::Id, int>(renderPassesInDrawOrder[i]->id, i));
m_renderPassesInDrawOrder.push_back(renderPassesInDrawOrder.take(renderPassesInDrawOrder.begin() + i));
}
renderPassesInDrawOrder.clear();
if (!m_renderPassesInDrawOrder.empty())
m_renderPassesInDrawOrder.back()->damage_rect.Union(oldRootDamage);
}
void DelegatedRendererLayerImpl::clearRenderPasses()
{
// FIXME: Release the resources back to the nested compositor.
m_renderPassesIndexById.clear();
m_renderPassesInDrawOrder.clear();
}
void DelegatedRendererLayerImpl::didLoseOutputSurface()
{
clearRenderPasses();
}
static inline int indexToId(int index) { return index + 1; }
static inline int idToIndex(int id) { return id - 1; }
RenderPass::Id DelegatedRendererLayerImpl::firstContributingRenderPassId() const
{
return RenderPass::Id(id(), indexToId(0));
}
RenderPass::Id DelegatedRendererLayerImpl::nextContributingRenderPassId(RenderPass::Id previous) const
{
return RenderPass::Id(previous.layer_id, previous.index + 1);
}
RenderPass::Id DelegatedRendererLayerImpl::convertDelegatedRenderPassId(RenderPass::Id delegatedRenderPassId) const
{
base::hash_map<RenderPass::Id, int>::const_iterator it = m_renderPassesIndexById.find(delegatedRenderPassId);
DCHECK(it != m_renderPassesIndexById.end());
unsigned delegatedRenderPassIndex = it->second;
return RenderPass::Id(id(), indexToId(delegatedRenderPassIndex));
}
void DelegatedRendererLayerImpl::appendContributingRenderPasses(RenderPassSink& renderPassSink)
{
DCHECK(hasContributingDelegatedRenderPasses());
for (size_t i = 0; i < m_renderPassesInDrawOrder.size() - 1; ++i) {
RenderPass::Id outputRenderPassId = convertDelegatedRenderPassId(m_renderPassesInDrawOrder[i]->id);
// Don't clash with the RenderPass we generate if we own a RenderSurfaceImpl.
DCHECK(outputRenderPassId.index > 0);
renderPassSink.appendRenderPass(m_renderPassesInDrawOrder[i]->Copy(outputRenderPassId));
}
}
void DelegatedRendererLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuadsData)
{
if (m_renderPassesInDrawOrder.empty())
return;
RenderPass::Id targetRenderPassId = appendQuadsData.renderPassId;
const RenderPass* rootDelegatedRenderPass = m_renderPassesInDrawOrder.back();
DCHECK(rootDelegatedRenderPass->output_rect.origin().IsOrigin());
gfx::Size frameSize = rootDelegatedRenderPass->output_rect.size();
// 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.
DCHECK(targetRenderPassId.layer_id == renderTarget()->id());
appendRenderPassQuads(quadSink, appendQuadsData, rootDelegatedRenderPass, frameSize);
} else {
// Verify that the renderPass we are appending to was created by us.
DCHECK(targetRenderPassId.layer_id == id());
int renderPassIndex = idToIndex(targetRenderPassId.index);
const RenderPass* delegatedRenderPass = m_renderPassesInDrawOrder[renderPassIndex];
appendRenderPassQuads(quadSink, appendQuadsData, delegatedRenderPass, frameSize);
}
}
void DelegatedRendererLayerImpl::appendRenderPassQuads(QuadSink& quadSink, AppendQuadsData& appendQuadsData, const RenderPass* delegatedRenderPass, gfx::Size frameSize) const
{
const SharedQuadState* currentSharedQuadState = 0;
SharedQuadState* copiedSharedQuadState = 0;
for (size_t i = 0; i < delegatedRenderPass->quad_list.size(); ++i) {
const DrawQuad* quad = delegatedRenderPass->quad_list[i];
if (quad->shared_quad_state != currentSharedQuadState) {
currentSharedQuadState = quad->shared_quad_state;
copiedSharedQuadState = quadSink.useSharedQuadState(currentSharedQuadState->Copy());
bool isRootDelegatedRenderPass = delegatedRenderPass == m_renderPassesInDrawOrder.back();
if (isRootDelegatedRenderPass) {
// Don't allow areas inside the bounds that are empty.
DCHECK(m_displaySize.IsEmpty() || gfx::Rect(m_displaySize).Contains(gfx::Rect(bounds())));
gfx::Size displaySize = m_displaySize.IsEmpty() ? bounds() : m_displaySize;
gfx::Transform delegatedFrameToLayerSpaceTransform;
delegatedFrameToLayerSpaceTransform.Scale(
static_cast<double>(displaySize.width()) / frameSize.width(),
static_cast<double>(displaySize.height()) / frameSize.height());
copiedSharedQuadState->content_to_target_transform = drawTransform() * delegatedFrameToLayerSpaceTransform * copiedSharedQuadState->content_to_target_transform;
if (renderTarget() == this) {
DCHECK(!isClipped());
DCHECK(renderSurface());
copiedSharedQuadState->clip_rect = MathUtil::mapClippedRect(
drawTransform() * delegatedFrameToLayerSpaceTransform,
copiedSharedQuadState->clip_rect);
} else {
gfx::Rect clip_rect = drawableContentRect();
if (copiedSharedQuadState->is_clipped) {
clip_rect.Intersect(MathUtil::mapClippedRect(
drawTransform() * delegatedFrameToLayerSpaceTransform,
copiedSharedQuadState->clip_rect));
}
copiedSharedQuadState->clip_rect = clip_rect;
copiedSharedQuadState->is_clipped = true;
}
copiedSharedQuadState->opacity *= drawOpacity();
}
}
DCHECK(copiedSharedQuadState);
scoped_ptr<DrawQuad> copyQuad;
if (quad->material != DrawQuad::RENDER_PASS)
copyQuad = quad->Copy(copiedSharedQuadState);
else {
RenderPass::Id contributingDelegatedRenderPassId = RenderPassDrawQuad::MaterialCast(quad)->render_pass_id;
RenderPass::Id contributingRenderPassId = convertDelegatedRenderPassId(contributingDelegatedRenderPassId);
DCHECK(contributingRenderPassId != appendQuadsData.renderPassId);
copyQuad = RenderPassDrawQuad::MaterialCast(quad)->Copy(copiedSharedQuadState, contributingRenderPassId).PassAs<DrawQuad>();
}
DCHECK(copyQuad.get());
quadSink.append(copyQuad.Pass(), appendQuadsData);
}
}
const char* DelegatedRendererLayerImpl::layerTypeAsString() const
{
return "DelegatedRendererLayer";
}
} // namespace cc
|