Commit 839d9e67 by Nicolas Capens Committed by Nicolas Capens

Eliminate RefCountObject.

Bug 18591036 Change-Id: Iabe4eb6c60767f3668cca31de36505df9c96145d Reviewed-on: https://swiftshader-review.googlesource.com/1556Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent aa660293
...@@ -32,6 +32,20 @@ ...@@ -32,6 +32,20 @@
namespace es2 namespace es2
{ {
int VertexAttribute::typeSize() const
{
switch (mType)
{
case GL_BYTE: return mSize * sizeof(GLbyte);
case GL_UNSIGNED_BYTE: return mSize * sizeof(GLubyte);
case GL_SHORT: return mSize * sizeof(GLshort);
case GL_UNSIGNED_SHORT: return mSize * sizeof(GLushort);
case GL_FIXED: return mSize * sizeof(GLfixed);
case GL_FLOAT: return mSize * sizeof(GLfloat);
default: UNREACHABLE(); return mSize * sizeof(GLfloat);
}
}
Context::Context(const egl::Config *config, const Context *shareContext) : mConfig(config) Context::Context(const egl::Config *config, const Context *shareContext) : mConfig(config)
{ {
sw::Context *context = new sw::Context(); sw::Context *context = new sw::Context();
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#define LIBGLESV2_CONTEXT_H_ #define LIBGLESV2_CONTEXT_H_
#include "libEGL/Context.hpp" #include "libEGL/Context.hpp"
#include "RefCountObject.h"
#include "Image.hpp" #include "Image.hpp"
#include "Renderer/Sampler.hpp" #include "Renderer/Sampler.hpp"
...@@ -85,19 +84,7 @@ class VertexAttribute ...@@ -85,19 +84,7 @@ class VertexAttribute
{ {
} }
int typeSize() const int typeSize() const;
{
switch (mType)
{
case GL_BYTE: return mSize * sizeof(GLbyte);
case GL_UNSIGNED_BYTE: return mSize * sizeof(GLubyte);
case GL_SHORT: return mSize * sizeof(GLshort);
case GL_UNSIGNED_SHORT: return mSize * sizeof(GLushort);
case GL_FIXED: return mSize * sizeof(GLfixed);
case GL_FLOAT: return mSize * sizeof(GLfloat);
default: UNREACHABLE(); return mSize * sizeof(GLfloat);
}
}
GLsizei stride() const GLsizei stride() const
{ {
......
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2012 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
// RefCountObject.cpp: Defines the RefCountObject base class that provides
// lifecycle support for GL objects using the traditional BindObject scheme, but
// that need to be reference counted for correct cross-context deletion.
// (Concretely, textures, buffers and renderbuffers.)
#include "RefCountObject.h"
#include "Common/Thread.hpp"
namespace es2
{
RefCountObject::RefCountObject(GLuint id)
{
mId = id;
referenceCount = 0;
}
RefCountObject::~RefCountObject()
{
ASSERT(referenceCount == 0);
}
void RefCountObject::addRef()
{
sw::atomicIncrement(&referenceCount);
}
void RefCountObject::release()
{
ASSERT(referenceCount > 0);
if(referenceCount > 0)
{
sw::atomicDecrement(&referenceCount);
}
if(referenceCount == 0)
{
delete this;
}
}
void RefCountObjectBindingPointer::set(RefCountObject *newObject)
{
// addRef first in case newObject == mObject and this is the last reference to it.
if(newObject != NULL) newObject->addRef();
if(mObject != NULL) mObject->release();
mObject = newObject;
}
}
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2012 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
// RefCountObject.h: Defines the RefCountObject base class that provides
// lifecycle support for GL objects using the traditional BindObject scheme, but
// that need to be reference counted for correct cross-context deletion.
// (Concretely, textures, buffers and renderbuffers.)
#ifndef LIBGLESV2_REFCOUNTOBJECT_H_
#define LIBGLESV2_REFCOUNTOBJECT_H_
#include "common/debug.h"
#define GL_APICALL
#include <GLES2/gl2.h>
#include <cstddef>
namespace es2
{
class RefCountObject
{
public:
explicit RefCountObject(GLuint id);
virtual ~RefCountObject();
virtual void addRef();
virtual void release();
GLuint id() const {return mId;}
private:
GLuint mId;
volatile int referenceCount;
};
class RefCountObjectBindingPointer
{
protected:
RefCountObjectBindingPointer() : mObject(NULL) { }
~RefCountObjectBindingPointer() { ASSERT(mObject == NULL); } // Objects have to be released before the resource manager is destroyed, so they must be explicitly cleaned up.
void set(RefCountObject *newObject);
RefCountObject *get() const { return mObject; }
public:
GLuint id() const { return (mObject != NULL) ? mObject->id() : 0; }
bool operator ! () const { return (get() == NULL); }
private:
RefCountObject *mObject;
};
template<class ObjectType>
class BindingPointer : public RefCountObjectBindingPointer
{
public:
void set(ObjectType *newObject) { RefCountObjectBindingPointer::set(newObject); }
ObjectType *get() const { return static_cast<ObjectType*>(RefCountObjectBindingPointer::get()); }
ObjectType *operator -> () const { return get(); }
};
}
#endif // LIBGLESV2_REFCOUNTOBJECT_H_
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
namespace es2 namespace es2
{ {
Texture::Texture(GLuint id) : RefCountObject(id) Texture::Texture()
{ {
mMinFilter = GL_NEAREST_MIPMAP_LINEAR; mMinFilter = GL_NEAREST_MIPMAP_LINEAR;
mMagFilter = GL_LINEAR; mMagFilter = GL_LINEAR;
...@@ -36,13 +36,35 @@ Texture::Texture(GLuint id) : RefCountObject(id) ...@@ -36,13 +36,35 @@ Texture::Texture(GLuint id) : RefCountObject(id)
mMaxAnisotropy = 1.0f; mMaxAnisotropy = 1.0f;
resource = new sw::Resource(0); resource = new sw::Resource(0);
referenceCount = 0;
} }
Texture::~Texture() Texture::~Texture()
{ {
ASSERT(referenceCount == 0);
resource->destruct(); resource->destruct();
} }
void Texture::addRef()
{
sw::atomicIncrement(&referenceCount);
}
void Texture::release()
{
ASSERT(referenceCount > 0);
if(referenceCount > 0)
{
sw::atomicDecrement(&referenceCount);
}
if(referenceCount == 0)
{
delete this;
}
}
sw::Resource *Texture::getResource() const sw::Resource *Texture::getResource() const
{ {
return resource; return resource;
...@@ -280,7 +302,7 @@ bool Texture::isMipmapFiltered() const ...@@ -280,7 +302,7 @@ bool Texture::isMipmapFiltered() const
return false; return false;
} }
Texture2D::Texture2D(GLuint id) : Texture(id) Texture2D::Texture2D()
{ {
for(int i = 0; i < MIPMAP_LEVELS; i++) for(int i = 0; i < MIPMAP_LEVELS; i++)
{ {
...@@ -543,7 +565,7 @@ bool Texture2D::isShared(GLenum target, unsigned int level) const ...@@ -543,7 +565,7 @@ bool Texture2D::isShared(GLenum target, unsigned int level) const
return image[level]->isShared(); return image[level]->isShared();
} }
TextureCubeMap::TextureCubeMap(GLuint id) : Texture(id) TextureCubeMap::TextureCubeMap()
{ {
for(int f = 0; f < 6; f++) for(int f = 0; f < 6; f++)
{ {
...@@ -846,34 +868,6 @@ bool TextureCubeMap::isShared(GLenum target, unsigned int level) const ...@@ -846,34 +868,6 @@ bool TextureCubeMap::isShared(GLenum target, unsigned int level) const
return image[face][level]->isShared(); return image[face][level]->isShared();
} }
TextureExternal::TextureExternal(GLuint id) : Texture2D(id)
{
mMinFilter = GL_LINEAR;
mMagFilter = GL_LINEAR;
mWrapS = GL_CLAMP_TO_EDGE;
mWrapT = GL_CLAMP_TO_EDGE;
}
TextureExternal::~TextureExternal()
{
}
GLenum TextureExternal::getTarget() const
{
return GL_TEXTURE_EXTERNAL_OES;
}
void TextureExternal::setImage(Image *sharedImage)
{
if(image[0])
{
image[0]->release();
}
sharedImage->addRef();
image[0] = sharedImage;
}
} }
// Exported functions for use by EGL // Exported functions for use by EGL
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#ifndef LIBGLESV2_TEXTURE_H_ #ifndef LIBGLESV2_TEXTURE_H_
#define LIBGLESV2_TEXTURE_H_ #define LIBGLESV2_TEXTURE_H_
#include "RefCountObject.h"
#include "utilities.h" #include "utilities.h"
#include "libEGL/Texture2D.hpp" #include "libEGL/Texture2D.hpp"
#include "common/debug.h" #include "common/debug.h"
...@@ -45,13 +44,16 @@ enum ...@@ -45,13 +44,16 @@ enum
IMPLEMENTATION_MAX_SAMPLES = 4 IMPLEMENTATION_MAX_SAMPLES = 4
}; };
class Texture : public RefCountObject class Texture
{ {
public: public:
explicit Texture(GLuint id); explicit Texture();
virtual ~Texture(); virtual ~Texture();
virtual void addRef();
virtual void release();
sw::Resource *getResource() const; sw::Resource *getResource() const;
virtual GLenum getTarget() const = 0; virtual GLenum getTarget() const = 0;
...@@ -102,12 +104,13 @@ protected: ...@@ -102,12 +104,13 @@ protected:
GLfloat mMaxAnisotropy; GLfloat mMaxAnisotropy;
sw::Resource *resource; sw::Resource *resource;
volatile int referenceCount;
}; };
class Texture2D : public Texture, public egl::Texture2D class Texture2D : public Texture, public egl::Texture2D
{ {
public: public:
explicit Texture2D(GLuint id); explicit Texture2D();
virtual ~Texture2D(); virtual ~Texture2D();
...@@ -147,7 +150,7 @@ protected: ...@@ -147,7 +150,7 @@ protected:
class TextureCubeMap : public Texture class TextureCubeMap : public Texture
{ {
public: public:
explicit TextureCubeMap(GLuint id); explicit TextureCubeMap();
virtual ~TextureCubeMap(); virtual ~TextureCubeMap();
...@@ -187,17 +190,6 @@ private: ...@@ -187,17 +190,6 @@ private:
Image *image[6][IMPLEMENTATION_MAX_TEXTURE_LEVELS]; Image *image[6][IMPLEMENTATION_MAX_TEXTURE_LEVELS];
}; };
class TextureExternal : public Texture2D
{
public:
explicit TextureExternal(GLuint id);
virtual ~TextureExternal();
virtual GLenum getTarget() const;
void setImage(Image *image);
};
} }
#endif // LIBGLESV2_TEXTURE_H_ #endif // LIBGLESV2_TEXTURE_H_
...@@ -1536,7 +1536,7 @@ void RADAPIENTRY radTextureStorage(RADtexture texture, RADtextureTarget target, ...@@ -1536,7 +1536,7 @@ void RADAPIENTRY radTextureStorage(RADtexture texture, RADtextureTarget target,
{ {
case RAD_TEXTURE_2D: case RAD_TEXTURE_2D:
{ {
es2::Texture2D *tex = new es2::Texture2D(0); es2::Texture2D *tex = new es2::Texture2D();
for(int level = 0; level < levels; level++) for(int level = 0; level < levels; level++)
{ {
tex->setImage(level, width >> level, height >> level, format, type, 1, nullptr); tex->setImage(level, width >> level, height >> level, format, type, 1, nullptr);
......
...@@ -168,7 +168,6 @@ copy "$(OutDir)libRAD.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)\"</Comman ...@@ -168,7 +168,6 @@ copy "$(OutDir)libRAD.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)\"</Comman
<ClCompile Include="libRAD.cpp" /> <ClCompile Include="libRAD.cpp" />
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
<ClCompile Include="Program.cpp" /> <ClCompile Include="Program.cpp" />
<ClCompile Include="RefCountObject.cpp" />
<ClCompile Include="Shader.cpp" /> <ClCompile Include="Shader.cpp" />
<ClCompile Include="Texture.cpp" /> <ClCompile Include="Texture.cpp" />
<ClCompile Include="utilities.cpp" /> <ClCompile Include="utilities.cpp" />
...@@ -185,7 +184,6 @@ copy "$(OutDir)libRAD.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)\"</Comman ...@@ -185,7 +184,6 @@ copy "$(OutDir)libRAD.dll" "$(ProjectDir)..\..\..\lib\$(Configuration)\"</Comman
<ClInclude Include="main.h" /> <ClInclude Include="main.h" />
<ClInclude Include="mathutil.h" /> <ClInclude Include="mathutil.h" />
<ClInclude Include="Program.h" /> <ClInclude Include="Program.h" />
<ClInclude Include="RefCountObject.h" />
<ClInclude Include="resource.h" /> <ClInclude Include="resource.h" />
<ClInclude Include="Shader.h" /> <ClInclude Include="Shader.h" />
<ClInclude Include="Texture.h" /> <ClInclude Include="Texture.h" />
......
...@@ -29,9 +29,6 @@ ...@@ -29,9 +29,6 @@
<ClCompile Include="Program.cpp"> <ClCompile Include="Program.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="RefCountObject.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Shader.cpp"> <ClCompile Include="Shader.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
...@@ -64,9 +61,6 @@ ...@@ -64,9 +61,6 @@
<ClInclude Include="Program.h"> <ClInclude Include="Program.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="RefCountObject.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h"> <ClInclude Include="resource.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
......
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