Enable automatic rescaling in bench_pictures
bench_pictures with "--device gpu" is failing because we're trying to allocate
too much GPU memory. Move the recently-added scaling code into picture_utils
and share it between render_pictures and bench_pictures.
Review URL: https://codereview.appspot.com/6495125
git-svn-id: http://skia.googlecode.com/svn/trunk@5543 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tools/render_pictures_main.cpp b/tools/render_pictures_main.cpp
index 87d5d4b..7d54516 100644
--- a/tools/render_pictures_main.cpp
+++ b/tools/render_pictures_main.cpp
@@ -89,27 +89,6 @@
}
}
-static bool area_too_big(int w, int h, SkISize* newSize) {
- // just a guess, based on what seems to fail on smaller android devices
- static const int64_t kMaxAreaForMemory = 16 * 1024 * 1024;
-
- if ((int64_t)w * h > kMaxAreaForMemory) {
- do {
- w >>= 1;
- h >>= 1;
- } while ((int64_t)w * h > kMaxAreaForMemory);
- if (0 == w) {
- w = 1;
- }
- if (0 == h) {
- h = 1;
- }
- newSize->set(w, h);
- return true;
- }
- return false;
-}
-
static void render_picture(const SkString& inputPath, const SkString& outputDir,
sk_tools::PictureRenderer& renderer) {
SkString inputFilename;
@@ -122,32 +101,16 @@
return;
}
- SkPicture picture(&inputStream);
+ SkPicture* picture = SkNEW_ARGS(SkPicture, (&inputStream));
+ SkAutoTUnref<SkPicture> aur(picture);
- SkDebugf("drawing... [%i %i] %s\n", picture.width(), picture.height(),
+ SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(),
inputPath.c_str());
+ // rescale to avoid memory issues allocating a very large offscreen
+ sk_tools::resize_if_needed(&aur);
- // rescale to avoid memory issues allcoating a very large offscreen
- SkPicture* pic = &picture;
- SkISize newSize;
- SkAutoUnref aur(NULL);
-
- if (area_too_big(picture.width(), picture.height(), &newSize)) {
- pic = new SkPicture;
- aur.reset(pic);
-
- SkCanvas* canvas = pic->beginRecording(newSize.width(), newSize.height());
- SkScalar scale = SkIntToScalar(newSize.width()) / picture.width();
- canvas->scale(scale, scale);
- canvas->drawPicture(picture);
- pic->endRecording();
-
- SkDebugf("... rescaling to [%d %d] to avoid overly large allocations\n",
- newSize.width(), newSize.height());
- }
-
- renderer.init(pic);
+ renderer.init(aur);
renderer.render(true);