blob: 311643e919f0c2fd4a29ce78302c8a2cd7d92a99 [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#if SK_SUPPORT_GPU
17#include "GrTextureProxy.h"
18#include "GrRenderTargetContext.h"
19
20static const int kSize = 64;
21
Robert Phillipsdd3b3f42017-04-24 10:57:28 -040022static sk_sp<GrRenderTargetContext> get_rtc(GrContext* ctx) {
23 return ctx->makeDeferredRenderTargetContext(SkBackingFit::kExact,
24 kSize, kSize,
25 kRGBA_8888_GrPixelConfig, nullptr);
Robert Phillipseaa86252016-11-08 13:49:39 +000026}
27
28static void check_is_wrapped_status(skiatest::Reporter* reporter,
29 GrRenderTargetContext* rtCtx,
30 bool wrappedExpectation) {
31 REPORTER_ASSERT(reporter, rtCtx->isWrapped_ForTesting() == wrappedExpectation);
32
Robert Phillipsf200a902017-01-30 13:27:37 -050033 GrTextureProxy* tProxy = rtCtx->asTextureProxy();
Robert Phillipseaa86252016-11-08 13:49:39 +000034 REPORTER_ASSERT(reporter, tProxy);
35
36 REPORTER_ASSERT(reporter, tProxy->isWrapped_ForTesting() == wrappedExpectation);
37}
38
39DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RenderTargetContextTest, reporter, ctxInfo) {
40 GrContext* ctx = ctxInfo.grContext();
41
Robert Phillipseaa86252016-11-08 13:49:39 +000042 // Calling instantiate on a GrRenderTargetContext's textureProxy also instantiates the
43 // GrRenderTargetContext
44 {
Robert Phillipsdd3b3f42017-04-24 10:57:28 -040045 sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx));
Robert Phillipseaa86252016-11-08 13:49:39 +000046
47 check_is_wrapped_status(reporter, rtCtx.get(), false);
48
Robert Phillipsf200a902017-01-30 13:27:37 -050049 GrTextureProxy* tProxy = rtCtx->asTextureProxy();
Robert Phillipseaa86252016-11-08 13:49:39 +000050 REPORTER_ASSERT(reporter, tProxy);
51
Robert Phillips81dd3e02017-06-23 11:59:24 -040052 REPORTER_ASSERT(reporter, tProxy->instantiate(ctx->resourceProvider()));
Robert Phillipseaa86252016-11-08 13:49:39 +000053
54 check_is_wrapped_status(reporter, rtCtx.get(), true);
55 }
56
57 // readPixels switches a deferred rtCtx to wrapped
58 {
Robert Phillipsdd3b3f42017-04-24 10:57:28 -040059 sk_sp<GrRenderTargetContext> rtCtx(get_rtc(ctx));
Robert Phillipseaa86252016-11-08 13:49:39 +000060
61 check_is_wrapped_status(reporter, rtCtx.get(), false);
62
63 SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(kSize, kSize);
64 SkAutoTMalloc<uint32_t> dstBuffer(kSize * kSize);
65 static const size_t kRowBytes = sizeof(uint32_t) * kSize;
66
67 bool result = rtCtx->readPixels(dstInfo, dstBuffer.get(), kRowBytes, 0, 0);
68 REPORTER_ASSERT(reporter, result);
69
70 check_is_wrapped_status(reporter, rtCtx.get(), true);
71 }
72
73 // TODO: in a future world we should be able to add a test that the majority of
74 // GrRenderTargetContext calls do not force the instantiation of a deferred
75 // GrRenderTargetContext
76}
77#endif
Robert Phillips1119dc32017-04-11 12:54:57 -040078#endif