robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "tests/Test.h" |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 11 | |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 12 | #include "include/gpu/GrDirectContext.h" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrDirectContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrProxyProvider.h" |
Robert Phillips | e94b4e1 | 2020-07-23 13:54:35 -0400 | [diff] [blame] | 15 | #include "src/gpu/GrRecordingContextPriv.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 16 | #include "src/gpu/GrRenderTargetProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/gpu/GrResourceProvider.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrSurfaceProxy.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 19 | #include "src/gpu/GrTexture.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 20 | #include "src/gpu/GrTextureProxy.h" |
Brian Salomon | 557e812 | 2019-10-24 10:37:08 -0400 | [diff] [blame] | 21 | #include "tests/TestUtils.h" |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 22 | |
Robert Phillips | 7928e76 | 2017-02-28 16:30:28 -0500 | [diff] [blame] | 23 | static const int kWidthHeight = 128; |
| 24 | |
Robert Phillips | e94b4e1 | 2020-07-23 13:54:35 -0400 | [diff] [blame] | 25 | static sk_sp<GrTextureProxy> make_deferred(GrRecordingContext* rContext) { |
| 26 | GrProxyProvider* proxyProvider = rContext->priv().proxyProvider(); |
| 27 | const GrCaps* caps = rContext->priv().caps(); |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 28 | |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 29 | const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888, |
| 30 | GrRenderable::kYes); |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 31 | return proxyProvider->createProxy(format, {kWidthHeight, kWidthHeight}, GrRenderable::kYes, 1, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 32 | GrMipmapped::kNo, SkBackingFit::kApprox, SkBudgeted::kYes, |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 33 | GrProtected::kNo); |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 34 | } |
| 35 | |
Robert Phillips | e94b4e1 | 2020-07-23 13:54:35 -0400 | [diff] [blame] | 36 | static sk_sp<GrTextureProxy> make_wrapped(GrRecordingContext* rContext) { |
| 37 | GrProxyProvider* proxyProvider = rContext->priv().proxyProvider(); |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 38 | |
Chris Dalton | d004e0b | 2018-09-27 09:28:03 -0600 | [diff] [blame] | 39 | return proxyProvider->testingOnly_createInstantiatedProxy( |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 40 | {kWidthHeight, kWidthHeight}, GrColorType::kRGBA_8888, GrRenderable::kYes, 1, |
Greg Daniel | 3a36511 | 2020-02-14 10:47:18 -0500 | [diff] [blame] | 41 | SkBackingFit::kExact, SkBudgeted::kNo, GrProtected::kNo); |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ProxyRefTest, reporter, ctxInfo) { |
Robert Phillips | e94b4e1 | 2020-07-23 13:54:35 -0400 | [diff] [blame] | 45 | auto dContext = ctxInfo.directContext(); |
| 46 | GrResourceProvider* resourceProvider = dContext->priv().resourceProvider(); |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 47 | |
| 48 | for (auto make : { make_deferred, make_wrapped }) { |
Robert Phillips | 80bff5b | 2019-08-20 16:56:18 -0400 | [diff] [blame] | 49 | // An extra ref |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 50 | { |
Robert Phillips | e94b4e1 | 2020-07-23 13:54:35 -0400 | [diff] [blame] | 51 | sk_sp<GrTextureProxy> proxy((*make)(dContext)); |
Robert Phillips | 80bff5b | 2019-08-20 16:56:18 -0400 | [diff] [blame] | 52 | if (proxy) { |
John Stiles | 31954bf | 2020-08-07 17:35:54 -0400 | [diff] [blame] | 53 | sk_sp<GrTextureProxy> extraRef(proxy); // NOLINT(performance-unnecessary-copy-initialization) |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 54 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 55 | int backingRefs = proxy->isInstantiated() ? 1 : -1; |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 56 | |
Brian Salomon | 28a8f28 | 2019-10-24 20:07:39 -0400 | [diff] [blame] | 57 | CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, backingRefs); |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 58 | |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 59 | proxy->instantiate(resourceProvider); |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 60 | |
Brian Salomon | 28a8f28 | 2019-10-24 20:07:39 -0400 | [diff] [blame] | 61 | CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, 1); |
Jim Van Verth | 311cc6b | 2017-09-20 17:51:59 -0400 | [diff] [blame] | 62 | } |
Brian Salomon | 28a8f28 | 2019-10-24 20:07:39 -0400 | [diff] [blame] | 63 | CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1); |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | // Multiple normal refs |
| 67 | { |
Robert Phillips | e94b4e1 | 2020-07-23 13:54:35 -0400 | [diff] [blame] | 68 | sk_sp<GrTextureProxy> proxy((*make)(dContext)); |
John Stiles | a008b0f | 2020-08-16 08:48:02 -0400 | [diff] [blame] | 69 | if (proxy) { |
Jim Van Verth | 311cc6b | 2017-09-20 17:51:59 -0400 | [diff] [blame] | 70 | proxy->ref(); |
| 71 | proxy->ref(); |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 72 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 73 | int backingRefs = proxy->isInstantiated() ? 1 : -1; |
Robert Phillips | 715d08c | 2018-07-18 13:56:48 -0400 | [diff] [blame] | 74 | |
Brian Salomon | 28a8f28 | 2019-10-24 20:07:39 -0400 | [diff] [blame] | 75 | CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, backingRefs); |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 76 | |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 77 | proxy->instantiate(resourceProvider); |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 78 | |
Brian Salomon | 28a8f28 | 2019-10-24 20:07:39 -0400 | [diff] [blame] | 79 | CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, 1); |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 80 | |
Jim Van Verth | 311cc6b | 2017-09-20 17:51:59 -0400 | [diff] [blame] | 81 | proxy->unref(); |
| 82 | proxy->unref(); |
| 83 | } |
Brian Salomon | 28a8f28 | 2019-10-24 20:07:39 -0400 | [diff] [blame] | 84 | CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1); |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | // Continue using (reffing) proxy after instantiation |
| 88 | { |
Robert Phillips | e94b4e1 | 2020-07-23 13:54:35 -0400 | [diff] [blame] | 89 | sk_sp<GrTextureProxy> proxy((*make)(dContext)); |
Robert Phillips | 80bff5b | 2019-08-20 16:56:18 -0400 | [diff] [blame] | 90 | if (proxy) { |
John Stiles | 31954bf | 2020-08-07 17:35:54 -0400 | [diff] [blame] | 91 | sk_sp<GrTextureProxy> firstExtraRef(proxy); // NOLINT(performance-unnecessary-copy-initialization) |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 92 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 93 | int backingRefs = proxy->isInstantiated() ? 1 : -1; |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 94 | |
Brian Salomon | 28a8f28 | 2019-10-24 20:07:39 -0400 | [diff] [blame] | 95 | CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, backingRefs); |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 96 | |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 97 | proxy->instantiate(resourceProvider); |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 98 | |
Brian Salomon | 28a8f28 | 2019-10-24 20:07:39 -0400 | [diff] [blame] | 99 | CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, 1); |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 100 | |
John Stiles | 31954bf | 2020-08-07 17:35:54 -0400 | [diff] [blame] | 101 | sk_sp<GrTextureProxy> secondExtraRef(proxy); // NOLINT(performance-unnecessary-copy-initialization) |
Brian Salomon | 28a8f28 | 2019-10-24 20:07:39 -0400 | [diff] [blame] | 102 | CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, 1); |
Jim Van Verth | 311cc6b | 2017-09-20 17:51:59 -0400 | [diff] [blame] | 103 | } |
Brian Salomon | 28a8f28 | 2019-10-24 20:07:39 -0400 | [diff] [blame] | 104 | CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1); |
robertphillips | 1125a03 | 2016-11-16 11:17:17 -0800 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | } |