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" |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 12 | #include "SkGr.h" |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 13 | #include "mock/GrMockTypes.h" |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 14 | |
| 15 | class GrMockCaps : public GrCaps { |
| 16 | public: |
| 17 | GrMockCaps(const GrContextOptions& contextOptions, const GrMockOptions& options) |
| 18 | : INHERITED(contextOptions), fOptions(options) { |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 19 | fInstanceAttribSupport = options.fInstanceAttribSupport; |
| 20 | fMapBufferFlags = options.fMapBufferFlags; |
| 21 | fBufferMapThreshold = SK_MaxS32; // Overridable in GrContextOptions. |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 22 | fMaxTextureSize = options.fMaxTextureSize; |
| 23 | fMaxRenderTargetSize = SkTMin(options.fMaxRenderTargetSize, fMaxTextureSize); |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 24 | fMaxPreferredRenderTargetSize = fMaxRenderTargetSize; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 25 | fMaxVertexAttributes = options.fMaxVertexAttributes; |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 26 | |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 27 | fShaderCaps.reset(new GrShaderCaps(contextOptions)); |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 28 | fShaderCaps->fGeometryShaderSupport = options.fGeometryShaderSupport; |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 29 | fShaderCaps->fIntegerSupport = options.fIntegerSupport; |
| 30 | fShaderCaps->fFlatInterpolationSupport = options.fFlatInterpolationSupport; |
Robert Phillips | 7ffbcf9 | 2017-12-04 12:52:46 -0500 | [diff] [blame] | 31 | fShaderCaps->fMaxFragmentSamplers = options.fMaxFragmentSamplers; |
Brian Salomon | 821ef18 | 2017-11-07 16:41:11 -0500 | [diff] [blame] | 32 | fShaderCaps->fShaderDerivativeSupport = options.fShaderDerivativeSupport; |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 33 | |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 34 | this->applyOptionsOverrides(contextOptions); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 35 | } |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 36 | bool isConfigTexturable(GrPixelConfig config) const override { |
| 37 | return fOptions.fConfigOptions[config].fTexturable; |
| 38 | } |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 39 | |
Greg Daniel | bb76ace | 2017-09-29 15:58:22 -0400 | [diff] [blame] | 40 | bool isConfigCopyable(GrPixelConfig config) const override { |
| 41 | return false; |
| 42 | } |
| 43 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 44 | int getRenderTargetSampleCount(int requestCount, GrPixelConfig config) const override { |
| 45 | requestCount = SkTMax(requestCount, 1); |
| 46 | switch (fOptions.fConfigOptions[config].fRenderability) { |
| 47 | case GrMockOptions::ConfigOptions::Renderability::kNo: |
| 48 | return 0; |
| 49 | case GrMockOptions::ConfigOptions::Renderability::kNonMSAA: |
| 50 | return requestCount > 1 ? 0 : 1; |
| 51 | case GrMockOptions::ConfigOptions::Renderability::kMSAA: |
| 52 | return requestCount > kMaxSampleCnt ? 0 : GrNextPow2(requestCount); |
| 53 | } |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | int maxRenderTargetSampleCount(GrPixelConfig config) const override { |
| 58 | switch (fOptions.fConfigOptions[config].fRenderability) { |
| 59 | case GrMockOptions::ConfigOptions::Renderability::kNo: |
| 60 | return 0; |
| 61 | case GrMockOptions::ConfigOptions::Renderability::kNonMSAA: |
| 62 | return 1; |
| 63 | case GrMockOptions::ConfigOptions::Renderability::kMSAA: |
| 64 | return kMaxSampleCnt; |
| 65 | } |
| 66 | return 0; |
| 67 | } |
| 68 | |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 69 | bool surfaceSupportsReadPixels(const GrSurface*) const override { return true; } |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 70 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 71 | bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, GrSurfaceOrigin*, |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 72 | bool* rectsMustMatch, bool* disallowSubrect) const override { |
| 73 | return false; |
| 74 | } |
| 75 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 76 | bool validateBackendTexture(const GrBackendTexture& tex, SkColorType, |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 77 | GrPixelConfig* config) const override { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 78 | GrMockTextureInfo texInfo; |
| 79 | if (!tex.getMockTextureInfo(&texInfo)) { |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 80 | return false; |
| 81 | } |
| 82 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 83 | *config = texInfo.fConfig; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 84 | return true; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 85 | } |
| 86 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 87 | bool validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType, |
| 88 | GrPixelConfig*) const override { |
| 89 | return false; |
| 90 | } |
| 91 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 92 | bool getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct, |
| 93 | GrPixelConfig* config) const override { |
| 94 | const GrPixelConfig* mockFormat = format.getMockFormat(); |
| 95 | if (!mockFormat) { |
| 96 | return false; |
| 97 | } |
| 98 | *config = *mockFormat; |
| 99 | return true; |
| 100 | } |
| 101 | |
Jim Van Verth | 9bf8120 | 2018-10-30 15:53:36 -0400 | [diff] [blame] | 102 | bool getYUVAConfigFromBackendTexture(const GrBackendTexture& tex, |
| 103 | GrPixelConfig* config) const override { |
| 104 | GrMockTextureInfo texInfo; |
| 105 | if (!tex.getMockTextureInfo(&texInfo)) { |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | *config = texInfo.fConfig; |
| 110 | return true; |
| 111 | } |
| 112 | |
Jim Van Verth | b7f0b9c | 2018-10-22 14:12:03 -0400 | [diff] [blame] | 113 | bool getYUVAConfigFromBackendFormat(const GrBackendFormat& format, |
| 114 | GrPixelConfig* config) const override { |
| 115 | const GrPixelConfig* mockFormat = format.getMockFormat(); |
| 116 | if (!mockFormat) { |
| 117 | return false; |
| 118 | } |
| 119 | *config = *mockFormat; |
| 120 | return true; |
| 121 | } |
| 122 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 123 | GrBackendFormat getBackendFormatFromGrColorType(GrColorType ct, |
| 124 | GrSRGBEncoded srgbEncoded) const override { |
| 125 | GrPixelConfig config = GrColorTypeToPixelConfig(ct, srgbEncoded); |
| 126 | if (config == kUnknown_GrPixelConfig) { |
| 127 | return GrBackendFormat(); |
| 128 | } |
| 129 | return GrBackendFormat::MakeMock(config); |
| 130 | } |
| 131 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 132 | private: |
Timothy Liang | 036fdfe | 2018-06-28 15:50:36 -0400 | [diff] [blame] | 133 | GrBackendFormat onCreateFormatFromBackendTexture( |
| 134 | const GrBackendTexture& backendTex) const override { |
| 135 | GrMockTextureInfo mockInfo; |
| 136 | SkAssertResult(backendTex.getMockTextureInfo(&mockInfo)); |
| 137 | return GrBackendFormat::MakeMock(mockInfo.fConfig); |
| 138 | } |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame^] | 139 | bool onSurfaceSupportsWritePixels(const GrSurface*) const override { return true; } |
| 140 | bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, |
| 141 | const SkIRect& srcRect, const SkIPoint& dstPoint) const override { |
| 142 | return true; |
| 143 | } |
Timothy Liang | 036fdfe | 2018-06-28 15:50:36 -0400 | [diff] [blame] | 144 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 145 | static const int kMaxSampleCnt = 16; |
| 146 | |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 147 | GrMockOptions fOptions; |
| 148 | typedef GrCaps INHERITED; |
| 149 | }; |
| 150 | |
| 151 | #endif |