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#include "GrResourceProvider.h" 14 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. */ 18class GrSurfaceProxyPriv { 19public: 20 bool isInstantiated() const { return SkToBool(fProxy->fTarget); } 21 22 // This should only be called after a successful call to instantiate 23 GrSurface* peekSurface() const { 24 SkASSERT(fProxy->fTarget); 25 return fProxy->fTarget; 26 } 27 28 // If the proxy is already instantiated, return its backing GrTexture; if not, 29 // return null 30 GrTexture* peekTexture() const { 31 return fProxy->fTarget ? fProxy->fTarget->asTexture() : nullptr; 32 } 33 34 // This should only be called after a successful call to instantiate 35 GrRenderTarget* peekRenderTarget() const { 36 SkASSERT(fProxy->fTarget && fProxy->fTarget->asRenderTarget()); 37 return fProxy->fTarget ? fProxy->fTarget->asRenderTarget() : nullptr; 38 } 39 40 // Beware! This call is only guaranteed to tell you if the proxy in question has 41 // any pending IO in its current state. It won't tell you about the IO state in the 42 // future when the proxy is actually used/instantiated. 43 bool hasPendingIO() const { return fProxy->hasPendingIO(); } 44 45 // Beware! This call is only guaranteed to tell you if the proxy in question has 46 // any pending writes in its current state. It won't tell you about the IO state in the 47 // future when the proxy is actually used/instantiated. 48 bool hasPendingWrite() const { return fProxy->hasPendingWrite(); } 49 50 void computeScratchKey(GrScratchKey* key) const { return fProxy->computeScratchKey(key); } 51 52 // Create a GrSurface-derived class that meets the requirements (i.e, desc, renderability) 53 // of the GrSurfaceProxy. 54 sk_sp<GrSurface> createSurface(GrResourceProvider* resourceProvider) const { 55 return fProxy->createSurface(resourceProvider); 56 } 57 58 // Assign this proxy the provided GrSurface as its backing surface 59 void assign(sk_sp<GrSurface> surface) { fProxy->assign(std::move(surface)); } 60 61 bool requiresNoPendingIO() const { 62 return fProxy->fFlags & GrResourceProvider::kNoPendingIO_Flag; 63 } 64 65 // Don't abuse this call!!!!!!! 66 bool isExact() const { return SkBackingFit::kExact == fProxy->fFit; } 67 68 // Don't. Just don't. 69 void exactify(); 70 71 bool doLazyInstantiation(GrResourceProvider*); 72 73 static bool AttachStencilIfNeeded(GrResourceProvider*, GrSurface*, bool needsStencil); 74 75private: 76 explicit GrSurfaceProxyPriv(GrSurfaceProxy* proxy) : fProxy(proxy) {} 77 GrSurfaceProxyPriv(const GrSurfaceProxyPriv&) {} // unimpl 78 GrSurfaceProxyPriv& operator=(const GrSurfaceProxyPriv&); // unimpl 79 80 // No taking addresses of this type. 81 const GrSurfaceProxyPriv* operator&() const; 82 GrSurfaceProxyPriv* operator&(); 83 84 GrSurfaceProxy* fProxy; 85 86 friend class GrSurfaceProxy; // to construct/copy this type. 87}; 88 89inline GrSurfaceProxyPriv GrSurfaceProxy::priv() { return GrSurfaceProxyPriv(this); } 90 91inline const GrSurfaceProxyPriv GrSurfaceProxy::priv () const { 92 return GrSurfaceProxyPriv(const_cast<GrSurfaceProxy*>(this)); 93} 94 95#endif 96