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

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: Change CHECK() into DCHECK(). 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | cc/gl_renderer_unittest.cc » ('j') | no next file with comments »
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 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 contentsDeviceTransform, contentsDeviceTransformInverse); 531 contentsDeviceTransform, contentsDeviceTransformInverse);
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;
542 unsigned contentsTextureId = 0;
543 if (filterBitmap.getTexture()) {
544 GrTexture* texture = reinterpret_cast<GrTexture*>(filterBitmap.getTextur e());
545 contentsTextureId = texture->getTextureHandle();
546 } else {
547 contentsResourceLock = make_scoped_ptr(new ResourceProvider::ScopedReadL ockGL(m_resourceProvider, contentsTexture->id()));
548 contentsTextureId = contentsResourceLock->textureId();
549 }
550 541
551 // Draw the background texture if there is one. 542 // Draw the background texture if there is one.
552 if (backgroundTexture) { 543 if (backgroundTexture) {
553 DCHECK(backgroundTexture->size() == quad->rect.size()); 544 DCHECK(backgroundTexture->size() == quad->rect.size());
554 ResourceProvider::ScopedReadLockGL lock(m_resourceProvider, backgroundTe xture->id()); 545 ResourceProvider::ScopedReadLockGL lock(m_resourceProvider, backgroundTe xture->id());
555 copyTextureToFramebuffer(frame, lock.textureId(), quad->rect, quad->quad Transform()); 546 copyTextureToFramebuffer(frame, lock.textureId(), quad->rect, quad->quad Transform());
556 } 547 }
557 548
558 bool clipped = false; 549 bool clipped = false;
559 gfx::QuadF deviceQuad = MathUtil::mapQuad(contentsDeviceTransform, sharedGeo metryQuad(), clipped); 550 gfx::QuadF deviceQuad = MathUtil::mapQuad(contentsDeviceTransform, sharedGeo metryQuad(), clipped);
(...skipping 10 matching lines...) Expand all
570 561
571 scoped_ptr<ResourceProvider::ScopedReadLockGL> maskResourceLock; 562 scoped_ptr<ResourceProvider::ScopedReadLockGL> maskResourceLock;
572 unsigned maskTextureId = 0; 563 unsigned maskTextureId = 0;
573 if (quad->mask_resource_id) { 564 if (quad->mask_resource_id) {
574 maskResourceLock.reset(new ResourceProvider::ScopedReadLockGL(m_resource Provider, quad->mask_resource_id)); 565 maskResourceLock.reset(new ResourceProvider::ScopedReadLockGL(m_resource Provider, quad->mask_resource_id));
575 maskTextureId = maskResourceLock->textureId(); 566 maskTextureId = maskResourceLock->textureId();
576 } 567 }
577 568
578 // FIXME: use the backgroundTexture and blend the background in with this dr aw instead of having a separate copy of the background texture. 569 // FIXME: use the backgroundTexture and blend the background in with this dr aw instead of having a separate copy of the background texture.
579 570
580 context()->bindTexture(GL_TEXTURE_2D, contentsTextureId); 571 scoped_ptr<ResourceProvider::ScopedReadLockGL> contentsResourceLock;
572 if (filterBitmap.getTexture()) {
573 GrTexture* texture = reinterpret_cast<GrTexture*>(filterBitmap.getTextur e());
574 context()->bindTexture(GL_TEXTURE_2D, texture->getTextureHandle());
575 } else
576 contentsResourceLock = make_scoped_ptr(new ResourceProvider::ScopedSampl erGL(m_resourceProvider, contentsTexture->id(),
577 GL_TEXTURE_2D, GL_LINEAR));
581 578
582 int shaderQuadLocation = -1; 579 int shaderQuadLocation = -1;
583 int shaderEdgeLocation = -1; 580 int shaderEdgeLocation = -1;
584 int shaderMaskSamplerLocation = -1; 581 int shaderMaskSamplerLocation = -1;
585 int shaderMaskTexCoordScaleLocation = -1; 582 int shaderMaskTexCoordScaleLocation = -1;
586 int shaderMaskTexCoordOffsetLocation = -1; 583 int shaderMaskTexCoordOffsetLocation = -1;
587 int shaderMatrixLocation = -1; 584 int shaderMatrixLocation = -1;
588 int shaderAlphaLocation = -1; 585 int shaderAlphaLocation = -1;
589 if (useAA && maskTextureId) { 586 if (useAA && maskTextureId) {
590 const RenderPassMaskProgramAA* program = renderPassMaskProgramAA(); 587 const RenderPassMaskProgramAA* program = renderPassMaskProgramAA();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 shaderAlphaLocation = program->fragmentShader().alphaLocation(); 623 shaderAlphaLocation = program->fragmentShader().alphaLocation();
627 } 624 }
628 625
629 if (shaderMaskSamplerLocation != -1) { 626 if (shaderMaskSamplerLocation != -1) {
630 DCHECK(shaderMaskTexCoordScaleLocation != 1); 627 DCHECK(shaderMaskTexCoordScaleLocation != 1);
631 DCHECK(shaderMaskTexCoordOffsetLocation != 1); 628 DCHECK(shaderMaskTexCoordOffsetLocation != 1);
632 GLC(context(), context()->activeTexture(GL_TEXTURE1)); 629 GLC(context(), context()->activeTexture(GL_TEXTURE1));
633 GLC(context(), context()->uniform1i(shaderMaskSamplerLocation, 1)); 630 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)); 631 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)); 632 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); 633 m_resourceProvider->bindForSampling(quad->mask_resource_id, GL_TEXTURE_2 D, GL_LINEAR);
637 GLC(context(), context()->activeTexture(GL_TEXTURE0)); 634 GLC(context(), context()->activeTexture(GL_TEXTURE0));
638 } 635 }
639 636
640 if (shaderEdgeLocation != -1) { 637 if (shaderEdgeLocation != -1) {
641 float edge[24]; 638 float edge[24];
642 deviceLayerEdges.toFloatArray(edge); 639 deviceLayerEdges.toFloatArray(edge);
643 deviceLayerBounds.toFloatArray(&edge[12]); 640 deviceLayerBounds.toFloatArray(&edge[12]);
644 GLC(context(), context()->uniform3fv(shaderEdgeLocation, 8, edge)); 641 GLC(context(), context()->uniform3fv(shaderEdgeLocation, 8, edge));
645 } 642 }
646 643
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 } else { 771 } else {
775 if (quad->swizzle_contents) 772 if (quad->swizzle_contents)
776 tileUniformLocation(tileProgramSwizzleOpaque(), uniforms); 773 tileUniformLocation(tileProgramSwizzleOpaque(), uniforms);
777 else 774 else
778 tileUniformLocation(tileProgramOpaque(), uniforms); 775 tileUniformLocation(tileProgramOpaque(), uniforms);
779 } 776 }
780 } 777 }
781 778
782 setUseProgram(uniforms.program); 779 setUseProgram(uniforms.program);
783 GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0)); 780 GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0));
784 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad ->resource_id); 781 bool scaled = (texToGeomScaleX != 1 || texToGeomScaleY != 1);
785 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur eId())); 782 GLenum filter = (quad->IsAntialiased() || scaled || !quad->quadTransform().I sIdentityOrIntegerTranslation()) ? GL_LINEAR : GL_NEAREST;
783 ResourceProvider::ScopedSamplerGL quadResourceLock(m_resourceProvider, quad- >resource_id, GL_TEXTURE_2D, filter);
786 784
787 bool useAA = !clipped && quad->IsAntialiased(); 785 bool useAA = !clipped && quad->IsAntialiased();
788 if (useAA) { 786 if (useAA) {
789 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceLayerQuad.Bound ingBox())); 787 LayerQuad deviceLayerBounds = LayerQuad(gfx::QuadF(deviceLayerQuad.Bound ingBox()));
790 deviceLayerBounds.inflateAntiAliasingDistance(); 788 deviceLayerBounds.inflateAntiAliasingDistance();
791 789
792 LayerQuad deviceLayerEdges = LayerQuad(deviceLayerQuad); 790 LayerQuad deviceLayerEdges = LayerQuad(deviceLayerQuad);
793 deviceLayerEdges.inflateAntiAliasingDistance(); 791 deviceLayerEdges.inflateAntiAliasingDistance();
794 792
795 float edge[24]; 793 float edge[24];
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 877
880 void GLRenderer::drawYUVVideoQuad(const DrawingFrame& frame, const YUVVideoDrawQ uad* quad) 878 void GLRenderer::drawYUVVideoQuad(const DrawingFrame& frame, const YUVVideoDrawQ uad* quad)
881 { 879 {
882 const VideoYUVProgram* program = videoYUVProgram(); 880 const VideoYUVProgram* program = videoYUVProgram();
883 DCHECK(program && (program->initialized() || isContextLost())); 881 DCHECK(program && (program->initialized() || isContextLost()));
884 882
885 const VideoLayerImpl::FramePlane& yPlane = quad->y_plane; 883 const VideoLayerImpl::FramePlane& yPlane = quad->y_plane;
886 const VideoLayerImpl::FramePlane& uPlane = quad->u_plane; 884 const VideoLayerImpl::FramePlane& uPlane = quad->u_plane;
887 const VideoLayerImpl::FramePlane& vPlane = quad->v_plane; 885 const VideoLayerImpl::FramePlane& vPlane = quad->v_plane;
888 886
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)); 887 GLC(context(), context()->activeTexture(GL_TEXTURE1));
893 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, yPlaneLock.textureId()) ); 888 ResourceProvider::ScopedSamplerGL yPlaneLock(m_resourceProvider, yPlane.reso urceId, GL_TEXTURE_2D, GL_LINEAR);
894 GLC(context(), context()->activeTexture(GL_TEXTURE2)); 889 GLC(context(), context()->activeTexture(GL_TEXTURE2));
895 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, uPlaneLock.textureId()) ); 890 ResourceProvider::ScopedSamplerGL uPlaneLock(m_resourceProvider, uPlane.reso urceId, GL_TEXTURE_2D, GL_LINEAR);
896 GLC(context(), context()->activeTexture(GL_TEXTURE3)); 891 GLC(context(), context()->activeTexture(GL_TEXTURE3));
897 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, vPlaneLock.textureId()) ); 892 ResourceProvider::ScopedSamplerGL vPlaneLock(m_resourceProvider, vPlane.reso urceId, GL_TEXTURE_2D, GL_LINEAR);
898 893
899 setUseProgram(program->program()); 894 setUseProgram(program->program());
900 895
901 GLC(context(), context()->uniform2f(program->vertexShader().texScaleLocation (), quad->tex_scale.width(), quad->tex_scale.height())); 896 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)); 897 GLC(context(), context()->uniform1i(program->fragmentShader().yTextureLocati on(), 1));
903 GLC(context(), context()->uniform1i(program->fragmentShader().uTextureLocati on(), 2)); 898 GLC(context(), context()->uniform1i(program->fragmentShader().uTextureLocati on(), 2));
904 GLC(context(), context()->uniform1i(program->fragmentShader().vTextureLocati on(), 3)); 899 GLC(context(), context()->uniform1i(program->fragmentShader().vTextureLocati on(), 3));
905 900
906 // These values are magic numbers that are used in the transformation from Y UV to RGB color values. 901 // 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 902 // They are taken from the following webpage: http://www.fourcc.org/fccyvrgb .php
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 TexTransformTextureProgramBinding binding; 1074 TexTransformTextureProgramBinding binding;
1080 if (quad->flipped) 1075 if (quad->flipped)
1081 binding.set(textureProgramFlip(), context()); 1076 binding.set(textureProgramFlip(), context());
1082 else 1077 else
1083 binding.set(textureProgram(), context()); 1078 binding.set(textureProgram(), context());
1084 setUseProgram(binding.programId); 1079 setUseProgram(binding.programId);
1085 GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); 1080 GLC(context(), context()->uniform1i(binding.samplerLocation, 0));
1086 const gfx::RectF& uvRect = quad->uv_rect; 1081 const gfx::RectF& uvRect = quad->uv_rect;
1087 GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x() , uvRect.y(), uvRect.width(), uvRect.height())); 1082 GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x() , uvRect.y(), uvRect.width(), uvRect.height()));
1088 1083
1089 ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad ->resource_id); 1084 ResourceProvider::ScopedSamplerGL quadResourceLock(m_resourceProvider, quad- >resource_id, GL_TEXTURE_2D, GL_LINEAR);
1090 GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textur eId()));
1091 1085
1092 if (!quad->premultiplied_alpha) { 1086 if (!quad->premultiplied_alpha) {
1093 // As it turns out, the premultiplied alpha blending function (ONE, ONE_ MINUS_SRC_ALPHA) 1087 // As it turns out, the premultiplied alpha blending function (ONE, ONE_ MINUS_SRC_ALPHA)
1094 // will never cause the alpha channel to be set to anything less than 1. 0 if it is 1088 // will never cause the alpha channel to be set to anything less than 1. 0 if it is
1095 // initialized to that value! Therefore, premultipliedAlpha being false is the first 1089 // initialized to that value! Therefore, premultipliedAlpha being false is the first
1096 // situation we can generally see an alpha channel less than 1.0 coming out of the 1090 // situation we can generally see an alpha channel less than 1.0 coming out of the
1097 // compositor. This is causing platform differences in some layout tests (see 1091 // compositor. This is causing platform differences in some layout tests (see
1098 // https://bugs.webkit.org/show_bug.cgi?id=82412), so in this situation, use a separate 1092 // https://bugs.webkit.org/show_bug.cgi?id=82412), so in this situation, use a separate
1099 // blend function for the alpha channel to avoid modifying it. Don't use colorMask for this 1093 // blend function for the alpha channel to avoid modifying it. Don't use colorMask for this
1100 // as it has performance implications on some platforms. 1094 // as it has performance implications on some platforms.
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
1753 1747
1754 releaseRenderPassTextures(); 1748 releaseRenderPassTextures();
1755 } 1749 }
1756 1750
1757 bool GLRenderer::isContextLost() 1751 bool GLRenderer::isContextLost()
1758 { 1752 {
1759 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR); 1753 return (m_context->getGraphicsResetStatusARB() != GL_NO_ERROR);
1760 } 1754 }
1761 1755
1762 } // namespace cc 1756 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/gl_renderer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698