ProxyRefTest.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright 2016 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. // This is a GPU-backend specific test.
  8. #include "tests/Test.h"
  9. #include "include/gpu/GrTexture.h"
  10. #include "src/gpu/GrContextPriv.h"
  11. #include "src/gpu/GrPendingIOResource.h"
  12. #include "src/gpu/GrProxyProvider.h"
  13. #include "src/gpu/GrRenderTargetProxy.h"
  14. #include "src/gpu/GrResourceProvider.h"
  15. #include "src/gpu/GrSurfaceProxy.h"
  16. #include "src/gpu/GrTextureProxy.h"
  17. static const int kWidthHeight = 128;
  18. static void check_refs(skiatest::Reporter* reporter,
  19. GrTextureProxy* proxy,
  20. int32_t expectedProxyRefs,
  21. int32_t expectedBackingRefs) {
  22. int32_t actualProxyRefs = proxy->priv().getProxyRefCnt();
  23. int32_t actualBackingRefs = proxy->testingOnly_getBackingRefCnt();
  24. SkASSERT(actualProxyRefs == expectedProxyRefs);
  25. SkASSERT(actualBackingRefs == expectedBackingRefs);
  26. REPORTER_ASSERT(reporter, actualProxyRefs == expectedProxyRefs);
  27. REPORTER_ASSERT(reporter, actualBackingRefs == expectedBackingRefs);
  28. }
  29. static sk_sp<GrTextureProxy> make_deferred(GrProxyProvider* proxyProvider, const GrCaps* caps) {
  30. GrSurfaceDesc desc;
  31. desc.fWidth = kWidthHeight;
  32. desc.fHeight = kWidthHeight;
  33. desc.fConfig = kRGBA_8888_GrPixelConfig;
  34. const GrBackendFormat format = caps->getBackendFormatFromColorType(GrColorType::kRGBA_8888);
  35. return proxyProvider->createProxy(format, desc, GrRenderable::kYes, 1,
  36. kBottomLeft_GrSurfaceOrigin, SkBackingFit::kApprox,
  37. SkBudgeted::kYes, GrProtected::kNo);
  38. }
  39. static sk_sp<GrTextureProxy> make_wrapped(GrProxyProvider* proxyProvider, const GrCaps* caps) {
  40. GrSurfaceDesc desc;
  41. desc.fWidth = kWidthHeight;
  42. desc.fHeight = kWidthHeight;
  43. desc.fConfig = kRGBA_8888_GrPixelConfig;
  44. return proxyProvider->testingOnly_createInstantiatedProxy(
  45. desc, GrRenderable::kYes, 1, kBottomLeft_GrSurfaceOrigin, SkBackingFit::kExact,
  46. SkBudgeted::kNo, GrProtected::kNo);
  47. }
  48. DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ProxyRefTest, reporter, ctxInfo) {
  49. GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
  50. GrResourceProvider* resourceProvider = ctxInfo.grContext()->priv().resourceProvider();
  51. const GrCaps* caps = ctxInfo.grContext()->priv().caps();
  52. for (auto make : { make_deferred, make_wrapped }) {
  53. // Pending IO ref
  54. {
  55. sk_sp<GrTextureProxy> proxy((*make)(proxyProvider, caps));
  56. if (proxy.get()) {
  57. GrProxyPendingIO pendingIO(proxy.get());
  58. int backingRefs = proxy->isInstantiated() ? 1 : -1;
  59. check_refs(reporter, proxy.get(), 2, backingRefs);
  60. proxy->instantiate(resourceProvider);
  61. check_refs(reporter, proxy.get(), 2, 1);
  62. }
  63. check_refs(reporter, proxy.get(), 1, 1);
  64. }
  65. // Multiple normal refs
  66. {
  67. sk_sp<GrTextureProxy> proxy((*make)(proxyProvider, caps));
  68. if (proxy.get()) {
  69. proxy->ref();
  70. proxy->ref();
  71. int backingRefs = proxy->isInstantiated() ? 1 : -1;
  72. check_refs(reporter, proxy.get(), 3, backingRefs);
  73. proxy->instantiate(resourceProvider);
  74. check_refs(reporter, proxy.get(), 3, 1);
  75. proxy->unref();
  76. proxy->unref();
  77. }
  78. check_refs(reporter, proxy.get(), 1, 1);
  79. }
  80. // Continue using (reffing) proxy after instantiation
  81. {
  82. sk_sp<GrTextureProxy> proxy((*make)(proxyProvider, caps));
  83. if (proxy.get()) {
  84. proxy->ref();
  85. GrProxyPendingIO pendingIO(proxy.get());
  86. int backingRefs = proxy->isInstantiated() ? 1 : -1;
  87. check_refs(reporter, proxy.get(), 3, backingRefs);
  88. proxy->instantiate(resourceProvider);
  89. check_refs(reporter, proxy.get(), 3, 1);
  90. proxy->unref();
  91. check_refs(reporter, proxy.get(), 2, 1);
  92. GrProxyPendingIO secondPendingIO(proxy.get());
  93. check_refs(reporter, proxy.get(), 3, 1);
  94. }
  95. check_refs(reporter, proxy.get(), 1, 1);
  96. }
  97. }
  98. }