blob: 760b258d07e3037a870d28f4b140b22f0ba311e8 [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 Phillips1119dc32017-04-11 12:54:57 -040012// 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 Phillipseaa86252016-11-08 13:49:39 +000017#if SK_SUPPORT_GPU
18#include "GrTextureProxy.h"
19#include "GrRenderTargetContext.h"
20
21static const int kSize = 64;
22
Robert Phillips93429212017-04-11 12:23:17 +000023static sk_sp<GrRenderTargetContext> get_rtc(GrContext* ctx, bool wrapped) {
24
25 if (wrapped) {
26 return ctx->makeRenderTargetContext(SkBackingFit::kExact,
27 kSize, kSize,
28 kRGBA_8888_GrPixelConfig, nullptr);
29 } else {
30 return ctx->makeDeferredRenderTargetContext(SkBackingFit::kExact,
31 kSize, kSize,
32 kRGBA_8888_GrPixelConfig, nullptr);
33 }
Robert Phillipseaa86252016-11-08 13:49:39 +000034}
35
36static void check_is_wrapped_status(skiatest::Reporter* reporter,
37 GrRenderTargetContext* rtCtx,
38 bool wrappedExpectation) {
39 REPORTER_ASSERT(reporter, rtCtx->isWrapped_ForTesting() == wrappedExpectation);
40
Robert Phillipsf200a902017-01-30 13:27:37 -050041 GrTextureProxy* tProxy = rtCtx->asTextureProxy();
Robert Phillipseaa86252016-11-08 13:49:39 +000042 REPORTER_ASSERT(reporter, tProxy);
43
44 REPORTER_ASSERT(reporter, tProxy->isWrapped_ForTesting() == wrappedExpectation);
45}
46
47DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RenderTargetContextTest, reporter, ctxInfo) {
48 GrContext* ctx = ctxInfo.grContext();
49
Robert Phillips93429212017-04-11 12:23:17 +000050 // A wrapped rtCtx's textureProxy is also wrapped
51 {
52 sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx, true));
53 check_is_wrapped_status(reporter, rtCtx.get(), true);
54 }
55
Robert Phillipseaa86252016-11-08 13:49:39 +000056 // Calling instantiate on a GrRenderTargetContext's textureProxy also instantiates the
57 // GrRenderTargetContext
58 {
Robert Phillips93429212017-04-11 12:23:17 +000059 sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx, false));
Robert Phillipseaa86252016-11-08 13:49:39 +000060
61 check_is_wrapped_status(reporter, rtCtx.get(), false);
62
Robert Phillipsf200a902017-01-30 13:27:37 -050063 GrTextureProxy* tProxy = rtCtx->asTextureProxy();
Robert Phillipseaa86252016-11-08 13:49:39 +000064 REPORTER_ASSERT(reporter, tProxy);
65
Brian Osman32342f02017-03-04 08:12:46 -050066 GrTexture* tex = tProxy->instantiate(ctx->resourceProvider());
Robert Phillipseaa86252016-11-08 13:49:39 +000067 REPORTER_ASSERT(reporter, tex);
68
69 check_is_wrapped_status(reporter, rtCtx.get(), true);
70 }
71
72 // readPixels switches a deferred rtCtx to wrapped
73 {
Robert Phillips93429212017-04-11 12:23:17 +000074 sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx, false));
Robert Phillipseaa86252016-11-08 13:49:39 +000075
76 check_is_wrapped_status(reporter, rtCtx.get(), false);
77
78 SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(kSize, kSize);
79 SkAutoTMalloc<uint32_t> dstBuffer(kSize * kSize);
80 static const size_t kRowBytes = sizeof(uint32_t) * kSize;
81
82 bool result = rtCtx->readPixels(dstInfo, dstBuffer.get(), kRowBytes, 0, 0);
83 REPORTER_ASSERT(reporter, result);
84
85 check_is_wrapped_status(reporter, rtCtx.get(), true);
86 }
87
88 // TODO: in a future world we should be able to add a test that the majority of
89 // GrRenderTargetContext calls do not force the instantiation of a deferred
90 // GrRenderTargetContext
91}
92#endif
Robert Phillips1119dc32017-04-11 12:54:57 -040093#endif