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 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 15 | GrBackendTexture::GrBackendTexture(int width, |
| 16 | int height, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 17 | const GrVkImageInfo* vkInfo) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 18 | : fWidth(width) |
| 19 | , fHeight(height) |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 20 | , fConfig( |
| 21 | #ifdef SK_VULKAN |
| 22 | GrVkFormatToPixelConfig(vkInfo->fFormat) |
| 23 | #else |
| 24 | kUnknown_GrPixelConfig |
| 25 | #endif |
| 26 | ) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 27 | , fBackend(kVulkan_GrBackend) |
| 28 | , fVkInfo(vkInfo) {} |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 29 | |
| 30 | GrBackendTexture::GrBackendTexture(int width, |
| 31 | int height, |
| 32 | GrPixelConfig config, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 33 | const GrGLTextureInfo* glInfo) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 34 | : fWidth(width) |
| 35 | , fHeight(height) |
| 36 | , fConfig(config) |
| 37 | , fBackend(kOpenGL_GrBackend) |
| 38 | , fGLInfo(glInfo) {} |
| 39 | |
| 40 | GrBackendTexture::GrBackendTexture(const GrBackendTextureDesc& desc, GrBackend backend) |
| 41 | : fWidth(desc.fWidth) |
| 42 | , fHeight(desc.fHeight) |
| 43 | , fConfig(kVulkan_GrBackend == backend |
| 44 | #ifdef SK_VULKAN |
| 45 | ? GrVkFormatToPixelConfig(((GrVkImageInfo*)desc.fTextureHandle)->fFormat) |
| 46 | #else |
| 47 | ? kUnknown_GrPixelConfig |
| 48 | #endif |
| 49 | : desc.fConfig) |
| 50 | , fBackend(backend) |
| 51 | , fHandle(desc.fTextureHandle) {} |
| 52 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 53 | const GrVkImageInfo* GrBackendTexture::getVkImageInfo() const { |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 54 | if (kVulkan_GrBackend == fBackend) { |
| 55 | return fVkInfo; |
| 56 | } |
| 57 | return nullptr; |
| 58 | } |
| 59 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 60 | const GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() const { |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 61 | if (kOpenGL_GrBackend == fBackend) { |
| 62 | return fGLInfo; |
| 63 | } |
| 64 | return nullptr; |
| 65 | } |
| 66 | |
| 67 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 68 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 69 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 70 | int height, |
| 71 | int sampleCnt, |
| 72 | int stencilBits, |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 73 | const GrVkImageInfo& vkInfo) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 74 | : fWidth(width) |
| 75 | , fHeight(height) |
| 76 | , fSampleCnt(sampleCnt) |
| 77 | , fStencilBits(stencilBits) |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 78 | , fConfig( |
| 79 | #ifdef SK_VULKAN |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 80 | GrVkFormatToPixelConfig(vkInfo.fFormat) |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 81 | #else |
| 82 | kUnknown_GrPixelConfig |
| 83 | #endif |
| 84 | ) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 85 | , fBackend(kVulkan_GrBackend) |
| 86 | , fVkInfo(vkInfo) {} |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 87 | |
| 88 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 89 | int height, |
| 90 | int sampleCnt, |
| 91 | int stencilBits, |
| 92 | GrPixelConfig config, |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 93 | const GrGLFramebufferInfo& glInfo) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 94 | : fWidth(width) |
| 95 | , fHeight(height) |
| 96 | , fSampleCnt(sampleCnt) |
| 97 | , fStencilBits(stencilBits) |
| 98 | , fConfig(config) |
| 99 | , fBackend(kOpenGL_GrBackend) |
| 100 | , fGLInfo(glInfo) {} |
| 101 | |
| 102 | GrBackendRenderTarget::GrBackendRenderTarget(const GrBackendRenderTargetDesc& desc, |
| 103 | GrBackend backend) |
| 104 | : fWidth(desc.fWidth) |
| 105 | , fHeight(desc.fHeight) |
| 106 | , fSampleCnt(desc.fSampleCnt) |
| 107 | , fStencilBits(desc.fStencilBits) |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 108 | , fConfig(desc.fConfig) |
| 109 | , fBackend(backend) { |
| 110 | if (kOpenGL_GrBackend == backend) { |
| 111 | fGLInfo = *reinterpret_cast<const GrGLFramebufferInfo*>(desc.fRenderTargetHandle); |
| 112 | } else { |
| 113 | SkASSERT(kVulkan_GrBackend == backend); |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 114 | #ifdef SK_VULKAN |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 115 | const GrVkImageInfo* vkInfo = |
| 116 | reinterpret_cast<const GrVkImageInfo*>(desc.fRenderTargetHandle); |
| 117 | fConfig = GrVkFormatToPixelConfig(vkInfo->fFormat); |
| 118 | fVkInfo = *vkInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 119 | #else |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 120 | fConfig = kUnknown_GrPixelConfig; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 121 | #endif |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 122 | } |
| 123 | } |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 124 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 125 | const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const { |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 126 | if (kVulkan_GrBackend == fBackend) { |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 127 | return &fVkInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 128 | } |
| 129 | return nullptr; |
| 130 | } |
| 131 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 132 | const GrGLFramebufferInfo* GrBackendRenderTarget::getGLFramebufferInfo() const { |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 133 | if (kOpenGL_GrBackend == fBackend) { |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 134 | return &fGLInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 135 | } |
| 136 | return nullptr; |
| 137 | } |
| 138 | |