OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "CCRendererGL.h" | 7 #include "CCRendererGL.h" |
8 | 8 |
9 #include "CCDamageTracker.h" | 9 #include "CCDamageTracker.h" |
10 #include "CCLayerQuad.h" | 10 #include "CCLayerQuad.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 { | 52 { |
53 #if OS(DARWIN) | 53 #if OS(DARWIN) |
54 return true; | 54 return true; |
55 #else | 55 #else |
56 return false; | 56 return false; |
57 #endif | 57 #endif |
58 } | 58 } |
59 | 59 |
60 } // anonymous namespace | 60 } // anonymous namespace |
61 | 61 |
62 scoped_ptr<CCRendererGL> CCRendererGL::create(CCRendererClient* client, CCResour
ceProvider* resourceProvider) | 62 scoped_ptr<GLRenderer> GLRenderer::create(RendererClient* client, ResourceProvid
er* resourceProvider) |
63 { | 63 { |
64 scoped_ptr<CCRendererGL> renderer(make_scoped_ptr(new CCRendererGL(client, r
esourceProvider))); | 64 scoped_ptr<GLRenderer> renderer(make_scoped_ptr(new GLRenderer(client, resou
rceProvider))); |
65 if (!renderer->initialize()) | 65 if (!renderer->initialize()) |
66 return scoped_ptr<CCRendererGL>(); | 66 return scoped_ptr<GLRenderer>(); |
67 | 67 |
68 return renderer.Pass(); | 68 return renderer.Pass(); |
69 } | 69 } |
70 | 70 |
71 CCRendererGL::CCRendererGL(CCRendererClient* client, | 71 GLRenderer::GLRenderer(RendererClient* client, |
72 CCResourceProvider* resourceProvider) | 72 ResourceProvider* resourceProvider) |
73 : CCDirectRenderer(client, resourceProvider) | 73 : DirectRenderer(client, resourceProvider) |
74 , m_offscreenFramebufferId(0) | 74 , m_offscreenFramebufferId(0) |
75 , m_sharedGeometryQuad(FloatRect(-0.5f, -0.5f, 1.0f, 1.0f)) | 75 , m_sharedGeometryQuad(FloatRect(-0.5f, -0.5f, 1.0f, 1.0f)) |
76 , m_context(resourceProvider->graphicsContext3D()) | 76 , m_context(resourceProvider->graphicsContext3D()) |
77 , m_isViewportChanged(false) | 77 , m_isViewportChanged(false) |
78 , m_isFramebufferDiscarded(false) | 78 , m_isFramebufferDiscarded(false) |
79 , m_discardFramebufferWhenNotVisible(false) | 79 , m_discardFramebufferWhenNotVisible(false) |
80 , m_isUsingBindUniform(false) | 80 , m_isUsingBindUniform(false) |
81 , m_visible(true) | 81 , m_visible(true) |
82 { | 82 { |
83 ASSERT(m_context); | 83 ASSERT(m_context); |
84 } | 84 } |
85 | 85 |
86 bool CCRendererGL::initialize() | 86 bool GLRenderer::initialize() |
87 { | 87 { |
88 if (!m_context->makeContextCurrent()) | 88 if (!m_context->makeContextCurrent()) |
89 return false; | 89 return false; |
90 | 90 |
91 m_context->setContextLostCallback(this); | 91 m_context->setContextLostCallback(this); |
92 m_context->pushGroupMarkerEXT("CompositorContext"); | 92 m_context->pushGroupMarkerEXT("CompositorContext"); |
93 | 93 |
94 std::string extensionsString = UTF16ToASCII(m_context->getString(GraphicsCon
text3D::EXTENSIONS)); | 94 std::string extensionsString = UTF16ToASCII(m_context->getString(GraphicsCon
text3D::EXTENSIONS)); |
95 std::vector<std::string> extensionsList; | 95 std::vector<std::string> extensionsList; |
96 base::SplitString(extensionsString, ' ', &extensionsList); | 96 base::SplitString(extensionsString, ' ', &extensionsList); |
97 std::set<string> extensions(extensionsList.begin(), extensionsList.end()); | 97 std::set<string> extensions(extensionsList.begin(), extensionsList.end()); |
98 | 98 |
99 if (settings().acceleratePainting && extensions.count("GL_EXT_texture_format
_BGRA8888") | 99 if (settings().acceleratePainting && extensions.count("GL_EXT_texture_format
_BGRA8888") |
100 && extensions.count("GL_EXT_read_format_bg
ra")) | 100 && extensions.count("GL_EXT_read_format_bg
ra")) |
101 m_capabilities.usingAcceleratedPainting = true; | 101 m_capabilities.usingAcceleratedPainting = true; |
102 else | 102 else |
103 m_capabilities.usingAcceleratedPainting = false; | 103 m_capabilities.usingAcceleratedPainting = false; |
104 | 104 |
105 | 105 |
106 m_capabilities.contextHasCachedFrontBuffer = extensions.count("GL_CHROMIUM_f
ront_buffer_cached"); | 106 m_capabilities.contextHasCachedFrontBuffer = extensions.count("GL_CHROMIUM_f
ront_buffer_cached"); |
107 | 107 |
108 m_capabilities.usingPartialSwap = CCSettings::partialSwapEnabled() && extens
ions.count("GL_CHROMIUM_post_sub_buffer"); | 108 m_capabilities.usingPartialSwap = Settings::partialSwapEnabled() && extensio
ns.count("GL_CHROMIUM_post_sub_buffer"); |
109 | 109 |
110 // Use the swapBuffers callback only with the threaded proxy. | 110 // Use the swapBuffers callback only with the threaded proxy. |
111 if (CCProxy::hasImplThread()) | 111 if (Proxy::hasImplThread()) |
112 m_capabilities.usingSwapCompleteCallback = extensions.count("GL_CHROMIUM
_swapbuffers_complete_callback"); | 112 m_capabilities.usingSwapCompleteCallback = extensions.count("GL_CHROMIUM
_swapbuffers_complete_callback"); |
113 if (m_capabilities.usingSwapCompleteCallback) | 113 if (m_capabilities.usingSwapCompleteCallback) |
114 m_context->setSwapBuffersCompleteCallbackCHROMIUM(this); | 114 m_context->setSwapBuffersCompleteCallbackCHROMIUM(this); |
115 | 115 |
116 m_capabilities.usingSetVisibility = extensions.count("GL_CHROMIUM_set_visibi
lity"); | 116 m_capabilities.usingSetVisibility = extensions.count("GL_CHROMIUM_set_visibi
lity"); |
117 | 117 |
118 if (extensions.count("GL_CHROMIUM_iosurface")) | 118 if (extensions.count("GL_CHROMIUM_iosurface")) |
119 ASSERT(extensions.count("GL_ARB_texture_rectangle")); | 119 ASSERT(extensions.count("GL_ARB_texture_rectangle")); |
120 | 120 |
121 m_capabilities.usingGpuMemoryManager = extensions.count("GL_CHROMIUM_gpu_mem
ory_manager"); | 121 m_capabilities.usingGpuMemoryManager = extensions.count("GL_CHROMIUM_gpu_mem
ory_manager"); |
(...skipping 10 matching lines...) Expand all Loading... |
132 m_isUsingBindUniform = extensions.count("GL_CHROMIUM_bind_uniform_location")
; | 132 m_isUsingBindUniform = extensions.count("GL_CHROMIUM_bind_uniform_location")
; |
133 | 133 |
134 if (!initializeSharedObjects()) | 134 if (!initializeSharedObjects()) |
135 return false; | 135 return false; |
136 | 136 |
137 // Make sure the viewport and context gets initialized, even if it is to zer
o. | 137 // Make sure the viewport and context gets initialized, even if it is to zer
o. |
138 viewportChanged(); | 138 viewportChanged(); |
139 return true; | 139 return true; |
140 } | 140 } |
141 | 141 |
142 CCRendererGL::~CCRendererGL() | 142 GLRenderer::~GLRenderer() |
143 { | 143 { |
144 ASSERT(CCProxy::isImplThread()); | 144 ASSERT(Proxy::isImplThread()); |
145 m_context->setSwapBuffersCompleteCallbackCHROMIUM(0); | 145 m_context->setSwapBuffersCompleteCallbackCHROMIUM(0); |
146 m_context->setMemoryAllocationChangedCallbackCHROMIUM(0); | 146 m_context->setMemoryAllocationChangedCallbackCHROMIUM(0); |
147 m_context->setContextLostCallback(0); | 147 m_context->setContextLostCallback(0); |
148 cleanupSharedObjects(); | 148 cleanupSharedObjects(); |
149 } | 149 } |
150 | 150 |
151 const RendererCapabilities& CCRendererGL::capabilities() const | 151 const RendererCapabilities& GLRenderer::capabilities() const |
152 { | 152 { |
153 return m_capabilities; | 153 return m_capabilities; |
154 } | 154 } |
155 | 155 |
156 WebGraphicsContext3D* CCRendererGL::context() | 156 WebGraphicsContext3D* GLRenderer::context() |
157 { | 157 { |
158 return m_context; | 158 return m_context; |
159 } | 159 } |
160 | 160 |
161 void CCRendererGL::debugGLCall(WebGraphicsContext3D* context, const char* comman
d, const char* file, int line) | 161 void GLRenderer::debugGLCall(WebGraphicsContext3D* context, const char* command,
const char* file, int line) |
162 { | 162 { |
163 unsigned long error = context->getError(); | 163 unsigned long error = context->getError(); |
164 if (error != GraphicsContext3D::NO_ERROR) | 164 if (error != GraphicsContext3D::NO_ERROR) |
165 LOG_ERROR("GL command failed: File: %s\n\tLine %d\n\tcommand: %s, error
%x\n", file, line, command, static_cast<int>(error)); | 165 LOG_ERROR("GL command failed: File: %s\n\tLine %d\n\tcommand: %s, error
%x\n", file, line, command, static_cast<int>(error)); |
166 } | 166 } |
167 | 167 |
168 void CCRendererGL::setVisible(bool visible) | 168 void GLRenderer::setVisible(bool visible) |
169 { | 169 { |
170 if (m_visible == visible) | 170 if (m_visible == visible) |
171 return; | 171 return; |
172 m_visible = visible; | 172 m_visible = visible; |
173 | 173 |
174 // TODO: Replace setVisibilityCHROMIUM with an extension to explicitly manag
e front/backbuffers | 174 // TODO: Replace setVisibilityCHROMIUM with an extension to explicitly manag
e front/backbuffers |
175 // crbug.com/116049 | 175 // crbug.com/116049 |
176 if (m_capabilities.usingSetVisibility) | 176 if (m_capabilities.usingSetVisibility) |
177 m_context->setVisibilityCHROMIUM(visible); | 177 m_context->setVisibilityCHROMIUM(visible); |
178 | 178 |
179 enforceMemoryPolicy(); | 179 enforceMemoryPolicy(); |
180 } | 180 } |
181 | 181 |
182 void CCRendererGL::releaseRenderPassTextures() | 182 void GLRenderer::releaseRenderPassTextures() |
183 { | 183 { |
184 m_renderPassTextures.clear(); | 184 m_renderPassTextures.clear(); |
185 } | 185 } |
186 | 186 |
187 void CCRendererGL::viewportChanged() | 187 void GLRenderer::viewportChanged() |
188 { | 188 { |
189 m_isViewportChanged = true; | 189 m_isViewportChanged = true; |
190 } | 190 } |
191 | 191 |
192 void CCRendererGL::clearFramebuffer(DrawingFrame& frame) | 192 void GLRenderer::clearFramebuffer(DrawingFrame& frame) |
193 { | 193 { |
194 // On DEBUG builds, opaque render passes are cleared to blue to easily see r
egions that were not drawn on the screen. | 194 // On DEBUG builds, opaque render passes are cleared to blue to easily see r
egions that were not drawn on the screen. |
195 if (frame.currentRenderPass->hasTransparentBackground()) | 195 if (frame.currentRenderPass->hasTransparentBackground()) |
196 GLC(m_context, m_context->clearColor(0, 0, 0, 0)); | 196 GLC(m_context, m_context->clearColor(0, 0, 0, 0)); |
197 else | 197 else |
198 GLC(m_context, m_context->clearColor(0, 0, 1, 1)); | 198 GLC(m_context, m_context->clearColor(0, 0, 1, 1)); |
199 | 199 |
200 #if defined(NDEBUG) | 200 #if defined(NDEBUG) |
201 if (frame.currentRenderPass->hasTransparentBackground()) | 201 if (frame.currentRenderPass->hasTransparentBackground()) |
202 #endif | 202 #endif |
203 m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT); | 203 m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT); |
204 } | 204 } |
205 | 205 |
206 void CCRendererGL::beginDrawingFrame(DrawingFrame& frame) | 206 void GLRenderer::beginDrawingFrame(DrawingFrame& frame) |
207 { | 207 { |
208 // FIXME: Remove this once framebuffer is automatically recreated on first u
se | 208 // FIXME: Remove this once framebuffer is automatically recreated on first u
se |
209 ensureFramebuffer(); | 209 ensureFramebuffer(); |
210 | 210 |
211 if (viewportSize().isEmpty()) | 211 if (viewportSize().isEmpty()) |
212 return; | 212 return; |
213 | 213 |
214 TRACE_EVENT0("cc", "CCRendererGL::drawLayers"); | 214 TRACE_EVENT0("cc", "GLRenderer::drawLayers"); |
215 if (m_isViewportChanged) { | 215 if (m_isViewportChanged) { |
216 // Only reshape when we know we are going to draw. Otherwise, the reshap
e | 216 // Only reshape when we know we are going to draw. Otherwise, the reshap
e |
217 // can leave the window at the wrong size if we never draw and the prope
r | 217 // can leave the window at the wrong size if we never draw and the prope
r |
218 // viewport size is never set. | 218 // viewport size is never set. |
219 m_isViewportChanged = false; | 219 m_isViewportChanged = false; |
220 m_context->reshape(viewportWidth(), viewportHeight()); | 220 m_context->reshape(viewportWidth(), viewportHeight()); |
221 } | 221 } |
222 | 222 |
223 makeContextCurrent(); | 223 makeContextCurrent(); |
224 // Bind the common vertex attributes used for drawing all the layers. | 224 // Bind the common vertex attributes used for drawing all the layers. |
225 m_sharedGeometry->prepareForDraw(); | 225 m_sharedGeometry->prepareForDraw(); |
226 | 226 |
227 GLC(m_context, m_context->disable(GraphicsContext3D::DEPTH_TEST)); | 227 GLC(m_context, m_context->disable(GraphicsContext3D::DEPTH_TEST)); |
228 GLC(m_context, m_context->disable(GraphicsContext3D::CULL_FACE)); | 228 GLC(m_context, m_context->disable(GraphicsContext3D::CULL_FACE)); |
229 GLC(m_context, m_context->colorMask(true, true, true, true)); | 229 GLC(m_context, m_context->colorMask(true, true, true, true)); |
230 GLC(m_context, m_context->enable(GraphicsContext3D::BLEND)); | 230 GLC(m_context, m_context->enable(GraphicsContext3D::BLEND)); |
231 GLC(m_context, m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3
D::ONE_MINUS_SRC_ALPHA)); | 231 GLC(m_context, m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3
D::ONE_MINUS_SRC_ALPHA)); |
232 } | 232 } |
233 | 233 |
234 void CCRendererGL::doNoOp() | 234 void GLRenderer::doNoOp() |
235 { | 235 { |
236 GLC(m_context, m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0)
); | 236 GLC(m_context, m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0)
); |
237 GLC(m_context, m_context->flush()); | 237 GLC(m_context, m_context->flush()); |
238 } | 238 } |
239 | 239 |
240 void CCRendererGL::drawQuad(DrawingFrame& frame, const CCDrawQuad* quad) | 240 void GLRenderer::drawQuad(DrawingFrame& frame, const DrawQuad* quad) |
241 { | 241 { |
242 if (quad->needsBlending()) | 242 if (quad->needsBlending()) |
243 GLC(m_context, m_context->enable(GraphicsContext3D::BLEND)); | 243 GLC(m_context, m_context->enable(GraphicsContext3D::BLEND)); |
244 else | 244 else |
245 GLC(m_context, m_context->disable(GraphicsContext3D::BLEND)); | 245 GLC(m_context, m_context->disable(GraphicsContext3D::BLEND)); |
246 | 246 |
247 switch (quad->material()) { | 247 switch (quad->material()) { |
248 case CCDrawQuad::Invalid: | 248 case DrawQuad::Invalid: |
249 ASSERT_NOT_REACHED(); | 249 ASSERT_NOT_REACHED(); |
250 break; | 250 break; |
251 case CCDrawQuad::Checkerboard: | 251 case DrawQuad::Checkerboard: |
252 drawCheckerboardQuad(frame, CCCheckerboardDrawQuad::materialCast(quad)); | 252 drawCheckerboardQuad(frame, CheckerboardDrawQuad::materialCast(quad)); |
253 break; | 253 break; |
254 case CCDrawQuad::DebugBorder: | 254 case DrawQuad::DebugBorder: |
255 drawDebugBorderQuad(frame, CCDebugBorderDrawQuad::materialCast(quad)); | 255 drawDebugBorderQuad(frame, DebugBorderDrawQuad::materialCast(quad)); |
256 break; | 256 break; |
257 case CCDrawQuad::IOSurfaceContent: | 257 case DrawQuad::IOSurfaceContent: |
258 drawIOSurfaceQuad(frame, CCIOSurfaceDrawQuad::materialCast(quad)); | 258 drawIOSurfaceQuad(frame, IOSurfaceDrawQuad::materialCast(quad)); |
259 break; | 259 break; |
260 case CCDrawQuad::RenderPass: | 260 case DrawQuad::RenderPass: |
261 drawRenderPassQuad(frame, CCRenderPassDrawQuad::materialCast(quad)); | 261 drawRenderPassQuad(frame, RenderPassDrawQuad::materialCast(quad)); |
262 break; | 262 break; |
263 case CCDrawQuad::SolidColor: | 263 case DrawQuad::SolidColor: |
264 drawSolidColorQuad(frame, CCSolidColorDrawQuad::materialCast(quad)); | 264 drawSolidColorQuad(frame, SolidColorDrawQuad::materialCast(quad)); |
265 break; | 265 break; |
266 case CCDrawQuad::StreamVideoContent: | 266 case DrawQuad::StreamVideoContent: |
267 drawStreamVideoQuad(frame, CCStreamVideoDrawQuad::materialCast(quad)); | 267 drawStreamVideoQuad(frame, StreamVideoDrawQuad::materialCast(quad)); |
268 break; | 268 break; |
269 case CCDrawQuad::TextureContent: | 269 case DrawQuad::TextureContent: |
270 drawTextureQuad(frame, CCTextureDrawQuad::materialCast(quad)); | 270 drawTextureQuad(frame, TextureDrawQuad::materialCast(quad)); |
271 break; | 271 break; |
272 case CCDrawQuad::TiledContent: | 272 case DrawQuad::TiledContent: |
273 drawTileQuad(frame, CCTileDrawQuad::materialCast(quad)); | 273 drawTileQuad(frame, TileDrawQuad::materialCast(quad)); |
274 break; | 274 break; |
275 case CCDrawQuad::YUVVideoContent: | 275 case DrawQuad::YUVVideoContent: |
276 drawYUVVideoQuad(frame, CCYUVVideoDrawQuad::materialCast(quad)); | 276 drawYUVVideoQuad(frame, YUVVideoDrawQuad::materialCast(quad)); |
277 break; | 277 break; |
278 } | 278 } |
279 } | 279 } |
280 | 280 |
281 void CCRendererGL::drawCheckerboardQuad(const DrawingFrame& frame, const CCCheck
erboardDrawQuad* quad) | 281 void GLRenderer::drawCheckerboardQuad(const DrawingFrame& frame, const Checkerbo
ardDrawQuad* quad) |
282 { | 282 { |
283 const TileCheckerboardProgram* program = tileCheckerboardProgram(); | 283 const TileCheckerboardProgram* program = tileCheckerboardProgram(); |
284 ASSERT(program && program->initialized()); | 284 ASSERT(program && program->initialized()); |
285 GLC(context(), context()->useProgram(program->program())); | 285 GLC(context(), context()->useProgram(program->program())); |
286 | 286 |
287 SkColor color = quad->color(); | 287 SkColor color = quad->color(); |
288 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation(
), SkColorGetR(color) / 255.0, SkColorGetG(color) / 255.0, SkColorGetB(color) /
255.0, 1)); | 288 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation(
), SkColorGetR(color) / 255.0, SkColorGetG(color) / 255.0, SkColorGetB(color) /
255.0, 1)); |
289 | 289 |
290 const int checkerboardWidth = 16; | 290 const int checkerboardWidth = 16; |
291 float frequency = 1.0 / checkerboardWidth; | 291 float frequency = 1.0 / checkerboardWidth; |
292 | 292 |
293 IntRect tileRect = quad->quadRect(); | 293 IntRect tileRect = quad->quadRect(); |
294 float texOffsetX = tileRect.x() % checkerboardWidth; | 294 float texOffsetX = tileRect.x() % checkerboardWidth; |
295 float texOffsetY = tileRect.y() % checkerboardWidth; | 295 float texOffsetY = tileRect.y() % checkerboardWidth; |
296 float texScaleX = tileRect.width(); | 296 float texScaleX = tileRect.width(); |
297 float texScaleY = tileRect.height(); | 297 float texScaleY = tileRect.height(); |
298 GLC(context(), context()->uniform4f(program->fragmentShader().texTransformLo
cation(), texOffsetX, texOffsetY, texScaleX, texScaleY)); | 298 GLC(context(), context()->uniform4f(program->fragmentShader().texTransformLo
cation(), texOffsetX, texOffsetY, texScaleX, texScaleY)); |
299 | 299 |
300 GLC(context(), context()->uniform1f(program->fragmentShader().frequencyLocat
ion(), frequency)); | 300 GLC(context(), context()->uniform1f(program->fragmentShader().frequencyLocat
ion(), frequency)); |
301 | 301 |
302 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation())
; | 302 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation())
; |
303 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), program->ve
rtexShader().matrixLocation()); | 303 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), program->ve
rtexShader().matrixLocation()); |
304 } | 304 } |
305 | 305 |
306 void CCRendererGL::drawDebugBorderQuad(const DrawingFrame& frame, const CCDebugB
orderDrawQuad* quad) | 306 void GLRenderer::drawDebugBorderQuad(const DrawingFrame& frame, const DebugBorde
rDrawQuad* quad) |
307 { | 307 { |
308 static float glMatrix[16]; | 308 static float glMatrix[16]; |
309 const SolidColorProgram* program = solidColorProgram(); | 309 const SolidColorProgram* program = solidColorProgram(); |
310 ASSERT(program && program->initialized()); | 310 ASSERT(program && program->initialized()); |
311 GLC(context(), context()->useProgram(program->program())); | 311 GLC(context(), context()->useProgram(program->program())); |
312 | 312 |
313 // Use the full quadRect for debug quads to not move the edges based on part
ial swaps. | 313 // Use the full quadRect for debug quads to not move the edges based on part
ial swaps. |
314 const IntRect& layerRect = quad->quadRect(); | 314 const IntRect& layerRect = quad->quadRect(); |
315 WebTransformationMatrix renderMatrix = quad->quadTransform(); | 315 WebTransformationMatrix renderMatrix = quad->quadTransform(); |
316 renderMatrix.translate(0.5 * layerRect.width() + layerRect.x(), 0.5 * layerR
ect.height() + layerRect.y()); | 316 renderMatrix.translate(0.5 * layerRect.width() + layerRect.x(), 0.5 * layerR
ect.height() + layerRect.y()); |
317 renderMatrix.scaleNonUniform(layerRect.width(), layerRect.height()); | 317 renderMatrix.scaleNonUniform(layerRect.width(), layerRect.height()); |
318 CCRendererGL::toGLMatrix(&glMatrix[0], frame.projectionMatrix * renderMatrix
); | 318 GLRenderer::toGLMatrix(&glMatrix[0], frame.projectionMatrix * renderMatrix); |
319 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().matrixLoc
ation(), 1, false, &glMatrix[0])); | 319 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().matrixLoc
ation(), 1, false, &glMatrix[0])); |
320 | 320 |
321 SkColor color = quad->color(); | 321 SkColor color = quad->color(); |
322 float alpha = SkColorGetA(color) / 255.0; | 322 float alpha = SkColorGetA(color) / 255.0; |
323 | 323 |
324 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation(
), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, (
SkColorGetB(color) / 255.0) * alpha, alpha)); | 324 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation(
), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, (
SkColorGetB(color) / 255.0) * alpha, alpha)); |
325 | 325 |
326 GLC(context(), context()->lineWidth(quad->width())); | 326 GLC(context(), context()->lineWidth(quad->width())); |
327 | 327 |
328 // The indices for the line are stored in the same array as the triangle ind
ices. | 328 // The indices for the line are stored in the same array as the triangle ind
ices. |
329 GLC(context(), context()->drawElements(GraphicsContext3D::LINE_LOOP, 4, Grap
hicsContext3D::UNSIGNED_SHORT, 6 * sizeof(unsigned short))); | 329 GLC(context(), context()->drawElements(GraphicsContext3D::LINE_LOOP, 4, Grap
hicsContext3D::UNSIGNED_SHORT, 6 * sizeof(unsigned short))); |
330 } | 330 } |
331 | 331 |
332 static inline SkBitmap applyFilters(CCRendererGL* renderer, const WebKit::WebFil
terOperations& filters, CCScopedTexture* sourceTexture) | 332 static inline SkBitmap applyFilters(GLRenderer* renderer, const WebKit::WebFilte
rOperations& filters, ScopedTexture* sourceTexture) |
333 { | 333 { |
334 if (filters.isEmpty()) | 334 if (filters.isEmpty()) |
335 return SkBitmap(); | 335 return SkBitmap(); |
336 | 336 |
337 WebGraphicsContext3D* filterContext = CCProxy::hasImplThread() ? WebSharedGr
aphicsContext3D::compositorThreadContext() : WebSharedGraphicsContext3D::mainThr
eadContext(); | 337 WebGraphicsContext3D* filterContext = Proxy::hasImplThread() ? WebSharedGrap
hicsContext3D::compositorThreadContext() : WebSharedGraphicsContext3D::mainThrea
dContext(); |
338 GrContext* filterGrContext = CCProxy::hasImplThread() ? WebSharedGraphicsCon
text3D::compositorThreadGrContext() : WebSharedGraphicsContext3D::mainThreadGrCo
ntext(); | 338 GrContext* filterGrContext = Proxy::hasImplThread() ? WebSharedGraphicsConte
xt3D::compositorThreadGrContext() : WebSharedGraphicsContext3D::mainThreadGrCont
ext(); |
339 | 339 |
340 if (!filterContext || !filterGrContext) | 340 if (!filterContext || !filterGrContext) |
341 return SkBitmap(); | 341 return SkBitmap(); |
342 | 342 |
343 renderer->context()->flush(); | 343 renderer->context()->flush(); |
344 | 344 |
345 CCResourceProvider::ScopedWriteLockGL lock(renderer->resourceProvider(), sou
rceTexture->id()); | 345 ResourceProvider::ScopedWriteLockGL lock(renderer->resourceProvider(), sourc
eTexture->id()); |
346 SkBitmap source = CCRenderSurfaceFilters::apply(filters, lock.textureId(), s
ourceTexture->size(), filterContext, filterGrContext); | 346 SkBitmap source = RenderSurfaceFilters::apply(filters, lock.textureId(), sou
rceTexture->size(), filterContext, filterGrContext); |
347 return source; | 347 return source; |
348 } | 348 } |
349 | 349 |
350 scoped_ptr<CCScopedTexture> CCRendererGL::drawBackgroundFilters(DrawingFrame& fr
ame, const CCRenderPassDrawQuad* quad, const WebKit::WebFilterOperations& filter
s, const WebTransformationMatrix& contentsDeviceTransform) | 350 scoped_ptr<ScopedTexture> GLRenderer::drawBackgroundFilters(DrawingFrame& frame,
const RenderPassDrawQuad* quad, const WebKit::WebFilterOperations& filters, con
st WebTransformationMatrix& contentsDeviceTransform) |
351 { | 351 { |
352 // This method draws a background filter, which applies a filter to any pixe
ls behind the quad and seen through its background. | 352 // This method draws a background filter, which applies a filter to any pixe
ls behind the quad and seen through its background. |
353 // The algorithm works as follows: | 353 // The algorithm works as follows: |
354 // 1. Compute a bounding box around the pixels that will be visible through
the quad. | 354 // 1. Compute a bounding box around the pixels that will be visible through
the quad. |
355 // 2. Read the pixels in the bounding box into a buffer R. | 355 // 2. Read the pixels in the bounding box into a buffer R. |
356 // 3. Apply the background filter to R, so that it is applied in the pixels'
coordinate space. | 356 // 3. Apply the background filter to R, so that it is applied in the pixels'
coordinate space. |
357 // 4. Apply the quad's inverse transform to map the pixels in R into the qua
d's content space. This implicitly | 357 // 4. Apply the quad's inverse transform to map the pixels in R into the qua
d's content space. This implicitly |
358 // clips R by the content bounds of the quad since the destination texture h
as bounds matching the quad's content. | 358 // clips R by the content bounds of the quad since the destination texture h
as bounds matching the quad's content. |
359 // 5. Draw the background texture for the contents using the same transform
as used to draw the contents itself. This is done | 359 // 5. Draw the background texture for the contents using the same transform
as used to draw the contents itself. This is done |
360 // without blending to replace the current background pixels with the new fi
ltered background. | 360 // without blending to replace the current background pixels with the new fi
ltered background. |
361 // 6. Draw the contents of the quad over drop of the new background with ble
nding, as per usual. The filtered background | 361 // 6. Draw the contents of the quad over drop of the new background with ble
nding, as per usual. The filtered background |
362 // pixels will show through any non-opaque pixels in this draws. | 362 // pixels will show through any non-opaque pixels in this draws. |
363 // | 363 // |
364 // Pixel copies in this algorithm occur at steps 2, 3, 4, and 5. | 364 // Pixel copies in this algorithm occur at steps 2, 3, 4, and 5. |
365 | 365 |
366 // FIXME: When this algorithm changes, update CCLayerTreeHost::prioritizeTex
tures() accordingly. | 366 // FIXME: When this algorithm changes, update LayerTreeHost::prioritizeTextu
res() accordingly. |
367 | 367 |
368 if (filters.isEmpty()) | 368 if (filters.isEmpty()) |
369 return scoped_ptr<CCScopedTexture>(); | 369 return scoped_ptr<ScopedTexture>(); |
370 | 370 |
371 // FIXME: We only allow background filters on an opaque render surface becau
se other surfaces may contain | 371 // FIXME: We only allow background filters on an opaque render surface becau
se other surfaces may contain |
372 // translucent pixels, and the contents behind those translucent pixels woul
dn't have the filter applied. | 372 // translucent pixels, and the contents behind those translucent pixels woul
dn't have the filter applied. |
373 if (frame.currentRenderPass->hasTransparentBackground()) | 373 if (frame.currentRenderPass->hasTransparentBackground()) |
374 return scoped_ptr<CCScopedTexture>(); | 374 return scoped_ptr<ScopedTexture>(); |
375 ASSERT(!frame.currentTexture); | 375 ASSERT(!frame.currentTexture); |
376 | 376 |
377 // FIXME: Do a single readback for both the surface and replica and cache th
e filtered results (once filter textures are not reused). | 377 // FIXME: Do a single readback for both the surface and replica and cache th
e filtered results (once filter textures are not reused). |
378 IntRect deviceRect = enclosingIntRect(CCMathUtil::mapClippedRect(contentsDev
iceTransform, sharedGeometryQuad().boundingBox())); | 378 IntRect deviceRect = enclosingIntRect(MathUtil::mapClippedRect(contentsDevic
eTransform, sharedGeometryQuad().boundingBox())); |
379 | 379 |
380 int top, right, bottom, left; | 380 int top, right, bottom, left; |
381 filters.getOutsets(top, right, bottom, left); | 381 filters.getOutsets(top, right, bottom, left); |
382 deviceRect.move(-left, -top); | 382 deviceRect.move(-left, -top); |
383 deviceRect.expand(left + right, top + bottom); | 383 deviceRect.expand(left + right, top + bottom); |
384 | 384 |
385 deviceRect.intersect(frame.currentRenderPass->outputRect()); | 385 deviceRect.intersect(frame.currentRenderPass->outputRect()); |
386 | 386 |
387 scoped_ptr<CCScopedTexture> deviceBackgroundTexture = CCScopedTexture::creat
e(m_resourceProvider); | 387 scoped_ptr<ScopedTexture> deviceBackgroundTexture = ScopedTexture::create(m_
resourceProvider); |
388 if (!getFramebufferTexture(deviceBackgroundTexture.get(), deviceRect)) | 388 if (!getFramebufferTexture(deviceBackgroundTexture.get(), deviceRect)) |
389 return scoped_ptr<CCScopedTexture>(); | 389 return scoped_ptr<ScopedTexture>(); |
390 | 390 |
391 SkBitmap filteredDeviceBackground = applyFilters(this, filters, deviceBackgr
oundTexture.get()); | 391 SkBitmap filteredDeviceBackground = applyFilters(this, filters, deviceBackgr
oundTexture.get()); |
392 if (!filteredDeviceBackground.getTexture()) | 392 if (!filteredDeviceBackground.getTexture()) |
393 return scoped_ptr<CCScopedTexture>(); | 393 return scoped_ptr<ScopedTexture>(); |
394 | 394 |
395 GrTexture* texture = reinterpret_cast<GrTexture*>(filteredDeviceBackground.g
etTexture()); | 395 GrTexture* texture = reinterpret_cast<GrTexture*>(filteredDeviceBackground.g
etTexture()); |
396 int filteredDeviceBackgroundTextureId = texture->getTextureHandle(); | 396 int filteredDeviceBackgroundTextureId = texture->getTextureHandle(); |
397 | 397 |
398 scoped_ptr<CCScopedTexture> backgroundTexture = CCScopedTexture::create(m_re
sourceProvider); | 398 scoped_ptr<ScopedTexture> backgroundTexture = ScopedTexture::create(m_resour
ceProvider); |
399 if (!backgroundTexture->allocate(CCRenderer::ImplPool, quad->quadRect().size
(), GraphicsContext3D::RGBA, CCResourceProvider::TextureUsageFramebuffer)) | 399 if (!backgroundTexture->allocate(Renderer::ImplPool, quad->quadRect().size()
, GraphicsContext3D::RGBA, ResourceProvider::TextureUsageFramebuffer)) |
400 return scoped_ptr<CCScopedTexture>(); | 400 return scoped_ptr<ScopedTexture>(); |
401 | 401 |
402 const CCRenderPass* targetRenderPass = frame.currentRenderPass; | 402 const RenderPass* targetRenderPass = frame.currentRenderPass; |
403 bool usingBackgroundTexture = useScopedTexture(frame, backgroundTexture.get(
), quad->quadRect()); | 403 bool usingBackgroundTexture = useScopedTexture(frame, backgroundTexture.get(
), quad->quadRect()); |
404 | 404 |
405 if (usingBackgroundTexture) { | 405 if (usingBackgroundTexture) { |
406 // Copy the readback pixels from device to the background texture for th
e surface. | 406 // Copy the readback pixels from device to the background texture for th
e surface. |
407 WebTransformationMatrix deviceToFramebufferTransform; | 407 WebTransformationMatrix deviceToFramebufferTransform; |
408 deviceToFramebufferTransform.translate(quad->quadRect().width() / 2.0, q
uad->quadRect().height() / 2.0); | 408 deviceToFramebufferTransform.translate(quad->quadRect().width() / 2.0, q
uad->quadRect().height() / 2.0); |
409 deviceToFramebufferTransform.scale3d(quad->quadRect().width(), quad->qua
dRect().height(), 1); | 409 deviceToFramebufferTransform.scale3d(quad->quadRect().width(), quad->qua
dRect().height(), 1); |
410 deviceToFramebufferTransform.multiply(contentsDeviceTransform.inverse())
; | 410 deviceToFramebufferTransform.multiply(contentsDeviceTransform.inverse())
; |
411 copyTextureToFramebuffer(frame, filteredDeviceBackgroundTextureId, devic
eRect, deviceToFramebufferTransform); | 411 copyTextureToFramebuffer(frame, filteredDeviceBackgroundTextureId, devic
eRect, deviceToFramebufferTransform); |
412 } | 412 } |
413 | 413 |
414 useRenderPass(frame, targetRenderPass); | 414 useRenderPass(frame, targetRenderPass); |
415 | 415 |
416 if (!usingBackgroundTexture) | 416 if (!usingBackgroundTexture) |
417 return scoped_ptr<CCScopedTexture>(); | 417 return scoped_ptr<ScopedTexture>(); |
418 return backgroundTexture.Pass(); | 418 return backgroundTexture.Pass(); |
419 } | 419 } |
420 | 420 |
421 void CCRendererGL::drawRenderPassQuad(DrawingFrame& frame, const CCRenderPassDra
wQuad* quad) | 421 void GLRenderer::drawRenderPassQuad(DrawingFrame& frame, const RenderPassDrawQua
d* quad) |
422 { | 422 { |
423 CachedTexture* contentsTexture = m_renderPassTextures.get(quad->renderPassId
()); | 423 CachedTexture* contentsTexture = m_renderPassTextures.get(quad->renderPassId
()); |
424 if (!contentsTexture || !contentsTexture->id()) | 424 if (!contentsTexture || !contentsTexture->id()) |
425 return; | 425 return; |
426 | 426 |
427 const CCRenderPass* renderPass = frame.renderPassesById->get(quad->renderPas
sId()); | 427 const RenderPass* renderPass = frame.renderPassesById->get(quad->renderPassI
d()); |
428 ASSERT(renderPass); | 428 ASSERT(renderPass); |
429 if (!renderPass) | 429 if (!renderPass) |
430 return; | 430 return; |
431 | 431 |
432 WebTransformationMatrix quadRectMatrix; | 432 WebTransformationMatrix quadRectMatrix; |
433 quadRectTransform(&quadRectMatrix, quad->quadTransform(), quad->quadRect()); | 433 quadRectTransform(&quadRectMatrix, quad->quadTransform(), quad->quadRect()); |
434 WebTransformationMatrix contentsDeviceTransform = (frame.windowMatrix * fram
e.projectionMatrix * quadRectMatrix).to2dTransform(); | 434 WebTransformationMatrix contentsDeviceTransform = (frame.windowMatrix * fram
e.projectionMatrix * quadRectMatrix).to2dTransform(); |
435 | 435 |
436 // Can only draw surface if device matrix is invertible. | 436 // Can only draw surface if device matrix is invertible. |
437 if (!contentsDeviceTransform.isInvertible()) | 437 if (!contentsDeviceTransform.isInvertible()) |
438 return; | 438 return; |
439 | 439 |
440 scoped_ptr<CCScopedTexture> backgroundTexture = drawBackgroundFilters(frame,
quad, renderPass->backgroundFilters(), contentsDeviceTransform); | 440 scoped_ptr<ScopedTexture> backgroundTexture = drawBackgroundFilters(frame, q
uad, renderPass->backgroundFilters(), contentsDeviceTransform); |
441 | 441 |
442 // FIXME: Cache this value so that we don't have to do it for both the surfa
ce and its replica. | 442 // FIXME: Cache this value so that we don't have to do it for both the surfa
ce and its replica. |
443 // Apply filters to the contents texture. | 443 // Apply filters to the contents texture. |
444 SkBitmap filterBitmap = applyFilters(this, renderPass->filters(), contentsTe
xture); | 444 SkBitmap filterBitmap = applyFilters(this, renderPass->filters(), contentsTe
xture); |
445 scoped_ptr<CCResourceProvider::ScopedReadLockGL> contentsResourceLock; | 445 scoped_ptr<ResourceProvider::ScopedReadLockGL> contentsResourceLock; |
446 unsigned contentsTextureId = 0; | 446 unsigned contentsTextureId = 0; |
447 if (filterBitmap.getTexture()) { | 447 if (filterBitmap.getTexture()) { |
448 GrTexture* texture = reinterpret_cast<GrTexture*>(filterBitmap.getTextur
e()); | 448 GrTexture* texture = reinterpret_cast<GrTexture*>(filterBitmap.getTextur
e()); |
449 contentsTextureId = texture->getTextureHandle(); | 449 contentsTextureId = texture->getTextureHandle(); |
450 } else { | 450 } else { |
451 contentsResourceLock = make_scoped_ptr(new CCResourceProvider::ScopedRea
dLockGL(m_resourceProvider, contentsTexture->id())); | 451 contentsResourceLock = make_scoped_ptr(new ResourceProvider::ScopedReadL
ockGL(m_resourceProvider, contentsTexture->id())); |
452 contentsTextureId = contentsResourceLock->textureId(); | 452 contentsTextureId = contentsResourceLock->textureId(); |
453 } | 453 } |
454 | 454 |
455 // Draw the background texture if there is one. | 455 // Draw the background texture if there is one. |
456 if (backgroundTexture) { | 456 if (backgroundTexture) { |
457 ASSERT(backgroundTexture->size() == quad->quadRect().size()); | 457 ASSERT(backgroundTexture->size() == quad->quadRect().size()); |
458 CCResourceProvider::ScopedReadLockGL lock(m_resourceProvider, background
Texture->id()); | 458 ResourceProvider::ScopedReadLockGL lock(m_resourceProvider, backgroundTe
xture->id()); |
459 copyTextureToFramebuffer(frame, lock.textureId(), quad->quadRect(), quad
->quadTransform()); | 459 copyTextureToFramebuffer(frame, lock.textureId(), quad->quadRect(), quad
->quadTransform()); |
460 } | 460 } |
461 | 461 |
462 bool clipped = false; | 462 bool clipped = false; |
463 FloatQuad deviceQuad = CCMathUtil::mapQuad(contentsDeviceTransform, sharedGe
ometryQuad(), clipped); | 463 FloatQuad deviceQuad = MathUtil::mapQuad(contentsDeviceTransform, sharedGeom
etryQuad(), clipped); |
464 ASSERT(!clipped); | 464 ASSERT(!clipped); |
465 CCLayerQuad deviceLayerBounds = CCLayerQuad(FloatQuad(deviceQuad.boundingBox
())); | 465 LayerQuad deviceLayerBounds = LayerQuad(FloatQuad(deviceQuad.boundingBox()))
; |
466 CCLayerQuad deviceLayerEdges = CCLayerQuad(deviceQuad); | 466 LayerQuad deviceLayerEdges = LayerQuad(deviceQuad); |
467 | 467 |
468 // Use anti-aliasing programs only when necessary. | 468 // Use anti-aliasing programs only when necessary. |
469 bool useAA = (!deviceQuad.isRectilinear() || !deviceQuad.boundingBox().isExp
ressibleAsIntRect()); | 469 bool useAA = (!deviceQuad.isRectilinear() || !deviceQuad.boundingBox().isExp
ressibleAsIntRect()); |
470 if (useAA) { | 470 if (useAA) { |
471 deviceLayerBounds.inflateAntiAliasingDistance(); | 471 deviceLayerBounds.inflateAntiAliasingDistance(); |
472 deviceLayerEdges.inflateAntiAliasingDistance(); | 472 deviceLayerEdges.inflateAntiAliasingDistance(); |
473 } | 473 } |
474 | 474 |
475 scoped_ptr<CCResourceProvider::ScopedReadLockGL> maskResourceLock; | 475 scoped_ptr<ResourceProvider::ScopedReadLockGL> maskResourceLock; |
476 unsigned maskTextureId = 0; | 476 unsigned maskTextureId = 0; |
477 if (quad->maskResourceId()) { | 477 if (quad->maskResourceId()) { |
478 maskResourceLock.reset(new CCResourceProvider::ScopedReadLockGL(m_resour
ceProvider, quad->maskResourceId())); | 478 maskResourceLock.reset(new ResourceProvider::ScopedReadLockGL(m_resource
Provider, quad->maskResourceId())); |
479 maskTextureId = maskResourceLock->textureId(); | 479 maskTextureId = maskResourceLock->textureId(); |
480 } | 480 } |
481 | 481 |
482 // FIXME: use the backgroundTexture and blend the background in with this dr
aw instead of having a separate copy of the background texture. | 482 // FIXME: use the backgroundTexture and blend the background in with this dr
aw instead of having a separate copy of the background texture. |
483 | 483 |
484 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE0)); | 484 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE0)); |
485 context()->bindTexture(GraphicsContext3D::TEXTURE_2D, contentsTextureId); | 485 context()->bindTexture(GraphicsContext3D::TEXTURE_2D, contentsTextureId); |
486 | 486 |
487 int shaderQuadLocation = -1; | 487 int shaderQuadLocation = -1; |
488 int shaderEdgeLocation = -1; | 488 int shaderEdgeLocation = -1; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 } | 543 } |
544 | 544 |
545 if (shaderEdgeLocation != -1) { | 545 if (shaderEdgeLocation != -1) { |
546 float edge[24]; | 546 float edge[24]; |
547 deviceLayerEdges.toFloatArray(edge); | 547 deviceLayerEdges.toFloatArray(edge); |
548 deviceLayerBounds.toFloatArray(&edge[12]); | 548 deviceLayerBounds.toFloatArray(&edge[12]); |
549 GLC(context(), context()->uniform3fv(shaderEdgeLocation, 8, edge)); | 549 GLC(context(), context()->uniform3fv(shaderEdgeLocation, 8, edge)); |
550 } | 550 } |
551 | 551 |
552 // Map device space quad to surface space. contentsDeviceTransform has no 3d
component since it was generated with to2dTransform() so we don't need to proje
ct. | 552 // Map device space quad to surface space. contentsDeviceTransform has no 3d
component since it was generated with to2dTransform() so we don't need to proje
ct. |
553 FloatQuad surfaceQuad = CCMathUtil::mapQuad(contentsDeviceTransform.inverse(
), deviceLayerEdges.floatQuad(), clipped); | 553 FloatQuad surfaceQuad = MathUtil::mapQuad(contentsDeviceTransform.inverse(),
deviceLayerEdges.floatQuad(), clipped); |
554 ASSERT(!clipped); | 554 ASSERT(!clipped); |
555 | 555 |
556 setShaderOpacity(quad->opacity(), shaderAlphaLocation); | 556 setShaderOpacity(quad->opacity(), shaderAlphaLocation); |
557 setShaderFloatQuad(surfaceQuad, shaderQuadLocation); | 557 setShaderFloatQuad(surfaceQuad, shaderQuadLocation); |
558 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), shaderMatri
xLocation); | 558 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), shaderMatri
xLocation); |
559 } | 559 } |
560 | 560 |
561 void CCRendererGL::drawSolidColorQuad(const DrawingFrame& frame, const CCSolidCo
lorDrawQuad* quad) | 561 void GLRenderer::drawSolidColorQuad(const DrawingFrame& frame, const SolidColorD
rawQuad* quad) |
562 { | 562 { |
563 const SolidColorProgram* program = solidColorProgram(); | 563 const SolidColorProgram* program = solidColorProgram(); |
564 GLC(context(), context()->useProgram(program->program())); | 564 GLC(context(), context()->useProgram(program->program())); |
565 | 565 |
566 SkColor color = quad->color(); | 566 SkColor color = quad->color(); |
567 float opacity = quad->opacity(); | 567 float opacity = quad->opacity(); |
568 float alpha = (SkColorGetA(color) / 255.0) * opacity; | 568 float alpha = (SkColorGetA(color) / 255.0) * opacity; |
569 | 569 |
570 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation(
), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, (
SkColorGetB(color) / 255.0) * alpha, alpha)); | 570 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation(
), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, (
SkColorGetB(color) / 255.0) * alpha, alpha)); |
571 | 571 |
(...skipping 18 matching lines...) Expand all Loading... |
590 uniforms.vertexTexTransformLocation = program->vertexShader().vertexTexTrans
formLocation(); | 590 uniforms.vertexTexTransformLocation = program->vertexShader().vertexTexTrans
formLocation(); |
591 uniforms.matrixLocation = program->vertexShader().matrixLocation(); | 591 uniforms.matrixLocation = program->vertexShader().matrixLocation(); |
592 uniforms.pointLocation = program->vertexShader().pointLocation(); | 592 uniforms.pointLocation = program->vertexShader().pointLocation(); |
593 | 593 |
594 uniforms.samplerLocation = program->fragmentShader().samplerLocation(); | 594 uniforms.samplerLocation = program->fragmentShader().samplerLocation(); |
595 uniforms.alphaLocation = program->fragmentShader().alphaLocation(); | 595 uniforms.alphaLocation = program->fragmentShader().alphaLocation(); |
596 uniforms.fragmentTexTransformLocation = program->fragmentShader().fragmentTe
xTransformLocation(); | 596 uniforms.fragmentTexTransformLocation = program->fragmentShader().fragmentTe
xTransformLocation(); |
597 uniforms.edgeLocation = program->fragmentShader().edgeLocation(); | 597 uniforms.edgeLocation = program->fragmentShader().edgeLocation(); |
598 } | 598 } |
599 | 599 |
600 void CCRendererGL::drawTileQuad(const DrawingFrame& frame, const CCTileDrawQuad*
quad) | 600 void GLRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQuad* qua
d) |
601 { | 601 { |
602 IntRect tileRect = quad->quadVisibleRect(); | 602 IntRect tileRect = quad->quadVisibleRect(); |
603 | 603 |
604 FloatRect clampRect(tileRect); | 604 FloatRect clampRect(tileRect); |
605 // Clamp texture coordinates to avoid sampling outside the layer | 605 // Clamp texture coordinates to avoid sampling outside the layer |
606 // by deflating the tile region half a texel or half a texel | 606 // by deflating the tile region half a texel or half a texel |
607 // minus epsilon for one pixel layers. The resulting clamp region | 607 // minus epsilon for one pixel layers. The resulting clamp region |
608 // is mapped to the unit square by the vertex shader and mapped | 608 // is mapped to the unit square by the vertex shader and mapped |
609 // back to normalized texture coordinates by the fragment shader | 609 // back to normalized texture coordinates by the fragment shader |
610 // after being clamped to 0-1 range. | 610 // after being clamped to 0-1 range. |
(...skipping 20 matching lines...) Expand all Loading... |
631 float fragmentTexScaleX = clampRect.width() / textureSize.width(); | 631 float fragmentTexScaleX = clampRect.width() / textureSize.width(); |
632 float fragmentTexScaleY = clampRect.height() / textureSize.height(); | 632 float fragmentTexScaleY = clampRect.height() / textureSize.height(); |
633 | 633 |
634 | 634 |
635 FloatQuad localQuad; | 635 FloatQuad localQuad; |
636 WebTransformationMatrix deviceTransform = WebTransformationMatrix(frame.wind
owMatrix * frame.projectionMatrix * quad->quadTransform()).to2dTransform(); | 636 WebTransformationMatrix deviceTransform = WebTransformationMatrix(frame.wind
owMatrix * frame.projectionMatrix * quad->quadTransform()).to2dTransform(); |
637 if (!deviceTransform.isInvertible()) | 637 if (!deviceTransform.isInvertible()) |
638 return; | 638 return; |
639 | 639 |
640 bool clipped = false; | 640 bool clipped = false; |
641 FloatQuad deviceLayerQuad = CCMathUtil::mapQuad(deviceTransform, FloatQuad(q
uad->visibleContentRect()), clipped); | 641 FloatQuad deviceLayerQuad = MathUtil::mapQuad(deviceTransform, FloatQuad(qua
d->visibleContentRect()), clipped); |
642 ASSERT(!clipped); | 642 ASSERT(!clipped); |
643 | 643 |
644 TileProgramUniforms uniforms; | 644 TileProgramUniforms uniforms; |
645 // For now, we simply skip anti-aliasing with the quad is clipped. This only
happens | 645 // For now, we simply skip anti-aliasing with the quad is clipped. This only
happens |
646 // on perspective transformed layers that go partially behind the camera. | 646 // on perspective transformed layers that go partially behind the camera. |
647 if (quad->isAntialiased() && !clipped) { | 647 if (quad->isAntialiased() && !clipped) { |
648 if (quad->swizzleContents()) | 648 if (quad->swizzleContents()) |
649 tileUniformLocation(tileProgramSwizzleAA(), uniforms); | 649 tileUniformLocation(tileProgramSwizzleAA(), uniforms); |
650 else | 650 else |
651 tileUniformLocation(tileProgramAA(), uniforms); | 651 tileUniformLocation(tileProgramAA(), uniforms); |
652 } else { | 652 } else { |
653 if (quad->needsBlending()) { | 653 if (quad->needsBlending()) { |
654 if (quad->swizzleContents()) | 654 if (quad->swizzleContents()) |
655 tileUniformLocation(tileProgramSwizzle(), uniforms); | 655 tileUniformLocation(tileProgramSwizzle(), uniforms); |
656 else | 656 else |
657 tileUniformLocation(tileProgram(), uniforms); | 657 tileUniformLocation(tileProgram(), uniforms); |
658 } else { | 658 } else { |
659 if (quad->swizzleContents()) | 659 if (quad->swizzleContents()) |
660 tileUniformLocation(tileProgramSwizzleOpaque(), uniforms); | 660 tileUniformLocation(tileProgramSwizzleOpaque(), uniforms); |
661 else | 661 else |
662 tileUniformLocation(tileProgramOpaque(), uniforms); | 662 tileUniformLocation(tileProgramOpaque(), uniforms); |
663 } | 663 } |
664 } | 664 } |
665 | 665 |
666 GLC(context(), context()->useProgram(uniforms.program)); | 666 GLC(context(), context()->useProgram(uniforms.program)); |
667 GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0)); | 667 GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0)); |
668 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE0)); | 668 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE0)); |
669 CCResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, qu
ad->resourceId()); | 669 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad
->resourceId()); |
670 GLC(context(), context()->bindTexture(GraphicsContext3D::TEXTURE_2D, quadRes
ourceLock.textureId())); | 670 GLC(context(), context()->bindTexture(GraphicsContext3D::TEXTURE_2D, quadRes
ourceLock.textureId())); |
671 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MIN_FILTER, quad->textureFilter())); | 671 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MIN_FILTER, quad->textureFilter())); |
672 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MAG_FILTER, quad->textureFilter())); | 672 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MAG_FILTER, quad->textureFilter())); |
673 | 673 |
674 bool useAA = !clipped && quad->isAntialiased(); | 674 bool useAA = !clipped && quad->isAntialiased(); |
675 if (useAA) { | 675 if (useAA) { |
676 CCLayerQuad deviceLayerBounds = CCLayerQuad(FloatQuad(deviceLayerQuad.bo
undingBox())); | 676 LayerQuad deviceLayerBounds = LayerQuad(FloatQuad(deviceLayerQuad.boundi
ngBox())); |
677 deviceLayerBounds.inflateAntiAliasingDistance(); | 677 deviceLayerBounds.inflateAntiAliasingDistance(); |
678 | 678 |
679 CCLayerQuad deviceLayerEdges = CCLayerQuad(deviceLayerQuad); | 679 LayerQuad deviceLayerEdges = LayerQuad(deviceLayerQuad); |
680 deviceLayerEdges.inflateAntiAliasingDistance(); | 680 deviceLayerEdges.inflateAntiAliasingDistance(); |
681 | 681 |
682 float edge[24]; | 682 float edge[24]; |
683 deviceLayerEdges.toFloatArray(edge); | 683 deviceLayerEdges.toFloatArray(edge); |
684 deviceLayerBounds.toFloatArray(&edge[12]); | 684 deviceLayerBounds.toFloatArray(&edge[12]); |
685 GLC(context(), context()->uniform3fv(uniforms.edgeLocation, 8, edge)); | 685 GLC(context(), context()->uniform3fv(uniforms.edgeLocation, 8, edge)); |
686 | 686 |
687 GLC(context(), context()->uniform4f(uniforms.vertexTexTransformLocation,
vertexTexTranslateX, vertexTexTranslateY, vertexTexScaleX, vertexTexScaleY)); | 687 GLC(context(), context()->uniform4f(uniforms.vertexTexTransformLocation,
vertexTexTranslateX, vertexTexTranslateY, vertexTexScaleX, vertexTexScaleY)); |
688 GLC(context(), context()->uniform4f(uniforms.fragmentTexTransformLocatio
n, fragmentTexTranslateX, fragmentTexTranslateY, fragmentTexScaleX, fragmentTexS
caleY)); | 688 GLC(context(), context()->uniform4f(uniforms.fragmentTexTransformLocatio
n, fragmentTexTranslateX, fragmentTexTranslateY, fragmentTexScaleX, fragmentTexS
caleY)); |
689 | 689 |
690 FloatPoint bottomRight(tileRect.maxX(), tileRect.maxY()); | 690 FloatPoint bottomRight(tileRect.maxX(), tileRect.maxY()); |
691 FloatPoint bottomLeft(tileRect.x(), tileRect.maxY()); | 691 FloatPoint bottomLeft(tileRect.x(), tileRect.maxY()); |
692 FloatPoint topLeft(tileRect.x(), tileRect.y()); | 692 FloatPoint topLeft(tileRect.x(), tileRect.y()); |
693 FloatPoint topRight(tileRect.maxX(), tileRect.y()); | 693 FloatPoint topRight(tileRect.maxX(), tileRect.y()); |
694 | 694 |
695 // Map points to device space. | 695 // Map points to device space. |
696 bottomRight = CCMathUtil::mapPoint(deviceTransform, bottomRight, clipped
); | 696 bottomRight = MathUtil::mapPoint(deviceTransform, bottomRight, clipped); |
697 ASSERT(!clipped); | 697 ASSERT(!clipped); |
698 bottomLeft = CCMathUtil::mapPoint(deviceTransform, bottomLeft, clipped); | 698 bottomLeft = MathUtil::mapPoint(deviceTransform, bottomLeft, clipped); |
699 ASSERT(!clipped); | 699 ASSERT(!clipped); |
700 topLeft = CCMathUtil::mapPoint(deviceTransform, topLeft, clipped); | 700 topLeft = MathUtil::mapPoint(deviceTransform, topLeft, clipped); |
701 ASSERT(!clipped); | 701 ASSERT(!clipped); |
702 topRight = CCMathUtil::mapPoint(deviceTransform, topRight, clipped); | 702 topRight = MathUtil::mapPoint(deviceTransform, topRight, clipped); |
703 ASSERT(!clipped); | 703 ASSERT(!clipped); |
704 | 704 |
705 CCLayerQuad::Edge bottomEdge(bottomRight, bottomLeft); | 705 LayerQuad::Edge bottomEdge(bottomRight, bottomLeft); |
706 CCLayerQuad::Edge leftEdge(bottomLeft, topLeft); | 706 LayerQuad::Edge leftEdge(bottomLeft, topLeft); |
707 CCLayerQuad::Edge topEdge(topLeft, topRight); | 707 LayerQuad::Edge topEdge(topLeft, topRight); |
708 CCLayerQuad::Edge rightEdge(topRight, bottomRight); | 708 LayerQuad::Edge rightEdge(topRight, bottomRight); |
709 | 709 |
710 // Only apply anti-aliasing to edges not clipped by culling or scissorin
g. | 710 // Only apply anti-aliasing to edges not clipped by culling or scissorin
g. |
711 if (quad->topEdgeAA() && tileRect.y() == quad->quadRect().y()) | 711 if (quad->topEdgeAA() && tileRect.y() == quad->quadRect().y()) |
712 topEdge = deviceLayerEdges.top(); | 712 topEdge = deviceLayerEdges.top(); |
713 if (quad->leftEdgeAA() && tileRect.x() == quad->quadRect().x()) | 713 if (quad->leftEdgeAA() && tileRect.x() == quad->quadRect().x()) |
714 leftEdge = deviceLayerEdges.left(); | 714 leftEdge = deviceLayerEdges.left(); |
715 if (quad->rightEdgeAA() && tileRect.maxX() == quad->quadRect().maxX()) | 715 if (quad->rightEdgeAA() && tileRect.maxX() == quad->quadRect().maxX()) |
716 rightEdge = deviceLayerEdges.right(); | 716 rightEdge = deviceLayerEdges.right(); |
717 if (quad->bottomEdgeAA() && tileRect.maxY() == quad->quadRect().maxY()) | 717 if (quad->bottomEdgeAA() && tileRect.maxY() == quad->quadRect().maxY()) |
718 bottomEdge = deviceLayerEdges.bottom(); | 718 bottomEdge = deviceLayerEdges.bottom(); |
719 | 719 |
720 float sign = FloatQuad(tileRect).isCounterclockwise() ? -1 : 1; | 720 float sign = FloatQuad(tileRect).isCounterclockwise() ? -1 : 1; |
721 bottomEdge.scale(sign); | 721 bottomEdge.scale(sign); |
722 leftEdge.scale(sign); | 722 leftEdge.scale(sign); |
723 topEdge.scale(sign); | 723 topEdge.scale(sign); |
724 rightEdge.scale(sign); | 724 rightEdge.scale(sign); |
725 | 725 |
726 // Create device space quad. | 726 // Create device space quad. |
727 CCLayerQuad deviceQuad(leftEdge, topEdge, rightEdge, bottomEdge); | 727 LayerQuad deviceQuad(leftEdge, topEdge, rightEdge, bottomEdge); |
728 | 728 |
729 // Map device space quad to local space. contentsDeviceTransform has no
3d component since it was generated with to2dTransform() so we don't need to pro
ject. | 729 // Map device space quad to local space. contentsDeviceTransform has no
3d component since it was generated with to2dTransform() so we don't need to pro
ject. |
730 WebTransformationMatrix inverseDeviceTransform = deviceTransform.inverse
(); | 730 WebTransformationMatrix inverseDeviceTransform = deviceTransform.inverse
(); |
731 localQuad = CCMathUtil::mapQuad(inverseDeviceTransform, deviceQuad.float
Quad(), clipped); | 731 localQuad = MathUtil::mapQuad(inverseDeviceTransform, deviceQuad.floatQu
ad(), clipped); |
732 | 732 |
733 // We should not ASSERT(!clipped) here, because anti-aliasing inflation
may cause deviceQuad to become | 733 // We should not ASSERT(!clipped) here, because anti-aliasing inflation
may cause deviceQuad to become |
734 // clipped. To our knowledge this scenario does not need to be handled d
ifferently than the unclipped case. | 734 // clipped. To our knowledge this scenario does not need to be handled d
ifferently than the unclipped case. |
735 } else { | 735 } else { |
736 // Move fragment shader transform to vertex shader. We can do this while | 736 // Move fragment shader transform to vertex shader. We can do this while |
737 // still producing correct results as fragmentTexTransformLocation | 737 // still producing correct results as fragmentTexTransformLocation |
738 // should always be non-negative when tiles are transformed in a way | 738 // should always be non-negative when tiles are transformed in a way |
739 // that could result in sampling outside the layer. | 739 // that could result in sampling outside the layer. |
740 vertexTexScaleX *= fragmentTexScaleX; | 740 vertexTexScaleX *= fragmentTexScaleX; |
741 vertexTexScaleY *= fragmentTexScaleY; | 741 vertexTexScaleY *= fragmentTexScaleY; |
(...skipping 15 matching lines...) Expand all Loading... |
757 | 757 |
758 // The tile quad shader behaves differently compared to all other shaders. | 758 // The tile quad shader behaves differently compared to all other shaders. |
759 // The transform and vertex data are used to figure out the extents that the | 759 // The transform and vertex data are used to figure out the extents that the |
760 // un-antialiased quad should have and which vertex this is and the float | 760 // un-antialiased quad should have and which vertex this is and the float |
761 // quad passed in via uniform is the actual geometry that gets used to draw | 761 // quad passed in via uniform is the actual geometry that gets used to draw |
762 // it. This is why this centered rect is used and not the original quadRect. | 762 // it. This is why this centered rect is used and not the original quadRect. |
763 FloatRect centeredRect(FloatPoint(-0.5 * tileRect.width(), -0.5 * tileRect.h
eight()), tileRect.size()); | 763 FloatRect centeredRect(FloatPoint(-0.5 * tileRect.width(), -0.5 * tileRect.h
eight()), tileRect.size()); |
764 drawQuadGeometry(frame, quad->quadTransform(), centeredRect, uniforms.matrix
Location); | 764 drawQuadGeometry(frame, quad->quadTransform(), centeredRect, uniforms.matrix
Location); |
765 } | 765 } |
766 | 766 |
767 void CCRendererGL::drawYUVVideoQuad(const DrawingFrame& frame, const CCYUVVideoD
rawQuad* quad) | 767 void GLRenderer::drawYUVVideoQuad(const DrawingFrame& frame, const YUVVideoDrawQ
uad* quad) |
768 { | 768 { |
769 const VideoYUVProgram* program = videoYUVProgram(); | 769 const VideoYUVProgram* program = videoYUVProgram(); |
770 ASSERT(program && program->initialized()); | 770 ASSERT(program && program->initialized()); |
771 | 771 |
772 const CCVideoLayerImpl::FramePlane& yPlane = quad->yPlane(); | 772 const VideoLayerImpl::FramePlane& yPlane = quad->yPlane(); |
773 const CCVideoLayerImpl::FramePlane& uPlane = quad->uPlane(); | 773 const VideoLayerImpl::FramePlane& uPlane = quad->uPlane(); |
774 const CCVideoLayerImpl::FramePlane& vPlane = quad->vPlane(); | 774 const VideoLayerImpl::FramePlane& vPlane = quad->vPlane(); |
775 | 775 |
776 CCResourceProvider::ScopedReadLockGL yPlaneLock(m_resourceProvider, yPlane.r
esourceId); | 776 ResourceProvider::ScopedReadLockGL yPlaneLock(m_resourceProvider, yPlane.res
ourceId); |
777 CCResourceProvider::ScopedReadLockGL uPlaneLock(m_resourceProvider, uPlane.r
esourceId); | 777 ResourceProvider::ScopedReadLockGL uPlaneLock(m_resourceProvider, uPlane.res
ourceId); |
778 CCResourceProvider::ScopedReadLockGL vPlaneLock(m_resourceProvider, vPlane.r
esourceId); | 778 ResourceProvider::ScopedReadLockGL vPlaneLock(m_resourceProvider, vPlane.res
ourceId); |
779 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE1)); | 779 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE1)); |
780 GLC(context(), context()->bindTexture(GraphicsContext3D::TEXTURE_2D, yPlaneL
ock.textureId())); | 780 GLC(context(), context()->bindTexture(GraphicsContext3D::TEXTURE_2D, yPlaneL
ock.textureId())); |
781 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE2)); | 781 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE2)); |
782 GLC(context(), context()->bindTexture(GraphicsContext3D::TEXTURE_2D, uPlaneL
ock.textureId())); | 782 GLC(context(), context()->bindTexture(GraphicsContext3D::TEXTURE_2D, uPlaneL
ock.textureId())); |
783 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE3)); | 783 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE3)); |
784 GLC(context(), context()->bindTexture(GraphicsContext3D::TEXTURE_2D, vPlaneL
ock.textureId())); | 784 GLC(context(), context()->bindTexture(GraphicsContext3D::TEXTURE_2D, vPlaneL
ock.textureId())); |
785 | 785 |
786 GLC(context(), context()->useProgram(program->program())); | 786 GLC(context(), context()->useProgram(program->program())); |
787 | 787 |
788 float yWidthScaleFactor = static_cast<float>(yPlane.visibleSize.width()) / y
Plane.size.width(); | 788 float yWidthScaleFactor = static_cast<float>(yPlane.visibleSize.width()) / y
Plane.size.width(); |
789 // Arbitrarily take the u sizes because u and v dimensions are identical. | 789 // Arbitrarily take the u sizes because u and v dimensions are identical. |
790 float uvWidthScaleFactor = static_cast<float>(uPlane.visibleSize.width()) /
uPlane.size.width(); | 790 float uvWidthScaleFactor = static_cast<float>(uPlane.visibleSize.width()) /
uPlane.size.width(); |
791 GLC(context(), context()->uniform1f(program->vertexShader().yWidthScaleFacto
rLocation(), yWidthScaleFactor)); | 791 GLC(context(), context()->uniform1f(program->vertexShader().yWidthScaleFacto
rLocation(), yWidthScaleFactor)); |
792 GLC(context(), context()->uniform1f(program->vertexShader().uvWidthScaleFact
orLocation(), uvWidthScaleFactor)); | 792 GLC(context(), context()->uniform1f(program->vertexShader().uvWidthScaleFact
orLocation(), uvWidthScaleFactor)); |
793 | 793 |
794 GLC(context(), context()->uniform1i(program->fragmentShader().yTextureLocati
on(), 1)); | 794 GLC(context(), context()->uniform1i(program->fragmentShader().yTextureLocati
on(), 1)); |
795 GLC(context(), context()->uniform1i(program->fragmentShader().uTextureLocati
on(), 2)); | 795 GLC(context(), context()->uniform1i(program->fragmentShader().uTextureLocati
on(), 2)); |
796 GLC(context(), context()->uniform1i(program->fragmentShader().vTextureLocati
on(), 3)); | 796 GLC(context(), context()->uniform1i(program->fragmentShader().vTextureLocati
on(), 3)); |
797 | 797 |
798 // These values are magic numbers that are used in the transformation from Y
UV to RGB color values. | 798 // These values are magic numbers that are used in the transformation from Y
UV to RGB color values. |
799 // They are taken from the following webpage: http://www.fourcc.org/fccyvrgb
.php | 799 // They are taken from the following webpage: http://www.fourcc.org/fccyvrgb
.php |
800 float yuv2RGB[9] = { | 800 float yuv2RGB[9] = { |
801 1.164f, 1.164f, 1.164f, | 801 1.164f, 1.164f, 1.164f, |
802 0.f, -.391f, 2.018f, | 802 0.f, -.391f, 2.018f, |
803 1.596f, -.813f, 0.f, | 803 1.596f, -.813f, 0.f, |
804 }; | 804 }; |
805 GLC(context(), context()->uniformMatrix3fv(program->fragmentShader().ccMatri
xLocation(), 1, 0, yuv2RGB)); | 805 GLC(context(), context()->uniformMatrix3fv(program->fragmentShader().matrixL
ocation(), 1, 0, yuv2RGB)); |
806 | 806 |
807 // These values map to 16, 128, and 128 respectively, and are computed | 807 // These values map to 16, 128, and 128 respectively, and are computed |
808 // as a fraction over 256 (e.g. 16 / 256 = 0.0625). | 808 // as a fraction over 256 (e.g. 16 / 256 = 0.0625). |
809 // They are used in the YUV to RGBA conversion formula: | 809 // They are used in the YUV to RGBA conversion formula: |
810 // Y - 16 : Gives 16 values of head and footroom for overshooting | 810 // Y - 16 : Gives 16 values of head and footroom for overshooting |
811 // U - 128 : Turns unsigned U into signed U [-128,127] | 811 // U - 128 : Turns unsigned U into signed U [-128,127] |
812 // V - 128 : Turns unsigned V into signed V [-128,127] | 812 // V - 128 : Turns unsigned V into signed V [-128,127] |
813 float yuvAdjust[3] = { | 813 float yuvAdjust[3] = { |
814 -0.0625f, | 814 -0.0625f, |
815 -0.5f, | 815 -0.5f, |
816 -0.5f, | 816 -0.5f, |
817 }; | 817 }; |
818 GLC(context(), context()->uniform3fv(program->fragmentShader().yuvAdjLocatio
n(), 1, yuvAdjust)); | 818 GLC(context(), context()->uniform3fv(program->fragmentShader().yuvAdjLocatio
n(), 1, yuvAdjust)); |
819 | 819 |
820 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation())
; | 820 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation())
; |
821 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), program->ve
rtexShader().matrixLocation()); | 821 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), program->ve
rtexShader().matrixLocation()); |
822 | 822 |
823 // Reset active texture back to texture 0. | 823 // Reset active texture back to texture 0. |
824 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE0)); | 824 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE0)); |
825 } | 825 } |
826 | 826 |
827 void CCRendererGL::drawStreamVideoQuad(const DrawingFrame& frame, const CCStream
VideoDrawQuad* quad) | 827 void GLRenderer::drawStreamVideoQuad(const DrawingFrame& frame, const StreamVide
oDrawQuad* quad) |
828 { | 828 { |
829 static float glMatrix[16]; | 829 static float glMatrix[16]; |
830 | 830 |
831 ASSERT(m_capabilities.usingEglImage); | 831 ASSERT(m_capabilities.usingEglImage); |
832 | 832 |
833 const VideoStreamTextureProgram* program = videoStreamTextureProgram(); | 833 const VideoStreamTextureProgram* program = videoStreamTextureProgram(); |
834 GLC(context(), context()->useProgram(program->program())); | 834 GLC(context(), context()->useProgram(program->program())); |
835 | 835 |
836 toGLMatrix(&glMatrix[0], quad->matrix()); | 836 toGLMatrix(&glMatrix[0], quad->matrix()); |
837 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().texMatrix
Location(), 1, false, glMatrix)); | 837 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().texMatrix
Location(), 1, false, glMatrix)); |
(...skipping 24 matching lines...) Expand all Loading... |
862 | 862 |
863 struct TexTransformTextureProgramBinding : TextureProgramBinding { | 863 struct TexTransformTextureProgramBinding : TextureProgramBinding { |
864 template<class Program> void set(Program* program) | 864 template<class Program> void set(Program* program) |
865 { | 865 { |
866 TextureProgramBinding::set(program); | 866 TextureProgramBinding::set(program); |
867 texTransformLocation = program->vertexShader().texTransformLocation(); | 867 texTransformLocation = program->vertexShader().texTransformLocation(); |
868 } | 868 } |
869 int texTransformLocation; | 869 int texTransformLocation; |
870 }; | 870 }; |
871 | 871 |
872 void CCRendererGL::drawTextureQuad(const DrawingFrame& frame, const CCTextureDra
wQuad* quad) | 872 void GLRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureDrawQua
d* quad) |
873 { | 873 { |
874 ASSERT(CCProxy::isImplThread()); | 874 ASSERT(Proxy::isImplThread()); |
875 | 875 |
876 TexTransformTextureProgramBinding binding; | 876 TexTransformTextureProgramBinding binding; |
877 if (quad->flipped()) | 877 if (quad->flipped()) |
878 binding.set(textureProgramFlip()); | 878 binding.set(textureProgramFlip()); |
879 else | 879 else |
880 binding.set(textureProgram()); | 880 binding.set(textureProgram()); |
881 GLC(context(), context()->useProgram(binding.programId)); | 881 GLC(context(), context()->useProgram(binding.programId)); |
882 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); | 882 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); |
883 const FloatRect& uvRect = quad->uvRect(); | 883 const FloatRect& uvRect = quad->uvRect(); |
884 GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x()
, uvRect.y(), uvRect.width(), uvRect.height())); | 884 GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x()
, uvRect.y(), uvRect.width(), uvRect.height())); |
885 | 885 |
886 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE0)); | 886 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE0)); |
887 CCResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, qu
ad->resourceId()); | 887 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad
->resourceId()); |
888 GLC(context(), context()->bindTexture(GraphicsContext3D::TEXTURE_2D, quadRes
ourceLock.textureId())); | 888 GLC(context(), context()->bindTexture(GraphicsContext3D::TEXTURE_2D, quadRes
ourceLock.textureId())); |
889 | 889 |
890 // FIXME: setting the texture parameters every time is redundant. Move this
code somewhere | 890 // FIXME: setting the texture parameters every time is redundant. Move this
code somewhere |
891 // where it will only happen once per texture. | 891 // where it will only happen once per texture. |
892 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR)); | 892 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR)); |
893 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR)); | 893 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR)); |
894 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE)); | 894 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE)); |
895 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE)); | 895 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE)); |
896 | 896 |
897 if (!quad->premultipliedAlpha()) { | 897 if (!quad->premultipliedAlpha()) { |
898 // As it turns out, the premultiplied alpha blending function (ONE, ONE_
MINUS_SRC_ALPHA) | 898 // As it turns out, the premultiplied alpha blending function (ONE, ONE_
MINUS_SRC_ALPHA) |
899 // will never cause the alpha channel to be set to anything less than 1.
0 if it is | 899 // will never cause the alpha channel to be set to anything less than 1.
0 if it is |
900 // initialized to that value! Therefore, premultipliedAlpha being false
is the first | 900 // initialized to that value! Therefore, premultipliedAlpha being false
is the first |
901 // situation we can generally see an alpha channel less than 1.0 coming
out of the | 901 // situation we can generally see an alpha channel less than 1.0 coming
out of the |
902 // compositor. This is causing platform differences in some layout tests
(see | 902 // compositor. This is causing platform differences in some layout tests
(see |
903 // https://bugs.webkit.org/show_bug.cgi?id=82412), so in this situation,
use a separate | 903 // https://bugs.webkit.org/show_bug.cgi?id=82412), so in this situation,
use a separate |
904 // blend function for the alpha channel to avoid modifying it. Don't use
colorMask for this | 904 // blend function for the alpha channel to avoid modifying it. Don't use
colorMask for this |
905 // as it has performance implications on some platforms. | 905 // as it has performance implications on some platforms. |
906 GLC(context(), context()->blendFuncSeparate(GraphicsContext3D::SRC_ALPHA
, GraphicsContext3D::ONE_MINUS_SRC_ALPHA, GraphicsContext3D::ZERO, GraphicsConte
xt3D::ONE)); | 906 GLC(context(), context()->blendFuncSeparate(GraphicsContext3D::SRC_ALPHA
, GraphicsContext3D::ONE_MINUS_SRC_ALPHA, GraphicsContext3D::ZERO, GraphicsConte
xt3D::ONE)); |
907 } | 907 } |
908 | 908 |
909 setShaderOpacity(quad->opacity(), binding.alphaLocation); | 909 setShaderOpacity(quad->opacity(), binding.alphaLocation); |
910 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), binding.mat
rixLocation); | 910 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), binding.mat
rixLocation); |
911 | 911 |
912 if (!quad->premultipliedAlpha()) | 912 if (!quad->premultipliedAlpha()) |
913 GLC(m_context, m_context->blendFunc(GraphicsContext3D::ONE, GraphicsCont
ext3D::ONE_MINUS_SRC_ALPHA)); | 913 GLC(m_context, m_context->blendFunc(GraphicsContext3D::ONE, GraphicsCont
ext3D::ONE_MINUS_SRC_ALPHA)); |
914 } | 914 } |
915 | 915 |
916 void CCRendererGL::drawIOSurfaceQuad(const DrawingFrame& frame, const CCIOSurfac
eDrawQuad* quad) | 916 void GLRenderer::drawIOSurfaceQuad(const DrawingFrame& frame, const IOSurfaceDra
wQuad* quad) |
917 { | 917 { |
918 ASSERT(CCProxy::isImplThread()); | 918 ASSERT(Proxy::isImplThread()); |
919 TexTransformTextureProgramBinding binding; | 919 TexTransformTextureProgramBinding binding; |
920 binding.set(textureIOSurfaceProgram()); | 920 binding.set(textureIOSurfaceProgram()); |
921 | 921 |
922 GLC(context(), context()->useProgram(binding.programId)); | 922 GLC(context(), context()->useProgram(binding.programId)); |
923 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); | 923 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); |
924 if (quad->orientation() == CCIOSurfaceDrawQuad::Flipped) | 924 if (quad->orientation() == IOSurfaceDrawQuad::Flipped) |
925 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, qua
d->ioSurfaceSize().height(), quad->ioSurfaceSize().width(), quad->ioSurfaceSize(
).height() * -1.0)); | 925 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, qua
d->ioSurfaceSize().height(), quad->ioSurfaceSize().width(), quad->ioSurfaceSize(
).height() * -1.0)); |
926 else | 926 else |
927 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0,
quad->ioSurfaceSize().width(), quad->ioSurfaceSize().height())); | 927 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0,
quad->ioSurfaceSize().width(), quad->ioSurfaceSize().height())); |
928 | 928 |
929 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE0)); | 929 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE0)); |
930 GLC(context(), context()->bindTexture(Extensions3D::TEXTURE_RECTANGLE_ARB, q
uad->ioSurfaceTextureId())); | 930 GLC(context(), context()->bindTexture(Extensions3D::TEXTURE_RECTANGLE_ARB, q
uad->ioSurfaceTextureId())); |
931 | 931 |
932 setShaderOpacity(quad->opacity(), binding.alphaLocation); | 932 setShaderOpacity(quad->opacity(), binding.alphaLocation); |
933 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), binding.mat
rixLocation); | 933 drawQuadGeometry(frame, quad->quadTransform(), quad->quadRect(), binding.mat
rixLocation); |
934 | 934 |
935 GLC(context(), context()->bindTexture(Extensions3D::TEXTURE_RECTANGLE_ARB, 0
)); | 935 GLC(context(), context()->bindTexture(Extensions3D::TEXTURE_RECTANGLE_ARB, 0
)); |
936 } | 936 } |
937 | 937 |
938 void CCRendererGL::finishDrawingFrame(DrawingFrame& frame) | 938 void GLRenderer::finishDrawingFrame(DrawingFrame& frame) |
939 { | 939 { |
940 m_currentFramebufferLock.reset(); | 940 m_currentFramebufferLock.reset(); |
941 m_swapBufferRect.unite(enclosingIntRect(frame.rootDamageRect)); | 941 m_swapBufferRect.unite(enclosingIntRect(frame.rootDamageRect)); |
942 | 942 |
943 GLC(m_context, m_context->disable(GraphicsContext3D::SCISSOR_TEST)); | 943 GLC(m_context, m_context->disable(GraphicsContext3D::SCISSOR_TEST)); |
944 GLC(m_context, m_context->disable(GraphicsContext3D::BLEND)); | 944 GLC(m_context, m_context->disable(GraphicsContext3D::BLEND)); |
945 } | 945 } |
946 | 946 |
947 bool CCRendererGL::flippedFramebuffer() const | 947 bool GLRenderer::flippedFramebuffer() const |
948 { | 948 { |
949 return true; | 949 return true; |
950 } | 950 } |
951 | 951 |
952 void CCRendererGL::toGLMatrix(float* flattened, const WebTransformationMatrix& m
) | 952 void GLRenderer::toGLMatrix(float* flattened, const WebTransformationMatrix& m) |
953 { | 953 { |
954 flattened[0] = m.m11(); | 954 flattened[0] = m.m11(); |
955 flattened[1] = m.m12(); | 955 flattened[1] = m.m12(); |
956 flattened[2] = m.m13(); | 956 flattened[2] = m.m13(); |
957 flattened[3] = m.m14(); | 957 flattened[3] = m.m14(); |
958 flattened[4] = m.m21(); | 958 flattened[4] = m.m21(); |
959 flattened[5] = m.m22(); | 959 flattened[5] = m.m22(); |
960 flattened[6] = m.m23(); | 960 flattened[6] = m.m23(); |
961 flattened[7] = m.m24(); | 961 flattened[7] = m.m24(); |
962 flattened[8] = m.m31(); | 962 flattened[8] = m.m31(); |
963 flattened[9] = m.m32(); | 963 flattened[9] = m.m32(); |
964 flattened[10] = m.m33(); | 964 flattened[10] = m.m33(); |
965 flattened[11] = m.m34(); | 965 flattened[11] = m.m34(); |
966 flattened[12] = m.m41(); | 966 flattened[12] = m.m41(); |
967 flattened[13] = m.m42(); | 967 flattened[13] = m.m42(); |
968 flattened[14] = m.m43(); | 968 flattened[14] = m.m43(); |
969 flattened[15] = m.m44(); | 969 flattened[15] = m.m44(); |
970 } | 970 } |
971 | 971 |
972 void CCRendererGL::setShaderFloatQuad(const FloatQuad& quad, int quadLocation) | 972 void GLRenderer::setShaderFloatQuad(const FloatQuad& quad, int quadLocation) |
973 { | 973 { |
974 if (quadLocation == -1) | 974 if (quadLocation == -1) |
975 return; | 975 return; |
976 | 976 |
977 float point[8]; | 977 float point[8]; |
978 point[0] = quad.p1().x(); | 978 point[0] = quad.p1().x(); |
979 point[1] = quad.p1().y(); | 979 point[1] = quad.p1().y(); |
980 point[2] = quad.p2().x(); | 980 point[2] = quad.p2().x(); |
981 point[3] = quad.p2().y(); | 981 point[3] = quad.p2().y(); |
982 point[4] = quad.p3().x(); | 982 point[4] = quad.p3().x(); |
983 point[5] = quad.p3().y(); | 983 point[5] = quad.p3().y(); |
984 point[6] = quad.p4().x(); | 984 point[6] = quad.p4().x(); |
985 point[7] = quad.p4().y(); | 985 point[7] = quad.p4().y(); |
986 GLC(m_context, m_context->uniform2fv(quadLocation, 4, point)); | 986 GLC(m_context, m_context->uniform2fv(quadLocation, 4, point)); |
987 } | 987 } |
988 | 988 |
989 void CCRendererGL::setShaderOpacity(float opacity, int alphaLocation) | 989 void GLRenderer::setShaderOpacity(float opacity, int alphaLocation) |
990 { | 990 { |
991 if (alphaLocation != -1) | 991 if (alphaLocation != -1) |
992 GLC(m_context, m_context->uniform1f(alphaLocation, opacity)); | 992 GLC(m_context, m_context->uniform1f(alphaLocation, opacity)); |
993 } | 993 } |
994 | 994 |
995 void CCRendererGL::drawQuadGeometry(const DrawingFrame& frame, const WebKit::Web
TransformationMatrix& drawTransform, const FloatRect& quadRect, int matrixLocati
on) | 995 void GLRenderer::drawQuadGeometry(const DrawingFrame& frame, const WebKit::WebTr
ansformationMatrix& drawTransform, const FloatRect& quadRect, int matrixLocation
) |
996 { | 996 { |
997 WebTransformationMatrix quadRectMatrix; | 997 WebTransformationMatrix quadRectMatrix; |
998 quadRectTransform(&quadRectMatrix, drawTransform, quadRect); | 998 quadRectTransform(&quadRectMatrix, drawTransform, quadRect); |
999 static float glMatrix[16]; | 999 static float glMatrix[16]; |
1000 toGLMatrix(&glMatrix[0], frame.projectionMatrix * quadRectMatrix); | 1000 toGLMatrix(&glMatrix[0], frame.projectionMatrix * quadRectMatrix); |
1001 GLC(m_context, m_context->uniformMatrix4fv(matrixLocation, 1, false, &glMatr
ix[0])); | 1001 GLC(m_context, m_context->uniformMatrix4fv(matrixLocation, 1, false, &glMatr
ix[0])); |
1002 | 1002 |
1003 GLC(m_context, m_context->drawElements(GraphicsContext3D::TRIANGLES, 6, Grap
hicsContext3D::UNSIGNED_SHORT, 0)); | 1003 GLC(m_context, m_context->drawElements(GraphicsContext3D::TRIANGLES, 6, Grap
hicsContext3D::UNSIGNED_SHORT, 0)); |
1004 } | 1004 } |
1005 | 1005 |
1006 void CCRendererGL::copyTextureToFramebuffer(const DrawingFrame& frame, int textu
reId, const IntRect& rect, const WebTransformationMatrix& drawMatrix) | 1006 void GLRenderer::copyTextureToFramebuffer(const DrawingFrame& frame, int texture
Id, const IntRect& rect, const WebTransformationMatrix& drawMatrix) |
1007 { | 1007 { |
1008 const RenderPassProgram* program = renderPassProgram(); | 1008 const RenderPassProgram* program = renderPassProgram(); |
1009 | 1009 |
1010 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE0)); | 1010 GLC(context(), context()->activeTexture(GraphicsContext3D::TEXTURE0)); |
1011 GLC(context(), context()->bindTexture(GraphicsContext3D::TEXTURE_2D, texture
Id)); | 1011 GLC(context(), context()->bindTexture(GraphicsContext3D::TEXTURE_2D, texture
Id)); |
1012 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR)); | 1012 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR)); |
1013 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR)); | 1013 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR)); |
1014 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE)); | 1014 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE)); |
1015 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE)); | 1015 GLC(context(), context()->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE)); |
1016 | 1016 |
1017 GLC(context(), context()->useProgram(program->program())); | 1017 GLC(context(), context()->useProgram(program->program())); |
1018 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio
n(), 0)); | 1018 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio
n(), 0)); |
1019 setShaderOpacity(1, program->fragmentShader().alphaLocation()); | 1019 setShaderOpacity(1, program->fragmentShader().alphaLocation()); |
1020 drawQuadGeometry(frame, drawMatrix, rect, program->vertexShader().matrixLoca
tion()); | 1020 drawQuadGeometry(frame, drawMatrix, rect, program->vertexShader().matrixLoca
tion()); |
1021 } | 1021 } |
1022 | 1022 |
1023 void CCRendererGL::finish() | 1023 void GLRenderer::finish() |
1024 { | 1024 { |
1025 TRACE_EVENT0("cc", "CCRendererGL::finish"); | 1025 TRACE_EVENT0("cc", "GLRenderer::finish"); |
1026 m_context->finish(); | 1026 m_context->finish(); |
1027 } | 1027 } |
1028 | 1028 |
1029 bool CCRendererGL::swapBuffers() | 1029 bool GLRenderer::swapBuffers() |
1030 { | 1030 { |
1031 ASSERT(m_visible); | 1031 ASSERT(m_visible); |
1032 ASSERT(!m_isFramebufferDiscarded); | 1032 ASSERT(!m_isFramebufferDiscarded); |
1033 | 1033 |
1034 TRACE_EVENT0("cc", "CCRendererGL::swapBuffers"); | 1034 TRACE_EVENT0("cc", "GLRenderer::swapBuffers"); |
1035 // We're done! Time to swapbuffers! | 1035 // We're done! Time to swapbuffers! |
1036 | 1036 |
1037 if (m_capabilities.usingPartialSwap) { | 1037 if (m_capabilities.usingPartialSwap) { |
1038 // If supported, we can save significant bandwidth by only swapping the
damaged/scissored region (clamped to the viewport) | 1038 // If supported, we can save significant bandwidth by only swapping the
damaged/scissored region (clamped to the viewport) |
1039 m_swapBufferRect.intersect(IntRect(IntPoint(), viewportSize())); | 1039 m_swapBufferRect.intersect(IntRect(IntPoint(), viewportSize())); |
1040 int flippedYPosOfRectBottom = viewportHeight() - m_swapBufferRect.y() -
m_swapBufferRect.height(); | 1040 int flippedYPosOfRectBottom = viewportHeight() - m_swapBufferRect.y() -
m_swapBufferRect.height(); |
1041 m_context->postSubBufferCHROMIUM(m_swapBufferRect.x(), flippedYPosOfRect
Bottom, m_swapBufferRect.width(), m_swapBufferRect.height()); | 1041 m_context->postSubBufferCHROMIUM(m_swapBufferRect.x(), flippedYPosOfRect
Bottom, m_swapBufferRect.width(), m_swapBufferRect.height()); |
1042 } else { | 1042 } else { |
1043 // Note that currently this has the same effect as swapBuffers; we shoul
d | 1043 // Note that currently this has the same effect as swapBuffers; we shoul
d |
1044 // consider exposing a different entry point on WebGraphicsContext3D. | 1044 // consider exposing a different entry point on WebGraphicsContext3D. |
1045 m_context->prepareTexture(); | 1045 m_context->prepareTexture(); |
1046 } | 1046 } |
1047 | 1047 |
1048 m_swapBufferRect = IntRect(); | 1048 m_swapBufferRect = IntRect(); |
1049 | 1049 |
1050 return true; | 1050 return true; |
1051 } | 1051 } |
1052 | 1052 |
1053 void CCRendererGL::onSwapBuffersComplete() | 1053 void GLRenderer::onSwapBuffersComplete() |
1054 { | 1054 { |
1055 m_client->onSwapBuffersComplete(); | 1055 m_client->onSwapBuffersComplete(); |
1056 } | 1056 } |
1057 | 1057 |
1058 void CCRendererGL::onMemoryAllocationChanged(WebGraphicsMemoryAllocation allocat
ion) | 1058 void GLRenderer::onMemoryAllocationChanged(WebGraphicsMemoryAllocation allocatio
n) |
1059 { | 1059 { |
1060 // FIXME: This is called on the main thread in single threaded mode, but we
expect it on the impl thread. | 1060 // FIXME: This is called on the main thread in single threaded mode, but we
expect it on the impl thread. |
1061 if (!CCProxy::hasImplThread()) { | 1061 if (!Proxy::hasImplThread()) { |
1062 ASSERT(CCProxy::isMainThread()); | 1062 ASSERT(Proxy::isMainThread()); |
1063 DebugScopedSetImplThread impl; | 1063 DebugScopedSetImplThread impl; |
1064 onMemoryAllocationChangedOnImplThread(allocation); | 1064 onMemoryAllocationChangedOnImplThread(allocation); |
1065 } else { | 1065 } else { |
1066 ASSERT(CCProxy::isImplThread()); | 1066 ASSERT(Proxy::isImplThread()); |
1067 onMemoryAllocationChangedOnImplThread(allocation); | 1067 onMemoryAllocationChangedOnImplThread(allocation); |
1068 } | 1068 } |
1069 } | 1069 } |
1070 | 1070 |
1071 void CCRendererGL::onMemoryAllocationChangedOnImplThread(WebKit::WebGraphicsMemo
ryAllocation allocation) | 1071 void GLRenderer::onMemoryAllocationChangedOnImplThread(WebKit::WebGraphicsMemory
Allocation allocation) |
1072 { | 1072 { |
1073 m_discardFramebufferWhenNotVisible = !allocation.suggestHaveBackbuffer; | 1073 m_discardFramebufferWhenNotVisible = !allocation.suggestHaveBackbuffer; |
1074 // Just ignore the memory manager when it says to set the limit to zero | 1074 // Just ignore the memory manager when it says to set the limit to zero |
1075 // bytes. This will happen when the memory manager thinks that the renderer | 1075 // bytes. This will happen when the memory manager thinks that the renderer |
1076 // is not visible (which the renderer knows better). | 1076 // is not visible (which the renderer knows better). |
1077 if (allocation.gpuResourceSizeInBytes) | 1077 if (allocation.gpuResourceSizeInBytes) |
1078 m_client->setMemoryAllocationLimitBytes(allocation.gpuResourceSizeInByte
s); | 1078 m_client->setMemoryAllocationLimitBytes(allocation.gpuResourceSizeInByte
s); |
1079 enforceMemoryPolicy(); | 1079 enforceMemoryPolicy(); |
1080 } | 1080 } |
1081 | 1081 |
1082 void CCRendererGL::enforceMemoryPolicy() | 1082 void GLRenderer::enforceMemoryPolicy() |
1083 { | 1083 { |
1084 if (!m_visible) { | 1084 if (!m_visible) { |
1085 TRACE_EVENT0("cc", "CCRendererGL::enforceMemoryPolicy dropping resources
"); | 1085 TRACE_EVENT0("cc", "GLRenderer::enforceMemoryPolicy dropping resources")
; |
1086 releaseRenderPassTextures(); | 1086 releaseRenderPassTextures(); |
1087 if (m_discardFramebufferWhenNotVisible) | 1087 if (m_discardFramebufferWhenNotVisible) |
1088 discardFramebuffer(); | 1088 discardFramebuffer(); |
1089 GLC(m_context, m_context->flush()); | 1089 GLC(m_context, m_context->flush()); |
1090 } | 1090 } |
1091 } | 1091 } |
1092 | 1092 |
1093 void CCRendererGL::discardFramebuffer() | 1093 void GLRenderer::discardFramebuffer() |
1094 { | 1094 { |
1095 if (m_isFramebufferDiscarded) | 1095 if (m_isFramebufferDiscarded) |
1096 return; | 1096 return; |
1097 | 1097 |
1098 if (!m_capabilities.usingDiscardFramebuffer) | 1098 if (!m_capabilities.usingDiscardFramebuffer) |
1099 return; | 1099 return; |
1100 | 1100 |
1101 // FIXME: Update attachments argument to appropriate values once they are no
longer ignored. | 1101 // FIXME: Update attachments argument to appropriate values once they are no
longer ignored. |
1102 m_context->discardFramebufferEXT(GraphicsContext3D::TEXTURE_2D, 0, 0); | 1102 m_context->discardFramebufferEXT(GraphicsContext3D::TEXTURE_2D, 0, 0); |
1103 m_isFramebufferDiscarded = true; | 1103 m_isFramebufferDiscarded = true; |
1104 | 1104 |
1105 // Damage tracker needs a full reset every time framebuffer is discarded. | 1105 // Damage tracker needs a full reset every time framebuffer is discarded. |
1106 m_client->setFullRootLayerDamage(); | 1106 m_client->setFullRootLayerDamage(); |
1107 } | 1107 } |
1108 | 1108 |
1109 void CCRendererGL::ensureFramebuffer() | 1109 void GLRenderer::ensureFramebuffer() |
1110 { | 1110 { |
1111 if (!m_isFramebufferDiscarded) | 1111 if (!m_isFramebufferDiscarded) |
1112 return; | 1112 return; |
1113 | 1113 |
1114 if (!m_capabilities.usingDiscardFramebuffer) | 1114 if (!m_capabilities.usingDiscardFramebuffer) |
1115 return; | 1115 return; |
1116 | 1116 |
1117 m_context->ensureFramebufferCHROMIUM(); | 1117 m_context->ensureFramebufferCHROMIUM(); |
1118 m_isFramebufferDiscarded = false; | 1118 m_isFramebufferDiscarded = false; |
1119 } | 1119 } |
1120 | 1120 |
1121 void CCRendererGL::onContextLost() | 1121 void GLRenderer::onContextLost() |
1122 { | 1122 { |
1123 m_client->didLoseContext(); | 1123 m_client->didLoseContext(); |
1124 } | 1124 } |
1125 | 1125 |
1126 | 1126 |
1127 void CCRendererGL::getFramebufferPixels(void *pixels, const IntRect& rect) | 1127 void GLRenderer::getFramebufferPixels(void *pixels, const IntRect& rect) |
1128 { | 1128 { |
1129 ASSERT(rect.maxX() <= viewportWidth() && rect.maxY() <= viewportHeight()); | 1129 ASSERT(rect.maxX() <= viewportWidth() && rect.maxY() <= viewportHeight()); |
1130 | 1130 |
1131 if (!pixels) | 1131 if (!pixels) |
1132 return; | 1132 return; |
1133 | 1133 |
1134 makeContextCurrent(); | 1134 makeContextCurrent(); |
1135 | 1135 |
1136 bool doWorkaround = needsIOSurfaceReadbackWorkaround(); | 1136 bool doWorkaround = needsIOSurfaceReadbackWorkaround(); |
1137 | 1137 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 // Clean up. | 1184 // Clean up. |
1185 GLC(m_context, m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER
, 0)); | 1185 GLC(m_context, m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER
, 0)); |
1186 GLC(m_context, m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0))
; | 1186 GLC(m_context, m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0))
; |
1187 GLC(m_context, m_context->deleteFramebuffer(temporaryFBO)); | 1187 GLC(m_context, m_context->deleteFramebuffer(temporaryFBO)); |
1188 GLC(m_context, m_context->deleteTexture(temporaryTexture)); | 1188 GLC(m_context, m_context->deleteTexture(temporaryTexture)); |
1189 } | 1189 } |
1190 | 1190 |
1191 enforceMemoryPolicy(); | 1191 enforceMemoryPolicy(); |
1192 } | 1192 } |
1193 | 1193 |
1194 bool CCRendererGL::getFramebufferTexture(CCScopedTexture* texture, const IntRect
& deviceRect) | 1194 bool GLRenderer::getFramebufferTexture(ScopedTexture* texture, const IntRect& de
viceRect) |
1195 { | 1195 { |
1196 ASSERT(!texture->id() || (texture->size() == deviceRect.size() && texture->f
ormat() == GraphicsContext3D::RGB)); | 1196 ASSERT(!texture->id() || (texture->size() == deviceRect.size() && texture->f
ormat() == GraphicsContext3D::RGB)); |
1197 | 1197 |
1198 if (!texture->id() && !texture->allocate(CCRenderer::ImplPool, deviceRect.si
ze(), GraphicsContext3D::RGB, CCResourceProvider::TextureUsageAny)) | 1198 if (!texture->id() && !texture->allocate(Renderer::ImplPool, deviceRect.size
(), GraphicsContext3D::RGB, ResourceProvider::TextureUsageAny)) |
1199 return false; | 1199 return false; |
1200 | 1200 |
1201 CCResourceProvider::ScopedWriteLockGL lock(m_resourceProvider, texture->id()
); | 1201 ResourceProvider::ScopedWriteLockGL lock(m_resourceProvider, texture->id()); |
1202 GLC(m_context, m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, lock.te
xtureId())); | 1202 GLC(m_context, m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, lock.te
xtureId())); |
1203 GLC(m_context, m_context->copyTexImage2D(GraphicsContext3D::TEXTURE_2D, 0, t
exture->format(), | 1203 GLC(m_context, m_context->copyTexImage2D(GraphicsContext3D::TEXTURE_2D, 0, t
exture->format(), |
1204 deviceRect.x(), deviceRect.y(), dev
iceRect.width(), deviceRect.height(), 0)); | 1204 deviceRect.x(), deviceRect.y(), dev
iceRect.width(), deviceRect.height(), 0)); |
1205 return true; | 1205 return true; |
1206 } | 1206 } |
1207 | 1207 |
1208 bool CCRendererGL::useScopedTexture(DrawingFrame& frame, const CCScopedTexture*
texture, const IntRect& viewportRect) | 1208 bool GLRenderer::useScopedTexture(DrawingFrame& frame, const ScopedTexture* text
ure, const IntRect& viewportRect) |
1209 { | 1209 { |
1210 ASSERT(texture->id()); | 1210 ASSERT(texture->id()); |
1211 frame.currentRenderPass = 0; | 1211 frame.currentRenderPass = 0; |
1212 frame.currentTexture = texture; | 1212 frame.currentTexture = texture; |
1213 | 1213 |
1214 return bindFramebufferToTexture(frame, texture, viewportRect); | 1214 return bindFramebufferToTexture(frame, texture, viewportRect); |
1215 } | 1215 } |
1216 | 1216 |
1217 void CCRendererGL::bindFramebufferToOutputSurface(DrawingFrame& frame) | 1217 void GLRenderer::bindFramebufferToOutputSurface(DrawingFrame& frame) |
1218 { | 1218 { |
1219 m_currentFramebufferLock.reset(); | 1219 m_currentFramebufferLock.reset(); |
1220 GLC(m_context, m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0)
); | 1220 GLC(m_context, m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0)
); |
1221 } | 1221 } |
1222 | 1222 |
1223 bool CCRendererGL::bindFramebufferToTexture(DrawingFrame& frame, const CCScopedT
exture* texture, const IntRect& framebufferRect) | 1223 bool GLRenderer::bindFramebufferToTexture(DrawingFrame& frame, const ScopedTextu
re* texture, const IntRect& framebufferRect) |
1224 { | 1224 { |
1225 ASSERT(texture->id()); | 1225 ASSERT(texture->id()); |
1226 | 1226 |
1227 GLC(m_context, m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_
offscreenFramebufferId)); | 1227 GLC(m_context, m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_
offscreenFramebufferId)); |
1228 m_currentFramebufferLock = make_scoped_ptr(new CCResourceProvider::ScopedWri
teLockGL(m_resourceProvider, texture->id())); | 1228 m_currentFramebufferLock = make_scoped_ptr(new ResourceProvider::ScopedWrite
LockGL(m_resourceProvider, texture->id())); |
1229 unsigned textureId = m_currentFramebufferLock->textureId(); | 1229 unsigned textureId = m_currentFramebufferLock->textureId(); |
1230 GLC(m_context, m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFE
R, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, textureI
d, 0)); | 1230 GLC(m_context, m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFE
R, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, textureI
d, 0)); |
1231 | 1231 |
1232 #if !defined ( NDEBUG ) | 1232 #if !defined ( NDEBUG ) |
1233 if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != Gra
phicsContext3D::FRAMEBUFFER_COMPLETE) { | 1233 if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != Gra
phicsContext3D::FRAMEBUFFER_COMPLETE) { |
1234 ASSERT_NOT_REACHED(); | 1234 ASSERT_NOT_REACHED(); |
1235 return false; | 1235 return false; |
1236 } | 1236 } |
1237 #endif | 1237 #endif |
1238 | 1238 |
1239 initializeMatrices(frame, framebufferRect, false); | 1239 initializeMatrices(frame, framebufferRect, false); |
1240 setDrawViewportSize(framebufferRect.size()); | 1240 setDrawViewportSize(framebufferRect.size()); |
1241 | 1241 |
1242 return true; | 1242 return true; |
1243 } | 1243 } |
1244 | 1244 |
1245 void CCRendererGL::enableScissorTestRect(const IntRect& scissorRect) | 1245 void GLRenderer::enableScissorTestRect(const IntRect& scissorRect) |
1246 { | 1246 { |
1247 GLC(m_context, m_context->enable(GraphicsContext3D::SCISSOR_TEST)); | 1247 GLC(m_context, m_context->enable(GraphicsContext3D::SCISSOR_TEST)); |
1248 GLC(m_context, m_context->scissor(scissorRect.x(), scissorRect.y(), scissorR
ect.width(), scissorRect.height())); | 1248 GLC(m_context, m_context->scissor(scissorRect.x(), scissorRect.y(), scissorR
ect.width(), scissorRect.height())); |
1249 } | 1249 } |
1250 | 1250 |
1251 void CCRendererGL::disableScissorTest() | 1251 void GLRenderer::disableScissorTest() |
1252 { | 1252 { |
1253 GLC(m_context, m_context->disable(GraphicsContext3D::SCISSOR_TEST)); | 1253 GLC(m_context, m_context->disable(GraphicsContext3D::SCISSOR_TEST)); |
1254 } | 1254 } |
1255 | 1255 |
1256 void CCRendererGL::setDrawViewportSize(const IntSize& viewportSize) | 1256 void GLRenderer::setDrawViewportSize(const IntSize& viewportSize) |
1257 { | 1257 { |
1258 GLC(m_context, m_context->viewport(0, 0, viewportSize.width(), viewportSize.
height())); | 1258 GLC(m_context, m_context->viewport(0, 0, viewportSize.width(), viewportSize.
height())); |
1259 } | 1259 } |
1260 | 1260 |
1261 bool CCRendererGL::makeContextCurrent() | 1261 bool GLRenderer::makeContextCurrent() |
1262 { | 1262 { |
1263 return m_context->makeContextCurrent(); | 1263 return m_context->makeContextCurrent(); |
1264 } | 1264 } |
1265 | 1265 |
1266 bool CCRendererGL::initializeSharedObjects() | 1266 bool GLRenderer::initializeSharedObjects() |
1267 { | 1267 { |
1268 TRACE_EVENT0("cc", "CCRendererGL::initializeSharedObjects"); | 1268 TRACE_EVENT0("cc", "GLRenderer::initializeSharedObjects"); |
1269 makeContextCurrent(); | 1269 makeContextCurrent(); |
1270 | 1270 |
1271 // Create an FBO for doing offscreen rendering. | 1271 // Create an FBO for doing offscreen rendering. |
1272 GLC(m_context, m_offscreenFramebufferId = m_context->createFramebuffer()); | 1272 GLC(m_context, m_offscreenFramebufferId = m_context->createFramebuffer()); |
1273 | 1273 |
1274 // We will always need these programs to render, so create the programs eage
rly so that the shader compilation can | 1274 // We will always need these programs to render, so create the programs eage
rly so that the shader compilation can |
1275 // start while we do other work. Other programs are created lazily on first
access. | 1275 // start while we do other work. Other programs are created lazily on first
access. |
1276 m_sharedGeometry = make_scoped_ptr(new GeometryBinding(m_context, quadVertex
Rect())); | 1276 m_sharedGeometry = make_scoped_ptr(new GeometryBinding(m_context, quadVertex
Rect())); |
1277 m_renderPassProgram = make_scoped_ptr(new RenderPassProgram(m_context)); | 1277 m_renderPassProgram = make_scoped_ptr(new RenderPassProgram(m_context)); |
1278 m_tileProgram = make_scoped_ptr(new TileProgram(m_context)); | 1278 m_tileProgram = make_scoped_ptr(new TileProgram(m_context)); |
1279 m_tileProgramOpaque = make_scoped_ptr(new TileProgramOpaque(m_context)); | 1279 m_tileProgramOpaque = make_scoped_ptr(new TileProgramOpaque(m_context)); |
1280 | 1280 |
1281 GLC(m_context, m_context->flush()); | 1281 GLC(m_context, m_context->flush()); |
1282 | 1282 |
1283 return true; | 1283 return true; |
1284 } | 1284 } |
1285 | 1285 |
1286 const CCRendererGL::TileCheckerboardProgram* CCRendererGL::tileCheckerboardProgr
am() | 1286 const GLRenderer::TileCheckerboardProgram* GLRenderer::tileCheckerboardProgram() |
1287 { | 1287 { |
1288 if (!m_tileCheckerboardProgram) | 1288 if (!m_tileCheckerboardProgram) |
1289 m_tileCheckerboardProgram = make_scoped_ptr(new TileCheckerboardProgram(
m_context)); | 1289 m_tileCheckerboardProgram = make_scoped_ptr(new TileCheckerboardProgram(
m_context)); |
1290 if (!m_tileCheckerboardProgram->initialized()) { | 1290 if (!m_tileCheckerboardProgram->initialized()) { |
1291 TRACE_EVENT0("cc", "CCRendererGL::checkerboardProgram::initalize"); | 1291 TRACE_EVENT0("cc", "GLRenderer::checkerboardProgram::initalize"); |
1292 m_tileCheckerboardProgram->initialize(m_context, m_isUsingBindUniform); | 1292 m_tileCheckerboardProgram->initialize(m_context, m_isUsingBindUniform); |
1293 } | 1293 } |
1294 return m_tileCheckerboardProgram.get(); | 1294 return m_tileCheckerboardProgram.get(); |
1295 } | 1295 } |
1296 | 1296 |
1297 const CCRendererGL::SolidColorProgram* CCRendererGL::solidColorProgram() | 1297 const GLRenderer::SolidColorProgram* GLRenderer::solidColorProgram() |
1298 { | 1298 { |
1299 if (!m_solidColorProgram) | 1299 if (!m_solidColorProgram) |
1300 m_solidColorProgram = make_scoped_ptr(new SolidColorProgram(m_context)); | 1300 m_solidColorProgram = make_scoped_ptr(new SolidColorProgram(m_context)); |
1301 if (!m_solidColorProgram->initialized()) { | 1301 if (!m_solidColorProgram->initialized()) { |
1302 TRACE_EVENT0("cc", "CCRendererGL::solidColorProgram::initialize"); | 1302 TRACE_EVENT0("cc", "GLRenderer::solidColorProgram::initialize"); |
1303 m_solidColorProgram->initialize(m_context, m_isUsingBindUniform); | 1303 m_solidColorProgram->initialize(m_context, m_isUsingBindUniform); |
1304 } | 1304 } |
1305 return m_solidColorProgram.get(); | 1305 return m_solidColorProgram.get(); |
1306 } | 1306 } |
1307 | 1307 |
1308 const CCRendererGL::RenderPassProgram* CCRendererGL::renderPassProgram() | 1308 const GLRenderer::RenderPassProgram* GLRenderer::renderPassProgram() |
1309 { | 1309 { |
1310 ASSERT(m_renderPassProgram); | 1310 ASSERT(m_renderPassProgram); |
1311 if (!m_renderPassProgram->initialized()) { | 1311 if (!m_renderPassProgram->initialized()) { |
1312 TRACE_EVENT0("cc", "CCRendererGL::renderPassProgram::initialize"); | 1312 TRACE_EVENT0("cc", "GLRenderer::renderPassProgram::initialize"); |
1313 m_renderPassProgram->initialize(m_context, m_isUsingBindUniform); | 1313 m_renderPassProgram->initialize(m_context, m_isUsingBindUniform); |
1314 } | 1314 } |
1315 return m_renderPassProgram.get(); | 1315 return m_renderPassProgram.get(); |
1316 } | 1316 } |
1317 | 1317 |
1318 const CCRendererGL::RenderPassProgramAA* CCRendererGL::renderPassProgramAA() | 1318 const GLRenderer::RenderPassProgramAA* GLRenderer::renderPassProgramAA() |
1319 { | 1319 { |
1320 if (!m_renderPassProgramAA) | 1320 if (!m_renderPassProgramAA) |
1321 m_renderPassProgramAA = make_scoped_ptr(new RenderPassProgramAA(m_contex
t)); | 1321 m_renderPassProgramAA = make_scoped_ptr(new RenderPassProgramAA(m_contex
t)); |
1322 if (!m_renderPassProgramAA->initialized()) { | 1322 if (!m_renderPassProgramAA->initialized()) { |
1323 TRACE_EVENT0("cc", "CCRendererGL::renderPassProgramAA::initialize"); | 1323 TRACE_EVENT0("cc", "GLRenderer::renderPassProgramAA::initialize"); |
1324 m_renderPassProgramAA->initialize(m_context, m_isUsingBindUniform); | 1324 m_renderPassProgramAA->initialize(m_context, m_isUsingBindUniform); |
1325 } | 1325 } |
1326 return m_renderPassProgramAA.get(); | 1326 return m_renderPassProgramAA.get(); |
1327 } | 1327 } |
1328 | 1328 |
1329 const CCRendererGL::RenderPassMaskProgram* CCRendererGL::renderPassMaskProgram() | 1329 const GLRenderer::RenderPassMaskProgram* GLRenderer::renderPassMaskProgram() |
1330 { | 1330 { |
1331 if (!m_renderPassMaskProgram) | 1331 if (!m_renderPassMaskProgram) |
1332 m_renderPassMaskProgram = make_scoped_ptr(new RenderPassMaskProgram(m_co
ntext)); | 1332 m_renderPassMaskProgram = make_scoped_ptr(new RenderPassMaskProgram(m_co
ntext)); |
1333 if (!m_renderPassMaskProgram->initialized()) { | 1333 if (!m_renderPassMaskProgram->initialized()) { |
1334 TRACE_EVENT0("cc", "CCRendererGL::renderPassMaskProgram::initialize"); | 1334 TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgram::initialize"); |
1335 m_renderPassMaskProgram->initialize(m_context, m_isUsingBindUniform); | 1335 m_renderPassMaskProgram->initialize(m_context, m_isUsingBindUniform); |
1336 } | 1336 } |
1337 return m_renderPassMaskProgram.get(); | 1337 return m_renderPassMaskProgram.get(); |
1338 } | 1338 } |
1339 | 1339 |
1340 const CCRendererGL::RenderPassMaskProgramAA* CCRendererGL::renderPassMaskProgram
AA() | 1340 const GLRenderer::RenderPassMaskProgramAA* GLRenderer::renderPassMaskProgramAA() |
1341 { | 1341 { |
1342 if (!m_renderPassMaskProgramAA) | 1342 if (!m_renderPassMaskProgramAA) |
1343 m_renderPassMaskProgramAA = make_scoped_ptr(new RenderPassMaskProgramAA(
m_context)); | 1343 m_renderPassMaskProgramAA = make_scoped_ptr(new RenderPassMaskProgramAA(
m_context)); |
1344 if (!m_renderPassMaskProgramAA->initialized()) { | 1344 if (!m_renderPassMaskProgramAA->initialized()) { |
1345 TRACE_EVENT0("cc", "CCRendererGL::renderPassMaskProgramAA::initialize"); | 1345 TRACE_EVENT0("cc", "GLRenderer::renderPassMaskProgramAA::initialize"); |
1346 m_renderPassMaskProgramAA->initialize(m_context, m_isUsingBindUniform); | 1346 m_renderPassMaskProgramAA->initialize(m_context, m_isUsingBindUniform); |
1347 } | 1347 } |
1348 return m_renderPassMaskProgramAA.get(); | 1348 return m_renderPassMaskProgramAA.get(); |
1349 } | 1349 } |
1350 | 1350 |
1351 const CCRendererGL::TileProgram* CCRendererGL::tileProgram() | 1351 const GLRenderer::TileProgram* GLRenderer::tileProgram() |
1352 { | 1352 { |
1353 ASSERT(m_tileProgram); | 1353 ASSERT(m_tileProgram); |
1354 if (!m_tileProgram->initialized()) { | 1354 if (!m_tileProgram->initialized()) { |
1355 TRACE_EVENT0("cc", "CCRendererGL::tileProgram::initialize"); | 1355 TRACE_EVENT0("cc", "GLRenderer::tileProgram::initialize"); |
1356 m_tileProgram->initialize(m_context, m_isUsingBindUniform); | 1356 m_tileProgram->initialize(m_context, m_isUsingBindUniform); |
1357 } | 1357 } |
1358 return m_tileProgram.get(); | 1358 return m_tileProgram.get(); |
1359 } | 1359 } |
1360 | 1360 |
1361 const CCRendererGL::TileProgramOpaque* CCRendererGL::tileProgramOpaque() | 1361 const GLRenderer::TileProgramOpaque* GLRenderer::tileProgramOpaque() |
1362 { | 1362 { |
1363 ASSERT(m_tileProgramOpaque); | 1363 ASSERT(m_tileProgramOpaque); |
1364 if (!m_tileProgramOpaque->initialized()) { | 1364 if (!m_tileProgramOpaque->initialized()) { |
1365 TRACE_EVENT0("cc", "CCRendererGL::tileProgramOpaque::initialize"); | 1365 TRACE_EVENT0("cc", "GLRenderer::tileProgramOpaque::initialize"); |
1366 m_tileProgramOpaque->initialize(m_context, m_isUsingBindUniform); | 1366 m_tileProgramOpaque->initialize(m_context, m_isUsingBindUniform); |
1367 } | 1367 } |
1368 return m_tileProgramOpaque.get(); | 1368 return m_tileProgramOpaque.get(); |
1369 } | 1369 } |
1370 | 1370 |
1371 const CCRendererGL::TileProgramAA* CCRendererGL::tileProgramAA() | 1371 const GLRenderer::TileProgramAA* GLRenderer::tileProgramAA() |
1372 { | 1372 { |
1373 if (!m_tileProgramAA) | 1373 if (!m_tileProgramAA) |
1374 m_tileProgramAA = make_scoped_ptr(new TileProgramAA(m_context)); | 1374 m_tileProgramAA = make_scoped_ptr(new TileProgramAA(m_context)); |
1375 if (!m_tileProgramAA->initialized()) { | 1375 if (!m_tileProgramAA->initialized()) { |
1376 TRACE_EVENT0("cc", "CCRendererGL::tileProgramAA::initialize"); | 1376 TRACE_EVENT0("cc", "GLRenderer::tileProgramAA::initialize"); |
1377 m_tileProgramAA->initialize(m_context, m_isUsingBindUniform); | 1377 m_tileProgramAA->initialize(m_context, m_isUsingBindUniform); |
1378 } | 1378 } |
1379 return m_tileProgramAA.get(); | 1379 return m_tileProgramAA.get(); |
1380 } | 1380 } |
1381 | 1381 |
1382 const CCRendererGL::TileProgramSwizzle* CCRendererGL::tileProgramSwizzle() | 1382 const GLRenderer::TileProgramSwizzle* GLRenderer::tileProgramSwizzle() |
1383 { | 1383 { |
1384 if (!m_tileProgramSwizzle) | 1384 if (!m_tileProgramSwizzle) |
1385 m_tileProgramSwizzle = make_scoped_ptr(new TileProgramSwizzle(m_context)
); | 1385 m_tileProgramSwizzle = make_scoped_ptr(new TileProgramSwizzle(m_context)
); |
1386 if (!m_tileProgramSwizzle->initialized()) { | 1386 if (!m_tileProgramSwizzle->initialized()) { |
1387 TRACE_EVENT0("cc", "CCRendererGL::tileProgramSwizzle::initialize"); | 1387 TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzle::initialize"); |
1388 m_tileProgramSwizzle->initialize(m_context, m_isUsingBindUniform); | 1388 m_tileProgramSwizzle->initialize(m_context, m_isUsingBindUniform); |
1389 } | 1389 } |
1390 return m_tileProgramSwizzle.get(); | 1390 return m_tileProgramSwizzle.get(); |
1391 } | 1391 } |
1392 | 1392 |
1393 const CCRendererGL::TileProgramSwizzleOpaque* CCRendererGL::tileProgramSwizzleOp
aque() | 1393 const GLRenderer::TileProgramSwizzleOpaque* GLRenderer::tileProgramSwizzleOpaque
() |
1394 { | 1394 { |
1395 if (!m_tileProgramSwizzleOpaque) | 1395 if (!m_tileProgramSwizzleOpaque) |
1396 m_tileProgramSwizzleOpaque = make_scoped_ptr(new TileProgramSwizzleOpaqu
e(m_context)); | 1396 m_tileProgramSwizzleOpaque = make_scoped_ptr(new TileProgramSwizzleOpaqu
e(m_context)); |
1397 if (!m_tileProgramSwizzleOpaque->initialized()) { | 1397 if (!m_tileProgramSwizzleOpaque->initialized()) { |
1398 TRACE_EVENT0("cc", "CCRendererGL::tileProgramSwizzleOpaque::initialize")
; | 1398 TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzleOpaque::initialize"); |
1399 m_tileProgramSwizzleOpaque->initialize(m_context, m_isUsingBindUniform); | 1399 m_tileProgramSwizzleOpaque->initialize(m_context, m_isUsingBindUniform); |
1400 } | 1400 } |
1401 return m_tileProgramSwizzleOpaque.get(); | 1401 return m_tileProgramSwizzleOpaque.get(); |
1402 } | 1402 } |
1403 | 1403 |
1404 const CCRendererGL::TileProgramSwizzleAA* CCRendererGL::tileProgramSwizzleAA() | 1404 const GLRenderer::TileProgramSwizzleAA* GLRenderer::tileProgramSwizzleAA() |
1405 { | 1405 { |
1406 if (!m_tileProgramSwizzleAA) | 1406 if (!m_tileProgramSwizzleAA) |
1407 m_tileProgramSwizzleAA = make_scoped_ptr(new TileProgramSwizzleAA(m_cont
ext)); | 1407 m_tileProgramSwizzleAA = make_scoped_ptr(new TileProgramSwizzleAA(m_cont
ext)); |
1408 if (!m_tileProgramSwizzleAA->initialized()) { | 1408 if (!m_tileProgramSwizzleAA->initialized()) { |
1409 TRACE_EVENT0("cc", "CCRendererGL::tileProgramSwizzleAA::initialize"); | 1409 TRACE_EVENT0("cc", "GLRenderer::tileProgramSwizzleAA::initialize"); |
1410 m_tileProgramSwizzleAA->initialize(m_context, m_isUsingBindUniform); | 1410 m_tileProgramSwizzleAA->initialize(m_context, m_isUsingBindUniform); |
1411 } | 1411 } |
1412 return m_tileProgramSwizzleAA.get(); | 1412 return m_tileProgramSwizzleAA.get(); |
1413 } | 1413 } |
1414 | 1414 |
1415 const CCRendererGL::TextureProgram* CCRendererGL::textureProgram() | 1415 const GLRenderer::TextureProgram* GLRenderer::textureProgram() |
1416 { | 1416 { |
1417 if (!m_textureProgram) | 1417 if (!m_textureProgram) |
1418 m_textureProgram = make_scoped_ptr(new TextureProgram(m_context)); | 1418 m_textureProgram = make_scoped_ptr(new TextureProgram(m_context)); |
1419 if (!m_textureProgram->initialized()) { | 1419 if (!m_textureProgram->initialized()) { |
1420 TRACE_EVENT0("cc", "CCRendererGL::textureProgram::initialize"); | 1420 TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); |
1421 m_textureProgram->initialize(m_context, m_isUsingBindUniform); | 1421 m_textureProgram->initialize(m_context, m_isUsingBindUniform); |
1422 } | 1422 } |
1423 return m_textureProgram.get(); | 1423 return m_textureProgram.get(); |
1424 } | 1424 } |
1425 | 1425 |
1426 const CCRendererGL::TextureProgramFlip* CCRendererGL::textureProgramFlip() | 1426 const GLRenderer::TextureProgramFlip* GLRenderer::textureProgramFlip() |
1427 { | 1427 { |
1428 if (!m_textureProgramFlip) | 1428 if (!m_textureProgramFlip) |
1429 m_textureProgramFlip = make_scoped_ptr(new TextureProgramFlip(m_context)
); | 1429 m_textureProgramFlip = make_scoped_ptr(new TextureProgramFlip(m_context)
); |
1430 if (!m_textureProgramFlip->initialized()) { | 1430 if (!m_textureProgramFlip->initialized()) { |
1431 TRACE_EVENT0("cc", "CCRendererGL::textureProgramFlip::initialize"); | 1431 TRACE_EVENT0("cc", "GLRenderer::textureProgramFlip::initialize"); |
1432 m_textureProgramFlip->initialize(m_context, m_isUsingBindUniform); | 1432 m_textureProgramFlip->initialize(m_context, m_isUsingBindUniform); |
1433 } | 1433 } |
1434 return m_textureProgramFlip.get(); | 1434 return m_textureProgramFlip.get(); |
1435 } | 1435 } |
1436 | 1436 |
1437 const CCRendererGL::TextureIOSurfaceProgram* CCRendererGL::textureIOSurfaceProgr
am() | 1437 const GLRenderer::TextureIOSurfaceProgram* GLRenderer::textureIOSurfaceProgram() |
1438 { | 1438 { |
1439 if (!m_textureIOSurfaceProgram) | 1439 if (!m_textureIOSurfaceProgram) |
1440 m_textureIOSurfaceProgram = make_scoped_ptr(new TextureIOSurfaceProgram(
m_context)); | 1440 m_textureIOSurfaceProgram = make_scoped_ptr(new TextureIOSurfaceProgram(
m_context)); |
1441 if (!m_textureIOSurfaceProgram->initialized()) { | 1441 if (!m_textureIOSurfaceProgram->initialized()) { |
1442 TRACE_EVENT0("cc", "CCRendererGL::textureIOSurfaceProgram::initialize"); | 1442 TRACE_EVENT0("cc", "GLRenderer::textureIOSurfaceProgram::initialize"); |
1443 m_textureIOSurfaceProgram->initialize(m_context, m_isUsingBindUniform); | 1443 m_textureIOSurfaceProgram->initialize(m_context, m_isUsingBindUniform); |
1444 } | 1444 } |
1445 return m_textureIOSurfaceProgram.get(); | 1445 return m_textureIOSurfaceProgram.get(); |
1446 } | 1446 } |
1447 | 1447 |
1448 const CCRendererGL::VideoYUVProgram* CCRendererGL::videoYUVProgram() | 1448 const GLRenderer::VideoYUVProgram* GLRenderer::videoYUVProgram() |
1449 { | 1449 { |
1450 if (!m_videoYUVProgram) | 1450 if (!m_videoYUVProgram) |
1451 m_videoYUVProgram = make_scoped_ptr(new VideoYUVProgram(m_context)); | 1451 m_videoYUVProgram = make_scoped_ptr(new VideoYUVProgram(m_context)); |
1452 if (!m_videoYUVProgram->initialized()) { | 1452 if (!m_videoYUVProgram->initialized()) { |
1453 TRACE_EVENT0("cc", "CCRendererGL::videoYUVProgram::initialize"); | 1453 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); |
1454 m_videoYUVProgram->initialize(m_context, m_isUsingBindUniform); | 1454 m_videoYUVProgram->initialize(m_context, m_isUsingBindUniform); |
1455 } | 1455 } |
1456 return m_videoYUVProgram.get(); | 1456 return m_videoYUVProgram.get(); |
1457 } | 1457 } |
1458 | 1458 |
1459 const CCRendererGL::VideoStreamTextureProgram* CCRendererGL::videoStreamTextureP
rogram() | 1459 const GLRenderer::VideoStreamTextureProgram* GLRenderer::videoStreamTextureProgr
am() |
1460 { | 1460 { |
1461 if (!m_videoStreamTextureProgram) | 1461 if (!m_videoStreamTextureProgram) |
1462 m_videoStreamTextureProgram = make_scoped_ptr(new VideoStreamTextureProg
ram(m_context)); | 1462 m_videoStreamTextureProgram = make_scoped_ptr(new VideoStreamTextureProg
ram(m_context)); |
1463 if (!m_videoStreamTextureProgram->initialized()) { | 1463 if (!m_videoStreamTextureProgram->initialized()) { |
1464 TRACE_EVENT0("cc", "CCRendererGL::streamTextureProgram::initialize"); | 1464 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize"); |
1465 m_videoStreamTextureProgram->initialize(m_context, m_isUsingBindUniform)
; | 1465 m_videoStreamTextureProgram->initialize(m_context, m_isUsingBindUniform)
; |
1466 } | 1466 } |
1467 return m_videoStreamTextureProgram.get(); | 1467 return m_videoStreamTextureProgram.get(); |
1468 } | 1468 } |
1469 | 1469 |
1470 void CCRendererGL::cleanupSharedObjects() | 1470 void GLRenderer::cleanupSharedObjects() |
1471 { | 1471 { |
1472 makeContextCurrent(); | 1472 makeContextCurrent(); |
1473 | 1473 |
1474 m_sharedGeometry.reset(); | 1474 m_sharedGeometry.reset(); |
1475 | 1475 |
1476 if (m_tileProgram) | 1476 if (m_tileProgram) |
1477 m_tileProgram->cleanup(m_context); | 1477 m_tileProgram->cleanup(m_context); |
1478 if (m_tileProgramOpaque) | 1478 if (m_tileProgramOpaque) |
1479 m_tileProgramOpaque->cleanup(m_context); | 1479 m_tileProgramOpaque->cleanup(m_context); |
1480 if (m_tileProgramSwizzle) | 1480 if (m_tileProgramSwizzle) |
(...skipping 30 matching lines...) Expand all Loading... |
1511 | 1511 |
1512 if (m_solidColorProgram) | 1512 if (m_solidColorProgram) |
1513 m_solidColorProgram->cleanup(m_context); | 1513 m_solidColorProgram->cleanup(m_context); |
1514 | 1514 |
1515 if (m_offscreenFramebufferId) | 1515 if (m_offscreenFramebufferId) |
1516 GLC(m_context, m_context->deleteFramebuffer(m_offscreenFramebufferId)); | 1516 GLC(m_context, m_context->deleteFramebuffer(m_offscreenFramebufferId)); |
1517 | 1517 |
1518 releaseRenderPassTextures(); | 1518 releaseRenderPassTextures(); |
1519 } | 1519 } |
1520 | 1520 |
1521 bool CCRendererGL::isContextLost() | 1521 bool GLRenderer::isContextLost() |
1522 { | 1522 { |
1523 return (m_context->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERRO
R); | 1523 return (m_context->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERRO
R); |
1524 } | 1524 } |
1525 | 1525 |
1526 } // namespace cc | 1526 } // namespace cc |
OLD | NEW |