#define GrGpuResourceRef_DEFINED
#include "GrGpuResource.h"
+#include "GrRenderTarget.h"
+#include "GrTexture.h"
#include "SkRefCnt.h"
/**
/** Adopts a ref from the caller. ioType expresses what type of IO operations will be marked as
pending on the resource when markPendingIO is called. */
- GrGpuResourceRef(GrGpuResource*, GrIORef::IOType);
+ GrGpuResourceRef(GrGpuResource*, GrIOType);
/** Adopts a ref from the caller. ioType expresses what type of IO operations will be marked as
pending on the resource when markPendingIO is called. */
- void setResource(GrGpuResource*, GrIORef::IOType);
+ void setResource(GrGpuResource*, GrIOType);
private:
/** Called by owning GrProgramElement when the program element is first scheduled for
called. */
void pendingIOComplete() const;
- friend class GrRODrawState;
+ friend class GrDrawState;
+ friend class GrOptDrawState;
friend class GrProgramElement;
- GrGpuResource* fResource;
- mutable bool fOwnRef;
- mutable bool fPendingIO;
- GrIORef::IOType fIOType;
+ GrGpuResource* fResource;
+ mutable bool fOwnRef;
+ mutable bool fPendingIO;
+ GrIOType fIOType;
typedef SkNoncopyable INHERITED;
};
/** Adopts a ref from the caller. ioType expresses what type of IO operations will be marked as
pending on the resource when markPendingIO is called. */
- GrTGpuResourceRef(T* resource, GrIORef::IOType ioType) : INHERITED(resource, ioType) {}
+ GrTGpuResourceRef(T* resource, GrIOType ioType) : INHERITED(resource, ioType) { }
T* get() const { return static_cast<T*>(this->getResource()); }
/** Adopts a ref from the caller. ioType expresses what type of IO operations will be marked as
pending on the resource when markPendingIO is called. */
- void set(T* resource, GrIORef::IOType ioType) { this->setResource(resource, ioType); }
+ void set(T* resource, GrIOType ioType) { this->setResource(resource, ioType); }
+
+private:
+ typedef GrGpuResourceRef INHERITED;
+};
+
+// Specializations for GrTexture and GrRenderTarget because they use virtual inheritance.
+template<> class GrTGpuResourceRef<GrTexture> : public GrGpuResourceRef {
+public:
+ GrTGpuResourceRef() {}
+
+ GrTGpuResourceRef(GrTexture* texture, GrIOType ioType) : INHERITED(texture, ioType) { }
+
+ GrTexture* get() const {
+ GrSurface* surface = static_cast<GrSurface*>(this->getResource());
+ if (surface) {
+ return surface->asTexture();
+ } else {
+ return NULL;
+ }
+ }
+
+ void set(GrTexture* texture, GrIOType ioType) { this->setResource(texture, ioType); }
+
+private:
+ typedef GrGpuResourceRef INHERITED;
+};
+
+template<> class GrTGpuResourceRef<GrRenderTarget> : public GrGpuResourceRef {
+public:
+ GrTGpuResourceRef() {}
+
+ GrTGpuResourceRef(GrRenderTarget* rt, GrIOType ioType) : INHERITED(rt, ioType) { }
+
+ GrRenderTarget* get() const {
+ GrSurface* surface = static_cast<GrSurface*>(this->getResource());
+ if (surface) {
+ return surface->asRenderTarget();
+ } else {
+ return NULL;
+ }
+ }
+
+ void set(GrRenderTarget* rt, GrIOType ioType) { this->setResource(rt, ioType); }
private:
typedef GrGpuResourceRef INHERITED;
* This is similar to GrTGpuResourceRef but can only be in the pending IO state. It never owns a
* ref.
*/
-template <typename T, GrIORef::IOType IO_TYPE> class GrPendingIOResource : SkNoncopyable {
+template <typename T, GrIOType IO_TYPE> class GrPendingIOResource : SkNoncopyable {
public:
GrPendingIOResource(T* resource) : fResource(resource) {
if (NULL != fResource) {
switch (IO_TYPE) {
- case GrIORef::kRead_IOType:
+ case kRead_GrIOType:
fResource->addPendingRead();
break;
- case GrIORef::kWrite_IOType:
+ case kWrite_GrIOType:
fResource->addPendingWrite();
break;
- case GrIORef::kRW_IOType:
+ case kRW_GrIOType:
fResource->addPendingRead();
fResource->addPendingWrite();
break;
~GrPendingIOResource() {
if (NULL != fResource) {
switch (IO_TYPE) {
- case GrIORef::kRead_IOType:
+ case kRead_GrIOType:
fResource->completedRead();
break;
- case GrIORef::kWrite_IOType:
+ case kWrite_GrIOType:
fResource->completedWrite();
break;
- case GrIORef::kRW_IOType:
+ case kRW_GrIOType:
fResource->completedRead();
fResource->completedWrite();
break;
T* get() const { return fResource; }
private:
- T* fResource;
+ T* fResource;
};
#endif