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 GrMockOptions_DEFINED
9#define GrMockOptions_DEFINED
10
11#include "include/gpu/GrTypes.h"
12#include "include/private/GrTypesPriv.h"
13
14class GrBackendFormat;
15
16struct GrMockTextureInfo {
17 GrMockTextureInfo()
18 : fColorType(GrColorType::kUnknown)
19 , fCompressionType(SkImage::CompressionType::kNone)
20 , fID(0) {}
21
22 GrMockTextureInfo(GrColorType colorType,
23 SkImage::CompressionType compressionType,
24 int id)
25 : fColorType(colorType)
26 , fCompressionType(compressionType)
27 , fID(id) {
28 SkASSERT(fID);
29 if (fCompressionType != SkImage::CompressionType::kNone) {
30 SkASSERT(colorType == GrColorType::kUnknown);
31 }
32 }
33
34 bool operator==(const GrMockTextureInfo& that) const {
35 return fColorType == that.fColorType &&
36 fCompressionType == that.fCompressionType &&
37 fID == that.fID;
38 }
39
40 GrBackendFormat getBackendFormat() const;
41
42 SkImage::CompressionType compressionType() const { return fCompressionType; }
43
44 GrColorType colorType() const {
45 SkASSERT(fCompressionType == SkImage::CompressionType::kNone);
46 return fColorType;
47 }
48
49 int id() const { return fID; }
50
51private:
52 GrColorType fColorType;
53 SkImage::CompressionType fCompressionType;
54 int fID;
55};
56
57struct GrMockRenderTargetInfo {
58 GrMockRenderTargetInfo()
59 : fColorType(GrColorType::kUnknown)
60 , fID(0) {}
61
62 GrMockRenderTargetInfo(GrColorType colorType, int id)
63 : fColorType(colorType)
64 , fID(id) {
65 SkASSERT(fID);
66 }
67
68 bool operator==(const GrMockRenderTargetInfo& that) const {
69 return fColorType == that.fColorType &&
70 fID == that.fID;
71 }
72
73 GrBackendFormat getBackendFormat() const;
74
75 GrColorType colorType() const { return fColorType; }
76
77private:
78 GrColorType fColorType;
79 int fID;
80};
81
82/**
83 * A pointer to this type is used as the GrBackendContext when creating a Mock GrContext. It can be
84 * used to specify capability options for the mock context. If nullptr is used a default constructed
85 * GrMockOptions is used.
86 */
87struct GrMockOptions {
88 GrMockOptions() {
89 using Renderability = ConfigOptions::Renderability;
90 // By default RGBA_8888 and BGRA_8888 are textureable and renderable and
91 // A8 and RGB565 are texturable.
92 fConfigOptions[(int)GrColorType::kRGBA_8888].fRenderability = Renderability::kNonMSAA;
93 fConfigOptions[(int)GrColorType::kRGBA_8888].fTexturable = true;
94 fConfigOptions[(int)GrColorType::kAlpha_8].fTexturable = true;
95 fConfigOptions[(int)GrColorType::kBGR_565].fTexturable = true;
96
97 fConfigOptions[(int)GrColorType::kBGRA_8888] = fConfigOptions[(int)GrColorType::kRGBA_8888];
98
99 fCompressedOptions[(int)SkImage::CompressionType::kETC2_RGB8_UNORM].fTexturable = true;
100 fCompressedOptions[(int)SkImage::CompressionType::kBC1_RGB8_UNORM].fTexturable = true;
101 fCompressedOptions[(int)SkImage::CompressionType::kBC1_RGBA8_UNORM].fTexturable = true;
102 }
103
104 struct ConfigOptions {
105 enum Renderability { kNo, kNonMSAA, kMSAA };
106 Renderability fRenderability = kNo;
107 bool fTexturable = false;
108 };
109
110 // GrCaps options.
111 bool fMipmapSupport = false;
112 bool fDrawInstancedSupport = false;
113 bool fHalfFloatVertexAttributeSupport = false;
114 uint32_t fMapBufferFlags = 0;
115 int fMaxTextureSize = 2048;
116 int fMaxRenderTargetSize = 2048;
117 int fMaxVertexAttributes = 16;
118 int fMaxTessellationSegments = 0;
119 ConfigOptions fConfigOptions[kGrColorTypeCnt];
120 ConfigOptions fCompressedOptions[SkImage::kCompressionTypeCount];
121
122 // GrShaderCaps options.
123 bool fGeometryShaderSupport = false;
124 bool fIntegerSupport = false;
125 bool fFlatInterpolationSupport = false;
126 int fMaxVertexSamplers = 0;
127 int fMaxFragmentSamplers = 8;
128 bool fShaderDerivativeSupport = true;
129 bool fDualSourceBlendingSupport = false;
130
131 // GrMockGpu options.
132 bool fFailTextureAllocations = false;
133};
134
135#endif
136