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 | 81dd3e0 | 2017-06-23 11:59:24 -0400 | [diff] [blame] | 12 | // MDB TODO: the early instantiation of the renderTargetContext's backing GrRenderTargetProxy |
| 13 | // mixes this test up. Re-enable once backing GPU resources are distributed by MDB at flush time. |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 14 | #if 0 |
| 15 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 16 | #include "GrTextureProxy.h" |
| 17 | #include "GrRenderTargetContext.h" |
| 18 | |
| 19 | static const int kSize = 64; |
| 20 | |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame] | 21 | static sk_sp<GrRenderTargetContext> get_rtc(GrContext* ctx) { |
| 22 | return ctx->makeDeferredRenderTargetContext(SkBackingFit::kExact, |
| 23 | kSize, kSize, |
| 24 | kRGBA_8888_GrPixelConfig, nullptr); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | static void check_is_wrapped_status(skiatest::Reporter* reporter, |
| 28 | GrRenderTargetContext* rtCtx, |
| 29 | bool wrappedExpectation) { |
| 30 | REPORTER_ASSERT(reporter, rtCtx->isWrapped_ForTesting() == wrappedExpectation); |
| 31 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 32 | GrTextureProxy* tProxy = rtCtx->asTextureProxy(); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 33 | REPORTER_ASSERT(reporter, tProxy); |
| 34 | |
| 35 | REPORTER_ASSERT(reporter, tProxy->isWrapped_ForTesting() == wrappedExpectation); |
| 36 | } |
| 37 | |
| 38 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RenderTargetContextTest, reporter, ctxInfo) { |
| 39 | GrContext* ctx = ctxInfo.grContext(); |
| 40 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 41 | // Calling instantiate on a GrRenderTargetContext's textureProxy also instantiates the |
| 42 | // GrRenderTargetContext |
| 43 | { |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame] | 44 | sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx)); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 45 | |
| 46 | check_is_wrapped_status(reporter, rtCtx.get(), false); |
| 47 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 48 | GrTextureProxy* tProxy = rtCtx->asTextureProxy(); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 49 | REPORTER_ASSERT(reporter, tProxy); |
| 50 | |
Robert Phillips | 81dd3e0 | 2017-06-23 11:59:24 -0400 | [diff] [blame] | 51 | REPORTER_ASSERT(reporter, tProxy->instantiate(ctx->resourceProvider())); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 52 | |
| 53 | check_is_wrapped_status(reporter, rtCtx.get(), true); |
| 54 | } |
| 55 | |
| 56 | // readPixels switches a deferred rtCtx to wrapped |
| 57 | { |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame] | 58 | sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx)); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 59 | |
| 60 | check_is_wrapped_status(reporter, rtCtx.get(), false); |
| 61 | |
| 62 | SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(kSize, kSize); |
| 63 | SkAutoTMalloc<uint32_t> dstBuffer(kSize * kSize); |
| 64 | static const size_t kRowBytes = sizeof(uint32_t) * kSize; |
| 65 | |
| 66 | bool result = rtCtx->readPixels(dstInfo, dstBuffer.get(), kRowBytes, 0, 0); |
| 67 | REPORTER_ASSERT(reporter, result); |
| 68 | |
| 69 | check_is_wrapped_status(reporter, rtCtx.get(), true); |
| 70 | } |
| 71 | |
| 72 | // TODO: in a future world we should be able to add a test that the majority of |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 73 | // GrRenderTargetContext calls do not force the instantiation of a deferred |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 74 | // GrRenderTargetContext |
| 75 | } |
| 76 | #endif |