blob: 9ef2deb597d728bc0f02fc7ca71f8c2b8670d586 [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"
Adlai Hollera0693042020-10-14 11:23:11 -040013#include "src/gpu/GrDirectContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrProxyProvider.h"
Robert Phillipse94b4e12020-07-23 13:54:35 -040015#include "src/gpu/GrRecordingContextPriv.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040016#include "src/gpu/GrRenderTargetProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "src/gpu/GrResourceProvider.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040018#include "src/gpu/GrSurfaceProxy.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000019#include "src/gpu/GrTexture.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040020#include "src/gpu/GrTextureProxy.h"
Brian Salomon557e8122019-10-24 10:37:08 -040021#include "tests/TestUtils.h"
robertphillips1125a032016-11-16 11:17:17 -080022
Robert Phillips7928e762017-02-28 16:30:28 -050023static const int kWidthHeight = 128;
24
Robert Phillipse94b4e12020-07-23 13:54:35 -040025static sk_sp<GrTextureProxy> make_deferred(GrRecordingContext* rContext) {
26 GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
27 const GrCaps* caps = rContext->priv().caps();
Robert Phillips0a15cc62019-07-30 12:49:10 -040028
Robert Phillips0a15cc62019-07-30 12:49:10 -040029 const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888,
30 GrRenderable::kYes);
Brian Salomondf1bd6d2020-03-26 20:37:01 -040031 return proxyProvider->createProxy(format, {kWidthHeight, kWidthHeight}, GrRenderable::kYes, 1,
Brian Salomon7e67dca2020-07-21 09:27:25 -040032 GrMipmapped::kNo, SkBackingFit::kApprox, SkBudgeted::kYes,
Brian Salomondf1bd6d2020-03-26 20:37:01 -040033 GrProtected::kNo);
robertphillips1125a032016-11-16 11:17:17 -080034}
35
Robert Phillipse94b4e12020-07-23 13:54:35 -040036static sk_sp<GrTextureProxy> make_wrapped(GrRecordingContext* rContext) {
37 GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
Robert Phillips0a15cc62019-07-30 12:49:10 -040038
Chris Daltond004e0b2018-09-27 09:28:03 -060039 return proxyProvider->testingOnly_createInstantiatedProxy(
Brian Salomon4eb38b72019-08-05 12:58:39 -040040 {kWidthHeight, kWidthHeight}, GrColorType::kRGBA_8888, GrRenderable::kYes, 1,
Greg Daniel3a365112020-02-14 10:47:18 -050041 SkBackingFit::kExact, SkBudgeted::kNo, GrProtected::kNo);
robertphillips1125a032016-11-16 11:17:17 -080042}
43
44DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ProxyRefTest, reporter, ctxInfo) {
Robert Phillipse94b4e12020-07-23 13:54:35 -040045 auto dContext = ctxInfo.directContext();
46 GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
robertphillips1125a032016-11-16 11:17:17 -080047
48 for (auto make : { make_deferred, make_wrapped }) {
Robert Phillips80bff5b2019-08-20 16:56:18 -040049 // An extra ref
robertphillips1125a032016-11-16 11:17:17 -080050 {
Robert Phillipse94b4e12020-07-23 13:54:35 -040051 sk_sp<GrTextureProxy> proxy((*make)(dContext));
Robert Phillips80bff5b2019-08-20 16:56:18 -040052 if (proxy) {
John Stiles31954bf2020-08-07 17:35:54 -040053 sk_sp<GrTextureProxy> extraRef(proxy); // NOLINT(performance-unnecessary-copy-initialization)
robertphillips1125a032016-11-16 11:17:17 -080054
Robert Phillipsb5204762019-06-19 14:12:13 -040055 int backingRefs = proxy->isInstantiated() ? 1 : -1;
robertphillips1125a032016-11-16 11:17:17 -080056
Brian Salomon28a8f282019-10-24 20:07:39 -040057 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, backingRefs);
robertphillips1125a032016-11-16 11:17:17 -080058
Robert Phillips0bd24dc2018-01-16 08:06:32 -050059 proxy->instantiate(resourceProvider);
robertphillips1125a032016-11-16 11:17:17 -080060
Brian Salomon28a8f282019-10-24 20:07:39 -040061 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, 1);
Jim Van Verth311cc6b2017-09-20 17:51:59 -040062 }
Brian Salomon28a8f282019-10-24 20:07:39 -040063 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1);
robertphillips1125a032016-11-16 11:17:17 -080064 }
65
66 // Multiple normal refs
67 {
Robert Phillipse94b4e12020-07-23 13:54:35 -040068 sk_sp<GrTextureProxy> proxy((*make)(dContext));
John Stilesa008b0f2020-08-16 08:48:02 -040069 if (proxy) {
Jim Van Verth311cc6b2017-09-20 17:51:59 -040070 proxy->ref();
71 proxy->ref();
robertphillips1125a032016-11-16 11:17:17 -080072
Robert Phillipsb5204762019-06-19 14:12:13 -040073 int backingRefs = proxy->isInstantiated() ? 1 : -1;
Robert Phillips715d08c2018-07-18 13:56:48 -040074
Brian Salomon28a8f282019-10-24 20:07:39 -040075 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, backingRefs);
robertphillips1125a032016-11-16 11:17:17 -080076
Robert Phillips0bd24dc2018-01-16 08:06:32 -050077 proxy->instantiate(resourceProvider);
robertphillips1125a032016-11-16 11:17:17 -080078
Brian Salomon28a8f282019-10-24 20:07:39 -040079 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, 1);
robertphillips1125a032016-11-16 11:17:17 -080080
Jim Van Verth311cc6b2017-09-20 17:51:59 -040081 proxy->unref();
82 proxy->unref();
83 }
Brian Salomon28a8f282019-10-24 20:07:39 -040084 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1);
robertphillips1125a032016-11-16 11:17:17 -080085 }
86
87 // Continue using (reffing) proxy after instantiation
88 {
Robert Phillipse94b4e12020-07-23 13:54:35 -040089 sk_sp<GrTextureProxy> proxy((*make)(dContext));
Robert Phillips80bff5b2019-08-20 16:56:18 -040090 if (proxy) {
John Stiles31954bf2020-08-07 17:35:54 -040091 sk_sp<GrTextureProxy> firstExtraRef(proxy); // NOLINT(performance-unnecessary-copy-initialization)
robertphillips1125a032016-11-16 11:17:17 -080092
Robert Phillipsb5204762019-06-19 14:12:13 -040093 int backingRefs = proxy->isInstantiated() ? 1 : -1;
robertphillips1125a032016-11-16 11:17:17 -080094
Brian Salomon28a8f282019-10-24 20:07:39 -040095 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, backingRefs);
robertphillips1125a032016-11-16 11:17:17 -080096
Robert Phillips0bd24dc2018-01-16 08:06:32 -050097 proxy->instantiate(resourceProvider);
robertphillips1125a032016-11-16 11:17:17 -080098
Brian Salomon28a8f282019-10-24 20:07:39 -040099 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 2, 1);
robertphillips1125a032016-11-16 11:17:17 -0800100
John Stiles31954bf2020-08-07 17:35:54 -0400101 sk_sp<GrTextureProxy> secondExtraRef(proxy); // NOLINT(performance-unnecessary-copy-initialization)
Brian Salomon28a8f282019-10-24 20:07:39 -0400102 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 3, 1);
Jim Van Verth311cc6b2017-09-20 17:51:59 -0400103 }
Brian Salomon28a8f282019-10-24 20:07:39 -0400104 CheckSingleThreadedProxyRefs(reporter, proxy.get(), 1, 1);
robertphillips1125a032016-11-16 11:17:17 -0800105 }
106 }
107}