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" |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 12 | #include "GrMtlStencilAttachment.h" |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 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: |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 24 | typedef GrMtlStencilAttachment::Format StencilFormat; |
| 25 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 26 | GrMtlCaps(const GrContextOptions& contextOptions, id<MTLDevice> device, |
| 27 | MTLFeatureSet featureSet); |
| 28 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 29 | bool isConfigTexturable(GrPixelConfig config) const override { |
| 30 | return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kTextureable_Flag); |
| 31 | } |
| 32 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 33 | int getRenderTargetSampleCount(int requestedCount, GrPixelConfig) const override; |
| 34 | int maxRenderTargetSampleCount(GrPixelConfig) const override; |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 35 | |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 36 | bool surfaceSupportsReadPixels(const GrSurface*) const override { return true; } |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 37 | |
Greg Daniel | bb76ace | 2017-09-29 15:58:22 -0400 | [diff] [blame] | 38 | bool isConfigCopyable(GrPixelConfig config) const override { |
| 39 | return true; |
| 40 | } |
| 41 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 42 | /** |
| 43 | * Returns both a supported and most prefered stencil format to use in draws. |
| 44 | */ |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 45 | const StencilFormat& preferredStencilFormat() const { |
| 46 | return fPreferredStencilFormat; |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 47 | } |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 48 | |
Timothy Liang | e35055f | 2018-07-20 16:53:00 -0400 | [diff] [blame] | 49 | bool canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCount, GrSurfaceOrigin dstOrigin, |
| 50 | GrPixelConfig srcConfig, int srcSampleCount, GrSurfaceOrigin srcOrigin, |
| 51 | const SkIRect& srcRect, const SkIPoint& dstPoint, |
| 52 | bool areDstSrcSameObj) const; |
| 53 | |
Timothy Liang | e30739a | 2018-07-31 10:51:17 -0400 | [diff] [blame] | 54 | bool canCopyAsDraw(GrPixelConfig dstConfig, bool dstIsRenderable, |
| 55 | GrPixelConfig srcConfig, bool srcIsTextureable) const; |
| 56 | |
Timothy Liang | 70c787a | 2018-08-01 09:56:25 -0400 | [diff] [blame] | 57 | bool canCopyAsDrawThenBlit(GrPixelConfig dstConfig, GrPixelConfig srcConfig, |
| 58 | bool srcIsTextureable) const; |
| 59 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 60 | bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, GrSurfaceOrigin*, |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 61 | bool* rectsMustMatch, bool* disallowSubrect) const override { |
| 62 | return false; |
| 63 | } |
| 64 | |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 65 | GrPixelConfig validateBackendRenderTarget(const GrBackendRenderTarget&, |
Greg Daniel | d742b6b | 2019-02-05 15:15:31 -0500 | [diff] [blame] | 66 | SkColorType) const override; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 67 | |
Greg Daniel | d742b6b | 2019-02-05 15:15:31 -0500 | [diff] [blame] | 68 | GrPixelConfig getConfigFromBackendFormat(const GrBackendFormat&, SkColorType) const override; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 69 | |
Greg Daniel | d742b6b | 2019-02-05 15:15:31 -0500 | [diff] [blame] | 70 | GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const override; |
Jim Van Verth | b7f0b9c | 2018-10-22 14:12:03 -0400 | [diff] [blame] | 71 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 72 | GrBackendFormat getBackendFormatFromGrColorType(GrColorType ct, |
| 73 | GrSRGBEncoded srgbEncoded) const override; |
| 74 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 75 | private: |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 76 | void initFeatureSet(MTLFeatureSet featureSet); |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 77 | |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 78 | void initStencilFormat(const id<MTLDevice> device); |
| 79 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 80 | void initGrCaps(const id<MTLDevice> device); |
| 81 | void initShaderCaps(); |
Timothy Liang | 036fdfe | 2018-06-28 15:50:36 -0400 | [diff] [blame] | 82 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 83 | void initConfigTable(); |
| 84 | |
Jim Van Verth | 686046b | 2019-03-18 15:39:22 -0400 | [diff] [blame] | 85 | bool onSurfaceSupportsWritePixels(const GrSurface*) const override; |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 86 | bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, |
| 87 | const SkIRect& srcRect, const SkIPoint& dstPoint) const override; |
| 88 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 89 | struct ConfigInfo { |
| 90 | ConfigInfo() : fFlags(0) {} |
| 91 | |
| 92 | enum { |
| 93 | kTextureable_Flag = 0x1, |
| 94 | kRenderable_Flag = 0x2, // Color attachment and blendable |
| 95 | kMSAA_Flag = 0x4, |
| 96 | kResolve_Flag = 0x8, |
| 97 | }; |
Brian Osman | 6305105 | 2018-08-27 13:36:48 -0400 | [diff] [blame] | 98 | // TODO: Put kMSAA_Flag back when MSAA is implemented |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 99 | static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag | |
Brian Osman | 6305105 | 2018-08-27 13:36:48 -0400 | [diff] [blame] | 100 | /*kMSAA_Flag |*/ kResolve_Flag; |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 101 | |
| 102 | uint16_t fFlags; |
| 103 | }; |
| 104 | ConfigInfo fConfigTable[kGrPixelConfigCnt]; |
| 105 | |
| 106 | enum class Platform { |
| 107 | kMac, |
| 108 | kIOS |
| 109 | }; |
| 110 | bool isMac() { return Platform::kMac == fPlatform; } |
| 111 | bool isIOS() { return Platform::kIOS == fPlatform; } |
| 112 | |
| 113 | Platform fPlatform; |
| 114 | int fFamilyGroup; |
| 115 | int fVersion; |
| 116 | |
| 117 | SkTDArray<int> fSampleCounts; |
| 118 | |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 119 | StencilFormat fPreferredStencilFormat; |
| 120 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 121 | typedef GrCaps INHERITED; |
| 122 | }; |
| 123 | |
| 124 | #endif |