| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrGpuResourceRef_DEFINED | 8 #ifndef GrGpuResourceRef_DEFINED |
| 9 #define GrGpuResourceRef_DEFINED | 9 #define GrGpuResourceRef_DEFINED |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 * | 32 * |
| 33 * TODO: Once GrDODrawState no longer exists and therefore GrDrawState and GrOpt
DrawState no | 33 * TODO: Once GrDODrawState no longer exists and therefore GrDrawState and GrOpt
DrawState no |
| 34 * longer share an instance of this class, attempt to make the resource owned by
GrGpuResourceRef | 34 * longer share an instance of this class, attempt to make the resource owned by
GrGpuResourceRef |
| 35 * only settable via the constructor. | 35 * only settable via the constructor. |
| 36 */ | 36 */ |
| 37 class GrGpuResourceRef : SkNoncopyable { | 37 class GrGpuResourceRef : SkNoncopyable { |
| 38 public: | 38 public: |
| 39 ~GrGpuResourceRef(); | 39 ~GrGpuResourceRef(); |
| 40 | 40 |
| 41 GrGpuResource* getResource() const { return fResource; } | 41 GrGpuResource* getResource() const { return fResource; } |
| 42 GrGpuResource* getDst() const { |
| 43 SkASSERT(fIOType == kRead_GrIOType || fIOType == kRW_GrIOType); |
| 44 SkASSERT(fDst); |
| 45 return fDst; |
| 46 } |
| 42 | 47 |
| 43 /** Does this object own a pending read or write on the resource it is wrapp
ing. */ | 48 /** Does this object own a pending read or write on the resource it is wrapp
ing. */ |
| 44 bool ownsPendingIO() const { return fPendingIO; } | 49 bool ownsPendingIO() const { return fPendingIO; } |
| 45 | 50 |
| 46 /** Shortcut for calling setResource() with NULL. It cannot be called after
markingPendingIO | 51 /** Shortcut for calling setResource() with NULL. It cannot be called after
markingPendingIO |
| 47 is called. */ | 52 is called. */ |
| 48 void reset(); | 53 void reset(); |
| 49 | 54 |
| 50 protected: | 55 protected: |
| 51 GrGpuResourceRef(); | 56 GrGpuResourceRef(); |
| 52 | 57 |
| 53 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as | 58 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as |
| 54 pending on the resource when markPendingIO is called. */ | 59 pending on the resource when markPendingIO is called. */ |
| 55 GrGpuResourceRef(GrGpuResource*, GrIOType); | 60 GrGpuResourceRef(GrGpuResource*, GrIOType, GrGpuResource* dst); |
| 56 | 61 |
| 57 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as | 62 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as |
| 58 pending on the resource when markPendingIO is called. */ | 63 pending on the resource when markPendingIO is called. */ |
| 59 void setResource(GrGpuResource*, GrIOType); | 64 void setResource(GrGpuResource*, GrIOType, GrGpuResource* dst); |
| 60 | 65 |
| 61 private: | 66 private: |
| 62 /** Called by owning GrProgramElement when the program element is first sche
duled for | 67 /** Called by owning GrProgramElement when the program element is first sche
duled for |
| 63 execution. It can only be called once. */ | 68 execution. It can only be called once. */ |
| 64 void markPendingIO() const; | 69 void markPendingIO() const; |
| 65 | 70 |
| 66 /** Called when the program element/draw state is no longer owned by GrDrawT
arget-client code. | 71 /** Called when the program element/draw state is no longer owned by GrDrawT
arget-client code. |
| 67 This lets the cache know that the drawing code will no longer schedule a
dditional reads or | 72 This lets the cache know that the drawing code will no longer schedule a
dditional reads or |
| 68 writes to the resource using the program element or draw state. It can o
nly be called once. | 73 writes to the resource using the program element or draw state. It can o
nly be called once. |
| 69 */ | 74 */ |
| 70 void removeRef() const; | 75 void removeRef() const; |
| 71 | 76 |
| 72 /** Called to indicate that the previous pending IO is complete. Useful when
the owning object | 77 /** Called to indicate that the previous pending IO is complete. Useful when
the owning object |
| 73 still has refs, so it is not about to destroy this GrGpuResourceRef, but
its previously | 78 still has refs, so it is not about to destroy this GrGpuResourceRef, but
its previously |
| 74 pending executions have been complete. Can only be called if removeRef()
was not previously | 79 pending executions have been complete. Can only be called if removeRef()
was not previously |
| 75 called. */ | 80 called. */ |
| 76 void pendingIOComplete() const; | 81 void pendingIOComplete() const; |
| 77 | 82 |
| 78 friend class GrProgramElement; | 83 friend class GrProgramElement; |
| 79 | 84 |
| 80 GrGpuResource* fResource; | 85 GrGpuResource* fResource; |
| 81 mutable bool fOwnRef; | 86 mutable bool fOwnRef; |
| 82 mutable bool fPendingIO; | 87 mutable bool fPendingIO; |
| 83 GrIOType fIOType; | 88 GrIOType fIOType; |
| 89 GrGpuResource* fDst; |
| 84 | 90 |
| 85 typedef SkNoncopyable INHERITED; | 91 typedef SkNoncopyable INHERITED; |
| 86 }; | 92 }; |
| 87 | 93 |
| 88 /** | 94 /** |
| 89 * Templated version of GrGpuResourceRef to enforce type safety. | 95 * Templated version of GrGpuResourceRef to enforce type safety. |
| 90 */ | 96 */ |
| 91 template <typename T> class GrTGpuResourceRef : public GrGpuResourceRef { | 97 template <typename T> class GrTGpuResourceRef : public GrGpuResourceRef { |
| 92 public: | 98 public: |
| 93 GrTGpuResourceRef() {} | 99 GrTGpuResourceRef() {} |
| 94 | 100 |
| 95 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as | 101 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as |
| 96 pending on the resource when markPendingIO is called. */ | 102 pending on the resource when markPendingIO is called. */ |
| 97 GrTGpuResourceRef(T* resource, GrIOType ioType) : INHERITED(resource, ioType
) { } | 103 GrTGpuResourceRef(T* resource, GrIOType ioType) : INHERITED(resource, ioType
) { } |
| 98 | 104 |
| 99 T* get() const { return static_cast<T*>(this->getResource()); } | 105 T* get() const { return static_cast<T*>(this->getResource()); } |
| 100 | 106 |
| 101 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as | 107 /** Adopts a ref from the caller. ioType expresses what type of IO operation
s will be marked as |
| 102 pending on the resource when markPendingIO is called. */ | 108 pending on the resource when markPendingIO is called. */ |
| 103 void set(T* resource, GrIOType ioType) { this->setResource(resource, ioType)
; } | 109 void set(T* resource, GrIOType ioType, T* dst) { this->setResource(resource,
ioType, dst); } |
| 104 | 110 |
| 105 private: | 111 private: |
| 106 typedef GrGpuResourceRef INHERITED; | 112 typedef GrGpuResourceRef INHERITED; |
| 107 }; | 113 }; |
| 108 | 114 |
| 109 // Specializations for GrTexture and GrRenderTarget because they use virtual inh
eritance. | 115 // Specializations for GrTexture and GrRenderTarget because they use virtual inh
eritance. |
| 110 template<> class GrTGpuResourceRef<GrTexture> : public GrGpuResourceRef { | 116 template<> class GrTGpuResourceRef<GrTexture> : public GrGpuResourceRef { |
| 111 public: | 117 public: |
| 112 GrTGpuResourceRef() {} | 118 GrTGpuResourceRef() {} |
| 113 | 119 |
| 114 GrTGpuResourceRef(GrTexture* texture, GrIOType ioType) : INHERITED(texture,
ioType) { } | 120 GrTGpuResourceRef(GrTexture* texture, GrIOType ioType, GrRenderTarget* dst)
: INHERITED(texture, ioType, dst) { } |
| 115 | 121 |
| 116 GrTexture* get() const { | 122 GrTexture* get() const { |
| 117 GrSurface* surface = static_cast<GrSurface*>(this->getResource()); | 123 GrSurface* surface = static_cast<GrSurface*>(this->getResource()); |
| 118 if (surface) { | 124 if (surface) { |
| 119 return surface->asTexture(); | 125 return surface->asTexture(); |
| 120 } else { | 126 } else { |
| 121 return NULL; | 127 return NULL; |
| 122 } | 128 } |
| 123 } | 129 } |
| 124 | 130 |
| 125 void set(GrTexture* texture, GrIOType ioType) { this->setResource(texture, i
oType); } | 131 void set(GrTexture* texture, GrIOType ioType, GrRenderTarget* dst) { this->s
etResource(texture, ioType, dst); } |
| 126 | 132 |
| 127 private: | 133 private: |
| 128 typedef GrGpuResourceRef INHERITED; | 134 typedef GrGpuResourceRef INHERITED; |
| 129 }; | 135 }; |
| 130 | 136 |
| 131 template<> class GrTGpuResourceRef<GrRenderTarget> : public GrGpuResourceRef { | 137 template<> class GrTGpuResourceRef<GrRenderTarget> : public GrGpuResourceRef { |
| 132 public: | 138 public: |
| 133 GrTGpuResourceRef() {} | 139 GrTGpuResourceRef() {} |
| 134 | 140 |
| 135 GrTGpuResourceRef(GrRenderTarget* rt, GrIOType ioType) : INHERITED(rt, ioTyp
e) { } | 141 GrTGpuResourceRef(GrRenderTarget* rt, GrIOType ioType, GrRenderTarget* dst)
: INHERITED(rt, ioType, dst) { } |
| 136 | 142 |
| 137 GrRenderTarget* get() const { | 143 GrRenderTarget* get() const { |
| 138 GrSurface* surface = static_cast<GrSurface*>(this->getResource()); | 144 GrSurface* surface = static_cast<GrSurface*>(this->getResource()); |
| 139 if (surface) { | 145 if (surface) { |
| 140 return surface->asRenderTarget(); | 146 return surface->asRenderTarget(); |
| 141 } else { | 147 } else { |
| 142 return NULL; | 148 return NULL; |
| 143 } | 149 } |
| 144 } | 150 } |
| 145 | 151 |
| 146 void set(GrRenderTarget* rt, GrIOType ioType) { this->setResource(rt, ioType
); } | 152 void set(GrRenderTarget* rt, GrIOType ioType, GrRenderTarget* dst) { this->s
etResource(rt, ioType, dst); } |
| 147 | 153 |
| 148 private: | 154 private: |
| 149 typedef GrGpuResourceRef INHERITED; | 155 typedef GrGpuResourceRef INHERITED; |
| 150 }; | 156 }; |
| 151 | 157 |
| 152 /** | 158 /** |
| 153 * This is similar to GrTGpuResourceRef but can only be in the pending IO state.
It never owns a | 159 * This is similar to GrTGpuResourceRef but can only be in the pending IO state.
It never owns a |
| 154 * ref. | 160 * ref. |
| 155 */ | 161 */ |
| 156 template <typename T, GrIOType IO_TYPE> class GrPendingIOResource : SkNoncopyabl
e { | 162 template <typename T, GrIOType IO_TYPE> class GrPendingIOResource : SkNoncopyabl
e { |
| 157 public: | 163 public: |
| 158 GrPendingIOResource(T* resource = NULL) : fResource(NULL) { | 164 GrPendingIOResource(T* resource = NULL, GrGpuResource* dst = NULL) : fResour
ce(NULL) { |
| 159 this->reset(resource); | 165 this->reset(resource, dst); |
| 160 } | 166 } |
| 161 | 167 |
| 162 void reset(T* resource) { | 168 void reset(T* resource, GrGpuResource* dst) { |
| 163 if (resource) { | 169 if (resource) { |
| 164 switch (IO_TYPE) { | 170 switch (IO_TYPE) { |
| 165 case kRead_GrIOType: | 171 case kRead_GrIOType: |
| 166 resource->addPendingRead(); | 172 resource->addPendingRead(dst); |
| 167 break; | 173 break; |
| 168 case kWrite_GrIOType: | 174 case kWrite_GrIOType: |
| 169 resource->addPendingWrite(); | 175 resource->addPendingWrite(); |
| 170 break; | 176 break; |
| 171 case kRW_GrIOType: | 177 case kRW_GrIOType: |
| 172 resource->addPendingRead(); | 178 resource->addPendingRead(dst); |
| 173 resource->addPendingWrite(); | 179 resource->addPendingWrite(); |
| 174 break; | 180 break; |
| 175 } | 181 } |
| 176 } | 182 } |
| 177 this->release(); | 183 this->release(); |
| 178 fResource = resource; | 184 fResource = resource; |
| 179 } | 185 } |
| 180 | 186 |
| 181 ~GrPendingIOResource() { | 187 ~GrPendingIOResource() { |
| 182 this->release(); | 188 this->release(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 204 fResource->completedRead(); | 210 fResource->completedRead(); |
| 205 fResource->completedWrite(); | 211 fResource->completedWrite(); |
| 206 break; | 212 break; |
| 207 } | 213 } |
| 208 } | 214 } |
| 209 } | 215 } |
| 210 | 216 |
| 211 T* fResource; | 217 T* fResource; |
| 212 }; | 218 }; |
| 213 #endif | 219 #endif |
| OLD | NEW |