GrContextThreadSafeProxy.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 "include/gpu/GrContextThreadSafeProxy.h"
  8. #include "src/gpu/GrContextThreadSafeProxyPriv.h"
  9. #include "include/core/SkSurfaceCharacterization.h"
  10. #include "include/gpu/GrContext.h"
  11. #include "src/gpu/GrBaseContextPriv.h"
  12. #include "src/gpu/GrCaps.h"
  13. #include "src/gpu/GrSkSLFPFactoryCache.h"
  14. #include "src/image/SkSurface_Gpu.h"
  15. #ifdef SK_VULKAN
  16. #include "src/gpu/vk/GrVkCaps.h"
  17. #endif
  18. GrContextThreadSafeProxy::GrContextThreadSafeProxy(GrBackendApi backend,
  19. const GrContextOptions& options,
  20. uint32_t contextID)
  21. : INHERITED(backend, options, contextID) {
  22. }
  23. GrContextThreadSafeProxy::~GrContextThreadSafeProxy() = default;
  24. bool GrContextThreadSafeProxy::init(sk_sp<const GrCaps> caps,
  25. sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) {
  26. return INHERITED::init(std::move(caps), std::move(FPFactoryCache));
  27. }
  28. SkSurfaceCharacterization GrContextThreadSafeProxy::createCharacterization(
  29. size_t cacheMaxResourceBytes,
  30. const SkImageInfo& ii, const GrBackendFormat& backendFormat,
  31. int sampleCnt, GrSurfaceOrigin origin,
  32. const SkSurfaceProps& surfaceProps,
  33. bool isMipMapped, bool willUseGLFBO0, bool isTextureable,
  34. GrProtected isProtected) {
  35. if (!backendFormat.isValid()) {
  36. return SkSurfaceCharacterization(); // return an invalid characterization
  37. }
  38. SkASSERT(isTextureable || !isMipMapped);
  39. if (GrBackendApi::kOpenGL != backendFormat.backend() && willUseGLFBO0) {
  40. // The willUseGLFBO0 flags can only be used for a GL backend.
  41. return SkSurfaceCharacterization(); // return an invalid characterization
  42. }
  43. if (!this->caps()->mipMapSupport()) {
  44. isMipMapped = false;
  45. }
  46. if (!SkSurface_Gpu::Valid(this->caps(), backendFormat)) {
  47. return SkSurfaceCharacterization(); // return an invalid characterization
  48. }
  49. GrColorType grColorType = SkColorTypeToGrColorType(ii.colorType());
  50. if (!this->caps()->areColorTypeAndFormatCompatible(grColorType, backendFormat)) {
  51. return SkSurfaceCharacterization(); // return an invalid characterization
  52. }
  53. sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, grColorType, backendFormat);
  54. if (!sampleCnt) {
  55. return SkSurfaceCharacterization(); // return an invalid characterization
  56. }
  57. if (willUseGLFBO0 && isTextureable) {
  58. return SkSurfaceCharacterization(); // return an invalid characterization
  59. }
  60. if (isTextureable && !this->caps()->isFormatTexturable(grColorType, backendFormat)) {
  61. // Skia doesn't agree that this is textureable.
  62. return SkSurfaceCharacterization(); // return an invalid characterization
  63. }
  64. if (GrBackendApi::kVulkan == backendFormat.backend()) {
  65. if (GrBackendApi::kVulkan != this->backend()) {
  66. return SkSurfaceCharacterization(); // return an invalid characterization
  67. }
  68. #ifdef SK_VULKAN
  69. const GrVkCaps* vkCaps = (const GrVkCaps*) this->caps();
  70. // The protection status of the characterization and the context need to match
  71. if (isProtected != GrProtected(vkCaps->supportsProtectedMemory())) {
  72. return SkSurfaceCharacterization(); // return an invalid characterization
  73. }
  74. #endif
  75. }
  76. return SkSurfaceCharacterization(sk_ref_sp<GrContextThreadSafeProxy>(this),
  77. cacheMaxResourceBytes, ii, backendFormat,
  78. origin, sampleCnt,
  79. SkSurfaceCharacterization::Textureable(isTextureable),
  80. SkSurfaceCharacterization::MipMapped(isMipMapped),
  81. SkSurfaceCharacterization::UsesGLFBO0(willUseGLFBO0),
  82. SkSurfaceCharacterization::VulkanSecondaryCBCompatible(false),
  83. isProtected,
  84. surfaceProps);
  85. }
  86. ////////////////////////////////////////////////////////////////////////////////
  87. sk_sp<GrSkSLFPFactoryCache> GrContextThreadSafeProxyPriv::fpFactoryCache() {
  88. return fProxy->fpFactoryCache();
  89. }
  90. sk_sp<GrContextThreadSafeProxy> GrContextThreadSafeProxyPriv::Make(
  91. GrBackendApi backend,
  92. const GrContextOptions& options,
  93. uint32_t contextID,
  94. sk_sp<const GrCaps> caps,
  95. sk_sp<GrSkSLFPFactoryCache> cache) {
  96. sk_sp<GrContextThreadSafeProxy> proxy(new GrContextThreadSafeProxy(backend, options,
  97. contextID));
  98. if (!proxy->init(std::move(caps), std::move(cache))) {
  99. return nullptr;
  100. }
  101. return proxy;
  102. }