aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/render_pictures_main.cpp
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-02-22 21:38:35 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-02-22 21:38:35 +0000
commitf8d7d2731318cdf510ab68e6b3f5ec68ab22c8e2 (patch)
treeb62a29fabe0b0af3f8f17ffbe8d607508c1d2c00 /tools/render_pictures_main.cpp
parent5c90e291425b2788f47679266d9584845ceefc2e (diff)
Create SkLazyPixelRef which performs lazy decoding.
The new pixel ref behaves similarly to SkImageRef, with some key differences: It does not depend on the images project. It requires an SkImageCache, which handles allocation and caching of the pixel memory. It takes a function signature for decoding which decodes into already allocated pixel memory rather than into an SkBitmap. Add two implementations of SkImageCache: SkLruImageCache and SkAshmemImageCache. Replace SkSerializationHelpers::DecodeBitmap with SkPicture::InstallPixelRefProc, and update sites that referenced it. SkBitmapFactory now sets the pixel ref to a new object of the new class SkLazyPixelRef, provided it has an SkImageCache for caching. Provide an option to do lazy decodes in render_pictures and bench_pictures. SkPicture: Eliminate the default parameters in the constructor. If a proc for decoding bitmaps is installed, use it to decode any encoded data in subpictures. When parsing deserializing subpictures, check for success. When serializing subpictures, pass the picture's bitmap encoder to the subpicture's call to serialize. Update BitmapFactoryTest to test its new behavior. BUG=https://code.google.com/p/skia/issues/detail?id=1008 BUG=https://code.google.com/p/skia/issues/detail?id=1009 Review URL: https://codereview.appspot.com/7060052 git-svn-id: http://skia.googlecode.com/svn/trunk@7835 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools/render_pictures_main.cpp')
-rw-r--r--tools/render_pictures_main.cpp48
1 files changed, 45 insertions, 3 deletions
diff --git a/tools/render_pictures_main.cpp b/tools/render_pictures_main.cpp
index 3ab5628e6c..146b04552f 100644
--- a/tools/render_pictures_main.cpp
+++ b/tools/render_pictures_main.cpp
@@ -7,6 +7,7 @@
#include "CopyTilesRenderer.h"
#include "SkBitmap.h"
+#include "SkBitmapFactory.h"
#include "SkCanvas.h"
#include "SkDevice.h"
#include "SkGraphics.h"
@@ -35,6 +36,7 @@ static void usage(const char* argv0) {
" [--validate [--maxComponentDiff n]]\n"
" [--writeWholeImage]\n"
" [--clone n]\n"
+" [--enable-deferred-image-decoding]\n"
" [--viewport width height][--scale sf]\n"
" [--device bitmap"
#if SK_SUPPORT_GPU
@@ -83,6 +85,8 @@ static void usage(const char* argv0) {
SkDebugf(
" --multi count : Set the number of threads for multi threaded drawing. Must be greater\n"
" than 1. Only works with tiled rendering.\n"
+" --enable-deferred-image-decoding : Defer decoding until drawing images. Has no effect if\n"
+" the provided skp does not have its images encoded.\n"
" --viewport width height : Set the viewport.\n"
" --scale sf : Scale drawing by sf.\n"
" --pipe: Benchmark SkGPipe rendering. Currently incompatible with \"mode\".\n");
@@ -127,6 +131,39 @@ static void make_output_filepath(SkString* path, const SkString& dir,
path->remove(path->size() - 4, 4);
}
+bool lazy_decode = false;
+
+#include "SkData.h"
+#include "SkLruImageCache.h"
+
+static SkLruImageCache gLruImageCache(1024*1024);
+
+#ifdef SK_BUILD_FOR_ANDROID
+#include "SkAshmemImageCache.h"
+#include "SkImage.h"
+
+static SkImageCache* cache_selector(const SkImage::Info& info) {
+ if (info.fWidth * info.fHeight > 32 * 1024) {
+ return SkAshmemImageCache::GetAshmemImageCache();
+ }
+ return &gLruImageCache;
+}
+
+#endif
+
+static bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap) {
+ void* copiedBuffer = sk_malloc_throw(size);
+ memcpy(copiedBuffer, buffer, size);
+ SkAutoDataUnref data(SkData::NewFromMalloc(copiedBuffer, size));
+ SkBitmapFactory factory(&SkImageDecoder::DecodeMemoryToTarget);
+#ifdef SK_BUILD_FOR_ANDROID
+ factory.setCacheSelector(&cache_selector);
+#else
+ factory.setImageCache(&gLruImageCache);
+#endif
+ return factory.installPixelRef(data, bitmap);
+}
+
static bool render_picture(const SkString& inputPath, const SkString* outputDir,
sk_tools::PictureRenderer& renderer,
SkBitmap** out,
@@ -142,8 +179,12 @@ static bool render_picture(const SkString& inputPath, const SkString* outputDir,
}
bool success = false;
- SkPicture* picture = SkNEW_ARGS(SkPicture,
- (&inputStream, &success, &SkImageDecoder::DecodeStream));
+ SkPicture* picture;
+ if (lazy_decode) {
+ picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &lazy_decode_bitmap));
+ } else {
+ picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &SkImageDecoder::DecodeMemory));
+ }
if (!success) {
SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str());
return false;
@@ -536,7 +577,8 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
usage(argv0);
exit(-1);
}
-
+ } else if (0 == strcmp(*argv, "--enable-deferred-image-decoding")) {
+ lazy_decode = true;
} else if ((0 == strcmp(*argv, "-h")) || (0 == strcmp(*argv, "--help"))) {
SkSafeUnref(renderer);
usage(argv0);