GrDawnCaps.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright 2019 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. #include "GrDawnCaps.h"
  8. GrDawnCaps::GrDawnCaps(const GrContextOptions& contextOptions) : INHERITED(contextOptions) {
  9. fBufferMapThreshold = SK_MaxS32; // FIXME: get this from Dawn?
  10. fShaderCaps.reset(new GrShaderCaps(contextOptions));
  11. fMaxTextureSize = 2048;
  12. fPerformPartialClearsAsDraws = true;
  13. }
  14. bool GrDawnCaps::isFormatSRGB(const GrBackendFormat& format) const {
  15. return false;
  16. }
  17. bool GrDawnCaps::isConfigTexturable(GrPixelConfig config) const {
  18. switch (config) {
  19. case kRGBA_8888_GrPixelConfig:
  20. case kBGRA_8888_GrPixelConfig:
  21. case kAlpha_8_GrPixelConfig:
  22. return true;
  23. default:
  24. return false;
  25. }
  26. }
  27. GrPixelConfig GrDawnCaps::onGetConfigFromBackendFormat(const GrBackendFormat& format,
  28. GrColorType colorType) const {
  29. dawn::TextureFormat textureFormat = *format.getDawnFormat();
  30. switch (colorType) {
  31. case GrColorType::kUnknown:
  32. return kUnknown_GrPixelConfig;
  33. case GrColorType::kAlpha_8:
  34. if (dawn::TextureFormat::R8Unorm == textureFormat) {
  35. return kAlpha_8_as_Red_GrPixelConfig;
  36. }
  37. break;
  38. case GrColorType::kRGBA_8888:
  39. if (dawn::TextureFormat::RGBA8Unorm == textureFormat) {
  40. return kRGBA_8888_GrPixelConfig;
  41. }
  42. break;
  43. case GrColorType::kRGB_888x:
  44. break;
  45. case GrColorType::kBGRA_8888:
  46. if (dawn::TextureFormat::BGRA8Unorm == textureFormat) {
  47. return kBGRA_8888_GrPixelConfig;
  48. }
  49. break;
  50. default:
  51. break;
  52. }
  53. return kUnknown_GrPixelConfig;
  54. }
  55. GrPixelConfig GrDawnCaps::getYUVAConfigFromBackendFormat(const GrBackendFormat& backendFormat)
  56. const {
  57. const dawn::TextureFormat* format = backendFormat.getDawnFormat();
  58. if (!format) {
  59. return kUnknown_GrPixelConfig;
  60. }
  61. switch (*format) {
  62. case dawn::TextureFormat::R8Unorm:
  63. return kAlpha_8_as_Red_GrPixelConfig;
  64. break;
  65. case dawn::TextureFormat::RGBA8Unorm:
  66. return kRGBA_8888_GrPixelConfig;
  67. break;
  68. case dawn::TextureFormat::BGRA8Unorm:
  69. return kBGRA_8888_GrPixelConfig;
  70. break;
  71. default:
  72. return kUnknown_GrPixelConfig;
  73. break;
  74. }
  75. }
  76. size_t GrDawnCaps::onTransferFromOffsetAlignment(GrColorType bufferColorType) const {
  77. if (bufferColorType == GrColorType::kRGB_888x) {
  78. return false;
  79. }
  80. size_t bpp = GrColorTypeBytesPerPixel(bufferColorType);
  81. switch (bpp & 0b11) {
  82. case 0: return bpp;
  83. case 2: return 2 * bpp;
  84. default: return 4 * bpp;
  85. }
  86. }
  87. static GrSwizzle get_swizzle(const GrBackendFormat& format, GrColorType colorType,
  88. bool forOutput) {
  89. SkASSERT(format.getDawnFormat());
  90. switch (colorType) {
  91. case GrColorType::kAlpha_8: // fall through
  92. case GrColorType::kAlpha_F16:
  93. if (forOutput) {
  94. return GrSwizzle::AAAA();
  95. } else {
  96. return GrSwizzle::RRRR();
  97. }
  98. case GrColorType::kGray_8:
  99. if (!forOutput) {
  100. return GrSwizzle::RRRA();
  101. }
  102. break;
  103. case GrColorType::kRGB_888x:
  104. if (!forOutput) {
  105. return GrSwizzle::RGB1();
  106. }
  107. default:
  108. return GrSwizzle::RGBA();
  109. }
  110. return GrSwizzle::RGBA();
  111. }
  112. bool GrDawnCaps::isFormatTexturable(GrColorType ct, const GrBackendFormat& format) const {
  113. GrPixelConfig config = this->getConfigFromBackendFormat(format, ct);
  114. if (kUnknown_GrPixelConfig == config) {
  115. return false;
  116. }
  117. return this->isConfigTexturable(config);
  118. }
  119. bool GrDawnCaps::isFormatCopyable(GrColorType ct, const GrBackendFormat& format) const {
  120. return true;
  121. }
  122. int GrDawnCaps::getRenderTargetSampleCount(int requestedCount, GrColorType ct,
  123. const GrBackendFormat& format) const {
  124. GrPixelConfig config = this->getConfigFromBackendFormat(format, ct);
  125. if (kUnknown_GrPixelConfig == config) {
  126. return 0;
  127. }
  128. return this->getRenderTargetSampleCount(requestedCount, config);
  129. }
  130. GrBackendFormat GrDawnCaps::getBackendFormatFromColorType(GrColorType ct) const {
  131. GrPixelConfig config = GrColorTypeToPixelConfig(ct);
  132. if (config == kUnknown_GrPixelConfig) {
  133. return GrBackendFormat();
  134. }
  135. dawn::TextureFormat format;
  136. if (!GrPixelConfigToDawnFormat(config, &format)) {
  137. return GrBackendFormat();
  138. }
  139. return GrBackendFormat::MakeDawn(format);
  140. }
  141. GrBackendFormat GrDawnCaps::getBackendFormatFromCompressionType(SkImage::CompressionType type) const
  142. {
  143. return GrBackendFormat();
  144. }
  145. GrSwizzle GrDawnCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const
  146. {
  147. return get_swizzle(format, colorType, false);
  148. }
  149. bool GrDawnCaps::canClearTextureOnCreation() const {
  150. return true;
  151. }
  152. GrSwizzle GrDawnCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const
  153. {
  154. return get_swizzle(format, colorType, true);
  155. }
  156. bool GrDawnCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
  157. const GrBackendFormat& format) const {
  158. return true;
  159. }