| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 #include "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
| 10 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 | 419 |
| 420 int maxSize = this->caps()->maxTextureSize(); | 420 int maxSize = this->caps()->maxTextureSize(); |
| 421 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { | 421 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { |
| 422 return nullptr; | 422 return nullptr; |
| 423 } | 423 } |
| 424 | 424 |
| 425 GrGLTexture::IDDesc idDesc; | 425 GrGLTexture::IDDesc idDesc; |
| 426 GrSurfaceDesc surfDesc; | 426 GrSurfaceDesc surfDesc; |
| 427 | 427 |
| 428 idDesc.fTextureID = static_cast<GrGLuint>(desc.fTextureHandle); | 428 idDesc.fTextureID = static_cast<GrGLuint>(desc.fTextureHandle); |
| 429 | 429 // We only support GL_TEXTURE_2D at the moment. |
| 430 idDesc.fTarget = GR_GL_TEXTURE_2D; |
| 431 |
| 430 switch (ownership) { | 432 switch (ownership) { |
| 431 case kAdopt_GrWrapOwnership: | 433 case kAdopt_GrWrapOwnership: |
| 432 idDesc.fLifeCycle = GrGpuResource::kAdopted_LifeCycle; | 434 idDesc.fLifeCycle = GrGpuResource::kAdopted_LifeCycle; |
| 433 break; | 435 break; |
| 434 case kBorrow_GrWrapOwnership: | 436 case kBorrow_GrWrapOwnership: |
| 435 idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle; | 437 idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle; |
| 436 break; | 438 break; |
| 437 } | 439 } |
| 438 | 440 |
| 439 // next line relies on GrBackendTextureDesc's flags matching GrTexture's | 441 // next line relies on GrBackendTextureDesc's flags matching GrTexture's |
| (...skipping 10 matching lines...) Expand all Loading... |
| 450 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { | 452 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { |
| 451 surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 453 surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 452 } else { | 454 } else { |
| 453 surfDesc.fOrigin = desc.fOrigin; | 455 surfDesc.fOrigin = desc.fOrigin; |
| 454 } | 456 } |
| 455 | 457 |
| 456 GrGLTexture* texture = nullptr; | 458 GrGLTexture* texture = nullptr; |
| 457 if (renderTarget) { | 459 if (renderTarget) { |
| 458 GrGLRenderTarget::IDDesc rtIDDesc; | 460 GrGLRenderTarget::IDDesc rtIDDesc; |
| 459 if (!this->createRenderTargetObjects(surfDesc, GrGpuResource::kUncached_
LifeCycle, | 461 if (!this->createRenderTargetObjects(surfDesc, GrGpuResource::kUncached_
LifeCycle, |
| 460 idDesc.fTextureID, &rtIDDesc)) { | 462 idDesc.fTextureID, idDesc.fTarget,
&rtIDDesc)) { |
| 461 return nullptr; | 463 return nullptr; |
| 462 } | 464 } |
| 463 texture = new GrGLTextureRenderTarget(this, surfDesc, idDesc, rtIDDesc); | 465 texture = new GrGLTextureRenderTarget(this, surfDesc, idDesc, rtIDDesc); |
| 464 } else { | 466 } else { |
| 465 texture = new GrGLTexture(this, surfDesc, idDesc); | 467 texture = new GrGLTexture(this, surfDesc, idDesc); |
| 466 } | 468 } |
| 467 if (nullptr == texture) { | 469 if (nullptr == texture) { |
| 468 return nullptr; | 470 return nullptr; |
| 469 } | 471 } |
| 470 | 472 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 if (!glTex) { | 568 if (!glTex) { |
| 567 return false; | 569 return false; |
| 568 } | 570 } |
| 569 | 571 |
| 570 // OpenGL doesn't do sRGB <-> linear conversions when reading and writing pi
xels. | 572 // OpenGL doesn't do sRGB <-> linear conversions when reading and writing pi
xels. |
| 571 if (GrPixelConfigIsSRGB(surface->config()) != GrPixelConfigIsSRGB(config)) { | 573 if (GrPixelConfigIsSRGB(surface->config()) != GrPixelConfigIsSRGB(config)) { |
| 572 return false; | 574 return false; |
| 573 } | 575 } |
| 574 | 576 |
| 575 this->setScratchTextureUnit(); | 577 this->setScratchTextureUnit(); |
| 576 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTex->textureID())); | 578 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); |
| 577 | 579 |
| 578 bool success = false; | 580 bool success = false; |
| 579 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { | 581 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { |
| 580 // We check that config == desc.fConfig in GrGLGpu::canWriteTexturePixel
s() | 582 // We check that config == desc.fConfig in GrGLGpu::canWriteTexturePixel
s() |
| 581 SkASSERT(config == glTex->desc().fConfig); | 583 SkASSERT(config == glTex->desc().fConfig); |
| 582 success = this->uploadCompressedTexData(glTex->desc(), buffer, false, le
ft, top, width, | 584 success = this->uploadCompressedTexData(glTex->desc(), glTex->target(),
buffer, false, left, |
| 583 height); | 585 top, width, height); |
| 584 } else { | 586 } else { |
| 585 success = this->uploadTexData(glTex->desc(), false, left, top, width, he
ight, config, | 587 success = this->uploadTexData(glTex->desc(), glTex->target(), false, lef
t, top, width, |
| 586 buffer, rowBytes); | 588 height, config, buffer, rowBytes); |
| 587 } | 589 } |
| 588 | 590 |
| 589 if (success) { | 591 if (success) { |
| 590 glTex->texturePriv().dirtyMipMaps(true); | 592 glTex->texturePriv().dirtyMipMaps(true); |
| 591 return true; | 593 return true; |
| 592 } | 594 } |
| 593 | 595 |
| 594 return false; | 596 return false; |
| 595 } | 597 } |
| 596 | 598 |
| 597 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, | 599 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, |
| 598 const GrGLInterface* interface) { | 600 const GrGLInterface* interface) { |
| 599 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { | 601 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { |
| 600 return GR_GL_GET_ERROR(interface); | 602 return GR_GL_GET_ERROR(interface); |
| 601 } else { | 603 } else { |
| 602 return CHECK_ALLOC_ERROR(interface); | 604 return CHECK_ALLOC_ERROR(interface); |
| 603 } | 605 } |
| 604 } | 606 } |
| 605 | 607 |
| 606 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, | 608 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, |
| 609 GrGLenum target, |
| 607 bool isNewTexture, | 610 bool isNewTexture, |
| 608 int left, int top, int width, int height, | 611 int left, int top, int width, int height, |
| 609 GrPixelConfig dataConfig, | 612 GrPixelConfig dataConfig, |
| 610 const void* data, | 613 const void* data, |
| 611 size_t rowBytes) { | 614 size_t rowBytes) { |
| 612 SkASSERT(data || isNewTexture); | 615 SkASSERT(data || isNewTexture); |
| 613 | 616 |
| 614 // If we're uploading compressed data then we should be using uploadCompress
edTexData | 617 // If we're uploading compressed data then we should be using uploadCompress
edTexData |
| 615 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); | 618 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); |
| 616 | 619 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 static_cast<GrGLint>(GrUnpackAlignment(dataConfig)))); | 715 static_cast<GrGLint>(GrUnpackAlignment(dataConfig)))); |
| 713 } | 716 } |
| 714 bool succeeded = true; | 717 bool succeeded = true; |
| 715 if (isNewTexture && | 718 if (isNewTexture && |
| 716 0 == left && 0 == top && | 719 0 == left && 0 == top && |
| 717 desc.fWidth == width && desc.fHeight == height) { | 720 desc.fWidth == width && desc.fHeight == height) { |
| 718 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 721 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 719 if (useTexStorage) { | 722 if (useTexStorage) { |
| 720 // We never resize or change formats of textures. | 723 // We never resize or change formats of textures. |
| 721 GL_ALLOC_CALL(this->glInterface(), | 724 GL_ALLOC_CALL(this->glInterface(), |
| 722 TexStorage2D(GR_GL_TEXTURE_2D, | 725 TexStorage2D(target, |
| 723 1, // levels | 726 1, // levels |
| 724 internalFormat, | 727 internalFormat, |
| 725 desc.fWidth, desc.fHeight)); | 728 desc.fWidth, desc.fHeight)); |
| 726 } else { | 729 } else { |
| 727 GL_ALLOC_CALL(this->glInterface(), | 730 GL_ALLOC_CALL(this->glInterface(), |
| 728 TexImage2D(GR_GL_TEXTURE_2D, | 731 TexImage2D(target, |
| 729 0, // level | 732 0, // level |
| 730 internalFormat, | 733 internalFormat, |
| 731 desc.fWidth, desc.fHeight, | 734 desc.fWidth, desc.fHeight, |
| 732 0, // border | 735 0, // border |
| 733 externalFormat, externalType, | 736 externalFormat, externalType, |
| 734 data)); | 737 data)); |
| 735 } | 738 } |
| 736 GrGLenum error = check_alloc_error(desc, this->glInterface()); | 739 GrGLenum error = check_alloc_error(desc, this->glInterface()); |
| 737 if (error != GR_GL_NO_ERROR) { | 740 if (error != GR_GL_NO_ERROR) { |
| 738 succeeded = false; | 741 succeeded = false; |
| 739 } else { | 742 } else { |
| 740 // if we have data and we used TexStorage to create the texture, we | 743 // if we have data and we used TexStorage to create the texture, we |
| 741 // now upload with TexSubImage. | 744 // now upload with TexSubImage. |
| 742 if (data && useTexStorage) { | 745 if (data && useTexStorage) { |
| 743 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, | 746 GL_CALL(TexSubImage2D(target, |
| 744 0, // level | 747 0, // level |
| 745 left, top, | 748 left, top, |
| 746 width, height, | 749 width, height, |
| 747 externalFormat, externalType, | 750 externalFormat, externalType, |
| 748 data)); | 751 data)); |
| 749 } | 752 } |
| 750 } | 753 } |
| 751 } else { | 754 } else { |
| 752 if (swFlipY || glFlipY) { | 755 if (swFlipY || glFlipY) { |
| 753 top = desc.fHeight - (top + height); | 756 top = desc.fHeight - (top + height); |
| 754 } | 757 } |
| 755 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, | 758 GL_CALL(TexSubImage2D(target, |
| 756 0, // level | 759 0, // level |
| 757 left, top, | 760 left, top, |
| 758 width, height, | 761 width, height, |
| 759 externalFormat, externalType, data)); | 762 externalFormat, externalType, data)); |
| 760 } | 763 } |
| 761 | 764 |
| 762 if (restoreGLRowLength) { | 765 if (restoreGLRowLength) { |
| 763 SkASSERT(this->glCaps().unpackRowLengthSupport()); | 766 SkASSERT(this->glCaps().unpackRowLengthSupport()); |
| 764 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); | 767 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
| 765 } | 768 } |
| 766 if (glFlipY) { | 769 if (glFlipY) { |
| 767 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); | 770 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); |
| 768 } | 771 } |
| 769 return succeeded; | 772 return succeeded; |
| 770 } | 773 } |
| 771 | 774 |
| 772 // TODO: This function is using a lot of wonky semantics like, if width == -1 | 775 // TODO: This function is using a lot of wonky semantics like, if width == -1 |
| 773 // then set width = desc.fWdith ... blah. A better way to do it might be to | 776 // then set width = desc.fWdith ... blah. A better way to do it might be to |
| 774 // create a CompressedTexData struct that takes a desc/ptr and figures out | 777 // create a CompressedTexData struct that takes a desc/ptr and figures out |
| 775 // the proper upload semantics. Then users can construct this function how they | 778 // the proper upload semantics. Then users can construct this function how they |
| 776 // see fit if they want to go against the "standard" way to do it. | 779 // see fit if they want to go against the "standard" way to do it. |
| 777 bool GrGLGpu::uploadCompressedTexData(const GrSurfaceDesc& desc, | 780 bool GrGLGpu::uploadCompressedTexData(const GrSurfaceDesc& desc, |
| 781 GrGLenum target, |
| 778 const void* data, | 782 const void* data, |
| 779 bool isNewTexture, | 783 bool isNewTexture, |
| 780 int left, int top, int width, int height)
{ | 784 int left, int top, int width, int height)
{ |
| 781 SkASSERT(data || isNewTexture); | 785 SkASSERT(data || isNewTexture); |
| 782 | 786 |
| 783 // No support for software flip y, yet... | 787 // No support for software flip y, yet... |
| 784 SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin); | 788 SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin); |
| 785 | 789 |
| 786 if (-1 == width) { | 790 if (-1 == width) { |
| 787 width = desc.fWidth; | 791 width = desc.fWidth; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 807 | 811 |
| 808 // We only need the internal format for compressed 2D textures. | 812 // We only need the internal format for compressed 2D textures. |
| 809 GrGLenum internalFormat = 0; | 813 GrGLenum internalFormat = 0; |
| 810 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, nullptr,
nullptr)) { | 814 if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, nullptr,
nullptr)) { |
| 811 return false; | 815 return false; |
| 812 } | 816 } |
| 813 | 817 |
| 814 if (isNewTexture) { | 818 if (isNewTexture) { |
| 815 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 819 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 816 GL_ALLOC_CALL(this->glInterface(), | 820 GL_ALLOC_CALL(this->glInterface(), |
| 817 CompressedTexImage2D(GR_GL_TEXTURE_2D, | 821 CompressedTexImage2D(target, |
| 818 0, // level | 822 0, // level |
| 819 internalFormat, | 823 internalFormat, |
| 820 width, height, | 824 width, height, |
| 821 0, // border | 825 0, // border |
| 822 SkToInt(dataSize), | 826 SkToInt(dataSize), |
| 823 data)); | 827 data)); |
| 824 GrGLenum error = check_alloc_error(desc, this->glInterface()); | 828 GrGLenum error = check_alloc_error(desc, this->glInterface()); |
| 825 if (error != GR_GL_NO_ERROR) { | 829 if (error != GR_GL_NO_ERROR) { |
| 826 return false; | 830 return false; |
| 827 } | 831 } |
| 828 } else { | 832 } else { |
| 829 // Paletted textures can't be updated. | 833 // Paletted textures can't be updated. |
| 830 if (GR_GL_PALETTE8_RGBA8 == internalFormat) { | 834 if (GR_GL_PALETTE8_RGBA8 == internalFormat) { |
| 831 return false; | 835 return false; |
| 832 } | 836 } |
| 833 GL_CALL(CompressedTexSubImage2D(GR_GL_TEXTURE_2D, | 837 GL_CALL(CompressedTexSubImage2D(target, |
| 834 0, // level | 838 0, // level |
| 835 left, top, | 839 left, top, |
| 836 width, height, | 840 width, height, |
| 837 internalFormat, | 841 internalFormat, |
| 838 SkToInt(dataSize), | 842 SkToInt(dataSize), |
| 839 data)); | 843 data)); |
| 840 } | 844 } |
| 841 | 845 |
| 842 return true; | 846 return true; |
| 843 } | 847 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 case GrGLCaps::kNone_MSFBOType: | 881 case GrGLCaps::kNone_MSFBOType: |
| 878 SkFAIL("Shouldn't be here if we don't support multisampled renderbuf
fers."); | 882 SkFAIL("Shouldn't be here if we don't support multisampled renderbuf
fers."); |
| 879 break; | 883 break; |
| 880 } | 884 } |
| 881 return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface())); | 885 return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface())); |
| 882 } | 886 } |
| 883 | 887 |
| 884 bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc, | 888 bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc, |
| 885 GrGpuResource::LifeCycle lifeCycle, | 889 GrGpuResource::LifeCycle lifeCycle, |
| 886 GrGLuint texID, | 890 GrGLuint texID, |
| 891 GrGLenum textureTarget, |
| 887 GrGLRenderTarget::IDDesc* idDesc) { | 892 GrGLRenderTarget::IDDesc* idDesc) { |
| 888 idDesc->fMSColorRenderbufferID = 0; | 893 idDesc->fMSColorRenderbufferID = 0; |
| 889 idDesc->fRTFBOID = 0; | 894 idDesc->fRTFBOID = 0; |
| 890 idDesc->fTexFBOID = 0; | 895 idDesc->fTexFBOID = 0; |
| 891 idDesc->fLifeCycle = lifeCycle; | 896 idDesc->fLifeCycle = lifeCycle; |
| 892 idDesc->fSampleConfig = (GrGLCaps::kMixedSamples_MSFBOType == this->glCaps()
.msFBOType() && | 897 idDesc->fSampleConfig = (GrGLCaps::kMixedSamples_MSFBOType == this->glCaps()
.msFBOType() && |
| 893 desc.fSampleCnt > 0) ? GrRenderTarget::kStencil_Samp
leConfig : | 898 desc.fSampleCnt > 0) ? GrRenderTarget::kStencil_Samp
leConfig : |
| 894 GrRenderTarget::kUnified_Samp
leConfig; | 899 GrRenderTarget::kUnified_Samp
leConfig; |
| 895 | 900 |
| 896 GrGLenum status; | 901 GrGLenum status; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, idDesc->fMSColorRenderbuffe
rID)); | 940 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, idDesc->fMSColorRenderbuffe
rID)); |
| 936 if (!renderbuffer_storage_msaa(*fGLContext, | 941 if (!renderbuffer_storage_msaa(*fGLContext, |
| 937 desc.fSampleCnt, | 942 desc.fSampleCnt, |
| 938 msColorFormat, | 943 msColorFormat, |
| 939 desc.fWidth, desc.fHeight)) { | 944 desc.fWidth, desc.fHeight)) { |
| 940 goto FAILED; | 945 goto FAILED; |
| 941 } | 946 } |
| 942 fStats.incRenderTargetBinds(); | 947 fStats.incRenderTargetBinds(); |
| 943 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fRTFBOID)); | 948 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fRTFBOID)); |
| 944 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 949 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 945 GR_GL_COLOR_ATTACHMENT0, | 950 GR_GL_COLOR_ATTACHMENT0, |
| 946 GR_GL_RENDERBUFFER, | 951 GR_GL_RENDERBUFFER, |
| 947 idDesc->fMSColorRenderbufferID)); | 952 idDesc->fMSColorRenderbufferID)); |
| 948 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || | 953 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || |
| 949 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { | 954 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { |
| 950 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 955 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 951 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | 956 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
| 952 goto FAILED; | 957 goto FAILED; |
| 953 } | 958 } |
| 954 fGLContext->caps()->markConfigAsValidColorAttachment(desc.fConfig); | 959 fGLContext->caps()->markConfigAsValidColorAttachment(desc.fConfig); |
| 955 } | 960 } |
| 956 } | 961 } |
| 957 fStats.incRenderTargetBinds(); | 962 fStats.incRenderTargetBinds(); |
| 958 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fTexFBOID)); | 963 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fTexFBOID)); |
| 959 | 964 |
| 960 if (this->glCaps().usesImplicitMSAAResolve() && desc.fSampleCnt > 0) { | 965 if (this->glCaps().usesImplicitMSAAResolve() && desc.fSampleCnt > 0) { |
| 961 GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, | 966 GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, |
| 962 GR_GL_COLOR_ATTACHMENT0, | 967 GR_GL_COLOR_ATTACHMENT0, |
| 963 GR_GL_TEXTURE_2D, | 968 textureTarget, |
| 964 texID, 0, desc.fSampleCnt)); | 969 texID, 0, desc.fSampleCnt)); |
| 965 } else { | 970 } else { |
| 966 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, | 971 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
| 967 GR_GL_COLOR_ATTACHMENT0, | 972 GR_GL_COLOR_ATTACHMENT0, |
| 968 GR_GL_TEXTURE_2D, | 973 textureTarget, |
| 969 texID, 0)); | 974 texID, 0)); |
| 970 } | 975 } |
| 971 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || | 976 if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || |
| 972 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { | 977 !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { |
| 973 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 978 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 974 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | 979 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
| 975 goto FAILED; | 980 goto FAILED; |
| 976 } | 981 } |
| 977 fGLContext->caps()->markConfigAsValidColorAttachment(desc.fConfig); | 982 fGLContext->caps()->markConfigAsValidColorAttachment(desc.fConfig); |
| 978 } | 983 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC
nt) { | 1016 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC
nt) { |
| 1012 //SkDebugf("MSAA RT requested but not supported on this platform."); | 1017 //SkDebugf("MSAA RT requested but not supported on this platform."); |
| 1013 return return_null_texture(); | 1018 return return_null_texture(); |
| 1014 } | 1019 } |
| 1015 | 1020 |
| 1016 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); | 1021 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
| 1017 | 1022 |
| 1018 GrGLTexture::IDDesc idDesc; | 1023 GrGLTexture::IDDesc idDesc; |
| 1019 GL_CALL(GenTextures(1, &idDesc.fTextureID)); | 1024 GL_CALL(GenTextures(1, &idDesc.fTextureID)); |
| 1020 idDesc.fLifeCycle = lifeCycle; | 1025 idDesc.fLifeCycle = lifeCycle; |
| 1026 // We only support GL_TEXTURE_2D at the moment. |
| 1027 idDesc.fTarget = GR_GL_TEXTURE_2D; |
| 1021 | 1028 |
| 1022 if (!idDesc.fTextureID) { | 1029 if (!idDesc.fTextureID) { |
| 1023 return return_null_texture(); | 1030 return return_null_texture(); |
| 1024 } | 1031 } |
| 1025 | 1032 |
| 1026 this->setScratchTextureUnit(); | 1033 this->setScratchTextureUnit(); |
| 1027 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, idDesc.fTextureID)); | 1034 GL_CALL(BindTexture(idDesc.fTarget, idDesc.fTextureID)); |
| 1028 | 1035 |
| 1029 if (renderTarget && this->glCaps().textureUsageSupport()) { | 1036 if (renderTarget && this->glCaps().textureUsageSupport()) { |
| 1030 // provides a hint about how this texture will be used | 1037 // provides a hint about how this texture will be used |
| 1031 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 1038 GL_CALL(TexParameteri(idDesc.fTarget, |
| 1032 GR_GL_TEXTURE_USAGE, | 1039 GR_GL_TEXTURE_USAGE, |
| 1033 GR_GL_FRAMEBUFFER_ATTACHMENT)); | 1040 GR_GL_FRAMEBUFFER_ATTACHMENT)); |
| 1034 } | 1041 } |
| 1035 | 1042 |
| 1036 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some | 1043 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some |
| 1037 // drivers have a bug where an FBO won't be complete if it includes a | 1044 // drivers have a bug where an FBO won't be complete if it includes a |
| 1038 // texture that is not mipmap complete (considering the filter in use). | 1045 // texture that is not mipmap complete (considering the filter in use). |
| 1039 GrGLTexture::TexParams initialTexParams; | 1046 GrGLTexture::TexParams initialTexParams; |
| 1040 // we only set a subset here so invalidate first | 1047 // we only set a subset here so invalidate first |
| 1041 initialTexParams.invalidate(); | 1048 initialTexParams.invalidate(); |
| 1042 initialTexParams.fMinFilter = GR_GL_NEAREST; | 1049 initialTexParams.fMinFilter = GR_GL_NEAREST; |
| 1043 initialTexParams.fMagFilter = GR_GL_NEAREST; | 1050 initialTexParams.fMagFilter = GR_GL_NEAREST; |
| 1044 initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE; | 1051 initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE; |
| 1045 initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE; | 1052 initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE; |
| 1046 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 1053 GL_CALL(TexParameteri(idDesc.fTarget, |
| 1047 GR_GL_TEXTURE_MAG_FILTER, | 1054 GR_GL_TEXTURE_MAG_FILTER, |
| 1048 initialTexParams.fMagFilter)); | 1055 initialTexParams.fMagFilter)); |
| 1049 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 1056 GL_CALL(TexParameteri(idDesc.fTarget, |
| 1050 GR_GL_TEXTURE_MIN_FILTER, | 1057 GR_GL_TEXTURE_MIN_FILTER, |
| 1051 initialTexParams.fMinFilter)); | 1058 initialTexParams.fMinFilter)); |
| 1052 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 1059 GL_CALL(TexParameteri(idDesc.fTarget, |
| 1053 GR_GL_TEXTURE_WRAP_S, | 1060 GR_GL_TEXTURE_WRAP_S, |
| 1054 initialTexParams.fWrapS)); | 1061 initialTexParams.fWrapS)); |
| 1055 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 1062 GL_CALL(TexParameteri(idDesc.fTarget, |
| 1056 GR_GL_TEXTURE_WRAP_T, | 1063 GR_GL_TEXTURE_WRAP_T, |
| 1057 initialTexParams.fWrapT)); | 1064 initialTexParams.fWrapT)); |
| 1058 if (!this->uploadTexData(desc, true, 0, 0, | 1065 if (!this->uploadTexData(desc, idDesc.fTarget, true, 0, 0, |
| 1059 desc.fWidth, desc.fHeight, | 1066 desc.fWidth, desc.fHeight, |
| 1060 desc.fConfig, srcData, rowBytes)) { | 1067 desc.fConfig, srcData, rowBytes)) { |
| 1061 GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); | 1068 GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); |
| 1062 return return_null_texture(); | 1069 return return_null_texture(); |
| 1063 } | 1070 } |
| 1064 | 1071 |
| 1065 GrGLTexture* tex; | 1072 GrGLTexture* tex; |
| 1066 if (renderTarget) { | 1073 if (renderTarget) { |
| 1067 // unbind the texture from the texture unit before binding it to the fra
me buffer | 1074 // unbind the texture from the texture unit before binding it to the fra
me buffer |
| 1068 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, 0)); | 1075 GL_CALL(BindTexture(idDesc.fTarget, 0)); |
| 1069 GrGLRenderTarget::IDDesc rtIDDesc; | 1076 GrGLRenderTarget::IDDesc rtIDDesc; |
| 1070 | 1077 |
| 1071 if (!this->createRenderTargetObjects(desc, lifeCycle, idDesc.fTextureID,
&rtIDDesc)) { | 1078 if (!this->createRenderTargetObjects(desc, lifeCycle, idDesc.fTextureID,
idDesc.fTarget, |
| 1079 &rtIDDesc)) { |
| 1072 GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); | 1080 GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); |
| 1073 return return_null_texture(); | 1081 return return_null_texture(); |
| 1074 } | 1082 } |
| 1075 tex = new GrGLTextureRenderTarget(this, desc, idDesc, rtIDDesc); | 1083 tex = new GrGLTextureRenderTarget(this, desc, idDesc, rtIDDesc); |
| 1076 } else { | 1084 } else { |
| 1077 tex = new GrGLTexture(this, desc, idDesc); | 1085 tex = new GrGLTexture(this, desc, idDesc); |
| 1078 } | 1086 } |
| 1079 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); | 1087 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); |
| 1080 #ifdef TRACE_TEXTURE_CREATION | 1088 #ifdef TRACE_TEXTURE_CREATION |
| 1081 SkDebugf("--- new texture [%d] size=(%d %d) config=%d\n", | 1089 SkDebugf("--- new texture [%d] size=(%d %d) config=%d\n", |
| 1082 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); | 1090 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); |
| 1083 #endif | 1091 #endif |
| 1084 return tex; | 1092 return tex; |
| 1085 } | 1093 } |
| 1086 | 1094 |
| 1087 GrTexture* GrGLGpu::onCreateCompressedTexture(const GrSurfaceDesc& desc, | 1095 GrTexture* GrGLGpu::onCreateCompressedTexture(const GrSurfaceDesc& desc, |
| 1088 GrGpuResource::LifeCycle lifeCycle
, | 1096 GrGpuResource::LifeCycle lifeCycle
, |
| 1089 const void* srcData) { | 1097 const void* srcData) { |
| 1090 // Make sure that we're not flipping Y. | 1098 // Make sure that we're not flipping Y. |
| 1091 if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { | 1099 if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { |
| 1092 return return_null_texture(); | 1100 return return_null_texture(); |
| 1093 } | 1101 } |
| 1094 | 1102 |
| 1095 GrGLTexture::IDDesc idDesc; | 1103 GrGLTexture::IDDesc idDesc; |
| 1096 GL_CALL(GenTextures(1, &idDesc.fTextureID)); | 1104 GL_CALL(GenTextures(1, &idDesc.fTextureID)); |
| 1097 idDesc.fLifeCycle = lifeCycle; | 1105 idDesc.fLifeCycle = lifeCycle; |
| 1106 // We only support GL_TEXTURE_2D at the moment. |
| 1107 idDesc.fTarget = GR_GL_TEXTURE_2D; |
| 1098 | 1108 |
| 1099 if (!idDesc.fTextureID) { | 1109 if (!idDesc.fTextureID) { |
| 1100 return return_null_texture(); | 1110 return return_null_texture(); |
| 1101 } | 1111 } |
| 1102 | 1112 |
| 1103 this->setScratchTextureUnit(); | 1113 this->setScratchTextureUnit(); |
| 1104 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, idDesc.fTextureID)); | 1114 GL_CALL(BindTexture(idDesc.fTarget, idDesc.fTextureID)); |
| 1105 | 1115 |
| 1106 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some | 1116 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some |
| 1107 // drivers have a bug where an FBO won't be complete if it includes a | 1117 // drivers have a bug where an FBO won't be complete if it includes a |
| 1108 // texture that is not mipmap complete (considering the filter in use). | 1118 // texture that is not mipmap complete (considering the filter in use). |
| 1109 GrGLTexture::TexParams initialTexParams; | 1119 GrGLTexture::TexParams initialTexParams; |
| 1110 // we only set a subset here so invalidate first | 1120 // we only set a subset here so invalidate first |
| 1111 initialTexParams.invalidate(); | 1121 initialTexParams.invalidate(); |
| 1112 initialTexParams.fMinFilter = GR_GL_NEAREST; | 1122 initialTexParams.fMinFilter = GR_GL_NEAREST; |
| 1113 initialTexParams.fMagFilter = GR_GL_NEAREST; | 1123 initialTexParams.fMagFilter = GR_GL_NEAREST; |
| 1114 initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE; | 1124 initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE; |
| 1115 initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE; | 1125 initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE; |
| 1116 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 1126 GL_CALL(TexParameteri(idDesc.fTarget, |
| 1117 GR_GL_TEXTURE_MAG_FILTER, | 1127 GR_GL_TEXTURE_MAG_FILTER, |
| 1118 initialTexParams.fMagFilter)); | 1128 initialTexParams.fMagFilter)); |
| 1119 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 1129 GL_CALL(TexParameteri(idDesc.fTarget, |
| 1120 GR_GL_TEXTURE_MIN_FILTER, | 1130 GR_GL_TEXTURE_MIN_FILTER, |
| 1121 initialTexParams.fMinFilter)); | 1131 initialTexParams.fMinFilter)); |
| 1122 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 1132 GL_CALL(TexParameteri(idDesc.fTarget, |
| 1123 GR_GL_TEXTURE_WRAP_S, | 1133 GR_GL_TEXTURE_WRAP_S, |
| 1124 initialTexParams.fWrapS)); | 1134 initialTexParams.fWrapS)); |
| 1125 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 1135 GL_CALL(TexParameteri(idDesc.fTarget, |
| 1126 GR_GL_TEXTURE_WRAP_T, | 1136 GR_GL_TEXTURE_WRAP_T, |
| 1127 initialTexParams.fWrapT)); | 1137 initialTexParams.fWrapT)); |
| 1128 | 1138 |
| 1129 if (!this->uploadCompressedTexData(desc, srcData)) { | 1139 if (!this->uploadCompressedTexData(desc, idDesc.fTarget, srcData)) { |
| 1130 GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); | 1140 GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); |
| 1131 return return_null_texture(); | 1141 return return_null_texture(); |
| 1132 } | 1142 } |
| 1133 | 1143 |
| 1134 GrGLTexture* tex; | 1144 GrGLTexture* tex; |
| 1135 tex = new GrGLTexture(this, desc, idDesc); | 1145 tex = new GrGLTexture(this, desc, idDesc); |
| 1136 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); | 1146 tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); |
| 1137 #ifdef TRACE_TEXTURE_CREATION | 1147 #ifdef TRACE_TEXTURE_CREATION |
| 1138 SkDebugf("--- new compressed texture [%d] size=(%d %d) config=%d\n", | 1148 SkDebugf("--- new compressed texture [%d] size=(%d %d) config=%d\n", |
| 1139 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); | 1149 glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); |
| (...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2286 | 2296 |
| 2287 // If we created a rt/tex and rendered to it without using a texture and now
we're texturing | 2297 // If we created a rt/tex and rendered to it without using a texture and now
we're texturing |
| 2288 // from the rt it will still be the last bound texture, but it needs resolvi
ng. So keep this | 2298 // from the rt it will still be the last bound texture, but it needs resolvi
ng. So keep this |
| 2289 // out of the "last != next" check. | 2299 // out of the "last != next" check. |
| 2290 GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderTa
rget()); | 2300 GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderTa
rget()); |
| 2291 if (texRT) { | 2301 if (texRT) { |
| 2292 this->onResolveRenderTarget(texRT); | 2302 this->onResolveRenderTarget(texRT); |
| 2293 } | 2303 } |
| 2294 | 2304 |
| 2295 uint32_t textureID = texture->getUniqueID(); | 2305 uint32_t textureID = texture->getUniqueID(); |
| 2306 GrGLenum target = texture->target(); |
| 2296 if (fHWBoundTextureUniqueIDs[unitIdx] != textureID) { | 2307 if (fHWBoundTextureUniqueIDs[unitIdx] != textureID) { |
| 2297 this->setTextureUnit(unitIdx); | 2308 this->setTextureUnit(unitIdx); |
| 2298 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, texture->textureID())); | 2309 GL_CALL(BindTexture(target, texture->textureID())); |
| 2299 fHWBoundTextureUniqueIDs[unitIdx] = textureID; | 2310 fHWBoundTextureUniqueIDs[unitIdx] = textureID; |
| 2300 } | 2311 } |
| 2301 | 2312 |
| 2302 ResetTimestamp timestamp; | 2313 ResetTimestamp timestamp; |
| 2303 const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(&ti
mestamp); | 2314 const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(&ti
mestamp); |
| 2304 bool setAll = timestamp < this->getResetTimestamp(); | 2315 bool setAll = timestamp < this->getResetTimestamp(); |
| 2305 GrGLTexture::TexParams newTexParams; | 2316 GrGLTexture::TexParams newTexParams; |
| 2306 | 2317 |
| 2307 static GrGLenum glMinFilterModes[] = { | 2318 static GrGLenum glMinFilterModes[] = { |
| 2308 GR_GL_NEAREST, | 2319 GR_GL_NEAREST, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2320 if (!this->caps()->mipMapSupport() || GrPixelConfigIsCompressed(texture-
>config())) { | 2331 if (!this->caps()->mipMapSupport() || GrPixelConfigIsCompressed(texture-
>config())) { |
| 2321 filterMode = GrTextureParams::kBilerp_FilterMode; | 2332 filterMode = GrTextureParams::kBilerp_FilterMode; |
| 2322 } | 2333 } |
| 2323 } | 2334 } |
| 2324 | 2335 |
| 2325 newTexParams.fMinFilter = glMinFilterModes[filterMode]; | 2336 newTexParams.fMinFilter = glMinFilterModes[filterMode]; |
| 2326 newTexParams.fMagFilter = glMagFilterModes[filterMode]; | 2337 newTexParams.fMagFilter = glMagFilterModes[filterMode]; |
| 2327 | 2338 |
| 2328 if (GrTextureParams::kMipMap_FilterMode == filterMode && | 2339 if (GrTextureParams::kMipMap_FilterMode == filterMode && |
| 2329 texture->texturePriv().mipMapsAreDirty()) { | 2340 texture->texturePriv().mipMapsAreDirty()) { |
| 2330 GL_CALL(GenerateMipmap(GR_GL_TEXTURE_2D)); | 2341 GL_CALL(GenerateMipmap(target)); |
| 2331 texture->texturePriv().dirtyMipMaps(false); | 2342 texture->texturePriv().dirtyMipMaps(false); |
| 2332 } | 2343 } |
| 2333 | 2344 |
| 2334 newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX()); | 2345 newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX()); |
| 2335 newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY()); | 2346 newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY()); |
| 2336 memcpy(newTexParams.fSwizzleRGBA, | 2347 memcpy(newTexParams.fSwizzleRGBA, |
| 2337 GrGLShaderBuilder::GetTexParamSwizzle(texture->config(), this->glCaps
()), | 2348 GrGLShaderBuilder::GetTexParamSwizzle(texture->config(), this->glCaps
()), |
| 2338 sizeof(newTexParams.fSwizzleRGBA)); | 2349 sizeof(newTexParams.fSwizzleRGBA)); |
| 2339 if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) { | 2350 if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) { |
| 2340 this->setTextureUnit(unitIdx); | 2351 this->setTextureUnit(unitIdx); |
| 2341 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 2352 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MAG_FILTER, newTexParams.fMa
gFilter)); |
| 2342 GR_GL_TEXTURE_MAG_FILTER, | |
| 2343 newTexParams.fMagFilter)); | |
| 2344 } | 2353 } |
| 2345 if (setAll || newTexParams.fMinFilter != oldTexParams.fMinFilter) { | 2354 if (setAll || newTexParams.fMinFilter != oldTexParams.fMinFilter) { |
| 2346 this->setTextureUnit(unitIdx); | 2355 this->setTextureUnit(unitIdx); |
| 2347 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 2356 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MIN_FILTER, newTexParams.fMi
nFilter)); |
| 2348 GR_GL_TEXTURE_MIN_FILTER, | |
| 2349 newTexParams.fMinFilter)); | |
| 2350 } | 2357 } |
| 2351 if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) { | 2358 if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) { |
| 2352 this->setTextureUnit(unitIdx); | 2359 this->setTextureUnit(unitIdx); |
| 2353 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 2360 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_S, newTexParams.fWrapS)
); |
| 2354 GR_GL_TEXTURE_WRAP_S, | |
| 2355 newTexParams.fWrapS)); | |
| 2356 } | 2361 } |
| 2357 if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) { | 2362 if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) { |
| 2358 this->setTextureUnit(unitIdx); | 2363 this->setTextureUnit(unitIdx); |
| 2359 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, | 2364 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_T, newTexParams.fWrapT)
); |
| 2360 GR_GL_TEXTURE_WRAP_T, | |
| 2361 newTexParams.fWrapT)); | |
| 2362 } | 2365 } |
| 2363 if (this->glCaps().textureSwizzleSupport() && | 2366 if (this->glCaps().textureSwizzleSupport() && |
| 2364 (setAll || memcmp(newTexParams.fSwizzleRGBA, | 2367 (setAll || memcmp(newTexParams.fSwizzleRGBA, |
| 2365 oldTexParams.fSwizzleRGBA, | 2368 oldTexParams.fSwizzleRGBA, |
| 2366 sizeof(newTexParams.fSwizzleRGBA)))) { | 2369 sizeof(newTexParams.fSwizzleRGBA)))) { |
| 2367 this->setTextureUnit(unitIdx); | 2370 this->setTextureUnit(unitIdx); |
| 2368 if (this->glStandard() == kGLES_GrGLStandard) { | 2371 if (this->glStandard() == kGLES_GrGLStandard) { |
| 2369 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA. | 2372 // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA. |
| 2370 const GrGLenum* swizzle = newTexParams.fSwizzleRGBA; | 2373 const GrGLenum* swizzle = newTexParams.fSwizzleRGBA; |
| 2371 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_R, swi
zzle[0])); | 2374 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_R, swizzle[0])); |
| 2372 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_G, swi
zzle[1])); | 2375 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_G, swizzle[1])); |
| 2373 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_B, swi
zzle[2])); | 2376 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_B, swizzle[2])); |
| 2374 GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_A, swi
zzle[3])); | 2377 GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_A, swizzle[3])); |
| 2375 } else { | 2378 } else { |
| 2376 GR_STATIC_ASSERT(sizeof(newTexParams.fSwizzleRGBA[0]) == sizeof(GrGL
int)); | 2379 GR_STATIC_ASSERT(sizeof(newTexParams.fSwizzleRGBA[0]) == sizeof(GrGL
int)); |
| 2377 const GrGLint* swizzle = reinterpret_cast<const GrGLint*>(newTexPara
ms.fSwizzleRGBA); | 2380 const GrGLint* swizzle = reinterpret_cast<const GrGLint*>(newTexPara
ms.fSwizzleRGBA); |
| 2378 GL_CALL(TexParameteriv(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_RGBA,
swizzle)); | 2381 GL_CALL(TexParameteriv(target, GR_GL_TEXTURE_SWIZZLE_RGBA, swizzle))
; |
| 2379 } | 2382 } |
| 2380 } | 2383 } |
| 2381 texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); | 2384 texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); |
| 2382 } | 2385 } |
| 2383 | 2386 |
| 2384 void GrGLGpu::flushColorWrite(bool writeColor) { | 2387 void GrGLGpu::flushColorWrite(bool writeColor) { |
| 2385 if (!writeColor) { | 2388 if (!writeColor) { |
| 2386 if (kNo_TriState != fHWWriteToColor) { | 2389 if (kNo_TriState != fHWWriteToColor) { |
| 2387 GL_CALL(ColorMask(GR_GL_FALSE, GR_GL_FALSE, | 2390 GL_CALL(ColorMask(GR_GL_FALSE, GR_GL_FALSE, |
| 2388 GR_GL_FALSE, GR_GL_FALSE)); | 2391 GR_GL_FALSE, GR_GL_FALSE)); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2674 return true; | 2677 return true; |
| 2675 } else { | 2678 } else { |
| 2676 return false; | 2679 return false; |
| 2677 } | 2680 } |
| 2678 } | 2681 } |
| 2679 | 2682 |
| 2680 } | 2683 } |
| 2681 | 2684 |
| 2682 // If a temporary FBO was created, its non-zero ID is returned. The viewport tha
t the copy rect is | 2685 // If a temporary FBO was created, its non-zero ID is returned. The viewport tha
t the copy rect is |
| 2683 // relative to is output. | 2686 // relative to is output. |
| 2684 GrGLuint GrGLGpu::bindSurfaceAsFBO(GrSurface* surface, GrGLenum fboTarget, GrGLI
Rect* viewport, | 2687 void GrGLGpu::bindSurfaceFBOForCopy(GrSurface* surface, GrGLenum fboTarget, GrGL
IRect* viewport, |
| 2685 TempFBOTarget tempFBOTarget) { | 2688 TempFBOTarget tempFBOTarget) { |
| 2686 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarge
t()); | 2689 GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarge
t()); |
| 2687 if (nullptr == rt) { | 2690 if (nullptr == rt) { |
| 2688 SkASSERT(surface->asTexture()); | 2691 SkASSERT(surface->asTexture()); |
| 2689 GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textur
eID(); | 2692 GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textur
eID(); |
| 2693 GrGLenum target = static_cast<GrGLTexture*>(surface->asTexture())->targe
t(); |
| 2690 GrGLuint* tempFBOID; | 2694 GrGLuint* tempFBOID; |
| 2691 tempFBOID = kSrc_TempFBOTarget == tempFBOTarget ? &fTempSrcFBOID : &fTem
pDstFBOID; | 2695 tempFBOID = kSrc_TempFBOTarget == tempFBOTarget ? &fTempSrcFBOID : &fTem
pDstFBOID; |
| 2692 | 2696 |
| 2693 if (0 == *tempFBOID) { | 2697 if (0 == *tempFBOID) { |
| 2694 GR_GL_CALL(this->glInterface(), GenFramebuffers(1, tempFBOID)); | 2698 GR_GL_CALL(this->glInterface(), GenFramebuffers(1, tempFBOID)); |
| 2695 } | 2699 } |
| 2696 | 2700 |
| 2697 fStats.incRenderTargetBinds(); | 2701 fStats.incRenderTargetBinds(); |
| 2698 GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, *tempFBOID)); | 2702 GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, *tempFBOID)); |
| 2699 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget, | 2703 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget, |
| 2700 GR_GL_COLOR_ATTACHM
ENT0, | 2704 GR_GL_COLOR_ATTACHM
ENT0, |
| 2701 GR_GL_TEXTURE_2D, | 2705 target, |
| 2702 texID, | 2706 texID, |
| 2703 0)); | 2707 0)); |
| 2704 viewport->fLeft = 0; | 2708 viewport->fLeft = 0; |
| 2705 viewport->fBottom = 0; | 2709 viewport->fBottom = 0; |
| 2706 viewport->fWidth = surface->width(); | 2710 viewport->fWidth = surface->width(); |
| 2707 viewport->fHeight = surface->height(); | 2711 viewport->fHeight = surface->height(); |
| 2708 return *tempFBOID; | |
| 2709 } else { | 2712 } else { |
| 2710 GrGLuint tempFBOID = 0; | |
| 2711 fStats.incRenderTargetBinds(); | 2713 fStats.incRenderTargetBinds(); |
| 2712 GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, rt->renderFBO
ID())); | 2714 GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, rt->renderFBO
ID())); |
| 2713 *viewport = rt->getViewport(); | 2715 *viewport = rt->getViewport(); |
| 2714 return tempFBOID; | |
| 2715 } | 2716 } |
| 2716 } | 2717 } |
| 2717 | 2718 |
| 2718 void GrGLGpu::unbindTextureFromFBO(GrGLenum fboTarget) { | 2719 void GrGLGpu::unbindTextureFBOForCopy(GrGLenum fboTarget, GrSurface* surface) { |
| 2719 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget, | 2720 // bindSurfaceFBOForCopy temporarily binds textures that are not render targ
ets to |
| 2720 GR_GL_COLOR_ATTACHMENT0
, | 2721 if (!surface->asRenderTarget()) { |
| 2721 GR_GL_TEXTURE_2D, | 2722 SkASSERT(surface->asTexture()); |
| 2722 0, | 2723 GrGLenum textureTarget = static_cast<GrGLTexture*>(surface->asTexture())
->target(); |
| 2723 0)); | 2724 GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget, |
| 2725 GR_GL_COLOR_ATTACHM
ENT0, |
| 2726 textureTarget, |
| 2727 0, |
| 2728 0)); |
| 2729 } |
| 2724 } | 2730 } |
| 2725 | 2731 |
| 2726 bool GrGLGpu::initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc)
const { | 2732 bool GrGLGpu::initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc)
const { |
| 2727 // If the src is a texture, we can implement the blit as a draw assuming the
config is | 2733 // If the src is a texture, we can implement the blit as a draw assuming the
config is |
| 2728 // renderable. | 2734 // renderable. |
| 2729 if (src->asTexture() && this->caps()->isConfigRenderable(src->config(), fals
e)) { | 2735 if (src->asTexture() && this->caps()->isConfigRenderable(src->config(), fals
e)) { |
| 2730 desc->fOrigin = kDefault_GrSurfaceOrigin; | 2736 desc->fOrigin = kDefault_GrSurfaceOrigin; |
| 2731 desc->fFlags = kRenderTarget_GrSurfaceFlag; | 2737 desc->fFlags = kRenderTarget_GrSurfaceFlag; |
| 2732 desc->fConfig = src->config(); | 2738 desc->fConfig = src->config(); |
| 2733 return true; | 2739 return true; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2961 this->flushStencil(stencil); | 2967 this->flushStencil(stencil); |
| 2962 | 2968 |
| 2963 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); | 2969 GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); |
| 2964 } | 2970 } |
| 2965 | 2971 |
| 2966 void GrGLGpu::copySurfaceAsCopyTexSubImage(GrSurface* dst, | 2972 void GrGLGpu::copySurfaceAsCopyTexSubImage(GrSurface* dst, |
| 2967 GrSurface* src, | 2973 GrSurface* src, |
| 2968 const SkIRect& srcRect, | 2974 const SkIRect& srcRect, |
| 2969 const SkIPoint& dstPoint) { | 2975 const SkIPoint& dstPoint) { |
| 2970 SkASSERT(can_copy_texsubimage(dst, src, this)); | 2976 SkASSERT(can_copy_texsubimage(dst, src, this)); |
| 2971 GrGLuint srcFBO; | |
| 2972 GrGLIRect srcVP; | 2977 GrGLIRect srcVP; |
| 2973 srcFBO = this->bindSurfaceAsFBO(src, GR_GL_FRAMEBUFFER, &srcVP, kSrc_TempFBO
Target); | 2978 this->bindSurfaceFBOForCopy(src, GR_GL_FRAMEBUFFER, &srcVP, kSrc_TempFBOTarg
et); |
| 2974 GrGLTexture* dstTex = static_cast<GrGLTexture*>(dst->asTexture()); | 2979 GrGLTexture* dstTex = static_cast<GrGLTexture*>(dst->asTexture()); |
| 2975 SkASSERT(dstTex); | 2980 SkASSERT(dstTex); |
| 2976 // We modified the bound FBO | 2981 // We modified the bound FBO |
| 2977 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; | 2982 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 2978 GrGLIRect srcGLRect; | 2983 GrGLIRect srcGLRect; |
| 2979 srcGLRect.setRelativeTo(srcVP, | 2984 srcGLRect.setRelativeTo(srcVP, |
| 2980 srcRect.fLeft, | 2985 srcRect.fLeft, |
| 2981 srcRect.fTop, | 2986 srcRect.fTop, |
| 2982 srcRect.width(), | 2987 srcRect.width(), |
| 2983 srcRect.height(), | 2988 srcRect.height(), |
| 2984 src->origin()); | 2989 src->origin()); |
| 2985 | 2990 |
| 2986 this->setScratchTextureUnit(); | 2991 this->setScratchTextureUnit(); |
| 2987 GL_CALL(BindTexture(GR_GL_TEXTURE_2D, dstTex->textureID())); | 2992 GL_CALL(BindTexture(dstTex->target(), dstTex->textureID())); |
| 2988 GrGLint dstY; | 2993 GrGLint dstY; |
| 2989 if (kBottomLeft_GrSurfaceOrigin == dst->origin()) { | 2994 if (kBottomLeft_GrSurfaceOrigin == dst->origin()) { |
| 2990 dstY = dst->height() - (dstPoint.fY + srcGLRect.fHeight); | 2995 dstY = dst->height() - (dstPoint.fY + srcGLRect.fHeight); |
| 2991 } else { | 2996 } else { |
| 2992 dstY = dstPoint.fY; | 2997 dstY = dstPoint.fY; |
| 2993 } | 2998 } |
| 2994 GL_CALL(CopyTexSubImage2D(GR_GL_TEXTURE_2D, 0, | 2999 GL_CALL(CopyTexSubImage2D(dstTex->target(), 0, |
| 2995 dstPoint.fX, dstY, | 3000 dstPoint.fX, dstY, |
| 2996 srcGLRect.fLeft, srcGLRect.fBottom, | 3001 srcGLRect.fLeft, srcGLRect.fBottom, |
| 2997 srcGLRect.fWidth, srcGLRect.fHeight)); | 3002 srcGLRect.fWidth, srcGLRect.fHeight)); |
| 2998 if (srcFBO) { | 3003 this->unbindTextureFBOForCopy(GR_GL_FRAMEBUFFER, src); |
| 2999 this->unbindTextureFromFBO(GR_GL_FRAMEBUFFER); | |
| 3000 } | |
| 3001 } | 3004 } |
| 3002 | 3005 |
| 3003 bool GrGLGpu::copySurfaceAsBlitFramebuffer(GrSurface* dst, | 3006 bool GrGLGpu::copySurfaceAsBlitFramebuffer(GrSurface* dst, |
| 3004 GrSurface* src, | 3007 GrSurface* src, |
| 3005 const SkIRect& srcRect, | 3008 const SkIRect& srcRect, |
| 3006 const SkIPoint& dstPoint) { | 3009 const SkIPoint& dstPoint) { |
| 3007 SkASSERT(can_blit_framebuffer(dst, src, this)); | 3010 SkASSERT(can_blit_framebuffer(dst, src, this)); |
| 3008 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, | 3011 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, |
| 3009 srcRect.width(), srcRect.height()); | 3012 srcRect.width(), srcRect.height()); |
| 3010 if (dst == src) { | 3013 if (dst == src) { |
| 3011 if (SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect)) { | 3014 if (SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect)) { |
| 3012 return false; | 3015 return false; |
| 3013 } | 3016 } |
| 3014 } | 3017 } |
| 3015 | 3018 |
| 3016 GrGLuint dstFBO; | |
| 3017 GrGLuint srcFBO; | |
| 3018 GrGLIRect dstVP; | 3019 GrGLIRect dstVP; |
| 3019 GrGLIRect srcVP; | 3020 GrGLIRect srcVP; |
| 3020 dstFBO = this->bindSurfaceAsFBO(dst, GR_GL_DRAW_FRAMEBUFFER, &dstVP, | 3021 this->bindSurfaceFBOForCopy(dst, GR_GL_DRAW_FRAMEBUFFER, &dstVP, kDst_TempFB
OTarget); |
| 3021 kDst_TempFBOTarget); | 3022 this->bindSurfaceFBOForCopy(src, GR_GL_READ_FRAMEBUFFER, &srcVP, kSrc_TempFB
OTarget); |
| 3022 srcFBO = this->bindSurfaceAsFBO(src, GR_GL_READ_FRAMEBUFFER, &srcVP, | |
| 3023 kSrc_TempFBOTarget); | |
| 3024 // We modified the bound FBO | 3023 // We modified the bound FBO |
| 3025 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; | 3024 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 3026 GrGLIRect srcGLRect; | 3025 GrGLIRect srcGLRect; |
| 3027 GrGLIRect dstGLRect; | 3026 GrGLIRect dstGLRect; |
| 3028 srcGLRect.setRelativeTo(srcVP, | 3027 srcGLRect.setRelativeTo(srcVP, |
| 3029 srcRect.fLeft, | 3028 srcRect.fLeft, |
| 3030 srcRect.fTop, | 3029 srcRect.fTop, |
| 3031 srcRect.width(), | 3030 srcRect.width(), |
| 3032 srcRect.height(), | 3031 srcRect.height(), |
| 3033 src->origin()); | 3032 src->origin()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3053 } | 3052 } |
| 3054 GL_CALL(BlitFramebuffer(srcGLRect.fLeft, | 3053 GL_CALL(BlitFramebuffer(srcGLRect.fLeft, |
| 3055 srcY0, | 3054 srcY0, |
| 3056 srcGLRect.fLeft + srcGLRect.fWidth, | 3055 srcGLRect.fLeft + srcGLRect.fWidth, |
| 3057 srcY1, | 3056 srcY1, |
| 3058 dstGLRect.fLeft, | 3057 dstGLRect.fLeft, |
| 3059 dstGLRect.fBottom, | 3058 dstGLRect.fBottom, |
| 3060 dstGLRect.fLeft + dstGLRect.fWidth, | 3059 dstGLRect.fLeft + dstGLRect.fWidth, |
| 3061 dstGLRect.fBottom + dstGLRect.fHeight, | 3060 dstGLRect.fBottom + dstGLRect.fHeight, |
| 3062 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); | 3061 GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); |
| 3063 if (dstFBO) { | 3062 this->unbindTextureFBOForCopy(GR_GL_DRAW_FRAMEBUFFER, dst); |
| 3064 this->unbindTextureFromFBO(GR_GL_DRAW_FRAMEBUFFER); | 3063 this->unbindTextureFBOForCopy(GR_GL_READ_FRAMEBUFFER, src); |
| 3065 } | |
| 3066 if (srcFBO) { | |
| 3067 this->unbindTextureFromFBO(GR_GL_READ_FRAMEBUFFER); | |
| 3068 } | |
| 3069 return true; | 3064 return true; |
| 3070 } | 3065 } |
| 3071 | 3066 |
| 3072 void GrGLGpu::xferBarrier(GrRenderTarget* rt, GrXferBarrierType type) { | 3067 void GrGLGpu::xferBarrier(GrRenderTarget* rt, GrXferBarrierType type) { |
| 3073 SkASSERT(type); | 3068 SkASSERT(type); |
| 3074 switch (type) { | 3069 switch (type) { |
| 3075 case kTexture_GrXferBarrierType: { | 3070 case kTexture_GrXferBarrierType: { |
| 3076 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt); | 3071 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt); |
| 3077 if (glrt->textureFBOID() != glrt->renderFBOID()) { | 3072 if (glrt->textureFBOID() != glrt->renderFBOID()) { |
| 3078 // The render target uses separate storage so no need for glText
ureBarrier. | 3073 // The render target uses separate storage so no need for glText
ureBarrier. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3182 this->setVertexArrayID(gpu, 0); | 3177 this->setVertexArrayID(gpu, 0); |
| 3183 } | 3178 } |
| 3184 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3179 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 3185 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3180 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 3186 fDefaultVertexArrayAttribState.resize(attrCount); | 3181 fDefaultVertexArrayAttribState.resize(attrCount); |
| 3187 } | 3182 } |
| 3188 attribState = &fDefaultVertexArrayAttribState; | 3183 attribState = &fDefaultVertexArrayAttribState; |
| 3189 } | 3184 } |
| 3190 return attribState; | 3185 return attribState; |
| 3191 } | 3186 } |
| OLD | NEW |