blob: 7edfa79d969c11e21e8a055e870f1e45cc747af9 [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"
Ethan Nicholas01063512018-10-08 16:58:25 -040012#include "GrMtlStencilAttachment.h"
Greg Danielcebcb842017-07-31 10:45:52 -040013#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:
Ethan Nicholas01063512018-10-08 16:58:25 -040024 typedef GrMtlStencilAttachment::Format StencilFormat;
25
Greg Danielcebcb842017-07-31 10:45:52 -040026 GrMtlCaps(const GrContextOptions& contextOptions, id<MTLDevice> device,
27 MTLFeatureSet featureSet);
28
Greg Danielcebcb842017-07-31 10:45:52 -040029 bool isConfigTexturable(GrPixelConfig config) const override {
30 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kTextureable_Flag);
31 }
32
Brian Salomonbdecacf2018-02-02 20:32:49 -050033 int getRenderTargetSampleCount(int requestedCount, GrPixelConfig) const override;
34 int maxRenderTargetSampleCount(GrPixelConfig) const override;
Greg Danielcebcb842017-07-31 10:45:52 -040035
Brian Salomonff4ccaa2018-12-05 21:35:33 +000036 bool surfaceSupportsWritePixels(const GrSurface*) const override { return true; }
Brian Salomon19eaf2d2018-03-19 16:06:44 -040037 bool surfaceSupportsReadPixels(const GrSurface*) const override { return true; }
Brian Salomon5f33a8c2018-02-26 14:32:39 -050038
Greg Danielbb76ace2017-09-29 15:58:22 -040039 bool isConfigCopyable(GrPixelConfig config) const override {
40 return true;
41 }
42
Greg Danielcebcb842017-07-31 10:45:52 -040043 /**
44 * Returns both a supported and most prefered stencil format to use in draws.
45 */
Ethan Nicholas01063512018-10-08 16:58:25 -040046 const StencilFormat& preferredStencilFormat() const {
47 return fPreferredStencilFormat;
Greg Danielcebcb842017-07-31 10:45:52 -040048 }
Ethan Nicholas01063512018-10-08 16:58:25 -040049
Timothy Liange35055f2018-07-20 16:53:00 -040050 bool canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCount, GrSurfaceOrigin dstOrigin,
51 GrPixelConfig srcConfig, int srcSampleCount, GrSurfaceOrigin srcOrigin,
52 const SkIRect& srcRect, const SkIPoint& dstPoint,
53 bool areDstSrcSameObj) const;
54
Timothy Liange30739a2018-07-31 10:51:17 -040055 bool canCopyAsDraw(GrPixelConfig dstConfig, bool dstIsRenderable,
56 GrPixelConfig srcConfig, bool srcIsTextureable) const;
57
Timothy Liang70c787a2018-08-01 09:56:25 -040058 bool canCopyAsDrawThenBlit(GrPixelConfig dstConfig, GrPixelConfig srcConfig,
59 bool srcIsTextureable) const;
60
Brian Salomonff4ccaa2018-12-05 21:35:33 +000061 bool canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
62 const SkIRect& srcRect, const SkIPoint& dstPoint) const override;
63
Brian Salomon2a4f9832018-03-03 22:43:43 -050064 bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, GrSurfaceOrigin*,
Greg Danielcebcb842017-07-31 10:45:52 -040065 bool* rectsMustMatch, bool* disallowSubrect) const override {
66 return false;
67 }
68
Greg Danielfaa095e2017-12-19 13:15:02 -050069 bool validateBackendTexture(const GrBackendTexture&, SkColorType,
70 GrPixelConfig*) const override {
71 return false;
72 }
73 bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType,
74 GrPixelConfig*) const override {
Greg Danielf5d87582017-12-18 14:48:15 -050075 return false;
76 }
77
Robert Phillipsfc711a22018-02-13 17:03:00 -050078 bool getConfigFromBackendFormat(const GrBackendFormat&, SkColorType,
79 GrPixelConfig*) const override {
80 return false;
81 }
82
Jim Van Verth9bf81202018-10-30 15:53:36 -040083 bool getYUVAConfigFromBackendTexture(const GrBackendTexture&,
84 GrPixelConfig*) const override {
85 return false;
86 }
87
Jim Van Verthb7f0b9c2018-10-22 14:12:03 -040088 bool getYUVAConfigFromBackendFormat(const GrBackendFormat&,
89 GrPixelConfig*) const override {
90 return false;
91 }
92
Greg Daniel4065d452018-11-16 15:43:41 -050093 GrBackendFormat getBackendFormatFromGrColorType(GrColorType ct,
94 GrSRGBEncoded srgbEncoded) const override;
95
Ethan Nicholas56d19a52018-10-15 11:26:20 -040096 bool performPartialClearsAsDraws() const override {
97 return true;
98 }
99
Greg Danielfaa095e2017-12-19 13:15:02 -0500100private:
Greg Danielcebcb842017-07-31 10:45:52 -0400101 void initFeatureSet(MTLFeatureSet featureSet);
Ben Wagner63fd7602017-10-09 15:45:33 -0400102
Ethan Nicholas01063512018-10-08 16:58:25 -0400103 void initStencilFormat(const id<MTLDevice> device);
104
Greg Danielcebcb842017-07-31 10:45:52 -0400105 void initGrCaps(const id<MTLDevice> device);
106 void initShaderCaps();
Timothy Liang036fdfe2018-06-28 15:50:36 -0400107
Timothy Liang036fdfe2018-06-28 15:50:36 -0400108 GrBackendFormat onCreateFormatFromBackendTexture(const GrBackendTexture&) const override;
Timothy Liang036fdfe2018-06-28 15:50:36 -0400109
Greg Danielcebcb842017-07-31 10:45:52 -0400110 void initConfigTable();
111
112 struct ConfigInfo {
113 ConfigInfo() : fFlags(0) {}
114
115 enum {
116 kTextureable_Flag = 0x1,
117 kRenderable_Flag = 0x2, // Color attachment and blendable
118 kMSAA_Flag = 0x4,
119 kResolve_Flag = 0x8,
120 };
Brian Osman63051052018-08-27 13:36:48 -0400121 // TODO: Put kMSAA_Flag back when MSAA is implemented
Greg Danielcebcb842017-07-31 10:45:52 -0400122 static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag |
Brian Osman63051052018-08-27 13:36:48 -0400123 /*kMSAA_Flag |*/ kResolve_Flag;
Greg Danielcebcb842017-07-31 10:45:52 -0400124
125 uint16_t fFlags;
126 };
127 ConfigInfo fConfigTable[kGrPixelConfigCnt];
128
129 enum class Platform {
130 kMac,
131 kIOS
132 };
133 bool isMac() { return Platform::kMac == fPlatform; }
134 bool isIOS() { return Platform::kIOS == fPlatform; }
135
136 Platform fPlatform;
137 int fFamilyGroup;
138 int fVersion;
139
140 SkTDArray<int> fSampleCounts;
141
Ethan Nicholas01063512018-10-08 16:58:25 -0400142 StencilFormat fPreferredStencilFormat;
143
Greg Danielcebcb842017-07-31 10:45:52 -0400144 typedef GrCaps INHERITED;
145};
146
147#endif