blob: c9a9ad02e61c57c6747a920a7e4b0cf85f1a8034 [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#ifndef GrBackendSurface_DEFINED
9#define GrBackendSurface_DEFINED
10
11#include "GrTypes.h"
Greg Danielbcf612b2017-05-01 13:50:58 +000012#include "gl/GrGLTypes.h"
Brian Salomon8fe24272017-07-07 12:56:11 -040013#include "mock/GrMockTypes.h"
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000014
15#ifdef SK_VULKAN
Greg Danielbcf612b2017-05-01 13:50:58 +000016#include "vk/GrVkTypes.h"
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000017#endif
Greg Daniel94403452017-04-18 15:52:36 -040018
Brian Salomonec045b42017-07-07 10:34:40 -040019class SK_API GrBackendTexture {
Greg Daniel94403452017-04-18 15:52:36 -040020public:
Brian Salomon8fe24272017-07-07 12:56:11 -040021 // Creates an invalid backend texture.
22 GrBackendTexture() : fConfig(kUnknown_GrPixelConfig) {}
23
Greg Daniel94403452017-04-18 15:52:36 -040024 GrBackendTexture(int width,
25 int height,
Robert Phillipsfad9e3f2017-06-13 22:16:08 +000026 GrPixelConfig config,
27 const GrGLTextureInfo& glInfo);
Greg Danielc0f8e422017-06-13 13:47:53 -040028
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000029#ifdef SK_VULKAN
30 GrBackendTexture(int width,
31 int height,
32 const GrVkImageInfo& vkInfo);
33#endif
34
Brian Salomon8fe24272017-07-07 12:56:11 -040035 GrBackendTexture(int width,
36 int height,
37 GrPixelConfig config,
38 const GrMockTextureInfo& mockInfo);
39
Greg Daniel94403452017-04-18 15:52:36 -040040 int width() const { return fWidth; }
41 int height() const { return fHeight; }
42 GrPixelConfig config() const { return fConfig; }
43 GrBackend backend() const {return fBackend; }
44
Robert Phillipsfad9e3f2017-06-13 22:16:08 +000045 // If the backend API is GL, this returns a pointer to the GrGLTextureInfo struct. Otherwise
46 // it returns nullptr.
47 const GrGLTextureInfo* getGLTextureInfo() const;
Greg Danielc0f8e422017-06-13 13:47:53 -040048
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000049#ifdef SK_VULKAN
50 // If the backend API is Vulkan, this returns a pointer to the GrVkImageInfo struct. Otherwise
51 // it returns nullptr.
52 const GrVkImageInfo* getVkImageInfo() const;
53#endif
54
Brian Salomon8fe24272017-07-07 12:56:11 -040055 // If the backend API is Mock, this returns a pointer to the GrMockTextureInfo struct. Otherwise
56 // it returns nullptr.
57 const GrMockTextureInfo* getMockTextureInfo() const;
58
Greg Daniel94403452017-04-18 15:52:36 -040059private:
Brian Salomon8fe24272017-07-07 12:56:11 -040060 bool isValid() const { return fConfig != kUnknown_GrPixelConfig; }
61
Greg Daniel94403452017-04-18 15:52:36 -040062 int fWidth; //<! width in pixels
63 int fHeight; //<! height in pixels
64 GrPixelConfig fConfig;
65 GrBackend fBackend;
66
67 union {
Robert Phillipsfad9e3f2017-06-13 22:16:08 +000068 GrGLTextureInfo fGLInfo;
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000069#ifdef SK_VULKAN
70 GrVkImageInfo fVkInfo;
71#endif
Brian Salomon8fe24272017-07-07 12:56:11 -040072 GrMockTextureInfo fMockInfo;
Greg Daniel94403452017-04-18 15:52:36 -040073 };
74};
75
Brian Salomonec045b42017-07-07 10:34:40 -040076class SK_API GrBackendRenderTarget {
Greg Daniel94403452017-04-18 15:52:36 -040077public:
78 GrBackendRenderTarget(int width,
79 int height,
80 int sampleCnt,
81 int stencilBits,
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000082 GrPixelConfig config,
83 const GrGLFramebufferInfo& glInfo);
Greg Daniel94403452017-04-18 15:52:36 -040084
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000085#ifdef SK_VULKAN
Greg Daniel94403452017-04-18 15:52:36 -040086 GrBackendRenderTarget(int width,
87 int height,
88 int sampleCnt,
89 int stencilBits,
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +000090 const GrVkImageInfo& vkInfo);
91#endif
Greg Daniel94403452017-04-18 15:52:36 -040092
93 int width() const { return fWidth; }
94 int height() const { return fHeight; }
95 int sampleCnt() const { return fSampleCnt; }
96 int stencilBits() const { return fStencilBits; }
97 GrPixelConfig config() const { return fConfig; }
98 GrBackend backend() const {return fBackend; }
99
Robert Phillipsfad9e3f2017-06-13 22:16:08 +0000100 // If the backend API is GL, this returns a pointer to the GrGLFramebufferInfo struct. Otherwise
101 // it returns nullptr.
102 const GrGLFramebufferInfo* getGLFramebufferInfo() const;
Greg Danielc0f8e422017-06-13 13:47:53 -0400103
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000104#ifdef SK_VULKAN
105 // If the backend API is Vulkan, this returns a pointer to the GrVkImageInfo struct. Otherwise
106 // it returns nullptr
107 const GrVkImageInfo* getVkImageInfo() const;
108#endif
109
Greg Daniel94403452017-04-18 15:52:36 -0400110private:
Brian Salomon807371c2017-07-20 20:48:12 +0000111 // Temporary constructor which can be used to convert from a GrBackendRenderTargetDesc.
112 GrBackendRenderTarget(const GrBackendRenderTargetDesc& desc, GrBackend backend);
113
114 // Friending for access to above constructor taking a GrBackendRenderTargetDesc
115 friend class SkSurface;
116
Greg Daniel94403452017-04-18 15:52:36 -0400117 int fWidth; //<! width in pixels
118 int fHeight; //<! height in pixels
119
120 int fSampleCnt;
121 int fStencilBits;
122 GrPixelConfig fConfig;
123
124 GrBackend fBackend;
125
126 union {
Robert Phillipsfad9e3f2017-06-13 22:16:08 +0000127 GrGLFramebufferInfo fGLInfo;
Robert Phillipsfcd5fdd2017-06-14 01:43:29 +0000128#ifdef SK_VULKAN
129 GrVkImageInfo fVkInfo;
130#endif
Greg Daniel94403452017-04-18 15:52:36 -0400131 };
132};
133
134#endif
135