GrMockTypes.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #ifndef GrMockOptions_DEFINED
  8. #define GrMockOptions_DEFINED
  9. #include "include/gpu/GrTypes.h"
  10. #include "include/private/GrTypesPriv.h"
  11. class GrBackendFormat;
  12. struct GrMockTextureInfo {
  13. GrMockTextureInfo()
  14. : fColorType(GrColorType::kUnknown)
  15. , fID(0) {}
  16. GrMockTextureInfo(GrColorType colorType, int id)
  17. : fColorType(colorType)
  18. , fID(id) {
  19. SkASSERT(fID);
  20. }
  21. bool operator==(const GrMockTextureInfo& that) const {
  22. return fColorType == that.fColorType &&
  23. fID == that.fID;
  24. }
  25. GrPixelConfig pixelConfig() const {
  26. return GrColorTypeToPixelConfig(fColorType);
  27. }
  28. GrBackendFormat getBackendFormat() const;
  29. GrColorType fColorType;
  30. int fID;
  31. };
  32. struct GrMockRenderTargetInfo {
  33. GrMockRenderTargetInfo()
  34. : fColorType(GrColorType::kUnknown)
  35. , fID(0) {}
  36. GrMockRenderTargetInfo(GrColorType colorType, int id)
  37. : fColorType(colorType)
  38. , fID(id) {
  39. SkASSERT(fID);
  40. }
  41. bool operator==(const GrMockRenderTargetInfo& that) const {
  42. return fColorType == that.fColorType &&
  43. fID == that.fID;
  44. }
  45. GrPixelConfig pixelConfig() const {
  46. return GrColorTypeToPixelConfig(fColorType);
  47. }
  48. GrBackendFormat getBackendFormat() const;
  49. GrColorType colorType() const { return fColorType; }
  50. private:
  51. GrColorType fColorType;
  52. int fID;
  53. };
  54. /**
  55. * A pointer to this type is used as the GrBackendContext when creating a Mock GrContext. It can be
  56. * used to specify capability options for the mock context. If nullptr is used a default constructed
  57. * GrMockOptions is used.
  58. */
  59. struct GrMockOptions {
  60. GrMockOptions() {
  61. using Renderability = ConfigOptions::Renderability;
  62. // By default RGBA_8888 and BGRA_8888 are textureable and renderable and
  63. // A8 and RGB565 are texturable.
  64. fConfigOptions[(int)GrColorType::kRGBA_8888].fRenderability = Renderability::kNonMSAA;
  65. fConfigOptions[(int)GrColorType::kRGBA_8888].fTexturable = true;
  66. fConfigOptions[(int)GrColorType::kAlpha_8].fTexturable = true;
  67. fConfigOptions[(int)GrColorType::kBGR_565].fTexturable = true;
  68. fConfigOptions[(int)GrColorType::kBGRA_8888] = fConfigOptions[(int)GrColorType::kRGBA_8888];
  69. }
  70. struct ConfigOptions {
  71. enum Renderability { kNo, kNonMSAA, kMSAA };
  72. Renderability fRenderability = kNo;
  73. bool fTexturable = false;
  74. };
  75. // GrCaps options.
  76. bool fInstanceAttribSupport = false;
  77. bool fHalfFloatVertexAttributeSupport = false;
  78. uint32_t fMapBufferFlags = 0;
  79. int fMaxTextureSize = 2048;
  80. int fMaxRenderTargetSize = 2048;
  81. int fMaxVertexAttributes = 16;
  82. ConfigOptions fConfigOptions[kGrColorTypeCnt];
  83. // GrShaderCaps options.
  84. bool fGeometryShaderSupport = false;
  85. bool fIntegerSupport = false;
  86. bool fFlatInterpolationSupport = false;
  87. int fMaxVertexSamplers = 0;
  88. int fMaxFragmentSamplers = 8;
  89. bool fShaderDerivativeSupport = true;
  90. bool fDualSourceBlendingSupport = false;
  91. // GrMockGpu options.
  92. bool fFailTextureAllocations = false;
  93. };
  94. #endif