DM: conserve memory when using --skps
authormtklein <mtklein@chromium.org>
Thu, 7 Aug 2014 21:27:03 +0000 (14:27 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 7 Aug 2014 21:27:03 +0000 (14:27 -0700)
 - limit to maximum 1000x1000 viewport like in bench_pictures and nanobench
 - use lazy bitmap decoding when reading the pictures from disk

BUG=skia:
R=reed@google.com, mtklein@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/448263002

dm/DM.cpp
dm/DMSKPTask.cpp
gyp/dm.gypi

index 6256d0d..081c0f0 100644 (file)
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -2,6 +2,7 @@
 // For a high-level overview, please see dm/README.
 
 #include "CrashHandler.h"
+#include "LazyDecodeBitmap.h"
 #include "SkCommonFlags.h"
 #include "SkForceLinking.h"
 #include "SkGraphics.h"
@@ -143,7 +144,8 @@ static void kick_off_skps(const SkTArray<SkString>& skps,
             SkDebugf("Could not read %s.\n", skps[i].c_str());
             exit(1);
         }
-        SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.get()));
+        SkAutoTUnref<SkPicture> pic(
+                SkPicture::CreateFromStream(stream.get(), &sk_tools::LazyDecodeBitmap));
         if (pic.get() == NULL) {
             SkDebugf("Could not read %s as an SkPicture.\n", skps[i].c_str());
             exit(1);
index 357d46e..3d02915 100644 (file)
@@ -6,6 +6,8 @@
 #include "SkPictureRecorder.h"
 
 DEFINE_bool(skr, true, "Test that SKPs draw the same when re-recorded with SkRecord backend.");
+DEFINE_int32(skpMaxWidth,  1000, "Max SKPTask viewport width.");
+DEFINE_int32(skpMaxHeight, 1000, "Max SKPTask viewport height.");
 
 namespace DM {
 
@@ -28,7 +30,7 @@ public:
         SkAutoTDelete<const SkPicture> skrPicture(recorder.endRecording());
 
         SkBitmap bitmap;
-        AllocatePixels(kN32_SkColorType, fPicture->width(), fPicture->height(), &bitmap);
+        AllocatePixels(kN32_SkColorType, fReference.width(), fReference.height(), &bitmap);
         DrawPicture(*skrPicture, &bitmap);
 
         if (!BitmapsEqual(fReference, bitmap)) {
@@ -48,8 +50,10 @@ SKPTask::SKPTask(Reporter* r, TaskRunner* tr, const SkPicture* pic, SkString fil
     : CpuTask(r, tr), fPicture(SkRef(pic)), fName(FileToTaskName(filename)) {}
 
 void SKPTask::draw() {
+    const int width  = SkTMin(fPicture->width(),  FLAGS_skpMaxWidth),
+              height = SkTMin(fPicture->height(), FLAGS_skpMaxHeight);
     SkBitmap bitmap;
-    AllocatePixels(kN32_SkColorType, fPicture->width(), fPicture->height(), &bitmap);
+    AllocatePixels(kN32_SkColorType, width, height, &bitmap);
     DrawPicture(*fPicture, &bitmap);
 
     this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
index 1f11e17..92262f3 100644 (file)
@@ -50,6 +50,7 @@
     '../src/utils/debugger/SkDebugCanvas.cpp',
     '../src/utils/debugger/SkDrawCommand.cpp',
     '../src/utils/debugger/SkObjectParser.cpp',
+    '../tools/LazyDecodeBitmap.cpp',
   ],
   'conditions': [
     [ 'skia_gpu == 1', {