Chromium Code Reviews| Index: tests/ReadWriteAlphaTest.cpp |
| diff --git a/tests/ReadWriteAlphaTest.cpp b/tests/ReadWriteAlphaTest.cpp |
| index 0a8441797c2a4bfd657f2209294cd8082efbb4e2..5dbc5f1ec48ec99bba66a6ea31dccb013556a53c 100644 |
| --- a/tests/ReadWriteAlphaTest.cpp |
| +++ b/tests/ReadWriteAlphaTest.cpp |
| @@ -18,12 +18,11 @@ static const int X_SIZE = 13; |
| static const int Y_SIZE = 13; |
| DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, context) { |
| - unsigned char alphaData[X_SIZE][Y_SIZE]; |
| - |
| - memset(alphaData, 0, X_SIZE * Y_SIZE); |
| + unsigned char alphaData[X_SIZE * Y_SIZE]; |
| bool match; |
| - unsigned char readback[X_SIZE][Y_SIZE]; |
| + |
| + static const size_t kRowBytes[] = {0, X_SIZE, X_SIZE + 1, 2 * X_SIZE - 1}; |
| for (int rt = 0; rt < 2; ++rt) { |
| GrSurfaceDesc desc; |
| @@ -35,6 +34,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, context) { |
| desc.fHeight = Y_SIZE; |
| // We are initializing the texture with zeros here |
| + memset(alphaData, 0, X_SIZE * Y_SIZE); |
| SkAutoTUnref<GrTexture> texture( |
| context->textureProvider()->createTexture(desc, false, alphaData, 0)); |
| if (!texture) { |
| @@ -47,61 +47,68 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, context) { |
| // create a distinctive texture |
| for (int y = 0; y < Y_SIZE; ++y) { |
| for (int x = 0; x < X_SIZE; ++x) { |
| - alphaData[x][y] = y*X_SIZE+x; |
| + alphaData[y * X_SIZE + x] = y*X_SIZE+x; |
| } |
| } |
| - // upload the texture |
| - texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, |
| - alphaData, 0); |
| + for (auto rowBytes : kRowBytes) { |
| + // upload the texture (do per-rowbytes iteration because we may overwrite below). |
| + texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, |
| + alphaData, 0); |
| - // clear readback to something non-zero so we can detect readback failures |
| - memset(readback, 0x1, X_SIZE * Y_SIZE); |
| + size_t nonZeroRowBytes = rowBytes ? rowBytes : X_SIZE; |
| + SkAutoTDeleteArray<uint8_t> readback(new uint8_t[nonZeroRowBytes * Y_SIZE]); |
| + // clear readback to something non-zero so we can detect readback failures |
| + memset(readback.get(), 0x1, nonZeroRowBytes * Y_SIZE); |
| - // read the texture back |
| - texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, |
| - readback, 0); |
| + // read the texture back |
| + texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, |
| + readback.get(), rowBytes); |
| - // make sure the original & read back versions match |
| - match = true; |
| + // make sure the original & read back versions match |
| + match = true; |
|
robertphillips
2016/02/01 15:38:31
Can we have a subroutine for this that we also use
bsalomon
2016/02/01 20:18:10
Done.
|
| - for (int y = 0; y < Y_SIZE && match; ++y) { |
| - for (int x = 0; x < X_SIZE && match; ++x) { |
| - if (alphaData[x][y] != readback[x][y]) { |
| - SkDebugf("Failed alpha readback. Expected: 0x%02x, " |
| - "Got: 0x%02x at (%d,%d), rt: %d", alphaData[x][y], readback[x][y], x, |
| - y, rt); |
| - match = false; |
| + for (int y = 0; y < Y_SIZE && match; ++y) { |
| + for (int x = 0; x < X_SIZE && match; ++x) { |
| + uint8_t rbValue = readback.get()[y * nonZeroRowBytes + x]; |
| + if (alphaData[y * X_SIZE + x] != rbValue) { |
| + SkDebugf("Failed alpha readback. Expected: 0x%02x, " |
| + "Got: 0x%02x at (%d,%d), rt:%d, rb:%zd", alphaData[y * X_SIZE + x], |
| + rbValue, x, y, rt, rowBytes); |
| + match = false; |
| + } |
| } |
| } |
| - } |
| - // Now try writing on the single channel texture (if we could create as a RT). |
| - if (texture->asRenderTarget()) { |
| - SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
| - SkAutoTUnref<SkBaseDevice> device(SkGpuDevice::Create( |
| - texture->asRenderTarget(), &props, SkGpuDevice::kUninit_InitContents)); |
| - SkCanvas canvas(device); |
| + // Now try writing on the single channel texture (if we could create as a RT). |
| + if (texture->asRenderTarget()) { |
| + SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
| + SkAutoTUnref<SkBaseDevice> device(SkGpuDevice::Create( |
| + texture->asRenderTarget(), &props, SkGpuDevice::kUninit_InitContents)); |
| + SkCanvas canvas(device); |
| - SkPaint paint; |
| + SkPaint paint; |
| - const SkRect rect = SkRect::MakeLTRB(-10, -10, X_SIZE + 10, Y_SIZE + 10); |
| + const SkRect rect = SkRect::MakeLTRB(-10, -10, X_SIZE + 10, Y_SIZE + 10); |
| - paint.setColor(SK_ColorWHITE); |
| + paint.setColor(SK_ColorWHITE); |
| - canvas.drawRect(rect, paint); |
| + canvas.drawRect(rect, paint); |
| - texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, readback, 0); |
| + memset(readback.get(), 0x1, nonZeroRowBytes * Y_SIZE); |
| + texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, readback.get(), |
| + rowBytes); |
| - match = true; |
| - |
| - for (int y = 0; y < Y_SIZE && match; ++y) { |
| - for (int x = 0; x < X_SIZE && match; ++x) { |
| - if (0xFF != readback[x][y]) { |
| - ERRORF(reporter, |
| - "Failed alpha readback after clear. Expected: 0xFF, Got: 0x%02x at " |
| - "(%d,%d)", readback[x][y], x, y); |
| - match = false; |
| + match = true; |
| + for (int y = 0; y < Y_SIZE && match; ++y) { |
| + for (int x = 0; x < X_SIZE && match; ++x) { |
| + uint8_t rbValue = readback.get()[y * nonZeroRowBytes + x]; |
| + if (0xFF != rbValue) { |
| + ERRORF(reporter, |
| + "Failed alpha readback after clear. Expected: 0xFF, Got: 0x%02x" |
| + " at (%d,%d), rb:%zd", rbValue, x, y, rowBytes); |
| + match = false; |
| + } |
| } |
| } |
| } |
| @@ -114,6 +121,12 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, context) { |
| kSRGBA_8888_GrPixelConfig |
| }; |
| + for (int y = 0; y < Y_SIZE; ++y) { |
| + for (int x = 0; x < X_SIZE; ++x) { |
| + alphaData[y * X_SIZE + x] = y*X_SIZE+x; |
| + } |
| + } |
| + |
| // Attempt to read back just alpha from a RGBA/BGRA texture. Once with a texture-only src and |
| // once with a render target. |
| for (auto cfg : kRGBAConfigs) { |
| @@ -124,11 +137,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, context) { |
| desc.fWidth = X_SIZE; |
| desc.fHeight = Y_SIZE; |
| - uint32_t rgbaData[X_SIZE][Y_SIZE]; |
| + uint32_t rgbaData[X_SIZE * Y_SIZE]; |
| // Make the alpha channel of the rgba texture come from alphaData. |
| for (int y = 0; y < Y_SIZE; ++y) { |
| for (int x = 0; x < X_SIZE; ++x) { |
| - rgbaData[x][y] = GrColorPackRGBA(6, 7, 8, alphaData[x][y]); |
| + rgbaData[y * X_SIZE + x] = GrColorPackRGBA(6, 7, 8, alphaData[y * X_SIZE + x]); |
| } |
| } |
| SkAutoTUnref<GrTexture> texture( |
| @@ -141,25 +154,28 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, context) { |
| continue; |
| } |
| - // clear readback to something non-zero so we can detect readback failures |
| - memset(readback, 0x0, X_SIZE * Y_SIZE); |
| - |
| - // read the texture back |
| - texture->readPixels(0, 0, desc.fWidth, desc.fHeight, kAlpha_8_GrPixelConfig, readback, |
| - 0); |
| - |
| - match = true; |
| - |
| - for (int y = 0; y < Y_SIZE && match; ++y) { |
| - for (int x = 0; x < X_SIZE && match; ++x) { |
| - if (alphaData[x][y] != readback[x][y]) { |
| - texture->readPixels(0, 0, desc.fWidth, desc.fHeight, |
| - kAlpha_8_GrPixelConfig, readback, 0); |
| - ERRORF(reporter, |
| - "Failed alpha readback from cfg %d. Expected: 0x%02x, Got: 0x%02x at" |
| - " (%d,%d), rt:%d", desc.fConfig, alphaData[x][y], readback[x][y], x, |
| - y, rt); |
| - match = false; |
| + for (auto rowBytes : kRowBytes) { |
| + size_t nonZeroRowBytes = rowBytes ? rowBytes : X_SIZE; |
| + |
| + SkAutoTDeleteArray<uint8_t> readback(new uint8_t[nonZeroRowBytes * Y_SIZE]); |
| + // clear readback to something non-zero so we can detect readback failures |
|
robertphillips
2016/02/01 15:38:31
0x0 -> 0x1 ?
bsalomon
2016/02/01 20:18:10
Changed the comment, this doesn't need to be non-z
|
| + memset(readback.get(), 0x0, nonZeroRowBytes * Y_SIZE); |
| + |
| + // read the texture back |
| + texture->readPixels(0, 0, desc.fWidth, desc.fHeight, kAlpha_8_GrPixelConfig, |
| + readback.get(), rowBytes); |
| + |
|
robertphillips
2016/02/01 15:38:31
... here ?
|
| + match = true; |
| + for (int y = 0; y < Y_SIZE && match; ++y) { |
| + for (int x = 0; x < X_SIZE && match; ++x) { |
| + uint8_t rbValue = readback.get()[y * nonZeroRowBytes + x]; |
| + if (alphaData[y * X_SIZE + x] != rbValue) { |
| + ERRORF(reporter, |
| + "Failed alpha readback from cfg %d. Expected: 0x%02x, Got: " |
| + "0x%02x at (%d,%d), rt:%d, rb:%zd", desc.fConfig, |
| + alphaData[y * X_SIZE + x], rbValue, x, y, rt, rowBytes); |
| + match = false; |
| + } |
| } |
| } |
| } |