• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
12 #include "SkGr.h"
13 #include "mock/GrMockTypes.h"
14 
15 class GrMockCaps : public GrCaps {
16 public:
GrMockCaps(const GrContextOptions & contextOptions,const GrMockOptions & options)17     GrMockCaps(const GrContextOptions& contextOptions, const GrMockOptions& options)
18             : INHERITED(contextOptions), fOptions(options) {
19         fInstanceAttribSupport = options.fInstanceAttribSupport;
20         fHalfFloatVertexAttributeSupport = options.fHalfFloatVertexAttributeSupport;
21         fMapBufferFlags = options.fMapBufferFlags;
22         fBufferMapThreshold = SK_MaxS32; // Overridable in GrContextOptions.
23         fMaxTextureSize = options.fMaxTextureSize;
24         fMaxRenderTargetSize = SkTMin(options.fMaxRenderTargetSize, fMaxTextureSize);
25         fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
26         fMaxVertexAttributes = options.fMaxVertexAttributes;
27 
28         fShaderCaps.reset(new GrShaderCaps(contextOptions));
29         fShaderCaps->fGeometryShaderSupport = options.fGeometryShaderSupport;
30         fShaderCaps->fIntegerSupport = options.fIntegerSupport;
31         fShaderCaps->fFlatInterpolationSupport = options.fFlatInterpolationSupport;
32         fShaderCaps->fMaxFragmentSamplers = options.fMaxFragmentSamplers;
33         fShaderCaps->fShaderDerivativeSupport = options.fShaderDerivativeSupport;
34 
35         this->applyOptionsOverrides(contextOptions);
36     }
isConfigTexturable(GrPixelConfig config)37     bool isConfigTexturable(GrPixelConfig config) const override {
38         return fOptions.fConfigOptions[config].fTexturable;
39     }
40 
isConfigCopyable(GrPixelConfig config)41     bool isConfigCopyable(GrPixelConfig config) const override {
42         return false;
43     }
44 
getRenderTargetSampleCount(int requestCount,GrPixelConfig config)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 
maxRenderTargetSampleCount(GrPixelConfig config)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 
surfaceSupportsReadPixels(const GrSurface *)70     bool surfaceSupportsReadPixels(const GrSurface*) const override { return true; }
71 
initDescForDstCopy(const GrRenderTargetProxy * src,GrSurfaceDesc * desc,GrSurfaceOrigin *,bool * rectsMustMatch,bool * disallowSubrect)72     bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, GrSurfaceOrigin*,
73                             bool* rectsMustMatch, bool* disallowSubrect) const override {
74         return false;
75     }
76 
validateBackendRenderTarget(const GrBackendRenderTarget &,SkColorType)77     GrPixelConfig validateBackendRenderTarget(const GrBackendRenderTarget&,
78                                               SkColorType) const override {
79         return kUnknown_GrPixelConfig;
80     }
81 
getConfigFromBackendFormat(const GrBackendFormat & format,SkColorType ct)82     GrPixelConfig getConfigFromBackendFormat(const GrBackendFormat& format,
83                                              SkColorType ct) const override {
84         const GrPixelConfig* mockFormat = format.getMockFormat();
85         if (!mockFormat) {
86             return kUnknown_GrPixelConfig;
87         }
88         return *mockFormat;
89     }
90 
getYUVAConfigFromBackendFormat(const GrBackendFormat & format)91     GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat& format) const override {
92         const GrPixelConfig* mockFormat = format.getMockFormat();
93         if (!mockFormat) {
94             return kUnknown_GrPixelConfig;
95         }
96         return *mockFormat;
97     }
98 
getBackendFormatFromGrColorType(GrColorType ct,GrSRGBEncoded srgbEncoded)99     GrBackendFormat getBackendFormatFromGrColorType(GrColorType ct,
100                                                     GrSRGBEncoded srgbEncoded) const override {
101         GrPixelConfig config = GrColorTypeToPixelConfig(ct, srgbEncoded);
102         if (config == kUnknown_GrPixelConfig) {
103             return GrBackendFormat();
104         }
105         return GrBackendFormat::MakeMock(config);
106     }
107 
108 private:
onSurfaceSupportsWritePixels(const GrSurface *)109     bool onSurfaceSupportsWritePixels(const GrSurface*) const override { return true; }
onCanCopySurface(const GrSurfaceProxy * dst,const GrSurfaceProxy * src,const SkIRect & srcRect,const SkIPoint & dstPoint)110     bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
111                           const SkIRect& srcRect, const SkIPoint& dstPoint) const override {
112         return true;
113     }
114 
115     static const int kMaxSampleCnt = 16;
116 
117     GrMockOptions fOptions;
118     typedef GrCaps INHERITED;
119 };
120 
121 #endif
122