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 "cc/gl_renderer.h" | 5 #include "cc/gl_renderer.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 { | 52 { |
53 #if defined(OS_MACOSX) | 53 #if defined(OS_MACOSX) |
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 // A basic vector class, used for vertex transforms and OpenGL vector upload | |
63 struct Vector { | |
jamesr
2012/11/28 00:00:37
cc/math_util.h has a HomogeneousCoordinate that's
whunt
2012/11/28 00:29:08
In truth we no longer need any math because I'm no
shawnsingh
2012/11/28 19:44:16
I think we should do the following:
(1) merge this
| |
64 float x, y, z, w; | |
65 Vector() {} | |
66 Vector(float x, float y, float z = 0.0f, float w = 0.0f) | |
67 : x(x), y(y), z(z), w(w) { } | |
68 }; | |
69 | |
70 // A basic matrix class, used for vertex transforms and OpenGL matrix upload | |
71 struct Matrix { | |
danakj
2012/11/27 23:47:47
Is there some reason to not just use gfx::Transfor
whunt
2012/11/28 00:29:08
This only works if gfx::Transform is of float type
danakj
2012/11/28 00:43:58
Oh okay, thanks for the explanation. Let's call it
| |
72 Vector x, y, z, w; | |
73 Matrix() {} | |
74 Matrix(const Vector& x, const Vector& y, const Vector& z, const Vector& w) | |
75 : x(x), y(y), z(z), w(w) { } | |
76 }; | |
77 | |
78 // An alternate vector constructor that defaults to w = 1.0f rather than w = 0.0 f | |
79 inline Vector const Point(float x, float y, float z = 0.0f, float w = 1.0f) { re turn Vector(x, y, z, w); } | |
80 | |
81 // The most basic math required to implement vertex transforms | |
82 inline Vector const operator +(const Vector& a, const Vector& b) { return Vector (a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); } | |
83 inline Vector const operator *(const Vector& a, float b) { return Vector(a.x * b , a.y * b, a.z * b, a.w * b); } | |
84 inline Vector const operator *(const Matrix& m, const Vector& v) { return m.x * v.x + m.y * v.y + m.z * v.z + m.w * v.w; } | |
85 | |
86 // A cache for storing textured quads to be drawn. Stores the minimum required | |
87 // data to tell if two back to back draws only differ in their transform. Quads | |
88 // that only differ by transform may be coalesced into a single draw call. | |
89 struct TexturedQuadDrawCache | |
jamesr
2012/11/28 00:00:37
Could we put this in its own file? Adding a new f
whunt
2012/11/28 00:29:08
Sure, no problem.
On 2012/11/28 00:00:37, jamesr
| |
90 { | |
91 // Values tracked to determine if textured quads may be coalesced | |
92 int programID; | |
93 int resourceID; | |
94 float alpha; | |
95 bool usePremultipliedAlpha; | |
96 bool needsBlending; | |
97 | |
98 // Information about the program binding that is required to draw | |
99 int alphaLocation; | |
100 int uvXformLocation; | |
101 int matrixLocation; | |
102 | |
103 // A cache for the coalesced quad data | |
104 std::vector<Vector> uvXformData; | |
105 std::vector<Matrix> matrixData; | |
106 | |
107 TexturedQuadDrawCache() | |
108 : programID(0) | |
109 , resourceID(0) | |
jamesr
2012/11/28 00:00:37
could you initialize all scalars and move the cons
whunt
2012/11/28 00:29:08
Constructor moved.
About initialization. I *can*
| |
110 { | |
111 } | |
112 }; | |
113 | |
62 scoped_ptr<GLRenderer> GLRenderer::create(RendererClient* client, ResourceProvid er* resourceProvider) | 114 scoped_ptr<GLRenderer> GLRenderer::create(RendererClient* client, ResourceProvid er* resourceProvider) |
63 { | 115 { |
64 scoped_ptr<GLRenderer> renderer(make_scoped_ptr(new GLRenderer(client, resou rceProvider))); | 116 scoped_ptr<GLRenderer> renderer(make_scoped_ptr(new GLRenderer(client, resou rceProvider))); |
65 if (!renderer->initialize()) | 117 if (!renderer->initialize()) |
66 return scoped_ptr<GLRenderer>(); | 118 return scoped_ptr<GLRenderer>(); |
67 | 119 |
68 return renderer.Pass(); | 120 return renderer.Pass(); |
69 } | 121 } |
70 | 122 |
71 GLRenderer::GLRenderer(RendererClient* client, ResourceProvider* resourceProvide r) | 123 GLRenderer::GLRenderer(RendererClient* client, ResourceProvider* resourceProvide r) |
72 : DirectRenderer(client, resourceProvider) | 124 : DirectRenderer(client, resourceProvider) |
73 , m_offscreenFramebufferId(0) | 125 , m_offscreenFramebufferId(0) |
74 , m_sharedGeometryQuad(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)) | 126 , m_sharedGeometryQuad(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f)) |
75 , m_context(resourceProvider->graphicsContext3D()) | 127 , m_context(resourceProvider->graphicsContext3D()) |
76 , m_isViewportChanged(false) | 128 , m_isViewportChanged(false) |
77 , m_isFramebufferDiscarded(false) | 129 , m_isFramebufferDiscarded(false) |
78 , m_discardFramebufferWhenNotVisible(false) | 130 , m_discardFramebufferWhenNotVisible(false) |
79 , m_isUsingBindUniform(false) | 131 , m_isUsingBindUniform(false) |
80 , m_visible(true) | 132 , m_visible(true) |
81 , m_isScissorEnabled(false) | 133 , m_isScissorEnabled(false) |
134 , m_drawCache(new TexturedQuadDrawCache()) | |
jamesr
2012/11/28 00:00:37
if we had TextureQuadDrawCache in its own header,
whunt
2012/11/28 00:29:08
This is true, but that would make everything that
| |
82 { | 135 { |
83 DCHECK(m_context); | 136 DCHECK(m_context); |
84 } | 137 } |
85 | 138 |
86 bool GLRenderer::initialize() | 139 bool GLRenderer::initialize() |
87 { | 140 { |
88 if (!m_context->makeContextCurrent()) | 141 if (!m_context->makeContextCurrent()) |
89 return false; | 142 return false; |
90 | 143 |
91 m_context->setContextLostCallback(this); | 144 m_context->setContextLostCallback(this); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 makeContextCurrent(); | 289 makeContextCurrent(); |
237 // Bind the common vertex attributes used for drawing all the layers. | 290 // Bind the common vertex attributes used for drawing all the layers. |
238 m_sharedGeometry->prepareForDraw(); | 291 m_sharedGeometry->prepareForDraw(); |
239 | 292 |
240 GLC(m_context, m_context->disable(GL_DEPTH_TEST)); | 293 GLC(m_context, m_context->disable(GL_DEPTH_TEST)); |
241 GLC(m_context, m_context->disable(GL_CULL_FACE)); | 294 GLC(m_context, m_context->disable(GL_CULL_FACE)); |
242 GLC(m_context, m_context->colorMask(true, true, true, true)); | 295 GLC(m_context, m_context->colorMask(true, true, true, true)); |
243 GLC(m_context, m_context->enable(GL_BLEND)); | 296 GLC(m_context, m_context->enable(GL_BLEND)); |
244 GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | 297 GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); |
245 GLC(context(), context()->activeTexture(GL_TEXTURE0)); | 298 GLC(context(), context()->activeTexture(GL_TEXTURE0)); |
299 m_blendShadow = true; | |
300 m_programShadow = 0; | |
246 } | 301 } |
247 | 302 |
248 void GLRenderer::doNoOp() | 303 void GLRenderer::doNoOp() |
249 { | 304 { |
250 GLC(m_context, m_context->bindFramebuffer(GL_FRAMEBUFFER, 0)); | 305 GLC(m_context, m_context->bindFramebuffer(GL_FRAMEBUFFER, 0)); |
251 GLC(m_context, m_context->flush()); | 306 GLC(m_context, m_context->flush()); |
252 } | 307 } |
253 | 308 |
254 void GLRenderer::drawQuad(DrawingFrame& frame, const DrawQuad* quad) | 309 void GLRenderer::drawQuad(DrawingFrame& frame, const DrawQuad* quad) |
255 { | 310 { |
256 DCHECK(quad->rect.Contains(quad->visible_rect)); | 311 DCHECK(quad->rect.Contains(quad->visible_rect)); |
257 | 312 if (quad->material != DrawQuad::TEXTURE_CONTENT) |
258 if (quad->ShouldDrawWithBlending()) | 313 { |
259 GLC(m_context, m_context->enable(GL_BLEND)); | 314 drawTextureQuadFlush(); |
260 else | 315 setBlendEnabled(quad->ShouldDrawWithBlending()); |
261 GLC(m_context, m_context->disable(GL_BLEND)); | 316 } |
262 | 317 |
263 switch (quad->material) { | 318 switch (quad->material) { |
264 case DrawQuad::INVALID: | 319 case DrawQuad::INVALID: |
265 NOTREACHED(); | 320 NOTREACHED(); |
266 break; | 321 break; |
267 case DrawQuad::CHECKERBOARD: | 322 case DrawQuad::CHECKERBOARD: |
268 drawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad)); | 323 drawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad)); |
269 break; | 324 break; |
270 case DrawQuad::DEBUG_BORDER: | 325 case DrawQuad::DEBUG_BORDER: |
271 drawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); | 326 drawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); |
272 break; | 327 break; |
273 case DrawQuad::IO_SURFACE_CONTENT: | 328 case DrawQuad::IO_SURFACE_CONTENT: |
274 drawIOSurfaceQuad(frame, IOSurfaceDrawQuad::MaterialCast(quad)); | 329 drawIOSurfaceQuad(frame, IOSurfaceDrawQuad::MaterialCast(quad)); |
275 break; | 330 break; |
276 case DrawQuad::RENDER_PASS: | 331 case DrawQuad::RENDER_PASS: |
277 drawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad)); | 332 drawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad)); |
278 break; | 333 break; |
279 case DrawQuad::SOLID_COLOR: | 334 case DrawQuad::SOLID_COLOR: |
280 drawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad)); | 335 drawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad)); |
281 break; | 336 break; |
282 case DrawQuad::STREAM_VIDEO_CONTENT: | 337 case DrawQuad::STREAM_VIDEO_CONTENT: |
283 drawStreamVideoQuad(frame, StreamVideoDrawQuad::MaterialCast(quad)); | 338 drawStreamVideoQuad(frame, StreamVideoDrawQuad::MaterialCast(quad)); |
284 break; | 339 break; |
285 case DrawQuad::TEXTURE_CONTENT: | 340 case DrawQuad::TEXTURE_CONTENT: |
286 drawTextureQuad(frame, TextureDrawQuad::MaterialCast(quad)); | 341 drawTextureQuadPush(frame, TextureDrawQuad::MaterialCast(quad)); |
287 break; | 342 break; |
288 case DrawQuad::TILED_CONTENT: | 343 case DrawQuad::TILED_CONTENT: |
289 drawTileQuad(frame, TileDrawQuad::MaterialCast(quad)); | 344 drawTileQuad(frame, TileDrawQuad::MaterialCast(quad)); |
290 break; | 345 break; |
291 case DrawQuad::YUV_VIDEO_CONTENT: | 346 case DrawQuad::YUV_VIDEO_CONTENT: |
292 drawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad)); | 347 drawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad)); |
293 break; | 348 break; |
294 } | 349 } |
295 } | 350 } |
296 | 351 |
297 void GLRenderer::drawCheckerboardQuad(const DrawingFrame& frame, const Checkerbo ardDrawQuad* quad) | 352 void GLRenderer::drawCheckerboardQuad(const DrawingFrame& frame, const Checkerbo ardDrawQuad* quad) |
298 { | 353 { |
299 const TileCheckerboardProgram* program = tileCheckerboardProgram(); | 354 const TileCheckerboardProgram* program = tileCheckerboardProgram(); |
300 DCHECK(program && (program->initialized() || isContextLost())); | 355 DCHECK(program && (program->initialized() || isContextLost())); |
301 GLC(context(), context()->useProgram(program->program())); | 356 setUseProgram(program->program()); |
302 | 357 |
303 SkColor color = quad->color; | 358 SkColor color = quad->color; |
304 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), SkColorGetR(color) / 255.0, SkColorGetG(color) / 255.0, SkColorGetB(color) / 255.0, 1)); | 359 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), SkColorGetR(color) / 255.0, SkColorGetG(color) / 255.0, SkColorGetB(color) / 255.0, 1)); |
305 | 360 |
306 const int checkerboardWidth = 16; | 361 const int checkerboardWidth = 16; |
307 float frequency = 1.0 / checkerboardWidth; | 362 float frequency = 1.0 / checkerboardWidth; |
308 | 363 |
309 gfx::Rect tileRect = quad->rect; | 364 gfx::Rect tileRect = quad->rect; |
310 float texOffsetX = tileRect.x() % checkerboardWidth; | 365 float texOffsetX = tileRect.x() % checkerboardWidth; |
311 float texOffsetY = tileRect.y() % checkerboardWidth; | 366 float texOffsetY = tileRect.y() % checkerboardWidth; |
312 float texScaleX = tileRect.width(); | 367 float texScaleX = tileRect.width(); |
313 float texScaleY = tileRect.height(); | 368 float texScaleY = tileRect.height(); |
314 GLC(context(), context()->uniform4f(program->fragmentShader().texTransformLo cation(), texOffsetX, texOffsetY, texScaleX, texScaleY)); | 369 GLC(context(), context()->uniform4f(program->fragmentShader().texTransformLo cation(), texOffsetX, texOffsetY, texScaleX, texScaleY)); |
315 | 370 |
316 GLC(context(), context()->uniform1f(program->fragmentShader().frequencyLocat ion(), frequency)); | 371 GLC(context(), context()->uniform1f(program->fragmentShader().frequencyLocat ion(), frequency)); |
317 | 372 |
318 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ; | 373 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ; |
319 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); | 374 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); |
320 } | 375 } |
321 | 376 |
322 void GLRenderer::drawDebugBorderQuad(const DrawingFrame& frame, const DebugBorde rDrawQuad* quad) | 377 void GLRenderer::drawDebugBorderQuad(const DrawingFrame& frame, const DebugBorde rDrawQuad* quad) |
323 { | 378 { |
324 static float glMatrix[16]; | 379 static float glMatrix[16]; |
325 const SolidColorProgram* program = solidColorProgram(); | 380 const SolidColorProgram* program = solidColorProgram(); |
326 DCHECK(program && (program->initialized() || isContextLost())); | 381 DCHECK(program && (program->initialized() || isContextLost())); |
327 GLC(context(), context()->useProgram(program->program())); | 382 setUseProgram(program->program()); |
328 | 383 |
329 // Use the full quadRect for debug quads to not move the edges based on part ial swaps. | 384 // Use the full quadRect for debug quads to not move the edges based on part ial swaps. |
330 const gfx::Rect& layerRect = quad->rect; | 385 const gfx::Rect& layerRect = quad->rect; |
331 gfx::Transform renderMatrix = quad->quadTransform(); | 386 gfx::Transform renderMatrix = quad->quadTransform(); |
332 renderMatrix.Translate(0.5 * layerRect.width() + layerRect.x(), 0.5 * layerR ect.height() + layerRect.y()); | 387 renderMatrix.Translate(0.5 * layerRect.width() + layerRect.x(), 0.5 * layerR ect.height() + layerRect.y()); |
333 renderMatrix.Scale(layerRect.width(), layerRect.height()); | 388 renderMatrix.Scale(layerRect.width(), layerRect.height()); |
334 GLRenderer::toGLMatrix(&glMatrix[0], frame.projectionMatrix * renderMatrix); | 389 GLRenderer::toGLMatrix(&glMatrix[0], frame.projectionMatrix * renderMatrix); |
335 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().matrixLoc ation(), 1, false, &glMatrix[0])); | 390 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().matrixLoc ation(), 1, false, &glMatrix[0])); |
336 | 391 |
337 SkColor color = quad->color; | 392 SkColor color = quad->color; |
338 float alpha = SkColorGetA(color) / 255.0; | 393 float alpha = SkColorGetA(color) / 255.0; |
339 | 394 |
340 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, ( SkColorGetB(color) / 255.0) * alpha, alpha)); | 395 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, ( SkColorGetB(color) / 255.0) * alpha, alpha)); |
341 | 396 |
342 GLC(context(), context()->lineWidth(quad->width)); | 397 GLC(context(), context()->lineWidth(quad->width)); |
343 | 398 |
344 // The indices for the line are stored in the same array as the triangle ind ices. | 399 // The indices for the line are stored in the same array as the triangle ind ices. |
345 GLC(context(), context()->drawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 6 * sizeof(unsigned short))); | 400 GLC(context(), context()->drawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_SHORT, 0 )); |
346 } | 401 } |
347 | 402 |
348 static WebGraphicsContext3D* getFilterContext(bool hasImplThread) | 403 static WebGraphicsContext3D* getFilterContext(bool hasImplThread) |
349 { | 404 { |
350 if (hasImplThread) | 405 if (hasImplThread) |
351 return WebSharedGraphicsContext3D::compositorThreadContext(); | 406 return WebSharedGraphicsContext3D::compositorThreadContext(); |
352 else | 407 else |
353 return WebSharedGraphicsContext3D::mainThreadContext(); | 408 return WebSharedGraphicsContext3D::mainThreadContext(); |
354 } | 409 } |
355 | 410 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 | 635 |
581 int shaderQuadLocation = -1; | 636 int shaderQuadLocation = -1; |
582 int shaderEdgeLocation = -1; | 637 int shaderEdgeLocation = -1; |
583 int shaderMaskSamplerLocation = -1; | 638 int shaderMaskSamplerLocation = -1; |
584 int shaderMaskTexCoordScaleLocation = -1; | 639 int shaderMaskTexCoordScaleLocation = -1; |
585 int shaderMaskTexCoordOffsetLocation = -1; | 640 int shaderMaskTexCoordOffsetLocation = -1; |
586 int shaderMatrixLocation = -1; | 641 int shaderMatrixLocation = -1; |
587 int shaderAlphaLocation = -1; | 642 int shaderAlphaLocation = -1; |
588 if (useAA && maskTextureId) { | 643 if (useAA && maskTextureId) { |
589 const RenderPassMaskProgramAA* program = renderPassMaskProgramAA(); | 644 const RenderPassMaskProgramAA* program = renderPassMaskProgramAA(); |
590 GLC(context(), context()->useProgram(program->program())); | 645 setUseProgram(program->program()); |
591 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLoc ation(), 0)); | 646 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLoc ation(), 0)); |
592 | 647 |
593 shaderQuadLocation = program->vertexShader().pointLocation(); | 648 shaderQuadLocation = program->vertexShader().pointLocation(); |
594 shaderEdgeLocation = program->fragmentShader().edgeLocation(); | 649 shaderEdgeLocation = program->fragmentShader().edgeLocation(); |
595 shaderMaskSamplerLocation = program->fragmentShader().maskSamplerLocatio n(); | 650 shaderMaskSamplerLocation = program->fragmentShader().maskSamplerLocatio n(); |
596 shaderMaskTexCoordScaleLocation = program->fragmentShader().maskTexCoord ScaleLocation(); | 651 shaderMaskTexCoordScaleLocation = program->fragmentShader().maskTexCoord ScaleLocation(); |
597 shaderMaskTexCoordOffsetLocation = program->fragmentShader().maskTexCoor dOffsetLocation(); | 652 shaderMaskTexCoordOffsetLocation = program->fragmentShader().maskTexCoor dOffsetLocation(); |
598 shaderMatrixLocation = program->vertexShader().matrixLocation(); | 653 shaderMatrixLocation = program->vertexShader().matrixLocation(); |
599 shaderAlphaLocation = program->fragmentShader().alphaLocation(); | 654 shaderAlphaLocation = program->fragmentShader().alphaLocation(); |
600 } else if (!useAA && maskTextureId) { | 655 } else if (!useAA && maskTextureId) { |
601 const RenderPassMaskProgram* program = renderPassMaskProgram(); | 656 const RenderPassMaskProgram* program = renderPassMaskProgram(); |
602 GLC(context(), context()->useProgram(program->program())); | 657 setUseProgram(program->program()); |
603 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLoc ation(), 0)); | 658 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLoc ation(), 0)); |
604 | 659 |
605 shaderMaskSamplerLocation = program->fragmentShader().maskSamplerLocatio n(); | 660 shaderMaskSamplerLocation = program->fragmentShader().maskSamplerLocatio n(); |
606 shaderMaskTexCoordScaleLocation = program->fragmentShader().maskTexCoord ScaleLocation(); | 661 shaderMaskTexCoordScaleLocation = program->fragmentShader().maskTexCoord ScaleLocation(); |
607 shaderMaskTexCoordOffsetLocation = program->fragmentShader().maskTexCoor dOffsetLocation(); | 662 shaderMaskTexCoordOffsetLocation = program->fragmentShader().maskTexCoor dOffsetLocation(); |
608 shaderMatrixLocation = program->vertexShader().matrixLocation(); | 663 shaderMatrixLocation = program->vertexShader().matrixLocation(); |
609 shaderAlphaLocation = program->fragmentShader().alphaLocation(); | 664 shaderAlphaLocation = program->fragmentShader().alphaLocation(); |
610 } else if (useAA && !maskTextureId) { | 665 } else if (useAA && !maskTextureId) { |
611 const RenderPassProgramAA* program = renderPassProgramAA(); | 666 const RenderPassProgramAA* program = renderPassProgramAA(); |
612 GLC(context(), context()->useProgram(program->program())); | 667 setUseProgram(program->program()); |
613 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLoc ation(), 0)); | 668 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLoc ation(), 0)); |
614 | 669 |
615 shaderQuadLocation = program->vertexShader().pointLocation(); | 670 shaderQuadLocation = program->vertexShader().pointLocation(); |
616 shaderEdgeLocation = program->fragmentShader().edgeLocation(); | 671 shaderEdgeLocation = program->fragmentShader().edgeLocation(); |
617 shaderMatrixLocation = program->vertexShader().matrixLocation(); | 672 shaderMatrixLocation = program->vertexShader().matrixLocation(); |
618 shaderAlphaLocation = program->fragmentShader().alphaLocation(); | 673 shaderAlphaLocation = program->fragmentShader().alphaLocation(); |
619 } else { | 674 } else { |
620 const RenderPassProgram* program = renderPassProgram(); | 675 const RenderPassProgram* program = renderPassProgram(); |
621 GLC(context(), context()->useProgram(program->program())); | 676 setUseProgram(program->program()); |
622 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLoc ation(), 0)); | 677 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLoc ation(), 0)); |
623 | 678 |
624 shaderMatrixLocation = program->vertexShader().matrixLocation(); | 679 shaderMatrixLocation = program->vertexShader().matrixLocation(); |
625 shaderAlphaLocation = program->fragmentShader().alphaLocation(); | 680 shaderAlphaLocation = program->fragmentShader().alphaLocation(); |
626 } | 681 } |
627 | 682 |
628 if (shaderMaskSamplerLocation != -1) { | 683 if (shaderMaskSamplerLocation != -1) { |
629 DCHECK(shaderMaskTexCoordScaleLocation != 1); | 684 DCHECK(shaderMaskTexCoordScaleLocation != 1); |
630 DCHECK(shaderMaskTexCoordOffsetLocation != 1); | 685 DCHECK(shaderMaskTexCoordOffsetLocation != 1); |
631 GLC(context(), context()->activeTexture(GL_TEXTURE1)); | 686 GLC(context(), context()->activeTexture(GL_TEXTURE1)); |
(...skipping 21 matching lines...) Expand all Loading... | |
653 | 708 |
654 // Flush the compositor context before the filter bitmap goes out of | 709 // Flush the compositor context before the filter bitmap goes out of |
655 // scope, so the draw gets processed before the filter texture gets deleted. | 710 // scope, so the draw gets processed before the filter texture gets deleted. |
656 if (filterBitmap.getTexture()) | 711 if (filterBitmap.getTexture()) |
657 m_context->flush(); | 712 m_context->flush(); |
658 } | 713 } |
659 | 714 |
660 void GLRenderer::drawSolidColorQuad(const DrawingFrame& frame, const SolidColorD rawQuad* quad) | 715 void GLRenderer::drawSolidColorQuad(const DrawingFrame& frame, const SolidColorD rawQuad* quad) |
661 { | 716 { |
662 const SolidColorProgram* program = solidColorProgram(); | 717 const SolidColorProgram* program = solidColorProgram(); |
663 GLC(context(), context()->useProgram(program->program())); | 718 setUseProgram(program->program()); |
664 | 719 |
665 SkColor color = quad->color; | 720 SkColor color = quad->color; |
666 float opacity = quad->opacity(); | 721 float opacity = quad->opacity(); |
667 float alpha = (SkColorGetA(color) / 255.0) * opacity; | 722 float alpha = (SkColorGetA(color) / 255.0) * opacity; |
668 | 723 |
669 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, ( SkColorGetB(color) / 255.0) * alpha, alpha)); | 724 GLC(context(), context()->uniform4f(program->fragmentShader().colorLocation( ), (SkColorGetR(color) / 255.0) * alpha, (SkColorGetG(color) / 255.0) * alpha, ( SkColorGetB(color) / 255.0) * alpha, alpha)); |
670 | 725 |
671 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); | 726 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); |
672 } | 727 } |
673 | 728 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
771 else | 826 else |
772 tileUniformLocation(tileProgram(), uniforms); | 827 tileUniformLocation(tileProgram(), uniforms); |
773 } else { | 828 } else { |
774 if (quad->swizzle_contents) | 829 if (quad->swizzle_contents) |
775 tileUniformLocation(tileProgramSwizzleOpaque(), uniforms); | 830 tileUniformLocation(tileProgramSwizzleOpaque(), uniforms); |
776 else | 831 else |
777 tileUniformLocation(tileProgramOpaque(), uniforms); | 832 tileUniformLocation(tileProgramOpaque(), uniforms); |
778 } | 833 } |
779 } | 834 } |
780 | 835 |
781 GLC(context(), context()->useProgram(uniforms.program)); | 836 setUseProgram(uniforms.program); |
782 GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0)); | 837 GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0)); |
783 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad ->resource_id); | 838 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad ->resource_id); |
784 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur eId())); | 839 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur eId())); |
785 | 840 |
786 bool useAA = !clipped && quad->IsAntialiased(); | 841 bool useAA = !clipped && quad->IsAntialiased(); |
787 if (useAA) { | 842 if (useAA) { |
788 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceLayerQuad.Bound ingBox())); | 843 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceLayerQuad.Bound ingBox())); |
789 deviceLayerBounds.inflateAntiAliasingDistance(); | 844 deviceLayerBounds.inflateAntiAliasingDistance(); |
790 | 845 |
791 LayerQuad deviceLayerEdges = LayerQuad(deviceLayerQuad); | 846 LayerQuad deviceLayerEdges = LayerQuad(deviceLayerQuad); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
888 ResourceProvider::ScopedReadLockGL yPlaneLock(m_resourceProvider, yPlane.res ourceId); | 943 ResourceProvider::ScopedReadLockGL yPlaneLock(m_resourceProvider, yPlane.res ourceId); |
889 ResourceProvider::ScopedReadLockGL uPlaneLock(m_resourceProvider, uPlane.res ourceId); | 944 ResourceProvider::ScopedReadLockGL uPlaneLock(m_resourceProvider, uPlane.res ourceId); |
890 ResourceProvider::ScopedReadLockGL vPlaneLock(m_resourceProvider, vPlane.res ourceId); | 945 ResourceProvider::ScopedReadLockGL vPlaneLock(m_resourceProvider, vPlane.res ourceId); |
891 GLC(context(), context()->activeTexture(GL_TEXTURE1)); | 946 GLC(context(), context()->activeTexture(GL_TEXTURE1)); |
892 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, yPlaneLock.textureId()) ); | 947 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, yPlaneLock.textureId()) ); |
893 GLC(context(), context()->activeTexture(GL_TEXTURE2)); | 948 GLC(context(), context()->activeTexture(GL_TEXTURE2)); |
894 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, uPlaneLock.textureId()) ); | 949 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, uPlaneLock.textureId()) ); |
895 GLC(context(), context()->activeTexture(GL_TEXTURE3)); | 950 GLC(context(), context()->activeTexture(GL_TEXTURE3)); |
896 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, vPlaneLock.textureId()) ); | 951 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, vPlaneLock.textureId()) ); |
897 | 952 |
898 GLC(context(), context()->useProgram(program->program())); | 953 setUseProgram(program->program()); |
899 | 954 |
900 GLC(context(), context()->uniform2f(program->vertexShader().texScaleLocation (), quad->tex_scale.width(), quad->tex_scale.height())); | 955 GLC(context(), context()->uniform2f(program->vertexShader().texScaleLocation (), quad->tex_scale.width(), quad->tex_scale.height())); |
901 GLC(context(), context()->uniform1i(program->fragmentShader().yTextureLocati on(), 1)); | 956 GLC(context(), context()->uniform1i(program->fragmentShader().yTextureLocati on(), 1)); |
902 GLC(context(), context()->uniform1i(program->fragmentShader().uTextureLocati on(), 2)); | 957 GLC(context(), context()->uniform1i(program->fragmentShader().uTextureLocati on(), 2)); |
903 GLC(context(), context()->uniform1i(program->fragmentShader().vTextureLocati on(), 3)); | 958 GLC(context(), context()->uniform1i(program->fragmentShader().vTextureLocati on(), 3)); |
904 | 959 |
905 // These values are magic numbers that are used in the transformation from Y UV to RGB color values. | 960 // These values are magic numbers that are used in the transformation from Y UV to RGB color values. |
906 // They are taken from the following webpage: http://www.fourcc.org/fccyvrgb .php | 961 // They are taken from the following webpage: http://www.fourcc.org/fccyvrgb .php |
907 float yuv2RGB[9] = { | 962 float yuv2RGB[9] = { |
908 1.164f, 1.164f, 1.164f, | 963 1.164f, 1.164f, 1.164f, |
(...skipping 22 matching lines...) Expand all Loading... | |
931 GLC(context(), context()->activeTexture(GL_TEXTURE0)); | 986 GLC(context(), context()->activeTexture(GL_TEXTURE0)); |
932 } | 987 } |
933 | 988 |
934 void GLRenderer::drawStreamVideoQuad(const DrawingFrame& frame, const StreamVide oDrawQuad* quad) | 989 void GLRenderer::drawStreamVideoQuad(const DrawingFrame& frame, const StreamVide oDrawQuad* quad) |
935 { | 990 { |
936 static float glMatrix[16]; | 991 static float glMatrix[16]; |
937 | 992 |
938 DCHECK(m_capabilities.usingEglImage); | 993 DCHECK(m_capabilities.usingEglImage); |
939 | 994 |
940 const VideoStreamTextureProgram* program = videoStreamTextureProgram(); | 995 const VideoStreamTextureProgram* program = videoStreamTextureProgram(); |
941 GLC(context(), context()->useProgram(program->program())); | 996 setUseProgram(program->program()); |
942 | 997 |
943 toGLMatrix(&glMatrix[0], quad->matrix); | 998 toGLMatrix(&glMatrix[0], quad->matrix); |
944 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().texMatrix Location(), 1, false, glMatrix)); | 999 GLC(context(), context()->uniformMatrix4fv(program->vertexShader().texMatrix Location(), 1, false, glMatrix)); |
945 | 1000 |
946 GLC(context(), context()->bindTexture(GL_TEXTURE_EXTERNAL_OES, quad->texture _id)); | 1001 GLC(context(), context()->bindTexture(GL_TEXTURE_EXTERNAL_OES, quad->texture _id)); |
947 | 1002 |
948 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio n(), 0)); | 1003 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio n(), 0)); |
949 | 1004 |
950 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ; | 1005 setShaderOpacity(quad->opacity(), program->fragmentShader().alphaLocation()) ; |
951 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); | 1006 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, program->vertexSh ader().matrixLocation()); |
(...skipping 18 matching lines...) Expand all Loading... | |
970 struct TexTransformTextureProgramBinding : TextureProgramBinding { | 1025 struct TexTransformTextureProgramBinding : TextureProgramBinding { |
971 template<class Program> void set( | 1026 template<class Program> void set( |
972 Program* program, WebKit::WebGraphicsContext3D* context) | 1027 Program* program, WebKit::WebGraphicsContext3D* context) |
973 { | 1028 { |
974 TextureProgramBinding::set(program, context); | 1029 TextureProgramBinding::set(program, context); |
975 texTransformLocation = program->vertexShader().texTransformLocation(); | 1030 texTransformLocation = program->vertexShader().texTransformLocation(); |
976 } | 1031 } |
977 int texTransformLocation; | 1032 int texTransformLocation; |
978 }; | 1033 }; |
979 | 1034 |
1035 void GLRenderer::drawTextureQuadFlush() | |
1036 { | |
1037 // Check to see if we have anything to draw | |
1038 if (m_drawCache->programID == 0) | |
1039 return; | |
1040 | |
1041 // Set the correct blending mode | |
1042 setBlendEnabled(m_drawCache->needsBlending); | |
1043 | |
1044 // Bind the program to the GL state | |
1045 setUseProgram(m_drawCache->programID); | |
1046 | |
1047 // Bind the texture to slot 0 | |
1048 GLC(context(), context()->activeTexture(GL_TEXTURE0)); | |
1049 ResourceProvider::ScopedReadLockGL lockedQuad(m_resourceProvider, m_drawCach e->resourceID); | |
1050 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, lockedQuad.textureId()) ); | |
1051 | |
1052 // set up premultiplied alpha | |
1053 if (!m_drawCache->usePremultipliedAlpha) { | |
1054 // As it turns out, the premultiplied alpha blending function (ONE, ONE_MI NUS_SRC_ALPHA) | |
1055 // will never cause the alpha channel to be set to anything less than 1. 0 if it is | |
1056 // initialized to that value! Therefore, premultipliedAlpha being false is the first | |
1057 // situation we can generally see an alpha channel less than 1.0 coming out of the | |
1058 // compositor. This is causing platform differences in some layout tests (see | |
1059 // https://bugs.webkit.org/show_bug.cgi?id=82412), so in this situation, use a separate | |
1060 // blend function for the alpha channel to avoid modifying it. Don't use colorMask for this | |
1061 // as it has performance implications on some platforms. | |
1062 GLC(context(), context()->blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_S RC_ALPHA, GL_ZERO, GL_ONE)); | |
1063 } | |
1064 | |
1065 // Set the shader opacity | |
1066 setShaderOpacity(m_drawCache->alpha, m_drawCache->alphaLocation); | |
1067 | |
1068 // Upload the tranforms for both points and uvs | |
1069 GLC(m_context, m_context->uniformMatrix4fv((int)m_drawCache->matrixLocation, (int)m_drawCache->matrixData.size(), false, (float*)&m_drawCache->matrixData.fr ont())); | |
1070 GLC(m_context, m_context->uniform4fv((int)m_drawCache->uvXformLocation, (int )m_drawCache->uvXformData.size(), (float*)&m_drawCache->uvXformData.front())); | |
1071 | |
1072 // Draw the quads! | |
1073 GLC(m_context, m_context->drawElements(GL_TRIANGLES, 6 * m_drawCache->matrix Data.size(), GL_UNSIGNED_SHORT, 0)); | |
1074 | |
1075 // Clean up after ourselves (reset state set above) | |
1076 if (!m_drawCache->usePremultipliedAlpha) | |
1077 GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | |
1078 | |
1079 // Clear the cache | |
1080 m_drawCache->programID = 0; | |
1081 m_drawCache->uvXformData.resize(0); | |
1082 m_drawCache->matrixData.resize(0); | |
1083 } | |
1084 | |
1085 void GLRenderer::drawTextureQuadPush(const DrawingFrame& frame, const TextureDra wQuad* quad) | |
shawnsingh
2012/11/28 19:44:16
The name at a glance doesn't make me think about t
whunt
2012/11/28 22:01:15
I like that suggestion. Done.
On 2012/11/28 19:44
| |
1086 { | |
1087 // Choose the correcte texture program binding | |
1088 TexTransformTextureProgramBinding binding; | |
1089 if (quad->flipped) | |
1090 binding.set(textureProgramFlip(), context()); | |
1091 else | |
1092 binding.set(textureProgram(), context()); | |
1093 | |
1094 int resourceID = quad->resource_id; | |
1095 | |
1096 if (m_drawCache->programID != binding.programId || | |
1097 m_drawCache->resourceID != resourceID || | |
1098 m_drawCache->alpha != quad->opacity() || | |
1099 m_drawCache->usePremultipliedAlpha != quad->premultiplied_alpha || | |
1100 m_drawCache->needsBlending != quad->ShouldDrawWithBlending() || | |
1101 m_drawCache->matrixData.size() >= 8) | |
1102 { | |
1103 drawTextureQuadFlush(); | |
1104 m_drawCache->programID = binding.programId; | |
1105 m_drawCache->resourceID = resourceID; | |
1106 m_drawCache->alpha = quad->opacity(); | |
1107 m_drawCache->usePremultipliedAlpha = quad->premultiplied_alpha; | |
1108 m_drawCache->needsBlending = quad->ShouldDrawWithBlending(); | |
1109 | |
1110 m_drawCache->alphaLocation = binding.alphaLocation; | |
1111 m_drawCache->uvXformLocation = binding.texTransformLocation; | |
1112 m_drawCache->matrixLocation = binding.matrixLocation; | |
1113 } | |
1114 | |
1115 // Generate the uv-transform | |
1116 const gfx::RectF& uvRect = quad->uv_rect; | |
1117 Vector uv(uvRect.x(), uvRect.y(), uvRect.width(), uvRect.height()); | |
1118 m_drawCache->uvXformData.push_back(uv); | |
1119 | |
1120 // Generate the transform matrix | |
1121 gfx::Transform quadRectMatrix; | |
1122 quadRectTransform(&quadRectMatrix, quad->quadTransform(), quad->rect); | |
1123 quadRectMatrix = frame.projectionMatrix * quadRectMatrix; | |
1124 | |
1125 Matrix m; | |
1126 quadRectMatrix.matrix().asColMajorf((float*)&m); | |
1127 m_drawCache->matrixData.push_back(m); | |
1128 } | |
1129 | |
980 void GLRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureDrawQua d* quad) | 1130 void GLRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureDrawQua d* quad) |
981 { | 1131 { |
982 TexTransformTextureProgramBinding binding; | 1132 TexTransformTextureProgramBinding binding; |
983 if (quad->flipped) | 1133 if (quad->flipped) |
984 binding.set(textureProgramFlip(), context()); | 1134 binding.set(textureProgramFlip(), context()); |
985 else | 1135 else |
986 binding.set(textureProgram(), context()); | 1136 binding.set(textureProgram(), context()); |
987 GLC(context(), context()->useProgram(binding.programId)); | 1137 setUseProgram(binding.programId); |
988 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); | 1138 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); |
989 const gfx::RectF& uvRect = quad->uv_rect; | 1139 const gfx::RectF& uvRect = quad->uv_rect; |
990 GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x() , uvRect.y(), uvRect.width(), uvRect.height())); | 1140 GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x() , uvRect.y(), uvRect.width(), uvRect.height())); |
991 | 1141 |
992 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad ->resource_id); | 1142 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad ->resource_id); |
993 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur eId())); | 1143 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur eId())); |
994 | 1144 |
995 if (!quad->premultiplied_alpha) { | 1145 if (!quad->premultiplied_alpha) { |
996 // As it turns out, the premultiplied alpha blending function (ONE, ONE_ MINUS_SRC_ALPHA) | 1146 // As it turns out, the premultiplied alpha blending function (ONE, ONE_ MINUS_SRC_ALPHA) |
997 // will never cause the alpha channel to be set to anything less than 1. 0 if it is | 1147 // will never cause the alpha channel to be set to anything less than 1. 0 if it is |
(...skipping 11 matching lines...) Expand all Loading... | |
1009 | 1159 |
1010 if (!quad->premultiplied_alpha) | 1160 if (!quad->premultiplied_alpha) |
1011 GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); | 1161 GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); |
1012 } | 1162 } |
1013 | 1163 |
1014 void GLRenderer::drawIOSurfaceQuad(const DrawingFrame& frame, const IOSurfaceDra wQuad* quad) | 1164 void GLRenderer::drawIOSurfaceQuad(const DrawingFrame& frame, const IOSurfaceDra wQuad* quad) |
1015 { | 1165 { |
1016 TexTransformTextureProgramBinding binding; | 1166 TexTransformTextureProgramBinding binding; |
1017 binding.set(textureIOSurfaceProgram(), context()); | 1167 binding.set(textureIOSurfaceProgram(), context()); |
1018 | 1168 |
1019 GLC(context(), context()->useProgram(binding.programId)); | 1169 setUseProgram(binding.programId); |
1020 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); | 1170 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); |
1021 if (quad->orientation == IOSurfaceDrawQuad::FLIPPED) | 1171 if (quad->orientation == IOSurfaceDrawQuad::FLIPPED) |
1022 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, qua d->io_surface_size.height(), quad->io_surface_size.width(), quad->io_surface_siz e.height() * -1.0)); | 1172 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, qua d->io_surface_size.height(), quad->io_surface_size.width(), quad->io_surface_siz e.height() * -1.0)); |
1023 else | 1173 else |
1024 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0, quad->io_surface_size.width(), quad->io_surface_size.height())); | 1174 GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0, quad->io_surface_size.width(), quad->io_surface_size.height())); |
1025 | 1175 |
1026 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, quad->io_sur face_texture_id)); | 1176 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, quad->io_sur face_texture_id)); |
1027 | 1177 |
1028 setShaderOpacity(quad->opacity(), binding.alphaLocation); | 1178 setShaderOpacity(quad->opacity(), binding.alphaLocation); |
1029 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, binding.matrixLoc ation); | 1179 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, binding.matrixLoc ation); |
1030 | 1180 |
1031 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); | 1181 GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, 0)); |
1032 } | 1182 } |
1033 | 1183 |
1034 void GLRenderer::finishDrawingFrame(DrawingFrame& frame) | 1184 void GLRenderer::finishDrawingFrame(DrawingFrame& frame) |
1035 { | 1185 { |
1036 m_currentFramebufferLock.reset(); | 1186 m_currentFramebufferLock.reset(); |
1037 m_swapBufferRect.Union(gfx::ToEnclosingRect(frame.rootDamageRect)); | 1187 m_swapBufferRect.Union(gfx::ToEnclosingRect(frame.rootDamageRect)); |
1038 | 1188 |
1039 GLC(m_context, m_context->disable(GL_BLEND)); | 1189 GLC(m_context, m_context->disable(GL_BLEND)); |
1190 m_blendShadow = false; | |
1191 } | |
1192 | |
1193 void GLRenderer::finishDrawingQuadList() | |
1194 { | |
1195 drawTextureQuadFlush(); | |
1040 } | 1196 } |
1041 | 1197 |
1042 bool GLRenderer::flippedFramebuffer() const | 1198 bool GLRenderer::flippedFramebuffer() const |
1043 { | 1199 { |
1044 return true; | 1200 return true; |
1045 } | 1201 } |
1046 | 1202 |
1047 void GLRenderer::ensureScissorTestEnabled() | 1203 void GLRenderer::ensureScissorTestEnabled() |
1048 { | 1204 { |
1049 if (m_isScissorEnabled) | 1205 if (m_isScissorEnabled) |
1050 return; | 1206 return; |
1051 | 1207 |
1208 drawTextureQuadFlush(); | |
1052 GLC(m_context, m_context->enable(GL_SCISSOR_TEST)); | 1209 GLC(m_context, m_context->enable(GL_SCISSOR_TEST)); |
1053 m_isScissorEnabled = true; | 1210 m_isScissorEnabled = true; |
1054 } | 1211 } |
1055 | 1212 |
1056 void GLRenderer::ensureScissorTestDisabled() | 1213 void GLRenderer::ensureScissorTestDisabled() |
1057 { | 1214 { |
1058 if (!m_isScissorEnabled) | 1215 if (!m_isScissorEnabled) |
1059 return; | 1216 return; |
1060 | 1217 |
1218 drawTextureQuadFlush(); | |
1061 GLC(m_context, m_context->disable(GL_SCISSOR_TEST)); | 1219 GLC(m_context, m_context->disable(GL_SCISSOR_TEST)); |
1062 m_isScissorEnabled = false; | 1220 m_isScissorEnabled = false; |
1063 } | 1221 } |
1064 | 1222 |
1065 void GLRenderer::toGLMatrix(float* glMatrix, const gfx::Transform& transform) | 1223 void GLRenderer::toGLMatrix(float* glMatrix, const gfx::Transform& transform) |
1066 { | 1224 { |
1067 transform.matrix().asColMajorf(glMatrix); | 1225 transform.matrix().asColMajorf(glMatrix); |
1068 } | 1226 } |
1069 | 1227 |
1070 void GLRenderer::setShaderQuadF(const gfx::QuadF& quad, int quadLocation) | 1228 void GLRenderer::setShaderQuadF(const gfx::QuadF& quad, int quadLocation) |
(...skipping 12 matching lines...) Expand all Loading... | |
1083 point[7] = quad.p4().y(); | 1241 point[7] = quad.p4().y(); |
1084 GLC(m_context, m_context->uniform2fv(quadLocation, 4, point)); | 1242 GLC(m_context, m_context->uniform2fv(quadLocation, 4, point)); |
1085 } | 1243 } |
1086 | 1244 |
1087 void GLRenderer::setShaderOpacity(float opacity, int alphaLocation) | 1245 void GLRenderer::setShaderOpacity(float opacity, int alphaLocation) |
1088 { | 1246 { |
1089 if (alphaLocation != -1) | 1247 if (alphaLocation != -1) |
1090 GLC(m_context, m_context->uniform1f(alphaLocation, opacity)); | 1248 GLC(m_context, m_context->uniform1f(alphaLocation, opacity)); |
1091 } | 1249 } |
1092 | 1250 |
1251 void GLRenderer::setBlendEnabled(bool enabled) | |
1252 { | |
1253 if (enabled != m_blendShadow) | |
1254 { | |
1255 if (enabled) | |
1256 GLC(m_context, m_context->enable(GL_BLEND)); | |
1257 else | |
1258 GLC(m_context, m_context->disable(GL_BLEND)); | |
1259 m_blendShadow = enabled; | |
1260 } | |
1261 } | |
1262 | |
1263 void GLRenderer::setUseProgram(unsigned program) | |
1264 { | |
1265 if (program != m_programShadow) | |
1266 { | |
1267 GLC(m_context, m_context->useProgram(program)); | |
1268 m_programShadow = program; | |
1269 } | |
1270 } | |
1271 | |
1093 void GLRenderer::drawQuadGeometry(const DrawingFrame& frame, const gfx::Transfor m& drawTransform, const gfx::RectF& quadRect, int matrixLocation) | 1272 void GLRenderer::drawQuadGeometry(const DrawingFrame& frame, const gfx::Transfor m& drawTransform, const gfx::RectF& quadRect, int matrixLocation) |
1094 { | 1273 { |
1095 gfx::Transform quadRectMatrix; | 1274 gfx::Transform quadRectMatrix; |
1096 quadRectTransform(&quadRectMatrix, drawTransform, quadRect); | 1275 quadRectTransform(&quadRectMatrix, drawTransform, quadRect); |
1097 static float glMatrix[16]; | 1276 static float glMatrix[16]; |
1098 toGLMatrix(&glMatrix[0], frame.projectionMatrix * quadRectMatrix); | 1277 toGLMatrix(&glMatrix[0], frame.projectionMatrix * quadRectMatrix); |
1099 GLC(m_context, m_context->uniformMatrix4fv(matrixLocation, 1, false, &glMatr ix[0])); | 1278 GLC(m_context, m_context->uniformMatrix4fv(matrixLocation, 1, false, &glMatr ix[0])); |
1100 | 1279 |
1101 GLC(m_context, m_context->drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0 )); | 1280 GLC(m_context, m_context->drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0 )); |
1102 } | 1281 } |
1103 | 1282 |
1104 void GLRenderer::copyTextureToFramebuffer(const DrawingFrame& frame, int texture Id, const gfx::Rect& rect, const gfx::Transform& drawMatrix) | 1283 void GLRenderer::copyTextureToFramebuffer(const DrawingFrame& frame, int texture Id, const gfx::Rect& rect, const gfx::Transform& drawMatrix) |
1105 { | 1284 { |
1106 const RenderPassProgram* program = renderPassProgram(); | 1285 const RenderPassProgram* program = renderPassProgram(); |
1107 | 1286 |
1108 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, textureId)); | 1287 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, textureId)); |
1109 | 1288 |
1110 GLC(context(), context()->useProgram(program->program())); | 1289 setUseProgram(program->program()); |
1111 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio n(), 0)); | 1290 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio n(), 0)); |
1112 setShaderOpacity(1, program->fragmentShader().alphaLocation()); | 1291 setShaderOpacity(1, program->fragmentShader().alphaLocation()); |
1113 drawQuadGeometry(frame, drawMatrix, rect, program->vertexShader().matrixLoca tion()); | 1292 drawQuadGeometry(frame, drawMatrix, rect, program->vertexShader().matrixLoca tion()); |
1114 } | 1293 } |
1115 | 1294 |
1116 void GLRenderer::finish() | 1295 void GLRenderer::finish() |
1117 { | 1296 { |
1118 TRACE_EVENT0("cc", "GLRenderer::finish"); | 1297 TRACE_EVENT0("cc", "GLRenderer::finish"); |
1119 m_context->finish(); | 1298 m_context->finish(); |
1120 } | 1299 } |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1351 void GLRenderer::setScissorTestRect(const gfx::Rect& scissorRect) | 1530 void GLRenderer::setScissorTestRect(const gfx::Rect& scissorRect) |
1352 { | 1531 { |
1353 ensureScissorTestEnabled(); | 1532 ensureScissorTestEnabled(); |
1354 | 1533 |
1355 // Don't unnecessarily ask the context to change the scissor, because it | 1534 // Don't unnecessarily ask the context to change the scissor, because it |
1356 // may cause undesired GPU pipeline flushes. | 1535 // may cause undesired GPU pipeline flushes. |
1357 if (scissorRect == m_scissorRect) | 1536 if (scissorRect == m_scissorRect) |
1358 return; | 1537 return; |
1359 | 1538 |
1360 m_scissorRect = scissorRect; | 1539 m_scissorRect = scissorRect; |
1540 drawTextureQuadFlush(); | |
1361 GLC(m_context, m_context->scissor(scissorRect.x(), scissorRect.y(), scissorR ect.width(), scissorRect.height())); | 1541 GLC(m_context, m_context->scissor(scissorRect.x(), scissorRect.y(), scissorR ect.width(), scissorRect.height())); |
1362 } | 1542 } |
1363 | 1543 |
1364 void GLRenderer::setDrawViewportSize(const gfx::Size& viewportSize) | 1544 void GLRenderer::setDrawViewportSize(const gfx::Size& viewportSize) |
1365 { | 1545 { |
1366 GLC(m_context, m_context->viewport(0, 0, viewportSize.width(), viewportSize. height())); | 1546 GLC(m_context, m_context->viewport(0, 0, viewportSize.width(), viewportSize. height())); |
1367 } | 1547 } |
1368 | 1548 |
1369 bool GLRenderer::makeContextCurrent() | 1549 bool GLRenderer::makeContextCurrent() |
1370 { | 1550 { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1520 return m_tileProgramSwizzleAA.get(); | 1700 return m_tileProgramSwizzleAA.get(); |
1521 } | 1701 } |
1522 | 1702 |
1523 const GLRenderer::TextureProgram* GLRenderer::textureProgram() | 1703 const GLRenderer::TextureProgram* GLRenderer::textureProgram() |
1524 { | 1704 { |
1525 if (!m_textureProgram) | 1705 if (!m_textureProgram) |
1526 m_textureProgram = make_scoped_ptr(new TextureProgram(m_context)); | 1706 m_textureProgram = make_scoped_ptr(new TextureProgram(m_context)); |
1527 if (!m_textureProgram->initialized()) { | 1707 if (!m_textureProgram->initialized()) { |
1528 TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); | 1708 TRACE_EVENT0("cc", "GLRenderer::textureProgram::initialize"); |
1529 m_textureProgram->initialize(m_context, m_isUsingBindUniform); | 1709 m_textureProgram->initialize(m_context, m_isUsingBindUniform); |
1710 GLC(context(), context()->uniform1i(m_textureProgram.get()->fragmentShad er().samplerLocation(), 0)); | |
1530 } | 1711 } |
1531 return m_textureProgram.get(); | 1712 return m_textureProgram.get(); |
1532 } | 1713 } |
1533 | 1714 |
1534 const GLRenderer::TextureProgramFlip* GLRenderer::textureProgramFlip() | 1715 const GLRenderer::TextureProgramFlip* GLRenderer::textureProgramFlip() |
1535 { | 1716 { |
1536 if (!m_textureProgramFlip) | 1717 if (!m_textureProgramFlip) |
1537 m_textureProgramFlip = make_scoped_ptr(new TextureProgramFlip(m_context) ); | 1718 m_textureProgramFlip = make_scoped_ptr(new TextureProgramFlip(m_context) ); |
1538 if (!m_textureProgramFlip->initialized()) { | 1719 if (!m_textureProgramFlip->initialized()) { |
1539 TRACE_EVENT0("cc", "GLRenderer::textureProgramFlip::initialize"); | 1720 TRACE_EVENT0("cc", "GLRenderer::textureProgramFlip::initialize"); |
1540 m_textureProgramFlip->initialize(m_context, m_isUsingBindUniform); | 1721 m_textureProgramFlip->initialize(m_context, m_isUsingBindUniform); |
1722 GLC(context(), context()->uniform1i(m_textureProgramFlip.get()->fragment Shader().samplerLocation(), 0)); | |
1541 } | 1723 } |
1542 return m_textureProgramFlip.get(); | 1724 return m_textureProgramFlip.get(); |
1543 } | 1725 } |
1544 | 1726 |
1545 const GLRenderer::TextureIOSurfaceProgram* GLRenderer::textureIOSurfaceProgram() | 1727 const GLRenderer::TextureIOSurfaceProgram* GLRenderer::textureIOSurfaceProgram() |
1546 { | 1728 { |
1547 if (!m_textureIOSurfaceProgram) | 1729 if (!m_textureIOSurfaceProgram) |
1548 m_textureIOSurfaceProgram = make_scoped_ptr(new TextureIOSurfaceProgram( m_context)); | 1730 m_textureIOSurfaceProgram = make_scoped_ptr(new TextureIOSurfaceProgram( m_context)); |
1549 if (!m_textureIOSurfaceProgram->initialized()) { | 1731 if (!m_textureIOSurfaceProgram->initialized()) { |
1550 TRACE_EVENT0("cc", "GLRenderer::textureIOSurfaceProgram::initialize"); | 1732 TRACE_EVENT0("cc", "GLRenderer::textureIOSurfaceProgram::initialize"); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1625 | 1807 |
1626 releaseRenderPassTextures(); | 1808 releaseRenderPassTextures(); |
1627 } | 1809 } |
1628 | 1810 |
1629 bool GLRenderer::isContextLost() | 1811 bool GLRenderer::isContextLost() |
1630 { | 1812 { |
1631 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); | 1813 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); |
1632 } | 1814 } |
1633 | 1815 |
1634 } // namespace cc | 1816 } // namespace cc |
OLD | NEW |