blob: 6c715228b2968e635dca2c1d4e032affb104b817 [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
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000015#ifdef SK_VULKAN
Greg Daniel94403452017-04-18 15:52:36 -040016GrBackendTexture::GrBackendTexture(int width,
17 int height,
Greg Daniel207282e2017-04-26 13:29:21 -040018 const GrVkImageInfo& vkInfo)
Greg Daniel94403452017-04-18 15:52:36 -040019 : fWidth(width)
20 , fHeight(height)
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000021 , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat))
Greg Daniel94403452017-04-18 15:52:36 -040022 , fBackend(kVulkan_GrBackend)
23 , fVkInfo(vkInfo) {}
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000024#endif
Greg Daniel94403452017-04-18 15:52:36 -040025
26GrBackendTexture::GrBackendTexture(int width,
27 int height,
28 GrPixelConfig config,
Greg Daniel207282e2017-04-26 13:29:21 -040029 const GrGLTextureInfo& glInfo)
Greg Daniel94403452017-04-18 15:52:36 -040030 : fWidth(width)
31 , fHeight(height)
32 , fConfig(config)
33 , fBackend(kOpenGL_GrBackend)
34 , fGLInfo(glInfo) {}
35
36GrBackendTexture::GrBackendTexture(const GrBackendTextureDesc& desc, GrBackend backend)
37 : fWidth(desc.fWidth)
38 , fHeight(desc.fHeight)
Greg Daniel207282e2017-04-26 13:29:21 -040039 , fConfig(desc.fConfig)
40 , fBackend(backend) {
41 if (kOpenGL_GrBackend == backend) {
42 fGLInfo = *reinterpret_cast<const GrGLTextureInfo*>(desc.fTextureHandle);
43 } else {
44 SkASSERT(kVulkan_GrBackend == backend);
Greg Daniel94403452017-04-18 15:52:36 -040045#ifdef SK_VULKAN
Greg Daniel207282e2017-04-26 13:29:21 -040046 const GrVkImageInfo* vkInfo =
47 reinterpret_cast<const GrVkImageInfo*>(desc.fTextureHandle);
48 fConfig = GrVkFormatToPixelConfig(vkInfo->fFormat);
49 fVkInfo = *vkInfo;
Greg Daniel94403452017-04-18 15:52:36 -040050#else
Greg Daniel207282e2017-04-26 13:29:21 -040051 fConfig = kUnknown_GrPixelConfig;
Greg Daniel94403452017-04-18 15:52:36 -040052#endif
Greg Daniel207282e2017-04-26 13:29:21 -040053 }
54}
Greg Daniel94403452017-04-18 15:52:36 -040055
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000056#ifdef SK_VULKAN
Greg Daniel7ef28f32017-04-20 16:41:55 +000057const GrVkImageInfo* GrBackendTexture::getVkImageInfo() const {
Greg Daniel94403452017-04-18 15:52:36 -040058 if (kVulkan_GrBackend == fBackend) {
Greg Daniel207282e2017-04-26 13:29:21 -040059 return &fVkInfo;
Greg Daniel94403452017-04-18 15:52:36 -040060 }
61 return nullptr;
62}
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000063#endif
Greg Daniel94403452017-04-18 15:52:36 -040064
Greg Daniel7ef28f32017-04-20 16:41:55 +000065const GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() const {
Greg Daniel94403452017-04-18 15:52:36 -040066 if (kOpenGL_GrBackend == fBackend) {
Greg Daniel207282e2017-04-26 13:29:21 -040067 return &fGLInfo;
Greg Daniel94403452017-04-18 15:52:36 -040068 }
69 return nullptr;
70}
71
72////////////////////////////////////////////////////////////////////////////////////////////////////
73
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000074#ifdef SK_VULKAN
Greg Daniel94403452017-04-18 15:52:36 -040075GrBackendRenderTarget::GrBackendRenderTarget(int width,
76 int height,
77 int sampleCnt,
78 int stencilBits,
Greg Danielbcf612b2017-05-01 13:50:58 +000079 const GrVkImageInfo& vkInfo)
Greg Daniel94403452017-04-18 15:52:36 -040080 : fWidth(width)
81 , fHeight(height)
82 , fSampleCnt(sampleCnt)
83 , fStencilBits(stencilBits)
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000084 , fConfig(GrVkFormatToPixelConfig(vkInfo.fFormat))
Greg Daniel94403452017-04-18 15:52:36 -040085 , fBackend(kVulkan_GrBackend)
86 , fVkInfo(vkInfo) {}
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000087#endif
Greg Daniel94403452017-04-18 15:52:36 -040088
89GrBackendRenderTarget::GrBackendRenderTarget(int width,
90 int height,
91 int sampleCnt,
92 int stencilBits,
93 GrPixelConfig config,
Greg Danielbcf612b2017-05-01 13:50:58 +000094 const GrGLFramebufferInfo& glInfo)
Greg Daniel94403452017-04-18 15:52:36 -040095 : fWidth(width)
96 , fHeight(height)
97 , fSampleCnt(sampleCnt)
98 , fStencilBits(stencilBits)
99 , fConfig(config)
100 , fBackend(kOpenGL_GrBackend)
101 , fGLInfo(glInfo) {}
102
103GrBackendRenderTarget::GrBackendRenderTarget(const GrBackendRenderTargetDesc& desc,
104 GrBackend backend)
105 : fWidth(desc.fWidth)
106 , fHeight(desc.fHeight)
107 , fSampleCnt(desc.fSampleCnt)
108 , fStencilBits(desc.fStencilBits)
Greg Danielbcf612b2017-05-01 13:50:58 +0000109 , fConfig(desc.fConfig)
110 , fBackend(backend) {
111 if (kOpenGL_GrBackend == backend) {
Greg Daniel6125efd2017-05-01 13:04:22 -0400112 fGLInfo.fFBOID = static_cast<GrGLuint>(desc.fRenderTargetHandle);
Greg Danielbcf612b2017-05-01 13:50:58 +0000113 } else {
114 SkASSERT(kVulkan_GrBackend == backend);
Greg Daniel94403452017-04-18 15:52:36 -0400115#ifdef SK_VULKAN
Greg Danielbcf612b2017-05-01 13:50:58 +0000116 const GrVkImageInfo* vkInfo =
117 reinterpret_cast<const GrVkImageInfo*>(desc.fRenderTargetHandle);
118 fConfig = GrVkFormatToPixelConfig(vkInfo->fFormat);
119 fVkInfo = *vkInfo;
Greg Daniel94403452017-04-18 15:52:36 -0400120#else
Greg Danielbcf612b2017-05-01 13:50:58 +0000121 fConfig = kUnknown_GrPixelConfig;
Greg Daniel94403452017-04-18 15:52:36 -0400122#endif
Greg Danielbcf612b2017-05-01 13:50:58 +0000123 }
124}
Greg Daniel94403452017-04-18 15:52:36 -0400125
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000126#ifdef SK_VULKAN
Greg Daniel7ef28f32017-04-20 16:41:55 +0000127const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const {
Greg Daniel94403452017-04-18 15:52:36 -0400128 if (kVulkan_GrBackend == fBackend) {
Greg Danielbcf612b2017-05-01 13:50:58 +0000129 return &fVkInfo;
Greg Daniel94403452017-04-18 15:52:36 -0400130 }
131 return nullptr;
132}
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000133#endif
Greg Daniel94403452017-04-18 15:52:36 -0400134
Greg Danielbcf612b2017-05-01 13:50:58 +0000135const GrGLFramebufferInfo* GrBackendRenderTarget::getGLFramebufferInfo() const {
Greg Daniel94403452017-04-18 15:52:36 -0400136 if (kOpenGL_GrBackend == fBackend) {
Greg Danielbcf612b2017-05-01 13:50:58 +0000137 return &fGLInfo;
Greg Daniel94403452017-04-18 15:52:36 -0400138 }
139 return nullptr;
140}
141