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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#if USE(ACCELERATED_COMPOSITING)
#include "cc/CCLayerImpl.h"
#include "GraphicsContext3D.h"
#include "LayerChromium.h" // FIXME: temporary and bad
#include "LayerRendererChromium.h"
#include "RenderSurfaceChromium.h"
#include <wtf/text/WTFString.h>
namespace {
void toGLMatrix(float* flattened, const WebCore::TransformationMatrix& m)
{
flattened[0] = m.m11();
flattened[1] = m.m12();
flattened[2] = m.m13();
flattened[3] = m.m14();
flattened[4] = m.m21();
flattened[5] = m.m22();
flattened[6] = m.m23();
flattened[7] = m.m24();
flattened[8] = m.m31();
flattened[9] = m.m32();
flattened[10] = m.m33();
flattened[11] = m.m34();
flattened[12] = m.m41();
flattened[13] = m.m42();
flattened[14] = m.m43();
flattened[15] = m.m44();
}
}
namespace WebCore {
CCLayerImpl::CCLayerImpl(LayerChromium* owner)
: m_owner(owner)
, m_anchorPoint(0.5, 0.5)
, m_anchorPointZ(0)
, m_doubleSided(true)
, m_masksToBounds(false)
, m_opacity(1.0)
, m_preserves3D(false)
#ifndef NDEBUG
, m_debugID(owner->debugID())
#endif
, m_targetRenderSurface(0)
, m_drawDepth(0)
, m_drawOpacity(0)
, m_debugBorderColor(0, 0, 0, 0)
, m_debugBorderWidth(0)
, m_renderSurface(0)
, m_layerRenderer(0)
{
}
CCLayerImpl::~CCLayerImpl()
{
}
// These are pseudo-structural hacks until we get real tree syncing up in this piece.
CCLayerImpl* CCLayerImpl::superlayer() const
{
return m_owner->superlayer() ? m_owner->superlayer()->ccLayerImpl() : 0;
}
CCLayerImpl* CCLayerImpl::maskLayer() const
{
return m_owner->maskLayer() ? m_owner->maskLayer()->ccLayerImpl() : 0;
}
CCLayerImpl* CCLayerImpl::replicaLayer() const
{
return m_owner->replicaLayer() ? m_owner->replicaLayer()->ccLayerImpl() : 0;
}
void CCLayerImpl::setLayerRenderer(LayerRendererChromium* renderer)
{
m_layerRenderer = renderer;
}
RenderSurfaceChromium* CCLayerImpl::createRenderSurface()
{
m_renderSurface = new RenderSurfaceChromium(this);
return m_renderSurface.get();
}
bool CCLayerImpl::descendantsDrawsContent()
{
const Vector<RefPtr<LayerChromium> >& sublayers = m_owner->getSublayers();
for (size_t i = 0; i < sublayers.size(); ++i) {
sublayers[i]->createCCLayerImplIfNeeded();
if (sublayers[i]->ccLayerImpl()->drawsContent() || sublayers[i]->ccLayerImpl()->descendantsDrawsContent())
return true;
}
return false;
}
// These belong on CCLayerImpl, but should be overridden by each type and not defer to the LayerChromium subtypes.
bool CCLayerImpl::drawsContent() const
{
return m_owner->drawsContent();
}
void CCLayerImpl::draw()
{
return m_owner->draw();
}
void CCLayerImpl::updateCompositorResources()
{
return m_owner->updateCompositorResources();
}
void CCLayerImpl::unreserveContentsTexture()
{
m_owner->unreserveContentsTexture();
}
void CCLayerImpl::bindContentsTexture()
{
m_owner->bindContentsTexture();
}
void CCLayerImpl::cleanupResources()
{
if (renderSurface())
renderSurface()->cleanupResources();
}
const IntRect CCLayerImpl::getDrawRect() const
{
// Form the matrix used by the shader to map the corners of the layer's
// bounds into the view space.
FloatRect layerRect(-0.5 * bounds().width(), -0.5 * bounds().height(), bounds().width(), bounds().height());
IntRect mappedRect = enclosingIntRect(drawTransform().mapRect(layerRect));
return mappedRect;
}
void CCLayerImpl::drawDebugBorder()
{
static float glMatrix[16];
if (!debugBorderColor().alpha())
return;
ASSERT(layerRenderer());
const LayerChromium::BorderProgram* program = layerRenderer()->borderProgram();
ASSERT(program && program->initialized());
layerRenderer()->useShader(program->program());
TransformationMatrix renderMatrix = drawTransform();
renderMatrix.scale3d(bounds().width(), bounds().height(), 1);
toGLMatrix(&glMatrix[0], layerRenderer()->projectionMatrix() * renderMatrix);
GraphicsContext3D* context = layerRenderer()->context();
GLC(context, context->uniformMatrix4fv(program->vertexShader().matrixLocation(), false, &glMatrix[0], 1));
GLC(context, context->uniform4f(program->fragmentShader().colorLocation(), debugBorderColor().red() / 255.0, debugBorderColor().green() / 255.0, debugBorderColor().blue() / 255.0, 1));
GLC(context, context->lineWidth(debugBorderWidth()));
// The indices for the line are stored in the same array as the triangle indices.
GLC(context, context->drawElements(GraphicsContext3D::LINE_LOOP, 4, GraphicsContext3D::UNSIGNED_SHORT, 6 * sizeof(unsigned short)));
}
void CCLayerImpl::writeIndent(TextStream& ts, int indent)
{
for (int i = 0; i != indent; ++i)
ts << " ";
}
void CCLayerImpl::dumpLayerProperties(TextStream& ts, int indent) const
{
writeIndent(ts, indent);
ts << "bounds: " << bounds().width() << ", " << bounds().height() << "\n";
if (m_targetRenderSurface) {
writeIndent(ts, indent);
ts << "targetRenderSurface: " << m_targetRenderSurface->name() << "\n";
}
writeIndent(ts, indent);
ts << "drawTransform: ";
ts << m_drawTransform.m11() << ", " << m_drawTransform.m12() << ", " << m_drawTransform.m13() << ", " << m_drawTransform.m14() << ", ";
ts << m_drawTransform.m21() << ", " << m_drawTransform.m22() << ", " << m_drawTransform.m23() << ", " << m_drawTransform.m24() << ", ";
ts << m_drawTransform.m31() << ", " << m_drawTransform.m32() << ", " << m_drawTransform.m33() << ", " << m_drawTransform.m34() << ", ";
ts << m_drawTransform.m41() << ", " << m_drawTransform.m42() << ", " << m_drawTransform.m43() << ", " << m_drawTransform.m44() << "\n";
}
}
#endif // USE(ACCELERATED_COMPOSITING)
|