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 | |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 10 | #include "gl/GrGLUtil.h" |
| 11 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 12 | #ifdef SK_VULKAN |
| 13 | #include "vk/GrVkTypes.h" |
| 14 | #include "vk/GrVkUtil.h" |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 15 | #endif |
| 16 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 17 | GrBackendFormat::GrBackendFormat(GrGLenum format, GrGLenum target) |
| 18 | : fBackend(kOpenGL_GrBackend) |
| 19 | , fValid(true) { |
| 20 | fGL.fTarget = target; |
| 21 | fGL.fFormat = format; |
| 22 | } |
| 23 | |
| 24 | const GrGLenum* GrBackendFormat::getGLFormat() const { |
| 25 | if (this->isValid() && kOpenGL_GrBackend == fBackend) { |
| 26 | return &fGL.fFormat; |
| 27 | } |
| 28 | return nullptr; |
| 29 | } |
| 30 | |
| 31 | const GrGLenum* GrBackendFormat::getGLTarget() const { |
| 32 | if (this->isValid() && kOpenGL_GrBackend == fBackend) { |
| 33 | return &fGL.fTarget; |
| 34 | } |
| 35 | return nullptr; |
| 36 | } |
| 37 | |
| 38 | #ifdef SK_VULKAN |
| 39 | GrBackendFormat::GrBackendFormat(VkFormat vkFormat) |
| 40 | : fBackend(kVulkan_GrBackend) |
| 41 | , fValid(true) |
| 42 | , fVkFormat(vkFormat) { |
| 43 | } |
| 44 | |
| 45 | const VkFormat* GrBackendFormat::getVkFormat() const { |
| 46 | if (this->isValid() && kVulkan_GrBackend == fBackend) { |
| 47 | return &fVkFormat; |
| 48 | } |
| 49 | return nullptr; |
| 50 | } |
| 51 | #endif |
| 52 | |
| 53 | GrBackendFormat::GrBackendFormat(GrPixelConfig config) |
| 54 | : fBackend(kMock_GrBackend) |
| 55 | , fValid(true) |
| 56 | , fMockFormat(config) { |
| 57 | } |
| 58 | |
| 59 | const GrPixelConfig* GrBackendFormat::getMockFormat() const { |
| 60 | if (this->isValid() && kMock_GrBackend == fBackend) { |
| 61 | return &fMockFormat; |
| 62 | } |
| 63 | return nullptr; |
| 64 | } |
| 65 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 66 | #ifdef SK_VULKAN |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 67 | GrBackendTexture::GrBackendTexture(int width, |
| 68 | int height, |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 69 | const GrVkImageInfo& vkInfo) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 70 | : fWidth(width) |
| 71 | , fHeight(height) |
Greg Daniel | 8a3f55c | 2018-03-14 17:32:12 +0000 | [diff] [blame] | 72 | , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat)) |
Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 73 | , fMipMapped(GrMipMapped(vkInfo.fLevelCount > 1)) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 74 | , fBackend(kVulkan_GrBackend) |
| 75 | , fVkInfo(vkInfo) {} |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 76 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 77 | |
| 78 | GrBackendTexture::GrBackendTexture(int width, |
| 79 | int height, |
| 80 | GrPixelConfig config, |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 81 | const GrGLTextureInfo& glInfo) |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 82 | : GrBackendTexture(width, height, config, GrMipMapped::kNo, glInfo) {} |
| 83 | |
| 84 | GrBackendTexture::GrBackendTexture(int width, |
| 85 | int height, |
| 86 | GrPixelConfig config, |
| 87 | GrMipMapped mipMapped, |
| 88 | const GrGLTextureInfo& glInfo) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 89 | : fWidth(width) |
| 90 | , fHeight(height) |
| 91 | , fConfig(config) |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 92 | , fMipMapped(mipMapped) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 93 | , fBackend(kOpenGL_GrBackend) |
| 94 | , fGLInfo(glInfo) {} |
| 95 | |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 96 | GrBackendTexture::GrBackendTexture(int width, |
| 97 | int height, |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 98 | GrMipMapped mipMapped, |
| 99 | const GrGLTextureInfo& glInfo) |
| 100 | : fWidth(width) |
| 101 | , fHeight(height) |
Greg Daniel | 8a3f55c | 2018-03-14 17:32:12 +0000 | [diff] [blame] | 102 | , fConfig(GrGLSizedFormatToPixelConfig(glInfo.fFormat)) |
Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 103 | , fMipMapped(mipMapped) |
| 104 | , fBackend(kOpenGL_GrBackend) |
| 105 | , fGLInfo(glInfo) {} |
| 106 | |
| 107 | GrBackendTexture::GrBackendTexture(int width, |
| 108 | int height, |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 109 | GrMipMapped mipMapped, |
| 110 | const GrMockTextureInfo& mockInfo) |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 111 | : fWidth(width) |
| 112 | , fHeight(height) |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 113 | , fConfig(mockInfo.fConfig) |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 114 | , fMipMapped(mipMapped) |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 115 | , fBackend(kMock_GrBackend) |
| 116 | , fMockInfo(mockInfo) {} |
| 117 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 118 | #ifdef SK_VULKAN |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 119 | const GrVkImageInfo* GrBackendTexture::getVkImageInfo() const { |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 120 | if (this->isValid() && kVulkan_GrBackend == fBackend) { |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 121 | return &fVkInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 122 | } |
| 123 | return nullptr; |
| 124 | } |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 125 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 126 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 127 | const GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() const { |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 128 | if (this->isValid() && kOpenGL_GrBackend == fBackend) { |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 129 | return &fGLInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 130 | } |
| 131 | return nullptr; |
| 132 | } |
| 133 | |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 134 | const GrMockTextureInfo* GrBackendTexture::getMockTextureInfo() const { |
| 135 | if (this->isValid() && kMock_GrBackend == fBackend) { |
| 136 | return &fMockInfo; |
| 137 | } |
| 138 | return nullptr; |
| 139 | } |
| 140 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 141 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 142 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 143 | #ifdef SK_VULKAN |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 144 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 145 | int height, |
| 146 | int sampleCnt, |
| 147 | int stencilBits, |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 148 | const GrVkImageInfo& vkInfo) |
Brian Salomon | afdc6b1 | 2018-03-09 12:02:32 -0500 | [diff] [blame] | 149 | : GrBackendRenderTarget(width, height, sampleCnt, vkInfo) { |
| 150 | // This is a deprecated constructor that takes a bogus stencil bits. |
| 151 | SkASSERT(0 == stencilBits); |
| 152 | } |
| 153 | |
| 154 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 155 | int height, |
| 156 | int sampleCnt, |
| 157 | const GrVkImageInfo& vkInfo) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 158 | : fWidth(width) |
| 159 | , fHeight(height) |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 160 | , fSampleCnt(SkTMax(1, sampleCnt)) |
Brian Salomon | afdc6b1 | 2018-03-09 12:02:32 -0500 | [diff] [blame] | 161 | , fStencilBits(0) // We always create stencil buffers internally for vulkan |
Greg Daniel | 8a3f55c | 2018-03-14 17:32:12 +0000 | [diff] [blame] | 162 | , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat)) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 163 | , fBackend(kVulkan_GrBackend) |
| 164 | , fVkInfo(vkInfo) {} |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 165 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 166 | |
| 167 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 168 | int height, |
| 169 | int sampleCnt, |
| 170 | int stencilBits, |
| 171 | GrPixelConfig config, |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 172 | const GrGLFramebufferInfo& glInfo) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 173 | : fWidth(width) |
| 174 | , fHeight(height) |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 175 | , fSampleCnt(SkTMax(1, sampleCnt)) |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 176 | , fStencilBits(stencilBits) |
| 177 | , fConfig(config) |
| 178 | , fBackend(kOpenGL_GrBackend) |
| 179 | , fGLInfo(glInfo) {} |
| 180 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 181 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 182 | int height, |
| 183 | int sampleCnt, |
| 184 | int stencilBits, |
| 185 | const GrGLFramebufferInfo& glInfo) |
| 186 | : fWidth(width) |
| 187 | , fHeight(height) |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 188 | , fSampleCnt(SkTMax(1, sampleCnt)) |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 189 | , fStencilBits(stencilBits) |
Greg Daniel | 8a3f55c | 2018-03-14 17:32:12 +0000 | [diff] [blame] | 190 | , fConfig(GrGLSizedFormatToPixelConfig(glInfo.fFormat)) |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 191 | , fBackend(kOpenGL_GrBackend) |
| 192 | , fGLInfo(glInfo) {} |
| 193 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 194 | GrBackendRenderTarget::GrBackendRenderTarget(int width, |
| 195 | int height, |
| 196 | int sampleCnt, |
| 197 | int stencilBits, |
| 198 | const GrMockRenderTargetInfo& mockInfo) |
| 199 | : fWidth(width) |
| 200 | , fHeight(height) |
| 201 | , fSampleCnt(SkTMax(1, sampleCnt)) |
| 202 | , fStencilBits(stencilBits) |
| 203 | , fConfig(mockInfo.fConfig) |
| 204 | , fMockInfo(mockInfo) {} |
| 205 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 206 | #ifdef SK_VULKAN |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 207 | const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const { |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 208 | if (kVulkan_GrBackend == fBackend) { |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 209 | return &fVkInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 210 | } |
| 211 | return nullptr; |
| 212 | } |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 213 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 214 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 215 | const GrGLFramebufferInfo* GrBackendRenderTarget::getGLFramebufferInfo() const { |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 216 | if (kOpenGL_GrBackend == fBackend) { |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 217 | return &fGLInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 218 | } |
| 219 | return nullptr; |
| 220 | } |
| 221 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 222 | const GrMockRenderTargetInfo* GrBackendRenderTarget::getMockRenderTargetInfo() const { |
| 223 | if (kMock_GrBackend == fBackend) { |
| 224 | return &fMockInfo; |
| 225 | } |
| 226 | return nullptr; |
| 227 | } |