| 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 | #ifndef GrBackendSurface_DEFINED |
| 9 | #define GrBackendSurface_DEFINED |
| 10 | |
| 11 | #include "GrTypes.h" |
| Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 12 | #include "gl/GrGLTypes.h" |
| Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 13 | #include "mock/GrMockTypes.h" |
| Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 14 | |
| 15 | #ifdef SK_VULKAN |
| Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 16 | #include "vk/GrVkTypes.h" |
| Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 17 | #endif |
| Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 18 | |
| Brian Salomon | ec045b4 | 2017-07-07 10:34:40 -0400 | [diff] [blame] | 19 | class SK_API GrBackendTexture { |
| Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 20 | public: |
| Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 21 | // Creates an invalid backend texture. |
| 22 | GrBackendTexture() : fConfig(kUnknown_GrPixelConfig) {} |
| 23 | |
| Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 24 | // GrGLTextureInfo::fFormat is ignored |
| 25 | // Deprecated: Should use version that does not take a GrPixelConfig instead |
| Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 26 | GrBackendTexture(int width, |
| 27 | int height, |
| Robert Phillips | fad9e3f | 2017-06-13 22:16:08 +0000 | [diff] [blame] | 28 | GrPixelConfig config, |
| 29 | const GrGLTextureInfo& glInfo); |
| Greg Daniel | c0f8e42 | 2017-06-13 13:47:53 -0400 | [diff] [blame] | 30 | |
| Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 31 | // GrGLTextureInfo::fFormat is ignored |
| 32 | // Deprecated: Should use version that does not take a GrPixelConfig instead |
| Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 33 | GrBackendTexture(int width, |
| 34 | int height, |
| 35 | GrPixelConfig config, |
| 36 | GrMipMapped, |
| 37 | const GrGLTextureInfo& glInfo); |
| 38 | |
| Greg Daniel | e7d8da4 | 2017-12-04 11:23:19 -0500 | [diff] [blame] | 39 | // The GrGLTextureInfo must have a valid fFormat. |
| 40 | GrBackendTexture(int width, |
| 41 | int height, |
| 42 | GrMipMapped, |
| 43 | const GrGLTextureInfo& glInfo); |
| 44 | |
| Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 45 | #ifdef SK_VULKAN |
| 46 | GrBackendTexture(int width, |
| 47 | int height, |
| 48 | const GrVkImageInfo& vkInfo); |
| 49 | #endif |
| 50 | |
| Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 51 | GrBackendTexture(int width, |
| 52 | int height, |
| 53 | GrPixelConfig config, |
| 54 | const GrMockTextureInfo& mockInfo); |
| 55 | |
| Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 56 | GrBackendTexture(int width, |
| 57 | int height, |
| 58 | GrPixelConfig config, |
| 59 | GrMipMapped, |
| 60 | const GrMockTextureInfo& mockInfo); |
| 61 | |
| Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 62 | int width() const { return fWidth; } |
| 63 | int height() const { return fHeight; } |
| Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 64 | bool hasMipMaps() const { return GrMipMapped::kYes == fMipMapped; } |
| Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 65 | GrBackend backend() const {return fBackend; } |
| 66 | |
| Robert Phillips | fad9e3f | 2017-06-13 22:16:08 +0000 | [diff] [blame] | 67 | // If the backend API is GL, this returns a pointer to the GrGLTextureInfo struct. Otherwise |
| 68 | // it returns nullptr. |
| 69 | const GrGLTextureInfo* getGLTextureInfo() const; |
| Greg Daniel | c0f8e42 | 2017-06-13 13:47:53 -0400 | [diff] [blame] | 70 | |
| Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 71 | #ifdef SK_VULKAN |
| 72 | // If the backend API is Vulkan, this returns a pointer to the GrVkImageInfo struct. Otherwise |
| 73 | // it returns nullptr. |
| 74 | const GrVkImageInfo* getVkImageInfo() const; |
| 75 | #endif |
| 76 | |
| Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 77 | // If the backend API is Mock, this returns a pointer to the GrMockTextureInfo struct. Otherwise |
| 78 | // it returns nullptr. |
| 79 | const GrMockTextureInfo* getMockTextureInfo() const; |
| 80 | |
| Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 81 | // Returns true if the backend texture has been initialized. |
| Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 82 | bool isValid() const { return fConfig != kUnknown_GrPixelConfig; } |
| 83 | |
| Eric Karl | 914a36b | 2017-10-12 12:44:50 -0700 | [diff] [blame] | 84 | private: |
| Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 85 | // Friending for access to the GrPixelConfig |
| Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 86 | friend class SkImage; |
| Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 87 | friend class SkSurface; |
| Greg Daniel | e728f67 | 2018-01-17 10:52:04 -0500 | [diff] [blame] | 88 | friend class GrBackendTextureImageGenerator; |
| Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 89 | friend class GrGpu; |
| 90 | friend class GrGLGpu; |
| 91 | friend class GrVkGpu; |
| 92 | GrPixelConfig config() const { return fConfig; } |
| 93 | |
| Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 94 | int fWidth; //<! width in pixels |
| 95 | int fHeight; //<! height in pixels |
| 96 | GrPixelConfig fConfig; |
| Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 97 | GrMipMapped fMipMapped; |
| Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 98 | GrBackend fBackend; |
| 99 | |
| 100 | union { |
| Robert Phillips | fad9e3f | 2017-06-13 22:16:08 +0000 | [diff] [blame] | 101 | GrGLTextureInfo fGLInfo; |
| Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 102 | #ifdef SK_VULKAN |
| 103 | GrVkImageInfo fVkInfo; |
| 104 | #endif |
| Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 105 | GrMockTextureInfo fMockInfo; |
| Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 106 | }; |
| 107 | }; |
| 108 | |
| Brian Salomon | ec045b4 | 2017-07-07 10:34:40 -0400 | [diff] [blame] | 109 | class SK_API GrBackendRenderTarget { |
| Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 110 | public: |
| Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 111 | // Creates an invalid backend texture. |
| 112 | GrBackendRenderTarget() : fConfig(kUnknown_GrPixelConfig) {} |
| 113 | |
| Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 114 | // GrGLTextureInfo::fFormat is ignored |
| 115 | // Deprecated: Should use version that does not take a GrPixelConfig instead |
| Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 116 | GrBackendRenderTarget(int width, |
| 117 | int height, |
| 118 | int sampleCnt, |
| 119 | int stencilBits, |
| Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 120 | GrPixelConfig config, |
| 121 | const GrGLFramebufferInfo& glInfo); |
| Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 122 | |
| Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 123 | // The GrGLTextureInfo must have a valid fFormat. |
| 124 | GrBackendRenderTarget(int width, |
| 125 | int height, |
| 126 | int sampleCnt, |
| 127 | int stencilBits, |
| 128 | const GrGLFramebufferInfo& glInfo); |
| 129 | |
| Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 130 | #ifdef SK_VULKAN |
| Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 131 | GrBackendRenderTarget(int width, |
| 132 | int height, |
| 133 | int sampleCnt, |
| 134 | int stencilBits, |
| Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 135 | const GrVkImageInfo& vkInfo); |
| 136 | #endif |
| Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 137 | |
| 138 | int width() const { return fWidth; } |
| 139 | int height() const { return fHeight; } |
| 140 | int sampleCnt() const { return fSampleCnt; } |
| 141 | int stencilBits() const { return fStencilBits; } |
| Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 142 | GrBackend backend() const {return fBackend; } |
| 143 | |
| Robert Phillips | fad9e3f | 2017-06-13 22:16:08 +0000 | [diff] [blame] | 144 | // If the backend API is GL, this returns a pointer to the GrGLFramebufferInfo struct. Otherwise |
| 145 | // it returns nullptr. |
| 146 | const GrGLFramebufferInfo* getGLFramebufferInfo() const; |
| Greg Daniel | c0f8e42 | 2017-06-13 13:47:53 -0400 | [diff] [blame] | 147 | |
| Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 148 | #ifdef SK_VULKAN |
| 149 | // If the backend API is Vulkan, this returns a pointer to the GrVkImageInfo struct. Otherwise |
| 150 | // it returns nullptr |
| 151 | const GrVkImageInfo* getVkImageInfo() const; |
| 152 | #endif |
| 153 | |
| Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 154 | // Returns true if the backend texture has been initialized. |
| 155 | bool isValid() const { return fConfig != kUnknown_GrPixelConfig; } |
| 156 | |
| Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 157 | private: |
| Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 158 | // Friending for access to the GrPixelConfig |
| 159 | friend class SkSurface; |
| Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 160 | friend class SkSurface_Gpu; |
| 161 | friend class SkImage_Gpu; |
| Greg Daniel | 5254ccc | 2017-11-13 11:05:52 -0500 | [diff] [blame] | 162 | friend class GrGpu; |
| 163 | friend class GrGLGpu; |
| 164 | friend class GrVkGpu; |
| 165 | GrPixelConfig config() const { return fConfig; } |
| 166 | |
| Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 167 | int fWidth; //<! width in pixels |
| 168 | int fHeight; //<! height in pixels |
| 169 | |
| 170 | int fSampleCnt; |
| 171 | int fStencilBits; |
| 172 | GrPixelConfig fConfig; |
| 173 | |
| 174 | GrBackend fBackend; |
| 175 | |
| 176 | union { |
| Robert Phillips | fad9e3f | 2017-06-13 22:16:08 +0000 | [diff] [blame] | 177 | GrGLFramebufferInfo fGLInfo; |
| Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 178 | #ifdef SK_VULKAN |
| 179 | GrVkImageInfo fVkInfo; |
| 180 | #endif |
| Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 181 | }; |
| 182 | }; |
| 183 | |
| 184 | #endif |
| 185 | |