• 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 "include/gpu/GrDirectContext.h"
13 #include "src/gpu/GrDirectContextPriv.h"
14 #include "src/gpu/GrImageInfo.h"
15 #include "src/gpu/GrTextureProxy.h"
16 #include "src/gpu/v1/SurfaceDrawContext_v1.h"
17 
18 static const int kSize = 64;
19 
get_sdc(GrRecordingContext * rContext)20 static std::unique_ptr<skgpu::v1::SurfaceDrawContext> get_sdc(GrRecordingContext* rContext) {
21     return skgpu::v1::SurfaceDrawContext::Make(rContext, GrColorType::kRGBA_8888, nullptr,
22                                                SkBackingFit::kExact, {kSize, kSize},
23                                                SkSurfaceProps());
24 }
25 
check_instantiation_status(skiatest::Reporter * reporter,skgpu::v1::SurfaceDrawContext * sdc,bool wrappedExpectation)26 static void check_instantiation_status(skiatest::Reporter* reporter,
27                                        skgpu::v1::SurfaceDrawContext* sdc,
28                                        bool wrappedExpectation) {
29     REPORTER_ASSERT(reporter, sdc->asRenderTargetProxy()->isInstantiated() == wrappedExpectation);
30 
31     GrTextureProxy* tProxy = sdc->asTextureProxy();
32     REPORTER_ASSERT(reporter, tProxy);
33 
34     REPORTER_ASSERT(reporter, tProxy->isInstantiated() == wrappedExpectation);
35 }
36 
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceDrawContextTest,reporter,ctxInfo)37 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceDrawContextTest, reporter, ctxInfo) {
38     auto dContext = ctxInfo.directContext();
39 
40     // Calling instantiate on a SurfaceDrawContext's textureProxy also instantiates the
41     // SurfaceDrawContext
42     {
43         auto sdc = get_sdc(dContext);
44 
45         check_instantiation_status(reporter, sdc.get(), false);
46 
47         GrTextureProxy* tProxy = sdc->asTextureProxy();
48         REPORTER_ASSERT(reporter, tProxy);
49 
50         REPORTER_ASSERT(reporter, tProxy->instantiate(dContext->priv().resourceProvider()));
51 
52         check_instantiation_status(reporter, sdc.get(), true);
53     }
54 
55     // readPixels switches a deferred sdCtx to wrapped
56     {
57         auto sdc = get_sdc(dContext);
58 
59         check_instantiation_status(reporter, sdc.get(), false);
60 
61         SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(kSize, kSize);
62         GrPixmap dstPM = GrPixmap::Allocate(dstInfo);
63 
64         bool result = sdc->readPixels(dContext, dstPM, {0, 0});
65         REPORTER_ASSERT(reporter, result);
66 
67         check_instantiation_status(reporter, sdc.get(), true);
68     }
69 
70     // TODO: in a future world we should be able to add a test that the majority of
71     // SurfaceDrawContext calls do not force the instantiation of a deferred
72     // SurfaceDrawContext
73 }
74