Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1278)

Unified Diff: tests/ReadWriteAlphaTest.cpp

Issue 1576023002: Make readback of alpha channel work for RGBA. (Closed) Base URL: https://skia.googlesource.com/skia.git@swiz
Patch Set: more Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/glsl/GrGLSLCaps.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ReadWriteAlphaTest.cpp
diff --git a/tests/ReadWriteAlphaTest.cpp b/tests/ReadWriteAlphaTest.cpp
index 1ee6b09a995d29ce5514dd571a315ceec1332f9b..09c8cb66d85e452b423dfbf77236699277adc42c 100644
--- a/tests/ReadWriteAlphaTest.cpp
+++ b/tests/ReadWriteAlphaTest.cpp
@@ -18,9 +18,9 @@ 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];
+ unsigned char alphaData[X_SIZE][Y_SIZE];
- memset(textureData, 0, X_SIZE * Y_SIZE);
+ memset(alphaData, 0, X_SIZE * Y_SIZE);
GrSurfaceDesc desc;
@@ -32,23 +32,28 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, context) {
desc.fHeight = Y_SIZE;
// We are initializing the texture with zeros here
- GrTexture* texture = context->textureProvider()->createTexture(desc, false, textureData, 0);
+ SkAutoTUnref<GrTexture> texture(
+ context->textureProvider()->createTexture(desc, false, alphaData, 0));
if (!texture) {
- return;
+ // Try again as a non-RT;
+ desc.fFlags = kNone_GrSurfaceFlags;
+ texture.reset(context->textureProvider()->createTexture(desc, false, alphaData, 0));
+ if (!texture) {
+ ERRORF(reporter, "Could not create A8 texture.");
+ return;
+ }
}
-
- SkAutoTUnref<GrTexture> au(texture);
-
+
// create a distinctive texture
for (int y = 0; y < Y_SIZE; ++y) {
for (int x = 0; x < X_SIZE; ++x) {
- textureData[x][y] = x*Y_SIZE+y;
+ alphaData[x][y] = x*Y_SIZE+y;
}
}
// upload the texture
texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
- textureData, 0);
+ alphaData, 0);
unsigned char readback[X_SIZE][Y_SIZE];
@@ -62,44 +67,84 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, context) {
// make sure the original & read back versions match
bool match = true;
- for (int y = 0; y < Y_SIZE; ++y) {
- for (int x = 0; x < X_SIZE; ++x) {
- if (textureData[x][y] != readback[x][y]) {
+ 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]) {
+ ERRORF(reporter, "Failed alpha readback. Expected: 0x%02x, Got: 0x%02x at (%d,%d)",
+ alphaData[x][y], readback[x][y], x, y);
match = false;
}
}
}
- REPORTER_ASSERT(reporter, match);
+ // 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
- 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);
- texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
- readback, 0);
-
- match = true;
+ match = true;
- for (int y = 0; y < Y_SIZE; ++y) {
- for (int x = 0; x < X_SIZE; ++x) {
- if (0xFF != readback[x][y]) {
- match = false;
+ 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;
+ }
}
}
}
- REPORTER_ASSERT(reporter, match);
+ // Attempt to read back just alpha from a RGBA texture. Once with a texture-only src and
+ // once with a render target.
+ for (int i = 0; i < 2; ++i) {
+ desc.fFlags = i ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags;
+ desc.fConfig = kRGBA_8888_GrPixelConfig;
+ 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]);
+ }
+ }
+ texture.reset(context->textureProvider()->createTexture(desc, false, rgbaData, 0));
+ if (!texture) {
+ ERRORF(reporter, "Failed to create RGBA texture.");
+ return;
+ }
+
+ // 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]) {
+ ERRORF(reporter,
+ "Failed alpha readback from RGBA. Expected: 0x%02x, Got: 0x%02x at "
+ "(%d,%d)", alphaData[x][y], readback[x][y], x, y);
+ match = false;
+ }
+ }
+ }
+ }
}
#endif
« no previous file with comments | « src/gpu/glsl/GrGLSLCaps.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698