• 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 
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 
isConfigTexturable(GrPixelConfig config)27     bool isConfigTexturable(GrPixelConfig config) const override {
28         return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kTextureable_Flag);
29     }
30 
31     int getRenderTargetSampleCount(int requestedCount, GrPixelConfig) const override;
maxRenderTargetSampleCount(GrPixelConfig)32     int maxRenderTargetSampleCount(GrPixelConfig) const override;
33 
34     bool surfaceSupportsWritePixels(const GrSurface* surface) const override { return true; }
35 
isConfigCopyable(GrPixelConfig config)36     bool isConfigCopyable(GrPixelConfig config) const override {
37         return true;
38     }
39 
40 #if 0
41     /**
42      * Returns both a supported and most prefered stencil format to use in draws.
43      */
44     const StencilFormat& preferedStencilFormat() const {
45         return fPreferedStencilFormat;
46     }
47 #endif
initDescForDstCopy(const GrRenderTargetProxy * src,GrSurfaceDesc * desc,bool * rectsMustMatch,bool * disallowSubrect)48     bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
49                             bool* rectsMustMatch, bool* disallowSubrect) const override {
50         return false;
51     }
52 
validateBackendTexture(const GrBackendTexture &,SkColorType,GrPixelConfig *)53     bool validateBackendTexture(const GrBackendTexture&, SkColorType,
54                                 GrPixelConfig*) const override {
55         return false;
56     }
validateBackendRenderTarget(const GrBackendRenderTarget &,SkColorType,GrPixelConfig *)57     bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType,
58                                      GrPixelConfig*) const override {
59         return false;
60     }
61 
getConfigFromBackendFormat(const GrBackendFormat &,SkColorType,GrPixelConfig *)62     bool getConfigFromBackendFormat(const GrBackendFormat&, SkColorType,
63                                     GrPixelConfig*) const override {
64         return false;
65     }
66 
67 private:
68     void initFeatureSet(MTLFeatureSet featureSet);
69 
70     void initGrCaps(const id<MTLDevice> device);
71     void initShaderCaps();
72     void initConfigTable();
73 
74     struct ConfigInfo {
ConfigInfoConfigInfo75         ConfigInfo() : fFlags(0) {}
76 
77         enum {
78             kTextureable_Flag = 0x1,
79             kRenderable_Flag  = 0x2, // Color attachment and blendable
80             kMSAA_Flag        = 0x4,
81             kResolve_Flag     = 0x8,
82         };
83         static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag |
84                                           kMSAA_Flag | kResolve_Flag;
85 
86         uint16_t fFlags;
87     };
88     ConfigInfo fConfigTable[kGrPixelConfigCnt];
89 
90     enum class Platform {
91         kMac,
92         kIOS
93     };
isMac()94     bool isMac() { return Platform::kMac == fPlatform; }
isIOS()95     bool isIOS() { return Platform::kIOS == fPlatform; }
96 
97     Platform fPlatform;
98     int fFamilyGroup;
99     int fVersion;
100 
101     SkTDArray<int> fSampleCounts;
102 
103     typedef GrCaps INHERITED;
104 };
105 
106 #endif
107