aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2015-12-15 12:37:38 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-12-15 12:37:38 -0800
commitf46a124ddd31ca4053c1719d720a74eb4a3cad6d (patch)
treeda38da2bedfd898286fd07817b1080c3bcc15a0f
parent66957946c0c418e71c0f36bb2904cc38c334eba4 (diff)
Set GL_PACK_ALIGNMENT before calling glReadPixels
-rw-r--r--include/gpu/GrTypes.h20
-rw-r--r--src/gpu/gl/GrGLGpu.cpp26
-rw-r--r--tests/ReadWriteAlphaTest.cpp5
3 files changed, 27 insertions, 24 deletions
diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h
index cf3773c89e..dbcb9a6583 100644
--- a/include/gpu/GrTypes.h
+++ b/include/gpu/GrTypes.h
@@ -363,26 +363,6 @@ static inline size_t GrBytesPerPixel(GrPixelConfig config) {
}
}
-static inline size_t GrUnpackAlignment(GrPixelConfig config) {
- SkASSERT(!GrPixelConfigIsCompressed(config));
- switch (config) {
- case kAlpha_8_GrPixelConfig:
- return 1;
- case kRGB_565_GrPixelConfig:
- case kRGBA_4444_GrPixelConfig:
- case kAlpha_half_GrPixelConfig:
- case kRGBA_half_GrPixelConfig:
- return 2;
- case kRGBA_8888_GrPixelConfig:
- case kBGRA_8888_GrPixelConfig:
- case kSRGBA_8888_GrPixelConfig:
- case kRGBA_float_GrPixelConfig:
- return 4;
- default:
- return 0;
- }
-}
-
static inline bool GrPixelConfigIsOpaque(GrPixelConfig config) {
switch (config) {
case kETC1_GrPixelConfig:
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 02d3b4ac27..17cbfb5945 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -648,6 +648,27 @@ bool GrGLGpu::onWritePixels(GrSurface* surface,
return false;
}
+// For GL_[UN]PACK_ALIGNMENT.
+static inline GrGLint config_alignment(GrPixelConfig config) {
+ SkASSERT(!GrPixelConfigIsCompressed(config));
+ switch (config) {
+ case kAlpha_8_GrPixelConfig:
+ return 1;
+ case kRGB_565_GrPixelConfig:
+ case kRGBA_4444_GrPixelConfig:
+ case kAlpha_half_GrPixelConfig:
+ case kRGBA_half_GrPixelConfig:
+ return 2;
+ case kRGBA_8888_GrPixelConfig:
+ case kBGRA_8888_GrPixelConfig:
+ case kSRGBA_8888_GrPixelConfig:
+ case kRGBA_float_GrPixelConfig:
+ return 4;
+ default:
+ return 0;
+ }
+}
+
static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc,
const GrGLInterface* interface) {
if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) {
@@ -790,8 +811,7 @@ bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc,
if (glFlipY) {
GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE));
}
- GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT,
- static_cast<GrGLint>(GrUnpackAlignment(dataConfig))));
+ GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, config_alignment(dataConfig)));
}
bool succeeded = true;
if (isNewTexture &&
@@ -2097,6 +2117,8 @@ bool GrGLGpu::onReadPixels(GrSurface* surface,
if (flipY && this->glCaps().packFlipYSupport()) {
GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 1));
}
+ GL_CALL(PixelStorei(GR_GL_PACK_ALIGNMENT, config_alignment(config)));
+
GL_CALL(ReadPixels(readRect.fLeft, readRect.fBottom,
readRect.fWidth, readRect.fHeight,
format, type, readDst));
diff --git a/tests/ReadWriteAlphaTest.cpp b/tests/ReadWriteAlphaTest.cpp
index a40f2c6457..1ee6b09a99 100644
--- a/tests/ReadWriteAlphaTest.cpp
+++ b/tests/ReadWriteAlphaTest.cpp
@@ -13,8 +13,9 @@
#include "GrContext.h"
#include "SkGpuDevice.h"
-static const int X_SIZE = 12;
-static const int Y_SIZE = 12;
+// This was made indivisible by 4 to ensure we test setting GL_PACK_ALIGNMENT properly.
+static const int X_SIZE = 13;
+static const int Y_SIZE = 13;
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, context) {
unsigned char textureData[X_SIZE][Y_SIZE];