Index: gm/image.cpp |
diff --git a/gm/image.cpp b/gm/image.cpp |
index 71fe0e176f094bdab2f047f93f79f2eb640cb6c0..1d79cd1bae6eefb1ca5a5d4d4e158c3827df9f7a 100644 |
--- a/gm/image.cpp |
+++ b/gm/image.cpp |
@@ -40,7 +40,7 @@ static void drawJpeg(SkCanvas* canvas, const SkISize& size) { |
SkAutoCanvasRestore acr(canvas, true); |
canvas->scale(size.width() * 1.0f / image->width(), |
size.height() * 1.0f / image->height()); |
- image->draw(canvas,0, 0, NULL); |
+ image->draw(canvas, 0, 0, NULL); |
image->unref(); |
} |
} |
@@ -65,7 +65,7 @@ static void drawContents(SkSurface* surface, SkColor fillC) { |
canvas->drawCircle(size.fWidth/2, size.fHeight/2, radius, paint); |
} |
-static void test_surface(SkCanvas* canvas, SkSurface* surf) { |
+static void test_surface(SkCanvas* canvas, SkSurface* surf, bool usePaint) { |
drawContents(surf, SK_ColorRED); |
SkImage* imgR = surf->newImageSnapshot(); |
@@ -87,9 +87,26 @@ static void test_surface(SkCanvas* canvas, SkSurface* surf) { |
// paint.setFilterBitmap(true); |
// paint.setAlpha(0x80); |
- imgR->draw(canvas, 0, 0, &paint); |
- imgG->draw(canvas, 0, 80, &paint); |
- surf->draw(canvas, 0, 160, &paint); |
+ imgR->draw(canvas, 0, 0, usePaint ? &paint : NULL); |
+ imgG->draw(canvas, 0, 80, usePaint ? &paint : NULL); |
+ surf->draw(canvas, 0, 160, usePaint ? &paint : NULL); |
+ |
+ SkRect src1, src2, src3; |
+ src1.iset(0, 0, surf->width(), surf->height()); |
+ src2.iset(-surf->width() / 2, -surf->height() / 2, |
+ surf->width(), surf->height()); |
+ src3.iset(0, 0, surf->width() / 2, surf->height() / 2); |
+ |
+ SkRect dst1, dst2, dst3, dst4; |
+ dst1.set(0, 240, 65, 305); |
+ dst2.set(0, 320, 65, 385); |
+ dst3.set(0, 400, 65, 465); |
+ dst4.set(0, 480, 65, 545); |
+ |
+ imgR->draw(canvas, &src1, dst1, usePaint ? &paint : NULL); |
+ imgG->draw(canvas, &src2, dst2, usePaint ? &paint : NULL); |
+ imgR->draw(canvas, &src3, dst3, usePaint ? &paint : NULL); |
+ imgG->draw(canvas, NULL, dst4, usePaint ? &paint : NULL); |
imgG->unref(); |
imgR->unref(); |
@@ -122,7 +139,7 @@ protected: |
} |
virtual SkISize onISize() { |
- return SkISize::Make(800, 500); |
+ return SkISize::Make(960, 1200); |
} |
virtual void onDraw(SkCanvas* canvas) { |
@@ -133,22 +150,32 @@ protected: |
static const char* kLabel1 = "Original Img"; |
static const char* kLabel2 = "Modified Img"; |
static const char* kLabel3 = "Cur Surface"; |
+ static const char* kLabel4 = "Full Crop"; |
+ static const char* kLabel5 = "Over-crop"; |
+ static const char* kLabel6 = "Upper-left"; |
+ static const char* kLabel7 = "No Crop"; |
- static const char* kLabel4 = "Pre-Alloc Img"; |
- static const char* kLabel5 = "New Alloc Img"; |
- static const char* kLabel6 = "SkPicture"; |
- static const char* kLabel7 = "GPU"; |
+ static const char* kLabel8 = "Pre-Alloc Img"; |
+ static const char* kLabel9 = "New Alloc Img"; |
+ static const char* kLabel10 = "SkPicture"; |
+ static const char* kLabel11 = "Null Paint"; |
+ static const char* kLabel12 = "GPU"; |
SkPaint textPaint; |
canvas->drawText(kLabel1, strlen(kLabel1), 10, 60, textPaint); |
canvas->drawText(kLabel2, strlen(kLabel2), 10, 140, textPaint); |
canvas->drawText(kLabel3, strlen(kLabel3), 10, 220, textPaint); |
+ canvas->drawText(kLabel4, strlen(kLabel4), 10, 300, textPaint); |
+ canvas->drawText(kLabel5, strlen(kLabel5), 10, 380, textPaint); |
+ canvas->drawText(kLabel6, strlen(kLabel6), 10, 460, textPaint); |
+ canvas->drawText(kLabel7, strlen(kLabel7), 10, 540, textPaint); |
- canvas->drawText(kLabel4, strlen(kLabel4), 80, 10, textPaint); |
- canvas->drawText(kLabel5, strlen(kLabel5), 160, 10, textPaint); |
- canvas->drawText(kLabel6, strlen(kLabel6), 250, 10, textPaint); |
- canvas->drawText(kLabel7, strlen(kLabel7), 340, 10, textPaint); |
+ canvas->drawText(kLabel8, strlen(kLabel8), 80, 10, textPaint); |
+ canvas->drawText(kLabel9, strlen(kLabel9), 160, 10, textPaint); |
+ canvas->drawText(kLabel10, strlen(kLabel10), 250, 10, textPaint); |
+ canvas->drawText(kLabel11, strlen(kLabel11), 320, 10, textPaint); |
+ canvas->drawText(kLabel12, strlen(kLabel12), 410, 10, textPaint); |
canvas->translate(80, 20); |
@@ -164,21 +191,24 @@ protected: |
SkAutoTUnref<SkSurface> surf0(SkSurface::NewRasterDirect(info, fBuffer, RB)); |
SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info)); |
SkAutoTUnref<SkSurface> surf2(SkSurface::NewPicture(info.fWidth, info.fHeight)); |
+ SkAutoTUnref<SkSurface> surf3(SkSurface::NewPicture(info.fWidth, info.fHeight)); |
#if SK_SUPPORT_GPU |
GrContext* ctx = skiagm::GetGr(); |
- SkAutoTUnref<SkSurface> surf3(SkSurface::NewRenderTarget(ctx, info, 0)); |
+ SkAutoTUnref<SkSurface> surf4(SkSurface::NewRenderTarget(ctx, info, 0)); |
#endif |
- test_surface(canvas, surf0); |
+ test_surface(canvas, surf0, true); |
+ canvas->translate(80, 0); |
+ test_surface(canvas, surf1, true); |
canvas->translate(80, 0); |
- test_surface(canvas, surf1); |
+ test_surface(canvas, surf2, true); |
canvas->translate(80, 0); |
- test_surface(canvas, surf2); |
+ test_surface(canvas, surf3, false); |
#if SK_SUPPORT_GPU |
if (NULL != ctx) { |
canvas->translate(80, 0); |
- test_surface(canvas, surf3); |
+ test_surface(canvas, surf4, true); |
} |
#endif |
} |