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 #include "gl/GrGLUtil.h"
11
12 #ifdef SK_VULKAN
13 #include "vk/GrVkTypes.h"
14 #include "vk/GrVkUtil.h"
15 #endif
16
GrBackendFormat(GrGLenum format,GrGLenum target)17 GrBackendFormat::GrBackendFormat(GrGLenum format, GrGLenum target)
18 : fBackend(kOpenGL_GrBackend)
19 , fValid(true) {
20 fGL.fTarget = target;
21 fGL.fFormat = format;
22 }
23
getGLFormat() const24 const GrGLenum* GrBackendFormat::getGLFormat() const {
25 if (this->isValid() && kOpenGL_GrBackend == fBackend) {
26 return &fGL.fFormat;
27 }
28 return nullptr;
29 }
30
getGLTarget() const31 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
GrBackendFormat(VkFormat vkFormat)39 GrBackendFormat::GrBackendFormat(VkFormat vkFormat)
40 : fBackend(kVulkan_GrBackend)
41 , fValid(true)
42 , fVkFormat(vkFormat) {
43 }
44
getVkFormat() const45 const VkFormat* GrBackendFormat::getVkFormat() const {
46 if (this->isValid() && kVulkan_GrBackend == fBackend) {
47 return &fVkFormat;
48 }
49 return nullptr;
50 }
51 #endif
52
GrBackendFormat(GrPixelConfig config)53 GrBackendFormat::GrBackendFormat(GrPixelConfig config)
54 : fBackend(kMock_GrBackend)
55 , fValid(true)
56 , fMockFormat(config) {
57 }
58
getMockFormat() const59 const GrPixelConfig* GrBackendFormat::getMockFormat() const {
60 if (this->isValid() && kMock_GrBackend == fBackend) {
61 return &fMockFormat;
62 }
63 return nullptr;
64 }
65
66 #ifdef SK_VULKAN
GrBackendTexture(int width,int height,const GrVkImageInfo & vkInfo)67 GrBackendTexture::GrBackendTexture(int width,
68 int height,
69 const GrVkImageInfo& vkInfo)
70 : fWidth(width)
71 , fHeight(height)
72 , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat))
73 , fMipMapped(GrMipMapped(vkInfo.fLevelCount > 1))
74 , fBackend(kVulkan_GrBackend)
75 , fVkInfo(vkInfo) {}
76 #endif
77
GrBackendTexture(int width,int height,GrPixelConfig config,const GrGLTextureInfo & glInfo)78 GrBackendTexture::GrBackendTexture(int width,
79 int height,
80 GrPixelConfig config,
81 const GrGLTextureInfo& glInfo)
82 : GrBackendTexture(width, height, config, GrMipMapped::kNo, glInfo) {}
83
GrBackendTexture(int width,int height,GrPixelConfig config,GrMipMapped mipMapped,const GrGLTextureInfo & glInfo)84 GrBackendTexture::GrBackendTexture(int width,
85 int height,
86 GrPixelConfig config,
87 GrMipMapped mipMapped,
88 const GrGLTextureInfo& glInfo)
89 : fWidth(width)
90 , fHeight(height)
91 , fConfig(config)
92 , fMipMapped(mipMapped)
93 , fBackend(kOpenGL_GrBackend)
94 , fGLInfo(glInfo) {}
95
GrBackendTexture(int width,int height,GrMipMapped mipMapped,const GrGLTextureInfo & glInfo)96 GrBackendTexture::GrBackendTexture(int width,
97 int height,
98 GrMipMapped mipMapped,
99 const GrGLTextureInfo& glInfo)
100 : fWidth(width)
101 , fHeight(height)
102 , fConfig(GrGLSizedFormatToPixelConfig(glInfo.fFormat))
103 , fMipMapped(mipMapped)
104 , fBackend(kOpenGL_GrBackend)
105 , fGLInfo(glInfo) {}
106
GrBackendTexture(int width,int height,GrPixelConfig config,const GrMockTextureInfo & mockInfo)107 GrBackendTexture::GrBackendTexture(int width,
108 int height,
109 GrPixelConfig config,
110 const GrMockTextureInfo& mockInfo)
111 : GrBackendTexture(width, height, config, GrMipMapped::kNo, mockInfo) {}
112
GrBackendTexture(int width,int height,GrPixelConfig config,GrMipMapped mipMapped,const GrMockTextureInfo & mockInfo)113 GrBackendTexture::GrBackendTexture(int width,
114 int height,
115 GrPixelConfig config,
116 GrMipMapped mipMapped,
117 const GrMockTextureInfo& mockInfo)
118 : fWidth(width)
119 , fHeight(height)
120 , fConfig(config)
121 , fMipMapped(mipMapped)
122 , fBackend(kMock_GrBackend)
123 , fMockInfo(mockInfo) {}
124
125 #ifdef SK_VULKAN
getVkImageInfo() const126 const GrVkImageInfo* GrBackendTexture::getVkImageInfo() const {
127 if (this->isValid() && kVulkan_GrBackend == fBackend) {
128 return &fVkInfo;
129 }
130 return nullptr;
131 }
132 #endif
133
getGLTextureInfo() const134 const GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() const {
135 if (this->isValid() && kOpenGL_GrBackend == fBackend) {
136 return &fGLInfo;
137 }
138 return nullptr;
139 }
140
getMockTextureInfo() const141 const GrMockTextureInfo* GrBackendTexture::getMockTextureInfo() const {
142 if (this->isValid() && kMock_GrBackend == fBackend) {
143 return &fMockInfo;
144 }
145 return nullptr;
146 }
147
148 ////////////////////////////////////////////////////////////////////////////////////////////////////
149
150 #ifdef SK_VULKAN
GrBackendRenderTarget(int width,int height,int sampleCnt,int stencilBits,const GrVkImageInfo & vkInfo)151 GrBackendRenderTarget::GrBackendRenderTarget(int width,
152 int height,
153 int sampleCnt,
154 int stencilBits,
155 const GrVkImageInfo& vkInfo)
156 : fWidth(width)
157 , fHeight(height)
158 , fSampleCnt(SkTMax(1, sampleCnt))
159 , fStencilBits(stencilBits)
160 , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat))
161 , fBackend(kVulkan_GrBackend)
162 , fVkInfo(vkInfo) {}
163 #endif
164
GrBackendRenderTarget(int width,int height,int sampleCnt,int stencilBits,GrPixelConfig config,const GrGLFramebufferInfo & glInfo)165 GrBackendRenderTarget::GrBackendRenderTarget(int width,
166 int height,
167 int sampleCnt,
168 int stencilBits,
169 GrPixelConfig config,
170 const GrGLFramebufferInfo& glInfo)
171 : fWidth(width)
172 , fHeight(height)
173 , fSampleCnt(SkTMax(1, sampleCnt))
174 , fStencilBits(stencilBits)
175 , fConfig(config)
176 , fBackend(kOpenGL_GrBackend)
177 , fGLInfo(glInfo) {}
178
GrBackendRenderTarget(int width,int height,int sampleCnt,int stencilBits,const GrGLFramebufferInfo & glInfo)179 GrBackendRenderTarget::GrBackendRenderTarget(int width,
180 int height,
181 int sampleCnt,
182 int stencilBits,
183 const GrGLFramebufferInfo& glInfo)
184 : fWidth(width)
185 , fHeight(height)
186 , fSampleCnt(SkTMax(1, sampleCnt))
187 , fStencilBits(stencilBits)
188 , fConfig(GrGLSizedFormatToPixelConfig(glInfo.fFormat))
189 , fBackend(kOpenGL_GrBackend)
190 , fGLInfo(glInfo) {}
191
192 #ifdef SK_VULKAN
getVkImageInfo() const193 const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const {
194 if (kVulkan_GrBackend == fBackend) {
195 return &fVkInfo;
196 }
197 return nullptr;
198 }
199 #endif
200
getGLFramebufferInfo() const201 const GrGLFramebufferInfo* GrBackendRenderTarget::getGLFramebufferInfo() const {
202 if (kOpenGL_GrBackend == fBackend) {
203 return &fGLInfo;
204 }
205 return nullptr;
206 }
207
208