GrMockCaps.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 GrMockCaps_DEFINED
  8. #define GrMockCaps_DEFINED
  9. #include "include/gpu/mock/GrMockTypes.h"
  10. #include "src/gpu/GrCaps.h"
  11. #include "src/gpu/SkGr.h"
  12. class GrMockCaps : public GrCaps {
  13. public:
  14. GrMockCaps(const GrContextOptions& contextOptions, const GrMockOptions& options)
  15. : INHERITED(contextOptions), fOptions(options) {
  16. fInstanceAttribSupport = options.fInstanceAttribSupport;
  17. fHalfFloatVertexAttributeSupport = options.fHalfFloatVertexAttributeSupport;
  18. fMapBufferFlags = options.fMapBufferFlags;
  19. fBufferMapThreshold = SK_MaxS32; // Overridable in GrContextOptions.
  20. fMaxTextureSize = options.fMaxTextureSize;
  21. fMaxRenderTargetSize = SkTMin(options.fMaxRenderTargetSize, fMaxTextureSize);
  22. fMaxPreferredRenderTargetSize = fMaxRenderTargetSize;
  23. fMaxVertexAttributes = options.fMaxVertexAttributes;
  24. fSampleLocationsSupport = true;
  25. fShaderCaps.reset(new GrShaderCaps(contextOptions));
  26. fShaderCaps->fGeometryShaderSupport = options.fGeometryShaderSupport;
  27. fShaderCaps->fIntegerSupport = options.fIntegerSupport;
  28. fShaderCaps->fFlatInterpolationSupport = options.fFlatInterpolationSupport;
  29. fShaderCaps->fMaxFragmentSamplers = options.fMaxFragmentSamplers;
  30. fShaderCaps->fShaderDerivativeSupport = options.fShaderDerivativeSupport;
  31. fShaderCaps->fDualSourceBlendingSupport = options.fDualSourceBlendingSupport;
  32. fShaderCaps->fSampleVariablesSupport = true;
  33. fShaderCaps->fSampleVariablesStencilSupport = true;
  34. this->applyOptionsOverrides(contextOptions);
  35. }
  36. bool isFormatSRGB(const GrBackendFormat& format) const override {
  37. if (!format.getMockColorType()) {
  38. return false;
  39. }
  40. return *format.getMockColorType() == GrColorType::kRGBA_8888_SRGB;
  41. }
  42. bool isFormatTexturable(GrColorType, const GrBackendFormat& format) const override {
  43. if (!format.getMockColorType()) {
  44. return false;
  45. }
  46. return fOptions.fConfigOptions[(int)*format.getMockColorType()].fTexturable;
  47. }
  48. bool isConfigTexturable(GrPixelConfig config) const override {
  49. GrColorType ct = GrPixelConfigToColorType(config);
  50. return fOptions.fConfigOptions[(int)ct].fTexturable;
  51. }
  52. bool isFormatCopyable(GrColorType, const GrBackendFormat& format) const override {
  53. return false;
  54. }
  55. bool isConfigCopyable(GrPixelConfig config) const override {
  56. return false;
  57. }
  58. int getRenderTargetSampleCount(int requestCount, GrColorType ct) const {
  59. requestCount = SkTMax(requestCount, 1);
  60. switch (fOptions.fConfigOptions[(int)ct].fRenderability) {
  61. case GrMockOptions::ConfigOptions::Renderability::kNo:
  62. return 0;
  63. case GrMockOptions::ConfigOptions::Renderability::kNonMSAA:
  64. return requestCount > 1 ? 0 : 1;
  65. case GrMockOptions::ConfigOptions::Renderability::kMSAA:
  66. return requestCount > kMaxSampleCnt ? 0 : GrNextPow2(requestCount);
  67. }
  68. return 0;
  69. }
  70. int getRenderTargetSampleCount(int requestCount,
  71. GrColorType, const GrBackendFormat& format) const override {
  72. if (!format.getMockColorType()) {
  73. return 0;
  74. }
  75. return this->getRenderTargetSampleCount(requestCount, *format.getMockColorType());
  76. }
  77. int getRenderTargetSampleCount(int requestCount, GrPixelConfig config) const override {
  78. GrColorType ct = GrPixelConfigToColorType(config);
  79. return this->getRenderTargetSampleCount(requestCount, ct);
  80. }
  81. int maxRenderTargetSampleCount(GrColorType ct) const {
  82. switch (fOptions.fConfigOptions[(int)ct].fRenderability) {
  83. case GrMockOptions::ConfigOptions::Renderability::kNo:
  84. return 0;
  85. case GrMockOptions::ConfigOptions::Renderability::kNonMSAA:
  86. return 1;
  87. case GrMockOptions::ConfigOptions::Renderability::kMSAA:
  88. return kMaxSampleCnt;
  89. }
  90. return 0;
  91. }
  92. int maxRenderTargetSampleCount(GrColorType, const GrBackendFormat& format) const override {
  93. if (!format.getMockColorType()) {
  94. return 0;
  95. }
  96. return this->maxRenderTargetSampleCount(*format.getMockColorType());
  97. }
  98. int maxRenderTargetSampleCount(GrPixelConfig config) const override {
  99. GrColorType ct = GrPixelConfigToColorType(config);
  100. return this->maxRenderTargetSampleCount(ct);
  101. }
  102. SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override {
  103. return SurfaceReadPixelsSupport::kSupported;
  104. }
  105. GrPixelConfig validateBackendRenderTarget(const GrBackendRenderTarget&,
  106. GrColorType) const override {
  107. return kUnknown_GrPixelConfig;
  108. }
  109. GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat& format) const override {
  110. if (!format.getMockColorType()) {
  111. return kUnknown_GrPixelConfig;
  112. }
  113. return GrColorTypeToPixelConfig(*format.getMockColorType());
  114. }
  115. GrColorType getYUVAColorTypeFromBackendFormat(const GrBackendFormat& format) const override {
  116. if (!format.getMockColorType()) {
  117. return GrColorType::kUnknown;
  118. }
  119. return *format.getMockColorType();
  120. }
  121. GrBackendFormat getBackendFormatFromColorType(GrColorType ct) const override {
  122. return GrBackendFormat::MakeMock(ct);
  123. }
  124. GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override {
  125. return {};
  126. }
  127. bool canClearTextureOnCreation() const override { return true; }
  128. GrSwizzle getTextureSwizzle(const GrBackendFormat&, GrColorType) const override {
  129. return GrSwizzle();
  130. }
  131. GrSwizzle getOutputSwizzle(const GrBackendFormat&, GrColorType) const override {
  132. return GrSwizzle();
  133. }
  134. private:
  135. bool onSurfaceSupportsWritePixels(const GrSurface*) const override { return true; }
  136. bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
  137. const SkIRect& srcRect, const SkIPoint& dstPoint) const override {
  138. return true;
  139. }
  140. size_t onTransferFromOffsetAlignment(GrColorType bufferColorType) const override {
  141. // arbitrary
  142. return GrSizeAlignUp(GrColorTypeBytesPerPixel(bufferColorType), 4);
  143. }
  144. GrPixelConfig onGetConfigFromBackendFormat(const GrBackendFormat& format,
  145. GrColorType) const override {
  146. if (!format.getMockColorType()) {
  147. return kUnknown_GrPixelConfig;
  148. }
  149. return GrColorTypeToPixelConfig(*format.getMockColorType());
  150. }
  151. bool onAreColorTypeAndFormatCompatible(GrColorType ct,
  152. const GrBackendFormat& format) const override {
  153. if (GrColorType::kUnknown == ct) {
  154. return false;
  155. }
  156. const GrColorType* mockColorType = format.getMockColorType();
  157. if (!mockColorType) {
  158. return false;
  159. }
  160. return ct == *mockColorType;
  161. }
  162. static const int kMaxSampleCnt = 16;
  163. GrMockOptions fOptions;
  164. typedef GrCaps INHERITED;
  165. };
  166. #endif