blob: c93a6080eb24da2b014d99efdd2ffe74fac5f03b [file] [log] [blame]
Robert Phillipseaa86252016-11-08 13:49:39 +00001/*
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 Phillips81dd3e02017-06-23 11:59:24 -040012// 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 Phillips1119dc32017-04-11 12:54:57 -040014#if 0
15
Robert Phillipseaa86252016-11-08 13:49:39 +000016#include "GrTextureProxy.h"
17#include "GrRenderTargetContext.h"
18
19static const int kSize = 64;
20
Robert Phillipsdd3b3f42017-04-24 10:57:28 -040021static sk_sp<GrRenderTargetContext> get_rtc(GrContext* ctx) {
22 return ctx->makeDeferredRenderTargetContext(SkBackingFit::kExact,
23 kSize, kSize,
24 kRGBA_8888_GrPixelConfig, nullptr);
Robert Phillipseaa86252016-11-08 13:49:39 +000025}
26
27static void check_is_wrapped_status(skiatest::Reporter* reporter,
28 GrRenderTargetContext* rtCtx,
29 bool wrappedExpectation) {
30 REPORTER_ASSERT(reporter, rtCtx->isWrapped_ForTesting() == wrappedExpectation);
31
Robert Phillipsf200a902017-01-30 13:27:37 -050032 GrTextureProxy* tProxy = rtCtx->asTextureProxy();
Robert Phillipseaa86252016-11-08 13:49:39 +000033 REPORTER_ASSERT(reporter, tProxy);
34
35 REPORTER_ASSERT(reporter, tProxy->isWrapped_ForTesting() == wrappedExpectation);
36}
37
38DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RenderTargetContextTest, reporter, ctxInfo) {
39 GrContext* ctx = ctxInfo.grContext();
40
Robert Phillipseaa86252016-11-08 13:49:39 +000041 // Calling instantiate on a GrRenderTargetContext's textureProxy also instantiates the
42 // GrRenderTargetContext
43 {
Robert Phillipsdd3b3f42017-04-24 10:57:28 -040044 sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx));
Robert Phillipseaa86252016-11-08 13:49:39 +000045
46 check_is_wrapped_status(reporter, rtCtx.get(), false);
47
Robert Phillipsf200a902017-01-30 13:27:37 -050048 GrTextureProxy* tProxy = rtCtx->asTextureProxy();
Robert Phillipseaa86252016-11-08 13:49:39 +000049 REPORTER_ASSERT(reporter, tProxy);
50
Robert Phillips81dd3e02017-06-23 11:59:24 -040051 REPORTER_ASSERT(reporter, tProxy->instantiate(ctx->resourceProvider()));
Robert Phillipseaa86252016-11-08 13:49:39 +000052
53 check_is_wrapped_status(reporter, rtCtx.get(), true);
54 }
55
56 // readPixels switches a deferred rtCtx to wrapped
57 {
Robert Phillipsdd3b3f42017-04-24 10:57:28 -040058 sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx));
Robert Phillipseaa86252016-11-08 13:49:39 +000059
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 Wagner63fd7602017-10-09 15:45:33 -040073 // GrRenderTargetContext calls do not force the instantiation of a deferred
Robert Phillipseaa86252016-11-08 13:49:39 +000074 // GrRenderTargetContext
75}
76#endif