blob: c23a9028ca2badd23d3d4c2c8ab8461e1608ee4f [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
Greg Danielcebcb842017-07-31 10:45:52 -040027 bool isConfigTexturable(GrPixelConfig config) const override {
28 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kTextureable_Flag);
29 }
30
Brian Salomonbdecacf2018-02-02 20:32:49 -050031 int getRenderTargetSampleCount(int requestedCount, GrPixelConfig) const override;
32 int maxRenderTargetSampleCount(GrPixelConfig) const override;
Greg Danielcebcb842017-07-31 10:45:52 -040033
Greg Danielbb76ace2017-09-29 15:58:22 -040034 bool isConfigCopyable(GrPixelConfig config) const override {
35 return true;
36 }
37
Greg Danielcebcb842017-07-31 10:45:52 -040038#if 0
39 /**
40 * Returns both a supported and most prefered stencil format to use in draws.
41 */
42 const StencilFormat& preferedStencilFormat() const {
43 return fPreferedStencilFormat;
44 }
45#endif
46 bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
47 bool* rectsMustMatch, bool* disallowSubrect) const override {
48 return false;
49 }
50
Greg Danielfaa095e2017-12-19 13:15:02 -050051 bool validateBackendTexture(const GrBackendTexture&, SkColorType,
52 GrPixelConfig*) const override {
53 return false;
54 }
55 bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType,
56 GrPixelConfig*) const override {
Greg Danielf5d87582017-12-18 14:48:15 -050057 return false;
58 }
59
Robert Phillipsfc711a22018-02-13 17:03:00 -050060 bool getConfigFromBackendFormat(const GrBackendFormat&, SkColorType,
61 GrPixelConfig*) const override {
62 return false;
63 }
64
Greg Danielfaa095e2017-12-19 13:15:02 -050065private:
Greg Danielcebcb842017-07-31 10:45:52 -040066 void initFeatureSet(MTLFeatureSet featureSet);
Ben Wagner63fd7602017-10-09 15:45:33 -040067
Greg Danielcebcb842017-07-31 10:45:52 -040068 void initGrCaps(const id<MTLDevice> device);
69 void initShaderCaps();
Greg Danielcebcb842017-07-31 10:45:52 -040070 void initConfigTable();
71
72 struct ConfigInfo {
73 ConfigInfo() : fFlags(0) {}
74
75 enum {
76 kTextureable_Flag = 0x1,
77 kRenderable_Flag = 0x2, // Color attachment and blendable
78 kMSAA_Flag = 0x4,
79 kResolve_Flag = 0x8,
80 };
81 static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag |
82 kMSAA_Flag | kResolve_Flag;
83
84 uint16_t fFlags;
85 };
86 ConfigInfo fConfigTable[kGrPixelConfigCnt];
87
88 enum class Platform {
89 kMac,
90 kIOS
91 };
92 bool isMac() { return Platform::kMac == fPlatform; }
93 bool isIOS() { return Platform::kIOS == fPlatform; }
94
95 Platform fPlatform;
96 int fFamilyGroup;
97 int fVersion;
98
99 SkTDArray<int> fSampleCounts;
100
101 typedef GrCaps INHERITED;
102};
103
104#endif