blob: 7822f605f4cdf35dc1c0bf7f93b6f211a12b2ebf [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 Salomon19eaf2d2018-03-19 16:06:44 -040036 bool surfaceSupportsReadPixels(const GrSurface*) const override { return true; }
Brian Salomon5f33a8c2018-02-26 14:32:39 -050037
Greg Danielbb76ace2017-09-29 15:58:22 -040038 bool isConfigCopyable(GrPixelConfig config) const override {
39 return true;
40 }
41
Greg Danielcebcb842017-07-31 10:45:52 -040042 /**
43 * Returns both a supported and most prefered stencil format to use in draws.
44 */
Ethan Nicholas01063512018-10-08 16:58:25 -040045 const StencilFormat& preferredStencilFormat() const {
46 return fPreferredStencilFormat;
Greg Danielcebcb842017-07-31 10:45:52 -040047 }
Ethan Nicholas01063512018-10-08 16:58:25 -040048
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
Brian Salomon2a4f9832018-03-03 22:43:43 -050060 bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, GrSurfaceOrigin*,
Greg Danielcebcb842017-07-31 10:45:52 -040061 bool* rectsMustMatch, bool* disallowSubrect) const override {
62 return false;
63 }
64
Brian Salomonf391d0f2018-12-14 09:18:50 -050065 GrPixelConfig validateBackendRenderTarget(const GrBackendRenderTarget&,
66 SkColorType) const override {
67 return kUnknown_GrPixelConfig;
Greg Danielf5d87582017-12-18 14:48:15 -050068 }
69
Brian Salomonf391d0f2018-12-14 09:18:50 -050070 GrPixelConfig getConfigFromBackendFormat(const GrBackendFormat&, SkColorType) const override {
71 return kUnknown_GrPixelConfig;
Robert Phillipsfc711a22018-02-13 17:03:00 -050072 }
73
Brian Salomonf391d0f2018-12-14 09:18:50 -050074 GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const override {
75 return kUnknown_GrPixelConfig;
Jim Van Verthb7f0b9c2018-10-22 14:12:03 -040076 }
77
Greg Daniel4065d452018-11-16 15:43:41 -050078 GrBackendFormat getBackendFormatFromGrColorType(GrColorType ct,
79 GrSRGBEncoded srgbEncoded) const override;
80
Ethan Nicholas56d19a52018-10-15 11:26:20 -040081 bool performPartialClearsAsDraws() const override {
82 return true;
83 }
84
Greg Danielfaa095e2017-12-19 13:15:02 -050085private:
Greg Danielcebcb842017-07-31 10:45:52 -040086 void initFeatureSet(MTLFeatureSet featureSet);
Ben Wagner63fd7602017-10-09 15:45:33 -040087
Ethan Nicholas01063512018-10-08 16:58:25 -040088 void initStencilFormat(const id<MTLDevice> device);
89
Greg Danielcebcb842017-07-31 10:45:52 -040090 void initGrCaps(const id<MTLDevice> device);
91 void initShaderCaps();
Timothy Liang036fdfe2018-06-28 15:50:36 -040092
Greg Danielcebcb842017-07-31 10:45:52 -040093 void initConfigTable();
94
Brian Salomonc67c31c2018-12-06 10:00:03 -050095 bool onSurfaceSupportsWritePixels(const GrSurface*) const override { return true; }
96 bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
97 const SkIRect& srcRect, const SkIPoint& dstPoint) const override;
98
Greg Danielcebcb842017-07-31 10:45:52 -040099 struct ConfigInfo {
100 ConfigInfo() : fFlags(0) {}
101
102 enum {
103 kTextureable_Flag = 0x1,
104 kRenderable_Flag = 0x2, // Color attachment and blendable
105 kMSAA_Flag = 0x4,
106 kResolve_Flag = 0x8,
107 };
Brian Osman63051052018-08-27 13:36:48 -0400108 // TODO: Put kMSAA_Flag back when MSAA is implemented
Greg Danielcebcb842017-07-31 10:45:52 -0400109 static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag |
Brian Osman63051052018-08-27 13:36:48 -0400110 /*kMSAA_Flag |*/ kResolve_Flag;
Greg Danielcebcb842017-07-31 10:45:52 -0400111
112 uint16_t fFlags;
113 };
114 ConfigInfo fConfigTable[kGrPixelConfigCnt];
115
116 enum class Platform {
117 kMac,
118 kIOS
119 };
120 bool isMac() { return Platform::kMac == fPlatform; }
121 bool isIOS() { return Platform::kIOS == fPlatform; }
122
123 Platform fPlatform;
124 int fFamilyGroup;
125 int fVersion;
126
127 SkTDArray<int> fSampleCounts;
128
Ethan Nicholas01063512018-10-08 16:58:25 -0400129 StencilFormat fPreferredStencilFormat;
130
Greg Danielcebcb842017-07-31 10:45:52 -0400131 typedef GrCaps INHERITED;
132};
133
134#endif