ProxyConversionTest.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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/GrBackendSurface.h"
  10. #include "include/gpu/GrRenderTarget.h"
  11. #include "include/gpu/GrTexture.h"
  12. #include "src/gpu/GrContextPriv.h"
  13. #include "src/gpu/GrGpu.h"
  14. #include "src/gpu/GrProxyProvider.h"
  15. #include "src/gpu/GrRenderTargetProxy.h"
  16. #include "src/gpu/GrSurfaceProxy.h"
  17. #include "src/gpu/GrTextureProxy.h"
  18. static sk_sp<GrSurfaceProxy> make_wrapped_rt(GrProxyProvider* provider,
  19. GrGpu* gpu,
  20. skiatest::Reporter* reporter,
  21. const GrSurfaceDesc& desc,
  22. GrSurfaceOrigin origin) {
  23. auto ct = GrPixelConfigToColorType(desc.fConfig);
  24. auto backendRT = gpu->createTestingOnlyBackendRenderTarget(desc.fWidth, desc.fHeight, ct);
  25. return provider->wrapBackendRenderTarget(backendRT, ct, origin, nullptr, nullptr);
  26. }
  27. void clean_up_wrapped_rt(GrGpu* gpu, sk_sp<GrSurfaceProxy> proxy) {
  28. SkASSERT(proxy->unique());
  29. SkASSERT(proxy->peekRenderTarget());
  30. GrBackendRenderTarget rt = proxy->peekRenderTarget()->getBackendRenderTarget();
  31. proxy.reset();
  32. gpu->deleteTestingOnlyBackendRenderTarget(rt);
  33. }
  34. static sk_sp<GrSurfaceProxy> make_offscreen_rt(GrProxyProvider* provider,
  35. const GrSurfaceDesc& desc,
  36. GrSurfaceOrigin origin) {
  37. return provider->testingOnly_createInstantiatedProxy(desc, GrRenderable::kYes, 1, origin,
  38. SkBackingFit::kExact, SkBudgeted::kYes,
  39. GrProtected::kNo);
  40. }
  41. static sk_sp<GrSurfaceProxy> make_texture(GrProxyProvider* provider,
  42. const GrSurfaceDesc& desc,
  43. GrRenderable renderable,
  44. GrSurfaceOrigin origin) {
  45. return provider->testingOnly_createInstantiatedProxy(
  46. desc, renderable, 1, origin, SkBackingFit::kExact, SkBudgeted::kYes, GrProtected::kNo);
  47. }
  48. // Test converting between RenderTargetProxies and TextureProxies for preinstantiated Proxies
  49. DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PreinstantiatedProxyConversionTest, reporter, ctxInfo) {
  50. GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
  51. GrGpu* gpu = ctxInfo.grContext()->priv().getGpu();
  52. GrSurfaceDesc desc;
  53. desc.fWidth = 64;
  54. desc.fHeight = 64;
  55. desc.fConfig = kRGBA_8888_GrPixelConfig;
  56. {
  57. // External on-screen render target.
  58. sk_sp<GrSurfaceProxy> sProxy(
  59. make_wrapped_rt(proxyProvider, gpu, reporter, desc, kBottomLeft_GrSurfaceOrigin));
  60. if (sProxy) {
  61. // RenderTarget-only
  62. GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
  63. REPORTER_ASSERT(reporter, rtProxy);
  64. REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
  65. REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
  66. clean_up_wrapped_rt(gpu, std::move(sProxy));
  67. }
  68. }
  69. {
  70. // Internal offscreen render target.
  71. sk_sp<GrSurfaceProxy> sProxy(
  72. make_offscreen_rt(proxyProvider, desc, kBottomLeft_GrSurfaceOrigin));
  73. if (sProxy) {
  74. // Both RenderTarget and Texture
  75. GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
  76. REPORTER_ASSERT(reporter, rtProxy);
  77. GrTextureProxy* tProxy = rtProxy->asTextureProxy();
  78. REPORTER_ASSERT(reporter, tProxy);
  79. REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
  80. REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
  81. }
  82. }
  83. {
  84. // Internal offscreen render target - but through GrTextureProxy
  85. sk_sp<GrSurfaceProxy> sProxy(
  86. make_texture(proxyProvider, desc, GrRenderable::kYes, kBottomLeft_GrSurfaceOrigin));
  87. if (sProxy) {
  88. // Both RenderTarget and Texture
  89. GrTextureProxy* tProxy = sProxy->asTextureProxy();
  90. REPORTER_ASSERT(reporter, tProxy);
  91. GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
  92. REPORTER_ASSERT(reporter, rtProxy);
  93. REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
  94. REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
  95. }
  96. }
  97. {
  98. // force no-RT
  99. sk_sp<GrSurfaceProxy> sProxy(
  100. make_texture(proxyProvider, desc, GrRenderable::kNo, kBottomLeft_GrSurfaceOrigin));
  101. if (sProxy) {
  102. // Texture-only
  103. GrTextureProxy* tProxy = sProxy->asTextureProxy();
  104. REPORTER_ASSERT(reporter, tProxy);
  105. REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
  106. REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
  107. }
  108. }
  109. }
  110. // Test converting between RenderTargetProxies and TextureProxies for deferred
  111. // Proxies
  112. DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
  113. GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
  114. GrSurfaceDesc desc;
  115. desc.fWidth = 64;
  116. desc.fHeight = 64;
  117. desc.fConfig = kRGBA_8888_GrPixelConfig;
  118. const GrBackendFormat format =
  119. ctxInfo.grContext()->priv().caps()->getBackendFormatFromColorType(
  120. GrColorType::kRGBA_8888);
  121. {
  122. sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
  123. format, desc, GrRenderable::kYes, 1, kBottomLeft_GrSurfaceOrigin,
  124. SkBackingFit::kApprox, SkBudgeted::kYes, GrProtected::kNo);
  125. // Both RenderTarget and Texture
  126. GrRenderTargetProxy* rtProxy = proxy->asRenderTargetProxy();
  127. REPORTER_ASSERT(reporter, rtProxy);
  128. GrTextureProxy* tProxy = rtProxy->asTextureProxy();
  129. REPORTER_ASSERT(reporter, tProxy);
  130. REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
  131. REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
  132. }
  133. {
  134. sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
  135. format, desc, GrRenderable::kYes, 1, kBottomLeft_GrSurfaceOrigin,
  136. SkBackingFit::kApprox, SkBudgeted::kYes, GrProtected::kNo);
  137. // Both RenderTarget and Texture - but via GrTextureProxy
  138. GrTextureProxy* tProxy = proxy->asTextureProxy();
  139. REPORTER_ASSERT(reporter, tProxy);
  140. GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
  141. REPORTER_ASSERT(reporter, rtProxy);
  142. REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
  143. REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
  144. }
  145. {
  146. sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(
  147. format, desc, GrRenderable::kNo, 1, kTopLeft_GrSurfaceOrigin, SkBackingFit::kApprox,
  148. SkBudgeted::kYes, GrProtected::kNo);
  149. // Texture-only
  150. GrTextureProxy* tProxy = proxy->asTextureProxy();
  151. REPORTER_ASSERT(reporter, tProxy);
  152. REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
  153. REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
  154. }
  155. }