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 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 27 | bool isConfigTexturable(GrPixelConfig config) const override { |
| 28 | return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kTextureable_Flag); |
| 29 | } |
| 30 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 31 | int getRenderTargetSampleCount(int requestedCount, GrPixelConfig) const override; |
| 32 | int maxRenderTargetSampleCount(GrPixelConfig) const override; |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 33 | |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 34 | bool surfaceSupportsWritePixels(const GrSurface*) const override { return true; } |
| 35 | bool surfaceSupportsReadPixels(const GrSurface*) const override { return true; } |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 36 | |
Greg Daniel | bb76ace | 2017-09-29 15:58:22 -0400 | [diff] [blame] | 37 | bool isConfigCopyable(GrPixelConfig config) const override { |
| 38 | return true; |
| 39 | } |
| 40 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 41 | #if 0 |
| 42 | /** |
| 43 | * Returns both a supported and most prefered stencil format to use in draws. |
| 44 | */ |
| 45 | const StencilFormat& preferedStencilFormat() const { |
| 46 | return fPreferedStencilFormat; |
| 47 | } |
| 48 | #endif |
Greg Daniel | ba2c826 | 2018-05-03 15:28:58 -0400 | [diff] [blame] | 49 | bool canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, |
| 50 | const SkIRect& srcRect, const SkIPoint& dstPoint) const override { |
| 51 | return false; |
| 52 | } |
| 53 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 54 | bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, GrSurfaceOrigin*, |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 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 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 68 | bool getConfigFromBackendFormat(const GrBackendFormat&, SkColorType, |
| 69 | GrPixelConfig*) const override { |
| 70 | return false; |
| 71 | } |
| 72 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 73 | private: |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 74 | void initFeatureSet(MTLFeatureSet featureSet); |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 75 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 76 | void initGrCaps(const id<MTLDevice> device); |
| 77 | void initShaderCaps(); |
Timothy Liang | 036fdfe | 2018-06-28 15:50:36 -0400 | [diff] [blame^] | 78 | |
| 79 | #ifdef GR_TEST_UTILS |
| 80 | GrBackendFormat onCreateFormatFromBackendTexture(const GrBackendTexture&) const override; |
| 81 | #endif |
| 82 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 83 | void initConfigTable(); |
| 84 | |
| 85 | struct ConfigInfo { |
| 86 | ConfigInfo() : fFlags(0) {} |
| 87 | |
| 88 | enum { |
| 89 | kTextureable_Flag = 0x1, |
| 90 | kRenderable_Flag = 0x2, // Color attachment and blendable |
| 91 | kMSAA_Flag = 0x4, |
| 92 | kResolve_Flag = 0x8, |
| 93 | }; |
| 94 | static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag | |
| 95 | kMSAA_Flag | kResolve_Flag; |
| 96 | |
| 97 | uint16_t fFlags; |
| 98 | }; |
| 99 | ConfigInfo fConfigTable[kGrPixelConfigCnt]; |
| 100 | |
| 101 | enum class Platform { |
| 102 | kMac, |
| 103 | kIOS |
| 104 | }; |
| 105 | bool isMac() { return Platform::kMac == fPlatform; } |
| 106 | bool isIOS() { return Platform::kIOS == fPlatform; } |
| 107 | |
| 108 | Platform fPlatform; |
| 109 | int fFamilyGroup; |
| 110 | int fVersion; |
| 111 | |
| 112 | SkTDArray<int> fSampleCounts; |
| 113 | |
| 114 | typedef GrCaps INHERITED; |
| 115 | }; |
| 116 | |
| 117 | #endif |