Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrBackendSurface.h" |
| 9 | |
| 10 | #ifdef SK_VULKAN |
| 11 | #include "vk/GrVkTypes.h" |
| 12 | #include "vk/GrVkUtil.h" |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 13 | #endif |
| 14 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 15 | #ifdef SK_VULKAN |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 16 | GrBackendTexture::GrBackendTexture(int width, |
| 17 | int height, |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 18 | const GrVkImageInfo& vkInfo) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 19 | : fWidth(width) |
| 20 | , fHeight(height) |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 21 | , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat)) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 22 | , fBackend(kVulkan_GrBackend) |
| 23 | , fVkInfo(vkInfo) {} |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 24 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 25 | |
| 26 | GrBackendTexture::GrBackendTexture(int width, |
| 27 | int height, |
| 28 | GrPixelConfig config, |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 29 | const GrGLTextureInfo& glInfo) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 30 | : fWidth(width) |
| 31 | , fHeight(height) |
| 32 | , fConfig(config) |
| 33 | , fBackend(kOpenGL_GrBackend) |
| 34 | , fGLInfo(glInfo) {} |
| 35 | |
| 36 | GrBackendTexture::GrBackendTexture(const GrBackendTextureDesc& desc, GrBackend backend) |
| 37 | : fWidth(desc.fWidth) |
| 38 | , fHeight(desc.fHeight) |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 39 | , fConfig(desc.fConfig) |
| 40 | , fBackend(backend) { |
| 41 | if (kOpenGL_GrBackend == backend) { |
| 42 | fGLInfo = *reinterpret_cast<const GrGLTextureInfo*>(desc.fTextureHandle); |
| 43 | } else { |
| 44 | SkASSERT(kVulkan_GrBackend == backend); |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 45 | #ifdef SK_VULKAN |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 46 | const GrVkImageInfo* vkInfo = |
| 47 | reinterpret_cast<const GrVkImageInfo*>(desc.fTextureHandle); |
| 48 | fConfig = GrVkFormatToPixelConfig(vkInfo->fFormat); |
| 49 | fVkInfo = *vkInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 50 | #else |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 51 | fConfig = kUnknown_GrPixelConfig; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 52 | #endif |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 53 | } |
| 54 | } |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 55 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 56 | #ifdef SK_VULKAN |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 57 | const GrVkImageInfo* GrBackendTexture::getVkImageInfo() const { |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 58 | if (kVulkan_GrBackend == fBackend) { |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 59 | return &fVkInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 60 | } |
| 61 | return nullptr; |
| 62 | } |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 63 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 64 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 65 | const GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() const { |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 66 | if (kOpenGL_GrBackend == fBackend) { |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 67 | return &fGLInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 68 | } |
| 69 | return nullptr; |
| 70 | } |
| 71 | |
| 72 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 73 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 74 | #ifdef SK_VULKAN |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 75 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 76 | int height, |
| 77 | int sampleCnt, |
| 78 | int stencilBits, |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 79 | const GrVkImageInfo& vkInfo) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 80 | : fWidth(width) |
| 81 | , fHeight(height) |
| 82 | , fSampleCnt(sampleCnt) |
| 83 | , fStencilBits(stencilBits) |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 84 | , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat)) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 85 | , fBackend(kVulkan_GrBackend) |
| 86 | , fVkInfo(vkInfo) {} |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 87 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 88 | |
| 89 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 90 | int height, |
| 91 | int sampleCnt, |
| 92 | int stencilBits, |
| 93 | GrPixelConfig config, |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 94 | const GrGLFramebufferInfo& glInfo) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 95 | : fWidth(width) |
| 96 | , fHeight(height) |
| 97 | , fSampleCnt(sampleCnt) |
| 98 | , fStencilBits(stencilBits) |
| 99 | , fConfig(config) |
| 100 | , fBackend(kOpenGL_GrBackend) |
| 101 | , fGLInfo(glInfo) {} |
| 102 | |
| 103 | GrBackendRenderTarget::GrBackendRenderTarget(const GrBackendRenderTargetDesc& desc, |
| 104 | GrBackend backend) |
| 105 | : fWidth(desc.fWidth) |
| 106 | , fHeight(desc.fHeight) |
| 107 | , fSampleCnt(desc.fSampleCnt) |
| 108 | , fStencilBits(desc.fStencilBits) |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 109 | , fConfig(desc.fConfig) |
| 110 | , fBackend(backend) { |
| 111 | if (kOpenGL_GrBackend == backend) { |
Greg Daniel | 6125efd | 2017-05-01 13:04:22 -0400 | [diff] [blame] | 112 | fGLInfo.fFBOID = static_cast<GrGLuint>(desc.fRenderTargetHandle); |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 113 | } else { |
| 114 | SkASSERT(kVulkan_GrBackend == backend); |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 115 | #ifdef SK_VULKAN |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 116 | const GrVkImageInfo* vkInfo = |
| 117 | reinterpret_cast<const GrVkImageInfo*>(desc.fRenderTargetHandle); |
| 118 | fConfig = GrVkFormatToPixelConfig(vkInfo->fFormat); |
| 119 | fVkInfo = *vkInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 120 | #else |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 121 | fConfig = kUnknown_GrPixelConfig; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 122 | #endif |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 125 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 126 | #ifdef SK_VULKAN |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 127 | const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const { |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 128 | if (kVulkan_GrBackend == fBackend) { |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 129 | return &fVkInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 130 | } |
| 131 | return nullptr; |
| 132 | } |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 133 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 134 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 135 | const GrGLFramebufferInfo* GrBackendRenderTarget::getGLFramebufferInfo() const { |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 136 | if (kOpenGL_GrBackend == fBackend) { |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 137 | return &fGLInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 138 | } |
| 139 | return nullptr; |
| 140 | } |
| 141 | |