add writePixels to SkSurface --> so we can remove it from canvas
Bug: skia:
Change-Id: Ib35d7bdc113c3fd9f6dfacb42ec61aaa448cb165
Reviewed-on: https://skia-review.googlesource.com/105623
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp
index 2a2ee39..f2ad10c 100644
--- a/tests/WritePixelsTest.cpp
+++ b/tests/WritePixelsTest.cpp
@@ -25,8 +25,6 @@
static const int DEV_W = 100, DEV_H = 100;
static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H);
-static const SkRect DEV_RECT_S = SkRect::MakeWH(DEV_W * SK_Scalar1,
- DEV_H * SK_Scalar1);
static const U8CPU DEV_PAD = 0xee;
static SkPMColor get_canvas_color(int x, int y) {
@@ -113,23 +111,15 @@
return pack_color_type(ct, a, r, g , b);
}
-static void fill_canvas(SkCanvas* canvas) {
+static void fill_surface(SkSurface* surface) {
SkBitmap bmp;
- if (bmp.isNull()) {
- bmp.allocN32Pixels(DEV_W, DEV_H);
- for (int y = 0; y < DEV_H; ++y) {
- for (int x = 0; x < DEV_W; ++x) {
- *bmp.getAddr32(x, y) = get_canvas_color(x, y);
- }
+ bmp.allocN32Pixels(DEV_W, DEV_H);
+ for (int y = 0; y < DEV_H; ++y) {
+ for (int x = 0; x < DEV_W; ++x) {
+ *bmp.getAddr32(x, y) = get_canvas_color(x, y);
}
}
- canvas->save();
- canvas->setMatrix(SkMatrix::I());
- canvas->clipRect(DEV_RECT_S, kReplace_SkClipOp);
- SkPaint paint;
- paint.setBlendMode(SkBlendMode::kSrc);
- canvas->drawBitmap(bmp, 0, 0, &paint);
- canvas->restore();
+ surface->writePixels(bmp, 0, 0);
}
/**
@@ -288,17 +278,17 @@
return true;
}
-static void call_writepixels(SkCanvas* canvas) {
+static void call_writepixels(SkSurface* surface) {
const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
SkPMColor pixel = 0;
- canvas->writePixels(info, &pixel, sizeof(SkPMColor), 0, 0);
+ surface->writePixels({info, &pixel, sizeof(SkPMColor)}, 0, 0);
}
DEF_TEST(WritePixelsSurfaceGenID, reporter) {
const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
auto surface(SkSurface::MakeRaster(info));
uint32_t genID1 = surface->generationID();
- call_writepixels(surface->getCanvas());
+ call_writepixels(surface.get());
uint32_t genID2 = surface->generationID();
REPORTER_ASSERT(reporter, genID1 != genID2);
}
@@ -369,14 +359,14 @@
const SkColorType ct = gSrcConfigs[c].fColorType;
const SkAlphaType at = gSrcConfigs[c].fAlphaType;
- fill_canvas(canvas);
+ fill_surface(surface);
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);
+ surface->writePixels(bmp, rect.fLeft, rect.fTop);
uint32_t idAfter = surface->generationID();
REPORTER_ASSERT(reporter, check_write(reporter, surface, bmp,
@@ -469,7 +459,7 @@
bm.allocPixels(smII);
bm.eraseColor(color);
- surf->getCanvas()->writePixels(bm, 0, 0);
+ surf->writePixels(bm, 0, 0);
return surf->makeImageSnapshot();
}