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 | |
| 11 | #include "GrSurfaceProxy.h" |
| 12 | |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 13 | #include "GrResourceProvider.h" |
| 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 | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 26 | // Beware! This call is only guaranteed to tell you if the proxy in question has |
| 27 | // any pending IO in its current state. It won't tell you about the IO state in the |
| 28 | // future when the proxy is actually used/instantiated. |
| 29 | bool hasPendingIO() const { return fProxy->hasPendingIO(); } |
| 30 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 31 | // Beware! This call is only guaranteed to tell you if the proxy in question has |
| 32 | // any pending writes in its current state. It won't tell you about the IO state in the |
| 33 | // future when the proxy is actually used/instantiated. |
| 34 | bool hasPendingWrite() const { return fProxy->hasPendingWrite(); } |
| 35 | |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 36 | void computeScratchKey(GrScratchKey* key) const { return fProxy->computeScratchKey(key); } |
| 37 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 38 | // Create a GrSurface-derived class that meets the requirements (i.e, desc, renderability) |
| 39 | // of the GrSurfaceProxy. |
| 40 | sk_sp<GrSurface> createSurface(GrResourceProvider* resourceProvider) const { |
| 41 | return fProxy->createSurface(resourceProvider); |
| 42 | } |
| 43 | |
| 44 | // Assign this proxy the provided GrSurface as its backing surface |
| 45 | void assign(sk_sp<GrSurface> surface) { fProxy->assign(std::move(surface)); } |
| 46 | |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 47 | bool requiresNoPendingIO() const { |
Robert Phillips | fe0253f | 2018-03-16 16:47:25 -0400 | [diff] [blame] | 48 | return fProxy->fSurfaceFlags & GrInternalSurfaceFlags::kNoPendingIO; |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 49 | } |
| 50 | |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 51 | // Don't abuse this call!!!!!!! |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 52 | bool isExact() const { return SkBackingFit::kExact == fProxy->fFit; } |
| 53 | |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 54 | // Don't. Just don't. |
| 55 | void exactify(); |
| 56 | |
Greg Daniel | bddcc95 | 2018-01-24 13:22:24 -0500 | [diff] [blame] | 57 | bool doLazyInstantiation(GrResourceProvider*); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 58 | |
Greg Daniel | 457469c | 2018-02-08 15:05:44 -0500 | [diff] [blame] | 59 | GrSurfaceProxy::LazyInstantiationType lazyInstantiationType() const { |
| 60 | return fProxy->fLazyInstantiationType; |
| 61 | } |
| 62 | |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 63 | bool isSafeToUninstantiate() const { |
| 64 | return SkToBool(fProxy->fTarget) && |
| 65 | SkToBool(fProxy->fLazyInstantiateCallback) && |
| 66 | GrSurfaceProxy::LazyInstantiationType::kUninstantiate == lazyInstantiationType(); |
| 67 | } |
| 68 | |
Robert Phillips | 01a9128 | 2018-07-26 08:03:04 -0400 | [diff] [blame] | 69 | static bool SK_WARN_UNUSED_RESULT AttachStencilIfNeeded(GrResourceProvider*, GrSurface*, |
| 70 | bool needsStencil); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 71 | |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 72 | private: |
| 73 | explicit GrSurfaceProxyPriv(GrSurfaceProxy* proxy) : fProxy(proxy) {} |
| 74 | GrSurfaceProxyPriv(const GrSurfaceProxyPriv&) {} // unimpl |
| 75 | GrSurfaceProxyPriv& operator=(const GrSurfaceProxyPriv&); // unimpl |
| 76 | |
| 77 | // No taking addresses of this type. |
| 78 | const GrSurfaceProxyPriv* operator&() const; |
| 79 | GrSurfaceProxyPriv* operator&(); |
| 80 | |
| 81 | GrSurfaceProxy* fProxy; |
| 82 | |
| 83 | friend class GrSurfaceProxy; // to construct/copy this type. |
| 84 | }; |
| 85 | |
| 86 | inline GrSurfaceProxyPriv GrSurfaceProxy::priv() { return GrSurfaceProxyPriv(this); } |
| 87 | |
| 88 | inline const GrSurfaceProxyPriv GrSurfaceProxy::priv () const { |
| 89 | return GrSurfaceProxyPriv(const_cast<GrSurfaceProxy*>(this)); |
| 90 | } |
| 91 | |
| 92 | #endif |