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 | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 18 | // This should only be called after a successful call to instantiate |
| 19 | GrSurface* peekSurface() const { |
| 20 | SkASSERT(fProxy->fTarget); |
| 21 | return fProxy->fTarget; |
| 22 | } |
| 23 | |
Robert Phillips | 3798c86 | 2017-03-27 11:08:16 -0400 | [diff] [blame] | 24 | // If the proxy is already instantiated, return its backing GrTexture; if not, |
| 25 | // return null |
Robert Phillips | 8a02f65 | 2017-05-12 14:49:16 -0400 | [diff] [blame] | 26 | GrTexture* peekTexture() const { |
Robert Phillips | 3798c86 | 2017-03-27 11:08:16 -0400 | [diff] [blame] | 27 | return fProxy->fTarget ? fProxy->fTarget->asTexture() : nullptr; |
| 28 | } |
| 29 | |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 30 | // This should only be called after a successful call to instantiate |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 31 | GrRenderTarget* peekRenderTarget() const { |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 32 | SkASSERT(fProxy->fTarget && fProxy->fTarget->asRenderTarget()); |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 33 | return fProxy->fTarget ? fProxy->fTarget->asRenderTarget() : nullptr; |
| 34 | } |
| 35 | |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 36 | // Beware! This call is only guaranteed to tell you if the proxy in question has |
| 37 | // any pending IO in its current state. It won't tell you about the IO state in the |
| 38 | // future when the proxy is actually used/instantiated. |
| 39 | bool hasPendingIO() const { return fProxy->hasPendingIO(); } |
| 40 | |
Robert Phillips | 7ee385e | 2017-03-30 08:02:11 -0400 | [diff] [blame] | 41 | // Beware! This call is only guaranteed to tell you if the proxy in question has |
| 42 | // any pending writes in its current state. It won't tell you about the IO state in the |
| 43 | // future when the proxy is actually used/instantiated. |
| 44 | bool hasPendingWrite() const { return fProxy->hasPendingWrite(); } |
| 45 | |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 46 | // Don't abuse this call!!!!!!! |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 47 | bool isExact() const { return SkBackingFit::kExact == fProxy->fFit; } |
| 48 | |
Robert Phillips | 0ae6faa | 2017-03-21 16:22:00 -0400 | [diff] [blame] | 49 | // Don't. Just don't. |
| 50 | void exactify(); |
| 51 | |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 52 | private: |
| 53 | explicit GrSurfaceProxyPriv(GrSurfaceProxy* proxy) : fProxy(proxy) {} |
| 54 | GrSurfaceProxyPriv(const GrSurfaceProxyPriv&) {} // unimpl |
| 55 | GrSurfaceProxyPriv& operator=(const GrSurfaceProxyPriv&); // unimpl |
| 56 | |
| 57 | // No taking addresses of this type. |
| 58 | const GrSurfaceProxyPriv* operator&() const; |
| 59 | GrSurfaceProxyPriv* operator&(); |
| 60 | |
| 61 | GrSurfaceProxy* fProxy; |
| 62 | |
| 63 | friend class GrSurfaceProxy; // to construct/copy this type. |
| 64 | }; |
| 65 | |
| 66 | inline GrSurfaceProxyPriv GrSurfaceProxy::priv() { return GrSurfaceProxyPriv(this); } |
| 67 | |
| 68 | inline const GrSurfaceProxyPriv GrSurfaceProxy::priv () const { |
| 69 | return GrSurfaceProxyPriv(const_cast<GrSurfaceProxy*>(this)); |
| 70 | } |
| 71 | |
| 72 | #endif |