Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / include / gpu / GrGpuResourceRef.h
index 6b3937b..93298f0 100644 (file)
@@ -9,6 +9,8 @@
 #define GrGpuResourceRef_DEFINED
 
 #include "GrGpuResource.h"
+#include "GrRenderTarget.h"
+#include "GrTexture.h"
 #include "SkRefCnt.h"
 
 /**
@@ -52,11 +54,11 @@ protected:
 
     /** 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
@@ -75,13 +77,14 @@ private:
         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;
 };
@@ -95,13 +98,56 @@ public:
 
     /** 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;
@@ -111,18 +157,18 @@ private:
  * 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;
@@ -133,13 +179,13 @@ public:
     ~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;
@@ -150,6 +196,6 @@ public:
     T* get() const { return fResource; }
 
 private:
-    T*      fResource;
+    T* fResource;
 };
 #endif