Changes the pointer from textures to their renderbuffer proxies to non-refcounted (2/2)
TRAC #19335
Issue=271
Instead, the texture maintains an internal refcount which causes the pointer to behave
kind of like a "weak" shared pointer-- its reference won't prevent the renderbuffer from
being deleted, but if the renderbuffer's refcount drops to zero, the texture should set
its pointer to the renderbuffer to null so that a new one can be created at the next
getRenderbuffer call.
Signed-off-by: Nicolas Capens
Signed-off-by: Daniel Koch
git-svn-id: https://angleproject.googlecode.com/svn/trunk@948 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/Renderbuffer.cpp b/src/libGLESv2/Renderbuffer.cpp
index 07ae6b5..6004255 100644
--- a/src/libGLESv2/Renderbuffer.cpp
+++ b/src/libGLESv2/Renderbuffer.cpp
@@ -22,6 +22,17 @@
{
}
+// The default case for classes inherited from RenderbufferInterface is not to
+// need to do anything upon the reference count to the parent Renderbuffer incrementing
+// or decrementing.
+void RenderbufferInterface::addProxyRef(const Renderbuffer *proxy)
+{
+}
+
+void RenderbufferInterface::releaseProxy(const Renderbuffer *proxy)
+{
+}
+
GLuint RenderbufferInterface::getRedSize() const
{
return dx2es::GetRedSize(getD3DFormat());
@@ -62,6 +73,18 @@
mTexture.set(NULL);
}
+// Textures need to maintain their own reference count for references via
+// Renderbuffers acting as proxies. Here, we notify the texture of a reference.
+void RenderbufferTexture::addProxyRef(const Renderbuffer *proxy)
+{
+ mTexture->addProxyRef(proxy);
+}
+
+void RenderbufferTexture::releaseProxy(const Renderbuffer *proxy)
+{
+ mTexture->releaseProxy(proxy);
+}
+
IDirect3DSurface9 *RenderbufferTexture::getRenderTarget()
{
return mTexture->getRenderTarget(mTarget);
@@ -113,6 +136,22 @@
delete mInstance;
}
+// The RenderbufferInterface contained in this Renderbuffer may need to maintain
+// its own reference count, so we pass it on here.
+void Renderbuffer::addRef() const
+{
+ mInstance->addProxyRef(this);
+
+ RefCountObject::addRef();
+}
+
+void Renderbuffer::release() const
+{
+ mInstance->releaseProxy(this);
+
+ RefCountObject::release();
+}
+
IDirect3DSurface9 *Renderbuffer::getRenderTarget()
{
return mInstance->getRenderTarget();