• 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/GrProxyProvider.h"
15 #include "src/gpu/GrRecordingContextPriv.h"
16 #include "src/gpu/GrRenderTargetProxy.h"
17 #include "src/gpu/GrResourceProvider.h"
18 #include "src/gpu/GrSurfaceProxy.h"
19 #include "src/gpu/GrTexture.h"
20 #include "src/gpu/GrTextureProxy.h"
21 #include "tests/TestUtils.h"
22 
23 static const int kWidthHeight = 128;
24 
make_deferred(GrRecordingContext * rContext)25 static sk_sp<GrTextureProxy> make_deferred(GrRecordingContext* rContext) {
26     GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
27     const GrCaps* caps = rContext->priv().caps();
28 
29     const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
30                                                                  GrRenderable::kYes);
31     return proxyProvider->createProxy(format, {kWidthHeight, kWidthHeight}, GrRenderable::kYes, 1,
32                                       GrMipmapped::kNo, SkBackingFit::kApprox, SkBudgeted::kYes,
33                                       GrProtected::kNo);
34 }
35 
make_wrapped(GrRecordingContext * rContext)36 static sk_sp<GrTextureProxy> make_wrapped(GrRecordingContext* rContext) {
37     GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
38 
39     return proxyProvider->testingOnly_createInstantiatedProxy(
40             {kWidthHeight, kWidthHeight}, GrColorType::kRGBA_8888, GrRenderable::kYes, 1,
41             SkBackingFit::kExact, SkBudgeted::kNo, GrProtected::kNo);
42 }
43 
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ProxyRefTest,reporter,ctxInfo)44 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ProxyRefTest, reporter, ctxInfo) {
45     auto dContext = ctxInfo.directContext();
46     GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
47 
48     for (auto make : { make_deferred, make_wrapped }) {
49         // An extra ref
50         {
51             sk_sp<GrTextureProxy> proxy((*make)(dContext));
52             if (proxy) {
53                 sk_sp<GrTextureProxy> extraRef(proxy);  // NOLINT(performance-unnecessary-copy-initialization)
54 
55                 int backingRefs = proxy->isInstantiated() ? 1 : -1;
56 
57                 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, backingRefs);
58 
59                 proxy->instantiate(resourceProvider);
60 
61                 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, 1);
62             }
63             CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1);
64         }
65 
66         // Multiple normal refs
67         {
68             sk_sp<GrTextureProxy> proxy((*make)(dContext));
69             if (proxy) {
70                 proxy->ref();
71                 proxy->ref();
72 
73                 int backingRefs = proxy->isInstantiated() ? 1 : -1;
74 
75                 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, backingRefs);
76 
77                 proxy->instantiate(resourceProvider);
78 
79                 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, 1);
80 
81                 proxy->unref();
82                 proxy->unref();
83             }
84             CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1);
85         }
86 
87         // Continue using (reffing) proxy after instantiation
88         {
89             sk_sp<GrTextureProxy> proxy((*make)(dContext));
90             if (proxy) {
91                 sk_sp<GrTextureProxy> firstExtraRef(proxy);  // NOLINT(performance-unnecessary-copy-initialization)
92 
93                 int backingRefs = proxy->isInstantiated() ? 1 : -1;
94 
95                 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, backingRefs);
96 
97                 proxy->instantiate(resourceProvider);
98 
99                 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, 1);
100 
101                 sk_sp<GrTextureProxy> secondExtraRef(proxy);  // NOLINT(performance-unnecessary-copy-initialization)
102                 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, 1);
103             }
104             CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1);
105         }
106     }
107 }
108