Commit 50bba309 by Nicolas Capens

Refactor Image creation.

Customize construction for each use case. Bug 26851951 Change-Id: Ic10166bbfeaf11e800fec2a6470446b76e49b825 Reviewed-on: https://swiftshader-review.googlesource.com/4710Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent b2022a76
......@@ -31,16 +31,12 @@ sw::Format SelectInternalFormat(GLenum format, GLenum type);
GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment);
GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format);
static inline sw::Resource *getParentResource(egl::Texture *texture)
{
return texture ? texture->getResource() : nullptr;
}
class Image : public sw::Surface, public gl::Object
{
public:
// 2D texture image
Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type)
: sw::Surface(getParentResource(parentTexture), width, height, 1, SelectInternalFormat(format, type), true, true),
: sw::Surface(parentTexture->getResource(), width, height, 1, SelectInternalFormat(format, type), true, true),
width(width), height(height), format(format), type(type), internalFormat(SelectInternalFormat(format, type)), depth(1),
parentTexture(parentTexture)
{
......@@ -48,8 +44,9 @@ public:
Object::addRef();
}
Image(Texture *parentTexture, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, int pitchP = 0)
: sw::Surface(getParentResource(parentTexture), width, height, depth, SelectInternalFormat(format, type), true, true, pitchP),
// 3D texture image
Image(Texture *parentTexture, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type)
: sw::Surface(parentTexture->getResource(), width, height, depth, SelectInternalFormat(format, type), true, true),
width(width), height(height), format(format), type(type), internalFormat(SelectInternalFormat(format, type)), depth(depth),
parentTexture(parentTexture)
{
......@@ -57,9 +54,21 @@ public:
Object::addRef();
}
Image(GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable, bool renderTarget)
: sw::Surface(nullptr, width, height, multiSampleDepth, internalFormat, lockable, renderTarget),
width(width), height(height), format(0 /*GL_NONE*/), type(0 /*GL_NONE*/), internalFormat(internalFormat), depth(multiSampleDepth), parentTexture(nullptr)
// Native EGL image
Image(GLsizei width, GLsizei height, GLenum format, GLenum type, int pitchP)
: sw::Surface(nullptr, width, height, depth, SelectInternalFormat(format, type), true, true, pitchP),
width(width), height(height), format(format), type(type), internalFormat(SelectInternalFormat(format, type)), depth(depth),
parentTexture(nullptr)
{
shared = true;
Object::addRef();
}
// Render target
Image(GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable)
: sw::Surface(nullptr, width, height, multiSampleDepth, internalFormat, lockable, true),
width(width), height(height), format(0 /*GL_NONE*/), type(0 /*GL_NONE*/), internalFormat(internalFormat), depth(multiSampleDepth),
parentTexture(nullptr)
{
shared = false;
Object::addRef();
......@@ -206,14 +215,13 @@ class AndroidNativeImage : public egl::Image
{
public:
explicit AndroidNativeImage(ANativeWindowBuffer *nativeBuffer)
: egl::Image(0, nativeBuffer->width, nativeBuffer->height, 1,
: egl::Image(nativeBuffer->width, nativeBuffer->height,
GLPixelFormatFromAndroid(nativeBuffer->format),
GLPixelTypeFromAndroid(nativeBuffer->format),
nativeBuffer->stride),
nativeBuffer(nativeBuffer)
{
nativeBuffer->common.incRef(&nativeBuffer->common);
markShared();
}
private:
......
......@@ -223,7 +223,7 @@ namespace es1
if(height > OUTLINE_RESOLUTION)
{
ERR("Invalid parameters: %dx%d", width, height);
return 0;
return nullptr;
}
bool lockable = true;
......@@ -251,12 +251,12 @@ namespace es1
UNREACHABLE(format);
}
egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable, true);
egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable);
if(!surface)
{
ERR("Out of memory");
return 0;
return nullptr;
}
return surface;
......@@ -267,15 +267,15 @@ namespace es1
if(height > OUTLINE_RESOLUTION)
{
ERR("Invalid parameters: %dx%d", width, height);
return 0;
return nullptr;
}
egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable, true);
egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable);
if(!surface)
{
ERR("Out of memory");
return 0;
return nullptr;
}
return surface;
......
......@@ -333,12 +333,12 @@ Texture2D::Texture2D(GLuint name) : Texture(name)
{
for(int i = 0; i < MIPMAP_LEVELS; i++)
{
image[i] = 0;
image[i] = nullptr;
}
mSurface = NULL;
mSurface = nullptr;
mColorbufferProxy = NULL;
mColorbufferProxy = nullptr;
mProxyRefs = 0;
}
......@@ -351,7 +351,7 @@ Texture2D::~Texture2D()
if(image[i])
{
image[i]->unbind(this);
image[i] = 0;
image[i] = nullptr;
}
}
......@@ -359,11 +359,11 @@ Texture2D::~Texture2D()
if(mSurface)
{
mSurface->setBoundTexture(NULL);
mSurface = NULL;
mSurface->setBoundTexture(nullptr);
mSurface = nullptr;
}
mColorbufferProxy = NULL;
mColorbufferProxy = nullptr;
}
// We need to maintain a count of references to renderbuffers acting as
......@@ -383,7 +383,7 @@ void Texture2D::releaseProxy(const Renderbuffer *proxy)
if(mProxyRefs == 0)
{
mColorbufferProxy = NULL;
mColorbufferProxy = nullptr;
}
}
......@@ -478,7 +478,7 @@ void Texture2D::bindTexImage(egl::Surface *surface)
if(image[level])
{
image[level]->unbind(this);
image[level] = 0;
image[level] = nullptr;
}
}
......@@ -495,7 +495,7 @@ void Texture2D::releaseTexImage()
if(image[level])
{
image[level]->unbind(this);
image[level] = 0;
image[level] = nullptr;
}
}
}
......@@ -721,10 +721,10 @@ Renderbuffer *Texture2D::getRenderbuffer(GLenum target)
{
if(target != GL_TEXTURE_2D)
{
return error(GL_INVALID_OPERATION, (Renderbuffer *)NULL);
return error(GL_INVALID_OPERATION, (Renderbuffer*)nullptr);
}
if(mColorbufferProxy == NULL)
if(!mColorbufferProxy)
{
mColorbufferProxy = new Renderbuffer(name, new RenderbufferTexture2D(this));
}
......@@ -786,10 +786,10 @@ egl::Image *createBackBuffer(int width, int height, const egl::Config *config)
{
if(config)
{
return new egl::Image(width, height, config->mRenderTargetFormat, config->mSamples, false, true);
return new egl::Image(width, height, config->mRenderTargetFormat, config->mSamples, false);
}
return 0;
return nullptr;
}
egl::Image *createDepthStencil(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard)
......@@ -825,12 +825,12 @@ egl::Image *createDepthStencil(unsigned int width, unsigned int height, sw::Form
UNREACHABLE(format);
}
egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable, true);
egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable);
if(!surface)
{
ERR("Out of memory");
return 0;
return nullptr;
}
return surface;
......
......@@ -241,7 +241,7 @@ namespace es2
if(height > OUTLINE_RESOLUTION)
{
ERR("Invalid parameters: %dx%d", width, height);
return 0;
return nullptr;
}
bool lockable = true;
......@@ -269,12 +269,12 @@ namespace es2
UNREACHABLE(format);
}
egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable, true);
egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable);
if(!surface)
{
ERR("Out of memory");
return 0;
return nullptr;
}
return surface;
......@@ -285,15 +285,15 @@ namespace es2
if(height > OUTLINE_RESOLUTION)
{
ERR("Invalid parameters: %dx%d", width, height);
return 0;
return nullptr;
}
egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable, true);
egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable);
if(!surface)
{
ERR("Out of memory");
return 0;
return nullptr;
}
return surface;
......
......@@ -504,12 +504,12 @@ Texture2D::Texture2D(GLuint name) : Texture(name)
{
for(int i = 0; i < MIPMAP_LEVELS; i++)
{
image[i] = 0;
image[i] = nullptr;
}
mSurface = NULL;
mSurface = nullptr;
mColorbufferProxy = NULL;
mColorbufferProxy = nullptr;
mProxyRefs = 0;
}
......@@ -522,7 +522,7 @@ Texture2D::~Texture2D()
if(image[i])
{
image[i]->unbind(this);
image[i] = 0;
image[i] = nullptr;
}
}
......@@ -530,11 +530,11 @@ Texture2D::~Texture2D()
if(mSurface)
{
mSurface->setBoundTexture(NULL);
mSurface = NULL;
mSurface->setBoundTexture(nullptr);
mSurface = nullptr;
}
mColorbufferProxy = NULL;
mColorbufferProxy = nullptr;
}
// We need to maintain a count of references to renderbuffers acting as
......@@ -554,7 +554,7 @@ void Texture2D::releaseProxy(const Renderbuffer *proxy)
if(mProxyRefs == 0)
{
mColorbufferProxy = NULL;
mColorbufferProxy = nullptr;
}
}
......@@ -649,7 +649,7 @@ void Texture2D::bindTexImage(egl::Surface *surface)
if(image[level])
{
image[level]->unbind(this);
image[level] = 0;
image[level] = nullptr;
}
}
......@@ -666,7 +666,7 @@ void Texture2D::releaseTexImage()
if(image[level])
{
image[level]->unbind(this);
image[level] = 0;
image[level] = nullptr;
}
}
}
......@@ -906,10 +906,10 @@ Renderbuffer *Texture2D::getRenderbuffer(GLenum target, GLint level, GLint layer
{
if(target != GL_TEXTURE_2D)
{
return error(GL_INVALID_OPERATION, (Renderbuffer *)NULL);
return error(GL_INVALID_OPERATION, (Renderbuffer*)nullptr);
}
if(mColorbufferProxy == NULL)
if(!mColorbufferProxy)
{
mColorbufferProxy = new Renderbuffer(name, new RenderbufferTexture2D(this, level));
}
......@@ -954,13 +954,13 @@ TextureCubeMap::TextureCubeMap(GLuint name) : Texture(name)
{
for(int i = 0; i < MIPMAP_LEVELS; i++)
{
image[f][i] = 0;
image[f][i] = nullptr;
}
}
for(int f = 0; f < 6; f++)
{
mFaceProxies[f] = NULL;
mFaceProxies[f] = nullptr;
mFaceProxyRefs[f] = 0;
}
}
......@@ -976,7 +976,7 @@ TextureCubeMap::~TextureCubeMap()
if(image[f][i])
{
image[f][i]->unbind(this);
image[f][i] = 0;
image[f][i] = nullptr;
}
}
}
......@@ -985,14 +985,14 @@ TextureCubeMap::~TextureCubeMap()
for(int i = 0; i < 6; i++)
{
mFaceProxies[i] = NULL;
mFaceProxies[i] = nullptr;
}
}
// We need to maintain a count of references to renderbuffers acting as
// proxies for this texture, so that the texture is not deleted while
// proxy references still exist. If the reference count drops to zero,
// we set our proxy pointer NULL, so that a new attempt at referencing
// we set our proxy pointer null, so that a new attempt at referencing
// will cause recreation.
void TextureCubeMap::addProxyRef(const Renderbuffer *proxy)
{
......@@ -1018,7 +1018,7 @@ void TextureCubeMap::releaseProxy(const Renderbuffer *proxy)
if(mFaceProxyRefs[f] == 0)
{
mFaceProxies[f] = NULL;
mFaceProxies[f] = nullptr;
}
}
}
......@@ -1361,12 +1361,12 @@ Renderbuffer *TextureCubeMap::getRenderbuffer(GLenum target, GLint level, GLint
{
if(!IsCubemapTextureTarget(target))
{
return error(GL_INVALID_OPERATION, (Renderbuffer *)NULL);
return error(GL_INVALID_OPERATION, (Renderbuffer*)nullptr);
}
int face = CubeFaceIndex(target);
if(mFaceProxies[face] == NULL)
if(!mFaceProxies[face])
{
mFaceProxies[face] = new Renderbuffer(name, new RenderbufferTextureCubeMap(this, target, level));
}
......@@ -1408,12 +1408,12 @@ Texture3D::Texture3D(GLuint name) : Texture(name)
{
for(int i = 0; i < MIPMAP_LEVELS; i++)
{
image[i] = 0;
image[i] = nullptr;
}
mSurface = NULL;
mSurface = nullptr;
mColorbufferProxy = NULL;
mColorbufferProxy = nullptr;
mProxyRefs = 0;
}
......@@ -1426,7 +1426,7 @@ Texture3D::~Texture3D()
if(image[i])
{
image[i]->unbind(this);
image[i] = 0;
image[i] = nullptr;
}
}
......@@ -1434,11 +1434,11 @@ Texture3D::~Texture3D()
if(mSurface)
{
mSurface->setBoundTexture(NULL);
mSurface = NULL;
mSurface->setBoundTexture(nullptr);
mSurface = nullptr;
}
mColorbufferProxy = NULL;
mColorbufferProxy = nullptr;
}
// We need to maintain a count of references to renderbuffers acting as
......@@ -1458,7 +1458,7 @@ void Texture3D::releaseProxy(const Renderbuffer *proxy)
if(mProxyRefs == 0)
{
mColorbufferProxy = NULL;
mColorbufferProxy = nullptr;
}
}
......@@ -1555,7 +1555,7 @@ void Texture3D::bindTexImage(egl::Surface *surface)
if(image[level])
{
image[level]->unbind(this);
image[level] = 0;
image[level] = nullptr;
}
}
......@@ -1572,7 +1572,7 @@ void Texture3D::releaseTexImage()
if(image[level])
{
image[level]->unbind(this);
image[level] = 0;
image[level] = nullptr;
}
}
}
......@@ -1819,10 +1819,10 @@ Renderbuffer *Texture3D::getRenderbuffer(GLenum target, GLint level, GLint layer
{
if(target != getTarget())
{
return error(GL_INVALID_OPERATION, (Renderbuffer *)NULL);
return error(GL_INVALID_OPERATION, (Renderbuffer*)nullptr);
}
if(mColorbufferProxy == NULL)
if(!mColorbufferProxy)
{
mColorbufferProxy = new Renderbuffer(name, new RenderbufferTexture3D(this, level, layer));
}
......@@ -1935,10 +1935,10 @@ egl::Image *createBackBuffer(int width, int height, const egl::Config *config)
{
if(config)
{
return new egl::Image(width, height, config->mRenderTargetFormat, config->mSamples, false, true);
return new egl::Image(width, height, config->mRenderTargetFormat, config->mSamples, false);
}
return 0;
return nullptr;
}
egl::Image *createDepthStencil(unsigned int width, unsigned int height, sw::Format format, int multiSampleDepth, bool discard)
......@@ -1974,12 +1974,12 @@ egl::Image *createDepthStencil(unsigned int width, unsigned int height, sw::Form
UNREACHABLE(format);
}
egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable, true);
egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable);
if(!surface)
{
ERR("Out of memory");
return 0;
return nullptr;
}
return surface;
......
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