move render target decls / defs to their own headers / srcs

Review URL: http://codereview.appspot.com/4806058/



git-svn-id: http://skia.googlecode.com/svn/trunk@1995 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/src/GrGLRenderTarget.cpp b/gpu/src/GrGLRenderTarget.cpp
new file mode 100644
index 0000000..d21e37f
--- /dev/null
+++ b/gpu/src/GrGLRenderTarget.cpp
@@ -0,0 +1,71 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#include "GrGLRenderTarget.h"
+
+#include "GrGpuGL.h"
+
+#define GPUGL static_cast<GrGpuGL*>(getGpu())
+
+GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
+                                   const GLRenderTargetIDs& ids,
+                                   GrGLTexID* texID,
+                                   GrPixelConfig config,
+                                   GrGLuint stencilBits,
+                                   bool isMultisampled,
+                                   const GrGLIRect& viewport,
+                                   GrGLTexture* texture)
+    : INHERITED(gpu, texture, viewport.fWidth, 
+                viewport.fHeight, config, 
+                stencilBits, isMultisampled) {
+    fRTFBOID                = ids.fRTFBOID;
+    fTexFBOID               = ids.fTexFBOID;
+    fStencilRenderbufferID  = ids.fStencilRenderbufferID;
+    fMSColorRenderbufferID  = ids.fMSColorRenderbufferID;
+    fViewport               = viewport;
+    fOwnIDs                 = ids.fOwnIDs;
+    fTexIDObj               = texID;
+    GrSafeRef(fTexIDObj);
+}
+
+void GrGLRenderTarget::onRelease() {
+    GPUGL->notifyRenderTargetDelete(this);
+    if (fOwnIDs) {
+        if (fTexFBOID) {
+            GR_GL(DeleteFramebuffers(1, &fTexFBOID));
+        }
+        if (fRTFBOID && fRTFBOID != fTexFBOID) {
+            GR_GL(DeleteFramebuffers(1, &fRTFBOID));
+        }
+        if (fStencilRenderbufferID) {
+            GR_GL(DeleteRenderbuffers(1, &fStencilRenderbufferID));
+        }
+        if (fMSColorRenderbufferID) {
+            GR_GL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
+        }
+    }
+    fRTFBOID                = 0;
+    fTexFBOID               = 0;
+    fStencilRenderbufferID  = 0;
+    fMSColorRenderbufferID  = 0;
+    GrSafeUnref(fTexIDObj);
+    fTexIDObj = NULL;
+}
+
+void GrGLRenderTarget::onAbandon() {
+    fRTFBOID                = 0;
+    fTexFBOID               = 0;
+    fStencilRenderbufferID  = 0;
+    fMSColorRenderbufferID  = 0;
+    if (NULL != fTexIDObj) {
+        fTexIDObj->abandon();
+        fTexIDObj = NULL;
+    }
+}
+
diff --git a/gpu/src/GrGLRenderTarget.h b/gpu/src/GrGLRenderTarget.h
new file mode 100644
index 0000000..48ff12d
--- /dev/null
+++ b/gpu/src/GrGLRenderTarget.h
@@ -0,0 +1,103 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#ifndef GrGLRenderTarget_DEFINED
+#define GrGLRenderTarget_DEFINED
+
+#include "GrGLIRect.h"
+#include "GrRenderTarget.h"
+#include "GrScalar.h"
+
+class GrGpuGL;
+class GrGLTexture;
+class GrGLTexID;
+
+class GrGLRenderTarget : public GrRenderTarget {
+
+public:
+    // set fTexFBOID to this value to indicate that it is multisampled but
+    // Gr doesn't know how to resolve it.
+    enum { kUnresolvableFBOID = 0 };
+
+    struct GLRenderTargetIDs {
+        GrGLuint      fRTFBOID;
+        GrGLuint      fTexFBOID;
+        GrGLuint      fStencilRenderbufferID;
+        GrGLuint      fMSColorRenderbufferID;
+        bool          fOwnIDs;
+        void reset() { memset(this, 0, sizeof(GLRenderTargetIDs)); }
+    };
+
+    GrGLRenderTarget(GrGpuGL* gpu,
+                     const GLRenderTargetIDs& ids,
+                     GrGLTexID* texID,
+                     GrPixelConfig config,
+                     GrGLuint stencilBits,
+                     bool isMultisampled,
+                     const GrGLIRect& fViewport,
+                     GrGLTexture* texture);
+
+    virtual ~GrGLRenderTarget() { this->release(); }
+
+    void setViewport(const GrGLIRect& rect) { fViewport = rect; }
+    const GrGLIRect& getViewport() const { return fViewport; }
+
+    // The following two functions return the same ID when a 
+    // texture-rendertarget is multisampled, and different IDs when
+    // it is.
+    // FBO ID used to render into
+    GrGLuint renderFBOID() const { return fRTFBOID; }
+    // FBO ID that has texture ID attached.
+    GrGLuint textureFBOID() const { return fTexFBOID; }
+
+    // override of GrRenderTarget 
+    virtual intptr_t getRenderTargetHandle() const {
+        return this->renderFBOID(); 
+    }
+    virtual intptr_t getRenderTargetResolvedHandle() const {
+        return this->textureFBOID();
+    }
+    virtual ResolveType getResolveType() const {
+        if (fRTFBOID == fTexFBOID) {
+            // catches FBO 0 and non MSAA case
+            return kAutoResolves_ResolveType;
+        } else if (kUnresolvableFBOID == fTexFBOID) {
+            return kCantResolve_ResolveType;
+        } else {
+            return kCanResolve_ResolveType;
+        }
+    }
+
+protected:
+    // override of GrResource
+    virtual void onAbandon();
+    virtual void onRelease();
+
+private:
+    GrGLuint      fRTFBOID;
+    GrGLuint      fTexFBOID;
+    GrGLuint      fStencilRenderbufferID;
+    GrGLuint      fMSColorRenderbufferID;
+
+    // Should this object delete IDs when it is destroyed or does someone
+    // else own them.
+    bool        fOwnIDs;
+
+    // when we switch to this rendertarget we want to set the viewport to
+    // only render to to content area (as opposed to the whole allocation) and
+    // we want the rendering to be at top left (GL has origin in bottom left)
+    GrGLIRect fViewport;
+
+    // non-NULL if this RT was created by Gr with an associated GrGLTexture.
+    GrGLTexID* fTexIDObj;
+
+    typedef GrRenderTarget INHERITED;
+};
+
+#endif
diff --git a/gpu/src/GrGLTexture.cpp b/gpu/src/GrGLTexture.cpp
index 02ddc53..e7db2ee 100644
--- a/gpu/src/GrGLTexture.cpp
+++ b/gpu/src/GrGLTexture.cpp
@@ -7,71 +7,12 @@
  */
 
 
