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;
......
......@@ -143,13 +143,13 @@ namespace es2
}
Device::~Device()
{
{
if(depthStencil)
{
depthStencil->release();
depthStencil = nullptr;
}
for(int i = 0; i < RENDERTARGETS; ++i)
{
if(renderTarget[i])
......@@ -219,7 +219,7 @@ namespace es2
int x0(0), y0(0), width(0), height(0);
getScissoredRegion(depthStencil, x0, y0, width, height);
depthStencil->clearDepthBuffer(z, x0, y0, width, height);
}
......@@ -241,9 +241,9 @@ namespace es2
if(height > OUTLINE_RESOLUTION)
{
ERR("Invalid parameters: %dx%d", width, height);
return 0;
return nullptr;
}
bool lockable = true;
switch(format)
......@@ -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,17 +285,17 @@ 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;
}
......@@ -405,7 +405,7 @@ namespace es2
vertexShaderConstantF[startRegister + i][2] = constantData[i * 4 + 2];
vertexShaderConstantF[startRegister + i][3] = constantData[i * 4 + 3];
}
vertexShaderConstantsFDirty = max(startRegister + count, vertexShaderConstantsFDirty);
vertexShaderDirty = true; // Reload DEF constants
}
......@@ -471,7 +471,7 @@ namespace es2
ERR("Invalid parameters");
return false;
}
int sWidth = source->getWidth();
int sHeight = source->getHeight();
int dWidth = dest->getWidth();
......@@ -732,7 +732,7 @@ namespace es2
{
Renderer::setVertexShaderConstantF(0, vertexShaderConstantF[0], vertexShaderConstantsFDirty);
}
Renderer::setVertexShader(vertexShader); // Loads shader constants set with DEF
vertexShaderConstantsFDirty = vertexShader->dirtyConstantsF; // Shader DEF'ed constants are dirty
}
......@@ -744,7 +744,7 @@ namespace es2
vertexShaderDirty = false;
}
}
bool Device::bindViewport()
{
if(viewport.width <= 0 || viewport.height <= 0)
......@@ -764,7 +764,7 @@ namespace es2
scissor.x1 = scissorRect.x1;
scissor.y0 = scissorRect.y0;
scissor.y1 = scissorRect.y1;
setScissor(scissor);
}
else
......@@ -774,7 +774,7 @@ namespace es2
scissor.x1 = viewport.x0 + viewport.width;
scissor.y0 = viewport.y0;
scissor.y1 = viewport.y0 + viewport.height;
for(int i = 0; i < RENDERTARGETS; ++i)
{
if(renderTarget[i])
......@@ -804,7 +804,7 @@ namespace es2
view.height = (float)viewport.height;
view.minZ = viewport.minZ;
view.maxZ = viewport.maxZ;
Renderer::setViewport(view);
return true;
......
......@@ -167,7 +167,7 @@ bool Texture::setMaxAnisotropy(float textureMaxAnisotropy)
{
return false;
}
if(mMaxAnisotropy != textureMaxAnisotropy)
{
mMaxAnisotropy = textureMaxAnisotropy;
......@@ -470,7 +470,7 @@ void Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLint zoffset, GL
bool Texture::copy(egl::Image *source, const sw::SliceRect &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, GLint zoffset, egl::Image *dest)
{
Device *device = getDevice();
sw::SliceRect destRect(xoffset, yoffset, xoffset + (sourceRect.x1 - sourceRect.x0), yoffset + (sourceRect.y1 - sourceRect.y0), zoffset);
bool success = device->stretchRect(source, &sourceRect, dest, &destRect, false);
......@@ -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,15 +530,15 @@ 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
// proxies for this texture, so that we do not attempt to use a pointer
// We need to maintain a count of references to renderbuffers acting as
// proxies for this texture, so that we do not attempt to use a pointer
// to a renderbuffer proxy which has been deleted.
void Texture2D::addProxyRef(const Renderbuffer *proxy)
{
......@@ -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;
}
}
}
......@@ -878,7 +878,7 @@ void Texture2D::generateMipmaps()
}
unsigned int q = log2(std::max(image[0]->getWidth(), image[0]->getHeight()));
for(unsigned int i = 1; i <= q; i++)
{
if(image[i])
......@@ -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
// 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;
}
}
}
......@@ -1270,7 +1270,7 @@ void TextureCubeMap::copyImage(GLenum target, GLint level, GLenum format, GLint
sw::SliceRect sourceRect(x, y, x + width, y + height, 0);
sourceRect.clip(0, 0, renderbuffer->getWidth(), renderbuffer->getHeight());
copy(renderTarget, sourceRect, sizedInternalFormat, 0, 0, 0, image[face][level]);
}
......@@ -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));
}
......@@ -1378,7 +1378,7 @@ egl::Image *TextureCubeMap::getRenderTarget(GLenum target, unsigned int level)
{
ASSERT(IsCubemapTextureTarget(target));
ASSERT(level < IMPLEMENTATION_MAX_TEXTURE_LEVELS);
int face = CubeFaceIndex(target);
if(image[face][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,15 +1434,15 @@ 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
// proxies for this texture, so that we do not attempt to use a pointer
// We need to maintain a count of references to renderbuffers acting as
// proxies for this texture, so that we do not attempt to use a pointer
// to a renderbuffer proxy which has been deleted.
void Texture3D::addProxyRef(const Renderbuffer *proxy)
{
......@@ -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)
......@@ -1948,7 +1948,7 @@ egl::Image *createDepthStencil(unsigned int width, unsigned int height, sw::Form
ERR("Invalid parameters: %dx%d", width, height);
return 0;
}
bool lockable = true;
switch(format)
......@@ -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