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 | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame^] | 23 | static sk_sp<GrRenderTargetContext> get_rtc(GrContext* ctx) { |
| 24 | return ctx->makeDeferredRenderTargetContext(SkBackingFit::kExact, |
| 25 | kSize, kSize, |
| 26 | kRGBA_8888_GrPixelConfig, nullptr); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | static void check_is_wrapped_status(skiatest::Reporter* reporter, |
| 30 | GrRenderTargetContext* rtCtx, |
| 31 | bool wrappedExpectation) { |
| 32 | REPORTER_ASSERT(reporter, rtCtx->isWrapped_ForTesting() == wrappedExpectation); |
| 33 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 34 | GrTextureProxy* tProxy = rtCtx->asTextureProxy(); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 35 | REPORTER_ASSERT(reporter, tProxy); |
| 36 | |
| 37 | REPORTER_ASSERT(reporter, tProxy->isWrapped_ForTesting() == wrappedExpectation); |
| 38 | } |
| 39 | |
| 40 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RenderTargetContextTest, reporter, ctxInfo) { |
| 41 | GrContext* ctx = ctxInfo.grContext(); |
| 42 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 43 | // Calling instantiate on a GrRenderTargetContext's textureProxy also instantiates the |
| 44 | // GrRenderTargetContext |
| 45 | { |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame^] | 46 | sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx)); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 47 | |
| 48 | check_is_wrapped_status(reporter, rtCtx.get(), false); |
| 49 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 50 | GrTextureProxy* tProxy = rtCtx->asTextureProxy(); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 51 | REPORTER_ASSERT(reporter, tProxy); |
| 52 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 53 | GrTexture* tex = tProxy->instantiate(ctx->resourceProvider()); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 54 | REPORTER_ASSERT(reporter, tex); |
| 55 | |
| 56 | check_is_wrapped_status(reporter, rtCtx.get(), true); |
| 57 | } |
| 58 | |
| 59 | // readPixels switches a deferred rtCtx to wrapped |
| 60 | { |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame^] | 61 | sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx)); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 62 | |
| 63 | check_is_wrapped_status(reporter, rtCtx.get(), false); |
| 64 | |
| 65 | SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(kSize, kSize); |
| 66 | SkAutoTMalloc<uint32_t> dstBuffer(kSize * kSize); |
| 67 | static const size_t kRowBytes = sizeof(uint32_t) * kSize; |
| 68 | |
| 69 | bool result = rtCtx->readPixels(dstInfo, dstBuffer.get(), kRowBytes, 0, 0); |
| 70 | REPORTER_ASSERT(reporter, result); |
| 71 | |
| 72 | check_is_wrapped_status(reporter, rtCtx.get(), true); |
| 73 | } |
| 74 | |
| 75 | // TODO: in a future world we should be able to add a test that the majority of |
| 76 | // GrRenderTargetContext calls do not force the instantiation of a deferred |
| 77 | // GrRenderTargetContext |
| 78 | } |
| 79 | #endif |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 80 | #endif |