SkSurfaceCharacterization.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. #ifndef SkSurfaceCharacterization_DEFINED
  8. #define SkSurfaceCharacterization_DEFINED
  9. #include "include/gpu/GrTypes.h"
  10. #include "include/core/SkColorSpace.h"
  11. #include "include/core/SkRefCnt.h"
  12. #include "include/core/SkSurfaceProps.h"
  13. class SkColorSpace;
  14. #if SK_SUPPORT_GPU
  15. #include "include/gpu/GrBackendSurface.h"
  16. // TODO: remove the GrContext.h include once Flutter is updated
  17. #include "include/gpu/GrContext.h"
  18. #include "include/gpu/GrContextThreadSafeProxy.h"
  19. /** \class SkSurfaceCharacterization
  20. A surface characterization contains all the information Ganesh requires to makes its internal
  21. rendering decisions. When passed into a SkDeferredDisplayListRecorder it will copy the
  22. data and pass it on to the SkDeferredDisplayList if/when it is created. Note that both of
  23. those objects (the Recorder and the DisplayList) will take a ref on the
  24. GrContextThreadSafeProxy and SkColorSpace objects.
  25. */
  26. class SK_API SkSurfaceCharacterization {
  27. public:
  28. enum class Textureable : bool { kNo = false, kYes = true };
  29. enum class MipMapped : bool { kNo = false, kYes = true };
  30. enum class UsesGLFBO0 : bool { kNo = false, kYes = true };
  31. // This flag indicates if the surface is wrapping a raw Vulkan secondary command buffer.
  32. enum class VulkanSecondaryCBCompatible : bool { kNo = false, kYes = true };
  33. SkSurfaceCharacterization()
  34. : fCacheMaxResourceBytes(0)
  35. , fOrigin(kBottomLeft_GrSurfaceOrigin)
  36. , fSampleCnt(0)
  37. , fIsTextureable(Textureable::kYes)
  38. , fIsMipMapped(MipMapped::kYes)
  39. , fUsesGLFBO0(UsesGLFBO0::kNo)
  40. , fVulkanSecondaryCBCompatible(VulkanSecondaryCBCompatible::kNo)
  41. , fIsProtected(GrProtected::kNo)
  42. , fSurfaceProps(0, kUnknown_SkPixelGeometry) {
  43. }
  44. SkSurfaceCharacterization(SkSurfaceCharacterization&&) = default;
  45. SkSurfaceCharacterization& operator=(SkSurfaceCharacterization&&) = default;
  46. SkSurfaceCharacterization(const SkSurfaceCharacterization&) = default;
  47. SkSurfaceCharacterization& operator=(const SkSurfaceCharacterization& other) = default;
  48. bool operator==(const SkSurfaceCharacterization& other) const;
  49. bool operator!=(const SkSurfaceCharacterization& other) const {
  50. return !(*this == other);
  51. }
  52. SkSurfaceCharacterization createResized(int width, int height) const;
  53. GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); }
  54. sk_sp<GrContextThreadSafeProxy> refContextInfo() const { return fContextInfo; }
  55. size_t cacheMaxResourceBytes() const { return fCacheMaxResourceBytes; }
  56. bool isValid() const { return kUnknown_SkColorType != fImageInfo.colorType(); }
  57. const SkImageInfo& imageInfo() const { return fImageInfo; }
  58. const GrBackendFormat& backendFormat() const { return fBackendFormat; }
  59. GrSurfaceOrigin origin() const { return fOrigin; }
  60. int width() const { return fImageInfo.width(); }
  61. int height() const { return fImageInfo.height(); }
  62. SkColorType colorType() const { return fImageInfo.colorType(); }
  63. int sampleCount() const { return fSampleCnt; }
  64. bool isTextureable() const { return Textureable::kYes == fIsTextureable; }
  65. bool isMipMapped() const { return MipMapped::kYes == fIsMipMapped; }
  66. bool usesGLFBO0() const { return UsesGLFBO0::kYes == fUsesGLFBO0; }
  67. bool vulkanSecondaryCBCompatible() const {
  68. return VulkanSecondaryCBCompatible::kYes == fVulkanSecondaryCBCompatible;
  69. }
  70. GrProtected isProtected() const { return fIsProtected; }
  71. SkColorSpace* colorSpace() const { return fImageInfo.colorSpace(); }
  72. sk_sp<SkColorSpace> refColorSpace() const { return fImageInfo.refColorSpace(); }
  73. const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
  74. // Is the provided backend texture compatible with this surface characterization?
  75. bool isCompatible(const GrBackendTexture&) const;
  76. private:
  77. friend class SkSurface_Gpu; // for 'set' & 'config'
  78. friend class GrVkSecondaryCBDrawContext; // for 'set' & 'config'
  79. friend class GrContextThreadSafeProxy; // for private ctor
  80. friend class SkDeferredDisplayListRecorder; // for 'config'
  81. friend class SkSurface; // for 'config'
  82. SkDEBUGCODE(void validate() const;)
  83. SkSurfaceCharacterization(sk_sp<GrContextThreadSafeProxy> contextInfo,
  84. size_t cacheMaxResourceBytes,
  85. const SkImageInfo& ii,
  86. const GrBackendFormat& backendFormat,
  87. GrSurfaceOrigin origin,
  88. int sampleCnt,
  89. Textureable isTextureable,
  90. MipMapped isMipMapped,
  91. UsesGLFBO0 usesGLFBO0,
  92. VulkanSecondaryCBCompatible vulkanSecondaryCBCompatible,
  93. GrProtected isProtected,
  94. const SkSurfaceProps& surfaceProps)
  95. : fContextInfo(std::move(contextInfo))
  96. , fCacheMaxResourceBytes(cacheMaxResourceBytes)
  97. , fImageInfo(ii)
  98. , fBackendFormat(backendFormat)
  99. , fOrigin(origin)
  100. , fSampleCnt(sampleCnt)
  101. , fIsTextureable(isTextureable)
  102. , fIsMipMapped(isMipMapped)
  103. , fUsesGLFBO0(usesGLFBO0)
  104. , fVulkanSecondaryCBCompatible(vulkanSecondaryCBCompatible)
  105. , fIsProtected(isProtected)
  106. , fSurfaceProps(surfaceProps) {
  107. SkDEBUGCODE(this->validate());
  108. }
  109. void set(sk_sp<GrContextThreadSafeProxy> contextInfo,
  110. size_t cacheMaxResourceBytes,
  111. const SkImageInfo& ii,
  112. const GrBackendFormat& backendFormat,
  113. GrSurfaceOrigin origin,
  114. int sampleCnt,
  115. Textureable isTextureable,
  116. MipMapped isMipMapped,
  117. UsesGLFBO0 usesGLFBO0,
  118. VulkanSecondaryCBCompatible vulkanSecondaryCBCompatible,
  119. GrProtected isProtected,
  120. const SkSurfaceProps& surfaceProps) {
  121. SkASSERT(MipMapped::kNo == isMipMapped || Textureable::kYes == isTextureable);
  122. SkASSERT(Textureable::kNo == isTextureable || UsesGLFBO0::kNo == usesGLFBO0);
  123. SkASSERT(VulkanSecondaryCBCompatible::kNo == vulkanSecondaryCBCompatible ||
  124. UsesGLFBO0::kNo == usesGLFBO0);
  125. SkASSERT(Textureable::kNo == isTextureable ||
  126. VulkanSecondaryCBCompatible::kNo == vulkanSecondaryCBCompatible);
  127. fContextInfo = contextInfo;
  128. fCacheMaxResourceBytes = cacheMaxResourceBytes;
  129. fImageInfo = ii;
  130. fBackendFormat = backendFormat;
  131. fOrigin = origin;
  132. fSampleCnt = sampleCnt;
  133. fIsTextureable = isTextureable;
  134. fIsMipMapped = isMipMapped;
  135. fUsesGLFBO0 = usesGLFBO0;
  136. fVulkanSecondaryCBCompatible = vulkanSecondaryCBCompatible;
  137. fIsProtected = isProtected;
  138. fSurfaceProps = surfaceProps;
  139. SkDEBUGCODE(this->validate());
  140. }
  141. sk_sp<GrContextThreadSafeProxy> fContextInfo;
  142. size_t fCacheMaxResourceBytes;
  143. SkImageInfo fImageInfo;
  144. GrBackendFormat fBackendFormat;
  145. GrSurfaceOrigin fOrigin;
  146. int fSampleCnt;
  147. Textureable fIsTextureable;
  148. MipMapped fIsMipMapped;
  149. UsesGLFBO0 fUsesGLFBO0;
  150. VulkanSecondaryCBCompatible fVulkanSecondaryCBCompatible;
  151. GrProtected fIsProtected;
  152. SkSurfaceProps fSurfaceProps;
  153. };
  154. #else// !SK_SUPPORT_GPU
  155. class SK_API SkSurfaceCharacterization {
  156. public:
  157. SkSurfaceCharacterization() : fSurfaceProps(0, kUnknown_SkPixelGeometry) { }
  158. SkSurfaceCharacterization createResized(int width, int height) const {
  159. return *this;
  160. }
  161. bool operator==(const SkSurfaceCharacterization& other) const { return false; }
  162. bool operator!=(const SkSurfaceCharacterization& other) const {
  163. return !(*this == other);
  164. }
  165. size_t cacheMaxResourceBytes() const { return 0; }
  166. bool isValid() const { return false; }
  167. int width() const { return 0; }
  168. int height() const { return 0; }
  169. int stencilCount() const { return 0; }
  170. bool isTextureable() const { return false; }
  171. bool isMipMapped() const { return false; }
  172. bool usesGLFBO0() const { return false; }
  173. bool vulkanSecondaryCBCompatible() const { return false; }
  174. SkColorSpace* colorSpace() const { return nullptr; }
  175. sk_sp<SkColorSpace> refColorSpace() const { return nullptr; }
  176. const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
  177. private:
  178. SkSurfaceProps fSurfaceProps;
  179. };
  180. #endif
  181. #endif