blob: dbb41851c68499ae1d4e40c3311e92e0edea3ac4 [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 Phillipsdd3b3f42017-04-24 10:57:28 -040023static sk_sp<GrRenderTargetContext> get_rtc(GrContext* ctx) {
24 return ctx->makeDeferredRenderTargetContext(SkBackingFit::kExact,
25 kSize, kSize,
26 kRGBA_8888_GrPixelConfig, nullptr);
Robert Phillipseaa86252016-11-08 13:49:39 +000027}
28
29static void check_is_wrapped_status(skiatest::Reporter* reporter,
30 GrRenderTargetContext* rtCtx,
31 bool wrappedExpectation) {
32 REPORTER_ASSERT(reporter, rtCtx->isWrapped_ForTesting() == wrappedExpectation);
33
Robert Phillipsf200a902017-01-30 13:27:37 -050034 GrTextureProxy* tProxy = rtCtx->asTextureProxy();
Robert Phillipseaa86252016-11-08 13:49:39 +000035 REPORTER_ASSERT(reporter, tProxy);
36
37 REPORTER_ASSERT(reporter, tProxy->isWrapped_ForTesting() == wrappedExpectation);
38}
39
40DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RenderTargetContextTest, reporter, ctxInfo) {
41 GrContext* ctx = ctxInfo.grContext();
42
Robert Phillipseaa86252016-11-08 13:49:39 +000043 // Calling instantiate on a GrRenderTargetContext's textureProxy also instantiates the
44 // GrRenderTargetContext
45 {
Robert Phillipsdd3b3f42017-04-24 10:57:28 -040046 sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx));
Robert Phillipseaa86252016-11-08 13:49:39 +000047
48 check_is_wrapped_status(reporter, rtCtx.get(), false);
49
Robert Phillipsf200a902017-01-30 13:27:37 -050050 GrTextureProxy* tProxy = rtCtx->asTextureProxy();
Robert Phillipseaa86252016-11-08 13:49:39 +000051 REPORTER_ASSERT(reporter, tProxy);
52
Brian Osman32342f02017-03-04 08:12:46 -050053 GrTexture* tex = tProxy->instantiate(ctx->resourceProvider());
Robert Phillipseaa86252016-11-08 13:49:39 +000054 REPORTER_ASSERT(reporter, tex);
55
56 check_is_wrapped_status(reporter, rtCtx.get(), true);
57 }
58
59 // readPixels switches a deferred rtCtx to wrapped
60 {
Robert Phillipsdd3b3f42017-04-24 10:57:28 -040061 sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx));
Robert Phillipseaa86252016-11-08 13:49:39 +000062
63 check_is_wrapped_status(reporter, rtCtx.get(), false);
64
65 SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(kSize, kSize);
66 SkAutoTMalloc<uint32_t> dstBuffer(kSize * kSize);
67 static const size_t kRowBytes = sizeof(uint32_t) * kSize;
68
69 bool result = rtCtx->readPixels(dstInfo, dstBuffer.get(), kRowBytes, 0, 0);
70 REPORTER_ASSERT(reporter, result);
71
72 check_is_wrapped_status(reporter, rtCtx.get(), true);
73 }
74
75 // TODO: in a future world we should be able to add a test that the majority of
76 // GrRenderTargetContext calls do not force the instantiation of a deferred
77 // GrRenderTargetContext
78}
79#endif
Robert Phillips1119dc32017-04-11 12:54:57 -040080#endif