blob: 70ff74fe59f849ba2cca1e9ee377ea970d2a3da0 [file] [log] [blame]
Greg Danielcebcb842017-07-31 10:45:52 -04001/*
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
17class GrShaderCaps;
18
19/**
20 * Stores some capabilities of a Mtl backend.
21 */
22class GrMtlCaps : public GrCaps {
23public:
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 Danielbb76ace2017-09-29 15:58:22 -040042 bool isConfigCopyable(GrPixelConfig config) const override {
43 return true;
44 }
45
Greg Danielcebcb842017-07-31 10:45:52 -040046#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 Danielfaa095e2017-12-19 13:15:02 -050059 bool validateBackendTexture(const GrBackendTexture&, SkColorType,
60 GrPixelConfig*) const override {
61 return false;
62 }
63 bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType,
64 GrPixelConfig*) const override {
Greg Danielf5d87582017-12-18 14:48:15 -050065 return false;
66 }
67
Greg Danielfaa095e2017-12-19 13:15:02 -050068private:
Greg Danielcebcb842017-07-31 10:45:52 -040069 void initFeatureSet(MTLFeatureSet featureSet);
Ben Wagner63fd7602017-10-09 15:45:33 -040070
Greg Danielcebcb842017-07-31 10:45:52 -040071 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