don't rely on canvas->readPixels
Bug: skia:3216 Change-Id: I01a8d0083c79c0fe71fbc4d8cfdde4fa6e48b636 Reviewed-on: https://skia-review.googlesource.com/25741 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
ce98801bbb
commit
f19421961c
@ -129,7 +129,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ApplyGamma, reporter, ctxInfo) {
|
||||
dstCanvas->flush();
|
||||
|
||||
sk_memset32(read.get(), 0, kW * kH);
|
||||
if (!dstCanvas->readPixels(ii, read.get(), kRowBytes, 0, 0)) {
|
||||
if (!dst->readPixels(ii, read.get(), kRowBytes, 0, 0)) {
|
||||
ERRORF(reporter, "Error calling readPixels");
|
||||
continue;
|
||||
}
|
||||
|
@ -236,12 +236,14 @@ static void blur_path(SkCanvas* canvas, const SkPath& path,
|
||||
}
|
||||
|
||||
// Readback the blurred draw results from the canvas
|
||||
static void readback(SkCanvas* canvas, int* result, int resultCount) {
|
||||
static void readback(const SkBitmap& src, int* result, int resultCount) {
|
||||
SkBitmap readback;
|
||||
readback.allocN32Pixels(resultCount, 30);
|
||||
canvas->readPixels(readback, 0, 0);
|
||||
SkPixmap pm;
|
||||
readback.peekPixels(&pm);
|
||||
src.readPixels(pm, 0, 0);
|
||||
|
||||
SkPMColor* pixels = (SkPMColor*) readback.getAddr32(0, 15);
|
||||
const SkPMColor* pixels = pm.addr32(0, 15);
|
||||
|
||||
for (int i = 0; i < resultCount; ++i) {
|
||||
result[i] = SkColorGetR(pixels[i]);
|
||||
@ -258,33 +260,9 @@ static void cpu_blur_path(const SkPath& path, SkScalar gaussianSigma,
|
||||
SkCanvas canvas(bitmap);
|
||||
|
||||
blur_path(&canvas, path, gaussianSigma);
|
||||
readback(&canvas, result, resultCount);
|
||||
readback(bitmap, result, resultCount);
|
||||
}
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#if 0
|
||||
// temporary disable; see below for explanation
|
||||
static bool gpu_blur_path(GrContext* context, const SkPath& path,
|
||||
SkScalar gaussianSigma,
|
||||
int* result, int resultCount) {
|
||||
GrSurfaceDesc desc;
|
||||
desc.fConfig = kSkia8888_GrPixelConfig;
|
||||
desc.fFlags = kRenderTarget_GrSurfaceFlag;
|
||||
desc.fWidth = resultCount;
|
||||
desc.fHeight = 30;
|
||||
desc.fSampleCnt = 0;
|
||||
|
||||
sk_sp<GrTexture> texture(grContext->createTexture(desc, false, nullptr, 0));
|
||||
sk_sp<SkGpuDevice> device(new SkGpuDevice(grContext, texture.get()));
|
||||
SkCanvas canvas(device.get());
|
||||
|
||||
blur_path(&canvas, path, gaussianSigma);
|
||||
readback(&canvas, result, resultCount);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if WRITE_CSV
|
||||
static void write_as_csv(const char* label, SkScalar scale, int* data, int count) {
|
||||
SkDebugf("%s_%.2f,", label, scale);
|
||||
@ -343,18 +321,6 @@ DEF_TEST(BlurSigmaRange, reporter) {
|
||||
|
||||
REPORTER_ASSERT(reporter, match(rectSpecialCaseResult, bruteForce1DResult, kSize, 5));
|
||||
REPORTER_ASSERT(reporter, match(generalCaseResult, bruteForce1DResult, kSize, 15));
|
||||
#if SK_SUPPORT_GPU
|
||||
#if 0
|
||||
int gpuResult[kSize];
|
||||
bool haveGPUResult = gpu_blur_path(context, rectPath, sigma, gpuResult, kSize);
|
||||
// Disabling this test for now -- I don't think it's a legit comparison.
|
||||
// Will continue to investigate this.
|
||||
if (haveGPUResult) {
|
||||
// 1 works everywhere but: Ubuntu13 & Nexus4
|
||||
REPORTER_ASSERT(reporter, match(gpuResult, bruteForce1DResult, kSize, 10));
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
REPORTER_ASSERT(reporter, match(groundTruthResult, bruteForce1DResult, kSize, 1));
|
||||
|
||||
#if WRITE_CSV
|
||||
|
@ -26,7 +26,7 @@ static void test_big_aa_rect(skiatest::Reporter* reporter) {
|
||||
int y = SkScalarRoundToInt(r.top());
|
||||
|
||||
// check that the pixel in question starts as transparent (by the surface)
|
||||
if (canvas->readPixels(output, x, y)) {
|
||||
if (surf->readPixels(output, x, y)) {
|
||||
REPORTER_ASSERT(reporter, 0 == pixel[0]);
|
||||
} else {
|
||||
REPORTER_ASSERT_MESSAGE(reporter, false, "readPixels failed");
|
||||
@ -39,7 +39,7 @@ static void test_big_aa_rect(skiatest::Reporter* reporter) {
|
||||
canvas->drawRect(r, paint);
|
||||
|
||||
// Now check that it is BLACK
|
||||
if (canvas->readPixels(output, x, y)) {
|
||||
if (surf->readPixels(output, x, y)) {
|
||||
// don't know what swizzling PMColor did, but white should always
|
||||
// appear the same.
|
||||
REPORTER_ASSERT(reporter, 0xFFFFFFFF == pixel[0]);
|
||||
|
@ -1413,7 +1413,8 @@ DEF_TEST(ImageFilterMatrixConvolutionSanityTest, reporter) {
|
||||
REPORTER_ASSERT(reporter, nullptr == conv.get());
|
||||
}
|
||||
|
||||
static void test_xfermode_cropped_input(SkCanvas* canvas, skiatest::Reporter* reporter) {
|
||||
static void test_xfermode_cropped_input(SkSurface* surf, skiatest::Reporter* reporter) {
|
||||
auto canvas = surf->getCanvas();
|
||||
canvas->clear(0);
|
||||
|
||||
SkBitmap bitmap;
|
||||
@ -1442,17 +1443,17 @@ static void test_xfermode_cropped_input(SkCanvas* canvas, skiatest::Reporter* re
|
||||
|
||||
uint32_t pixel;
|
||||
SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul_SkAlphaType);
|
||||
canvas->readPixels(info, &pixel, 4, 0, 0);
|
||||
surf->readPixels(info, &pixel, 4, 0, 0);
|
||||
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
|
||||
|
||||
paint.setImageFilter(std::move(xfermodeNoBg));
|
||||
canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite
|
||||
canvas->readPixels(info, &pixel, 4, 0, 0);
|
||||
surf->readPixels(info, &pixel, 4, 0, 0);
|
||||
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
|
||||
|
||||
paint.setImageFilter(std::move(xfermodeNoFgNoBg));
|
||||
canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite
|
||||
canvas->readPixels(info, &pixel, 4, 0, 0);
|
||||
surf->readPixels(info, &pixel, 4, 0, 0);
|
||||
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
|
||||
}
|
||||
|
||||
@ -1491,26 +1492,23 @@ DEF_TEST(ImageFilterNestedSaveLayer, reporter) {
|
||||
|
||||
SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul_SkAlphaType);
|
||||
uint32_t pixel;
|
||||
canvas.readPixels(info, &pixel, 4, 25, 25);
|
||||
temp.readPixels(info, &pixel, 4, 25, 25);
|
||||
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
|
||||
|
||||
// Test that drawSprite() with a filter nested inside a saveLayer() applies the
|
||||
// correct offset to the filter matrix.
|
||||
canvas.clear(0x0);
|
||||
canvas.readPixels(info, &pixel, 4, 25, 25);
|
||||
temp.readPixels(info, &pixel, 4, 25, 25);
|
||||
canvas.saveLayer(&bounds1, nullptr);
|
||||
canvas.drawBitmap(bitmap, 20, 20, &filterPaint); // drawSprite
|
||||
canvas.restore();
|
||||
|
||||
canvas.readPixels(info, &pixel, 4, 25, 25);
|
||||
temp.readPixels(info, &pixel, 4, 25, 25);
|
||||
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
|
||||
}
|
||||
|
||||
DEF_TEST(XfermodeImageFilterCroppedInput, reporter) {
|
||||
SkBitmap temp;
|
||||
temp.allocN32Pixels(100, 100);
|
||||
SkCanvas canvas(temp);
|
||||
test_xfermode_cropped_input(&canvas, reporter);
|
||||
test_xfermode_cropped_input(SkSurface::MakeRasterN32Premul(100, 100).get(), reporter);
|
||||
}
|
||||
|
||||
static void test_composed_imagefilter_offset(skiatest::Reporter* reporter, GrContext* context) {
|
||||
@ -1834,9 +1832,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(XfermodeImageFilterCroppedInput_Gpu, reporter
|
||||
SkBudgeted::kNo,
|
||||
SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kPremul_SkAlphaType)));
|
||||
|
||||
SkCanvas* canvas = surf->getCanvas();
|
||||
|
||||
test_xfermode_cropped_input(canvas, reporter);
|
||||
test_xfermode_cropped_input(surf.get(), reporter);
|
||||
}
|
||||
|
||||
DEF_GPUTEST_FOR_ALL_CONTEXTS(ImageFilterBlurLargeImage_Gpu, reporter, ctxInfo) {
|
||||
|
@ -56,12 +56,12 @@ static void run_shader_test(skiatest::Reporter* reporter, SkSurface* sourceSurfa
|
||||
|
||||
SkBitmap bmOrig;
|
||||
bmOrig.allocN32Pixels(info.width(), info.height());
|
||||
sourceSurface->getCanvas()->readPixels(bmOrig, 0, 0);
|
||||
sourceSurface->readPixels(bmOrig, 0, 0);
|
||||
|
||||
|
||||
SkBitmap bm;
|
||||
bm.allocN32Pixels(info.width(), info.height());
|
||||
destinationCanvas->readPixels(bm, 0, 0);
|
||||
destinationSurface->readPixels(bm, 0, 0);
|
||||
|
||||
test_bitmap_equality(reporter, bmOrig, bm);
|
||||
|
||||
@ -83,7 +83,7 @@ static void run_shader_test(skiatest::Reporter* reporter, SkSurface* sourceSurfa
|
||||
|
||||
SkBitmap bmt;
|
||||
bmt.allocN32Pixels(info.width(), info.height());
|
||||
destinationCanvas->readPixels(bmt, 0, 0);
|
||||
destinationSurface->readPixels(bmt, 0, 0);
|
||||
|
||||
// Test correctness
|
||||
{
|
||||
|
@ -76,10 +76,10 @@ static void test_premul_alpha_roundtrip(skiatest::Reporter* reporter, SkSurface*
|
||||
readBmp1.eraseColor(0);
|
||||
readBmp2.eraseColor(0);
|
||||
|
||||
canvas->readPixels(readBmp1, 0, 0);
|
||||
surf->readPixels(readBmp1, 0, 0);
|
||||
sk_tool_utils::write_pixels(canvas, readBmp1, 0, 0, gUnpremul[upmaIdx].fColorType,
|
||||
kUnpremul_SkAlphaType);
|
||||
canvas->readPixels(readBmp2, 0, 0);
|
||||
surf->readPixels(readBmp2, 0, 0);
|
||||
|
||||
bool success = true;
|
||||
for (int y = 0; y < 256 && success; ++y) {
|
||||
|
@ -359,7 +359,7 @@ static void test_readpixels(skiatest::Reporter* reporter, const sk_sp<SkSurface>
|
||||
fill_dst_bmp_with_init_data(&bmp);
|
||||
}
|
||||
uint32_t idBefore = surface->generationID();
|
||||
bool success = canvas->readPixels(bmp, srcRect.fLeft, srcRect.fTop);
|
||||
bool success = surface->readPixels(bmp, srcRect.fLeft, srcRect.fTop);
|
||||
uint32_t idAfter = surface->generationID();
|
||||
|
||||
// we expect to succeed when the read isn't fully clipped
|
||||
|
@ -67,7 +67,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheCache, reporter, ctxInfo) {
|
||||
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
canvas->drawBitmap(src, 0, 0);
|
||||
canvas->readPixels(readback, 0, 0);
|
||||
surface->readPixels(readback, 0, 0);
|
||||
|
||||
// "modify" the src texture
|
||||
src.notifyPixelsChanged();
|
||||
|
@ -37,11 +37,11 @@ DEF_TEST(SkImageFromBitmap_extractSubset, reporter) {
|
||||
|
||||
uint32_t pixel = 0;
|
||||
SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul_SkAlphaType);
|
||||
canvas.readPixels(info, &pixel, 4, 0, 0);
|
||||
tgt.readPixels(info, &pixel, 4, 0, 0);
|
||||
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
|
||||
canvas.readPixels(info, &pixel, 4, gWidth - 6, gWidth - 6);
|
||||
tgt.readPixels(info, &pixel, 4, gWidth - 6, gWidth - 6);
|
||||
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
|
||||
|
||||
canvas.readPixels(info, &pixel, 4, gWidth - 5, gWidth - 5);
|
||||
tgt.readPixels(info, &pixel, 4, gWidth - 5, gWidth - 5);
|
||||
REPORTER_ASSERT(reporter, pixel == SK_ColorTRANSPARENT);
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ void draw_child(skiatest::Reporter* reporter,
|
||||
// read pixels
|
||||
SkBitmap bitmap;
|
||||
bitmap.allocPixels(childII);
|
||||
childCanvas->readPixels(bitmap, 0, 0);
|
||||
childSurface->readPixels(bitmap, 0, 0);
|
||||
|
||||
check_pixels(reporter, bitmap);
|
||||
}
|
||||
|
@ -184,9 +184,8 @@ static bool check_pixel(SkPMColor a, SkPMColor b, bool didPremulConversion) {
|
||||
SkAbs32(aB - bB) <= 1;
|
||||
}
|
||||
|
||||
static bool check_write(skiatest::Reporter* reporter, SkCanvas* canvas, const SkBitmap& bitmap,
|
||||
static bool check_write(skiatest::Reporter* reporter, SkSurface* surf, const SkBitmap& bitmap,
|
||||
int writeX, int writeY) {
|
||||
const SkImageInfo canvasInfo = canvas->imageInfo();
|
||||
size_t canvasRowBytes;
|
||||
const uint32_t* canvasPixels;
|
||||
|
||||
@ -194,8 +193,8 @@ static bool check_write(skiatest::Reporter* reporter, SkCanvas* canvas, const Sk
|
||||
// At some point this will be unsupported, as we won't allow accessBitmap() to magically call
|
||||
// readPixels for the client.
|
||||
SkBitmap secretDevBitmap;
|
||||
secretDevBitmap.allocN32Pixels(canvasInfo.width(), canvasInfo.height());
|
||||
if (!canvas->readPixels(secretDevBitmap, 0, 0)) {
|
||||
secretDevBitmap.allocN32Pixels(surf->width(), surf->height());
|
||||
if (!surf->readPixels(secretDevBitmap, 0, 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -206,9 +205,7 @@ static bool check_write(skiatest::Reporter* reporter, SkCanvas* canvas, const Sk
|
||||
return false;
|
||||
}
|
||||
|
||||
if (canvasInfo.width() != DEV_W ||
|
||||
canvasInfo.height() != DEV_H ||
|
||||
canvasInfo.colorType() != kN32_SkColorType) {
|
||||
if (surf->width() != DEV_W || surf->height() != DEV_H) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -352,7 +349,7 @@ static void test_write_pixels(skiatest::Reporter* reporter, SkSurface* surface)
|
||||
SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H + 10),
|
||||
};
|
||||
|
||||
SkCanvas& canvas = *surface->getCanvas();
|
||||
SkCanvas* canvas = surface->getCanvas();
|
||||
|
||||
static const struct {
|
||||
SkColorType fColorType;
|
||||
@ -370,21 +367,21 @@ static void test_write_pixels(skiatest::Reporter* reporter, SkSurface* surface)
|
||||
const SkColorType ct = gSrcConfigs[c].fColorType;
|
||||
const SkAlphaType at = gSrcConfigs[c].fAlphaType;
|
||||
|
||||
fill_canvas(&canvas);
|
||||
fill_canvas(canvas);
|
||||
SkBitmap bmp;
|
||||
REPORTER_ASSERT(reporter, setup_bitmap(&bmp, ct, at, rect.width(),
|
||||
rect.height(), SkToBool(tightBmp)));
|
||||
uint32_t idBefore = surface->generationID();
|
||||
|
||||
// sk_tool_utils::write_pixels(&canvas, bmp, rect.fLeft, rect.fTop, ct, at);
|
||||
canvas.writePixels(bmp, rect.fLeft, rect.fTop);
|
||||
canvas->writePixels(bmp, rect.fLeft, rect.fTop);
|
||||
|
||||
uint32_t idAfter = surface->generationID();
|
||||
REPORTER_ASSERT(reporter, check_write(reporter, &canvas, bmp,
|
||||
REPORTER_ASSERT(reporter, check_write(reporter, surface, bmp,
|
||||
rect.fLeft, rect.fTop));
|
||||
|
||||
// we should change the genID iff pixels were actually written.
|
||||
SkIRect canvasRect = SkIRect::MakeSize(canvas.getBaseLayerSize());
|
||||
SkIRect canvasRect = SkIRect::MakeSize(canvas->getBaseLayerSize());
|
||||
SkIRect writeRect = SkIRect::MakeXYWH(rect.fLeft, rect.fTop,
|
||||
bmp.width(), bmp.height());
|
||||
bool intersects = SkIRect::Intersects(canvasRect, writeRect) ;
|
||||
|
@ -19,7 +19,7 @@
|
||||
static SkBitmap read_pixels(sk_sp<SkSurface> surface) {
|
||||
SkBitmap bmp;
|
||||
bmp.allocN32Pixels(surface->width(), surface->height());
|
||||
if (!surface->getCanvas()->readPixels(bmp, 0, 0)) {
|
||||
if (!surface->readPixels(bmp, 0, 0)) {
|
||||
SkDebugf("readPixels failed\n");
|
||||
}
|
||||
return bmp;
|
||||
|
Loading…
Reference in New Issue
Block a user