blob: 97b3b6ee03a2cf29df3ac7eb40ba24f9cdd3528d [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 Daniel7ef28f32017-04-20 16:41:55 +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
80 GrVkFormatToPixelConfig(vkInfo->fFormat)
81#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 Daniel7ef28f32017-04-20 16:41:55 +000093 const GrGLTextureInfo* 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)
108 , fConfig(kVulkan_GrBackend == backend
109#ifdef SK_VULKAN
110 ? GrVkFormatToPixelConfig(((GrVkImageInfo*)desc.fRenderTargetHandle)->fFormat)
111#else
112 ? kUnknown_GrPixelConfig
113#endif
114 : desc.fConfig)
115 , fBackend(backend)
116 , fHandle(desc.fRenderTargetHandle) {}
117
Greg Daniel7ef28f32017-04-20 16:41:55 +0000118const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const {
Greg Daniel94403452017-04-18 15:52:36 -0400119 if (kVulkan_GrBackend == fBackend) {
120 return fVkInfo;
121 }
122 return nullptr;
123}
124
Greg Daniel7ef28f32017-04-20 16:41:55 +0000125const GrGLTextureInfo* GrBackendRenderTarget::getGLTextureInfo() const {
Greg Daniel94403452017-04-18 15:52:36 -0400126 if (kOpenGL_GrBackend == fBackend) {
127 return fGLInfo;
128 }
129 return nullptr;
130}
131