Home | History | Annotate | Download | only in gpu
      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:
     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 
     24     // If the proxy is already instantiated, return its backing GrTexture; if not,
     25     // return null
     26     GrTexture* peekTexture() const {
     27         return fProxy->fTarget ? fProxy->fTarget->asTexture() : nullptr;
     28     }
     29 
     30     // This should only be called after a successful call to instantiate
     31     GrRenderTarget* peekRenderTarget() const {
     32         SkASSERT(fProxy->fTarget && fProxy->fTarget->asRenderTarget());
     33         return fProxy->fTarget ? fProxy->fTarget->asRenderTarget() : nullptr;
     34     }
     35 
     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 
     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 
     46     // Create a GrSurface-derived class that meets the requirements (i.e, desc, renderability)
     47     // of the GrSurfaceProxy.
     48     sk_sp<GrSurface> createSurface(GrResourceProvider* resourceProvider) const {
     49         return fProxy->createSurface(resourceProvider);
     50     }
     51 
     52     // Assign this proxy the provided GrSurface as its backing surface
     53     void assign(sk_sp<GrSurface> surface) { fProxy->assign(std::move(surface)); }
     54 
     55     // Don't abuse this call!!!!!!!
     56     bool isExact() const { return SkBackingFit::kExact == fProxy->fFit; }
     57 
     58     // Don't. Just don't.
     59     void exactify();
     60 
     61 private:
     62     explicit GrSurfaceProxyPriv(GrSurfaceProxy* proxy) : fProxy(proxy) {}
     63     GrSurfaceProxyPriv(const GrSurfaceProxyPriv&) {} // unimpl
     64     GrSurfaceProxyPriv& operator=(const GrSurfaceProxyPriv&); // unimpl
     65 
     66     // No taking addresses of this type.
     67     const GrSurfaceProxyPriv* operator&() const;
     68     GrSurfaceProxyPriv* operator&();
     69 
     70     GrSurfaceProxy* fProxy;
     71 
     72     friend class GrSurfaceProxy; // to construct/copy this type.
     73 };
     74 
     75 inline GrSurfaceProxyPriv GrSurfaceProxy::priv() { return GrSurfaceProxyPriv(this); }
     76 
     77 inline const GrSurfaceProxyPriv GrSurfaceProxy::priv () const {
     78     return GrSurfaceProxyPriv(const_cast<GrSurfaceProxy*>(this));
     79 }
     80 
     81 #endif
     82