blob: 406cb228ea3dede73cde86ab1c173f25512198b0 [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 Phillipsfcd5fdd2017-06-14 01:43:29 +000017#ifdef SK_VULKAN
Greg Daniel94403452017-04-18 15:52:36 -040018GrBackendTexture::GrBackendTexture(int width,
19 int height,
Greg Daniel207282e2017-04-26 13:29:21 -040020 const GrVkImageInfo& vkInfo)
Greg Daniel94403452017-04-18 15:52:36 -040021 : fWidth(width)
22 , fHeight(height)
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000023 , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat))
Chris Dalton3b51df12017-11-27 14:33:06 -070024 , fMipMapped(GrMipMapped(vkInfo.fLevelCount > 1))
Greg Daniel94403452017-04-18 15:52:36 -040025 , fBackend(kVulkan_GrBackend)
26 , fVkInfo(vkInfo) {}
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000027#endif
Greg Daniel94403452017-04-18 15:52:36 -040028
29GrBackendTexture::GrBackendTexture(int width,
30 int height,
31 GrPixelConfig config,
Greg Daniel207282e2017-04-26 13:29:21 -040032 const GrGLTextureInfo& glInfo)
Greg Daniel177e6952017-10-12 12:27:11 -040033 : GrBackendTexture(width, height, config, GrMipMapped::kNo, glInfo) {}
34
35GrBackendTexture::GrBackendTexture(int width,
36 int height,
37 GrPixelConfig config,
38 GrMipMapped mipMapped,
39 const GrGLTextureInfo& glInfo)
Greg Daniel94403452017-04-18 15:52:36 -040040 : fWidth(width)
41 , fHeight(height)
42 , fConfig(config)
Greg Daniel177e6952017-10-12 12:27:11 -040043 , fMipMapped(mipMapped)
Greg Daniel94403452017-04-18 15:52:36 -040044 , fBackend(kOpenGL_GrBackend)
45 , fGLInfo(glInfo) {}
46
Brian Salomon8fe24272017-07-07 12:56:11 -040047GrBackendTexture::GrBackendTexture(int width,
48 int height,
Greg Daniele7d8da42017-12-04 11:23:19 -050049 GrMipMapped mipMapped,
50 const GrGLTextureInfo& glInfo)
51 : fWidth(width)
52 , fHeight(height)
53 , fConfig(GrGLSizedFormatToPixelConfig(glInfo.fFormat))
54 , fMipMapped(mipMapped)
55 , fBackend(kOpenGL_GrBackend)
56 , fGLInfo(glInfo) {}
57
58GrBackendTexture::GrBackendTexture(int width,
59 int height,
Brian Salomon8fe24272017-07-07 12:56:11 -040060 GrPixelConfig config,
61 const GrMockTextureInfo& mockInfo)
Greg Daniel177e6952017-10-12 12:27:11 -040062 : GrBackendTexture(width, height, config, GrMipMapped::kNo, mockInfo) {}
63
64GrBackendTexture::GrBackendTexture(int width,
65 int height,
66 GrPixelConfig config,
67 GrMipMapped mipMapped,
68 const GrMockTextureInfo& mockInfo)
Brian Salomon8fe24272017-07-07 12:56:11 -040069 : fWidth(width)
70 , fHeight(height)
71 , fConfig(config)
Greg Daniel177e6952017-10-12 12:27:11 -040072 , fMipMapped(mipMapped)
Brian Salomon8fe24272017-07-07 12:56:11 -040073 , fBackend(kMock_GrBackend)
74 , fMockInfo(mockInfo) {}
75
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000076#ifdef SK_VULKAN
Greg Daniel7ef28f32017-04-20 16:41:55 +000077const GrVkImageInfo* GrBackendTexture::getVkImageInfo() const {
Brian Salomon8fe24272017-07-07 12:56:11 -040078 if (this->isValid() && kVulkan_GrBackend == fBackend) {
Greg Daniel207282e2017-04-26 13:29:21 -040079 return &fVkInfo;
Greg Daniel94403452017-04-18 15:52:36 -040080 }
81 return nullptr;
82}
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000083#endif
Greg Daniel94403452017-04-18 15:52:36 -040084
Greg Daniel7ef28f32017-04-20 16:41:55 +000085const GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() const {
Brian Salomon8fe24272017-07-07 12:56:11 -040086 if (this->isValid() && kOpenGL_GrBackend == fBackend) {
Greg Daniel207282e2017-04-26 13:29:21 -040087 return &fGLInfo;
Greg Daniel94403452017-04-18 15:52:36 -040088 }
89 return nullptr;
90}
91
Brian Salomon8fe24272017-07-07 12:56:11 -040092const GrMockTextureInfo* GrBackendTexture::getMockTextureInfo() const {
93 if (this->isValid() && kMock_GrBackend == fBackend) {
94 return &fMockInfo;
95 }
96 return nullptr;
97}
98
Greg Daniel94403452017-04-18 15:52:36 -040099////////////////////////////////////////////////////////////////////////////////////////////////////
100
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000101#ifdef SK_VULKAN
Greg Daniel94403452017-04-18 15:52:36 -0400102GrBackendRenderTarget::GrBackendRenderTarget(int width,
103 int height,
104 int sampleCnt,
105 int stencilBits,
Greg Danielbcf612b2017-05-01 13:50:58 +0000106 const GrVkImageInfo& vkInfo)
Greg Daniel94403452017-04-18 15:52:36 -0400107 : fWidth(width)
108 , fHeight(height)
109 , fSampleCnt(sampleCnt)
110 , fStencilBits(stencilBits)
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000111 , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat))
Greg Daniel94403452017-04-18 15:52:36 -0400112 , fBackend(kVulkan_GrBackend)
113 , fVkInfo(vkInfo) {}
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000114#endif
Greg Daniel94403452017-04-18 15:52:36 -0400115
116GrBackendRenderTarget::GrBackendRenderTarget(int width,
117 int height,
118 int sampleCnt,
119 int stencilBits,
120 GrPixelConfig config,
Greg Danielbcf612b2017-05-01 13:50:58 +0000121 const GrGLFramebufferInfo& glInfo)
Greg Daniel94403452017-04-18 15:52:36 -0400122 : fWidth(width)
123 , fHeight(height)
124 , fSampleCnt(sampleCnt)
125 , fStencilBits(stencilBits)
126 , fConfig(config)
127 , fBackend(kOpenGL_GrBackend)
128 , fGLInfo(glInfo) {}
129
Greg Danielfaa095e2017-12-19 13:15:02 -0500130GrBackendRenderTarget::GrBackendRenderTarget(int width,
131 int height,
132 int sampleCnt,
133 int stencilBits,
134 const GrGLFramebufferInfo& glInfo)
135 : fWidth(width)
136 , fHeight(height)
137 , fSampleCnt(sampleCnt)
138 , fStencilBits(stencilBits)
139 , fConfig(GrGLSizedFormatToPixelConfig(glInfo.fFormat))
140 , fBackend(kOpenGL_GrBackend)
141 , fGLInfo(glInfo) {}
142
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000143#ifdef SK_VULKAN
Greg Daniel7ef28f32017-04-20 16:41:55 +0000144const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const {
Greg Daniel94403452017-04-18 15:52:36 -0400145 if (kVulkan_GrBackend == fBackend) {
Greg Danielbcf612b2017-05-01 13:50:58 +0000146 return &fVkInfo;
Greg Daniel94403452017-04-18 15:52:36 -0400147 }
148 return nullptr;
149}
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000150#endif
Greg Daniel94403452017-04-18 15:52:36 -0400151
Greg Danielbcf612b2017-05-01 13:50:58 +0000152const GrGLFramebufferInfo* GrBackendRenderTarget::getGLFramebufferInfo() const {
Greg Daniel94403452017-04-18 15:52:36 -0400153 if (kOpenGL_GrBackend == fBackend) {
Greg Danielbcf612b2017-05-01 13:50:58 +0000154 return &fGLInfo;
Greg Daniel94403452017-04-18 15:52:36 -0400155 }
156 return nullptr;
157}
158