blob: 4bcd4599c5d0d44f1f65933f07ba239787773c76 [file] [log] [blame]
Brian Salomoncfe910d2017-07-06 16:40:18 -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 GrMockCaps_DEFINED
9#define GrMockCaps_DEFINED
10
11#include "GrCaps.h"
Brian Salomon8fe24272017-07-07 12:56:11 -040012#include "mock/GrMockTypes.h"
Brian Salomoncfe910d2017-07-06 16:40:18 -040013
14class GrMockCaps : public GrCaps {
15public:
16 GrMockCaps(const GrContextOptions& contextOptions, const GrMockOptions& options)
17 : INHERITED(contextOptions), fOptions(options) {
Chris Daltonfddb6c02017-11-04 15:22:22 -060018 fInstanceAttribSupport = options.fInstanceAttribSupport;
19 fMapBufferFlags = options.fMapBufferFlags;
20 fBufferMapThreshold = SK_MaxS32; // Overridable in GrContextOptions.
Brian Salomoncfe910d2017-07-06 16:40:18 -040021 fMaxTextureSize = options.fMaxTextureSize;
22 fMaxRenderTargetSize = SkTMin(options.fMaxRenderTargetSize, fMaxTextureSize);
Chris Dalton2612bae2018-02-22 13:41:37 -070023 fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
Brian Salomoncfe910d2017-07-06 16:40:18 -040024 fMaxVertexAttributes = options.fMaxVertexAttributes;
Chris Daltonfddb6c02017-11-04 15:22:22 -060025
Brian Salomoncfe910d2017-07-06 16:40:18 -040026 fShaderCaps.reset(new GrShaderCaps(contextOptions));
Chris Daltonfddb6c02017-11-04 15:22:22 -060027 fShaderCaps->fGeometryShaderSupport = options.fGeometryShaderSupport;
28 fShaderCaps->fTexelBufferSupport = options.fTexelBufferSupport;
29 fShaderCaps->fIntegerSupport = options.fIntegerSupport;
30 fShaderCaps->fFlatInterpolationSupport = options.fFlatInterpolationSupport;
31 fShaderCaps->fMaxVertexSamplers = options.fMaxVertexSamplers;
Robert Phillips7ffbcf92017-12-04 12:52:46 -050032 fShaderCaps->fMaxFragmentSamplers = options.fMaxFragmentSamplers;
Brian Salomon821ef182017-11-07 16:41:11 -050033 fShaderCaps->fShaderDerivativeSupport = options.fShaderDerivativeSupport;
Chris Daltonfddb6c02017-11-04 15:22:22 -060034
Brian Salomon8fe24272017-07-07 12:56:11 -040035 this->applyOptionsOverrides(contextOptions);
Brian Salomoncfe910d2017-07-06 16:40:18 -040036 }
Brian Salomoncfe910d2017-07-06 16:40:18 -040037 bool isConfigTexturable(GrPixelConfig config) const override {
38 return fOptions.fConfigOptions[config].fTexturable;
39 }
Brian Salomonbdecacf2018-02-02 20:32:49 -050040
Greg Danielbb76ace2017-09-29 15:58:22 -040041 bool isConfigCopyable(GrPixelConfig config) const override {
42 return false;
43 }
44
Brian Salomonbdecacf2018-02-02 20:32:49 -050045 int getRenderTargetSampleCount(int requestCount, GrPixelConfig config) const override {
46 requestCount = SkTMax(requestCount, 1);
47 switch (fOptions.fConfigOptions[config].fRenderability) {
48 case GrMockOptions::ConfigOptions::Renderability::kNo:
49 return 0;
50 case GrMockOptions::ConfigOptions::Renderability::kNonMSAA:
51 return requestCount > 1 ? 0 : 1;
52 case GrMockOptions::ConfigOptions::Renderability::kMSAA:
53 return requestCount > kMaxSampleCnt ? 0 : GrNextPow2(requestCount);
54 }
55 return 0;
56 }
57
58 int maxRenderTargetSampleCount(GrPixelConfig config) const override {
59 switch (fOptions.fConfigOptions[config].fRenderability) {
60 case GrMockOptions::ConfigOptions::Renderability::kNo:
61 return 0;
62 case GrMockOptions::ConfigOptions::Renderability::kNonMSAA:
63 return 1;
64 case GrMockOptions::ConfigOptions::Renderability::kMSAA:
65 return kMaxSampleCnt;
66 }
67 return 0;
68 }
69
Brian Salomonbe5947c2018-03-19 18:42:25 +000070 bool surfaceSupportsWritePixels(const GrSurface* surface) const override { return true; }
Brian Salomon5f33a8c2018-02-26 14:32:39 -050071
Brian Salomon2a4f9832018-03-03 22:43:43 -050072 bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, GrSurfaceOrigin*,
Brian Salomoncfe910d2017-07-06 16:40:18 -040073 bool* rectsMustMatch, bool* disallowSubrect) const override {
74 return false;
75 }
76
Greg Danielfaa095e2017-12-19 13:15:02 -050077 bool validateBackendTexture(const GrBackendTexture& tex, SkColorType,
Robert Phillipsfc711a22018-02-13 17:03:00 -050078 GrPixelConfig* config) const override {
79 const GrMockTextureInfo* texInfo = tex.getMockTextureInfo();
80 if (!texInfo) {
81 return false;
82 }
83
84 *config = texInfo->fConfig;
85 return true;
Greg Danielf5d87582017-12-18 14:48:15 -050086 }
87
Greg Danielfaa095e2017-12-19 13:15:02 -050088 bool validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType,
89 GrPixelConfig*) const override {
90 return false;
91 }
92
Robert Phillipsfc711a22018-02-13 17:03:00 -050093 bool getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
94 GrPixelConfig* config) const override {
95 const GrPixelConfig* mockFormat = format.getMockFormat();
96 if (!mockFormat) {
97 return false;
98 }
99 *config = *mockFormat;
100 return true;
101 }
102
Greg Danielfaa095e2017-12-19 13:15:02 -0500103private:
Brian Salomonbdecacf2018-02-02 20:32:49 -0500104 static const int kMaxSampleCnt = 16;
105
Brian Salomoncfe910d2017-07-06 16:40:18 -0400106 GrMockOptions fOptions;
107 typedef GrCaps INHERITED;
108};
109
110#endif