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