refactor DM::SetupBitmap
Seemed sort of repetitive.
BUG=skia:
R=reed@google.com, mtklein@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/286993005
git-svn-id: http://skia.googlecode.com/svn/trunk@14752 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/dm/DMBenchTask.cpp b/dm/DMBenchTask.cpp
index bcedb96..917e861 100644
--- a/dm/DMBenchTask.cpp
+++ b/dm/DMBenchTask.cpp
@@ -54,7 +54,7 @@
static void draw_raster(SkBenchmark* bench, SkColorType colorType) {
SkBitmap bitmap;
- SetupBitmap(colorType, bench, &bitmap);
+ AllocatePixels(colorType, bench->getSize().x(), bench->getSize().y(), &bitmap);
SkCanvas canvas(bitmap);
bench->preDraw();
diff --git a/dm/DMCpuGMTask.cpp b/dm/DMCpuGMTask.cpp
index eb7ed99..add5b38 100644
--- a/dm/DMCpuGMTask.cpp
+++ b/dm/DMCpuGMTask.cpp
@@ -26,7 +26,7 @@
void CpuGMTask::draw() {
SkBitmap bitmap;
- SetupBitmap(fColorType, fGM.get(), &bitmap);
+ AllocatePixels(fColorType, fGM->getISize().width(), fGM->getISize().height(), &bitmap);
SkCanvas canvas(bitmap);
canvas.concat(fGM->getInitialTransform());
diff --git a/dm/DMPipeTask.cpp b/dm/DMPipeTask.cpp
index 13636d6..22404ec 100644
--- a/dm/DMPipeTask.cpp
+++ b/dm/DMPipeTask.cpp
@@ -45,7 +45,7 @@
void PipeTask::draw() {
SkBitmap bitmap;
- SetupBitmap(fReference.colorType(), fGM.get(), &bitmap);
+ AllocatePixels(fReference, &bitmap);
SkCanvas canvas(bitmap);
PipeController pipeController(&canvas, &SkImageDecoder::DecodeMemory);
diff --git a/dm/DMQuiltTask.cpp b/dm/DMQuiltTask.cpp
index e8f8b60..f184980 100644
--- a/dm/DMQuiltTask.cpp
+++ b/dm/DMQuiltTask.cpp
@@ -25,7 +25,7 @@
SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get()));
SkBitmap full;
- SetupBitmap(fReference.colorType(), fGM.get(), &full);
+ AllocatePixels(fReference, &full);
SkCanvas fullCanvas(full);
SkBitmap tile;
diff --git a/dm/DMRecordTask.cpp b/dm/DMRecordTask.cpp
index ce27aaa..8241ac5 100644
--- a/dm/DMRecordTask.cpp
+++ b/dm/DMRecordTask.cpp
@@ -47,11 +47,7 @@
// Draw the SkRecord back into a bitmap.
SkBitmap bitmap;
- if (fGM.get()) {
- SetupBitmap(fReference.colorType(), fGM.get(), &bitmap);
- } else {
- SetupBitmap(fReference.colorType(), *fPicture, &bitmap);
- }
+ AllocatePixels(fReference, &bitmap);
SkCanvas target(bitmap);
SkRecordDraw(record, &target);
diff --git a/dm/DMReplayTask.cpp b/dm/DMReplayTask.cpp
index a126f2c..8683879 100644
--- a/dm/DMReplayTask.cpp
+++ b/dm/DMReplayTask.cpp
@@ -30,7 +30,7 @@
SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get(), 0, factory.get()));
SkBitmap bitmap;
- SetupBitmap(fReference.colorType(), fGM.get(), &bitmap);
+ AllocatePixels(fReference, &bitmap);
DrawPicture(recorded, &bitmap);
if (!BitmapsEqual(bitmap, fReference)) {
this->fail();
diff --git a/dm/DMSKPTask.cpp b/dm/DMSKPTask.cpp
index 53f8408..04c4184 100644
--- a/dm/DMSKPTask.cpp
+++ b/dm/DMSKPTask.cpp
@@ -19,7 +19,7 @@
void SKPTask::draw() {
SkBitmap bitmap;
- SetupBitmap(kN32_SkColorType, *fPicture, &bitmap);
+ AllocatePixels(kN32_SkColorType, fPicture->width(), fPicture->height(), &bitmap);
DrawPicture(fPicture, &bitmap);
this->spawnChild(SkNEW_ARGS(RecordTask,
diff --git a/dm/DMSerializeTask.cpp b/dm/DMSerializeTask.cpp
index aa0dabe..62c45b3 100644
--- a/dm/DMSerializeTask.cpp
+++ b/dm/DMSerializeTask.cpp
@@ -28,7 +28,7 @@
SkAutoTUnref<SkPicture> reconstructed(SkPicture::CreateFromStream(rStream));
SkBitmap bitmap;
- SetupBitmap(fReference.colorType(), fGM.get(), &bitmap);
+ AllocatePixels(fReference, &bitmap);
DrawPicture(reconstructed, &bitmap);
if (!BitmapsEqual(bitmap, fReference)) {
this->fail();
diff --git a/dm/DMUtil.cpp b/dm/DMUtil.cpp
index 5c75171..bef903d 100644
--- a/dm/DMUtil.cpp
+++ b/dm/DMUtil.cpp
@@ -21,21 +21,13 @@
return recorder.endRecording();
}
-static void setup_bitmap(SkColorType ct, int width, int height, SkBitmap* bitmap) {
+void AllocatePixels(SkColorType ct, int width, int height, SkBitmap* bitmap) {
bitmap->allocPixels(SkImageInfo::Make(width, height, ct, kPremul_SkAlphaType));
bitmap->eraseColor(0x00000000);
}
-void SetupBitmap(SkColorType ct, skiagm::GM* gm, SkBitmap* bitmap) {
- setup_bitmap(ct, gm->getISize().width(), gm->getISize().height(), bitmap);
-}
-
-void SetupBitmap(SkColorType ct, SkBenchmark* bench, SkBitmap* bitmap) {
- setup_bitmap(ct, bench->getSize().x(), bench->getSize().y(), bitmap);
-}
-
-void SetupBitmap(SkColorType ct, const SkPicture& pic, SkBitmap* bitmap) {
- setup_bitmap(ct, pic.width(), pic.height(), bitmap);
+void AllocatePixels(const SkBitmap& reference, SkBitmap* bitmap) {
+ AllocatePixels(reference.colorType(), reference.width(), reference.height(), bitmap);
}
void DrawPicture(SkPicture* picture, SkBitmap* bitmap) {
diff --git a/dm/DMUtil.h b/dm/DMUtil.h
index c2083ba..535d9f2 100644
--- a/dm/DMUtil.h
+++ b/dm/DMUtil.h
@@ -20,11 +20,10 @@
uint32_t recordFlags = 0,
SkBBHFactory* factory = NULL);
-// Prepare bitmap to have gm, bench or picture draw into it with this config.
-// TODO(mtklein): make SkBenchmark::getSize()/GM::getISize() const.
-void SetupBitmap(SkColorType, skiagm::GM* gm, SkBitmap* bitmap);
-void SetupBitmap(SkColorType, SkBenchmark* bench, SkBitmap* bitmap);
-void SetupBitmap(SkColorType, const SkPicture& picture, SkBitmap* bitmap);
+// Allocate an empty bitmap with this size and depth.
+void AllocatePixels(SkColorType, int w, int h, SkBitmap* bitmap);
+// Allocate an empty bitmap the same size and depth as reference.
+void AllocatePixels(const SkBitmap& reference, SkBitmap* bitmap);
// Draw picture to bitmap.
void DrawPicture(SkPicture* picture, SkBitmap* bitmap);