Skia
2D Graphics Library
SkSurfaceCharacterization.h
Go to the documentation of this file.
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 SkSurfaceCharacterization_DEFINED
9 #define SkSurfaceCharacterization_DEFINED
10 
11 #include "include/gpu/GrTypes.h"
12 
15 #include "include/core/SkRefCnt.h"
17 
18 class SkColorSpace;
19 
21 
22 #if SK_SUPPORT_GPU
24 
33 public:
34  enum class Textureable : bool { kNo = false, kYes = true };
35  enum class MipMapped : bool { kNo = false, kYes = true };
36  enum class UsesGLFBO0 : bool { kNo = false, kYes = true };
37  // This flag indicates that the backing VkImage for this Vulkan surface will have the
38  // VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set. This bit allows skia to handle advanced blends
39  // more optimally in a shader by being able to directly read the dst values.
40  enum class VkRTSupportsInputAttachment : bool { kNo = false, kYes = true };
41  // This flag indicates if the surface is wrapping a raw Vulkan secondary command buffer.
42  enum class VulkanSecondaryCBCompatible : bool { kNo = false, kYes = true };
43 
45  : fCacheMaxResourceBytes(0)
47  , fSampleCnt(0)
48  , fIsTextureable(Textureable::kYes)
49  , fIsMipMapped(MipMapped::kYes)
50  , fUsesGLFBO0(UsesGLFBO0::kNo)
51  , fVulkanSecondaryCBCompatible(VulkanSecondaryCBCompatible::kNo)
52  , fIsProtected(GrProtected::kNo)
53  , fSurfaceProps(0, kUnknown_SkPixelGeometry) {
54  }
55 
58 
60  SkSurfaceCharacterization& operator=(const SkSurfaceCharacterization& other) = default;
61  bool operator==(const SkSurfaceCharacterization& other) const;
62  bool operator!=(const SkSurfaceCharacterization& other) const {
63  return !(*this == other);
64  }
65 
66  /*
67  * Return a new surface characterization with the only difference being a different width
68  * and height
69  */
70  SkSurfaceCharacterization createResized(int width, int height) const;
71 
72  /*
73  * Return a new surface characterization with only a replaced color space
74  */
75  SkSurfaceCharacterization createColorSpace(sk_sp<SkColorSpace>) const;
76 
77  /*
78  * Return a new surface characterization with the backend format replaced. A colorType
79  * must also be supplied to indicate the interpretation of the new format.
80  */
81  SkSurfaceCharacterization createBackendFormat(SkColorType colorType,
82  const GrBackendFormat& backendFormat) const;
83 
84  /*
85  * Return a new surface characterization with just a different use of FBO0 (in GL)
86  */
87  SkSurfaceCharacterization createFBO0(bool usesGLFBO0) const;
88 
89  GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); }
90  sk_sp<GrContextThreadSafeProxy> refContextInfo() const { return fContextInfo; }
91  size_t cacheMaxResourceBytes() const { return fCacheMaxResourceBytes; }
92 
93  bool isValid() const { return kUnknown_SkColorType != fImageInfo.colorType(); }
94 
95  const SkImageInfo& imageInfo() const { return fImageInfo; }
96  const GrBackendFormat& backendFormat() const { return fBackendFormat; }
97  GrSurfaceOrigin origin() const { return fOrigin; }
98  SkISize dimensions() const { return fImageInfo.dimensions(); }
99  int width() const { return fImageInfo.width(); }
100  int height() const { return fImageInfo.height(); }
101  SkColorType colorType() const { return fImageInfo.colorType(); }
102  int sampleCount() const { return fSampleCnt; }
103  bool isTextureable() const { return Textureable::kYes == fIsTextureable; }
104  bool isMipMapped() const { return MipMapped::kYes == fIsMipMapped; }
105  bool usesGLFBO0() const { return UsesGLFBO0::kYes == fUsesGLFBO0; }
106  bool vkRTSupportsInputAttachment() const {
107  return VkRTSupportsInputAttachment::kYes == fVkRTSupportsInputAttachment;
108  }
109  bool vulkanSecondaryCBCompatible() const {
110  return VulkanSecondaryCBCompatible::kYes == fVulkanSecondaryCBCompatible;
111  }
112  GrProtected isProtected() const { return fIsProtected; }
113  SkColorSpace* colorSpace() const { return fImageInfo.colorSpace(); }
114  sk_sp<SkColorSpace> refColorSpace() const { return fImageInfo.refColorSpace(); }
115  const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
116 
117  // Is the provided backend texture compatible with this surface characterization?
118  bool isCompatible(const GrBackendTexture&) const;
119 
120 private:
121  friend class SkSurface_Gpu; // for 'set' & 'config'
122  friend class GrVkSecondaryCBDrawContext; // for 'set' & 'config'
123  friend class GrContextThreadSafeProxy; // for private ctor
124  friend class SkDeferredDisplayListRecorder; // for 'config'
125  friend class SkSurface; // for 'config'
126 
127  SkDEBUGCODE(void validate() const;)
128 
130  size_t cacheMaxResourceBytes,
131  const SkImageInfo& ii,
132  const GrBackendFormat& backendFormat,
133  GrSurfaceOrigin origin,
134  int sampleCnt,
135  Textureable isTextureable,
136  MipMapped isMipMapped,
137  UsesGLFBO0 usesGLFBO0,
138  VkRTSupportsInputAttachment vkRTSupportsInputAttachment,
139  VulkanSecondaryCBCompatible vulkanSecondaryCBCompatible,
140  GrProtected isProtected,
141  const SkSurfaceProps& surfaceProps)
142  : fContextInfo(std::move(contextInfo))
143  , fCacheMaxResourceBytes(cacheMaxResourceBytes)
144  , fImageInfo(ii)
145  , fBackendFormat(backendFormat)
146  , fOrigin(origin)
147  , fSampleCnt(sampleCnt)
148  , fIsTextureable(isTextureable)
149  , fIsMipMapped(isMipMapped)
150  , fUsesGLFBO0(usesGLFBO0)
151  , fVkRTSupportsInputAttachment(vkRTSupportsInputAttachment)
152  , fVulkanSecondaryCBCompatible(vulkanSecondaryCBCompatible)
153  , fIsProtected(isProtected)
154  , fSurfaceProps(surfaceProps) {
155  SkDEBUGCODE(this->validate());
156  }
157 
158  void set(sk_sp<GrContextThreadSafeProxy> contextInfo,
159  size_t cacheMaxResourceBytes,
160  const SkImageInfo& ii,
161  const GrBackendFormat& backendFormat,
162  GrSurfaceOrigin origin,
163  int sampleCnt,
164  Textureable isTextureable,
165  MipMapped isMipMapped,
166  UsesGLFBO0 usesGLFBO0,
167  VkRTSupportsInputAttachment vkRTSupportsInputAttachment,
168  VulkanSecondaryCBCompatible vulkanSecondaryCBCompatible,
169  GrProtected isProtected,
170  const SkSurfaceProps& surfaceProps) {
171  fContextInfo = contextInfo;
172  fCacheMaxResourceBytes = cacheMaxResourceBytes;
173 
174  fImageInfo = ii;
175  fBackendFormat = backendFormat;
176  fOrigin = origin;
177  fSampleCnt = sampleCnt;
178  fIsTextureable = isTextureable;
179  fIsMipMapped = isMipMapped;
180  fUsesGLFBO0 = usesGLFBO0;
181  fVkRTSupportsInputAttachment = vkRTSupportsInputAttachment;
182  fVulkanSecondaryCBCompatible = vulkanSecondaryCBCompatible;
183  fIsProtected = isProtected;
184  fSurfaceProps = surfaceProps;
185 
186  SkDEBUGCODE(this->validate());
187  }
188 
189  sk_sp<GrContextThreadSafeProxy> fContextInfo;
190  size_t fCacheMaxResourceBytes;
191 
192  SkImageInfo fImageInfo;
193  GrBackendFormat fBackendFormat;
194  GrSurfaceOrigin fOrigin;
195  int fSampleCnt;
196  Textureable fIsTextureable;
197  MipMapped fIsMipMapped;
198  UsesGLFBO0 fUsesGLFBO0;
199  VkRTSupportsInputAttachment fVkRTSupportsInputAttachment;
200  VulkanSecondaryCBCompatible fVulkanSecondaryCBCompatible;
201  GrProtected fIsProtected;
202  SkSurfaceProps fSurfaceProps;
203 };
204 
205 #else// !SK_SUPPORT_GPU
206 
208 public:
210 
211  SkSurfaceCharacterization createResized(int width, int height) const {
212  return *this;
213  }
214 
216  return *this;
217  }
218 
220  return *this;
221  }
222 
223  SkSurfaceCharacterization createFBO0(bool usesGLFBO0) const {
224  return *this;
225  }
226 
227  bool operator==(const SkSurfaceCharacterization& other) const { return false; }
228  bool operator!=(const SkSurfaceCharacterization& other) const {
229  return !(*this == other);
230  }
231 
232  size_t cacheMaxResourceBytes() const { return 0; }
233 
234  bool isValid() const { return false; }
235 
236  int width() const { return 0; }
237  int height() const { return 0; }
238  int stencilCount() const { return 0; }
239  bool isTextureable() const { return false; }
240  bool isMipMapped() const { return false; }
241  bool usesGLFBO0() const { return false; }
242  bool vkRTSupportsAttachmentInput() const { return false; }
243  bool vulkanSecondaryCBCompatible() const { return false; }
244  SkColorSpace* colorSpace() const { return nullptr; }
245  sk_sp<SkColorSpace> refColorSpace() const { return nullptr; }
246  const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
247 
248 private:
249  SkSurfaceProps fSurfaceProps;
250 };
251 
252 #endif
253 
254 #endif
SkSurfaceCharacterization::createBackendFormat
SkSurfaceCharacterization createBackendFormat(SkColorType, const GrBackendFormat &) const
Definition: SkSurfaceCharacterization.h:219
SkSurfaceCharacterization::vkRTSupportsAttachmentInput
bool vkRTSupportsAttachmentInput() const
Definition: SkSurfaceCharacterization.h:242
operator==
bool operator==(const sk_sp< T > &a, const sk_sp< U > &b)
Definition: SkRefCnt.h:338
SkSurfaceCharacterization::height
int height() const
Definition: SkSurfaceCharacterization.h:237
SkColorSpace.h
SkSurface
Definition: SkSurface.h:46
GrSurfaceOrigin
GrSurfaceOrigin
GPU SkImage and SkSurfaces can be stored such that (0, 0) in texture space may correspond to either t...
Definition: GrTypes.h:198
SkSurfaceCharacterization::isValid
bool isValid() const
Definition: SkSurfaceCharacterization.h:234
SkApplyPerspectiveClip::kYes
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
GrProtected
GrProtected
Definition: GrTypes.h:187
SkDeferredDisplayListRecorder
Definition: SkDeferredDisplayListRecorder.h:38
SkISize::width
constexpr int32_t width() const
Definition: SkSize.h:33
SkSurfaceCharacterization::vulkanSecondaryCBCompatible
bool vulkanSecondaryCBCompatible() const
Definition: SkSurfaceCharacterization.h:243
SkSurfaceCharacterization::createFBO0
SkSurfaceCharacterization createFBO0(bool usesGLFBO0) const
Definition: SkSurfaceCharacterization.h:223
SkSurfaceCharacterization::colorSpace
SkColorSpace * colorSpace() const
Definition: SkSurfaceCharacterization.h:244
operator!=
bool operator!=(const sk_sp< T > &a, const sk_sp< U > &b)
Definition: SkRefCnt.h:348
SkSurfaceCharacterization::stencilCount
int stencilCount() const
Definition: SkSurfaceCharacterization.h:238
SkRefCnt.h
kUnknown_SkPixelGeometry
@ kUnknown_SkPixelGeometry
Definition: SkSurfaceProps.h:19
sk_sp< SkColorSpace >
SkSurfaceCharacterization::isTextureable
bool isTextureable() const
Definition: SkSurfaceCharacterization.h:239
GrBackendSurface.h
GrBackendFormat
Definition: GrBackendSurface.h:48
SkSurfaceCharacterization::isMipMapped
bool isMipMapped() const
Definition: SkSurfaceCharacterization.h:240
SkDEBUGCODE
#define SkDEBUGCODE(...)
Definition: SkTypes.h:467
SK_API
#define SK_API
Definition: SkTypes.h:181
SkSurfaceProps
Describes properties and constraints of a given SkSurface.
Definition: SkSurfaceProps.h:51
SkImageInfo
Definition: SkImageInfo.h:283
SkISize
Definition: SkSize.h:13
SkSurfaceCharacterization::cacheMaxResourceBytes
size_t cacheMaxResourceBytes() const
Definition: SkSurfaceCharacterization.h:232
SkSurfaceProps.h
SkSurfaceCharacterization::operator!=
bool operator!=(const SkSurfaceCharacterization &other) const
Definition: SkSurfaceCharacterization.h:228
SkSurfaceCharacterization::createResized
SkSurfaceCharacterization createResized(int width, int height) const
Definition: SkSurfaceCharacterization.h:211
SkApplyPerspectiveClip::kNo
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.
GrTypes.h
SkSurfaceCharacterization::surfaceProps
const SkSurfaceProps & surfaceProps() const
Definition: SkSurfaceCharacterization.h:246
GrContextThreadSafeProxy.h
SkSurfaceCharacterization
Definition: SkSurfaceCharacterization.h:207
SkSurfaceCharacterization::refColorSpace
sk_sp< SkColorSpace > refColorSpace() const
Definition: SkSurfaceCharacterization.h:245
GrBackendTexture
Definition: GrBackendSurface.h:54
GrContextThreadSafeProxy
Definition: GrContextThreadSafeProxy.h:145
SkSurfaceCharacterization::SkSurfaceCharacterization
SkSurfaceCharacterization()
Definition: SkSurfaceCharacterization.h:209
SkColorType
SkColorType
Definition: SkImageInfo.h:64
kUnknown_SkColorType
@ kUnknown_SkColorType
uninitialized
Definition: SkImageInfo.h:65
SkSurfaceCharacterization::operator==
bool operator==(const SkSurfaceCharacterization &other) const
Definition: SkSurfaceCharacterization.h:227
SkSurfaceCharacterization::createColorSpace
SkSurfaceCharacterization createColorSpace(sk_sp< SkColorSpace >) const
Definition: SkSurfaceCharacterization.h:215
SkImageInfo.h
kBottomLeft_GrSurfaceOrigin
@ kBottomLeft_GrSurfaceOrigin
Definition: GrTypes.h:200
SkSurfaceCharacterization::width
int width() const
Definition: SkSurfaceCharacterization.h:236
SkColorSpace
Definition: SkColorSpace.h:104
SkSurfaceCharacterization::usesGLFBO0
bool usesGLFBO0() const
Definition: SkSurfaceCharacterization.h:241