diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp index 1123d893dc..6b6778d1ac 100644 --- a/tests/ReadPixelsTest.cpp +++ b/tests/ReadPixelsTest.cpp @@ -15,7 +15,6 @@ #if SK_SUPPORT_GPU #include "GrContext.h" #include "SkGr.h" -#include "SkGrPriv.h" #endif #include @@ -460,171 +459,3 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, ctxInfo) { } } #endif -///////////////////// -#if SK_SUPPORT_GPU - -// make_ringed_bitmap was lifted from gm/bleed.cpp, as that GM was what showed the following -// bug when a change was made to SkImage_Raster.cpp. It is possible that other test bitmaps -// would also tickle https://bug.skia.org/4351 but this one is know to do it, so I've pasted the code -// here so we have a dependable repro case. - -// Create a black&white checked texture with 2 1-pixel rings -// around the outside edge. The inner ring is red and the outer ring is blue. -static void make_ringed_bitmap(SkBitmap* result, int width, int height) { - SkASSERT(0 == width % 2 && 0 == height % 2); - - static const SkPMColor kRed = SkPreMultiplyColor(SK_ColorRED); - static const SkPMColor kBlue = SkPreMultiplyColor(SK_ColorBLUE); - static const SkPMColor kBlack = SkPreMultiplyColor(SK_ColorBLACK); - static const SkPMColor kWhite = SkPreMultiplyColor(SK_ColorWHITE); - - result->allocN32Pixels(width, height, true); - - SkPMColor* scanline = result->getAddr32(0, 0); - for (int x = 0; x < width; ++x) { - scanline[x] = kBlue; - } - scanline = result->getAddr32(0, 1); - scanline[0] = kBlue; - for (int x = 1; x < width - 1; ++x) { - scanline[x] = kRed; - } - scanline[width-1] = kBlue; - - for (int y = 2; y < height/2; ++y) { - scanline = result->getAddr32(0, y); - scanline[0] = kBlue; - scanline[1] = kRed; - for (int x = 2; x < width/2; ++x) { - scanline[x] = kBlack; - } - for (int x = width/2; x < width-2; ++x) { - scanline[x] = kWhite; - } - scanline[width-2] = kRed; - scanline[width-1] = kBlue; - } - - for (int y = height/2; y < height-2; ++y) { - scanline = result->getAddr32(0, y); - scanline[0] = kBlue; - scanline[1] = kRed; - for (int x = 2; x < width/2; ++x) { - scanline[x] = kWhite; - } - for (int x = width/2; x < width-2; ++x) { - scanline[x] = kBlack; - } - scanline[width-2] = kRed; - scanline[width-1] = kBlue; - } - - scanline = result->getAddr32(0, height-2); - scanline[0] = kBlue; - for (int x = 1; x < width - 1; ++x) { - scanline[x] = kRed; - } - scanline[width-1] = kBlue; - - scanline = result->getAddr32(0, height-1); - for (int x = 0; x < width; ++x) { - scanline[x] = kBlue; - } - result->setImmutable(); -} - -static void compare_textures(skiatest::Reporter* reporter, GrTexture* txa, GrTexture* txb) { - REPORTER_ASSERT(reporter, txa->width() == 2); - REPORTER_ASSERT(reporter, txa->height() == 2); - REPORTER_ASSERT(reporter, txb->width() == 2); - REPORTER_ASSERT(reporter, txb->height() == 2); - REPORTER_ASSERT(reporter, txa->config() == txb->config()); - - SkPMColor pixelsA[4], pixelsB[4]; - REPORTER_ASSERT(reporter, txa->readPixels(0, 0, 2, 2, txa->config(), pixelsA)); - REPORTER_ASSERT(reporter, txb->readPixels(0, 0, 2, 2, txa->config(), pixelsB)); - REPORTER_ASSERT(reporter, 0 == memcmp(pixelsA, pixelsB, sizeof(pixelsA))); -} - -static SkData* draw_into_surface(SkSurface* surf, const SkBitmap& bm, SkFilterQuality quality) { - SkCanvas* canvas = surf->getCanvas(); - canvas->clear(SK_ColorBLUE); - - SkPaint paint; - paint.setFilterQuality(quality); - - canvas->translate(40, 100); - canvas->rotate(30); - canvas->scale(20, 30); - canvas->translate(-SkScalarHalf(bm.width()), -SkScalarHalf(bm.height())); - canvas->drawBitmap(bm, 0, 0, &paint); - - return surf->makeImageSnapshot()->encode(); -} - -#include "SkStream.h" -static void dump_to_file(const char name[], SkData* data) { - SkFILEWStream file(name); - file.write(data->data(), data->size()); -} - -/* - * Test two different ways to turn a subset of a bitmap into a texture - * - subset and then upload to a texture - * - upload to a texture and then subset - * - * These two techniques result in the same pixels (ala readPixels) - * but when we draw them (rotated+scaled) we don't always get the same results. - * - * https://bug.skia.org/4351 - */ -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Subset_Gpu, reporter, ctxInfo) { - SkBitmap bitmap; - make_ringed_bitmap(&bitmap, 6, 6); - const SkIRect subset = SkIRect::MakeLTRB(2, 2, 4, 4); - - // make two textures... - SkBitmap bm_subset, tx_subset; - - // ... one from a texture-subset - SkAutoTUnref fullTx(GrRefCachedBitmapTexture(ctxInfo.grContext(), bitmap, - GrTextureParams::ClampNoFilter(), - SkSourceGammaTreatment::kRespect)); - SkBitmap tx_full; - GrWrapTextureInBitmap(fullTx, bitmap.width(), bitmap.height(), true, &tx_full); - tx_full.extractSubset(&tx_subset, subset); - - // ... one from a bitmap-subset - SkBitmap tmp_subset; - bitmap.extractSubset(&tmp_subset, subset); - SkAutoTUnref subsetTx(GrRefCachedBitmapTexture(ctxInfo.grContext(), tmp_subset, - GrTextureParams::ClampNoFilter(), - SkSourceGammaTreatment::kRespect)); - GrWrapTextureInBitmap(subsetTx, tmp_subset.width(), tmp_subset.height(), true, &bm_subset); - - // did we get the same subset? - compare_textures(reporter, bm_subset.getTexture(), tx_subset.getTexture()); - - // do they draw the same? - const SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128); - auto surfA(SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kNo, info)); - auto surfB(SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kNo, info)); - - if (false) { - // - // BUG: depending on the driver, if we calls this with various quality settings, it - // may fail. - // - SkFilterQuality quality = kLow_SkFilterQuality; - - SkAutoTUnref dataA(draw_into_surface(surfA.get(), bm_subset, quality)); - SkAutoTUnref dataB(draw_into_surface(surfB.get(), tx_subset, quality)); - - REPORTER_ASSERT(reporter, dataA->equals(dataB)); - if (false) { - dump_to_file("test_image_A.png", dataA); - dump_to_file("test_image_B.png", dataB); - } - } -} -#endif