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 
17 #ifdef SK_VULKAN
GrBackendTexture(int width,int height,const GrVkImageInfo & vkInfo)18 GrBackendTexture::GrBackendTexture(int width,
19                                    int height,
20                                    const GrVkImageInfo& vkInfo)
21         : fWidth(width)
22         , fHeight(height)
23         , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat))
24         , fMipMapped(GrMipMapped(vkInfo.fLevelCount > 1))
25         , fBackend(kVulkan_GrBackend)
26         , fVkInfo(vkInfo) {}
27 #endif
28 
GrBackendTexture(int width,int height,GrPixelConfig config,const GrGLTextureInfo & glInfo)29 GrBackendTexture::GrBackendTexture(int width,
30                                    int height,
31                                    GrPixelConfig config,
32                                    const GrGLTextureInfo& glInfo)
33         : GrBackendTexture(width, height, config, GrMipMapped::kNo, glInfo) {}
34 
GrBackendTexture(int width,int height,GrPixelConfig config,GrMipMapped mipMapped,const GrGLTextureInfo & glInfo)35 GrBackendTexture::GrBackendTexture(int width,
36                                    int height,
37                                    GrPixelConfig config,
38                                    GrMipMapped mipMapped,
39                                    const GrGLTextureInfo& glInfo)
40         : fWidth(width)
41         , fHeight(height)
42         , fConfig(config)
43         , fMipMapped(mipMapped)
44         , fBackend(kOpenGL_GrBackend)
45         , fGLInfo(glInfo) {}
46 
GrBackendTexture(int width,int height,GrMipMapped mipMapped,const GrGLTextureInfo & glInfo)47 GrBackendTexture::GrBackendTexture(int width,
48                                    int height,
49                                    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 
GrBackendTexture(int width,int height,GrPixelConfig config,const GrMockTextureInfo & mockInfo)58 GrBackendTexture::GrBackendTexture(int width,
59                                    int height,
60                                    GrPixelConfig config,
61                                    const GrMockTextureInfo& mockInfo)
62         : GrBackendTexture(width, height, config, GrMipMapped::kNo, mockInfo) {}
63 
GrBackendTexture(int width,int height,GrPixelConfig config,GrMipMapped mipMapped,const GrMockTextureInfo & mockInfo)64 GrBackendTexture::GrBackendTexture(int width,
65                                    int height,
66                                    GrPixelConfig config,
67                                    GrMipMapped mipMapped,
68                                    const GrMockTextureInfo& mockInfo)
69         : fWidth(width)
70         , fHeight(height)
71         , fConfig(config)
72         , fMipMapped(mipMapped)
73         , fBackend(kMock_GrBackend)
74         , fMockInfo(mockInfo) {}
75 
76 #ifdef SK_VULKAN
getVkImageInfo() const77 const GrVkImageInfo* GrBackendTexture::getVkImageInfo() const {
78     if (this->isValid() && kVulkan_GrBackend == fBackend) {
79         return &fVkInfo;
80     }
81     return nullptr;
82 }
83 #endif
84 
getGLTextureInfo() const85 const GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() const {
86     if (this->isValid() && kOpenGL_GrBackend == fBackend) {
87         return &fGLInfo;
88     }
89     return nullptr;
90 }
91 
getMockTextureInfo() const92 const GrMockTextureInfo* GrBackendTexture::getMockTextureInfo() const {
93     if (this->isValid() && kMock_GrBackend == fBackend) {
94         return &fMockInfo;
95     }
96     return nullptr;
97 }
98 
99 ////////////////////////////////////////////////////////////////////////////////////////////////////
100 
101 #ifdef SK_VULKAN
GrBackendRenderTarget(int width,int height,int sampleCnt,int stencilBits,const GrVkImageInfo & vkInfo)102 GrBackendRenderTarget::GrBackendRenderTarget(int width,
103                                              int height,
104                                              int sampleCnt,
105                                              int stencilBits,
106                                              const GrVkImageInfo& vkInfo)
107         : fWidth(width)
108         , fHeight(height)
109         , fSampleCnt(SkTMax(1, sampleCnt))
110         , fStencilBits(stencilBits)
111         , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat))
112         , fBackend(kVulkan_GrBackend)
113         , fVkInfo(vkInfo) {}
114 #endif
115 
GrBackendRenderTarget(int width,int height,int sampleCnt,int stencilBits,GrPixelConfig config,const GrGLFramebufferInfo & glInfo)116 GrBackendRenderTarget::GrBackendRenderTarget(int width,
117                                              int height,
118                                              int sampleCnt,
119                                              int stencilBits,
120                                              GrPixelConfig config,
121                                              const GrGLFramebufferInfo& glInfo)
122         : fWidth(width)
123         , fHeight(height)
124         , fSampleCnt(SkTMax(1, sampleCnt))
125         , fStencilBits(stencilBits)
126         , fConfig(config)
127         , fBackend(kOpenGL_GrBackend)
128         , fGLInfo(glInfo) {}
129 
GrBackendRenderTarget(int width,int height,int sampleCnt,int stencilBits,const GrGLFramebufferInfo & glInfo)130 GrBackendRenderTarget::GrBackendRenderTarget(int width,
131                                              int height,
132                                              int sampleCnt,
133                                              int stencilBits,
134                                              const GrGLFramebufferInfo& glInfo)
135         : fWidth(width)
136         , fHeight(height)
137         , fSampleCnt(SkTMax(1, sampleCnt))
138         , fStencilBits(stencilBits)
139         , fConfig(GrGLSizedFormatToPixelConfig(glInfo.fFormat))
140         , fBackend(kOpenGL_GrBackend)
141         , fGLInfo(glInfo) {}
142 
143 #ifdef SK_VULKAN
getVkImageInfo() const144 const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const {
145     if (kVulkan_GrBackend == fBackend) {
146         return &fVkInfo;
147     }
148     return nullptr;
149 }
150 #endif
151 
getGLFramebufferInfo() const152 const GrGLFramebufferInfo* GrBackendRenderTarget::getGLFramebufferInfo() const {
153     if (kOpenGL_GrBackend == fBackend) {
154         return &fGLInfo;
155     }
156     return nullptr;
157 }
158 
159