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 | |
| 13 | /** Class that adds methods to GrSurfaceProxy that are only intended for use internal to Skia. |
| 14 | This class is purely a privileged window into GrSurfaceProxy. It should never have additional |
| 15 | data members or virtual methods. */ |
| 16 | class GrSurfaceProxyPriv { |
| 17 | public: |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 18 | bool isInstantiated() const { return SkToBool(fProxy->fTarget); } |
| 19 | |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 20 | // This should only be called after a successful call to instantiate |
| 21 | GrSurface* peekSurface() const { |
| 22 | SkASSERT(fProxy->fTarget); |
| 23 | return fProxy->fTarget; |
| 24 | } |
| 25 | |
Robert Phillips | 3798c86 | 2017-03-27 11:08:16 -0400 | [diff] [blame] | 26 | // If the proxy is already instantiated, return its backing GrTexture; if not, |
| 27 | // return null |
Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 28 | GrTexture* peekTexture() const { |
Robert Phillips | 3798c86 | 2017-03-27 11:08:16 -0400 | [diff] [blame] | 29 | return fProxy->fTarget ? fProxy->fTarget->asTexture() : nullptr; |
| 30 | } |
| 31 | |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 32 | // This should only be called after a successful call to instantiate |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 33 | GrRenderTarget* peekRenderTarget() const { |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 34 | SkASSERT(fProxy->fTarget && fProxy->fTarget->asRenderTarget()); |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 35 | return fProxy->fTarget ? fProxy->fTarget->asRenderTarget() : nullptr; |
| 36 | } |
| 37 | |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 38 | // Beware! This call is only guaranteed to tell you if the proxy in question has |
| 39 | // any pending IO in its current state. It won't tell you about the IO state in the |
| 40 | // future when the proxy is actually used/instantiated. |
| 41 | bool hasPendingIO() const { return fProxy->hasPendingIO(); } |
| 42 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 43 | // Beware! This call is only guaranteed to tell you if the proxy in question has |
| 44 | // any pending writes in its current state. It won't tell you about the IO state in the |
| 45 | // future when the proxy is actually used/instantiated. |
| 46 | bool hasPendingWrite() const { return fProxy->hasPendingWrite(); } |
| 47 | |
Robert Phillips | 57aa367 | 2017-07-21 11:38:13 -0400 | [diff] [blame] | 48 | void computeScratchKey(GrScratchKey* key) const { return fProxy->computeScratchKey(key); } |
| 49 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 50 | // Create a GrSurface-derived class that meets the requirements (i.e, desc, renderability) |
| 51 | // of the GrSurfaceProxy. |
| 52 | sk_sp<GrSurface> createSurface(GrResourceProvider* resourceProvider) const { |
| 53 | return fProxy->createSurface(resourceProvider); |
| 54 | } |
| 55 | |
| 56 | // Assign this proxy the provided GrSurface as its backing surface |
| 57 | void assign(sk_sp<GrSurface> surface) { fProxy->assign(std::move(surface)); } |
| 58 | |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 59 | // Don't abuse this call!!!!!!! |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 60 | bool isExact() const { return SkBackingFit::kExact == fProxy->fFit; } |
| 61 | |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 62 | // Don't. Just don't. |
| 63 | void exactify(); |
| 64 | |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 65 | private: |
| 66 | explicit GrSurfaceProxyPriv(GrSurfaceProxy* proxy) : fProxy(proxy) {} |
| 67 | GrSurfaceProxyPriv(const GrSurfaceProxyPriv&) {} // unimpl |
| 68 | GrSurfaceProxyPriv& operator=(const GrSurfaceProxyPriv&); // unimpl |
| 69 | |
| 70 | // No taking addresses of this type. |
| 71 | const GrSurfaceProxyPriv* operator&() const; |
| 72 | GrSurfaceProxyPriv* operator&(); |
| 73 | |
| 74 | GrSurfaceProxy* fProxy; |
| 75 | |
| 76 | friend class GrSurfaceProxy; // to construct/copy this type. |
| 77 | }; |
| 78 | |
| 79 | inline GrSurfaceProxyPriv GrSurfaceProxy::priv() { return GrSurfaceProxyPriv(this); } |
| 80 | |
| 81 | inline const GrSurfaceProxyPriv GrSurfaceProxy::priv () const { |
| 82 | return GrSurfaceProxyPriv(const_cast<GrSurfaceProxy*>(this)); |
| 83 | } |
| 84 | |
| 85 | #endif |