Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 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 | |
| 8 | // This is a GPU-backend specific test. |
| 9 | |
| 10 | #include "Test.h" |
| 11 | |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame^] | 12 | // MDB TODO: With the move of the discard calls to the RenderTargetContext, deferred RTCs are being |
| 13 | // instantiated early. This test can be re-enabled once discards do not force an instantiation |
| 14 | // (i.e., when renderTargetProxies carry the op IORefs) |
| 15 | #if 0 |
| 16 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 17 | #if SK_SUPPORT_GPU |
| 18 | #include "GrTextureProxy.h" |
| 19 | #include "GrRenderTargetContext.h" |
| 20 | |
| 21 | static const int kSize = 64; |
| 22 | |
Robert Phillips | 9342921 | 2017-04-11 12:23:17 +0000 | [diff] [blame] | 23 | static sk_sp<GrRenderTargetContext> get_rtc(GrContext* ctx, bool wrapped) { |
| 24 | |
| 25 | if (wrapped) { |
| 26 | return ctx->makeRenderTargetContext(SkBackingFit::kExact, |
| 27 | kSize, kSize, |
| 28 | kRGBA_8888_GrPixelConfig, nullptr); |
| 29 | } else { |
| 30 | return ctx->makeDeferredRenderTargetContext(SkBackingFit::kExact, |
| 31 | kSize, kSize, |
| 32 | kRGBA_8888_GrPixelConfig, nullptr); |
| 33 | } |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static void check_is_wrapped_status(skiatest::Reporter* reporter, |
| 37 | GrRenderTargetContext* rtCtx, |
| 38 | bool wrappedExpectation) { |
| 39 | REPORTER_ASSERT(reporter, rtCtx->isWrapped_ForTesting() == wrappedExpectation); |
| 40 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 41 | GrTextureProxy* tProxy = rtCtx->asTextureProxy(); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 42 | REPORTER_ASSERT(reporter, tProxy); |
| 43 | |
| 44 | REPORTER_ASSERT(reporter, tProxy->isWrapped_ForTesting() == wrappedExpectation); |
| 45 | } |
| 46 | |
| 47 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RenderTargetContextTest, reporter, ctxInfo) { |
| 48 | GrContext* ctx = ctxInfo.grContext(); |
| 49 | |
Robert Phillips | 9342921 | 2017-04-11 12:23:17 +0000 | [diff] [blame] | 50 | // A wrapped rtCtx's textureProxy is also wrapped |
| 51 | { |
| 52 | sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx, true)); |
| 53 | check_is_wrapped_status(reporter, rtCtx.get(), true); |
| 54 | } |
| 55 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 56 | // Calling instantiate on a GrRenderTargetContext's textureProxy also instantiates the |
| 57 | // GrRenderTargetContext |
| 58 | { |
Robert Phillips | 9342921 | 2017-04-11 12:23:17 +0000 | [diff] [blame] | 59 | sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx, false)); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 60 | |
| 61 | check_is_wrapped_status(reporter, rtCtx.get(), false); |
| 62 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 63 | GrTextureProxy* tProxy = rtCtx->asTextureProxy(); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 64 | REPORTER_ASSERT(reporter, tProxy); |
| 65 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 66 | GrTexture* tex = tProxy->instantiate(ctx->resourceProvider()); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 67 | REPORTER_ASSERT(reporter, tex); |
| 68 | |
| 69 | check_is_wrapped_status(reporter, rtCtx.get(), true); |
| 70 | } |
| 71 | |
| 72 | // readPixels switches a deferred rtCtx to wrapped |
| 73 | { |
Robert Phillips | 9342921 | 2017-04-11 12:23:17 +0000 | [diff] [blame] | 74 | sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx, false)); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 75 | |
| 76 | check_is_wrapped_status(reporter, rtCtx.get(), false); |
| 77 | |
| 78 | SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(kSize, kSize); |
| 79 | SkAutoTMalloc<uint32_t> dstBuffer(kSize * kSize); |
| 80 | static const size_t kRowBytes = sizeof(uint32_t) * kSize; |
| 81 | |
| 82 | bool result = rtCtx->readPixels(dstInfo, dstBuffer.get(), kRowBytes, 0, 0); |
| 83 | REPORTER_ASSERT(reporter, result); |
| 84 | |
| 85 | check_is_wrapped_status(reporter, rtCtx.get(), true); |
| 86 | } |
| 87 | |
| 88 | // TODO: in a future world we should be able to add a test that the majority of |
| 89 | // GrRenderTargetContext calls do not force the instantiation of a deferred |
| 90 | // GrRenderTargetContext |
| 91 | } |
| 92 | #endif |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame^] | 93 | #endif |