blob: 68067c2b76919446529a83692dcdd081c9b325c2 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/gpu/GrContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/GrProxyProvider.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040014#include "src/gpu/GrRenderTargetProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/gpu/GrResourceProvider.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040016#include "src/gpu/GrSurfaceProxy.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000017#include "src/gpu/GrTexture.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040018#include "src/gpu/GrTextureProxy.h"
Brian Salomon557e8122019-10-24 10:37:08 -040019#include "tests/TestUtils.h"
robertphillips1125a032016-11-16 11:17:17 -080020
Robert Phillips7928e762017-02-28 16:30:28 -050021static const int kWidthHeight = 128;
22
Robert Phillips0a15cc62019-07-30 12:49:10 -040023static sk_sp<GrTextureProxy> make_deferred(GrContext* context) {
24 GrProxyProvider* proxyProvider = context->priv().proxyProvider();
25 const GrCaps* caps = context->priv().caps();
26
Robert Phillips0a15cc62019-07-30 12:49:10 -040027 const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
28 GrRenderable::kYes);
Greg Daniel47c20e82020-01-21 14:29:57 -050029 GrSwizzle swizzle = caps->getReadSwizzle(format, GrColorType::kRGBA_8888);
Brian Salomona56a7462020-02-07 14:17:25 -050030 return proxyProvider->createProxy(format, {kWidthHeight, kWidthHeight}, swizzle,
Greg Daniel3a365112020-02-14 10:47:18 -050031 GrRenderable::kYes, 1, GrMipMapped::kNo,
32 SkBackingFit::kApprox, SkBudgeted::kYes, 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 Phillips9da87e02019-02-04 13:26:26 -050044 GrResourceProvider* resourceProvider = ctxInfo.grContext()->priv().resourceProvider();
robertphillips1125a032016-11-16 11:17:17 -080045
46 for (auto make : { make_deferred, make_wrapped }) {
Robert Phillips80bff5b2019-08-20 16:56:18 -040047 // An extra ref
robertphillips1125a032016-11-16 11:17:17 -080048 {
Robert Phillips0a15cc62019-07-30 12:49:10 -040049 sk_sp<GrTextureProxy> proxy((*make)(ctxInfo.grContext()));
Robert Phillips80bff5b2019-08-20 16:56:18 -040050 if (proxy) {
51 sk_sp<GrTextureProxy> extraRef(proxy);
robertphillips1125a032016-11-16 11:17:17 -080052
Robert Phillipsb5204762019-06-19 14:12:13 -040053 int backingRefs = proxy->isInstantiated() ? 1 : -1;
robertphillips1125a032016-11-16 11:17:17 -080054
Brian Salomon28a8f282019-10-24 20:07:39 -040055 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, backingRefs);
robertphillips1125a032016-11-16 11:17:17 -080056
Robert Phillips0bd24dc2018-01-16 08:06:32 -050057 proxy->instantiate(resourceProvider);
robertphillips1125a032016-11-16 11:17:17 -080058
Brian Salomon28a8f282019-10-24 20:07:39 -040059 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, 1);
Jim Van Verth311cc6b2017-09-20 17:51:59 -040060 }
Brian Salomon28a8f282019-10-24 20:07:39 -040061 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1);
robertphillips1125a032016-11-16 11:17:17 -080062 }
63
64 // Multiple normal refs
65 {
Robert Phillips0a15cc62019-07-30 12:49:10 -040066 sk_sp<GrTextureProxy> proxy((*make)(ctxInfo.grContext()));
Jim Van Verth311cc6b2017-09-20 17:51:59 -040067 if (proxy.get()) {
68 proxy->ref();
69 proxy->ref();
robertphillips1125a032016-11-16 11:17:17 -080070
Robert Phillipsb5204762019-06-19 14:12:13 -040071 int backingRefs = proxy->isInstantiated() ? 1 : -1;
Robert Phillips715d08c2018-07-18 13:56:48 -040072
Brian Salomon28a8f282019-10-24 20:07:39 -040073 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, backingRefs);
robertphillips1125a032016-11-16 11:17:17 -080074
Robert Phillips0bd24dc2018-01-16 08:06:32 -050075 proxy->instantiate(resourceProvider);
robertphillips1125a032016-11-16 11:17:17 -080076
Brian Salomon28a8f282019-10-24 20:07:39 -040077 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, 1);
robertphillips1125a032016-11-16 11:17:17 -080078
Jim Van Verth311cc6b2017-09-20 17:51:59 -040079 proxy->unref();
80 proxy->unref();
81 }
Brian Salomon28a8f282019-10-24 20:07:39 -040082 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1);
robertphillips1125a032016-11-16 11:17:17 -080083 }
84
85 // Continue using (reffing) proxy after instantiation
86 {
Robert Phillips0a15cc62019-07-30 12:49:10 -040087 sk_sp<GrTextureProxy> proxy((*make)(ctxInfo.grContext()));
Robert Phillips80bff5b2019-08-20 16:56:18 -040088 if (proxy) {
89 sk_sp<GrTextureProxy> firstExtraRef(proxy);
robertphillips1125a032016-11-16 11:17:17 -080090
Robert Phillipsb5204762019-06-19 14:12:13 -040091 int backingRefs = proxy->isInstantiated() ? 1 : -1;
robertphillips1125a032016-11-16 11:17:17 -080092
Brian Salomon28a8f282019-10-24 20:07:39 -040093 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, backingRefs);
robertphillips1125a032016-11-16 11:17:17 -080094
Robert Phillips0bd24dc2018-01-16 08:06:32 -050095 proxy->instantiate(resourceProvider);
robertphillips1125a032016-11-16 11:17:17 -080096
Brian Salomon28a8f282019-10-24 20:07:39 -040097 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, 1);
robertphillips1125a032016-11-16 11:17:17 -080098
Robert Phillips80bff5b2019-08-20 16:56:18 -040099 sk_sp<GrTextureProxy> secondExtraRef(proxy);
Brian Salomon28a8f282019-10-24 20:07:39 -0400100 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, 1);
Jim Van Verth311cc6b2017-09-20 17:51:59 -0400101 }
Brian Salomon28a8f282019-10-24 20:07:39 -0400102 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1);
robertphillips1125a032016-11-16 11:17:17 -0800103 }
104 }
105}