From 670ff9ae7f37356bff08b30a356bb0c52dc8d62e Mon Sep 17 00:00:00 2001 From: "robertphillips@google.com" Date: Thu, 12 Apr 2012 19:53:31 +0000 Subject: [PATCH] Fixed uninitialized memory issue on Linux when running "gm --debuggl" http://codereview.appspot.com/6012052/ git-svn-id: http://skia.googlecode.com/svn/trunk@3666 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/gpu/gl/debug/GrDebugGL.cpp | 4 +- src/gpu/gl/debug/GrDebugGL.h | 12 +++++ src/gpu/gl/debug/GrGLCreateDebugInterface.cpp | 78 ++++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/src/gpu/gl/debug/GrDebugGL.cpp b/src/gpu/gl/debug/GrDebugGL.cpp index 60971eb..c4cfe89 100644 --- a/src/gpu/gl/debug/GrDebugGL.cpp +++ b/src/gpu/gl/debug/GrDebugGL.cpp @@ -29,7 +29,9 @@ GrDebugGL::Create GrDebugGL::gFactoryFunc[kObjTypeCount] = { GrDebugGL::GrDebugGL() - : fCurTextureUnit(0) + : fPackRowLength(0) + , fUnPackRowLength(0) + , fCurTextureUnit(0) , fArrayBuffer(NULL) , fElementArrayBuffer(NULL) , fFrameBuffer(NULL) diff --git a/src/gpu/gl/debug/GrDebugGL.h b/src/gpu/gl/debug/GrDebugGL.h index d6af98e..4e714ee 100644 --- a/src/gpu/gl/debug/GrDebugGL.h +++ b/src/gpu/gl/debug/GrDebugGL.h @@ -73,6 +73,16 @@ public: void useProgram(GrProgramObj *program); + void setPackRowLength(GrGLint packRowLength) { + fPackRowLength = packRowLength; + } + GrGLint getPackRowLength() const { return fPackRowLength; } + + void setUnPackRowLength(GrGLint unPackRowLength) { + fUnPackRowLength = unPackRowLength; + } + GrGLint getUnPackRowLength() const { return fUnPackRowLength; } + static GrDebugGL *getInstance() { // static GrDebugGL Obj; @@ -87,6 +97,8 @@ private: // the OpenGLES 2.0 spec says this must be >= 2 static const GrGLint kDefaultMaxTextureUnits = 8; + GrGLint fPackRowLength; + GrGLint fUnPackRowLength; GrGLuint fMaxTextureUnits; GrGLuint fCurTextureUnit; GrBufferObj * fArrayBuffer; diff --git a/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp b/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp index a9adf7d..ff744c0 100644 --- a/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp +++ b/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp @@ -16,6 +16,7 @@ #include "GrTextureObj.h" #include "GrFrameBufferObj.h" #include "GrRenderBufferObj.h" +#include "SkFloatingPoint.h" // the OpenGLES 2.0 spec says this must be >= 128 static const GrGLint kDefaultMaxVertexUniformVectors = 128; @@ -119,10 +120,83 @@ GrGLvoid GR_GL_FUNCTION_TYPE debugGLFlush() {} GrGLvoid GR_GL_FUNCTION_TYPE debugGLFrontFace(GrGLenum mode) {} GrGLvoid GR_GL_FUNCTION_TYPE debugGLLineWidth(GrGLfloat width) {} GrGLvoid GR_GL_FUNCTION_TYPE debugGLLinkProgram(GrGLuint program) {} -GrGLvoid GR_GL_FUNCTION_TYPE debugGLPixelStorei(GrGLenum pname, GrGLint param) {} +GrGLvoid GR_GL_FUNCTION_TYPE debugGLPixelStorei(GrGLenum pname, GrGLint param) { + + switch (pname) { + case GR_GL_UNPACK_ROW_LENGTH: + GrDebugGL::getInstance()->setUnPackRowLength(param); + break; + case GR_GL_PACK_ROW_LENGTH: + GrDebugGL::getInstance()->setPackRowLength(param); + break; + case GR_GL_UNPACK_ALIGNMENT: + break; + case GR_GL_PACK_ALIGNMENT: + GrAlwaysAssert(false); + break; + default: + GrAlwaysAssert(false); + break; + } +} GrGLvoid GR_GL_FUNCTION_TYPE debugGLQueryCounter(GrGLuint id, GrGLenum target) {} GrGLvoid GR_GL_FUNCTION_TYPE debugGLReadBuffer(GrGLenum src) {} -GrGLvoid GR_GL_FUNCTION_TYPE debugGLReadPixels(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels) {} +GrGLvoid GR_GL_FUNCTION_TYPE debugGLReadPixels(GrGLint x, GrGLint y, + GrGLsizei width, GrGLsizei height, + GrGLenum format, GrGLenum type, + GrGLvoid* pixels) { + + GrGLint pixelsInRow = width; + if (0 < GrDebugGL::getInstance()->getPackRowLength()) { + pixelsInRow = GrDebugGL::getInstance()->getPackRowLength(); + } + + GrGLint componentsPerPixel = 0; + + switch (format) { + case GR_GL_RGBA: + // fallthrough + case GR_GL_BGRA: + componentsPerPixel = 4; + break; + case GR_GL_RGB: + componentsPerPixel = 3; + break; + default: + GrAlwaysAssert(false); + break; + } + + GrGLint alignment = 4; // the pack alignment (one of 1, 2, 4 or 8) + // Ganesh currently doesn't support setting GR_GL_PACK_ALIGNMENT + + GrGLint componentSize = 0; // size (in bytes) of a single component + + switch (type) { + case GR_GL_UNSIGNED_BYTE: + componentSize = 1; + break; + default: + GrAlwaysAssert(false); + break; + } + + GrGLint rowStride = 0; // number of components (not bytes) to skip + if (componentSize >= alignment) { + rowStride = componentsPerPixel * pixelsInRow; + } else { + float fTemp = + sk_float_ceil(componentSize * componentsPerPixel * pixelsInRow / + static_cast(alignment)); + rowStride = static_cast(alignment * fTemp / componentSize); + } + + GrGLchar *scanline = static_cast(pixels); + for (int y = 0; y < height; ++y) { + memset(scanline, 0, componentsPerPixel * componentSize * width); + scanline += rowStride; + } +} GrGLvoid GR_GL_FUNCTION_TYPE debugGLScissor(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height) {} GrGLvoid GR_GL_FUNCTION_TYPE debugGLShaderSource(GrGLuint shader, GrGLsizei count, const char** str, const GrGLint* length) {} GrGLvoid GR_GL_FUNCTION_TYPE debugGLStencilFunc(GrGLenum func, GrGLint ref, GrGLuint mask) {} -- 2.7.4