Chromium Code Reviews| 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 } |
| 643 | 668 |
| 669 | |
|
danakj
2012/12/13 20:39:50
extra \n
| |
| 644 // 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. | 670 // 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. |
| 645 gfx::QuadF surfaceQuad = MathUtil::mapQuad(contentsDeviceTransformInverse, d eviceLayerEdges.ToQuadF(), clipped); | 671 gfx::QuadF surfaceQuad = MathUtil::mapQuad(contentsDeviceTransformInverse, d eviceLayerEdges.ToQuadF(), clipped); |
| 646 DCHECK(!clipped); | 672 DCHECK(!clipped); |
| 647 | 673 |
| 648 setShaderOpacity(quad->opacity(), shaderAlphaLocation); | 674 setShaderOpacity(quad->opacity(), shaderAlphaLocation); |
| 649 setShaderQuadF(surfaceQuad, shaderQuadLocation); | 675 setShaderQuadF(surfaceQuad, shaderQuadLocation); |
| 650 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, shaderMatrixLocat ion); | 676 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, shaderMatrixLocat ion); |
| 651 | 677 |
| 652 // Flush the compositor context before the filter bitmap goes out of | 678 // Flush the compositor context before the filter bitmap goes out of |
| 653 // scope, so the draw gets processed before the filter texture gets deleted. | 679 // scope, so the draw gets processed before the filter texture gets deleted. |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1221 } | 1247 } |
| 1222 | 1248 |
| 1223 void GLRenderer::copyTextureToFramebuffer(const DrawingFrame& frame, int texture Id, const gfx::Rect& rect, const gfx::Transform& drawMatrix) | 1249 void GLRenderer::copyTextureToFramebuffer(const DrawingFrame& frame, int texture Id, const gfx::Rect& rect, const gfx::Transform& drawMatrix) |
| 1224 { | 1250 { |
| 1225 const RenderPassProgram* program = renderPassProgram(); | 1251 const RenderPassProgram* program = renderPassProgram(); |
| 1226 | 1252 |
| 1227 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, textureId)); | 1253 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, textureId)); |
| 1228 | 1254 |
| 1229 setUseProgram(program->program()); | 1255 setUseProgram(program->program()); |
| 1230 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio n(), 0)); | 1256 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio n(), 0)); |
| 1257 GLC(context(), context()->uniform4f(program->vertexShader().texTransformLoca tion(), | |
| 1258 0.0f, 0.0f, 1.0f, 1.0f)); | |
| 1231 setShaderOpacity(1, program->fragmentShader().alphaLocation()); | 1259 setShaderOpacity(1, program->fragmentShader().alphaLocation()); |
| 1232 drawQuadGeometry(frame, drawMatrix, rect, program->vertexShader().matrixLoca tion()); | 1260 drawQuadGeometry(frame, drawMatrix, rect, program->vertexShader().matrixLoca tion()); |
| 1233 } | 1261 } |
| 1234 | 1262 |
| 1235 void GLRenderer::finish() | 1263 void GLRenderer::finish() |
| 1236 { | 1264 { |
| 1237 TRACE_EVENT0("cc", "GLRenderer::finish"); | 1265 TRACE_EVENT0("cc", "GLRenderer::finish"); |
| 1238 m_context->finish(); | 1266 m_context->finish(); |
| 1239 } | 1267 } |
| 1240 | 1268 |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1746 | 1774 |
| 1747 releaseRenderPassTextures(); | 1775 releaseRenderPassTextures(); |
| 1748 } | 1776 } |
| 1749 | 1777 |
| 1750 bool GLRenderer::isContextLost() | 1778 bool GLRenderer::isContextLost() |
| 1751 { | 1779 { |
| 1752 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); | 1780 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); |
| 1753 } | 1781 } |
| 1754 | 1782 |
| 1755 } // namespace cc | 1783 } // namespace cc |
| OLD | NEW |