blob: eaced6f649d4d57f1f41e8762b11a6618b172780 [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
Brian Salomon19eaf2d2018-03-19 16:06:44 -040034 bool surfaceSupportsWritePixels(const GrSurface*) const override { return true; }
35 bool surfaceSupportsReadPixels(const GrSurface*) const override { return true; }
Brian Salomon5f33a8c2018-02-26 14:32:39 -050036
Greg Danielbb76ace2017-09-29 15:58:22 -040037 bool isConfigCopyable(GrPixelConfig config) const override {
38 return true;
39 }
40
Greg Danielcebcb842017-07-31 10:45:52 -040041#if 0
42 /**
43 * Returns both a supported and most prefered stencil format to use in draws.
44 */
45 const StencilFormat& preferedStencilFormat() const {
46 return fPreferedStencilFormat;
47 }
48#endif
Timothy Liange35055f2018-07-20 16:53:00 -040049 bool canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCount, GrSurfaceOrigin dstOrigin,
50 GrPixelConfig srcConfig, int srcSampleCount, GrSurfaceOrigin srcOrigin,
51 const SkIRect& srcRect, const SkIPoint& dstPoint,
52 bool areDstSrcSameObj) const;
53
Timothy Liange30739a2018-07-31 10:51:17 -040054 bool canCopyAsDraw(GrPixelConfig dstConfig, bool dstIsRenderable,
55 GrPixelConfig srcConfig, bool srcIsTextureable) const;
56
Timothy Liang70c787a2018-08-01 09:56:25 -040057 bool canCopyAsDrawThenBlit(GrPixelConfig dstConfig, GrPixelConfig srcConfig,
58 bool srcIsTextureable) const;
59
Greg Danielba2c8262018-05-03 15:28:58 -040060 bool canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
Timothy Liange35055f2018-07-20 16:53:00 -040061 const SkIRect& srcRect, const SkIPoint& dstPoint) const override;
Greg Danielba2c8262018-05-03 15:28:58 -040062
Brian Salomon2a4f9832018-03-03 22:43:43 -050063 bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, GrSurfaceOrigin*,
Greg Danielcebcb842017-07-31 10:45:52 -040064 bool* rectsMustMatch, bool* disallowSubrect) const override {
65 return false;
66 }
67
Greg Danielfaa095e2017-12-19 13:15:02 -050068 bool validateBackendTexture(const GrBackendTexture&, SkColorType,
69 GrPixelConfig*) const override {
70 return false;
71 }
72 bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType,
73 GrPixelConfig*) const override {
Greg Danielf5d87582017-12-18 14:48:15 -050074 return false;
75 }
76
Robert Phillipsfc711a22018-02-13 17:03:00 -050077 bool getConfigFromBackendFormat(const GrBackendFormat&, SkColorType,
78 GrPixelConfig*) const override {
79 return false;
80 }
81
Greg Danielfaa095e2017-12-19 13:15:02 -050082private:
Greg Danielcebcb842017-07-31 10:45:52 -040083 void initFeatureSet(MTLFeatureSet featureSet);
Ben Wagner63fd7602017-10-09 15:45:33 -040084
Greg Danielcebcb842017-07-31 10:45:52 -040085 void initGrCaps(const id<MTLDevice> device);
86 void initShaderCaps();
Timothy Liang036fdfe2018-06-28 15:50:36 -040087
88#ifdef GR_TEST_UTILS
89 GrBackendFormat onCreateFormatFromBackendTexture(const GrBackendTexture&) const override;
90#endif
91
Greg Danielcebcb842017-07-31 10:45:52 -040092 void initConfigTable();
93
94 struct ConfigInfo {
95 ConfigInfo() : fFlags(0) {}
96
97 enum {
98 kTextureable_Flag = 0x1,
99 kRenderable_Flag = 0x2, // Color attachment and blendable
100 kMSAA_Flag = 0x4,
101 kResolve_Flag = 0x8,
102 };
103 static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag |
104 kMSAA_Flag | kResolve_Flag;
105
106 uint16_t fFlags;
107 };
108 ConfigInfo fConfigTable[kGrPixelConfigCnt];
109
110 enum class Platform {
111 kMac,
112 kIOS
113 };
114 bool isMac() { return Platform::kMac == fPlatform; }
115 bool isIOS() { return Platform::kIOS == fPlatform; }
116
117 Platform fPlatform;
118 int fFamilyGroup;
119 int fVersion;
120
121 SkTDArray<int> fSampleCounts;
122
123 typedef GrCaps INHERITED;
124};
125
126#endif