Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 1 | /* |
| 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 Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 12 | #include "mock/GrMockTypes.h" |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 13 | |
| 14 | class GrMockCaps : public GrCaps { |
| 15 | public: |
| 16 | GrMockCaps(const GrContextOptions& contextOptions, const GrMockOptions& options) |
| 17 | : INHERITED(contextOptions), fOptions(options) { |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 18 | fInstanceAttribSupport = options.fInstanceAttribSupport; |
| 19 | fMapBufferFlags = options.fMapBufferFlags; |
| 20 | fBufferMapThreshold = SK_MaxS32; // Overridable in GrContextOptions. |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 21 | fMaxTextureSize = options.fMaxTextureSize; |
| 22 | fMaxRenderTargetSize = SkTMin(options.fMaxRenderTargetSize, fMaxTextureSize); |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 23 | fMaxPreferredRenderTargetSize = fMaxRenderTargetSize; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 24 | fMaxVertexAttributes = options.fMaxVertexAttributes; |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 25 | |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 26 | fShaderCaps.reset(new GrShaderCaps(contextOptions)); |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 27 | 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 Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 32 | fShaderCaps->fMaxFragmentSamplers = options.fMaxFragmentSamplers; |
Brian Salomon | 821ef18 | 2017-11-07 16:41:11 -0500 | [diff] [blame] | 33 | fShaderCaps->fShaderDerivativeSupport = options.fShaderDerivativeSupport; |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 34 | |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 35 | this->applyOptionsOverrides(contextOptions); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 36 | } |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 37 | bool isConfigTexturable(GrPixelConfig config) const override { |
| 38 | return fOptions.fConfigOptions[config].fTexturable; |
| 39 | } |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 40 | |
Greg Daniel | bb76ace | 2017-09-29 15:58:22 -0400 | [diff] [blame] | 41 | bool isConfigCopyable(GrPixelConfig config) const override { |
| 42 | return false; |
| 43 | } |
| 44 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 45 | 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 Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame^] | 70 | bool surfaceSupportsWritePixels(const GrSurface*) const override { return true; } |
| 71 | bool surfaceSupportsReadPixels(const GrSurface*) const override { return true; } |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 72 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 73 | bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, GrSurfaceOrigin*, |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 74 | bool* rectsMustMatch, bool* disallowSubrect) const override { |
| 75 | return false; |
| 76 | } |
| 77 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 78 | bool validateBackendTexture(const GrBackendTexture& tex, SkColorType, |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 79 | GrPixelConfig* config) const override { |
| 80 | const GrMockTextureInfo* texInfo = tex.getMockTextureInfo(); |
| 81 | if (!texInfo) { |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | *config = texInfo->fConfig; |
| 86 | return true; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 87 | } |
| 88 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 89 | bool validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType, |
| 90 | GrPixelConfig*) const override { |
| 91 | return false; |
| 92 | } |
| 93 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 94 | bool getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct, |
| 95 | GrPixelConfig* config) const override { |
| 96 | const GrPixelConfig* mockFormat = format.getMockFormat(); |
| 97 | if (!mockFormat) { |
| 98 | return false; |
| 99 | } |
| 100 | *config = *mockFormat; |
| 101 | return true; |
| 102 | } |
| 103 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 104 | private: |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 105 | static const int kMaxSampleCnt = 16; |
| 106 | |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 107 | GrMockOptions fOptions; |
| 108 | typedef GrCaps INHERITED; |
| 109 | }; |
| 110 | |
| 111 | #endif |