Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 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 | |
| 29 | bool isConfigTexturable(GrPixelConfig config) const override { |
| 30 | return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kTextureable_Flag); |
| 31 | } |
| 32 | |
| 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 | |
Greg Daniel | bb76ace | 2017-09-29 15:58:22 -0400 | [diff] [blame] | 42 | bool isConfigCopyable(GrPixelConfig config) const override { |
| 43 | return true; |
| 44 | } |
| 45 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 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 |
| 54 | bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, |
| 55 | bool* rectsMustMatch, bool* disallowSubrect) const override { |
| 56 | return false; |
| 57 | } |
| 58 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame^] | 59 | bool validateBackendTexture(const GrBackendTexture&, SkColorType, |
| 60 | GrPixelConfig*) const override { |
| 61 | return false; |
| 62 | } |
| 63 | bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType, |
| 64 | GrPixelConfig*) const override { |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 65 | return false; |
| 66 | } |
| 67 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame^] | 68 | private: |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 69 | void initFeatureSet(MTLFeatureSet featureSet); |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 70 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 71 | void initGrCaps(const id<MTLDevice> device); |
| 72 | void initShaderCaps(); |
| 73 | void initSampleCount(); |
| 74 | void initConfigTable(); |
| 75 | |
| 76 | struct ConfigInfo { |
| 77 | ConfigInfo() : fFlags(0) {} |
| 78 | |
| 79 | enum { |
| 80 | kTextureable_Flag = 0x1, |
| 81 | kRenderable_Flag = 0x2, // Color attachment and blendable |
| 82 | kMSAA_Flag = 0x4, |
| 83 | kResolve_Flag = 0x8, |
| 84 | }; |
| 85 | static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag | |
| 86 | kMSAA_Flag | kResolve_Flag; |
| 87 | |
| 88 | uint16_t fFlags; |
| 89 | }; |
| 90 | ConfigInfo fConfigTable[kGrPixelConfigCnt]; |
| 91 | |
| 92 | enum class Platform { |
| 93 | kMac, |
| 94 | kIOS |
| 95 | }; |
| 96 | bool isMac() { return Platform::kMac == fPlatform; } |
| 97 | bool isIOS() { return Platform::kIOS == fPlatform; } |
| 98 | |
| 99 | Platform fPlatform; |
| 100 | int fFamilyGroup; |
| 101 | int fVersion; |
| 102 | |
| 103 | SkTDArray<int> fSampleCounts; |
| 104 | |
| 105 | typedef GrCaps INHERITED; |
| 106 | }; |
| 107 | |
| 108 | #endif |