• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
10 #include "tests/Test.h"
11 
12 #include "src/gpu/GrContextPriv.h"
13 #include "src/gpu/GrImageInfo.h"
14 #include "src/gpu/GrRenderTargetContext.h"
15 #include "src/gpu/GrTextureProxy.h"
16 
17 static const int kSize = 64;
18 
get_rtc(GrContext * ctx)19 static std::unique_ptr<GrRenderTargetContext> get_rtc(GrContext* ctx) {
20     return GrRenderTargetContext::Make(
21             ctx, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, {kSize, kSize});
22 }
23 
check_instantiation_status(skiatest::Reporter * reporter,GrRenderTargetContext * rtCtx,bool wrappedExpectation)24 static void check_instantiation_status(skiatest::Reporter* reporter,
25                                        GrRenderTargetContext* rtCtx,
26                                        bool wrappedExpectation) {
27     REPORTER_ASSERT(reporter, rtCtx->testingOnly_IsInstantiated() == wrappedExpectation);
28 
29     GrTextureProxy* tProxy = rtCtx->asTextureProxy();
30     REPORTER_ASSERT(reporter, tProxy);
31 
32     REPORTER_ASSERT(reporter, tProxy->isInstantiated() == wrappedExpectation);
33 }
34 
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RenderTargetContextTest,reporter,ctxInfo)35 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RenderTargetContextTest, reporter, ctxInfo) {
36     GrContext* ctx = ctxInfo.grContext();
37 
38     // Calling instantiate on a GrRenderTargetContext's textureProxy also instantiates the
39     // GrRenderTargetContext
40     {
41         auto rtCtx = get_rtc(ctx);
42 
43         check_instantiation_status(reporter, rtCtx.get(), false);
44 
45         GrTextureProxy* tProxy = rtCtx->asTextureProxy();
46         REPORTER_ASSERT(reporter, tProxy);
47 
48         REPORTER_ASSERT(reporter, tProxy->instantiate(ctx->priv().resourceProvider()));
49 
50         check_instantiation_status(reporter, rtCtx.get(), true);
51     }
52 
53     // readPixels switches a deferred rtCtx to wrapped
54     {
55         auto rtCtx = get_rtc(ctx);
56 
57         check_instantiation_status(reporter, rtCtx.get(), false);
58 
59         SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(kSize, kSize);
60         SkAutoTMalloc<uint32_t> dstBuffer(kSize * kSize);
61         static const size_t kRowBytes = sizeof(uint32_t) * kSize;
62 
63         bool result = rtCtx->readPixels(dstInfo, dstBuffer.get(), kRowBytes, {0, 0});
64         REPORTER_ASSERT(reporter, result);
65 
66         check_instantiation_status(reporter, rtCtx.get(), true);
67     }
68 
69     // TODO: in a future world we should be able to add a test that the majority of
70     // GrRenderTargetContext calls do not force the instantiation of a deferred
71     // GrRenderTargetContext
72 }
73