Replace SkPicture(SkStream) constructors with a factory.
SkPicture:
Remove the constructors which take an SkStream as an argument. Rather
than having to check a variable for success, the factory will return
NULL on failure.
Add a protected function for determining if an SkStream is an SKP
to share code with SkTimedPicture.
In the factory, check for a NULL SkStream.
Use a default decoder (from BUG:
https://code.google.com/p/skia/issues/detail?id=1325)
SkDebuggerGUI:
Call SkPicture::CreateFromStream when necessary.
Write a factory for creating SkTimedPictures and use it.
Use the factory throughout tools.
Add include/lazy to utils and effects gyp include_dirs so SkPicture.h
can reference SkImageDecoder.h which references SkBitmapFactory.h (in
include/lazy).
Changes code Chromium uses, so this will require a temporary Skia
and then a change to Chromium to use the new Skia code.
TODO: Create a decoder that does nothing to be used by pinspect,
lua pictures, etc, and allow it to not assert in SkOrderedReadBuffer.
R=reed@google.com
Review URL: https://codereview.chromium.org/17113004
git-svn-id: http://skia.googlecode.com/svn/trunk@9822 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tools/bench_pictures_main.cpp b/tools/bench_pictures_main.cpp
index 46d97de..720621e 100644
--- a/tools/bench_pictures_main.cpp
+++ b/tools/bench_pictures_main.cpp
@@ -173,16 +173,15 @@
gLruImageCache.setImageCacheLimit(0);
}
- bool success = false;
- SkPicture* picture;
+ SkPicture::InstallPixelRefProc proc;
if (FLAGS_deferImageDecoding) {
- picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &lazy_decode_bitmap));
+ proc = &lazy_decode_bitmap;
} else {
- picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &SkImageDecoder::DecodeMemory));
+ proc = &SkImageDecoder::DecodeMemory;
}
- SkAutoTDelete<SkPicture> ad(picture);
+ SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream, proc));
- if (!success) {
+ if (NULL == picture.get()) {
SkString err;
err.printf("Could not read an SkPicture from %s\n", inputPath.c_str());
gLogger.logError(err);
diff --git a/tools/filtermain.cpp b/tools/filtermain.cpp
index 4114a9d..39c484d 100644
--- a/tools/filtermain.cpp
+++ b/tools/filtermain.cpp
@@ -666,7 +666,7 @@
SkFILEStream inStream(inFile.c_str());
if (inStream.isValid()) {
- inPicture.reset(SkNEW_ARGS(SkPicture, (&inStream, NULL, &SkImageDecoder::DecodeMemory)));
+ inPicture.reset(SkPicture::CreateFromStream(&inStream));
}
if (NULL == inPicture.get()) {
diff --git a/tools/lua/lua_pictures.cpp b/tools/lua/lua_pictures.cpp
index 02b9a57..f1bca28 100644
--- a/tools/lua/lua_pictures.cpp
+++ b/tools/lua/lua_pictures.cpp
@@ -46,13 +46,7 @@
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
SkPicture* pic = NULL;
if (stream.get()) {
- bool success;
- pic = SkNEW_ARGS(SkPicture, (stream.get(), &success,
- &lazy_decode_bitmap));
- if (!success) {
- SkDELETE(pic);
- pic = NULL;
- }
+ pic = SkPicture::CreateFromStream(stream.get(), &lazy_decode_bitmap);
}
return pic;
}
diff --git a/tools/pinspect.cpp b/tools/pinspect.cpp
index f6304e6..969d87c 100644
--- a/tools/pinspect.cpp
+++ b/tools/pinspect.cpp
@@ -40,11 +40,10 @@
}
stream.rewind();
- bool success = false;
- SkPicture* pic = SkNEW_ARGS(SkPicture, (&stream, &success, &lazy_decode_bitmap));
- if (!success) {
+ SkPicture* pic = SkPicture::CreateFromStream(&stream, &lazy_decode_bitmap);
+ if (NULL == pic) {
SkDebugf("Could not create SkPicture: %s\n", path);
- return pic;
+ return NULL;
}
printf("picture size:[%d %d]\n", pic->width(), pic->height());
return pic;
diff --git a/tools/render_pdfs_main.cpp b/tools/render_pdfs_main.cpp
index 1821548..f443502 100644
--- a/tools/render_pdfs_main.cpp
+++ b/tools/render_pdfs_main.cpp
@@ -9,7 +9,6 @@
#include "SkDevice.h"
#include "SkForceLinking.h"
#include "SkGraphics.h"
-#include "SkImageDecoder.h"
#include "SkImageEncoder.h"
#include "SkOSFile.h"
#include "SkPicture.h"
@@ -169,11 +168,9 @@
return false;
}
- bool success = false;
- SkAutoTUnref<SkPicture>
- picture(SkNEW_ARGS(SkPicture, (&inputStream, &success, &SkImageDecoder::DecodeMemory)));
+ SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream));
- if (!success) {
+ if (NULL == picture.get()) {
SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str());
return false;
}
@@ -185,7 +182,7 @@
renderer.render();
- success = write_output(outputDir, inputFilename, renderer);
+ bool success = write_output(outputDir, inputFilename, renderer);
renderer.end();
return success;
diff --git a/tools/render_pictures_main.cpp b/tools/render_pictures_main.cpp
index 4a7e708..de477d3 100644
--- a/tools/render_pictures_main.cpp
+++ b/tools/render_pictures_main.cpp
@@ -149,21 +149,22 @@
return false;
}
- SkDebugf("deserializing... %s\n", inputPath.c_str());
-
- bool success = false;
- SkPicture* picture;
+ SkPicture::InstallPixelRefProc proc;
if (FLAGS_deferImageDecoding) {
- picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &lazy_decode_bitmap));
+ proc = &lazy_decode_bitmap;
} else if (FLAGS_writeEncodedImages) {
SkASSERT(!FLAGS_writePath.isEmpty());
reset_image_file_base_name(inputFilename);
- picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &write_image_to_file));
+ proc = &write_image_to_file;
} else {
- picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &SkImageDecoder::DecodeMemory));
+ proc = &SkImageDecoder::DecodeMemory;
}
- if (!success) {
+ SkDebugf("deserializing... %s\n", inputPath.c_str());
+
+ SkPicture* picture = SkPicture::CreateFromStream(&inputStream, proc);
+
+ if (NULL == picture) {
SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str());
return false;
}
@@ -186,7 +187,7 @@
make_output_filepath(outputPath, *outputDir, inputFilename);
}
- success = renderer.render(outputPath, out);
+ bool success = renderer.render(outputPath, out);
if (outputPath) {
if (!success) {
SkDebugf("Could not write to file %s\n", outputPath->c_str());