blob: 3a460f0ffee60ed28451c218201f6eb3825b081e [file] [log] [blame]
robertphillips1125a032016-11-16 11:17:17 -08001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -050010#include "tests/Test.h"
robertphillips1125a032016-11-16 11:17:17 -080011
Robert Phillips6d344c32020-07-06 10:56:46 -040012#include "include/gpu/GrDirectContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/GrContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrProxyProvider.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040015#include "src/gpu/GrRenderTargetProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "src/gpu/GrResourceProvider.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040017#include "src/gpu/GrSurfaceProxy.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000018#include "src/gpu/GrTexture.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040019#include "src/gpu/GrTextureProxy.h"
Brian Salomon557e8122019-10-24 10:37:08 -040020#include "tests/TestUtils.h"
robertphillips1125a032016-11-16 11:17:17 -080021
Robert Phillips7928e762017-02-28 16:30:28 -050022static const int kWidthHeight = 128;
23
Robert Phillips0a15cc62019-07-30 12:49:10 -040024static sk_sp<GrTextureProxy> make_deferred(GrContext* context) {
25 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
26 const GrCaps* caps = context->priv().caps();
27
Robert Phillips0a15cc62019-07-30 12:49:10 -040028 const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
29 GrRenderable::kYes);
Brian Salomondf1bd6d2020-03-26 20:37:01 -040030 return proxyProvider->createProxy(format, {kWidthHeight, kWidthHeight}, GrRenderable::kYes, 1,
Brian Salomon7e67dca2020-07-21 09:27:25 -040031 GrMipmapped::kNo, SkBackingFit::kApprox, SkBudgeted::kYes,
Brian Salomondf1bd6d2020-03-26 20:37:01 -040032 GrProtected::kNo);
robertphillips1125a032016-11-16 11:17:17 -080033}
34
Robert Phillips0a15cc62019-07-30 12:49:10 -040035static sk_sp<GrTextureProxy> make_wrapped(GrContext* context) {
36 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
37
Chris Daltond004e0b2018-09-27 09:28:03 -060038 return proxyProvider->testingOnly_createInstantiatedProxy(
Brian Salomon4eb38b72019-08-05 12:58:39 -040039 {kWidthHeight, kWidthHeight}, GrColorType::kRGBA_8888, GrRenderable::kYes, 1,
Greg Daniel3a365112020-02-14 10:47:18 -050040 SkBackingFit::kExact, SkBudgeted::kNo, GrProtected::kNo);
robertphillips1125a032016-11-16 11:17:17 -080041}
42
43DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ProxyRefTest, reporter, ctxInfo) {
Robert Phillips6d344c32020-07-06 10:56:46 -040044 auto direct = ctxInfo.directContext();
45 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
robertphillips1125a032016-11-16 11:17:17 -080046
47 for (auto make : { make_deferred, make_wrapped }) {
Robert Phillips80bff5b2019-08-20 16:56:18 -040048 // An extra ref
robertphillips1125a032016-11-16 11:17:17 -080049 {
Robert Phillips6d344c32020-07-06 10:56:46 -040050 sk_sp<GrTextureProxy> proxy((*make)(direct));
Robert Phillips80bff5b2019-08-20 16:56:18 -040051 if (proxy) {
52 sk_sp<GrTextureProxy> extraRef(proxy);
robertphillips1125a032016-11-16 11:17:17 -080053
Robert Phillipsb5204762019-06-19 14:12:13 -040054 int backingRefs = proxy->isInstantiated() ? 1 : -1;
robertphillips1125a032016-11-16 11:17:17 -080055
Brian Salomon28a8f282019-10-24 20:07:39 -040056 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, backingRefs);
robertphillips1125a032016-11-16 11:17:17 -080057
Robert Phillips0bd24dc2018-01-16 08:06:32 -050058 proxy->instantiate(resourceProvider);
robertphillips1125a032016-11-16 11:17:17 -080059
Brian Salomon28a8f282019-10-24 20:07:39 -040060 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, 1);
Jim Van Verth311cc6b2017-09-20 17:51:59 -040061 }
Brian Salomon28a8f282019-10-24 20:07:39 -040062 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1);
robertphillips1125a032016-11-16 11:17:17 -080063 }
64
65 // Multiple normal refs
66 {
Robert Phillips6d344c32020-07-06 10:56:46 -040067 sk_sp<GrTextureProxy> proxy((*make)(direct));
Jim Van Verth311cc6b2017-09-20 17:51:59 -040068 if (proxy.get()) {
69 proxy->ref();
70 proxy->ref();
robertphillips1125a032016-11-16 11:17:17 -080071
Robert Phillipsb5204762019-06-19 14:12:13 -040072 int backingRefs = proxy->isInstantiated() ? 1 : -1;
Robert Phillips715d08c2018-07-18 13:56:48 -040073
Brian Salomon28a8f282019-10-24 20:07:39 -040074 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, backingRefs);
robertphillips1125a032016-11-16 11:17:17 -080075
Robert Phillips0bd24dc2018-01-16 08:06:32 -050076 proxy->instantiate(resourceProvider);
robertphillips1125a032016-11-16 11:17:17 -080077
Brian Salomon28a8f282019-10-24 20:07:39 -040078 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, 1);
robertphillips1125a032016-11-16 11:17:17 -080079
Jim Van Verth311cc6b2017-09-20 17:51:59 -040080 proxy->unref();
81 proxy->unref();
82 }
Brian Salomon28a8f282019-10-24 20:07:39 -040083 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1);
robertphillips1125a032016-11-16 11:17:17 -080084 }
85
86 // Continue using (reffing) proxy after instantiation
87 {
Robert Phillips6d344c32020-07-06 10:56:46 -040088 sk_sp<GrTextureProxy> proxy((*make)(direct));
Robert Phillips80bff5b2019-08-20 16:56:18 -040089 if (proxy) {
90 sk_sp<GrTextureProxy> firstExtraRef(proxy);
robertphillips1125a032016-11-16 11:17:17 -080091
Robert Phillipsb5204762019-06-19 14:12:13 -040092 int backingRefs = proxy->isInstantiated() ? 1 : -1;
robertphillips1125a032016-11-16 11:17:17 -080093
Brian Salomon28a8f282019-10-24 20:07:39 -040094 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, backingRefs);
robertphillips1125a032016-11-16 11:17:17 -080095
Robert Phillips0bd24dc2018-01-16 08:06:32 -050096 proxy->instantiate(resourceProvider);
robertphillips1125a032016-11-16 11:17:17 -080097
Brian Salomon28a8f282019-10-24 20:07:39 -040098 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, 1);
robertphillips1125a032016-11-16 11:17:17 -080099
Robert Phillips80bff5b2019-08-20 16:56:18 -0400100 sk_sp<GrTextureProxy> secondExtraRef(proxy);
Brian Salomon28a8f282019-10-24 20:07:39 -0400101 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, 1);
Jim Van Verth311cc6b2017-09-20 17:51:59 -0400102 }
Brian Salomon28a8f282019-10-24 20:07:39 -0400103 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1);
robertphillips1125a032016-11-16 11:17:17 -0800104 }
105 }
106}