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#ifndef GrBackendSurface_DEFINED
9#define GrBackendSurface_DEFINED
10
11#include "GrTypes.h"
12#include "gl/GrGLTypes.h"
13#include "mock/GrMockTypes.h"
14
15#ifdef SK_VULKAN
16#include "vk/GrVkTypes.h"
17#endif
18
19class SK_API GrBackendTexture {
20public:
21    // Creates an invalid backend texture.
22    GrBackendTexture() : fConfig(kUnknown_GrPixelConfig) {}
23
24    GrBackendTexture(int width,
25                     int height,
26                     GrPixelConfig config,
27                     const GrGLTextureInfo& glInfo);
28
29#ifdef SK_VULKAN
30    GrBackendTexture(int width,
31                     int height,
32                     const GrVkImageInfo& vkInfo);
33#endif
34
35    GrBackendTexture(int width,
36                     int height,
37                     GrPixelConfig config,
38                     const GrMockTextureInfo& mockInfo);
39
40    int width() const { return fWidth; }
41    int height() const { return fHeight; }
42    GrPixelConfig config() const { return fConfig; }
43    GrBackend backend() const {return fBackend; }
44
45    // If the backend API is GL, this returns a pointer to the GrGLTextureInfo struct. Otherwise
46    // it returns nullptr.
47    const GrGLTextureInfo* getGLTextureInfo() const;
48
49#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
55    // 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
59private:
60    bool isValid() const { return fConfig != kUnknown_GrPixelConfig; }
61
62    // Temporary constructor which can be used to convert from a GrBackendTextureDesc.
63    GrBackendTexture(const GrBackendTextureDesc& desc, GrBackend backend);
64
65    // Friending for access to above constructor taking a GrBackendTextureDesc
66    friend class SkImage;
67    friend class SkSurface;
68
69    int fWidth;         //<! width in pixels
70    int fHeight;        //<! height in pixels
71    GrPixelConfig fConfig;
72    GrBackend fBackend;
73
74    union {
75        GrGLTextureInfo fGLInfo;
76#ifdef SK_VULKAN
77        GrVkImageInfo   fVkInfo;
78#endif
79        GrMockTextureInfo fMockInfo;
80    };
81};
82
83class SK_API GrBackendRenderTarget {
84public:
85    GrBackendRenderTarget(int width,
86                          int height,
87                          int sampleCnt,
88                          int stencilBits,
89                          GrPixelConfig config,
90                          const GrGLFramebufferInfo& glInfo);
91
92#ifdef SK_VULKAN
93    GrBackendRenderTarget(int width,
94                          int height,
95                          int sampleCnt,
96                          int stencilBits,
97                          const GrVkImageInfo& vkInfo);
98#endif
99
100    int width() const { return fWidth; }
101    int height() const { return fHeight; }
102    int sampleCnt() const { return fSampleCnt; }
103    int stencilBits() const { return fStencilBits; }
104    GrPixelConfig config() const { return fConfig; }
105    GrBackend backend() const {return fBackend; }
106
107    // If the backend API is GL, this returns a pointer to the GrGLFramebufferInfo struct. Otherwise
108    // it returns nullptr.
109    const GrGLFramebufferInfo* getGLFramebufferInfo() const;
110
111#ifdef SK_VULKAN
112    // If the backend API is Vulkan, this returns a pointer to the GrVkImageInfo struct. Otherwise
113    // it returns nullptr
114    const GrVkImageInfo* getVkImageInfo() const;
115#endif
116
117private:
118    // Temporary constructor which can be used to convert from a GrBackendRenderTargetDesc.
119    GrBackendRenderTarget(const GrBackendRenderTargetDesc& desc, GrBackend backend);
120
121    // Friending for access to above constructor taking a GrBackendTextureDesc
122    friend class SkSurface;
123
124    int fWidth;         //<! width in pixels
125    int fHeight;        //<! height in pixels
126
127    int fSampleCnt;
128    int fStencilBits;
129    GrPixelConfig fConfig;
130
131    GrBackend fBackend;
132
133    union {
134        GrGLFramebufferInfo fGLInfo;
135#ifdef SK_VULKAN
136        GrVkImageInfo   fVkInfo;
137#endif
138    };
139};
140
141#endif
142
143