Add support for GL_CHROMIUM_flipy

Review URL: http://codereview.appspot.com/5413051/


git-svn-id: http://skia.googlecode.com/svn/trunk@2723 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2011-11-21 15:53:13 +00:00
parent 3d60812865
commit 8ef3fd0ca6
3 changed files with 41 additions and 7 deletions

View File

@ -174,6 +174,7 @@
#define GR_GL_COLOR_CLEAR_VALUE 0x0C22
#define GR_GL_COLOR_WRITEMASK 0x0C23
#define GR_GL_UNPACK_ALIGNMENT 0x0CF5
#define GR_GL_UNPACK_FLIP_Y 0x9240
#define GR_GL_PACK_ALIGNMENT 0x0D05
#define GR_GL_MAX_TEXTURE_SIZE 0x0D33
#define GR_GL_MAX_VIEWPORT_DIMS 0x0D3A

View File

@ -305,9 +305,11 @@ void GrGpuGL::initCaps() {
if (kDesktop_GrGLBinding == this->glBinding()) {
fGLCaps.fUnpackRowLengthSupport = true;
fGLCaps.fUnpackFlipYSupport = false;
fGLCaps.fPackRowLengthSupport = true;
} else {
fGLCaps.fUnpackRowLengthSupport = this->hasExtension("GL_EXT_unpack_subimage");
fGLCaps.fUnpackFlipYSupport = this->hasExtension("GL_CHROMIUM_flipy");
// no extension for pack row length
fGLCaps.fPackRowLengthSupport = false;
}
@ -528,6 +530,17 @@ void GrGpuGL::onResetContext() {
GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
fHWDrawState.fRenderTarget = NULL;
// we assume these values
if (this->glCaps().fUnpackRowLengthSupport) {
GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
}
if (this->glCaps().fPackRowLengthSupport) {
GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0));
}
if (this->glCaps().fUnpackFlipYSupport) {
GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE));
}
}
GrTexture* GrGpuGL::onCreatePlatformTexture(const GrPlatformTextureDesc& desc) {
@ -760,8 +773,17 @@ void GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc,
* GL_UNPACK_ROW_LENGTH.
*/
bool restoreGLRowLength = false;
bool flipY = GrGLTexture::kBottomUp_Orientation == desc.fOrientation;
if (this->glCaps().fUnpackRowLengthSupport && !flipY) {
bool swFlipY = false;
bool glFlipY = false;
if (GrGLTexture::kBottomUp_Orientation == desc.fOrientation) {
if (this->glCaps().fUnpackFlipYSupport) {
glFlipY = true;
} else {
swFlipY = true;
}
}
if (this->glCaps().fUnpackRowLengthSupport && !swFlipY) {
// can't use this for flipping, only non-neg values allowed. :(
if (rowBytes != trimRowBytes) {
GrGLint rowLength = static_cast<GrGLint>(rowBytes / bpp);
@ -769,17 +791,17 @@ void GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc,
restoreGLRowLength = true;
}
} else {
if (trimRowBytes != rowBytes || flipY) {
if (trimRowBytes != rowBytes || swFlipY) {
// copy the data into our new storage, skipping the trailing bytes
size_t trimSize = height * trimRowBytes;
const char* src = (const char*)data;
if (flipY) {
if (swFlipY) {
src += (height - 1) * rowBytes;
}
char* dst = (char*)tempStorage.reset(trimSize);
for (int y = 0; y < height; y++) {
memcpy(dst, src, trimRowBytes);
if (flipY) {
if (swFlipY) {
src -= rowBytes;
} else {
src += rowBytes;
@ -790,7 +812,9 @@ void GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc,
data = tempStorage.get();
}
}
if (glFlipY) {
GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE));
}
GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, static_cast<GrGLint>(bpp)));
if (0 == left && 0 == top &&
desc.fWidth == width && desc.fHeight == height) {
@ -798,7 +822,7 @@ void GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc,
desc.fWidth, desc.fHeight, 0,
externalFormat, externalType, data));
} else {
if (flipY) {
if (swFlipY || glFlipY) {
top = desc.fHeight - (top + height);
}
GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, 0, left, top, width, height,
@ -809,6 +833,9 @@ void GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc,
GrAssert(this->glCaps().fUnpackRowLengthSupport);
GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0));
}
if (glFlipY) {
GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE));
}
}
bool GrGpuGL::createRenderTargetObjects(int width, int height,
@ -2377,6 +2404,8 @@ void GrGpuGL::GLCaps::print() const {
(fTextureSwizzleSupport ? "YES": "NO"));
GrPrintf("Unpack Row length support: %s\n",
(fUnpackRowLengthSupport ? "YES": "NO"));
GrPrintf("Unpack Flip Y support: %s\n",
(fUnpackFlipYSupport ? "YES": "NO"));
GrPrintf("Pack Row length support: %s\n",
(fPackRowLengthSupport ? "YES": "NO"));
}

View File

@ -55,6 +55,7 @@ protected:
, fBGRAIsInternalFormat(false)
, fTextureSwizzleSupport(false)
, fUnpackRowLengthSupport(false)
, fUnpackFlipYSupport(false)
, fPackRowLengthSupport(false) {
memset(fAASamples, 0, sizeof(fAASamples));
}
@ -102,6 +103,9 @@ protected:
// Is there support for GL_UNPACK_ROW_LENGTH
bool fUnpackRowLengthSupport;
// Is there support for GL_UNPACK_FLIP_Y
bool fUnpackFlipYSupport;
// Is there support for GL_PACK_ROW_LENGTH
bool fPackRowLengthSupport;