RenderTargetContextTest.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "src/gpu/GrContextPriv.h"
  10. #include "src/gpu/GrRenderTargetContext.h"
  11. #include "src/gpu/GrTextureProxy.h"
  12. static const int kSize = 64;
  13. static sk_sp<GrRenderTargetContext> get_rtc(GrContext* ctx) {
  14. return ctx->priv().makeDeferredRenderTargetContext(SkBackingFit::kExact, kSize, kSize,
  15. GrColorType::kRGBA_8888, nullptr);
  16. }
  17. static void check_instantiation_status(skiatest::Reporter* reporter,
  18. GrRenderTargetContext* rtCtx,
  19. bool wrappedExpectation) {
  20. REPORTER_ASSERT(reporter, rtCtx->testingOnly_IsInstantiated() == wrappedExpectation);
  21. GrTextureProxy* tProxy = rtCtx->asTextureProxy();
  22. REPORTER_ASSERT(reporter, tProxy);
  23. REPORTER_ASSERT(reporter, tProxy->isInstantiated() == wrappedExpectation);
  24. }
  25. DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RenderTargetContextTest, reporter, ctxInfo) {
  26. GrContext* ctx = ctxInfo.grContext();
  27. // Calling instantiate on a GrRenderTargetContext's textureProxy also instantiates the
  28. // GrRenderTargetContext
  29. {
  30. sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx));
  31. check_instantiation_status(reporter, rtCtx.get(), false);
  32. GrTextureProxy* tProxy = rtCtx->asTextureProxy();
  33. REPORTER_ASSERT(reporter, tProxy);
  34. REPORTER_ASSERT(reporter, tProxy->instantiate(ctx->priv().resourceProvider()));
  35. check_instantiation_status(reporter, rtCtx.get(), true);
  36. }
  37. // readPixels switches a deferred rtCtx to wrapped
  38. {
  39. sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx));
  40. check_instantiation_status(reporter, rtCtx.get(), false);
  41. SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(kSize, kSize);
  42. SkAutoTMalloc<uint32_t> dstBuffer(kSize * kSize);
  43. static const size_t kRowBytes = sizeof(uint32_t) * kSize;
  44. bool result = rtCtx->readPixels(dstInfo, dstBuffer.get(), kRowBytes, {0, 0});
  45. REPORTER_ASSERT(reporter, result);
  46. check_instantiation_status(reporter, rtCtx.get(), true);
  47. }
  48. // TODO: in a future world we should be able to add a test that the majority of
  49. // GrRenderTargetContext calls do not force the instantiation of a deferred
  50. // GrRenderTargetContext
  51. }