Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | #ifndef GrSurfaceProxyPriv_DEFINED |
| 9 | #define GrSurfaceProxyPriv_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/private/GrSurfaceProxy.h" |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 12 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrResourceProvider.h" |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 14 | |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 15 | /** Class that adds methods to GrSurfaceProxy that are only intended for use internal to Skia. |
| 16 | This class is purely a privileged window into GrSurfaceProxy. It should never have additional |
| 17 | data members or virtual methods. */ |
| 18 | class GrSurfaceProxyPriv { |
| 19 | public: |
Robert Phillips | 715d08c | 2018-07-18 13:56:48 -0400 | [diff] [blame] | 20 | // Beware! Woe betide anyone whosoever calls this method. |
| 21 | // The refs on proxies and their backing GrSurfaces shift around based on whether the proxy |
| 22 | // is instantiated or not. Additionally, the lifetime of a proxy (and a GrSurface) also |
| 23 | // depends on the read and write refs (So this method can validly return 0). |
| 24 | int32_t getProxyRefCnt() const { return fProxy->getProxyRefCnt(); } |
| 25 | |
Robert Phillips | 5f78adf | 2019-04-22 12:41:39 -0400 | [diff] [blame] | 26 | int32_t getTotalRefs() const { return fProxy->getTotalRefs(); } |
| 27 | |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 28 | void computeScratchKey(GrScratchKey* key) const { return fProxy->computeScratchKey(key); } |
| 29 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 30 | // Create a GrSurface-derived class that meets the requirements (i.e, desc, renderability) |
| 31 | // of the GrSurfaceProxy. |
| 32 | sk_sp<GrSurface> createSurface(GrResourceProvider* resourceProvider) const { |
| 33 | return fProxy->createSurface(resourceProvider); |
| 34 | } |
| 35 | |
| 36 | // Assign this proxy the provided GrSurface as its backing surface |
| 37 | void assign(sk_sp<GrSurface> surface) { fProxy->assign(std::move(surface)); } |
| 38 | |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 39 | // Don't abuse this call!!!!!!! |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 40 | bool isExact() const { return SkBackingFit::kExact == fProxy->fFit; } |
| 41 | |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 42 | // Don't. Just don't. |
| 43 | void exactify(); |
| 44 | |
Greg Daniel | bddcc95 | 2018-01-24 13:22:24 -0500 | [diff] [blame] | 45 | bool doLazyInstantiation(GrResourceProvider*); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 46 | |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 47 | GrSurfaceProxy::LazyInstantiationType lazyInstantiationType() const { |
| 48 | return fProxy->fLazyInstantiationType; |
| 49 | } |
| 50 | |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 51 | bool isSafeToDeinstantiate() const { |
| 52 | return SkToBool(fProxy->fTarget) && SkToBool(fProxy->fLazyInstantiateCallback) && |
| 53 | GrSurfaceProxy::LazyInstantiationType::kDeinstantiate == lazyInstantiationType(); |
| 54 | } |
| 55 | |
Robert Phillips | 01a9128 | 2018-07-26 08:03:04 -0400 | [diff] [blame] | 56 | static bool SK_WARN_UNUSED_RESULT AttachStencilIfNeeded(GrResourceProvider*, GrSurface*, |
| 57 | bool needsStencil); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 58 | |
Robert Phillips | 5f78adf | 2019-04-22 12:41:39 -0400 | [diff] [blame] | 59 | bool ignoredByResourceAllocator() const { return fProxy->ignoredByResourceAllocator(); } |
| 60 | void setIgnoredByResourceAllocator() { fProxy->setIgnoredByResourceAllocator(); } |
| 61 | |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 62 | private: |
| 63 | explicit GrSurfaceProxyPriv(GrSurfaceProxy* proxy) : fProxy(proxy) {} |
| 64 | GrSurfaceProxyPriv(const GrSurfaceProxyPriv&) {} // unimpl |
| 65 | GrSurfaceProxyPriv& operator=(const GrSurfaceProxyPriv&); // unimpl |
| 66 | |
| 67 | // No taking addresses of this type. |
| 68 | const GrSurfaceProxyPriv* operator&() const; |
| 69 | GrSurfaceProxyPriv* operator&(); |
| 70 | |
| 71 | GrSurfaceProxy* fProxy; |
| 72 | |
| 73 | friend class GrSurfaceProxy; // to construct/copy this type. |
| 74 | }; |
| 75 | |
| 76 | inline GrSurfaceProxyPriv GrSurfaceProxy::priv() { return GrSurfaceProxyPriv(this); } |
| 77 | |
| 78 | inline const GrSurfaceProxyPriv GrSurfaceProxy::priv () const { |
| 79 | return GrSurfaceProxyPriv(const_cast<GrSurfaceProxy*>(this)); |
| 80 | } |
| 81 | |
| 82 | #endif |