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 GrMtlCaps_DEFINED 9 #define GrMtlCaps_DEFINED 10 11 #include "GrCaps.h" 12 13 #include "SkTDArray.h" 14 15 #import <Metal/Metal.h> 16 17 class GrShaderCaps; 18 19 /** 20 * Stores some capabilities of a Mtl backend. 21 */ 22 class GrMtlCaps : public GrCaps { 23 public: 24 GrMtlCaps(const GrContextOptions& contextOptions, id<MTLDevice> device, 25 MTLFeatureSet featureSet); 26 27 int getSampleCount(int requestedCount, GrPixelConfig config) const override; 28 isConfigTexturable(GrPixelConfig config)29 bool isConfigTexturable(GrPixelConfig config) const override { 30 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kTextureable_Flag); 31 } 32 isConfigRenderable(GrPixelConfig config,bool withMSAA)33 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { 34 if (withMSAA) { 35 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kRenderable_Flag) && 36 SkToBool(fConfigTable[config].fFlags & ConfigInfo::kMSAA_Flag); 37 } else { 38 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kRenderable_Flag); 39 } 40 } 41 isConfigCopyable(GrPixelConfig config)42 bool isConfigCopyable(GrPixelConfig config) const override { 43 return true; 44 } 45 46 #if 0 47 /** 48 * Returns both a supported and most prefered stencil format to use in draws. 49 */ 50 const StencilFormat& preferedStencilFormat() const { 51 return fPreferedStencilFormat; 52 } 53 #endif initDescForDstCopy(const GrRenderTargetProxy * src,GrSurfaceDesc * desc,bool * rectsMustMatch,bool * disallowSubrect)54 bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, 55 bool* rectsMustMatch, bool* disallowSubrect) const override { 56 return false; 57 } 58 validateBackendTexture(const GrBackendTexture &,SkColorType,GrPixelConfig *)59 bool validateBackendTexture(const GrBackendTexture&, SkColorType, 60 GrPixelConfig*) const override { 61 return false; 62 } validateBackendRenderTarget(const GrBackendRenderTarget &,SkColorType,GrPixelConfig *)63 bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType, 64 GrPixelConfig*) const override { 65 return false; 66 } 67 68 private: 69 void initFeatureSet(MTLFeatureSet featureSet); 70 71 void initGrCaps(const id<MTLDevice> device); 72 void initShaderCaps(); 73 void initConfigTable(); 74 75 struct ConfigInfo { ConfigInfoConfigInfo76 ConfigInfo() : fFlags(0) {} 77 78 enum { 79 kTextureable_Flag = 0x1, 80 kRenderable_Flag = 0x2, // Color attachment and blendable 81 kMSAA_Flag = 0x4, 82 kResolve_Flag = 0x8, 83 }; 84 static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag | 85 kMSAA_Flag | kResolve_Flag; 86 87 uint16_t fFlags; 88 }; 89 ConfigInfo fConfigTable[kGrPixelConfigCnt]; 90 91 enum class Platform { 92 kMac, 93 kIOS 94 }; isMac()95 bool isMac() { return Platform::kMac == fPlatform; } isIOS()96 bool isIOS() { return Platform::kIOS == fPlatform; } 97 98 Platform fPlatform; 99 int fFamilyGroup; 100 int fVersion; 101 102 SkTDArray<int> fSampleCounts; 103 104 typedef GrCaps INHERITED; 105 }; 106 107 #endif 108