• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef SK_VULKAN
11 #include "vk/GrVkTypes.h"
12 #include "vk/GrVkUtil.h"
13 #endif
14 
15 #ifdef SK_VULKAN
GrBackendTexture(int width,int height,const GrVkImageInfo & vkInfo)16 GrBackendTexture::GrBackendTexture(int width,
17                                    int height,
18                                    const GrVkImageInfo& vkInfo)
19         : fWidth(width)
20         , fHeight(height)
21         , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat))
22         , fBackend(kVulkan_GrBackend)
23         , fVkInfo(vkInfo) {}
24 #endif
25 
GrBackendTexture(int width,int height,GrPixelConfig config,const GrGLTextureInfo & glInfo)26 GrBackendTexture::GrBackendTexture(int width,
27                                    int height,
28                                    GrPixelConfig config,
29                                    const GrGLTextureInfo& glInfo)
30         : fWidth(width)
31         , fHeight(height)
32         , fConfig(config)
33         , fBackend(kOpenGL_GrBackend)
34         , fGLInfo(glInfo) {}
35 
GrBackendTexture(int width,int height,GrPixelConfig config,const GrMockTextureInfo & mockInfo)36 GrBackendTexture::GrBackendTexture(int width,
37                                    int height,
38                                    GrPixelConfig config,
39                                    const GrMockTextureInfo& mockInfo)
40         : fWidth(width)
41         , fHeight(height)
42         , fConfig(config)
43         , fBackend(kMock_GrBackend)
44         , fMockInfo(mockInfo) {}
45 
GrBackendTexture(const GrBackendTextureDesc & desc,GrBackend backend)46 GrBackendTexture::GrBackendTexture(const GrBackendTextureDesc& desc, GrBackend backend)
47         : fWidth(desc.fWidth)
48         , fHeight(desc.fHeight)
49         , fConfig(desc.fConfig)
50         , fBackend(backend) {
51     switch (backend) {
52         case kOpenGL_GrBackend:
53             fGLInfo = *reinterpret_cast<const GrGLTextureInfo*>(desc.fTextureHandle);
54             break;
55 #ifdef SK_VULKAN
56         case kVulkan_GrBackend: {
57             const GrVkImageInfo* vkInfo =
58                     reinterpret_cast<const GrVkImageInfo*>(desc.fTextureHandle);
59             fConfig = GrVkFormatToPixelConfig(vkInfo->fFormat);
60             fVkInfo = *vkInfo;
61             break;
62         }
63 #endif
64         case kMock_GrBackend:
65             fMockInfo = *reinterpret_cast<const GrMockTextureInfo*>(desc.fTextureHandle);
66             break;
67         default:
68             fConfig = kUnknown_GrPixelConfig;
69             break;
70     }
71 }
72 
73 #ifdef SK_VULKAN
getVkImageInfo() const74 const GrVkImageInfo* GrBackendTexture::getVkImageInfo() const {
75     if (this->isValid() && kVulkan_GrBackend == fBackend) {
76         return &fVkInfo;
77     }
78     return nullptr;
79 }
80 #endif
81 
getGLTextureInfo() const82 const GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() const {
83     if (this->isValid() && kOpenGL_GrBackend == fBackend) {
84         return &fGLInfo;
85     }
86     return nullptr;
87 }
88 
getMockTextureInfo() const89 const GrMockTextureInfo* GrBackendTexture::getMockTextureInfo() const {
90     if (this->isValid() && kMock_GrBackend == fBackend) {
91         return &fMockInfo;
92     }
93     return nullptr;
94 }
95 
96 ////////////////////////////////////////////////////////////////////////////////////////////////////
97 
98 #ifdef SK_VULKAN
GrBackendRenderTarget(int width,int height,int sampleCnt,int stencilBits,const GrVkImageInfo & vkInfo)99 GrBackendRenderTarget::GrBackendRenderTarget(int width,
100                                              int height,
101                                              int sampleCnt,
102                                              int stencilBits,
103                                              const GrVkImageInfo& vkInfo)
104         : fWidth(width)
105         , fHeight(height)
106         , fSampleCnt(sampleCnt)
107         , fStencilBits(stencilBits)
108         , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat))
109         , fBackend(kVulkan_GrBackend)
110         , fVkInfo(vkInfo) {}
111 #endif
112 
GrBackendRenderTarget(int width,int height,int sampleCnt,int stencilBits,GrPixelConfig config,const GrGLFramebufferInfo & glInfo)113 GrBackendRenderTarget::GrBackendRenderTarget(int width,
114                                              int height,
115                                              int sampleCnt,
116                                              int stencilBits,
117                                              GrPixelConfig config,
118                                              const GrGLFramebufferInfo& glInfo)
119         : fWidth(width)
120         , fHeight(height)
121         , fSampleCnt(sampleCnt)
122         , fStencilBits(stencilBits)
123         , fConfig(config)
124         , fBackend(kOpenGL_GrBackend)
125         , fGLInfo(glInfo) {}
126 
GrBackendRenderTarget(const GrBackendRenderTargetDesc & desc,GrBackend backend)127 GrBackendRenderTarget::GrBackendRenderTarget(const GrBackendRenderTargetDesc& desc,
128                                              GrBackend backend)
129         : fWidth(desc.fWidth)
130         , fHeight(desc.fHeight)
131         , fSampleCnt(desc.fSampleCnt)
132         , fStencilBits(desc.fStencilBits)
133         , fConfig(desc.fConfig)
134         , fBackend(backend) {
135     if (kOpenGL_GrBackend == backend) {
136         fGLInfo.fFBOID = static_cast<GrGLuint>(desc.fRenderTargetHandle);
137     } else {
138         SkASSERT(kVulkan_GrBackend == backend);
139 #ifdef SK_VULKAN
140         const GrVkImageInfo* vkInfo =
141                 reinterpret_cast<const GrVkImageInfo*>(desc.fRenderTargetHandle);
142         fConfig = GrVkFormatToPixelConfig(vkInfo->fFormat);
143         fVkInfo = *vkInfo;
144 #else
145         fConfig = kUnknown_GrPixelConfig;
146 #endif
147     }
148 }
149 
150 #ifdef SK_VULKAN
getVkImageInfo() const151 const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const {
152     if (kVulkan_GrBackend == fBackend) {
153         return &fVkInfo;
154     }
155     return nullptr;
156 }
157 #endif
158 
getGLFramebufferInfo() const159 const GrGLFramebufferInfo* GrBackendRenderTarget::getGLFramebufferInfo() const {
160     if (kOpenGL_GrBackend == fBackend) {
161         return &fGLInfo;
162     }
163     return nullptr;
164 }
165 
166