blob: fa2582a18ecd0864793d029864813aa7a71769d0 [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#include "GrBackendSurface.h"
9
Greg Daniele7d8da42017-12-04 11:23:19 -050010#include "gl/GrGLUtil.h"
11
Greg Daniel94403452017-04-18 15:52:36 -040012#ifdef SK_VULKAN
13#include "vk/GrVkTypes.h"
14#include "vk/GrVkUtil.h"
Greg Daniel7ef28f32017-04-20 16:41:55 +000015#endif
16
Robert Phillipsfc711a22018-02-13 17:03:00 -050017GrBackendFormat::GrBackendFormat(GrGLenum format, GrGLenum target)
18 : fBackend(kOpenGL_GrBackend)
19 , fValid(true) {
20 fGL.fTarget = target;
21 fGL.fFormat = format;
22}
23
24const GrGLenum* GrBackendFormat::getGLFormat() const {
25 if (this->isValid() && kOpenGL_GrBackend == fBackend) {
26 return &fGL.fFormat;
27 }
28 return nullptr;
29}
30
31const 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
39GrBackendFormat::GrBackendFormat(VkFormat vkFormat)
40 : fBackend(kVulkan_GrBackend)
41 , fValid(true)
42 , fVkFormat(vkFormat) {
43}
44
45const VkFormat* GrBackendFormat::getVkFormat() const {
46 if (this->isValid() && kVulkan_GrBackend == fBackend) {
47 return &fVkFormat;
48 }
49 return nullptr;
50}
51#endif
52
53GrBackendFormat::GrBackendFormat(GrPixelConfig config)
54 : fBackend(kMock_GrBackend)
55 , fValid(true)
56 , fMockFormat(config) {
57}
58
59const GrPixelConfig* GrBackendFormat::getMockFormat() const {
60 if (this->isValid() && kMock_GrBackend == fBackend) {
61 return &fMockFormat;
62 }
63 return nullptr;
64}
65
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000066#ifdef SK_VULKAN
Greg Daniel94403452017-04-18 15:52:36 -040067GrBackendTexture::GrBackendTexture(int width,
68 int height,
Greg Daniel207282e2017-04-26 13:29:21 -040069 const GrVkImageInfo& vkInfo)
Greg Daniel94403452017-04-18 15:52:36 -040070 : fWidth(width)
71 , fHeight(height)
Greg Daniel8a3f55c2018-03-14 17:32:12 +000072 , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat))
Chris Dalton3b51df12017-11-27 14:33:06 -070073 , fMipMapped(GrMipMapped(vkInfo.fLevelCount > 1))
Greg Daniel94403452017-04-18 15:52:36 -040074 , fBackend(kVulkan_GrBackend)
75 , fVkInfo(vkInfo) {}
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000076#endif
Greg Daniel94403452017-04-18 15:52:36 -040077
78GrBackendTexture::GrBackendTexture(int width,
79 int height,
80 GrPixelConfig config,
Greg Daniel207282e2017-04-26 13:29:21 -040081 const GrGLTextureInfo& glInfo)
Greg Daniel177e6952017-10-12 12:27:11 -040082 : GrBackendTexture(width, height, config, GrMipMapped::kNo, glInfo) {}
83
84GrBackendTexture::GrBackendTexture(int width,
85 int height,
86 GrPixelConfig config,
87 GrMipMapped mipMapped,
88 const GrGLTextureInfo& glInfo)
Greg Daniel94403452017-04-18 15:52:36 -040089 : fWidth(width)
90 , fHeight(height)
91 , fConfig(config)
Greg Daniel177e6952017-10-12 12:27:11 -040092 , fMipMapped(mipMapped)
Greg Daniel94403452017-04-18 15:52:36 -040093 , fBackend(kOpenGL_GrBackend)
94 , fGLInfo(glInfo) {}
95
Brian Salomon8fe24272017-07-07 12:56:11 -040096GrBackendTexture::GrBackendTexture(int width,
97 int height,
Greg Daniele7d8da42017-12-04 11:23:19 -050098 GrMipMapped mipMapped,
99 const GrGLTextureInfo& glInfo)
100 : fWidth(width)
101 , fHeight(height)
Greg Daniel8a3f55c2018-03-14 17:32:12 +0000102 , fConfig(GrGLSizedFormatToPixelConfig(glInfo.fFormat))
Greg Daniele7d8da42017-12-04 11:23:19 -0500103 , fMipMapped(mipMapped)
104 , fBackend(kOpenGL_GrBackend)
105 , fGLInfo(glInfo) {}
106
107GrBackendTexture::GrBackendTexture(int width,
108 int height,
Greg Daniel177e6952017-10-12 12:27:11 -0400109 GrMipMapped mipMapped,
110 const GrMockTextureInfo& mockInfo)
Brian Salomon8fe24272017-07-07 12:56:11 -0400111 : fWidth(width)
112 , fHeight(height)
Brian Salomon0c51eea2018-03-09 17:02:09 -0500113 , fConfig(mockInfo.fConfig)
Greg Daniel177e6952017-10-12 12:27:11 -0400114 , fMipMapped(mipMapped)
Brian Salomon8fe24272017-07-07 12:56:11 -0400115 , fBackend(kMock_GrBackend)
116 , fMockInfo(mockInfo) {}
117
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000118#ifdef SK_VULKAN
Greg Daniel7ef28f32017-04-20 16:41:55 +0000119const GrVkImageInfo* GrBackendTexture::getVkImageInfo() const {
Brian Salomon8fe24272017-07-07 12:56:11 -0400120 if (this->isValid() && kVulkan_GrBackend == fBackend) {
Greg Daniel207282e2017-04-26 13:29:21 -0400121 return &fVkInfo;
Greg Daniel94403452017-04-18 15:52:36 -0400122 }
123 return nullptr;
124}
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000125#endif
Greg Daniel94403452017-04-18 15:52:36 -0400126
Greg Daniel7ef28f32017-04-20 16:41:55 +0000127const GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() const {
Brian Salomon8fe24272017-07-07 12:56:11 -0400128 if (this->isValid() && kOpenGL_GrBackend == fBackend) {
Greg Daniel207282e2017-04-26 13:29:21 -0400129 return &fGLInfo;
Greg Daniel94403452017-04-18 15:52:36 -0400130 }
131 return nullptr;
132}
133
Brian Salomon8fe24272017-07-07 12:56:11 -0400134const GrMockTextureInfo* GrBackendTexture::getMockTextureInfo() const {
135 if (this->isValid() && kMock_GrBackend == fBackend) {
136 return &fMockInfo;
137 }
138 return nullptr;
139}
140
Greg Daniel94403452017-04-18 15:52:36 -0400141////////////////////////////////////////////////////////////////////////////////////////////////////
142
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000143#ifdef SK_VULKAN
Greg Daniel94403452017-04-18 15:52:36 -0400144GrBackendRenderTarget::GrBackendRenderTarget(int width,
145 int height,
146 int sampleCnt,
147 int stencilBits,
Greg Danielbcf612b2017-05-01 13:50:58 +0000148 const GrVkImageInfo& vkInfo)
Brian Salomonafdc6b12018-03-09 12:02:32 -0500149 : GrBackendRenderTarget(width, height, sampleCnt, vkInfo) {
150 // This is a deprecated constructor that takes a bogus stencil bits.
151 SkASSERT(0 == stencilBits);
152}
153
154GrBackendRenderTarget::GrBackendRenderTarget(int width,
155 int height,
156 int sampleCnt,
157 const GrVkImageInfo& vkInfo)
Greg Daniel94403452017-04-18 15:52:36 -0400158 : fWidth(width)
159 , fHeight(height)
Brian Salomonbdecacf2018-02-02 20:32:49 -0500160 , fSampleCnt(SkTMax(1, sampleCnt))
Brian Salomonafdc6b12018-03-09 12:02:32 -0500161 , fStencilBits(0) // We always create stencil buffers internally for vulkan
Greg Daniel8a3f55c2018-03-14 17:32:12 +0000162 , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat))
Greg Daniel94403452017-04-18 15:52:36 -0400163 , fBackend(kVulkan_GrBackend)
164 , fVkInfo(vkInfo) {}
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000165#endif
Greg Daniel94403452017-04-18 15:52:36 -0400166
167GrBackendRenderTarget::GrBackendRenderTarget(int width,
168 int height,
169 int sampleCnt,
170 int stencilBits,
171 GrPixelConfig config,
Greg Danielbcf612b2017-05-01 13:50:58 +0000172 const GrGLFramebufferInfo& glInfo)
Greg Daniel94403452017-04-18 15:52:36 -0400173 : fWidth(width)
174 , fHeight(height)
Brian Salomonbdecacf2018-02-02 20:32:49 -0500175 , fSampleCnt(SkTMax(1, sampleCnt))
Greg Daniel94403452017-04-18 15:52:36 -0400176 , fStencilBits(stencilBits)
177 , fConfig(config)
178 , fBackend(kOpenGL_GrBackend)
179 , fGLInfo(glInfo) {}
180
Greg Danielfaa095e2017-12-19 13:15:02 -0500181GrBackendRenderTarget::GrBackendRenderTarget(int width,
182 int height,
183 int sampleCnt,
184 int stencilBits,
185 const GrGLFramebufferInfo& glInfo)
186 : fWidth(width)
187 , fHeight(height)
Brian Salomonbdecacf2018-02-02 20:32:49 -0500188 , fSampleCnt(SkTMax(1, sampleCnt))
Greg Danielfaa095e2017-12-19 13:15:02 -0500189 , fStencilBits(stencilBits)
Greg Daniel8a3f55c2018-03-14 17:32:12 +0000190 , fConfig(GrGLSizedFormatToPixelConfig(glInfo.fFormat))
Greg Danielfaa095e2017-12-19 13:15:02 -0500191 , fBackend(kOpenGL_GrBackend)
192 , fGLInfo(glInfo) {}
193
Brian Salomon0c51eea2018-03-09 17:02:09 -0500194GrBackendRenderTarget::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 Phillipsfcd5fdd2017-06-14 01:43:29 +0000206#ifdef SK_VULKAN
Greg Daniel7ef28f32017-04-20 16:41:55 +0000207const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const {
Greg Daniel94403452017-04-18 15:52:36 -0400208 if (kVulkan_GrBackend == fBackend) {
Greg Danielbcf612b2017-05-01 13:50:58 +0000209 return &fVkInfo;
Greg Daniel94403452017-04-18 15:52:36 -0400210 }
211 return nullptr;
212}
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000213#endif
Greg Daniel94403452017-04-18 15:52:36 -0400214
Greg Danielbcf612b2017-05-01 13:50:58 +0000215const GrGLFramebufferInfo* GrBackendRenderTarget::getGLFramebufferInfo() const {
Greg Daniel94403452017-04-18 15:52:36 -0400216 if (kOpenGL_GrBackend == fBackend) {
Greg Danielbcf612b2017-05-01 13:50:58 +0000217 return &fGLInfo;
Greg Daniel94403452017-04-18 15:52:36 -0400218 }
219 return nullptr;
220}
221
Brian Salomon0c51eea2018-03-09 17:02:09 -0500222const GrMockRenderTargetInfo* GrBackendRenderTarget::getMockRenderTargetInfo() const {
223 if (kMock_GrBackend == fBackend) {
224 return &fMockInfo;
225 }
226 return nullptr;
227}