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 | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 24 | GrBackendTexture(int width, |
| 25 | int height, |
Robert Phillips | fad9e3f | 2017-06-13 22:16:08 +0000 | [diff] [blame] | 26 | GrPixelConfig config, |
| 27 | const GrGLTextureInfo& glInfo); |
Greg Daniel | c0f8e42 | 2017-06-13 13:47:53 -0400 | [diff] [blame] | 28 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 29 | #ifdef SK_VULKAN |
| 30 | GrBackendTexture(int width, |
| 31 | int height, |
| 32 | const GrVkImageInfo& vkInfo); |
| 33 | #endif |
| 34 | |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 35 | GrBackendTexture(int width, |
| 36 | int height, |
| 37 | GrPixelConfig config, |
| 38 | const GrMockTextureInfo& mockInfo); |
| 39 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 40 | int width() const { return fWidth; } |
| 41 | int height() const { return fHeight; } |
| 42 | GrPixelConfig config() const { return fConfig; } |
| 43 | GrBackend backend() const {return fBackend; } |
| 44 | |
Robert Phillips | fad9e3f | 2017-06-13 22:16:08 +0000 | [diff] [blame] | 45 | // If the backend API is GL, this returns a pointer to the GrGLTextureInfo struct. Otherwise |
| 46 | // it returns nullptr. |
| 47 | const GrGLTextureInfo* getGLTextureInfo() const; |
Greg Daniel | c0f8e42 | 2017-06-13 13:47:53 -0400 | [diff] [blame] | 48 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 49 | #ifdef SK_VULKAN |
| 50 | // If the backend API is Vulkan, this returns a pointer to the GrVkImageInfo struct. Otherwise |
| 51 | // it returns nullptr. |
| 52 | const GrVkImageInfo* getVkImageInfo() const; |
| 53 | #endif |
| 54 | |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 55 | // If the backend API is Mock, this returns a pointer to the GrMockTextureInfo struct. Otherwise |
| 56 | // it returns nullptr. |
| 57 | const GrMockTextureInfo* getMockTextureInfo() const; |
| 58 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 59 | private: |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 60 | bool isValid() const { return fConfig != kUnknown_GrPixelConfig; } |
| 61 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 62 | int fWidth; //<! width in pixels |
| 63 | int fHeight; //<! height in pixels |
| 64 | GrPixelConfig fConfig; |
| 65 | GrBackend fBackend; |
| 66 | |
| 67 | union { |
Robert Phillips | fad9e3f | 2017-06-13 22:16:08 +0000 | [diff] [blame] | 68 | GrGLTextureInfo fGLInfo; |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 69 | #ifdef SK_VULKAN |
| 70 | GrVkImageInfo fVkInfo; |
| 71 | #endif |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 72 | GrMockTextureInfo fMockInfo; |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 73 | }; |
| 74 | }; |
| 75 | |
Brian Salomon | ec045b4 | 2017-07-07 10:34:40 -0400 | [diff] [blame] | 76 | class SK_API GrBackendRenderTarget { |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 77 | public: |
| 78 | GrBackendRenderTarget(int width, |
| 79 | int height, |
| 80 | int sampleCnt, |
| 81 | int stencilBits, |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 82 | GrPixelConfig config, |
| 83 | const GrGLFramebufferInfo& glInfo); |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 84 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 85 | #ifdef SK_VULKAN |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 86 | GrBackendRenderTarget(int width, |
| 87 | int height, |
| 88 | int sampleCnt, |
| 89 | int stencilBits, |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 90 | const GrVkImageInfo& vkInfo); |
| 91 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 92 | |
| 93 | int width() const { return fWidth; } |
| 94 | int height() const { return fHeight; } |
| 95 | int sampleCnt() const { return fSampleCnt; } |
| 96 | int stencilBits() const { return fStencilBits; } |
| 97 | GrPixelConfig config() const { return fConfig; } |
| 98 | GrBackend backend() const {return fBackend; } |
| 99 | |
Robert Phillips | fad9e3f | 2017-06-13 22:16:08 +0000 | [diff] [blame] | 100 | // If the backend API is GL, this returns a pointer to the GrGLFramebufferInfo struct. Otherwise |
| 101 | // it returns nullptr. |
| 102 | const GrGLFramebufferInfo* getGLFramebufferInfo() const; |
Greg Daniel | c0f8e42 | 2017-06-13 13:47:53 -0400 | [diff] [blame] | 103 | |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 104 | #ifdef SK_VULKAN |
| 105 | // If the backend API is Vulkan, this returns a pointer to the GrVkImageInfo struct. Otherwise |
| 106 | // it returns nullptr |
| 107 | const GrVkImageInfo* getVkImageInfo() const; |
| 108 | #endif |
| 109 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 110 | private: |
Brian Salomon | 807371c | 2017-07-20 20:48:12 +0000 | [diff] [blame] | 111 | // Temporary constructor which can be used to convert from a GrBackendRenderTargetDesc. |
| 112 | GrBackendRenderTarget(const GrBackendRenderTargetDesc& desc, GrBackend backend); |
| 113 | |
| 114 | // Friending for access to above constructor taking a GrBackendRenderTargetDesc |
| 115 | friend class SkSurface; |
| 116 | |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 117 | int fWidth; //<! width in pixels |
| 118 | int fHeight; //<! height in pixels |
| 119 | |
| 120 | int fSampleCnt; |
| 121 | int fStencilBits; |
| 122 | GrPixelConfig fConfig; |
| 123 | |
| 124 | GrBackend fBackend; |
| 125 | |
| 126 | union { |
Robert Phillips | fad9e3f | 2017-06-13 22:16:08 +0000 | [diff] [blame] | 127 | GrGLFramebufferInfo fGLInfo; |
Robert Phillips | fcd5fdd | 2017-06-14 01:43:29 +0000 | [diff] [blame] | 128 | #ifdef SK_VULKAN |
| 129 | GrVkImageInfo fVkInfo; |
| 130 | #endif |
Greg Daniel | 9440345 | 2017-04-18 15:52:36 -0400 | [diff] [blame] | 131 | }; |
| 132 | }; |
| 133 | |
| 134 | #endif |
| 135 | |