• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "GrMtlStencilAttachment.h"
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     typedef GrMtlStencilAttachment::Format StencilFormat;
25 
26     GrMtlCaps(const GrContextOptions& contextOptions, id<MTLDevice> device,
27               MTLFeatureSet featureSet);
28 
isConfigTexturable(GrPixelConfig config)29     bool isConfigTexturable(GrPixelConfig config) const override {
30         return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kTextureable_Flag);
31     }
32 
33     int getRenderTargetSampleCount(int requestedCount, GrPixelConfig) const override;
maxRenderTargetSampleCount(GrPixelConfig)34     int maxRenderTargetSampleCount(GrPixelConfig) const override;
35 
36     bool surfaceSupportsReadPixels(const GrSurface*) const override { return true; }
37 
isConfigCopyable(GrPixelConfig config)38     bool isConfigCopyable(GrPixelConfig config) const override {
39         return true;
40     }
41 
42     /**
43      * Returns both a supported and most prefered stencil format to use in draws.
44      */
preferredStencilFormat()45     const StencilFormat& preferredStencilFormat() const {
46         return fPreferredStencilFormat;
47     }
48 
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 
54     bool canCopyAsDraw(GrPixelConfig dstConfig, bool dstIsRenderable,
55                        GrPixelConfig srcConfig, bool srcIsTextureable) const;
56 
57     bool canCopyAsDrawThenBlit(GrPixelConfig dstConfig, GrPixelConfig srcConfig,
58                                bool srcIsTextureable) const;
59 
initDescForDstCopy(const GrRenderTargetProxy * src,GrSurfaceDesc * desc,GrSurfaceOrigin *,bool * rectsMustMatch,bool * disallowSubrect)60     bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, GrSurfaceOrigin*,
61                             bool* rectsMustMatch, bool* disallowSubrect) const override {
62         return false;
63     }
64 
65     GrPixelConfig validateBackendRenderTarget(const GrBackendRenderTarget&,
66                                               SkColorType) const override;
67 
68     GrPixelConfig getConfigFromBackendFormat(const GrBackendFormat&, SkColorType) const override;
69 
70     GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const override;
71 
72     GrBackendFormat getBackendFormatFromGrColorType(GrColorType ct,
73                                                     GrSRGBEncoded srgbEncoded) const override;
74 
75 private:
76     void initFeatureSet(MTLFeatureSet featureSet);
77 
78     void initStencilFormat(const id<MTLDevice> device);
79 
80     void initGrCaps(const id<MTLDevice> device);
81     void initShaderCaps();
82 
83     void initConfigTable();
84 
onSurfaceSupportsWritePixels(const GrSurface *)85     bool onSurfaceSupportsWritePixels(const GrSurface*) const override { return true; }
86     bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
87                           const SkIRect& srcRect, const SkIPoint& dstPoint) const override;
88 
89     struct ConfigInfo {
ConfigInfoConfigInfo90         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         };
98         // TODO: Put kMSAA_Flag back when MSAA is implemented
99         static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag |
100                                           /*kMSAA_Flag |*/ kResolve_Flag;
101 
102         uint16_t fFlags;
103     };
104     ConfigInfo fConfigTable[kGrPixelConfigCnt];
105 
106     enum class Platform {
107         kMac,
108         kIOS
109     };
isMac()110     bool isMac() { return Platform::kMac == fPlatform; }
isIOS()111     bool isIOS() { return Platform::kIOS == fPlatform; }
112 
113     Platform fPlatform;
114     int fFamilyGroup;
115     int fVersion;
116 
117     SkTDArray<int> fSampleCounts;
118 
119     StencilFormat fPreferredStencilFormat;
120 
121     typedef GrCaps INHERITED;
122 };
123 
124 #endif
125