1 /* 2 * Copyright 2018 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 GrSurfaceProxyRef_DEFINED 9 #define GrSurfaceProxyRef_DEFINED 10 11 #include "GrTypesPriv.h" 12 13 class GrSurfaceProxy; 14 15 class GrSurfaceProxyRef : SkNoncopyable { 16 public: 17 virtual ~GrSurfaceProxyRef(); 18 get()19 GrSurfaceProxy* get() const { return fProxy; } 20 21 /** Does this object own a pending read or write on the resource it is wrapping. */ ownsPendingIO()22 bool ownsPendingIO() const { return fPendingIO; } 23 24 /** What type of IO does this represent? This is independent of whether a normal ref or a 25 pending IO is currently held. */ ioType()26 GrIOType ioType() const { return fIOType; } 27 28 /** Shortcut for calling setProxy() with NULL. It cannot be called after markingPendingIO 29 is called. */ 30 void reset(); 31 32 protected: 33 GrSurfaceProxyRef(); 34 35 /** ioType expresses what type of IO operations will be marked as 36 pending on the resource when markPendingIO is called. */ 37 GrSurfaceProxyRef(sk_sp<GrSurfaceProxy>, GrIOType); 38 39 /** ioType expresses what type of IO operations will be marked as 40 pending on the resource when markPendingIO is called. */ 41 void setProxy(sk_sp<GrSurfaceProxy>, GrIOType); 42 43 private: 44 /** Called by owning GrProgramElement when the program element is first scheduled for 45 execution. It can only be called once. */ 46 void markPendingIO() const; 47 48 /** Called when the program element/draw state is no longer owned by GrOpList-client code. 49 This lets the cache know that the drawing code will no longer schedule additional reads or 50 writes to the resource using the program element or draw state. It can only be called once. 51 */ 52 void removeRef() const; 53 54 /** Called to indicate that the previous pending IO is complete. Useful when the owning object 55 still has refs, so it is not about to destroy this GrGpuResourceRef, but its previously 56 pending executions have been complete. Can only be called if removeRef() was not previously 57 called. */ 58 void pendingIOComplete() const; 59 60 friend class GrResourceIOProcessor; 61 friend class GrOpList; // for setProxy 62 63 GrSurfaceProxy* fProxy; 64 mutable bool fOwnRef; 65 mutable bool fPendingIO; 66 GrIOType fIOType; 67 68 typedef SkNoncopyable INHERITED; 69 }; 70 71 #endif 72