blob: 6a1448e17c9115b6084d3fa199e2341197a8b9e0 [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
10#ifdef SK_VULKAN
11#include "vk/GrVkTypes.h"
12#include "vk/GrVkUtil.h"
Greg Daniel7ef28f32017-04-20 16:41:55 +000013#endif
14
Greg Daniel94403452017-04-18 15:52:36 -040015GrBackendTexture::GrBackendTexture(int width,
16 int height,
Greg Daniel7ef28f32017-04-20 16:41:55 +000017 const GrVkImageInfo* vkInfo)
Greg Daniel94403452017-04-18 15:52:36 -040018 : fWidth(width)
19 , fHeight(height)
Greg Daniel7ef28f32017-04-20 16:41:55 +000020 , fConfig(
21#ifdef SK_VULKAN
22 GrVkFormatToPixelConfig(vkInfo->fFormat)
23#else
24 kUnknown_GrPixelConfig
25#endif
26 )
Greg Daniel94403452017-04-18 15:52:36 -040027 , fBackend(kVulkan_GrBackend)
28 , fVkInfo(vkInfo) {}
Greg Daniel94403452017-04-18 15:52:36 -040029
30GrBackendTexture::GrBackendTexture(int width,
31 int height,
32 GrPixelConfig config,
Greg Daniel7ef28f32017-04-20 16:41:55 +000033 const GrGLTextureInfo* glInfo)
Greg Daniel94403452017-04-18 15:52:36 -040034 : fWidth(width)
35 , fHeight(height)
36 , fConfig(config)
37 , fBackend(kOpenGL_GrBackend)
38 , fGLInfo(glInfo) {}
39
40GrBackendTexture::GrBackendTexture(const GrBackendTextureDesc& desc, GrBackend backend)
41 : fWidth(desc.fWidth)
42 , fHeight(desc.fHeight)
43 , fConfig(kVulkan_GrBackend == backend
44#ifdef SK_VULKAN
45 ? GrVkFormatToPixelConfig(((GrVkImageInfo*)desc.fTextureHandle)->fFormat)
46#else
47 ? kUnknown_GrPixelConfig
48#endif
49 : desc.fConfig)
50 , fBackend(backend)
51 , fHandle(desc.fTextureHandle) {}
52
Greg Daniel7ef28f32017-04-20 16:41:55 +000053const GrVkImageInfo* GrBackendTexture::getVkImageInfo() const {
Greg Daniel94403452017-04-18 15:52:36 -040054 if (kVulkan_GrBackend == fBackend) {
55 return fVkInfo;
56 }
57 return nullptr;
58}
59
Greg Daniel7ef28f32017-04-20 16:41:55 +000060const GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() const {
Greg Daniel94403452017-04-18 15:52:36 -040061 if (kOpenGL_GrBackend == fBackend) {
62 return fGLInfo;
63 }
64 return nullptr;
65}
66
67////////////////////////////////////////////////////////////////////////////////////////////////////
68
Greg Daniel94403452017-04-18 15:52:36 -040069GrBackendRenderTarget::GrBackendRenderTarget(int width,
70 int height,
71 int sampleCnt,
72 int stencilBits,
Greg Danielbcf612b2017-05-01 13:50:58 +000073 const GrVkImageInfo& vkInfo)
Greg Daniel94403452017-04-18 15:52:36 -040074 : fWidth(width)
75 , fHeight(height)
76 , fSampleCnt(sampleCnt)
77 , fStencilBits(stencilBits)
Greg Daniel7ef28f32017-04-20 16:41:55 +000078 , fConfig(
79#ifdef SK_VULKAN
Greg Danielbcf612b2017-05-01 13:50:58 +000080 GrVkFormatToPixelConfig(vkInfo.fFormat)
Greg Daniel7ef28f32017-04-20 16:41:55 +000081#else
82 kUnknown_GrPixelConfig
83#endif
84 )
Greg Daniel94403452017-04-18 15:52:36 -040085 , fBackend(kVulkan_GrBackend)
86 , fVkInfo(vkInfo) {}
Greg Daniel94403452017-04-18 15:52:36 -040087
88GrBackendRenderTarget::GrBackendRenderTarget(int width,
89 int height,
90 int sampleCnt,
91 int stencilBits,
92 GrPixelConfig config,
Greg Danielbcf612b2017-05-01 13:50:58 +000093 const GrGLFramebufferInfo& glInfo)
Greg Daniel94403452017-04-18 15:52:36 -040094 : fWidth(width)
95 , fHeight(height)
96 , fSampleCnt(sampleCnt)
97 , fStencilBits(stencilBits)
98 , fConfig(config)
99 , fBackend(kOpenGL_GrBackend)
100 , fGLInfo(glInfo) {}
101
102GrBackendRenderTarget::GrBackendRenderTarget(const GrBackendRenderTargetDesc& desc,
103 GrBackend backend)
104 : fWidth(desc.fWidth)
105 , fHeight(desc.fHeight)
106 , fSampleCnt(desc.fSampleCnt)
107 , fStencilBits(desc.fStencilBits)
Greg Danielbcf612b2017-05-01 13:50:58 +0000108 , fConfig(desc.fConfig)
109 , fBackend(backend) {
110 if (kOpenGL_GrBackend == backend) {
111 fGLInfo = *reinterpret_cast<const GrGLFramebufferInfo*>(desc.fRenderTargetHandle);
112 } else {
113 SkASSERT(kVulkan_GrBackend == backend);
Greg Daniel94403452017-04-18 15:52:36 -0400114#ifdef SK_VULKAN
Greg Danielbcf612b2017-05-01 13:50:58 +0000115 const GrVkImageInfo* vkInfo =
116 reinterpret_cast<const GrVkImageInfo*>(desc.fRenderTargetHandle);
117 fConfig = GrVkFormatToPixelConfig(vkInfo->fFormat);
118 fVkInfo = *vkInfo;
Greg Daniel94403452017-04-18 15:52:36 -0400119#else
Greg Danielbcf612b2017-05-01 13:50:58 +0000120 fConfig = kUnknown_GrPixelConfig;
Greg Daniel94403452017-04-18 15:52:36 -0400121#endif
Greg Danielbcf612b2017-05-01 13:50:58 +0000122 }
123}
Greg Daniel94403452017-04-18 15:52:36 -0400124
Greg Daniel7ef28f32017-04-20 16:41:55 +0000125const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const {
Greg Daniel94403452017-04-18 15:52:36 -0400126 if (kVulkan_GrBackend == fBackend) {
Greg Danielbcf612b2017-05-01 13:50:58 +0000127 return &fVkInfo;
Greg Daniel94403452017-04-18 15:52:36 -0400128 }
129 return nullptr;
130}
131
Greg Danielbcf612b2017-05-01 13:50:58 +0000132const GrGLFramebufferInfo* GrBackendRenderTarget::getGLFramebufferInfo() const {
Greg Daniel94403452017-04-18 15:52:36 -0400133 if (kOpenGL_GrBackend == fBackend) {
Greg Danielbcf612b2017-05-01 13:50:58 +0000134 return &fGLInfo;
Greg Daniel94403452017-04-18 15:52:36 -0400135 }
136 return nullptr;
137}
138