| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GrVkGpu.h" | 8 #include "GrVkGpu.h" |
| 9 | 9 |
| 10 #include "GrContextOptions.h" | 10 #include "GrContextOptions.h" |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 | 749 |
| 750 static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin) { | 750 static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin) { |
| 751 // By default, all textures in Vk use TopLeft | 751 // By default, all textures in Vk use TopLeft |
| 752 if (kDefault_GrSurfaceOrigin == origin) { | 752 if (kDefault_GrSurfaceOrigin == origin) { |
| 753 return kTopLeft_GrSurfaceOrigin; | 753 return kTopLeft_GrSurfaceOrigin; |
| 754 } else { | 754 } else { |
| 755 return origin; | 755 return origin; |
| 756 } | 756 } |
| 757 } | 757 } |
| 758 | 758 |
| 759 GrTexture* GrVkGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc, | 759 sk_sp<GrTexture> GrVkGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc, |
| 760 GrWrapOwnership ownership) { | 760 GrWrapOwnership ownership) { |
| 761 if (0 == desc.fTextureHandle) { | 761 if (0 == desc.fTextureHandle) { |
| 762 return nullptr; | 762 return nullptr; |
| 763 } | 763 } |
| 764 | 764 |
| 765 int maxSize = this->caps()->maxTextureSize(); | 765 int maxSize = this->caps()->maxTextureSize(); |
| 766 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { | 766 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { |
| 767 return nullptr; | 767 return nullptr; |
| 768 } | 768 } |
| 769 | 769 |
| 770 const GrVkImageInfo* info = reinterpret_cast<const GrVkImageInfo*>(desc.fTex
tureHandle); | 770 const GrVkImageInfo* info = reinterpret_cast<const GrVkImageInfo*>(desc.fTex
tureHandle); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 784 surfDesc.fFlags = (GrSurfaceFlags)desc.fFlags; | 784 surfDesc.fFlags = (GrSurfaceFlags)desc.fFlags; |
| 785 surfDesc.fWidth = desc.fWidth; | 785 surfDesc.fWidth = desc.fWidth; |
| 786 surfDesc.fHeight = desc.fHeight; | 786 surfDesc.fHeight = desc.fHeight; |
| 787 surfDesc.fConfig = desc.fConfig; | 787 surfDesc.fConfig = desc.fConfig; |
| 788 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()
); | 788 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()
); |
| 789 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFla
g); | 789 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFla
g); |
| 790 // In GL, Chrome assumes all textures are BottomLeft | 790 // In GL, Chrome assumes all textures are BottomLeft |
| 791 // In VK, we don't have this restriction | 791 // In VK, we don't have this restriction |
| 792 surfDesc.fOrigin = resolve_origin(desc.fOrigin); | 792 surfDesc.fOrigin = resolve_origin(desc.fOrigin); |
| 793 | 793 |
| 794 GrVkTexture* texture = nullptr; | 794 if (!renderTarget) { |
| 795 if (renderTarget) { | 795 return GrVkTexture::MakeWrappedTexture(this, surfDesc, ownership, info); |
| 796 texture = GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(this
, surfDesc, | |
| 797 owne
rship, info); | |
| 798 } else { | |
| 799 texture = GrVkTexture::CreateWrappedTexture(this, surfDesc, ownership, i
nfo); | |
| 800 } | 796 } |
| 801 if (!texture) { | 797 return GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget(this, surfDes
c, ownership, info); |
| 802 return nullptr; | |
| 803 } | |
| 804 | |
| 805 return texture; | |
| 806 } | 798 } |
| 807 | 799 |
| 808 GrRenderTarget* GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe
sc& wrapDesc, | 800 sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTa
rgetDesc& wrapDesc, |
| 809 GrWrapOwnership ownership) { | 801 GrWrapOwnership ownersh
ip) { |
| 810 | 802 |
| 811 const GrVkImageInfo* info = | 803 const GrVkImageInfo* info = |
| 812 reinterpret_cast<const GrVkImageInfo*>(wrapDesc.fRenderTargetHandle); | 804 reinterpret_cast<const GrVkImageInfo*>(wrapDesc.fRenderTargetHandle); |
| 813 if (VK_NULL_HANDLE == info->fImage || | 805 if (VK_NULL_HANDLE == info->fImage || |
| 814 (VK_NULL_HANDLE == info->fAlloc.fMemory && kAdopt_GrWrapOwnership == own
ership)) { | 806 (VK_NULL_HANDLE == info->fAlloc.fMemory && kAdopt_GrWrapOwnership == own
ership)) { |
| 815 return nullptr; | 807 return nullptr; |
| 816 } | 808 } |
| 817 | 809 |
| 818 GrSurfaceDesc desc; | 810 GrSurfaceDesc desc; |
| 819 desc.fConfig = wrapDesc.fConfig; | 811 desc.fConfig = wrapDesc.fConfig; |
| 820 desc.fFlags = kCheckAllocation_GrSurfaceFlag; | 812 desc.fFlags = kCheckAllocation_GrSurfaceFlag; |
| 821 desc.fWidth = wrapDesc.fWidth; | 813 desc.fWidth = wrapDesc.fWidth; |
| 822 desc.fHeight = wrapDesc.fHeight; | 814 desc.fHeight = wrapDesc.fHeight; |
| 823 desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount()
); | 815 desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount()
); |
| 824 | 816 |
| 825 desc.fOrigin = resolve_origin(wrapDesc.fOrigin); | 817 desc.fOrigin = resolve_origin(wrapDesc.fOrigin); |
| 826 | 818 |
| 827 GrVkRenderTarget* tgt = GrVkRenderTarget::CreateWrappedRenderTarget(this, de
sc, | 819 sk_sp<GrVkRenderTarget> tgt = GrVkRenderTarget::MakeWrappedRenderTarget(this
, desc, |
| 828 ownershi
p, | 820 owne
rship, info); |
| 829 info); | |
| 830 if (tgt && wrapDesc.fStencilBits) { | 821 if (tgt && wrapDesc.fStencilBits) { |
| 831 if (!createStencilAttachmentForRenderTarget(tgt, desc.fWidth, desc.fHeig
ht)) { | 822 if (!createStencilAttachmentForRenderTarget(tgt.get(), desc.fWidth, desc
.fHeight)) { |
| 832 tgt->unref(); | |
| 833 return nullptr; | 823 return nullptr; |
| 834 } | 824 } |
| 835 } | 825 } |
| 836 return tgt; | 826 return tgt; |
| 837 } | 827 } |
| 838 | 828 |
| 839 void GrVkGpu::generateMipmap(GrVkTexture* tex) { | 829 void GrVkGpu::generateMipmap(GrVkTexture* tex) { |
| 840 // don't do anything for linearly tiled textures (can't have mipmaps) | 830 // don't do anything for linearly tiled textures (can't have mipmaps) |
| 841 if (tex->isLinearTiled()) { | 831 if (tex->isLinearTiled()) { |
| 842 SkDebugf("Trying to create mipmap for linear tiled texture"); | 832 SkDebugf("Trying to create mipmap for linear tiled texture"); |
| (...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1913 (VkFence*)&f
ence, | 1903 (VkFence*)&f
ence, |
| 1914 VK_TRUE, | 1904 VK_TRUE, |
| 1915 timeout)); | 1905 timeout)); |
| 1916 return (VK_SUCCESS == result); | 1906 return (VK_SUCCESS == result); |
| 1917 } | 1907 } |
| 1918 | 1908 |
| 1919 void GrVkGpu::deleteFence(GrFence fence) const { | 1909 void GrVkGpu::deleteFence(GrFence fence) const { |
| 1920 GR_VK_CALL(this->vkInterface(), DestroyFence(this->device(), (VkFence)fence,
nullptr)); | 1910 GR_VK_CALL(this->vkInterface(), DestroyFence(this->device(), (VkFence)fence,
nullptr)); |
| 1921 } | 1911 } |
| 1922 | 1912 |
| OLD | NEW |