| Index: tests/ReadWriteAlphaTest.cpp | 
| diff --git a/tests/ReadWriteAlphaTest.cpp b/tests/ReadWriteAlphaTest.cpp | 
| index 1ee6b09a995d29ce5514dd571a315ceec1332f9b..61bb7a0a4f5b049f30f2ef20cf6266107c2896b5 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,80 @@ 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 && 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; | 
| +                } | 
| +            } | 
| +        } | 
| +    } | 
|  | 
| +    // Attempt to read back just alpha from a RGBA texture | 
| +    desc.fFlags     = 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) { | 
| -            if (0xFF != readback[x][y]) { | 
| +            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; | 
| } | 
| } | 
| } | 
| - | 
| -    REPORTER_ASSERT(reporter, match); | 
| } | 
|  | 
| #endif | 
|  |