blob: 9870617f24e9ba4169a52ce27012414106770abb [file] [log] [blame]
Greg Daniel4684f822018-03-08 15:27:36 -05001/*
2 * Copyright 2018 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
Brian Salomon967df202018-12-07 11:15:53 -05008#include "GrDeinstantiateProxyTracker.h"
Greg Daniel4684f822018-03-08 15:27:36 -05009
10#include "GrSurfaceProxy.h"
11#include "GrSurfaceProxyPriv.h"
12
Brian Salomon967df202018-12-07 11:15:53 -050013void GrDeinstantiateProxyTracker::addProxy(GrSurfaceProxy* proxy) {
Greg Daniel4684f822018-03-08 15:27:36 -050014#ifdef SK_DEBUG
15 using LazyType = GrSurfaceProxy::LazyInstantiationType;
Brian Salomon967df202018-12-07 11:15:53 -050016 SkASSERT(LazyType::kDeinstantiate == proxy->priv().lazyInstantiationType());
Greg Daniel4684f822018-03-08 15:27:36 -050017 for (int i = 0; i < fProxies.count(); ++i) {
Robert Phillipse4aae342018-03-14 10:26:57 -040018 SkASSERT(proxy != fProxies[i].get());
Greg Daniel4684f822018-03-08 15:27:36 -050019 }
20#endif
Robert Phillipse4aae342018-03-14 10:26:57 -040021 fProxies.push_back(sk_ref_sp(proxy));
Greg Daniel4684f822018-03-08 15:27:36 -050022}
23
Brian Salomon967df202018-12-07 11:15:53 -050024void GrDeinstantiateProxyTracker::deinstantiateAllProxies() {
Greg Daniel4684f822018-03-08 15:27:36 -050025 for (int i = 0; i < fProxies.count(); ++i) {
Robert Phillipse4aae342018-03-14 10:26:57 -040026 GrSurfaceProxy* proxy = fProxies[i].get();
Brian Salomon967df202018-12-07 11:15:53 -050027 SkASSERT(proxy->priv().isSafeToDeinstantiate());
28 proxy->deinstantiate();
Greg Daniel4684f822018-03-08 15:27:36 -050029 }
Robert Phillipse4aae342018-03-14 10:26:57 -040030
31 fProxies.reset();
Greg Daniel4684f822018-03-08 15:27:36 -050032}