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