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