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