SkSurfaceCharacterization.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright 2018 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 "include/core/SkSurfaceCharacterization.h"
  8. #if SK_SUPPORT_GPU
  9. #include "src/gpu/GrCaps.h"
  10. #include "src/gpu/GrContextThreadSafeProxyPriv.h"
  11. #ifdef SK_DEBUG
  12. void SkSurfaceCharacterization::validate() const {
  13. const GrCaps* caps = fContextInfo->priv().caps();
  14. GrColorType grCT = SkColorTypeToGrColorType(this->colorType());
  15. int maxColorSamples = caps->maxRenderTargetSampleCount(grCT, fBackendFormat);
  16. SkASSERT(maxColorSamples && fSampleCnt && fSampleCnt <= maxColorSamples);
  17. SkASSERT(caps->areColorTypeAndFormatCompatible(grCT, fBackendFormat));
  18. }
  19. #endif
  20. bool SkSurfaceCharacterization::operator==(const SkSurfaceCharacterization& other) const {
  21. if (!this->isValid() || !other.isValid()) {
  22. return false;
  23. }
  24. if (fContextInfo != other.fContextInfo) {
  25. return false;
  26. }
  27. return fCacheMaxResourceBytes == other.fCacheMaxResourceBytes &&
  28. fOrigin == other.fOrigin &&
  29. fImageInfo == other.fImageInfo &&
  30. fBackendFormat == other.fBackendFormat &&
  31. fSampleCnt == other.fSampleCnt &&
  32. fIsTextureable == other.fIsTextureable &&
  33. fIsMipMapped == other.fIsMipMapped &&
  34. fUsesGLFBO0 == other.fUsesGLFBO0 &&
  35. fVulkanSecondaryCBCompatible == other.fVulkanSecondaryCBCompatible &&
  36. fIsProtected == other.fIsProtected &&
  37. fSurfaceProps == other.fSurfaceProps;
  38. }
  39. SkSurfaceCharacterization SkSurfaceCharacterization::createResized(int width, int height) const {
  40. const GrCaps* caps = fContextInfo->priv().caps();
  41. if (!caps) {
  42. return SkSurfaceCharacterization();
  43. }
  44. if (width <= 0 || height <= 0 || width > caps->maxRenderTargetSize() ||
  45. height > caps->maxRenderTargetSize()) {
  46. return SkSurfaceCharacterization();
  47. }
  48. return SkSurfaceCharacterization(fContextInfo, fCacheMaxResourceBytes,
  49. fImageInfo.makeWH(width, height), fBackendFormat, fOrigin,
  50. fSampleCnt, fIsTextureable, fIsMipMapped, fUsesGLFBO0,
  51. fVulkanSecondaryCBCompatible, fIsProtected, fSurfaceProps);
  52. }
  53. bool SkSurfaceCharacterization::isCompatible(const GrBackendTexture& backendTex) const {
  54. if (!this->isValid() || !backendTex.isValid()) {
  55. return false;
  56. }
  57. if (fBackendFormat != backendTex.getBackendFormat()) {
  58. return false;
  59. }
  60. if (this->usesGLFBO0()) {
  61. // It is a backend texture so can't be wrapping FBO0
  62. return false;
  63. }
  64. if (this->vulkanSecondaryCBCompatible()) {
  65. return false;
  66. }
  67. if (this->isMipMapped() && !backendTex.hasMipMaps()) {
  68. // backend texture is allowed to have mipmaps even if the characterization doesn't require
  69. // them.
  70. return false;
  71. }
  72. if (this->width() != backendTex.width() || this->height() != backendTex.height()) {
  73. return false;
  74. }
  75. if (this->isProtected() != GrProtected(backendTex.isProtected())) {
  76. return false;
  77. }
  78. return true;
  79. }
  80. #endif