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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 if (!backgroundTexture->Allocate(Renderer::ImplPool, quad->rect.size(), GL_R
GBA, ResourceProvider::TextureUsageFramebuffer)) | 487 if (!backgroundTexture->Allocate(Renderer::ImplPool, quad->rect.size(), GL_R
GBA, ResourceProvider::TextureUsageFramebuffer)) |
488 return scoped_ptr<ScopedResource>(); | 488 return scoped_ptr<ScopedResource>(); |
489 | 489 |
490 const RenderPass* targetRenderPass = frame.currentRenderPass; | 490 const RenderPass* targetRenderPass = frame.currentRenderPass; |
491 bool usingBackgroundTexture = useScopedTexture(frame, backgroundTexture.get(
), quad->rect); | 491 bool usingBackgroundTexture = useScopedTexture(frame, backgroundTexture.get(
), quad->rect); |
492 | 492 |
493 if (usingBackgroundTexture) { | 493 if (usingBackgroundTexture) { |
494 // Copy the readback pixels from device to the background texture for th
e surface. | 494 // Copy the readback pixels from device to the background texture for th
e surface. |
495 gfx::Transform deviceToFramebufferTransform; | 495 gfx::Transform deviceToFramebufferTransform; |
496 deviceToFramebufferTransform.Translate(quad->rect.width() / 2.0, quad->r
ect.height() / 2.0); | 496 deviceToFramebufferTransform.Translate(quad->rect.width() / 2.0, quad->r
ect.height() / 2.0); |
497 deviceToFramebufferTransform.Scale3d(quad->rect.width(), quad->rect.heig
ht(), 1); | 497 deviceToFramebufferTransform.Scale(quad->rect.width(), quad->rect.height
()); |
498 deviceToFramebufferTransform.PreconcatTransform(contentsDeviceTransformI
nverse); | 498 deviceToFramebufferTransform.PreconcatTransform(contentsDeviceTransformI
nverse); |
499 copyTextureToFramebuffer(frame, filteredDeviceBackgroundTextureId, devic
eRect, deviceToFramebufferTransform); | 499 copyTextureToFramebuffer(frame, filteredDeviceBackgroundTextureId, devic
eRect, deviceToFramebufferTransform); |
500 } | 500 } |
501 | 501 |
502 useRenderPass(frame, targetRenderPass); | 502 useRenderPass(frame, targetRenderPass); |
503 | 503 |
504 if (!usingBackgroundTexture) | 504 if (!usingBackgroundTexture) |
505 return scoped_ptr<ScopedResource>(); | 505 return scoped_ptr<ScopedResource>(); |
506 return backgroundTexture.Pass(); | 506 return backgroundTexture.Pass(); |
507 } | 507 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 contentsResourceLock = make_scoped_ptr(new ResourceProvider::ScopedSampl
erGL(m_resourceProvider, contentsTexture->id(), | 576 contentsResourceLock = make_scoped_ptr(new ResourceProvider::ScopedSampl
erGL(m_resourceProvider, contentsTexture->id(), |
577
GL_TEXTURE_2D, GL_LINEAR)); | 577
GL_TEXTURE_2D, GL_LINEAR)); |
578 | 578 |
579 int shaderQuadLocation = -1; | 579 int shaderQuadLocation = -1; |
580 int shaderEdgeLocation = -1; | 580 int shaderEdgeLocation = -1; |
581 int shaderMaskSamplerLocation = -1; | 581 int shaderMaskSamplerLocation = -1; |
582 int shaderMaskTexCoordScaleLocation = -1; | 582 int shaderMaskTexCoordScaleLocation = -1; |
583 int shaderMaskTexCoordOffsetLocation = -1; | 583 int shaderMaskTexCoordOffsetLocation = -1; |
584 int shaderMatrixLocation = -1; | 584 int shaderMatrixLocation = -1; |
585 int shaderAlphaLocation = -1; | 585 int shaderAlphaLocation = -1; |
| 586 int shaderTexTransformLocation = -1; |
| 587 int shaderTexScaleLocation = -1; |
| 588 |
586 if (useAA && maskTextureId) { | 589 if (useAA && maskTextureId) { |
587 const RenderPassMaskProgramAA* program = renderPassMaskProgramAA(); | 590 const RenderPassMaskProgramAA* program = renderPassMaskProgramAA(); |
588 setUseProgram(program->program()); | 591 setUseProgram(program->program()); |
589 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLoc
ation(), 0)); | 592 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLoc
ation(), 0)); |
590 | 593 |
591 shaderQuadLocation = program->vertexShader().pointLocation(); | 594 shaderQuadLocation = program->vertexShader().pointLocation(); |
592 shaderEdgeLocation = program->fragmentShader().edgeLocation(); | 595 shaderEdgeLocation = program->fragmentShader().edgeLocation(); |
593 shaderMaskSamplerLocation = program->fragmentShader().maskSamplerLocatio
n(); | 596 shaderMaskSamplerLocation = program->fragmentShader().maskSamplerLocatio
n(); |
594 shaderMaskTexCoordScaleLocation = program->fragmentShader().maskTexCoord
ScaleLocation(); | 597 shaderMaskTexCoordScaleLocation = program->fragmentShader().maskTexCoord
ScaleLocation(); |
595 shaderMaskTexCoordOffsetLocation = program->fragmentShader().maskTexCoor
dOffsetLocation(); | 598 shaderMaskTexCoordOffsetLocation = program->fragmentShader().maskTexCoor
dOffsetLocation(); |
596 shaderMatrixLocation = program->vertexShader().matrixLocation(); | 599 shaderMatrixLocation = program->vertexShader().matrixLocation(); |
597 shaderAlphaLocation = program->fragmentShader().alphaLocation(); | 600 shaderAlphaLocation = program->fragmentShader().alphaLocation(); |
| 601 shaderTexScaleLocation = program->vertexShader().texScaleLocation(); |
598 } else if (!useAA && maskTextureId) { | 602 } else if (!useAA && maskTextureId) { |
599 const RenderPassMaskProgram* program = renderPassMaskProgram(); | 603 const RenderPassMaskProgram* program = renderPassMaskProgram(); |
600 setUseProgram(program->program()); | 604 setUseProgram(program->program()); |
601 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLoc
ation(), 0)); | 605 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLoc
ation(), 0)); |
602 | 606 |
603 shaderMaskSamplerLocation = program->fragmentShader().maskSamplerLocatio
n(); | 607 shaderMaskSamplerLocation = program->fragmentShader().maskSamplerLocatio
n(); |
604 shaderMaskTexCoordScaleLocation = program->fragmentShader().maskTexCoord
ScaleLocation(); | 608 shaderMaskTexCoordScaleLocation = program->fragmentShader().maskTexCoord
ScaleLocation(); |
605 shaderMaskTexCoordOffsetLocation = program->fragmentShader().maskTexCoor
dOffsetLocation(); | 609 shaderMaskTexCoordOffsetLocation = program->fragmentShader().maskTexCoor
dOffsetLocation(); |
606 shaderMatrixLocation = program->vertexShader().matrixLocation(); | 610 shaderMatrixLocation = program->vertexShader().matrixLocation(); |
607 shaderAlphaLocation = program->fragmentShader().alphaLocation(); | 611 shaderAlphaLocation = program->fragmentShader().alphaLocation(); |
| 612 shaderTexTransformLocation = program->vertexShader().texTransformLocatio
n(); |
608 } else if (useAA && !maskTextureId) { | 613 } else if (useAA && !maskTextureId) { |
609 const RenderPassProgramAA* program = renderPassProgramAA(); | 614 const RenderPassProgramAA* program = renderPassProgramAA(); |
610 setUseProgram(program->program()); | 615 setUseProgram(program->program()); |
611 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLoc
ation(), 0)); | 616 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLoc
ation(), 0)); |
612 | 617 |
613 shaderQuadLocation = program->vertexShader().pointLocation(); | 618 shaderQuadLocation = program->vertexShader().pointLocation(); |
614 shaderEdgeLocation = program->fragmentShader().edgeLocation(); | 619 shaderEdgeLocation = program->fragmentShader().edgeLocation(); |
615 shaderMatrixLocation = program->vertexShader().matrixLocation(); | 620 shaderMatrixLocation = program->vertexShader().matrixLocation(); |
616 shaderAlphaLocation = program->fragmentShader().alphaLocation(); | 621 shaderAlphaLocation = program->fragmentShader().alphaLocation(); |
| 622 shaderTexScaleLocation = program->vertexShader().texScaleLocation(); |
617 } else { | 623 } else { |
618 const RenderPassProgram* program = renderPassProgram(); | 624 const RenderPassProgram* program = renderPassProgram(); |
619 setUseProgram(program->program()); | 625 setUseProgram(program->program()); |
620 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLoc
ation(), 0)); | 626 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLoc
ation(), 0)); |
621 | 627 |
622 shaderMatrixLocation = program->vertexShader().matrixLocation(); | 628 shaderMatrixLocation = program->vertexShader().matrixLocation(); |
623 shaderAlphaLocation = program->fragmentShader().alphaLocation(); | 629 shaderAlphaLocation = program->fragmentShader().alphaLocation(); |
| 630 shaderTexTransformLocation = program->vertexShader().texTransformLocatio
n(); |
| 631 } |
| 632 |
| 633 float tex_scale_x = quad->rect.width() / static_cast<float>(contentsTexture-
>size().width()); |
| 634 float tex_scale_y = quad->rect.height() / static_cast<float>(contentsTexture
->size().height()); |
| 635 DCHECK_LE(tex_scale_x, 1.0f); |
| 636 DCHECK_LE(tex_scale_y, 1.0f); |
| 637 |
| 638 if (shaderTexTransformLocation != -1) { |
| 639 GLC(context(), context()->uniform4f(shaderTexTransformLocation, |
| 640 0.0f, 0.0f, |
| 641 tex_scale_x, tex_scale_y)); |
| 642 } else if (shaderTexScaleLocation != -1) { |
| 643 GLC(context(), context()->uniform2f(shaderTexScaleLocation, |
| 644 tex_scale_x, tex_scale_y)); |
| 645 } else { |
| 646 NOTREACHED(); |
624 } | 647 } |
625 | 648 |
626 if (shaderMaskSamplerLocation != -1) { | 649 if (shaderMaskSamplerLocation != -1) { |
627 DCHECK(shaderMaskTexCoordScaleLocation != 1); | 650 DCHECK(shaderMaskTexCoordScaleLocation != 1); |
628 DCHECK(shaderMaskTexCoordOffsetLocation != 1); | 651 DCHECK(shaderMaskTexCoordOffsetLocation != 1); |
629 GLC(context(), context()->activeTexture(GL_TEXTURE1)); | 652 GLC(context(), context()->activeTexture(GL_TEXTURE1)); |
630 GLC(context(), context()->uniform1i(shaderMaskSamplerLocation, 1)); | 653 GLC(context(), context()->uniform1i(shaderMaskSamplerLocation, 1)); |
631 GLC(context(), context()->uniform2f(shaderMaskTexCoordOffsetLocation, qu
ad->mask_uv_rect.x(), quad->mask_uv_rect.y())); | 654 GLC(context(), context()->uniform2f(shaderMaskTexCoordOffsetLocation, |
632 GLC(context(), context()->uniform2f(shaderMaskTexCoordScaleLocation, qua
d->mask_uv_rect.width(), quad->mask_uv_rect.height())); | 655 quad->mask_uv_rect.x(), quad->mask_u
v_rect.y())); |
| 656 GLC(context(), context()->uniform2f(shaderMaskTexCoordScaleLocation, |
| 657 quad->mask_uv_rect.width() / tex_sca
le_x, quad->mask_uv_rect.height() / tex_scale_y)); |
633 m_resourceProvider->bindForSampling(quad->mask_resource_id, GL_TEXTURE_2
D, GL_LINEAR); | 658 m_resourceProvider->bindForSampling(quad->mask_resource_id, GL_TEXTURE_2
D, GL_LINEAR); |
634 GLC(context(), context()->activeTexture(GL_TEXTURE0)); | 659 GLC(context(), context()->activeTexture(GL_TEXTURE0)); |
635 } | 660 } |
636 | 661 |
637 if (shaderEdgeLocation != -1) { | 662 if (shaderEdgeLocation != -1) { |
638 float edge[24]; | 663 float edge[24]; |
639 deviceLayerEdges.toFloatArray(edge); | 664 deviceLayerEdges.toFloatArray(edge); |
640 deviceLayerBounds.toFloatArray(&edge[12]); | 665 deviceLayerBounds.toFloatArray(&edge[12]); |
641 GLC(context(), context()->uniform3fv(shaderEdgeLocation, 8, edge)); | 666 GLC(context(), context()->uniform3fv(shaderEdgeLocation, 8, edge)); |
642 } | 667 } |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 } | 1250 } |
1226 | 1251 |
1227 void GLRenderer::copyTextureToFramebuffer(const DrawingFrame& frame, int texture
Id, const gfx::Rect& rect, const gfx::Transform& drawMatrix) | 1252 void GLRenderer::copyTextureToFramebuffer(const DrawingFrame& frame, int texture
Id, const gfx::Rect& rect, const gfx::Transform& drawMatrix) |
1228 { | 1253 { |
1229 const RenderPassProgram* program = renderPassProgram(); | 1254 const RenderPassProgram* program = renderPassProgram(); |
1230 | 1255 |
1231 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, textureId)); | 1256 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, textureId)); |
1232 | 1257 |
1233 setUseProgram(program->program()); | 1258 setUseProgram(program->program()); |
1234 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio
n(), 0)); | 1259 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio
n(), 0)); |
| 1260 GLC(context(), context()->uniform4f(program->vertexShader().texTransformLoca
tion(), |
| 1261 0.0f, 0.0f, 1.0f, 1.0f)); |
1235 setShaderOpacity(1, program->fragmentShader().alphaLocation()); | 1262 setShaderOpacity(1, program->fragmentShader().alphaLocation()); |
1236 drawQuadGeometry(frame, drawMatrix, rect, program->vertexShader().matrixLoca
tion()); | 1263 drawQuadGeometry(frame, drawMatrix, rect, program->vertexShader().matrixLoca
tion()); |
1237 } | 1264 } |
1238 | 1265 |
1239 void GLRenderer::finish() | 1266 void GLRenderer::finish() |
1240 { | 1267 { |
1241 TRACE_EVENT0("cc", "GLRenderer::finish"); | 1268 TRACE_EVENT0("cc", "GLRenderer::finish"); |
1242 m_context->finish(); | 1269 m_context->finish(); |
1243 } | 1270 } |
1244 | 1271 |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1748 | 1775 |
1749 releaseRenderPassTextures(); | 1776 releaseRenderPassTextures(); |
1750 } | 1777 } |
1751 | 1778 |
1752 bool GLRenderer::isContextLost() | 1779 bool GLRenderer::isContextLost() |
1753 { | 1780 { |
1754 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); | 1781 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); |
1755 } | 1782 } |
1756 | 1783 |
1757 } // namespace cc | 1784 } // namespace cc |
OLD | NEW |