| 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 #include "GrGLGpu.h" | 8 #include "GrGLGpu.h" |
| 9 #include "GrGLBuffer.h" | 9 #include "GrGLBuffer.h" |
| 10 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 desc.fConfig = wrapDesc.fConfig; | 691 desc.fConfig = wrapDesc.fConfig; |
| 692 desc.fFlags = kCheckAllocation_GrSurfaceFlag | kRenderTarget_GrSurfaceFlag; | 692 desc.fFlags = kCheckAllocation_GrSurfaceFlag | kRenderTarget_GrSurfaceFlag; |
| 693 desc.fWidth = wrapDesc.fWidth; | 693 desc.fWidth = wrapDesc.fWidth; |
| 694 desc.fHeight = wrapDesc.fHeight; | 694 desc.fHeight = wrapDesc.fHeight; |
| 695 desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount()
); | 695 desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount()
); |
| 696 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); | 696 desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); |
| 697 | 697 |
| 698 return GrGLRenderTarget::CreateWrapped(this, desc, idDesc, wrapDesc.fStencil
Bits); | 698 return GrGLRenderTarget::CreateWrapped(this, desc, idDesc, wrapDesc.fStencil
Bits); |
| 699 } | 699 } |
| 700 | 700 |
| 701 GrRenderTarget* GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextu
reDesc& desc) { | 701 static bool backend_texture_to_tex_info(const GrBackendTextureDesc& desc, |
| 702 GrGLTextureInfo* outInfo) { |
| 702 #ifdef SK_IGNORE_GL_TEXTURE_TARGET | 703 #ifdef SK_IGNORE_GL_TEXTURE_TARGET |
| 703 if (!desc.fTextureHandle) { | 704 if (!desc.fTextureHandle) { |
| 704 return nullptr; | 705 return false; |
| 705 } | 706 } |
| 706 #else | 707 #else |
| 707 const GrGLTextureInfo* info = reinterpret_cast<const GrGLTextureInfo*>(desc.
fTextureHandle); | 708 const GrGLTextureInfo* info = reinterpret_cast<const GrGLTextureInfo*>(desc.
fTextureHandle); |
| 708 if (!info || !info->fID) { | 709 if (!info || !info->fID) { |
| 709 return nullptr; | 710 return false; |
| 710 } | 711 } |
| 711 #endif | 712 #endif |
| 712 | |
| 713 GrGLTextureInfo texInfo; | 713 GrGLTextureInfo texInfo; |
| 714 GrSurfaceDesc surfDesc; | |
| 715 | |
| 716 #ifdef SK_IGNORE_GL_TEXTURE_TARGET | 714 #ifdef SK_IGNORE_GL_TEXTURE_TARGET |
| 717 texInfo.fID = static_cast<GrGLuint>(desc.fTextureHandle); | 715 texInfo.fID = static_cast<GrGLuint>(desc.fTextureHandle); |
| 718 // We only support GL_TEXTURE_2D at the moment. | 716 // We only support GL_TEXTURE_2D at the moment. |
| 719 texInfo.fTarget = GR_GL_TEXTURE_2D; | 717 texInfo.fTarget = GR_GL_TEXTURE_2D; |
| 720 #else | 718 #else |
| 721 texInfo = *info; | 719 texInfo = *info; |
| 722 #endif | 720 #endif |
| 723 | 721 |
| 724 if (GR_GL_TEXTURE_RECTANGLE != texInfo.fTarget && | 722 if (GR_GL_TEXTURE_RECTANGLE != texInfo.fTarget && |
| 725 GR_GL_TEXTURE_2D != texInfo.fTarget) { | 723 GR_GL_TEXTURE_2D != texInfo.fTarget) { |
| 726 // Only texture rectangle and texture 2d are supported. We do not check
whether texture | 724 // Only texture rectangle and texture 2d are supported. We do not check
whether texture |
| 727 // rectangle is supported by Skia - if the caller provided us with a tex
ture rectangle, | 725 // rectangle is supported by Skia - if the caller provided us with a tex
ture rectangle, |
| 728 // we assume the necessary support exists. | 726 // we assume the necessary support exists. |
| 727 return false; |
| 728 } |
| 729 *outInfo = texInfo; |
| 730 return true; |
| 731 } |
| 732 |
| 733 static void compute_backend_texture_key_for_wrap_as_render_target(const GrBacken
dTextureDesc& desc, |
| 734 GrUniqueKey* key)
{ |
| 735 GrGLTextureInfo texInfo; |
| 736 if (!backend_texture_to_tex_info(desc, &texInfo)) { |
| 737 return; |
| 738 } |
| 739 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| 740 GrUniqueKey::Builder builder(key, kDomain, 3); |
| 741 builder[0] = desc.fWidth; |
| 742 builder[1] = desc.fHeight; |
| 743 builder[2] = desc.fConfig | (desc.fFlags << 5) | (desc.fSampleCnt << 6) | (d
esc.fOrigin << 14) |
| 744 | ((texInfo.fTarget == GR_GL_TEXTURE_2D) << 16); |
| 745 builder.finish(); |
| 746 } |
| 747 |
| 748 void GrGLGpu::onComputeBackendTextureKeyForWrapAsRenderTarget(const GrBackendTex
tureDesc& desc, |
| 749 GrUniqueKey* key)
{ |
| 750 compute_backend_texture_key_for_wrap_as_render_target(desc, key); |
| 751 } |
| 752 |
| 753 bool GrGLGpu::onRewrapRenderTargetWithBackendTexture(const GrBackendTextureDesc&
desc, |
| 754 GrRenderTarget* rt) { |
| 755 GrGLTextureInfo texInfo; |
| 756 SkAssertResult(backend_texture_to_tex_info(desc, &texInfo)); |
| 757 |
| 758 |
| 759 GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(rt); |
| 760 SkASSERT(glRT); |
| 761 fStats.incRenderTargetBinds(); |
| 762 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, glRT->textureFBOID())); |
| 763 if (this->glCaps().usesImplicitMSAAResolve() && desc.fSampleCnt > 0) { |
| 764 GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, |
| 765 GR_GL_COLOR_ATTACHMENT0, |
| 766 texInfo.fTarget, |
| 767 texInfo.fID, 0, desc.fSampleCnt)
); |
| 768 } else { |
| 769 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
| 770 GR_GL_COLOR_ATTACHMENT0, |
| 771 texInfo.fTarget, |
| 772 texInfo.fID, 0)); |
| 773 } |
| 774 return true; |
| 775 } |
| 776 |
| 777 GrRenderTarget* GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextu
reDesc& desc) { |
| 778 GrGLTextureInfo texInfo; |
| 779 if (!backend_texture_to_tex_info(desc, &texInfo)) { |
| 729 return nullptr; | 780 return nullptr; |
| 730 } | 781 } |
| 731 | 782 |
| 783 GrSurfaceDesc surfDesc; |
| 732 surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags; | 784 surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags; |
| 733 surfDesc.fWidth = desc.fWidth; | 785 surfDesc.fWidth = desc.fWidth; |
| 734 surfDesc.fHeight = desc.fHeight; | 786 surfDesc.fHeight = desc.fHeight; |
| 735 surfDesc.fConfig = desc.fConfig; | 787 surfDesc.fConfig = desc.fConfig; |
| 736 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()
); | 788 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()
); |
| 737 // FIXME: this should be calling resolve_origin(), but Chrome code is curre
ntly | 789 // FIXME: this should be calling resolve_origin(), but Chrome code is curre
ntly |
| 738 // assuming the old behaviour, which is that backend textures are always | 790 // assuming the old behaviour, which is that backend textures are always |
| 739 // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to: | 791 // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to: |
| 740 // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); | 792 // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); |
| 741 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { | 793 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { |
| 742 surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 794 surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 743 } else { | 795 } else { |
| 744 surfDesc.fOrigin = desc.fOrigin; | 796 surfDesc.fOrigin = desc.fOrigin; |
| 745 } | 797 } |
| 746 | 798 |
| 747 GrGLRenderTarget::IDDesc rtIDDesc; | 799 GrGLRenderTarget::IDDesc rtIDDesc; |
| 748 if (!this->createRenderTargetObjects(surfDesc, texInfo, &rtIDDesc)) { | 800 if (!this->createRenderTargetObjects(surfDesc, texInfo, &rtIDDesc)) { |
| 749 return nullptr; | 801 return nullptr; |
| 750 } | 802 } |
| 751 return GrGLRenderTarget::CreateWrapped(this, surfDesc, rtIDDesc, 0); | 803 GrGLRenderTarget* rt = GrGLRenderTarget::CreateWrapped(this, surfDesc, rtIDD
esc, 0); |
| 804 GrUniqueKey key; |
| 805 compute_backend_texture_key_for_wrap_as_render_target(desc, &key); |
| 806 rt->resourcePriv().setUniqueKey(key); |
| 807 return rt; |
| 752 } | 808 } |
| 753 | 809 |
| 754 //////////////////////////////////////////////////////////////////////////////// | 810 //////////////////////////////////////////////////////////////////////////////// |
| 755 | 811 |
| 756 bool GrGLGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, | 812 bool GrGLGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, |
| 757 GrPixelConfig srcConfig, | 813 GrPixelConfig srcConfig, |
| 758 DrawPreference* drawPreference, | 814 DrawPreference* drawPreference, |
| 759 WritePixelTempDrawInfo* tempDrawInfo) { | 815 WritePixelTempDrawInfo* tempDrawInfo) { |
| 760 if (kIndex_8_GrPixelConfig == srcConfig || GrPixelConfigIsCompressed(dstSurf
ace->config())) { | 816 if (kIndex_8_GrPixelConfig == srcConfig || GrPixelConfigIsCompressed(dstSurf
ace->config())) { |
| 761 return false; | 817 return false; |
| (...skipping 3492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4254 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 4310 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |
| 4255 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 4311 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |
| 4256 copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 4312 copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
| 4257 copyParams->fWidth = texture->width(); | 4313 copyParams->fWidth = texture->width(); |
| 4258 copyParams->fHeight = texture->height(); | 4314 copyParams->fHeight = texture->height(); |
| 4259 return true; | 4315 return true; |
| 4260 } | 4316 } |
| 4261 } | 4317 } |
| 4262 return false; | 4318 return false; |
| 4263 } | 4319 } |
| OLD | NEW |