SkSurfaceCharacterization.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 "GrTypes.h"
  10. #include "SkColorSpace.h"
  11. #include "SkRefCnt.h"
  12. #include "SkSurfaceProps.h"
  13. class SkColorSpace;
  14. #if SK_SUPPORT_GPU
  15. #include "GrContext.h"
  16. /** \class SkSurfaceCharacterization
  17. A surface characterization contains all the information Ganesh requires to makes its internal
  18. rendering decisions. When passed into a SkDeferredDisplayListRecorder it will copy the
  19. data and pass it on to the SkDeferredDisplayList if/when it is created. Note that both of
  20. those objects (the Recorder and the DisplayList) will take a ref on the
  21. GrContextThreadSafeProxy and SkColorSpace objects.
  22. */
  23. class SK_API SkSurfaceCharacterization {
  24. public:
  25. enum class Textureable : bool { kNo = false, kYes = true };
  26. enum class MipMapped : bool { kNo = false, kYes = true };
  27. enum class UsesGLFBO0 : bool { kNo = false, kYes = true };
  28. SkSurfaceCharacterization()
  29. : fCacheMaxResourceBytes(0)
  30. , fOrigin(kBottomLeft_GrSurfaceOrigin)
  31. , fConfig(kUnknown_GrPixelConfig)
  32. , fFSAAType(GrFSAAType::kNone)
  33. , fStencilCnt(0)
  34. , fIsTextureable(Textureable::kYes)
  35. , fIsMipMapped(MipMapped::kYes)
  36. , fUsesGLFBO0(UsesGLFBO0::kNo)
  37. , fSurfaceProps(0, kUnknown_SkPixelGeometry) {
  38. }
  39. SkSurfaceCharacterization(SkSurfaceCharacterization&&) = default;
  40. SkSurfaceCharacterization& operator=(SkSurfaceCharacterization&&) = default;
  41. SkSurfaceCharacterization(const SkSurfaceCharacterization&) = default;
  42. SkSurfaceCharacterization& operator=(const SkSurfaceCharacterization& other) = default;
  43. bool operator==(const SkSurfaceCharacterization& other) const;
  44. bool operator!=(const SkSurfaceCharacterization& other) const {
  45. return !(*this == other);
  46. }
  47. SkSurfaceCharacterization createResized(int width, int height) const;
  48. GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); }
  49. sk_sp<GrContextThreadSafeProxy> refContextInfo() const { return fContextInfo; }
  50. size_t cacheMaxResourceBytes() const { return fCacheMaxResourceBytes; }
  51. bool isValid() const { return kUnknown_SkColorType != fImageInfo.colorType(); }
  52. const SkImageInfo& imageInfo() const { return fImageInfo; }
  53. GrSurfaceOrigin origin() const { return fOrigin; }
  54. int width() const { return fImageInfo.width(); }
  55. int height() const { return fImageInfo.height(); }
  56. SkColorType colorType() const { return fImageInfo.colorType(); }
  57. GrFSAAType fsaaType() const { return fFSAAType; }
  58. int stencilCount() const { return fStencilCnt; }
  59. bool isTextureable() const { return Textureable::kYes == fIsTextureable; }
  60. bool isMipMapped() const { return MipMapped::kYes == fIsMipMapped; }
  61. bool usesGLFBO0() const { return UsesGLFBO0::kYes == fUsesGLFBO0; }
  62. SkColorSpace* colorSpace() const { return fImageInfo.colorSpace(); }
  63. sk_sp<SkColorSpace> refColorSpace() const { return fImageInfo.refColorSpace(); }
  64. const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
  65. private:
  66. friend class SkSurface_Gpu; // for 'set' & 'config'
  67. friend class GrContextThreadSafeProxy; // for private ctor
  68. friend class SkDeferredDisplayListRecorder; // for 'config'
  69. friend class SkSurface; // for 'config'
  70. GrPixelConfig config() const { return fConfig; }
  71. SkSurfaceCharacterization(sk_sp<GrContextThreadSafeProxy> contextInfo,
  72. size_t cacheMaxResourceBytes,
  73. const SkImageInfo& ii,
  74. GrSurfaceOrigin origin,
  75. GrPixelConfig config,
  76. GrFSAAType FSAAType, int stencilCnt,
  77. Textureable isTextureable, MipMapped isMipMapped,
  78. UsesGLFBO0 usesGLFBO0,
  79. const SkSurfaceProps& surfaceProps)
  80. : fContextInfo(std::move(contextInfo))
  81. , fCacheMaxResourceBytes(cacheMaxResourceBytes)
  82. , fImageInfo(ii)
  83. , fOrigin(origin)
  84. , fConfig(config)
  85. , fFSAAType(FSAAType)
  86. , fStencilCnt(stencilCnt)
  87. , fIsTextureable(isTextureable)
  88. , fIsMipMapped(isMipMapped)
  89. , fUsesGLFBO0(usesGLFBO0)
  90. , fSurfaceProps(surfaceProps) {
  91. }
  92. void set(sk_sp<GrContextThreadSafeProxy> contextInfo,
  93. size_t cacheMaxResourceBytes,
  94. const SkImageInfo& ii,
  95. GrSurfaceOrigin origin,
  96. GrPixelConfig config,
  97. GrFSAAType fsaaType,
  98. int stencilCnt,
  99. Textureable isTextureable,
  100. MipMapped isMipMapped,
  101. UsesGLFBO0 usesGLFBO0,
  102. const SkSurfaceProps& surfaceProps) {
  103. SkASSERT(MipMapped::kNo == isMipMapped || Textureable::kYes == isTextureable);
  104. SkASSERT(Textureable::kNo == isTextureable || UsesGLFBO0::kNo == usesGLFBO0);
  105. fContextInfo = contextInfo;
  106. fCacheMaxResourceBytes = cacheMaxResourceBytes;
  107. fImageInfo = ii;
  108. fOrigin = origin;
  109. fConfig = config;
  110. fFSAAType = fsaaType;
  111. fStencilCnt = stencilCnt;
  112. fIsTextureable = isTextureable;
  113. fIsMipMapped = isMipMapped;
  114. fUsesGLFBO0 = usesGLFBO0;
  115. fSurfaceProps = surfaceProps;
  116. }
  117. sk_sp<GrContextThreadSafeProxy> fContextInfo;
  118. size_t fCacheMaxResourceBytes;
  119. SkImageInfo fImageInfo;
  120. GrSurfaceOrigin fOrigin;
  121. GrPixelConfig fConfig;
  122. GrFSAAType fFSAAType;
  123. int fStencilCnt;
  124. Textureable fIsTextureable;
  125. MipMapped fIsMipMapped;
  126. UsesGLFBO0 fUsesGLFBO0;
  127. SkSurfaceProps fSurfaceProps;
  128. };
  129. #else// !SK_SUPPORT_GPU
  130. class SK_API SkSurfaceCharacterization {
  131. public:
  132. SkSurfaceCharacterization() : fSurfaceProps(0, kUnknown_SkPixelGeometry) { }
  133. SkSurfaceCharacterization createResized(int width, int height) const {
  134. return *this;
  135. }
  136. bool operator==(const SkSurfaceCharacterization& other) const { return false; }
  137. bool operator!=(const SkSurfaceCharacterization& other) const {
  138. return !(*this == other);
  139. }
  140. size_t cacheMaxResourceBytes() const { return 0; }
  141. bool isValid() const { return false; }
  142. int width() const { return 0; }
  143. int height() const { return 0; }
  144. int stencilCount() const { return 0; }
  145. bool isTextureable() const { return false; }
  146. bool isMipMapped() const { return false; }
  147. bool usesGLFBO0() const { return false; }
  148. SkColorSpace* colorSpace() const { return nullptr; }
  149. sk_sp<SkColorSpace> refColorSpace() const { return nullptr; }
  150. const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
  151. private:
  152. SkSurfaceProps fSurfaceProps;
  153. };
  154. #endif
  155. #endif