-
 #include "GrGLTexture.h"
+
 #include "GrGpuGL.h"
 
 #define GPUGL static_cast<GrGpuGL*>(getGpu())
 
-GrGLRenderTarget::GrGLRenderTarget(GrGpuGL* gpu,
-                                   const GLRenderTargetIDs& ids,
-                                   GrGLTexID* texID,
-                                   GrPixelConfig config,
-                                   GrGLuint stencilBits,
-                                   bool isMultisampled,
-                                   const GrGLIRect& viewport,
-                                   GrGLTexture* texture)
-    : INHERITED(gpu, texture, viewport.fWidth, 
-                viewport.fHeight, config, 
-                stencilBits, isMultisampled) {
-    fRTFBOID                = ids.fRTFBOID;
-    fTexFBOID               = ids.fTexFBOID;
-    fStencilRenderbufferID  = ids.fStencilRenderbufferID;
-    fMSColorRenderbufferID  = ids.fMSColorRenderbufferID;
-    fViewport               = viewport;
-    fOwnIDs                 = ids.fOwnIDs;
-    fTexIDObj               = texID;
-    GrSafeRef(fTexIDObj);
-}
-
-void GrGLRenderTarget::onRelease() {
-    GPUGL->notifyRenderTargetDelete(this);
-    if (fOwnIDs) {
-        if (fTexFBOID) {
-            GR_GL(DeleteFramebuffers(1, &fTexFBOID));
-        }
-        if (fRTFBOID && fRTFBOID != fTexFBOID) {
-            GR_GL(DeleteFramebuffers(1, &fRTFBOID));
-        }
-        if (fStencilRenderbufferID) {
-            GR_GL(DeleteRenderbuffers(1, &fStencilRenderbufferID));
-        }
-        if (fMSColorRenderbufferID) {
-            GR_GL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
-        }
-    }
-    fRTFBOID                = 0;
-    fTexFBOID               = 0;
-    fStencilRenderbufferID  = 0;
-    fMSColorRenderbufferID  = 0;
-    GrSafeUnref(fTexIDObj);
-    fTexIDObj = NULL;
-}
-
-void GrGLRenderTarget::onAbandon() {
-    fRTFBOID                = 0;
-    fTexFBOID               = 0;
-    fStencilRenderbufferID  = 0;
-    fMSColorRenderbufferID  = 0;
-    if (NULL != fTexIDObj) {
-        fTexIDObj->abandon();
-        fTexIDObj = NULL;
-    }
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
-
 const GrGLenum* GrGLTexture::WrapMode2GLWrap() {
     static const GrGLenum mirrorRepeatModes[] = {
         GR_GL_CLAMP_TO_EDGE,
diff --git a/gpu/src/GrGLTexture.h b/gpu/src/GrGLTexture.h
index 32c2f20..7566a58 100644
--- a/gpu/src/GrGLTexture.h
+++ b/gpu/src/GrGLTexture.h
@@ -10,12 +10,9 @@
 #ifndef GrGLTexture_DEFINED
 #define GrGLTexture_DEFINED
 
-#include "GrTexture.h"
+#include "GrGLRenderTarget.h"
 #include "GrScalar.h"
-#include "GrGLIRect.h"
-
-class GrGpuGL;
-class GrGLTexture;
+#include "GrTexture.h"
 
 /**
  * A ref counted tex id that deletes the texture in its destructor.
@@ -41,89 +38,6 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 
-class GrGLRenderTarget : public GrRenderTarget {
-
-public:
-    // set fTexFBOID to this value to indicate that it is multisampled but
-    // Gr doesn't know how to resolve it.
-    enum { kUnresolvableFBOID = 0 };
-
-    struct GLRenderTargetIDs {
-        GrGLuint      fRTFBOID;
-        GrGLuint      fTexFBOID;
-        GrGLuint      fStencilRenderbufferID;
-        GrGLuint      fMSColorRenderbufferID;
-        bool          fOwnIDs;
-        void reset() { memset(this, 0, sizeof(GLRenderTargetIDs)); }
-    };
-
-    GrGLRenderTarget(GrGpuGL* gpu,
-                     const GLRenderTargetIDs& ids,
-                     GrGLTexID* texID,
-                     GrPixelConfig config,
-                     GrGLuint stencilBits,
-                     bool isMultisampled,
-                     const GrGLIRect& fViewport,
-                     GrGLTexture* texture);
-
-    virtual ~GrGLRenderTarget() { this->release(); }
-
-    void setViewport(const GrGLIRect& rect) { fViewport = rect; }
-    const GrGLIRect& getViewport() const { return fViewport; }
-
-    // The following two functions return the same ID when a 
-    // texture-rendertarget is multisampled, and different IDs when
-    // it is.
-    // FBO ID used to render into
-    GrGLuint renderFBOID() const { return fRTFBOID; }
-    // FBO ID that has texture ID attached.
-    GrGLuint textureFBOID() const { return fTexFBOID; }
-
-    // override of GrRenderTarget 
-    virtual intptr_t getRenderTargetHandle() const {
-        return this->renderFBOID(); 
-    }
-    virtual intptr_t getRenderTargetResolvedHandle() const {
-        return this->textureFBOID();
-    }
-    virtual ResolveType getResolveType() const {
-        if (fRTFBOID == fTexFBOID) {
-            // catches FBO 0 and non MSAA case
-            return kAutoResolves_ResolveType;
-        } else if (kUnresolvableFBOID == fTexFBOID) {
-            return kCantResolve_ResolveType;
-        } else {
-            return kCanResolve_ResolveType;
-        }
-    }
-
-protected:
-    // override of GrResource
-    virtual void onAbandon();
-    virtual void onRelease();
-
-private:
-    GrGLuint      fRTFBOID;
-    GrGLuint      fTexFBOID;
-    GrGLuint      fStencilRenderbufferID;
-    GrGLuint      fMSColorRenderbufferID;
-
-    // Should this object delete IDs when it is destroyed or does someone
-    // else own them.
-    bool        fOwnIDs;
-
-    // when we switch to this rendertarget we want to set the viewport to
-    // only render to to content area (as opposed to the whole allocation) and
-    // we want the rendering to be at top left (GL has origin in bottom left)
-    GrGLIRect fViewport;
-
-    // non-NULL if this RT was created by Gr with an associated GrGLTexture.
-    GrGLTexID* fTexIDObj;
-
-    typedef GrRenderTarget INHERITED;
-};
-
-////////////////////////////////////////////////////////////////////////////////
 
 class GrGLTexture : public GrTexture {
 
@@ -235,7 +149,6 @@
     GrScalar            fScaleX;
     GrScalar            fScaleY;
     Orientation         fOrientation;
-    GrGpuGL*            fGpuGL;
 
     typedef GrTexture INHERITED;
 };
diff --git a/gpu/src/GrRenderTarget.cpp b/gpu/src/GrRenderTarget.cpp
new file mode 100644
index 0000000..186fe8e
--- /dev/null
+++ b/gpu/src/GrRenderTarget.cpp
@@ -0,0 +1,58 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#include "GrRenderTarget.h"
+
+#include "GrContext.h"
+#include "GrGpu.h"
+
+bool GrRenderTarget::readPixels(int left, int top, int width, int height,
+                                GrPixelConfig config, void* buffer) {
+    // go through context so that all necessary flushing occurs
+    GrContext* context = this->getGpu()->getContext();
+    GrAssert(NULL != context);
+    return context->readRenderTargetPixels(this,
+                                           left, top, 
+                                           width, height,
+                                           config, buffer);
+}
+
+size_t GrRenderTarget::sizeInBytes() const {
+    int colorBits;
+    if (kUnknown_GrPixelConfig == fConfig) {
+        colorBits = 32; // don't know, make a guess
+    } else {
+        colorBits = GrBytesPerPixel(fConfig);
+    }
+    return fWidth * fHeight * (fStencilBits + colorBits);
+}
+
+void GrRenderTarget::flagAsNeedingResolve(const GrIRect* rect) {
+    if (kCanResolve_ResolveType == getResolveType()) {
+        if (NULL != rect) {
+            fResolveRect.join(*rect);
+            if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
+                fResolveRect.setEmpty();
+            }
+        } else {
+            fResolveRect.setLTRB(0, 0, this->width(), this->height());
+        }
+    }
+}
+
+void GrRenderTarget::overrideResolveRect(const GrIRect rect) {
+    fResolveRect = rect;
+    if (fResolveRect.isEmpty()) {
+        fResolveRect.setLargestInverted();
+    } else {
+        if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
+            fResolveRect.setLargestInverted();
+        }
+    }
+}
\ No newline at end of file
diff --git a/gpu/src/GrTexture.cpp b/gpu/src/GrTexture.cpp
index de3bce9..77868df 100644
--- a/gpu/src/GrTexture.cpp
+++ b/gpu/src/GrTexture.cpp
@@ -8,53 +8,10 @@
 
 
 #include "GrTexture.h"
+
 #include "GrContext.h"
 #include "GrGpu.h"
-
-bool GrRenderTarget::readPixels(int left, int top, int width, int height,
-                                GrPixelConfig config, void* buffer) {
-    // go through context so that all necessary flushing occurs
-    GrContext* context = this->getGpu()->getContext();
-    GrAssert(NULL != context);
-    return context->readRenderTargetPixels(this,
-                                           left, top, 
-                                           width, height,
-                                           config, buffer);
-}
-
-size_t GrRenderTarget::sizeInBytes() const {
-    int colorBits;
-    if (kUnknown_GrPixelConfig == fConfig) {
-        colorBits = 32; // don't know, make a guess
-    } else {
-        colorBits = GrBytesPerPixel(fConfig);
-    }
-    return fWidth * fHeight * (fStencilBits + colorBits);
-}
-
-void GrRenderTarget::flagAsNeedingResolve(const GrIRect* rect) {
-    if (kCanResolve_ResolveType == getResolveType()) {
-        if (NULL != rect) {
-            fResolveRect.join(*rect);
-            if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
-                fResolveRect.setEmpty();
-            }
-        } else {
-            fResolveRect.setLTRB(0, 0, this->width(), this->height());
-        }
-    }
-}
-
-void GrRenderTarget::overrideResolveRect(const GrIRect rect) {
-    fResolveRect = rect;
-    if (fResolveRect.isEmpty()) {
-        fResolveRect.setLargestInverted();
-    } else {
-        if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
-            fResolveRect.setLargestInverted();
-        }
-    }
-}
+#include "GrRenderTarget.h"
 
 bool GrTexture::readPixels(int left, int top, int width, int height,
                            GrPixelConfig config, void* buffer) {
@@ -67,3 +24,18 @@
                                         config, buffer);
 }
 
+void GrTexture::releaseRenderTarget() {
+    if (NULL != fRenderTarget) {
+        GrAssert(fRenderTarget->asTexture() == this);
+        fRenderTarget->onTextureReleaseRenderTarget();
+        fRenderTarget->unref();
+        fRenderTarget = NULL;
+    }
+}
+
+void GrTexture::onAbandon() {
+    if (NULL != fRenderTarget) {
+        fRenderTarget->abandon();
+    }
+}
+