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