Index: tests/PictureTest.cpp |
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp |
index d69de45fd4a6cdb5ccefaefda7b03a2077bd5a7b..6f9e6e7b38640f9238faae5bd2f240e95355b03c 100644 |
--- a/tests/PictureTest.cpp |
+++ b/tests/PictureTest.cpp |
@@ -38,9 +38,6 @@ |
#include "SkLumaColorFilter.h" |
#include "SkColorFilterImageFilter.h" |
-static const int gColorScale = 30; |
-static const int gColorOffset = 60; |
- |
static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) { |
bm->allocN32Pixels(w, h); |
bm->eraseColor(color); |
@@ -49,157 +46,10 @@ static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) { |
} |
} |
-static void make_checkerboard(SkBitmap* bm, int w, int h, bool immutable) { |
- SkASSERT(w % 2 == 0); |
- SkASSERT(h % 2 == 0); |
- bm->allocPixels(SkImageInfo::Make(w, h, kAlpha_8_SkColorType, |
- kPremul_SkAlphaType)); |
- SkAutoLockPixels lock(*bm); |
- for (int y = 0; y < h; y += 2) { |
- uint8_t* s = bm->getAddr8(0, y); |
- for (int x = 0; x < w; x += 2) { |
- *s++ = 0xFF; |
- *s++ = 0x00; |
- } |
- s = bm->getAddr8(0, y + 1); |
- for (int x = 0; x < w; x += 2) { |
- *s++ = 0x00; |
- *s++ = 0xFF; |
- } |
- } |
- if (immutable) { |
- bm->setImmutable(); |
- } |
-} |
- |
-static void init_paint(SkPaint* paint, const SkBitmap &bm) { |
- SkShader* shader = SkShader::CreateBitmapShader(bm, |
- SkShader::kClamp_TileMode, |
- SkShader::kClamp_TileMode); |
- paint->setShader(shader)->unref(); |
-} |
- |
robertphillips
2015/01/22 15:37:05
Remove this?
reed1
2015/01/22 17:02:40
Will do in followup CL
|
typedef void (*DrawBitmapProc)(SkCanvas*, const SkBitmap&, |
const SkBitmap&, const SkPoint&, |
SkTDArray<SkPixelRef*>* usedPixRefs); |
-static void drawpaint_proc(SkCanvas* canvas, const SkBitmap& bm, |
- const SkBitmap& altBM, const SkPoint& pos, |
- SkTDArray<SkPixelRef*>* usedPixRefs) { |
- SkPaint paint; |
- init_paint(&paint, bm); |
- |
- canvas->drawPaint(paint); |
- *usedPixRefs->append() = bm.pixelRef(); |
-} |
- |
-static void drawpoints_proc(SkCanvas* canvas, const SkBitmap& bm, |
- const SkBitmap& altBM, const SkPoint& pos, |
- SkTDArray<SkPixelRef*>* usedPixRefs) { |
- SkPaint paint; |
- init_paint(&paint, bm); |
- |
- // draw a rect |
- SkPoint points[5] = { |
- { pos.fX, pos.fY }, |
- { pos.fX + bm.width() - 1, pos.fY }, |
- { pos.fX + bm.width() - 1, pos.fY + bm.height() - 1 }, |
- { pos.fX, pos.fY + bm.height() - 1 }, |
- { pos.fX, pos.fY }, |
- }; |
- |
- canvas->drawPoints(SkCanvas::kPolygon_PointMode, 5, points, paint); |
- *usedPixRefs->append() = bm.pixelRef(); |
-} |
- |
-static void drawrect_proc(SkCanvas* canvas, const SkBitmap& bm, |
- const SkBitmap& altBM, const SkPoint& pos, |
- SkTDArray<SkPixelRef*>* usedPixRefs) { |
- SkPaint paint; |
- init_paint(&paint, bm); |
- |
- SkRect r = { 0, 0, SkIntToScalar(bm.width()), SkIntToScalar(bm.height()) }; |
- r.offset(pos.fX, pos.fY); |
- |
- canvas->drawRect(r, paint); |
- *usedPixRefs->append() = bm.pixelRef(); |
-} |
- |
-static void drawoval_proc(SkCanvas* canvas, const SkBitmap& bm, |
- const SkBitmap& altBM, const SkPoint& pos, |
- SkTDArray<SkPixelRef*>* usedPixRefs) { |
- SkPaint paint; |
- init_paint(&paint, bm); |
- |
- SkRect r = { 0, 0, SkIntToScalar(bm.width()), SkIntToScalar(bm.height()) }; |
- r.offset(pos.fX, pos.fY); |
- |
- canvas->drawOval(r, paint); |
- *usedPixRefs->append() = bm.pixelRef(); |
-} |
- |
-static void drawrrect_proc(SkCanvas* canvas, const SkBitmap& bm, |
- const SkBitmap& altBM, const SkPoint& pos, |
- SkTDArray<SkPixelRef*>* usedPixRefs) { |
- SkPaint paint; |
- init_paint(&paint, bm); |
- |
- SkRect r = { 0, 0, SkIntToScalar(bm.width()), SkIntToScalar(bm.height()) }; |
- r.offset(pos.fX, pos.fY); |
- |
- SkRRect rr; |
- rr.setRectXY(r, SkIntToScalar(bm.width())/4, SkIntToScalar(bm.height())/4); |
- canvas->drawRRect(rr, paint); |
- *usedPixRefs->append() = bm.pixelRef(); |
-} |
- |
-static void drawpath_proc(SkCanvas* canvas, const SkBitmap& bm, |
- const SkBitmap& altBM, const SkPoint& pos, |
- SkTDArray<SkPixelRef*>* usedPixRefs) { |
- SkPaint paint; |
- init_paint(&paint, bm); |
- |
- SkPath path; |
- path.lineTo(bm.width()/2.0f, SkIntToScalar(bm.height())); |
- path.lineTo(SkIntToScalar(bm.width()), 0); |
- path.close(); |
- path.offset(pos.fX, pos.fY); |
- |
- canvas->drawPath(path, paint); |
- *usedPixRefs->append() = bm.pixelRef(); |
-} |
- |
-static void drawbitmap_proc(SkCanvas* canvas, const SkBitmap& bm, |
- const SkBitmap& altBM, const SkPoint& pos, |
- SkTDArray<SkPixelRef*>* usedPixRefs) { |
- canvas->drawBitmap(bm, pos.fX, pos.fY, NULL); |
- *usedPixRefs->append() = bm.pixelRef(); |
-} |
- |
-static void drawbitmap_withshader_proc(SkCanvas* canvas, const SkBitmap& bm, |
- const SkBitmap& altBM, const SkPoint& pos, |
- SkTDArray<SkPixelRef*>* usedPixRefs) { |
- SkPaint paint; |
- init_paint(&paint, bm); |
- |
- // The bitmap in the paint is ignored unless we're drawing an A8 bitmap |
- canvas->drawBitmap(altBM, pos.fX, pos.fY, &paint); |
- *usedPixRefs->append() = bm.pixelRef(); |
- *usedPixRefs->append() = altBM.pixelRef(); |
-} |
- |
-static void drawsprite_proc(SkCanvas* canvas, const SkBitmap& bm, |
- const SkBitmap& altBM, const SkPoint& pos, |
- SkTDArray<SkPixelRef*>* usedPixRefs) { |
- const SkMatrix& ctm = canvas->getTotalMatrix(); |
- |
- SkPoint p(pos); |
- ctm.mapPoints(&p, 1); |
- |
- canvas->drawSprite(bm, (int)p.fX, (int)p.fY, NULL); |
- *usedPixRefs->append() = bm.pixelRef(); |
-} |
- |
robertphillips
2015/01/22 15:37:05
Remove this too
reed1
2015/01/22 17:02:40
Will do in followup CL
|
#if 0 |
// Although specifiable, this case doesn't seem to make sense (i.e., the |
// bitmap in the shader is never used). |
@@ -220,368 +70,6 @@ static void drawsprite_withshader_proc(SkCanvas* canvas, const SkBitmap& bm, |
} |
#endif |
-static void drawbitmaprect_proc(SkCanvas* canvas, const SkBitmap& bm, |
- const SkBitmap& altBM, const SkPoint& pos, |
- SkTDArray<SkPixelRef*>* usedPixRefs) { |
- SkRect r = { 0, 0, SkIntToScalar(bm.width()), SkIntToScalar(bm.height()) }; |
- |
- r.offset(pos.fX, pos.fY); |
- canvas->drawBitmapRectToRect(bm, NULL, r, NULL); |
- *usedPixRefs->append() = bm.pixelRef(); |
-} |
- |
-static void drawbitmaprect_withshader_proc(SkCanvas* canvas, |
- const SkBitmap& bm, |
- const SkBitmap& altBM, |
- const SkPoint& pos, |
- SkTDArray<SkPixelRef*>* usedPixRefs) { |
- SkPaint paint; |
- init_paint(&paint, bm); |
- |
- SkRect r = { 0, 0, SkIntToScalar(bm.width()), SkIntToScalar(bm.height()) }; |
- r.offset(pos.fX, pos.fY); |
- |
- // The bitmap in the paint is ignored unless we're drawing an A8 bitmap |
- canvas->drawBitmapRectToRect(altBM, NULL, r, &paint); |
- *usedPixRefs->append() = bm.pixelRef(); |
- *usedPixRefs->append() = altBM.pixelRef(); |
-} |
- |
-static void drawtext_proc(SkCanvas* canvas, const SkBitmap& bm, |
- const SkBitmap& altBM, const SkPoint& pos, |
- SkTDArray<SkPixelRef*>* usedPixRefs) { |
- SkPaint paint; |
- init_paint(&paint, bm); |
- paint.setTextSize(SkIntToScalar(1.5*bm.width())); |
- |
- canvas->drawText("0", 1, pos.fX, pos.fY+bm.width(), paint); |
- *usedPixRefs->append() = bm.pixelRef(); |
-} |
- |
-static void drawpostext_proc(SkCanvas* canvas, const SkBitmap& bm, |
- const SkBitmap& altBM, const SkPoint& pos, |
- SkTDArray<SkPixelRef*>* usedPixRefs) { |
- SkPaint paint; |
- init_paint(&paint, bm); |
- paint.setTextSize(SkIntToScalar(1.5*bm.width())); |
- |
- SkPoint point = { pos.fX, pos.fY + bm.height() }; |
- canvas->drawPosText("O", 1, &point, paint); |
- *usedPixRefs->append() = bm.pixelRef(); |
-} |
- |
-static void drawtextonpath_proc(SkCanvas* canvas, const SkBitmap& bm, |
- const SkBitmap& altBM, const SkPoint& pos, |
- SkTDArray<SkPixelRef*>* usedPixRefs) { |
- SkPaint paint; |
- |
- init_paint(&paint, bm); |
- paint.setTextSize(SkIntToScalar(1.5*bm.width())); |
- |
- SkPath path; |
- path.lineTo(SkIntToScalar(bm.width()), 0); |
- path.offset(pos.fX, pos.fY+bm.height()); |
- |
- canvas->drawTextOnPath("O", 1, path, NULL, paint); |
- *usedPixRefs->append() = bm.pixelRef(); |
-} |
- |
-static void drawverts_proc(SkCanvas* canvas, const SkBitmap& bm, |
- const SkBitmap& altBM, const SkPoint& pos, |
- SkTDArray<SkPixelRef*>* usedPixRefs) { |
- SkPaint paint; |
- init_paint(&paint, bm); |
- |
- SkPoint verts[4] = { |
- { pos.fX, pos.fY }, |
- { pos.fX + bm.width(), pos.fY }, |
- { pos.fX + bm.width(), pos.fY + bm.height() }, |
- { pos.fX, pos.fY + bm.height() } |
- }; |
- SkPoint texs[4] = { { 0, 0 }, |
- { SkIntToScalar(bm.width()), 0 }, |
- { SkIntToScalar(bm.width()), SkIntToScalar(bm.height()) }, |
- { 0, SkIntToScalar(bm.height()) } }; |
- uint16_t indices[6] = { 0, 1, 2, 0, 2, 3 }; |
- |
- canvas->drawVertices(SkCanvas::kTriangles_VertexMode, 4, verts, texs, NULL, NULL, |
- indices, 6, paint); |
- *usedPixRefs->append() = bm.pixelRef(); |
-} |
- |
-// Return a picture with the bitmaps drawn at the specified positions. |
-static SkPicture* record_bitmaps(const SkBitmap bm[], |
- const SkPoint pos[], |
- SkTDArray<SkPixelRef*> analytic[], |
- int count, |
- DrawBitmapProc proc) { |
- SkPictureRecorder recorder; |
- SkCanvas* canvas = recorder.beginRecording(1000, 1000); |
- for (int i = 0; i < count; ++i) { |
- analytic[i].rewind(); |
- canvas->save(); |
- SkRect clipRect = SkRect::MakeXYWH(pos[i].fX, pos[i].fY, |
- SkIntToScalar(bm[i].width()), |
- SkIntToScalar(bm[i].height())); |
- canvas->clipRect(clipRect, SkRegion::kIntersect_Op); |
- proc(canvas, bm[i], bm[count+i], pos[i], &analytic[i]); |
- canvas->restore(); |
- } |
- return recorder.endRecording(); |
-} |
- |
-static void rand_rect(SkRect* rect, SkRandom& rand, SkScalar W, SkScalar H) { |
- rect->fLeft = rand.nextRangeScalar(-W, 2*W); |
- rect->fTop = rand.nextRangeScalar(-H, 2*H); |
- rect->fRight = rect->fLeft + rand.nextRangeScalar(0, W); |
- rect->fBottom = rect->fTop + rand.nextRangeScalar(0, H); |
- |
- // we integralize rect to make our tests more predictable, since Gather is |
- // a little sloppy. |
- SkIRect ir; |
- rect->round(&ir); |
- rect->set(ir); |
-} |
- |
-static void draw(SkPicture* pic, int width, int height, SkBitmap* result) { |
- make_bm(result, width, height, SK_ColorBLACK, false); |
- |
- SkCanvas canvas(*result); |
- canvas.drawPicture(pic); |
-} |
- |
-template <typename T> int find_index(const T* array, T elem, int count) { |
- for (int i = 0; i < count; ++i) { |
- if (array[i] == elem) { |
- return i; |
- } |
- } |
- return -1; |
-} |
- |
-// Return true if 'ref' is found in array[] |
-static bool find(SkPixelRef const * const * array, SkPixelRef const * ref, int count) { |
- return find_index<const SkPixelRef*>(array, ref, count) >= 0; |
-} |
- |
-// Look at each pixel that is inside 'subset', and if its color appears in |
-// colors[], find the corresponding value in refs[] and append that ref into |
-// array, skipping duplicates of the same value. |
-// Note that gathering pixelRefs from rendered colors suffers from the problem |
-// that multiple simultaneous textures (e.g., A8 for alpha and 8888 for color) |
-// isn't easy to reconstruct. |
-static void gather_from_image(const SkBitmap& bm, SkPixelRef* const refs[], |
- int count, SkTDArray<SkPixelRef*>* array, |
- const SkRect& subset) { |
- SkIRect ir; |
- subset.roundOut(&ir); |
- |
- if (!ir.intersect(0, 0, bm.width()-1, bm.height()-1)) { |
- return; |
- } |
- |
- // Since we only want to return unique values in array, when we scan we just |
- // set a bit for each index'd color found. In practice we only have a few |
- // distinct colors, so we just use an int's bits as our array. Hence the |
- // assert that count <= number-of-bits-in-our-int. |
- SkASSERT((unsigned)count <= 32); |
- uint32_t bitarray = 0; |
- |
- SkAutoLockPixels alp(bm); |
- |
- for (int y = ir.fTop; y < ir.fBottom; ++y) { |
- for (int x = ir.fLeft; x < ir.fRight; ++x) { |
- SkPMColor pmc = *bm.getAddr32(x, y); |
- // the only good case where the color is not found would be if |
- // the color is transparent, meaning no bitmap was drawn in that |
- // pixel. |
- if (pmc) { |
- uint32_t index = SkGetPackedR32(pmc); |
- SkASSERT(SkGetPackedG32(pmc) == index); |
- SkASSERT(SkGetPackedB32(pmc) == index); |
- if (0 == index) { |
- continue; // background color |
- } |
- SkASSERT(0 == (index - gColorOffset) % gColorScale); |
- index = (index - gColorOffset) / gColorScale; |
- SkASSERT(static_cast<int>(index) < count); |
- bitarray |= 1 << index; |
- } |
- } |
- } |
- |
- for (int i = 0; i < count; ++i) { |
- if (bitarray & (1 << i)) { |
- *array->append() = refs[i]; |
- } |
- } |
-} |
- |
-static void gather_from_analytic(const SkPoint pos[], SkScalar w, SkScalar h, |
- const SkTDArray<SkPixelRef*> analytic[], |
- int count, |
- SkTDArray<SkPixelRef*>* result, |
- const SkRect& subset) { |
- for (int i = 0; i < count; ++i) { |
- SkRect rect = SkRect::MakeXYWH(pos[i].fX, pos[i].fY, w, h); |
- |
- if (SkRect::Intersects(subset, rect)) { |
- result->append(analytic[i].count(), analytic[i].begin()); |
- } |
- } |
-} |
- |
- |
-static const struct { |
- const DrawBitmapProc proc; |
- const char* const desc; |
-} gProcs[] = { |
- {drawpaint_proc, "drawpaint"}, |
- {drawpoints_proc, "drawpoints"}, |
- {drawrect_proc, "drawrect"}, |
- {drawoval_proc, "drawoval"}, |
- {drawrrect_proc, "drawrrect"}, |
- {drawpath_proc, "drawpath"}, |
- {drawbitmap_proc, "drawbitmap"}, |
- {drawbitmap_withshader_proc, "drawbitmap_withshader"}, |
- {drawsprite_proc, "drawsprite"}, |
-#if 0 |
- {drawsprite_withshader_proc, "drawsprite_withshader"}, |
-#endif |
- {drawbitmaprect_proc, "drawbitmaprect"}, |
- {drawbitmaprect_withshader_proc, "drawbitmaprect_withshader"}, |
- {drawtext_proc, "drawtext"}, |
- {drawpostext_proc, "drawpostext"}, |
- {drawtextonpath_proc, "drawtextonpath"}, |
- {drawverts_proc, "drawverts"}, |
-}; |
- |
-static void create_textures(SkBitmap* bm, SkPixelRef** refs, int num, int w, int h) { |
- // Our convention is that the color components contain an encoding of |
- // the index of their corresponding bitmap/pixelref. (0,0,0,0) is |
- // reserved for the background |
- for (int i = 0; i < num; ++i) { |
- make_bm(&bm[i], w, h, |
- SkColorSetARGB(0xFF, |
- gColorScale*i+gColorOffset, |
- gColorScale*i+gColorOffset, |
- gColorScale*i+gColorOffset), |
- true); |
- refs[i] = bm[i].pixelRef(); |
- } |
- |
- // The A8 alternate bitmaps are all BW checkerboards |
- for (int i = 0; i < num; ++i) { |
- make_checkerboard(&bm[num+i], w, h, true); |
- refs[num+i] = bm[num+i].pixelRef(); |
- } |
-} |
- |
-static void test_gatherpixelrefs(skiatest::Reporter* reporter) { |
- const int IW = 32; |
- const int IH = IW; |
- const SkScalar W = SkIntToScalar(IW); |
- const SkScalar H = W; |
- |
- static const int N = 4; |
- SkBitmap bm[2*N]; |
- SkPixelRef* refs[2*N]; |
- SkTDArray<SkPixelRef*> analytic[N]; |
- |
- const SkPoint pos[N] = { |
- { 0, 0 }, { W, 0 }, { 0, H }, { W, H } |
- }; |
- |
- create_textures(bm, refs, N, IW, IH); |
- |
- SkRandom rand; |
- for (size_t k = 0; k < SK_ARRAY_COUNT(gProcs); ++k) { |
- SkAutoTUnref<SkPicture> pic( |
- record_bitmaps(bm, pos, analytic, N, gProcs[k].proc)); |
- |
- REPORTER_ASSERT(reporter, pic->willPlayBackBitmaps() || N == 0); |
- // quick check for a small piece of each quadrant, which should just |
- // contain 1 or 2 bitmaps. |
- for (size_t i = 0; i < SK_ARRAY_COUNT(pos); ++i) { |
- SkRect r; |
- r.set(2, 2, W - 2, H - 2); |
- r.offset(pos[i].fX, pos[i].fY); |
- SkAutoDataUnref data(SkPictureUtils::GatherPixelRefs(pic, r)); |
- if (!data) { |
- ERRORF(reporter, "SkPictureUtils::GatherPixelRefs returned " |
- "NULL for %s.", gProcs[k].desc); |
- continue; |
- } |
- SkPixelRef** gatheredRefs = (SkPixelRef**)data->data(); |
- int count = static_cast<int>(data->size() / sizeof(SkPixelRef*)); |
- REPORTER_ASSERT(reporter, 1 == count || 2 == count); |
- if (1 == count) { |
- REPORTER_ASSERT(reporter, gatheredRefs[0] == refs[i]); |
- } else if (2 == count) { |
- REPORTER_ASSERT(reporter, |
- (gatheredRefs[0] == refs[i] && gatheredRefs[1] == refs[i+N]) || |
- (gatheredRefs[1] == refs[i] && gatheredRefs[0] == refs[i+N])); |
- } |
- } |
- |
- SkBitmap image; |
- draw(pic, 2*IW, 2*IH, &image); |
- |
- // Test a bunch of random (mostly) rects, and compare the gather results |
- // with a deduced list of refs by looking at the colors drawn. |
- for (int j = 0; j < 100; ++j) { |
- SkRect r; |
- rand_rect(&r, rand, 2*W, 2*H); |
- |
- SkTDArray<SkPixelRef*> fromImage; |
- gather_from_image(image, refs, N, &fromImage, r); |
- |
- SkTDArray<SkPixelRef*> fromAnalytic; |
- gather_from_analytic(pos, W, H, analytic, N, &fromAnalytic, r); |
- |
- SkData* data = SkPictureUtils::GatherPixelRefs(pic, r); |
- size_t dataSize = data ? data->size() : 0; |
- int gatherCount = static_cast<int>(dataSize / sizeof(SkPixelRef*)); |
- SkASSERT(gatherCount * sizeof(SkPixelRef*) == dataSize); |
- SkPixelRef** gatherRefs = data ? (SkPixelRef**)(data->data()) : NULL; |
- SkAutoDataUnref adu(data); |
- |
- // Everything that we saw drawn should appear in the analytic list |
- // but the analytic list may contain some pixelRefs that were not |
- // seen in the image (e.g., A8 textures used as masks) |
- for (int i = 0; i < fromImage.count(); ++i) { |
- if (-1 == fromAnalytic.find(fromImage[i])) { |
- ERRORF(reporter, "PixelRef missing %d %s", |
- i, gProcs[k].desc); |
- } |
- } |
- |
- /* |
- * GatherPixelRefs is conservative, so it can return more bitmaps |
- * than are strictly required. Thus our check here is only that |
- * Gather didn't miss any that we actually needed. Even that isn't |
- * a strict requirement on Gather, which is meant to be quick and |
- * only mostly-correct, but at the moment this test should work. |
- */ |
- for (int i = 0; i < fromAnalytic.count(); ++i) { |
- bool found = find(gatherRefs, fromAnalytic[i], gatherCount); |
- if (!found) { |
- ERRORF(reporter, "PixelRef missing %d %s", |
- i, gProcs[k].desc); |
- } |
-#if 0 |
- // enable this block of code to debug failures, as it will rerun |
- // the case that failed. |
- if (!found) { |
- SkData* data = SkPictureUtils::GatherPixelRefs(pic, r); |
- size_t dataSize = data ? data->size() : 0; |
- } |
-#endif |
- } |
- } |
- } |
-} |
- |
/* Hit a few SkPicture::Analysis cases not handled elsewhere. */ |
static void test_analysis(skiatest::Reporter* reporter) { |
SkPictureRecorder recorder; |
@@ -615,90 +103,6 @@ static void test_analysis(skiatest::Reporter* reporter) { |
} |
-static void test_gatherpixelrefsandrects(skiatest::Reporter* reporter) { |
- const int IW = 32; |
- const int IH = IW; |
- const SkScalar W = SkIntToScalar(IW); |
- const SkScalar H = W; |
- |
- static const int N = 4; |
- SkBitmap bm[2*N]; |
- SkPixelRef* refs[2*N]; |
- SkTDArray<SkPixelRef*> analytic[N]; |
- |
- const SkPoint pos[N] = { |
- { 0, 0 }, { W, 0 }, { 0, H }, { W, H } |
- }; |
- |
- create_textures(bm, refs, N, IW, IH); |
- |
- SkRandom rand; |
- for (size_t k = 0; k < SK_ARRAY_COUNT(gProcs); ++k) { |
- SkAutoTUnref<SkPicture> pic( |
- record_bitmaps(bm, pos, analytic, N, gProcs[k].proc)); |
- |
- REPORTER_ASSERT(reporter, pic->willPlayBackBitmaps() || N == 0); |
- |
- SkAutoTUnref<SkPictureUtils::SkPixelRefContainer> prCont( |
- new SkPictureUtils::SkPixelRefsAndRectsList); |
- |
- SkPictureUtils::GatherPixelRefsAndRects(pic, prCont); |
- |
- // quick check for a small piece of each quadrant, which should just |
- // contain 1 or 2 bitmaps. |
- for (size_t i = 0; i < SK_ARRAY_COUNT(pos); ++i) { |
- SkRect r; |
- r.set(2, 2, W - 2, H - 2); |
- r.offset(pos[i].fX, pos[i].fY); |
- |
- SkTDArray<SkPixelRef*> gatheredRefs; |
- prCont->query(r, &gatheredRefs); |
- |
- int count = gatheredRefs.count(); |
- REPORTER_ASSERT(reporter, 1 == count || 2 == count); |
- if (1 == count) { |
- REPORTER_ASSERT(reporter, gatheredRefs[0] == refs[i]); |
- } else if (2 == count) { |
- REPORTER_ASSERT(reporter, |
- (gatheredRefs[0] == refs[i] && gatheredRefs[1] == refs[i+N]) || |
- (gatheredRefs[1] == refs[i] && gatheredRefs[0] == refs[i+N])); |
- } |
- } |
- |
- SkBitmap image; |
- draw(pic, 2*IW, 2*IH, &image); |
- |
- // Test a bunch of random (mostly) rects, and compare the gather results |
- // with the analytic results and the pixel refs seen in a rendering. |
- for (int j = 0; j < 100; ++j) { |
- SkRect r; |
- rand_rect(&r, rand, 2*W, 2*H); |
- |
- SkTDArray<SkPixelRef*> fromImage; |
- gather_from_image(image, refs, N, &fromImage, r); |
- |
- SkTDArray<SkPixelRef*> fromAnalytic; |
- gather_from_analytic(pos, W, H, analytic, N, &fromAnalytic, r); |
- |
- SkTDArray<SkPixelRef*> gatheredRefs; |
- prCont->query(r, &gatheredRefs); |
- |
- // Everything that we saw drawn should appear in the analytic list |
- // but the analytic list may contain some pixelRefs that were not |
- // seen in the image (e.g., A8 textures used as masks) |
- for (int i = 0; i < fromImage.count(); ++i) { |
- REPORTER_ASSERT(reporter, -1 != fromAnalytic.find(fromImage[i])); |
- } |
- |
- // Everything in the analytic list should appear in the gathered |
- // list. |
- for (int i = 0; i < fromAnalytic.count(); ++i) { |
- REPORTER_ASSERT(reporter, -1 != gatheredRefs.find(fromAnalytic[i])); |
- } |
- } |
- } |
-} |
- |
#ifdef SK_DEBUG |
// Ensure that deleting an empty SkPicture does not assert. Asserts only fire |
// in debug mode, so only run in debug mode. |
@@ -1769,8 +1173,6 @@ DEF_TEST(Picture, reporter) { |
#endif |
test_has_text(reporter); |
test_analysis(reporter); |
- test_gatherpixelrefs(reporter); |
- test_gatherpixelrefsandrects(reporter); |
test_bitmap_with_encoded_data(reporter); |
test_clip_bound_opt(reporter); |
test_clip_expansion(reporter); |