Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: ui/cc/cc/CCRenderSurface.cpp

Issue 10701016: Initial import attempt, just to play with. Many things disabled/removed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/cc/cc/CCRenderSurface.h ('k') | ui/cc/cc/CCRenderSurfaceFilters.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27
28 #if USE(ACCELERATED_COMPOSITING)
29
30 #include "cc/CCRenderSurface.h"
31
32 #include "GraphicsContext3D.h"
33 #include "LayerRendererChromium.h"
34 #include "ManagedTexture.h"
35 #include "TextStream.h"
36 #include "cc/CCDamageTracker.h"
37 #include "cc/CCDebugBorderDrawQuad.h"
38 #include "cc/CCLayerImpl.h"
39 #include "cc/CCMathUtil.h"
40 #include "cc/CCQuadCuller.h"
41 #include "cc/CCRenderPassDrawQuad.h"
42 #include "cc/CCSharedQuadState.h"
43 #include <public/WebTransformationMatrix.h>
44 #include <wtf/text/CString.h>
45
46 using WebKit::WebTransformationMatrix;
47
48 namespace WebCore {
49
50 static const int debugSurfaceBorderWidth = 2;
51 static const int debugSurfaceBorderAlpha = 100;
52 static const int debugSurfaceBorderColorRed = 0;
53 static const int debugSurfaceBorderColorGreen = 0;
54 static const int debugSurfaceBorderColorBlue = 255;
55 static const int debugReplicaBorderColorRed = 160;
56 static const int debugReplicaBorderColorGreen = 0;
57 static const int debugReplicaBorderColorBlue = 255;
58
59 CCRenderSurface::CCRenderSurface(CCLayerImpl* owningLayer)
60 : m_owningLayer(owningLayer)
61 , m_surfacePropertyChanged(false)
62 , m_drawOpacity(1)
63 , m_drawOpacityIsAnimating(false)
64 , m_targetSurfaceTransformsAreAnimating(false)
65 , m_screenSpaceTransformsAreAnimating(false)
66 , m_nearestAncestorThatMovesPixels(0)
67 , m_targetRenderSurfaceLayerIndexHistory(0)
68 , m_currentLayerIndexHistory(0)
69 {
70 m_damageTracker = CCDamageTracker::create();
71 }
72
73 CCRenderSurface::~CCRenderSurface()
74 {
75 }
76
77 FloatRect CCRenderSurface::drawableContentRect() const
78 {
79 FloatRect localContentRect(-0.5 * m_contentRect.width(), -0.5 * m_contentRec t.height(),
80 m_contentRect.width(), m_contentRect.height());
81 FloatRect drawableContentRect = m_drawTransform.mapRect(localContentRect);
82 if (hasReplica())
83 drawableContentRect.unite(m_replicaDrawTransform.mapRect(localContentRec t));
84
85 return drawableContentRect;
86 }
87
88 bool CCRenderSurface::prepareContentsTexture(LayerRendererChromium* layerRendere r)
89 {
90 // FIXME: This method should be separated into two: one to reserve an
91 // existing surface, and one to create a new one. That way we will not
92 // need to pass null layerRenderer.
93 if (layerRenderer) {
94 TextureManager* textureManager = layerRenderer->implTextureManager();
95
96 if (!m_contentsTexture)
97 m_contentsTexture = ManagedTexture::create(textureManager);
98 }
99
100 if (!m_contentsTexture)
101 return false;
102
103 if (m_contentsTexture->isReserved())
104 return true;
105
106 if (!m_contentsTexture->reserve(m_contentRect.size(), GL_RGBA))
107 return false;
108
109 return true;
110 }
111
112 void CCRenderSurface::releaseContentsTexture()
113 {
114 if (!m_contentsTexture || !m_contentsTexture->isReserved())
115 return;
116 m_contentsTexture->unreserve();
117 }
118
119 bool CCRenderSurface::hasValidContentsTexture() const
120 {
121 return m_contentsTexture && m_contentsTexture->isReserved() && m_contentsTex ture->isValid(m_contentRect.size(), GL_RGBA);
122 }
123
124 bool CCRenderSurface::hasCachedContentsTexture() const
125 {
126 return m_contentsTexture && m_contentsTexture->isValid(m_contentRect.size(), GL_RGBA);
127 }
128
129 bool CCRenderSurface::prepareBackgroundTexture(LayerRendererChromium* layerRende rer)
130 {
131 TextureManager* textureManager = layerRenderer->implTextureManager();
132
133 if (!m_backgroundTexture)
134 m_backgroundTexture = ManagedTexture::create(textureManager);
135
136 if (m_backgroundTexture->isReserved())
137 return true;
138
139 if (!m_backgroundTexture->reserve(m_contentRect.size(), GL_RGBA))
140 return false;
141
142 return true;
143 }
144
145 void CCRenderSurface::releaseBackgroundTexture()
146 {
147 if (!m_backgroundTexture || !m_backgroundTexture->isReserved())
148 return;
149 m_backgroundTexture->unreserve();
150 }
151
152 bool CCRenderSurface::hasValidBackgroundTexture() const
153 {
154 return m_backgroundTexture && m_backgroundTexture->isReserved() && m_backgro undTexture->isValid(m_contentRect.size(), GL_RGBA);
155 }
156
157 String CCRenderSurface::name() const
158 {
159 return String::format("RenderSurface(id=%i,owner=%s)", m_owningLayer->id(), m_owningLayer->debugName().utf8().data());
160 }
161
162 static void writeIndent(TextStream& ts, int indent)
163 {
164 for (int i = 0; i != indent; ++i)
165 ts << " ";
166 }
167
168 void CCRenderSurface::dumpSurface(TextStream& ts, int indent) const
169 {
170 writeIndent(ts, indent);
171 ts << name() << "\n";
172
173 writeIndent(ts, indent+1);
174 ts << "contentRect: (" << m_contentRect.x() << ", " << m_contentRect.y() << ", " << m_contentRect.width() << ", " << m_contentRect.height() << "\n";
175
176 writeIndent(ts, indent+1);
177 ts << "drawTransform: ";
178 ts << m_drawTransform.m11() << ", " << m_drawTransform.m12() << ", " << m_dr awTransform.m13() << ", " << m_drawTransform.m14() << " // ";
179 ts << m_drawTransform.m21() << ", " << m_drawTransform.m22() << ", " << m_dr awTransform.m23() << ", " << m_drawTransform.m24() << " // ";
180 ts << m_drawTransform.m31() << ", " << m_drawTransform.m32() << ", " << m_dr awTransform.m33() << ", " << m_drawTransform.m34() << " // ";
181 ts << m_drawTransform.m41() << ", " << m_drawTransform.m42() << ", " << m_dr awTransform.m43() << ", " << m_drawTransform.m44() << "\n";
182
183 writeIndent(ts, indent+1);
184 ts << "damageRect is pos(" << m_damageTracker->currentDamageRect().x() << ", " << m_damageTracker->currentDamageRect().y() << "), ";
185 ts << "size(" << m_damageTracker->currentDamageRect().width() << "," << m_da mageTracker->currentDamageRect().height() << ")\n";
186 }
187
188 int CCRenderSurface::owningLayerId() const
189 {
190 return m_owningLayer ? m_owningLayer->id() : 0;
191 }
192
193 CCRenderSurface* CCRenderSurface::targetRenderSurface() const
194 {
195 CCLayerImpl* parent = m_owningLayer->parent();
196 if (!parent)
197 return 0;
198 return parent->targetRenderSurface();
199 }
200
201 bool CCRenderSurface::hasReplica() const
202 {
203 return m_owningLayer->replicaLayer();
204 }
205
206 bool CCRenderSurface::hasMask() const
207 {
208 return m_owningLayer->maskLayer();
209 }
210
211 bool CCRenderSurface::replicaHasMask() const
212 {
213 return hasReplica() && (m_owningLayer->maskLayer() || m_owningLayer->replica Layer()->maskLayer());
214 }
215
216 void CCRenderSurface::setClipRect(const IntRect& clipRect)
217 {
218 if (m_clipRect == clipRect)
219 return;
220
221 m_surfacePropertyChanged = true;
222 m_clipRect = clipRect;
223 }
224
225 bool CCRenderSurface::contentsChanged() const
226 {
227 return !m_damageTracker->currentDamageRect().isEmpty();
228 }
229
230 void CCRenderSurface::setContentRect(const IntRect& contentRect)
231 {
232 if (m_contentRect == contentRect)
233 return;
234
235 m_surfacePropertyChanged = true;
236 m_contentRect = contentRect;
237 }
238
239 bool CCRenderSurface::surfacePropertyChanged() const
240 {
241 // Surface property changes are tracked as follows:
242 //
243 // - m_surfacePropertyChanged is flagged when the clipRect or contentRect ch ange. As
244 // of now, these are the only two properties that can be affected by desce ndant layers.
245 //
246 // - all other property changes come from the owning layer (or some ancestor layer
247 // that propagates its change to the owning layer).
248 //
249 ASSERT(m_owningLayer);
250 return m_surfacePropertyChanged || m_owningLayer->layerPropertyChanged();
251 }
252
253 bool CCRenderSurface::surfacePropertyChangedOnlyFromDescendant() const
254 {
255 return m_surfacePropertyChanged && !m_owningLayer->layerPropertyChanged();
256 }
257
258 PassOwnPtr<CCSharedQuadState> CCRenderSurface::createSharedQuadState() const
259 {
260 bool isOpaque = false;
261 return CCSharedQuadState::create(originTransform(), drawTransform(), content Rect(), m_scissorRect, drawOpacity(), isOpaque);
262 }
263
264 PassOwnPtr<CCSharedQuadState> CCRenderSurface::createReplicaSharedQuadState() co nst
265 {
266 bool isOpaque = false;
267 return CCSharedQuadState::create(replicaOriginTransform(), replicaDrawTransf orm(), contentRect(), m_scissorRect, drawOpacity(), isOpaque);
268 }
269
270 FloatRect CCRenderSurface::computeRootScissorRectInCurrentSurface(const FloatRec t& rootScissorRect) const
271 {
272 WebTransformationMatrix inverseScreenSpaceTransform = m_screenSpaceTransform .inverse();
273 return CCMathUtil::projectClippedRect(inverseScreenSpaceTransform, rootSciss orRect);
274 }
275
276 void CCRenderSurface::appendQuads(CCQuadCuller& quadList, CCSharedQuadState* sha redQuadState, bool forReplica, const CCRenderPass* renderPass)
277 {
278 ASSERT(!forReplica || hasReplica());
279
280 if (m_owningLayer->hasDebugBorders()) {
281 int red = forReplica ? debugReplicaBorderColorRed : debugSurfaceBorderCo lorRed;
282 int green = forReplica ? debugReplicaBorderColorGreen : debugSurfaceBor derColorGreen;
283 int blue = forReplica ? debugReplicaBorderColorBlue : debugSurfaceBorder ColorBlue;
284 SkColor color = SkColorSetARGB(debugSurfaceBorderAlpha, red, green, blue );
285 quadList.appendSurface(CCDebugBorderDrawQuad::create(sharedQuadState, co ntentRect(), color, debugSurfaceBorderWidth));
286 }
287
288 // FIXME: By using the same RenderSurface for both the content and its refle ction,
289 // it's currently not possible to apply a separate mask to the reflection la yer
290 // or correctly handle opacity in reflections (opacity must be applied after drawing
291 // both the layer and its reflection). The solution is to introduce yet anot her RenderSurface
292 // to draw the layer and its reflection in. For now we only apply a separate reflection
293 // mask if the contents don't have a mask of their own.
294 CCLayerImpl* maskLayer = m_owningLayer->maskLayer();
295 if (maskLayer && (!maskLayer->drawsContent() || maskLayer->bounds().isEmpty( )))
296 maskLayer = 0;
297
298 if (!maskLayer && forReplica) {
299 maskLayer = m_owningLayer->replicaLayer()->maskLayer();
300 if (maskLayer && (!maskLayer->drawsContent() || maskLayer->bounds().isEm pty()))
301 maskLayer = 0;
302 }
303
304 int maskTextureId = maskLayer ? maskLayer->contentsTextureId() : 0;
305
306 quadList.appendSurface(CCRenderPassDrawQuad::create(sharedQuadState, content Rect(), renderPass, forReplica, filters(), backgroundFilters(), maskTextureId));
307 }
308
309 }
310 #endif // USE(ACCELERATED_COMPOSITING)
OLDNEW
« no previous file with comments | « ui/cc/cc/CCRenderSurface.h ('k') | ui/cc/cc/CCRenderSurfaceFilters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698