Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 1 | /* |
| 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 Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 8 | #include "GrDeinstantiateProxyTracker.h" |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 9 | |
| 10 | #include "GrSurfaceProxy.h" |
| 11 | #include "GrSurfaceProxyPriv.h" |
| 12 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 13 | void GrDeinstantiateProxyTracker::addProxy(GrSurfaceProxy* proxy) { |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 14 | #ifdef SK_DEBUG |
| 15 | using LazyType = GrSurfaceProxy::LazyInstantiationType; |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 16 | SkASSERT(LazyType::kDeinstantiate == proxy->priv().lazyInstantiationType()); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 17 | for (int i = 0; i < fProxies.count(); ++i) { |
Robert Phillips | e4aae34 | 2018-03-14 10:26:57 -0400 | [diff] [blame] | 18 | SkASSERT(proxy != fProxies[i].get()); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 19 | } |
| 20 | #endif |
Robert Phillips | e4aae34 | 2018-03-14 10:26:57 -0400 | [diff] [blame] | 21 | fProxies.push_back(sk_ref_sp(proxy)); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 22 | } |
| 23 | |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 24 | void GrDeinstantiateProxyTracker::deinstantiateAllProxies() { |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 25 | for (int i = 0; i < fProxies.count(); ++i) { |
Robert Phillips | e4aae34 | 2018-03-14 10:26:57 -0400 | [diff] [blame] | 26 | GrSurfaceProxy* proxy = fProxies[i].get(); |
Brian Salomon | 967df20 | 2018-12-07 11:15:53 -0500 | [diff] [blame] | 27 | SkASSERT(proxy->priv().isSafeToDeinstantiate()); |
| 28 | proxy->deinstantiate(); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 29 | } |
Robert Phillips | e4aae34 | 2018-03-14 10:26:57 -0400 | [diff] [blame] | 30 | |
| 31 | fProxies.reset(); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 32 | } |