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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "tests/Test.h" |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 11 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrContextPriv.h" |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrImageInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrRenderTargetContext.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 15 | #include "src/gpu/GrTextureProxy.h" |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 16 | |
| 17 | static const int kSize = 64; |
| 18 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 19 | static std::unique_ptr<GrRenderTargetContext> get_rtc(GrContext* ctx) { |
Greg Daniel | e20fcad | 2020-01-08 11:52:34 -0500 | [diff] [blame] | 20 | return GrRenderTargetContext::Make( |
| 21 | ctx, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, {kSize, kSize}); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 22 | } |
| 23 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 24 | static void check_instantiation_status(skiatest::Reporter* reporter, |
| 25 | GrRenderTargetContext* rtCtx, |
| 26 | bool wrappedExpectation) { |
| 27 | REPORTER_ASSERT(reporter, rtCtx->testingOnly_IsInstantiated() == wrappedExpectation); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 28 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 29 | GrTextureProxy* tProxy = rtCtx->asTextureProxy(); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 30 | REPORTER_ASSERT(reporter, tProxy); |
| 31 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 32 | REPORTER_ASSERT(reporter, tProxy->isInstantiated() == wrappedExpectation); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RenderTargetContextTest, reporter, ctxInfo) { |
| 36 | GrContext* ctx = ctxInfo.grContext(); |
| 37 | |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 38 | // Calling instantiate on a GrRenderTargetContext's textureProxy also instantiates the |
| 39 | // GrRenderTargetContext |
| 40 | { |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 41 | auto rtCtx = get_rtc(ctx); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 42 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 43 | check_instantiation_status(reporter, rtCtx.get(), false); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 44 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 45 | GrTextureProxy* tProxy = rtCtx->asTextureProxy(); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 46 | REPORTER_ASSERT(reporter, tProxy); |
| 47 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 48 | REPORTER_ASSERT(reporter, tProxy->instantiate(ctx->priv().resourceProvider())); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 49 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 50 | check_instantiation_status(reporter, rtCtx.get(), true); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | // readPixels switches a deferred rtCtx to wrapped |
| 54 | { |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 55 | auto rtCtx = get_rtc(ctx); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 56 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 57 | check_instantiation_status(reporter, rtCtx.get(), false); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 58 | |
| 59 | SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(kSize, kSize); |
| 60 | SkAutoTMalloc<uint32_t> dstBuffer(kSize * kSize); |
| 61 | static const size_t kRowBytes = sizeof(uint32_t) * kSize; |
| 62 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 63 | bool result = rtCtx->readPixels(dstInfo, dstBuffer.get(), kRowBytes, {0, 0}); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 64 | REPORTER_ASSERT(reporter, result); |
| 65 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 66 | check_instantiation_status(reporter, rtCtx.get(), true); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | // 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] | 70 | // GrRenderTargetContext calls do not force the instantiation of a deferred |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 71 | // GrRenderTargetContext |
| 72 | } |