blob: 4cc6da3566815b0e66e550f8286e856a4d61c5aa [file] [log] [blame]
Greg Daniel94403452017-04-18 15:52:36 -04001/*
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 Danielbcf612b2017-05-01 13:50:58 +000012#include "gl/GrGLTypes.h"
Brian Salomon8fe24272017-07-07 12:56:11 -040013#include "mock/GrMockTypes.h"
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000014
15#ifdef SK_VULKAN
Greg Danielbcf612b2017-05-01 13:50:58 +000016#include "vk/GrVkTypes.h"
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000017#endif
Greg Daniel94403452017-04-18 15:52:36 -040018
Brian Salomonec045b42017-07-07 10:34:40 -040019class SK_API GrBackendTexture {
Greg Daniel94403452017-04-18 15:52:36 -040020public:
Brian Salomon8fe24272017-07-07 12:56:11 -040021 // Creates an invalid backend texture.
22 GrBackendTexture() : fConfig(kUnknown_GrPixelConfig) {}
23
Greg Daniele7d8da42017-12-04 11:23:19 -050024 // GrGLTextureInfo::fFormat is ignored
25 // Deprecated: Should use version that does not take a GrPixelConfig instead
Greg Daniel94403452017-04-18 15:52:36 -040026 GrBackendTexture(int width,
27 int height,
Robert Phillipsfad9e3f2017-06-13 22:16:08 +000028 GrPixelConfig config,
29 const GrGLTextureInfo& glInfo);
Greg Danielc0f8e422017-06-13 13:47:53 -040030
Greg Daniele7d8da42017-12-04 11:23:19 -050031 // GrGLTextureInfo::fFormat is ignored
32 // Deprecated: Should use version that does not take a GrPixelConfig instead
Greg Daniel177e6952017-10-12 12:27:11 -040033 GrBackendTexture(int width,
34 int height,
35 GrPixelConfig config,
36 GrMipMapped,
37 const GrGLTextureInfo& glInfo);
38
Greg Daniele7d8da42017-12-04 11:23:19 -050039 // The GrGLTextureInfo must have a valid fFormat.
40 GrBackendTexture(int width,
41 int height,
42 GrMipMapped,
43 const GrGLTextureInfo& glInfo);
44
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000045#ifdef SK_VULKAN
46 GrBackendTexture(int width,
47 int height,
48 const GrVkImageInfo& vkInfo);
49#endif
50
Brian Salomon8fe24272017-07-07 12:56:11 -040051 GrBackendTexture(int width,
52 int height,
53 GrPixelConfig config,
54 const GrMockTextureInfo& mockInfo);
55
Greg Daniel177e6952017-10-12 12:27:11 -040056 GrBackendTexture(int width,
57 int height,
58 GrPixelConfig config,
59 GrMipMapped,
60 const GrMockTextureInfo& mockInfo);
61
Greg Daniel94403452017-04-18 15:52:36 -040062 int width() const { return fWidth; }
63 int height() const { return fHeight; }
Greg Daniel177e6952017-10-12 12:27:11 -040064 bool hasMipMaps() const { return GrMipMapped::kYes == fMipMapped; }
Greg Daniel94403452017-04-18 15:52:36 -040065 GrBackend backend() const {return fBackend; }
66
Robert Phillipsfad9e3f2017-06-13 22:16:08 +000067 // 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 Danielc0f8e422017-06-13 13:47:53 -040070
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000071#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 Salomon8fe24272017-07-07 12:56:11 -040077 // 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 Karl914a36b2017-10-12 12:44:50 -070081 // Returns true if the backend texture has been initialized.
Brian Salomon8fe24272017-07-07 12:56:11 -040082 bool isValid() const { return fConfig != kUnknown_GrPixelConfig; }
83
Eric Karl914a36b2017-10-12 12:44:50 -070084private:
Greg Daniel5254ccc2017-11-13 11:05:52 -050085 // Friending for access to the GrPixelConfig
Greg Danielfaa095e2017-12-19 13:15:02 -050086 friend class SkImage;
Greg Daniel5254ccc2017-11-13 11:05:52 -050087 friend class SkSurface;
Greg Daniele728f672018-01-17 10:52:04 -050088 friend class GrBackendTextureImageGenerator;
Greg Daniel5254ccc2017-11-13 11:05:52 -050089 friend class GrGpu;
90 friend class GrGLGpu;
91 friend class GrVkGpu;
92 GrPixelConfig config() const { return fConfig; }
93
Greg Daniel94403452017-04-18 15:52:36 -040094 int fWidth; //<! width in pixels
95 int fHeight; //<! height in pixels
96 GrPixelConfig fConfig;
Greg Daniel177e6952017-10-12 12:27:11 -040097 GrMipMapped fMipMapped;
Greg Daniel94403452017-04-18 15:52:36 -040098 GrBackend fBackend;
99
100 union {
Robert Phillipsfad9e3f2017-06-13 22:16:08 +0000101 GrGLTextureInfo fGLInfo;
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000102#ifdef SK_VULKAN
103 GrVkImageInfo fVkInfo;
104#endif
Brian Salomon8fe24272017-07-07 12:56:11 -0400105 GrMockTextureInfo fMockInfo;
Greg Daniel94403452017-04-18 15:52:36 -0400106 };
107};
108
Brian Salomonec045b42017-07-07 10:34:40 -0400109class SK_API GrBackendRenderTarget {
Greg Daniel94403452017-04-18 15:52:36 -0400110public:
Robert Phillips57e08282017-11-16 14:59:48 -0500111 // Creates an invalid backend texture.
112 GrBackendRenderTarget() : fConfig(kUnknown_GrPixelConfig) {}
113
Greg Danielfaa095e2017-12-19 13:15:02 -0500114 // GrGLTextureInfo::fFormat is ignored
115 // Deprecated: Should use version that does not take a GrPixelConfig instead
Greg Daniel94403452017-04-18 15:52:36 -0400116 GrBackendRenderTarget(int width,
117 int height,
118 int sampleCnt,
119 int stencilBits,
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000120 GrPixelConfig config,
121 const GrGLFramebufferInfo& glInfo);
Greg Daniel94403452017-04-18 15:52:36 -0400122
Greg Danielfaa095e2017-12-19 13:15:02 -0500123 // 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 Phillipsfcd5fdd2017-06-14 01:43:29 +0000130#ifdef SK_VULKAN
Greg Daniel94403452017-04-18 15:52:36 -0400131 GrBackendRenderTarget(int width,
132 int height,
133 int sampleCnt,
134 int stencilBits,
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000135 const GrVkImageInfo& vkInfo);
136#endif
Greg Daniel94403452017-04-18 15:52:36 -0400137
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 Daniel94403452017-04-18 15:52:36 -0400142 GrBackend backend() const {return fBackend; }
143
Robert Phillipsfad9e3f2017-06-13 22:16:08 +0000144 // 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 Danielc0f8e422017-06-13 13:47:53 -0400147
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000148#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 Phillips57e08282017-11-16 14:59:48 -0500154 // Returns true if the backend texture has been initialized.
155 bool isValid() const { return fConfig != kUnknown_GrPixelConfig; }
156
Greg Daniel94403452017-04-18 15:52:36 -0400157private:
Greg Daniel5254ccc2017-11-13 11:05:52 -0500158 // Friending for access to the GrPixelConfig
159 friend class SkSurface;
Greg Danielfaa095e2017-12-19 13:15:02 -0500160 friend class SkSurface_Gpu;
161 friend class SkImage_Gpu;
Greg Daniel5254ccc2017-11-13 11:05:52 -0500162 friend class GrGpu;
163 friend class GrGLGpu;
164 friend class GrVkGpu;
165 GrPixelConfig config() const { return fConfig; }
166
Greg Daniel94403452017-04-18 15:52:36 -0400167 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 Phillipsfad9e3f2017-06-13 22:16:08 +0000177 GrGLFramebufferInfo fGLInfo;
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000178#ifdef SK_VULKAN
179 GrVkImageInfo fVkInfo;
180#endif
Greg Daniel94403452017-04-18 15:52:36 -0400181 };
182};
183
184#endif
185