Commit 16ea3c87 by Nicolas Capens Committed by Nicolas Capens

Move common image implementations to EGL.

BUG=18110152 Change-Id: Ic3bf93d61682985e56b1b22c9fafd8c6e63cf442 Reviewed-on: https://swiftshader-review.googlesource.com/1253Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent ead7ac56
......@@ -14,31 +14,92 @@ typedef int GLsizei;
class Image : public sw::Surface
{
public:
Image(sw::Resource *texture, int width, int height, int depth, sw::Format format, bool lockable, bool renderTarget)
: sw::Surface(texture, width, height, depth, format, lockable, renderTarget)
Image(sw::Resource *resource, GLsizei width, GLsizei height, GLenum format, GLenum type, sw::Format internalFormat)
: width(width), height(height), format(format), type(type), internalFormat(internalFormat), multiSampleDepth(1)
, sw::Surface(resource, width, height, 1, internalFormat, true, true)
{
shared = false;
}
virtual void loadImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *input) = 0;
virtual void loadCompressedData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels) = 0;
Image(sw::Resource *resource, int width, int height, int depth, sw::Format internalFormat, bool lockable, bool renderTarget)
: width(width), height(height), format(0 /*GL_NONE*/), type(0 /*GL_NONE*/), internalFormat(internalFormat), multiSampleDepth(depth)
, sw::Surface(resource, width, height, depth, internalFormat, lockable, renderTarget)
{
shared = false;
}
GLsizei getWidth()
{
return width;
}
GLsizei getHeight()
{
return height;
}
GLenum Image::getFormat()
{
return format;
}
GLenum Image::getType()
{
return type;
}
sw::Format getInternalFormat()
{
return internalFormat;
}
virtual void *lock(unsigned int left, unsigned int top, sw::Lock lock) = 0;
virtual unsigned int getPitch() const = 0;
virtual void unlock() = 0;
int getMultiSampleDepth()
{
return multiSampleDepth;
}
virtual int getWidth() = 0;
virtual int getHeight() = 0;
virtual GLenum getFormat() = 0;
virtual GLenum getType() = 0;
virtual sw::Format getInternalFormat() = 0;
virtual int getMultiSampleDepth() = 0;
bool Image::isShared() const
{
return shared;
}
void Image::markShared()
{
shared = true;
}
void *Image::lock(unsigned int left, unsigned int top, sw::Lock lock)
{
return lockExternal(left, top, 0, lock, sw::PUBLIC);
}
unsigned int Image::getPitch() const
{
return getExternalPitchB();
}
void Image::unlock()
{
unlockExternal();
}
virtual void addRef() = 0;
virtual void release() = 0;
virtual void unbind() = 0; // Break parent ownership and release
virtual bool isShared() const = 0;
virtual void markShared() = 0;
virtual void loadImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *input) = 0;
virtual void loadCompressedData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels) = 0;
protected:
const GLsizei width;
const GLsizei height;
const GLenum format;
const GLenum type;
const sw::Format internalFormat;
const int multiSampleDepth;
private:
bool shared; // Used as an EGLImage
};
}
......
......@@ -243,7 +243,7 @@ namespace gl
UNREACHABLE();
}
Image *surface = new Image(0, width, height, format, GL_NONE_OES, GL_NONE_OES, multiSampleDepth, lockable, true);
Image *surface = new Image(0, width, height, format, multiSampleDepth, lockable, true);
if(!surface)
{
......@@ -262,7 +262,7 @@ namespace gl
return 0;
}
Image *surface = new Image(0, width, height, format, GL_NONE_OES, GL_NONE_OES, multiSampleDepth, lockable, true);
Image *surface = new Image(0, width, height, format, multiSampleDepth, lockable, true);
if(!surface)
{
......
......@@ -32,19 +32,16 @@ namespace gl
}
Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type)
: parentTexture(parentTexture), width(width), height(height), format(format), type(type)
, internalFormat(selectInternalFormat(format, type)), multiSampleDepth(1)
, egl::Image(getParentResource(parentTexture), width, height, 1, selectInternalFormat(format, type), true, true)
: parentTexture(parentTexture)
, egl::Image(getParentResource(parentTexture), width, height, format, type, selectInternalFormat(format, type))
{
shared = false;
referenceCount = 1;
}
Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, GLenum format, GLenum type, int multiSampleDepth, bool lockable, bool renderTarget)
: parentTexture(parentTexture), width(width), height(height), internalFormat(internalFormat), format(format), type(type), multiSampleDepth(multiSampleDepth)
Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable, bool renderTarget)
: parentTexture(parentTexture)
, egl::Image(getParentResource(parentTexture), width, height, multiSampleDepth, internalFormat, lockable, renderTarget)
{
shared = false;
referenceCount = 1;
}
......@@ -53,51 +50,6 @@ namespace gl
ASSERT(referenceCount == 0);
}
void *Image::lock(unsigned int left, unsigned int top, sw::Lock lock)
{
return lockExternal(left, top, 0, lock, sw::PUBLIC);
}
unsigned int Image::getPitch() const
{
return getExternalPitchB();
}
void Image::unlock()
{
unlockExternal();
}
int Image::getWidth()
{
return width;
}
int Image::getHeight()
{
return height;
}
GLenum Image::getFormat()
{
return format;
}
GLenum Image::getType()
{
return type;
}
sw::Format Image::getInternalFormat()
{
return internalFormat;
}
int Image::getMultiSampleDepth()
{
return multiSampleDepth;
}
void Image::addRef()
{
if(parentTexture)
......@@ -133,16 +85,6 @@ namespace gl
release();
}
bool Image::isShared() const
{
return shared;
}
void Image::markShared()
{
shared = true;
}
sw::Format Image::selectInternalFormat(GLenum format, GLenum type)
{
#if S3TC_SUPPORT
......@@ -206,11 +148,6 @@ namespace gl
return sw::FORMAT_A8R8G8B8;
}
int Image::bytes(sw::Format format)
{
return sw::Surface::bytes(format);
}
void Image::loadImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *input)
{
GLsizei inputPitch = ComputePitch(width, format, type, unpackAlignment);
......@@ -337,23 +274,6 @@ namespace gl
}
}
void Image::loadAlphaHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
{
for(int y = 0; y < height; y++)
{
const unsigned short *source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
unsigned short *dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 8);
for(int x = 0; x < width; x++)
{
dest[4 * x + 0] = 0;
dest[4 * x + 1] = 0;
dest[4 * x + 2] = 0;
dest[4 * x + 3] = source[x];
}
}
}
void Image::loadLuminanceImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
{
for(int y = 0; y < height; y++)
......@@ -382,23 +302,6 @@ namespace gl
}
}
void Image::loadLuminanceHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
{
for(int y = 0; y < height; y++)
{
const unsigned short *source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
unsigned short *dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 8);
for(int x = 0; x < width; x++)
{
dest[4 * x + 0] = source[x];
dest[4 * x + 1] = source[x];
dest[4 * x + 2] = source[x];
dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
}
}
}
void Image::loadLuminanceAlphaImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
{
for(int y = 0; y < height; y++)
......@@ -427,23 +330,6 @@ namespace gl
}
}
void Image::loadLuminanceAlphaHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
{
for(int y = 0; y < height; y++)
{
const unsigned short *source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
unsigned short *dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 8);
for(int x = 0; x < width; x++)
{
dest[4 * x + 0] = source[2*x+0];
dest[4 * x + 1] = source[2*x+0];
dest[4 * x + 2] = source[2*x+0];
dest[4 * x + 3] = source[2*x+1];
}
}
}
void Image::loadRGBUByteImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
{
for(int y = 0; y < height; y++)
......@@ -496,23 +382,6 @@ namespace gl
}
}
void Image::loadRGBHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
{
for(int y = 0; y < height; y++)
{
const unsigned short *source = reinterpret_cast<const unsigned short*>(static_cast<const unsigned char*>(input) + y * inputPitch);
unsigned short *dest = reinterpret_cast<unsigned short*>(static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 8);
for(int x = 0; x < width; x++)
{
dest[4 * x + 0] = source[x * 3 + 0];
dest[4 * x + 1] = source[x * 3 + 1];
dest[4 * x + 2] = source[x * 3 + 2];
dest[4 * x + 3] = 0x3C00; // SEEEEEMMMMMMMMMM, S = 0, E = 15, M = 0: 16bit flpt representation of 1
}
}
}
void Image::loadRGBAUByteImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
{
for(int y = 0; y < height; y++)
......@@ -575,17 +444,6 @@ namespace gl
}
}
void Image::loadRGBAHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
{
for(int y = 0; y < height; y++)
{
const unsigned char *source = static_cast<const unsigned char*>(input) + y * inputPitch;
unsigned char *dest = static_cast<unsigned char*>(buffer) + (y + yoffset) * getPitch() + xoffset * 8;
memcpy(dest, source, width * 8);
}
}
void Image::loadBGRAImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const
{
for(int y = 0; y < height; y++)
......
......@@ -26,67 +26,39 @@ namespace gl
{
public:
Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type);
Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, GLenum format, GLenum type, int multiSampleDepth, bool lockable, bool renderTarget);
Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable, bool renderTarget);
void loadImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *input);
void loadCompressedData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
void *lock(unsigned int left, unsigned int top, sw::Lock lock);
unsigned int getPitch() const;
void unlock();
int getWidth();
int getHeight();
GLenum getFormat();
GLenum getType();
virtual sw::Format getInternalFormat();
virtual int getMultiSampleDepth();
virtual void addRef();
virtual void release();
void unbind(); // Break parent ownership and release
virtual bool isShared() const;
void markShared();
static sw::Format selectInternalFormat(GLenum format, GLenum type);
static int bytes(sw::Format format);
private:
virtual ~Image();
void loadAlphaImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadAlphaFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadAlphaHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceAlphaImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceAlphaFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadLuminanceAlphaHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBUByteImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGB565ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBAUByteImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBA4444ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBA5551ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBAFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadRGBAHalfFloatImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadBGRAImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadD16ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadD32ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer) const;
void loadD24S8ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer);
Texture *parentTexture;
bool shared; // Used as an EGLImage
const GLsizei width;
const GLsizei height;
const GLenum format;
const GLenum type;
const sw::Format internalFormat;
const int multiSampleDepth;
volatile int referenceCount;
};
......
......@@ -766,7 +766,7 @@ extern "C"
UNREACHABLE();
}
gl::Image *surface = new gl::Image(0, width, height, format, GL_NONE_OES, GL_NONE_OES, multiSampleDepth, lockable, true);
gl::Image *surface = new gl::Image(0, width, height, format, multiSampleDepth, lockable, true);
if(!surface)
{
......
......@@ -265,7 +265,7 @@ namespace gl
UNREACHABLE();
}
Image *surface = new Image(0, width, height, format, GL_NONE, GL_NONE, multiSampleDepth, lockable, true);
Image *surface = new Image(0, width, height, format, multiSampleDepth, lockable, true);
if(!surface)
{
......@@ -284,7 +284,7 @@ namespace gl
return 0;
}
Image *surface = new Image(0, width, height, format, GL_NONE, GL_NONE, multiSampleDepth, lockable, true);
Image *surface = new Image(0, width, height, format, multiSampleDepth, lockable, true);
if(!surface)
{
......
......@@ -31,19 +31,16 @@ namespace gl
}
Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type)
: parentTexture(parentTexture), width(width), height(height), format(format), type(type)
, internalFormat(selectInternalFormat(format, type)), multiSampleDepth(1)
, egl::Image(getParentResource(parentTexture), width, height, 1, selectInternalFormat(format, type), true, true)
: parentTexture(parentTexture)
, egl::Image(getParentResource(parentTexture), width, height, format, type, selectInternalFormat(format, type))
{
shared = false;
referenceCount = 1;
}
Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, GLenum format, GLenum type, int multiSampleDepth, bool lockable, bool renderTarget)
: parentTexture(parentTexture), width(width), height(height), internalFormat(internalFormat), format(format), type(type), multiSampleDepth(multiSampleDepth)
Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable, bool renderTarget)
: parentTexture(parentTexture)
, egl::Image(getParentResource(parentTexture), width, height, multiSampleDepth, internalFormat, lockable, renderTarget)
{
shared = false;
referenceCount = 1;
}
......@@ -52,51 +49,6 @@ namespace gl
ASSERT(referenceCount == 0);
}
void *Image::lock(unsigned int left, unsigned int top, sw::Lock lock)
{
return lockExternal(left, top, 0, lock, sw::PUBLIC);
}
unsigned int Image::getPitch() const
{
return getExternalPitchB();
}
void Image::unlock()
{
unlockExternal();
}
int Image::getWidth()
{
return width;
}
int Image::getHeight()
{
return height;
}
GLenum Image::getFormat()
{
return format;
}
GLenum Image::getType()
{
return type;
}
sw::Format Image::getInternalFormat()
{
return internalFormat;
}
int Image::getMultiSampleDepth()
{
return multiSampleDepth;
}
void Image::addRef()
{
if(parentTexture)
......@@ -132,16 +84,6 @@ namespace gl
release();
}
bool Image::isShared() const
{
return shared;
}
void Image::markShared()
{
shared = true;
}
sw::Format Image::selectInternalFormat(GLenum format, GLenum type)
{
#if S3TC_SUPPORT
......@@ -225,11 +167,6 @@ namespace gl
return sw::FORMAT_A8R8G8B8;
}
int Image::bytes(sw::Format format)
{
return sw::Surface::bytes(format);
}
void Image::loadImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *input)
{
GLsizei inputPitch = ComputePitch(width, format, type, unpackAlignment);
......
......@@ -26,31 +26,16 @@ namespace gl
{
public:
Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type);
Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, GLenum format, GLenum type, int multiSampleDepth, bool lockable, bool renderTarget);
Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable, bool renderTarget);
void loadImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *input);
void loadCompressedData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
void *lock(unsigned int left, unsigned int top, sw::Lock lock);
unsigned int getPitch() const;
void unlock();
int getWidth();
int getHeight();
GLenum getFormat();
GLenum getType();
virtual sw::Format getInternalFormat();
virtual int getMultiSampleDepth();
virtual void addRef();
virtual void release();
void unbind(); // Break parent ownership and release
virtual bool isShared() const;
void markShared();
static sw::Format selectInternalFormat(GLenum format, GLenum type);
static int bytes(sw::Format format);
private:
virtual ~Image();
......@@ -79,14 +64,6 @@ namespace gl
void loadD24S8ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, int inputPitch, const void *input, void *buffer);
Texture *parentTexture;
bool shared; // Used as an EGLImage
const GLsizei width;
const GLsizei height;
const GLenum format;
const GLenum type;
const sw::Format internalFormat;
const int multiSampleDepth;
volatile int referenceCount;
};
......
......@@ -1199,7 +1199,7 @@ extern "C"
UNREACHABLE();
}
gl::Image *surface = new gl::Image(0, width, height, format, GL_NONE, GL_NONE, multiSampleDepth, lockable, true);
gl::Image *surface = new gl::Image(0, width, height, format, multiSampleDepth, lockable, true);
if(!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