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

Side by Side Diff: cc/gl_renderer.cc

Issue 11420079: Allow using a larger-than-necessary texture as cached render pass backing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: seems to work Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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());
enne (OOO) 2012/12/12 23:41:54 Can you assert here that scale_foo is <= 1?
jamesr 2012/12/13 01:15:06 Sure
635
636 if (shaderTexTransformLocation != -1) {
637 GLC(context(), context()->uniform4f(shaderTexTransformLocation,
638 0.0f, 0.0f,
639 tex_scale_x, tex_scale_y));
640 } else if (shaderTexScaleLocation != -1) {
641 GLC(context(), context()->uniform2f(shaderTexScaleLocation,
642 tex_scale_x, tex_scale_y));
643 } else {
644 NOTREACHED();
624 } 645 }
625 646
626 if (shaderMaskSamplerLocation != -1) { 647 if (shaderMaskSamplerLocation != -1) {
627 DCHECK(shaderMaskTexCoordScaleLocation != 1); 648 DCHECK(shaderMaskTexCoordScaleLocation != 1);
628 DCHECK(shaderMaskTexCoordOffsetLocation != 1); 649 DCHECK(shaderMaskTexCoordOffsetLocation != 1);
629 GLC(context(), context()->activeTexture(GL_TEXTURE1)); 650 GLC(context(), context()->activeTexture(GL_TEXTURE1));
630 GLC(context(), context()->uniform1i(shaderMaskSamplerLocation, 1)); 651 GLC(context(), context()->uniform1i(shaderMaskSamplerLocation, 1));
631 GLC(context(), context()->uniform2f(shaderMaskTexCoordScaleLocation, qua d->mask_tex_coord_scale_x, quad->mask_tex_coord_scale_y)); 652 GLC(context(), context()->uniform2f(shaderMaskTexCoordOffsetLocation,
632 GLC(context(), context()->uniform2f(shaderMaskTexCoordOffsetLocation, qu ad->mask_tex_coord_offset_x, quad->mask_tex_coord_offset_y)); 653 quad->mask_uv_rect.x(), quad->mask_u v_rect.y()));
654 GLC(context(), context()->uniform2f(shaderMaskTexCoordScaleLocation,
655 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); 656 m_resourceProvider->bindForSampling(quad->mask_resource_id, GL_TEXTURE_2 D, GL_LINEAR);
634 GLC(context(), context()->activeTexture(GL_TEXTURE0)); 657 GLC(context(), context()->activeTexture(GL_TEXTURE0));
635 } 658 }
636 659
637 if (shaderEdgeLocation != -1) { 660 if (shaderEdgeLocation != -1) {
638 float edge[24]; 661 float edge[24];
639 deviceLayerEdges.toFloatArray(edge); 662 deviceLayerEdges.toFloatArray(edge);
640 deviceLayerBounds.toFloatArray(&edge[12]); 663 deviceLayerBounds.toFloatArray(&edge[12]);
641 GLC(context(), context()->uniform3fv(shaderEdgeLocation, 8, edge)); 664 GLC(context(), context()->uniform3fv(shaderEdgeLocation, 8, edge));
642 } 665 }
643 666
667
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. 668 // 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); 669 gfx::QuadF surfaceQuad = MathUtil::mapQuad(contentsDeviceTransformInverse, d eviceLayerEdges.ToQuadF(), clipped);
646 DCHECK(!clipped); 670 DCHECK(!clipped);
647 671
648 setShaderOpacity(quad->opacity(), shaderAlphaLocation); 672 setShaderOpacity(quad->opacity(), shaderAlphaLocation);
649 setShaderQuadF(surfaceQuad, shaderQuadLocation); 673 setShaderQuadF(surfaceQuad, shaderQuadLocation);
650 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, shaderMatrixLocat ion); 674 drawQuadGeometry(frame, quad->quadTransform(), quad->rect, shaderMatrixLocat ion);
651 675
652 // Flush the compositor context before the filter bitmap goes out of 676 // Flush the compositor context before the filter bitmap goes out of
653 // scope, so the draw gets processed before the filter texture gets deleted. 677 // scope, so the draw gets processed before the filter texture gets deleted.
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 } 1245 }
1222 1246
1223 void GLRenderer::copyTextureToFramebuffer(const DrawingFrame& frame, int texture Id, const gfx::Rect& rect, const gfx::Transform& drawMatrix) 1247 void GLRenderer::copyTextureToFramebuffer(const DrawingFrame& frame, int texture Id, const gfx::Rect& rect, const gfx::Transform& drawMatrix)
1224 { 1248 {
1225 const RenderPassProgram* program = renderPassProgram(); 1249 const RenderPassProgram* program = renderPassProgram();
1226 1250
1227 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, textureId)); 1251 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, textureId));
1228 1252
1229 setUseProgram(program->program()); 1253 setUseProgram(program->program());
1230 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio n(), 0)); 1254 GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocatio n(), 0));
1255 GLC(context(), context()->uniform4f(program->vertexShader().texTransformLoca tion(),
enne (OOO) 2012/12/12 23:41:54 It's kind of scary that this wasn't set before.
jamesr 2012/12/13 01:15:06 Not as scary as it seems - I'm adding this vertex
1256 0.0f, 0.0f, 1.0f, 1.0f));
1231 setShaderOpacity(1, program->fragmentShader().alphaLocation()); 1257 setShaderOpacity(1, program->fragmentShader().alphaLocation());
1232 drawQuadGeometry(frame, drawMatrix, rect, program->vertexShader().matrixLoca tion()); 1258 drawQuadGeometry(frame, drawMatrix, rect, program->vertexShader().matrixLoca tion());
1233 } 1259 }
1234 1260
1235 void GLRenderer::finish() 1261 void GLRenderer::finish()
1236 { 1262 {
1237 TRACE_EVENT0("cc", "GLRenderer::finish"); 1263 TRACE_EVENT0("cc", "GLRenderer::finish");
1238 m_context->finish(); 1264 m_context->finish();
1239 } 1265 }
1240 1266
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 1772
1747 releaseRenderPassTextures(); 1773 releaseRenderPassTextures();
1748 } 1774 }
1749 1775
1750 bool GLRenderer::isContextLost() 1776 bool GLRenderer::isContextLost()
1751 { 1777 {
1752 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); 1778 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR);
1753 } 1779 }
1754 1780
1755 } // namespace cc 1781 } // namespace cc
OLDNEW
« no previous file with comments | « cc/gl_renderer.h ('k') | cc/gl_renderer_pixeltest.cc » ('j') | cc/gl_renderer_pixeltest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698