blob: 75bb2e71257c18b4be74f5cac36157dd226ed6f1 [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 bool canConfigBeImageStorage(GrPixelConfig) const override { return false; }
47
48#if 0
49 /**
50 * Returns both a supported and most prefered stencil format to use in draws.
51 */
52 const StencilFormat& preferedStencilFormat() const {
53 return fPreferedStencilFormat;
54 }
55#endif
56 bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
57 bool* rectsMustMatch, bool* disallowSubrect) const override {
58 return false;
59 }
60
61private:
62 void initFeatureSet(MTLFeatureSet featureSet);
Ben Wagner63fd7602017-10-09 15:45:33 -040063
Greg Danielcebcb842017-07-31 10:45:52 -040064 void initGrCaps(const id<MTLDevice> device);
65 void initShaderCaps();
66 void initSampleCount();
67 void initConfigTable();
68
69 struct ConfigInfo {
70 ConfigInfo() : fFlags(0) {}
71
72 enum {
73 kTextureable_Flag = 0x1,
74 kRenderable_Flag = 0x2, // Color attachment and blendable
75 kMSAA_Flag = 0x4,
76 kResolve_Flag = 0x8,
77 };
78 static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag |
79 kMSAA_Flag | kResolve_Flag;
80
81 uint16_t fFlags;
82 };
83 ConfigInfo fConfigTable[kGrPixelConfigCnt];
84
85 enum class Platform {
86 kMac,
87 kIOS
88 };
89 bool isMac() { return Platform::kMac == fPlatform; }
90 bool isIOS() { return Platform::kIOS == fPlatform; }
91
92 Platform fPlatform;
93 int fFamilyGroup;
94 int fVersion;
95
96 SkTDArray<int> fSampleCounts;
97
98 typedef GrCaps INHERITED;
99};
100
101#endif