blob: 935cb07822933daec8fa2d835496fe91d6dc48ed [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
Greg Danielfaa095e2017-12-19 13:15:02 -050060private:
Greg Danielcebcb842017-07-31 10:45:52 -040061 void initFeatureSet(MTLFeatureSet featureSet);
Ben Wagner63fd7602017-10-09 15:45:33 -040062
Greg Danielcebcb842017-07-31 10:45:52 -040063 void initGrCaps(const id<MTLDevice> device);
64 void initShaderCaps();
Greg Danielcebcb842017-07-31 10:45:52 -040065 void initConfigTable();
66
67 struct ConfigInfo {
68 ConfigInfo() : fFlags(0) {}
69
70 enum {
71 kTextureable_Flag = 0x1,
72 kRenderable_Flag = 0x2, // Color attachment and blendable
73 kMSAA_Flag = 0x4,
74 kResolve_Flag = 0x8,
75 };
76 static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag |
77 kMSAA_Flag | kResolve_Flag;
78
79 uint16_t fFlags;
80 };
81 ConfigInfo fConfigTable[kGrPixelConfigCnt];
82
83 enum class Platform {
84 kMac,
85 kIOS
86 };
87 bool isMac() { return Platform::kMac == fPlatform; }
88 bool isIOS() { return Platform::kIOS == fPlatform; }
89
90 Platform fPlatform;
91 int fFamilyGroup;
92 int fVersion;
93
94 SkTDArray<int> fSampleCounts;
95
96 typedef GrCaps INHERITED;
97};
98
99#endif