Commit 4e3bad4e by apatrick@chromium.org

Changed raw pointers to RefCountObject to BindingPointers.

I suspect there is a bug whereby an owning reference to a RefCountObject is temporarily assigned to a BindingPointer, causing it to be destroyed and making the owning raw pointer go dangling. Making this change for mColorbufferProxy seemed to fix a crash in Chrome with canvas 2D. This was previously landed in r417 and r418. Review URL: http://codereview.appspot.com/2108047 git-svn-id: https://angleproject.googlecode.com/svn/trunk@423 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent ff8bdfb0
......@@ -122,11 +122,8 @@ Context::Context(const egl::Config *config, const gl::Context *shareContext)
// In order that access to these initial textures not be lost, they are treated as texture
// objects all of whose names are 0.
mTexture2DZero = new Texture2D(0);
mTextureCubeMapZero = new TextureCubeMap(0);
mColorbufferZero = NULL;
mDepthStencilbufferZero = NULL;
mTexture2DZero.set(new Texture2D(0));
mTextureCubeMapZero.set(new TextureCubeMap(0));
mState.activeSampler = 0;
bindArrayBuffer(0);
......@@ -137,11 +134,6 @@ Context::Context(const egl::Config *config, const gl::Context *shareContext)
bindDrawFramebuffer(0);
bindRenderbuffer(0);
for (int type = 0; type < SAMPLER_TYPE_COUNT; type++)
{
mIncompleteTextures[type] = NULL;
}
mState.currentProgram = 0;
mState.packAlignment = 4;
......@@ -205,7 +197,7 @@ Context::~Context()
for (int type = 0; type < SAMPLER_TYPE_COUNT; type++)
{
delete mIncompleteTextures[type];
mIncompleteTextures[type].set(NULL);
}
for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
......@@ -219,8 +211,8 @@ Context::~Context()
mState.textureCubeMap.set(NULL);
mState.renderbuffer.set(NULL);
delete mTexture2DZero;
delete mTextureCubeMapZero;
mTexture2DZero.set(NULL);
mTextureCubeMapZero.set(NULL);
delete mBufferBackEnd;
delete mVertexDataManager;
......@@ -1088,7 +1080,7 @@ Texture2D *Context::getTexture2D()
{
if (mState.texture2D.id() == 0) // Special case: 0 refers to different initial textures based on the target
{
return mTexture2DZero;
return mTexture2DZero.get();
}
return static_cast<Texture2D*>(mState.texture2D.get());
......@@ -1098,7 +1090,7 @@ TextureCubeMap *Context::getTextureCubeMap()
{
if (mState.textureCubeMap.id() == 0) // Special case: 0 refers to different initial textures based on the target
{
return mTextureCubeMapZero;
return mTextureCubeMapZero.get();
}
return static_cast<TextureCubeMap*>(mState.textureCubeMap.get());
......@@ -1113,8 +1105,8 @@ Texture *Context::getSamplerTexture(unsigned int sampler, SamplerType type)
switch (type)
{
default: UNREACHABLE();
case SAMPLER_2D: return mTexture2DZero;
case SAMPLER_CUBE: return mTextureCubeMapZero;
case SAMPLER_2D: return mTexture2DZero.get();
case SAMPLER_CUBE: return mTextureCubeMapZero.get();
}
}
......@@ -3045,7 +3037,7 @@ void Context::detachRenderbuffer(GLuint renderbuffer)
Texture *Context::getIncompleteTexture(SamplerType type)
{
Texture *t = mIncompleteTextures[type];
Texture *t = mIncompleteTextures[type].get();
if (t == NULL)
{
......@@ -3081,7 +3073,7 @@ Texture *Context::getIncompleteTexture(SamplerType type)
break;
}
mIncompleteTextures[type] = t;
mIncompleteTextures[type].set(t);
}
return t;
......
......@@ -422,11 +422,9 @@ class Context
State mState;
Texture2D *mTexture2DZero;
TextureCubeMap *mTextureCubeMapZero;
BindingPointer<Texture2D> mTexture2DZero;
BindingPointer<TextureCubeMap> mTextureCubeMapZero;
Colorbuffer *mColorbufferZero;
DepthStencilbuffer *mDepthStencilbufferZero;
typedef std::map<GLuint, Framebuffer*> FramebufferMap;
FramebufferMap mFramebufferMap;
......@@ -443,7 +441,7 @@ class Context
Blit *mBlit;
Texture *mIncompleteTextures[SAMPLER_TYPE_COUNT];
BindingPointer<Texture> mIncompleteTextures[SAMPLER_TYPE_COUNT];
// Recorded errors
bool mInvalidEnum;
......
......@@ -923,12 +923,11 @@ int Texture::levelCount() const
Texture2D::Texture2D(GLuint id) : Texture(id)
{
mTexture = NULL;
mColorbufferProxy = NULL;
}
Texture2D::~Texture2D()
{
delete mColorbufferProxy;
mColorbufferProxy.set(NULL);
if (mTexture)
{
......@@ -1400,13 +1399,12 @@ Renderbuffer *Texture2D::getColorbuffer(GLenum target)
return error(GL_INVALID_OPERATION, (Renderbuffer *)NULL);
}
if (mColorbufferProxy == NULL)
if (mColorbufferProxy.get() == NULL)
{
mColorbufferProxy = new Renderbuffer(id(), new TextureColorbufferProxy(this, target));
mColorbufferProxy->addRef();
mColorbufferProxy.set(new Renderbuffer(id(), new TextureColorbufferProxy(this, target)));
}
return mColorbufferProxy;
return mColorbufferProxy.get();
}
IDirect3DSurface9 *Texture2D::getRenderTarget(GLenum target)
......@@ -1424,18 +1422,13 @@ IDirect3DSurface9 *Texture2D::getRenderTarget(GLenum target)
TextureCubeMap::TextureCubeMap(GLuint id) : Texture(id)
{
mTexture = NULL;
for (int i = 0; i < 6; i++)
{
mFaceProxies[i] = NULL;
}
}
TextureCubeMap::~TextureCubeMap()
{
for (int i = 0; i < 6; i++)
{
delete mFaceProxies[i];
mFaceProxies[i].set(NULL);
}
if (mTexture)
......@@ -2012,13 +2005,12 @@ Renderbuffer *TextureCubeMap::getColorbuffer(GLenum target)
unsigned int face = faceIndex(target);
if (mFaceProxies[face] == NULL)
if (mFaceProxies[face].get() == NULL)
{
mFaceProxies[face] = new Renderbuffer(id(), new TextureColorbufferProxy(this, target));
mFaceProxies[face]->addRef();
mFaceProxies[face].set(new Renderbuffer(id(), new TextureColorbufferProxy(this, target)));
}
return mFaceProxies[face];
return mFaceProxies[face].get();
}
IDirect3DSurface9 *TextureCubeMap::getRenderTarget(GLenum target)
......
......@@ -18,6 +18,7 @@
#include <d3d9.h>
#include "libGLESv2/Renderbuffer.h"
#include "libGLESv2/RefCountObject.h"
#include "libGLESv2/utilities.h"
#include "common/debug.h"
......@@ -239,7 +240,7 @@ class Texture2D : public Texture
IDirect3DTexture9 *mTexture;
Renderbuffer *mColorbufferProxy;
BindingPointer<Renderbuffer> mColorbufferProxy;
};
class TextureCubeMap : public Texture
......@@ -299,7 +300,7 @@ class TextureCubeMap : public Texture
IDirect3DCubeTexture9 *mTexture;
Renderbuffer *mFaceProxies[6];
BindingPointer<Renderbuffer> mFaceProxies[6];
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment