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

Side by Side Diff: cc/gl_renderer.cc

Issue 11358181: Use nearest neighbor filtering for non-translated quads (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Associate resources with min/mag filters and use NEAREST for tile quads when feasible. Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | cc/gl_renderer_unittest.cc » ('j') | cc/resource_provider.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 532
533 // FIXME: Cache this value so that we don't have to do it for both the surfa ce and its replica. 533 // FIXME: Cache this value so that we don't have to do it for both the surfa ce and its replica.
534 // Apply filters to the contents texture. 534 // Apply filters to the contents texture.
535 SkBitmap filterBitmap; 535 SkBitmap filterBitmap;
536 if (renderPass->filter) { 536 if (renderPass->filter) {
537 filterBitmap = applyImageFilter(this, renderPass->filter, contentsTextur e, m_client->hasImplThread()); 537 filterBitmap = applyImageFilter(this, renderPass->filter, contentsTextur e, m_client->hasImplThread());
538 } else { 538 } else {
539 filterBitmap = applyFilters(this, renderPass->filters, contentsTexture, m_client->hasImplThread()); 539 filterBitmap = applyFilters(this, renderPass->filters, contentsTexture, m_client->hasImplThread());
540 } 540 }
541 scoped_ptr<ResourceProvider::ScopedReadLockGL> contentsResourceLock; 541 scoped_ptr<ResourceProvider::ScopedReadLockGL> contentsResourceLock;
542 unsigned contentsTextureId = 0;
543 if (filterBitmap.getTexture()) { 542 if (filterBitmap.getTexture()) {
544 GrTexture* texture = reinterpret_cast<GrTexture*>(filterBitmap.getTextur e()); 543 GrTexture* texture = reinterpret_cast<GrTexture*>(filterBitmap.getTextur e());
545 contentsTextureId = texture->getTextureHandle(); 544 context()->bindTexture(GL_TEXTURE_2D, texture->getTextureHandle());
jamesr 2012/11/26 06:54:26 you're moving a bind call up here but look at line
546 } else { 545 } else
547 contentsResourceLock = make_scoped_ptr(new ResourceProvider::ScopedReadL ockGL(m_resourceProvider, contentsTexture->id())); 546 contentsResourceLock = make_scoped_ptr(new ResourceProvider::ScopedSampl erGL(m_resourceProvider, contentsTexture->id(), GL_TEXTURE_2D));
548 contentsTextureId = contentsResourceLock->textureId();
549 }
550 547
551 // Draw the background texture if there is one. 548 // Draw the background texture if there is one.
552 if (backgroundTexture) { 549 if (backgroundTexture) {
553 DCHECK(backgroundTexture->size() == quad->rect.size()); 550 DCHECK(backgroundTexture->size() == quad->rect.size());
554 ResourceProvider::ScopedReadLockGL lock(m_resourceProvider, backgroundTe xture->id()); 551 ResourceProvider::ScopedReadLockGL lock(m_resourceProvider, backgroundTe xture->id());
555 copyTextureToFramebuffer(frame, lock.textureId(), quad->rect, quad->quad Transform()); 552 copyTextureToFramebuffer(frame, lock.textureId(), quad->rect, quad->quad Transform());
jamesr 2012/11/26 06:54:26 but doesn't this also change the binding?
Sami 2012/11/30 17:49:27 Good catch. Gotta love shared context state. I'll
556 } 553 }
557 554
558 bool clipped = false; 555 bool clipped = false;
559 gfx::QuadF deviceQuad = MathUtil::mapQuad(contentsDeviceTransform, sharedGeo metryQuad(), clipped); 556 gfx::QuadF deviceQuad = MathUtil::mapQuad(contentsDeviceTransform, sharedGeo metryQuad(), clipped);
560 DCHECK(!clipped); 557 DCHECK(!clipped);
561 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceQuad.BoundingBox()) ); 558 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceQuad.BoundingBox()) );
562 LayerQuad deviceLayerEdges = LayerQuad(deviceQuad); 559 LayerQuad deviceLayerEdges = LayerQuad(deviceQuad);
563 560
564 // Use anti-aliasing programs only when necessary. 561 // Use anti-aliasing programs only when necessary.
565 bool useAA = (!deviceQuad.IsRectilinear() || !deviceQuad.BoundingBox().IsExp ressibleAsRect()); 562 bool useAA = (!deviceQuad.IsRectilinear() || !deviceQuad.BoundingBox().IsExp ressibleAsRect());
566 if (useAA) { 563 if (useAA) {
567 deviceLayerBounds.inflateAntiAliasingDistance(); 564 deviceLayerBounds.inflateAntiAliasingDistance();
568 deviceLayerEdges.inflateAntiAliasingDistance(); 565 deviceLayerEdges.inflateAntiAliasingDistance();
569 } 566 }
570 567
571 scoped_ptr<ResourceProvider::ScopedReadLockGL> maskResourceLock; 568 scoped_ptr<ResourceProvider::ScopedReadLockGL> maskResourceLock;
572 unsigned maskTextureId = 0; 569 unsigned maskTextureId = 0;
573 if (quad->mask_resource_id) { 570 if (quad->mask_resource_id) {
574 maskResourceLock.reset(new ResourceProvider::ScopedReadLockGL(m_resource Provider, quad->mask_resource_id)); 571 maskResourceLock.reset(new ResourceProvider::ScopedReadLockGL(m_resource Provider, quad->mask_resource_id));
575 maskTextureId = maskResourceLock->textureId(); 572 maskTextureId = maskResourceLock->textureId();
576 } 573 }
577 574
578 // FIXME: use the backgroundTexture and blend the background in with this dr aw instead of having a separate copy of the background texture. 575 // FIXME: use the backgroundTexture and blend the background in with this dr aw instead of having a separate copy of the background texture.
579 576
580 context()->bindTexture(GL_TEXTURE_2D, contentsTextureId);
581
582 int shaderQuadLocation = -1; 577 int shaderQuadLocation = -1;
583 int shaderEdgeLocation = -1; 578 int shaderEdgeLocation = -1;
584 int shaderMaskSamplerLocation = -1; 579 int shaderMaskSamplerLocation = -1;
585 int shaderMaskTexCoordScaleLocation = -1; 580 int shaderMaskTexCoordScaleLocation = -1;
586 int shaderMaskTexCoordOffsetLocation = -1; 581 int shaderMaskTexCoordOffsetLocation = -1;
587 int shaderMatrixLocation = -1; 582 int shaderMatrixLocation = -1;
588 int shaderAlphaLocation = -1; 583 int shaderAlphaLocation = -1;
589 if (useAA && maskTextureId) { 584 if (useAA && maskTextureId) {
590 const RenderPassMaskProgramAA* program = renderPassMaskProgramAA(); 585 const RenderPassMaskProgramAA* program = renderPassMaskProgramAA();
591 GLC(context(), context()->useProgram(program->program())); 586 GLC(context(), context()->useProgram(program->program()));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 shaderAlphaLocation = program->fragmentShader().alphaLocation(); 621 shaderAlphaLocation = program->fragmentShader().alphaLocation();
627 } 622 }
628 623
629 if (shaderMaskSamplerLocation != -1) { 624 if (shaderMaskSamplerLocation != -1) {
630 DCHECK(shaderMaskTexCoordScaleLocation != 1); 625 DCHECK(shaderMaskTexCoordScaleLocation != 1);
631 DCHECK(shaderMaskTexCoordOffsetLocation != 1); 626 DCHECK(shaderMaskTexCoordOffsetLocation != 1);
632 GLC(context(), context()->activeTexture(GL_TEXTURE1)); 627 GLC(context(), context()->activeTexture(GL_TEXTURE1));
633 GLC(context(), context()->uniform1i(shaderMaskSamplerLocation, 1)); 628 GLC(context(), context()->uniform1i(shaderMaskSamplerLocation, 1));
634 GLC(context(), context()->uniform2f(shaderMaskTexCoordScaleLocation, qua d->mask_tex_coord_scale_x, quad->mask_tex_coord_scale_y)); 629 GLC(context(), context()->uniform2f(shaderMaskTexCoordScaleLocation, qua d->mask_tex_coord_scale_x, quad->mask_tex_coord_scale_y));
635 GLC(context(), context()->uniform2f(shaderMaskTexCoordOffsetLocation, qu ad->mask_tex_coord_offset_x, quad->mask_tex_coord_offset_y)); 630 GLC(context(), context()->uniform2f(shaderMaskTexCoordOffsetLocation, qu ad->mask_tex_coord_offset_x, quad->mask_tex_coord_offset_y));
636 context()->bindTexture(GL_TEXTURE_2D, maskTextureId); 631 m_resourceProvider->bindForSampling(quad->mask_resource_id, GL_TEXTURE_2 D);
637 GLC(context(), context()->activeTexture(GL_TEXTURE0)); 632 GLC(context(), context()->activeTexture(GL_TEXTURE0));
638 } 633 }
639 634
640 if (shaderEdgeLocation != -1) { 635 if (shaderEdgeLocation != -1) {
641 float edge[24]; 636 float edge[24];
642 deviceLayerEdges.toFloatArray(edge); 637 deviceLayerEdges.toFloatArray(edge);
643 deviceLayerBounds.toFloatArray(&edge[12]); 638 deviceLayerBounds.toFloatArray(&edge[12]);
644 GLC(context(), context()->uniform3fv(shaderEdgeLocation, 8, edge)); 639 GLC(context(), context()->uniform3fv(shaderEdgeLocation, 8, edge));
645 } 640 }
646 641
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 } else { 769 } else {
775 if (quad->swizzle_contents) 770 if (quad->swizzle_contents)
776 tileUniformLocation(tileProgramSwizzleOpaque(), uniforms); 771 tileUniformLocation(tileProgramSwizzleOpaque(), uniforms);
777 else 772 else
778 tileUniformLocation(tileProgramOpaque(), uniforms); 773 tileUniformLocation(tileProgramOpaque(), uniforms);
779 } 774 }
780 } 775 }
781 776
782 GLC(context(), context()->useProgram(uniforms.program)); 777 GLC(context(), context()->useProgram(uniforms.program));
783 GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0)); 778 GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0));
784 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad ->resource_id); 779 GLenum filter = (quad->IsAntialiased() || texToGeomScaleX != 1 || texToGeomS caleY != 1 || !quad->quadTransform().isIntegerTranslation()) ? GL_LINEAR : GL_NE AREST;
jamesr 2012/11/26 06:54:26 this line is crazy long - can you break it up a bi
Sami 2012/11/30 17:49:27 Agreed, this is long even for WebKit standards. I'
785 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur eId())); 780 ResourceProvider::ScopedSamplerGL quadResourceLock(m_resourceProvider, quad- >resource_id, GL_TEXTURE_2D, filter, filter);
786 781
787 bool useAA = !clipped && quad->IsAntialiased(); 782 bool useAA = !clipped && quad->IsAntialiased();
788 if (useAA) { 783 if (useAA) {
789 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceLayerQuad.Bound ingBox())); 784 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceLayerQuad.Bound ingBox()));
790 deviceLayerBounds.inflateAntiAliasingDistance(); 785 deviceLayerBounds.inflateAntiAliasingDistance();
791 786
792 LayerQuad deviceLayerEdges = LayerQuad(deviceLayerQuad); 787 LayerQuad deviceLayerEdges = LayerQuad(deviceLayerQuad);
793 deviceLayerEdges.inflateAntiAliasingDistance(); 788 deviceLayerEdges.inflateAntiAliasingDistance();
794 789
795 float edge[24]; 790 float edge[24];
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 874
880 void GLRenderer::drawYUVVideoQuad(const DrawingFrame& frame, const YUVVideoDrawQ uad* quad) 875 void GLRenderer::drawYUVVideoQuad(const DrawingFrame& frame, const YUVVideoDrawQ uad* quad)
881 { 876 {
882 const VideoYUVProgram* program = videoYUVProgram(); 877 const VideoYUVProgram* program = videoYUVProgram();
883 DCHECK(program && (program->initialized() || isContextLost())); 878 DCHECK(program && (program->initialized() || isContextLost()));
884 879
885 const VideoLayerImpl::FramePlane& yPlane = quad->y_plane; 880 const VideoLayerImpl::FramePlane& yPlane = quad->y_plane;
886 const VideoLayerImpl::FramePlane& uPlane = quad->u_plane; 881 const VideoLayerImpl::FramePlane& uPlane = quad->u_plane;
887 const VideoLayerImpl::FramePlane& vPlane = quad->v_plane; 882 const VideoLayerImpl::FramePlane& vPlane = quad->v_plane;
888 883
889 ResourceProvider::ScopedReadLockGL yPlaneLock(m_resourceProvider, yPlane.res ourceId);
890 ResourceProvider::ScopedReadLockGL uPlaneLock(m_resourceProvider, uPlane.res ourceId);
891 ResourceProvider::ScopedReadLockGL vPlaneLock(m_resourceProvider, vPlane.res ourceId);
892 GLC(context(), context()->activeTexture(GL_TEXTURE1)); 884 GLC(context(), context()->activeTexture(GL_TEXTURE1));
893 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, yPlaneLock.textureId()) ); 885 ResourceProvider::ScopedSamplerGL yPlaneLock(m_resourceProvider, yPlane.reso urceId, GL_TEXTURE_2D);
894 GLC(context(), context()->activeTexture(GL_TEXTURE2)); 886 GLC(context(), context()->activeTexture(GL_TEXTURE2));
895 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, uPlaneLock.textureId()) ); 887 ResourceProvider::ScopedSamplerGL uPlaneLock(m_resourceProvider, uPlane.reso urceId, GL_TEXTURE_2D);
896 GLC(context(), context()->activeTexture(GL_TEXTURE3)); 888 GLC(context(), context()->activeTexture(GL_TEXTURE3));
897 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, vPlaneLock.textureId()) ); 889 ResourceProvider::ScopedSamplerGL vPlaneLock(m_resourceProvider, vPlane.reso urceId, GL_TEXTURE_2D);
898 890
899 GLC(context(), context()->useProgram(program->program())); 891 GLC(context(), context()->useProgram(program->program()));
900 892
901 GLC(context(), context()->uniform2f(program->vertexShader().texScaleLocation (), quad->tex_scale.width(), quad->tex_scale.height())); 893 GLC(context(), context()->uniform2f(program->vertexShader().texScaleLocation (), quad->tex_scale.width(), quad->tex_scale.height()));
902 GLC(context(), context()->uniform1i(program->fragmentShader().yTextureLocati on(), 1)); 894 GLC(context(), context()->uniform1i(program->fragmentShader().yTextureLocati on(), 1));
903 GLC(context(), context()->uniform1i(program->fragmentShader().uTextureLocati on(), 2)); 895 GLC(context(), context()->uniform1i(program->fragmentShader().uTextureLocati on(), 2));
904 GLC(context(), context()->uniform1i(program->fragmentShader().vTextureLocati on(), 3)); 896 GLC(context(), context()->uniform1i(program->fragmentShader().vTextureLocati on(), 3));
905 897
906 // These values are magic numbers that are used in the transformation from Y UV to RGB color values. 898 // These values are magic numbers that are used in the transformation from Y UV to RGB color values.
907 // They are taken from the following webpage: http://www.fourcc.org/fccyvrgb .php 899 // They are taken from the following webpage: http://www.fourcc.org/fccyvrgb .php
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 TexTransformTextureProgramBinding binding; 975 TexTransformTextureProgramBinding binding;
984 if (quad->flipped) 976 if (quad->flipped)
985 binding.set(textureProgramFlip(), context()); 977 binding.set(textureProgramFlip(), context());
986 else 978 else
987 binding.set(textureProgram(), context()); 979 binding.set(textureProgram(), context());
988 GLC(context(), context()->useProgram(binding.programId)); 980 GLC(context(), context()->useProgram(binding.programId));
989 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); 981 GLC(context(), context()->uniform1i(binding.samplerLocation, 0));
990 const gfx::RectF& uvRect = quad->uv_rect; 982 const gfx::RectF& uvRect = quad->uv_rect;
991 GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x() , uvRect.y(), uvRect.width(), uvRect.height())); 983 GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x() , uvRect.y(), uvRect.width(), uvRect.height()));
992 984
993 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad ->resource_id); 985 ResourceProvider::ScopedSamplerGL quadResourceLock(m_resourceProvider, quad- >resource_id, GL_TEXTURE_2D);
994 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur eId()));
995 986
996 if (!quad->premultiplied_alpha) { 987 if (!quad->premultiplied_alpha) {
997 // As it turns out, the premultiplied alpha blending function (ONE, ONE_ MINUS_SRC_ALPHA) 988 // As it turns out, the premultiplied alpha blending function (ONE, ONE_ MINUS_SRC_ALPHA)
998 // will never cause the alpha channel to be set to anything less than 1. 0 if it is 989 // will never cause the alpha channel to be set to anything less than 1. 0 if it is
999 // initialized to that value! Therefore, premultipliedAlpha being false is the first 990 // initialized to that value! Therefore, premultipliedAlpha being false is the first
1000 // situation we can generally see an alpha channel less than 1.0 coming out of the 991 // situation we can generally see an alpha channel less than 1.0 coming out of the
1001 // compositor. This is causing platform differences in some layout tests (see 992 // compositor. This is causing platform differences in some layout tests (see
1002 // https://bugs.webkit.org/show_bug.cgi?id=82412), so in this situation, use a separate 993 // https://bugs.webkit.org/show_bug.cgi?id=82412), so in this situation, use a separate
1003 // blend function for the alpha channel to avoid modifying it. Don't use colorMask for this 994 // blend function for the alpha channel to avoid modifying it. Don't use colorMask for this
1004 // as it has performance implications on some platforms. 995 // as it has performance implications on some platforms.
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 1632
1642 releaseRenderPassTextures(); 1633 releaseRenderPassTextures();
1643 } 1634 }
1644 1635
1645 bool GLRenderer::isContextLost() 1636 bool GLRenderer::isContextLost()
1646 { 1637 {
1647 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); 1638 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR);
1648 } 1639 }
1649 1640
1650 } // namespace cc 1641 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/gl_renderer_unittest.cc » ('j') | cc/resource_provider.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698