Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Unified Diff: gm/aaclip.cpp

Issue 159723006: add peekPixels to canvas (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gm/bitmapcopy.cpp » ('j') | include/core/SkCanvas.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/aaclip.cpp
diff --git a/gm/aaclip.cpp b/gm/aaclip.cpp
index ec29a4f896f324a87d3f8d7e9b825d6210b17885..537da07386d3b75818cb3951244976ebf0c9eed5 100644
--- a/gm/aaclip.cpp
+++ b/gm/aaclip.cpp
@@ -8,6 +8,7 @@
#include "gm.h"
#include "SkCanvas.h"
#include "SkPath.h"
+#include "SkSurface.h"
static void test_quadstroke(SkCanvas* canvas) {
SkPath path;
@@ -122,27 +123,28 @@ static void test_grad(SkCanvas* canvas) {
canvas->drawPaint(p);
}
-static SkCanvas* MakeCanvas(const SkIRect& bounds) {
- SkBitmap bm;
- bm.allocN32Pixels(bounds.width(), bounds.height());
- bm.eraseColor(SK_ColorTRANSPARENT);
-
- SkCanvas* canvas = new SkCanvas(bm);
- canvas->translate(-SkIntToScalar(bounds.fLeft), -SkIntToScalar(bounds.fTop));
- return canvas;
+static SkSurface* MakeSurface(const SkIRect& bounds) {
+ SkImageInfo info = SkImageInfo::MakeN32Premul(bounds.width(),
+ bounds.height());
+ SkSurface* surface = SkSurface::NewRaster(info);
+ surface->getCanvas()->clear(0);
+ surface->getCanvas()->translate(-SkIntToScalar(bounds.fLeft),
+ -SkIntToScalar(bounds.fTop));
+ return surface;
}
+static void compare(SkSurface* a, SkSurface* b) {
#ifdef SK_DEBUG
-static void GetBitmap(const SkCanvas* canvas, SkBitmap* bm) {
- *bm = canvas->getDevice()->accessBitmap(false);
-}
-#endif
+ SkImageInfo infoa, infob;
+ size_t rowBytesa, rowBytesb;
+
+ const void* pa = a->peekPixels(&infoa, &rowBytesa);
+ const void* pb = b->peekPixels(&infob, &rowBytesb);
+ SkASSERT(pa && pb);
-static void compare_canvas(const SkCanvas* a, const SkCanvas* b) {
-#ifdef SK_DEBUG
SkBitmap bma, bmb;
- GetBitmap(a, &bma);
- GetBitmap(b, &bmb);
+ bma.installPixels(infoa, const_cast<void*>(pa), rowBytesa, NULL, NULL);
+ bmb.installPixels(infob, const_cast<void*>(pb), rowBytesb, NULL, NULL);
SkASSERT(bma.width() == bmb.width());
SkASSERT(bma.height() == bmb.height());
@@ -175,13 +177,13 @@ static void test_maskFromPath(const SkPath& path) {
SkPaint paint;
paint.setAntiAlias(true);
- SkAutoTUnref<SkCanvas> path_canvas(MakeCanvas(bounds));
- path_canvas->drawPath(path, paint);
+ SkAutoTUnref<SkSurface> path_surface(MakeSurface(bounds));
+ path_surface->getCanvas()->drawPath(path, paint);
- SkAutoTUnref<SkCanvas> rect_canvas(MakeCanvas(bounds));
- drawRectAsPath(rect_canvas, path.getBounds(), paint);
+ SkAutoTUnref<SkSurface> rect_surface(MakeSurface(bounds));
+ drawRectAsPath(rect_surface->getCanvas(), path.getBounds(), paint);
- compare_canvas(path_canvas, rect_canvas);
+ compare(path_surface, rect_surface);
}
static void test_mask() {
@@ -285,7 +287,7 @@ protected:
if (false) {
test_grad(canvas); return;
}
- if (false) { // avoid bit rot, suppress warning
+ if (true) { // avoid bit rot, suppress warning
test_mask();
}
« no previous file with comments | « no previous file | gm/bitmapcopy.cpp » ('j') | include/core/SkCanvas.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698