Add APIs and plumbing for external rendertaret-textures w/ and w/out MSAA.
Review URL: http://codereview.appspot.com/4388049/
git-svn-id: http://skia.googlecode.com/svn/trunk@1102 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/include/GrGLTexture.h b/gpu/include/GrGLTexture.h
index 94ae7b4..cb50a1e 100644
--- a/gpu/include/GrGLTexture.h
+++ b/gpu/include/GrGLTexture.h
@@ -14,7 +14,6 @@
limitations under the License.
*/
-
#ifndef GrGLTexture_DEFINED
#define GrGLTexture_DEFINED
@@ -31,10 +30,10 @@
class GrGLTexID : public GrRefCnt {
public:
- GrGLTexID(GrGLuint texID) : fTexID(texID) {}
+ GrGLTexID(GrGLuint texID, bool ownsID) : fTexID(texID), fOwnsID(ownsID) {}
virtual ~GrGLTexID() {
- if (0 != fTexID) {
+ if (0 != fTexID && fOwnsID) {
GR_GL(DeleteTextures(1, &fTexID));
}
}
@@ -44,27 +43,25 @@
private:
GrGLuint fTexID;
+ bool fOwnsID;
};
+////////////////////////////////////////////////////////////////////////////////
+
class GrGLRenderTarget : public GrRenderTarget {
public:
- virtual ~GrGLRenderTarget() { this->release(); }
+ // set fTexFBOID to this value to indicate that it is multisampled but
+ // Gr doesn't know how to resolve it.
+ enum { kUnresolvableFBOID = 0 };
- bool resolveable() const { return fRTFBOID != fTexFBOID; }
- bool needsResolve() const { return fNeedsResolve; }
- void setDirty(bool dirty) { fNeedsResolve = resolveable() && dirty; }
-
- GrGLuint renderFBOID() const { return fRTFBOID; }
- GrGLuint textureFBOID() const { return fTexFBOID; }
-
-protected:
struct GLRenderTargetIDs {
GrGLuint fRTFBOID;
GrGLuint fTexFBOID;
GrGLuint fStencilRenderbufferID;
GrGLuint fMSColorRenderbufferID;
bool fOwnIDs;
+ void reset() { memset(this, 0, sizeof(GLRenderTargetIDs)); }
};
GrGLRenderTarget(GrGpuGL* gpu,
@@ -75,10 +72,33 @@
const GrGLIRect& fViewport,
GrGLTexture* texture);
+ virtual ~GrGLRenderTarget() { this->release(); }
+
void setViewport(const GrGLIRect& rect) { fViewport = rect; }
const GrGLIRect& getViewport() const { return fViewport; }
- // overloads of GrResource
+ // 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 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();
@@ -92,10 +112,6 @@
// else own them.
bool fOwnIDs;
- // If there separate Texture and RenderTarget FBO IDs then the rendertarget
- // must be resolved to the texture FBO before it is used as a texture.
- bool fNeedsResolve;
-
// 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)
@@ -104,12 +120,11 @@
// non-NULL if this RT was created by Gr with an associated GrGLTexture.
GrGLTexID* fTexIDObj;
- friend class GrGpuGL;
- friend class GrGLTexture;
-
typedef GrRenderTarget INHERITED;
};
+////////////////////////////////////////////////////////////////////////////////
+
class GrGLTexture : public GrTexture {
public:
@@ -122,8 +137,31 @@
GrGLenum fFilter;
GrGLenum fWrapS;
GrGLenum fWrapT;
+ void invalidate() { memset(this, 0xff, sizeof(TexParams)); }
};
+ struct GLTextureDesc {
+ uint32_t fContentWidth;
+ uint32_t fContentHeight;
+ uint32_t fAllocWidth;
+ uint32_t fAllocHeight;
+ GrPixelConfig fFormat;
+ GrGLuint fTextureID;
+ bool fOwnsID;
+ GrGLenum fUploadFormat;
+ GrGLenum fUploadByteCount;
+ GrGLenum fUploadType;
+ GrGLuint fStencilBits;
+ Orientation fOrientation;
+ };
+
+ typedef GrGLRenderTarget::GLRenderTargetIDs GLRenderTargetIDs;
+
+ GrGLTexture(GrGpuGL* gpu,
+ const GLTextureDesc& textureDesc,
+ const GLRenderTargetIDs& rtIDs,
+ const TexParams& initialTexParams);
+
virtual ~GrGLTexture() { this->release(); }
// overrides of GrTexture
@@ -176,26 +214,9 @@
// and it is up to the GrGpuGL derivative to handle y-mirroing.
Orientation orientation() const { return fOrientation; }
-protected:
+ static const GrGLenum* WrapMode2GLWrap();
- struct GLTextureDesc {
- uint32_t fContentWidth;
- uint32_t fContentHeight;
- uint32_t fAllocWidth;
- uint32_t fAllocHeight;
- GrPixelConfig fFormat;
- GrGLuint fTextureID;
- GrGLenum fUploadFormat;
- GrGLenum fUploadByteCount;
- GrGLenum fUploadType;
- GrGLuint fStencilBits;
- Orientation fOrientation;
- };
- typedef GrGLRenderTarget::GLRenderTargetIDs GLRenderTargetIDs;
- GrGLTexture(GrGpuGL* gpu,
- const GLTextureDesc& textureDesc,
- const GLRenderTargetIDs& rtIDs,
- const TexParams& initialTexParams);
+protected:
// overrides of GrTexture
virtual void onAbandon();
@@ -215,10 +236,6 @@
Orientation fOrientation;
GrGpuGL* fGpuGL;
- static const GrGLenum* WrapMode2GLWrap();
-
- friend class GrGpuGL;
-
typedef GrTexture INHERITED;
};