aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar keyar@chromium.org <keyar@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-21 19:05:08 +0000
committerGravatar keyar@chromium.org <keyar@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-21 19:05:08 +0000
commit9299eded3838a7997235ff033aa3b9a8d4c6d4d4 (patch)
tree2905d615f99521ececd9b97a7887f04eac962599 /tools
parentdb9a5fb55f77935774f21e07a04b6d1350ca54cc (diff)
Images are written by PictureRenderer and not render_pictures_main.
Review URL: https://codereview.appspot.com/6448174 git-svn-id: http://skia.googlecode.com/svn/trunk@5216 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools')
-rw-r--r--tools/PictureRenderer.cpp18
-rw-r--r--tools/PictureRenderer.h7
-rw-r--r--tools/picture_utils.cpp15
-rw-r--r--tools/picture_utils.h10
-rw-r--r--tools/render_pictures_main.cpp32
5 files changed, 48 insertions, 34 deletions
diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp
index 290c79a5fe..46b268100f 100644
--- a/tools/PictureRenderer.cpp
+++ b/tools/PictureRenderer.cpp
@@ -9,8 +9,10 @@
#include "SamplePipeControllers.h"
#include "SkCanvas.h"
#include "SkDevice.h"
+#include "SkImageEncoder.h"
#include "SkGPipe.h"
#include "SkPicture.h"
+#include "SkString.h"
#include "SkTDArray.h"
#include "SkTypes.h"
#include "picture_utils.h"
@@ -109,6 +111,22 @@ void PictureRenderer::finishDraw() {
#endif
}
+bool PictureRenderer::write(const SkString& path) const {
+ SkASSERT(fCanvas.get() != NULL);
+ SkASSERT(fPicture != NULL);
+ if (NULL == fCanvas.get() || NULL == fPicture) {
+ return false;
+ }
+
+ SkBitmap bitmap;
+ sk_tools::setup_bitmap(&bitmap, fPicture->width(), fPicture->height());
+
+ fCanvas->readPixels(&bitmap, 0, 0);
+ sk_tools::force_all_opaque(bitmap);
+
+ return SkImageEncoder::EncodeFile(path.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100);
+}
+
void PipePictureRenderer::render() {
SkASSERT(fCanvas.get() != NULL);
SkASSERT(fPicture != NULL);
diff --git a/tools/PictureRenderer.h b/tools/PictureRenderer.h
index 48184570da..cd6e18e373 100644
--- a/tools/PictureRenderer.h
+++ b/tools/PictureRenderer.h
@@ -20,6 +20,7 @@ class SkBitmap;
class SkCanvas;
class SkGLContext;
class SkPicture;
+class SkString;
namespace sk_tools {
@@ -37,10 +38,6 @@ public:
virtual void end();
void resetState();
- SkCanvas* getCanvas() {
- return fCanvas.get();
- }
-
void setDeviceType(SkDeviceTypes deviceType) {
fDeviceType = deviceType;
}
@@ -71,6 +68,8 @@ public:
#endif
{}
+ bool write(const SkString& path) const;
+
protected:
virtual void finishDraw();
SkCanvas* setupCanvas();
diff --git a/tools/picture_utils.cpp b/tools/picture_utils.cpp
index d38cbb0669..d5caf0c7dd 100644
--- a/tools/picture_utils.cpp
+++ b/tools/picture_utils.cpp
@@ -6,12 +6,27 @@
*/
#include "picture_utils.h"
+#include "SkColorPriv.h"
#include "SkBitmap.h"
#include "SkPicture.h"
#include "SkString.h"
#include "SkStream.h"
namespace sk_tools {
+ void force_all_opaque(const SkBitmap& bitmap) {
+ SkASSERT(NULL == bitmap.getTexture());
+ SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config());
+ if (NULL != bitmap.getTexture() || SkBitmap::kARGB_8888_Config == bitmap.config()) {
+ return;
+ }
+
+ SkAutoLockPixels lock(bitmap);
+ for (int y = 0; y < bitmap.height(); y++) {
+ for (int x = 0; x < bitmap.width(); x++) {
+ *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
+ }
+ }
+ }
void make_filepath(SkString* path, const SkString& dir, const SkString& name) {
size_t len = dir.size();
diff --git a/tools/picture_utils.h b/tools/picture_utils.h
index c0c5d8f069..18352f2bdf 100644
--- a/tools/picture_utils.h
+++ b/tools/picture_utils.h
@@ -15,6 +15,14 @@ class SkString;
class SkPicture;
namespace sk_tools {
+ // since PNG insists on unpremultiplying our alpha, we take no precision
+ // chances and force all pixels to be 100% opaque, otherwise on compare we
+ // may not get a perfect match.
+ //
+ // This expects a bitmap with a config type of 8888 and for the pixels to
+ // not be on the GPU.
+ void force_all_opaque(const SkBitmap& bitmap);
+
// Creates a posix style filepath by concatenating name onto dir with a
// forward slash into path.
void make_filepath(SkString* path, const SkString&, const SkString& name);
@@ -22,7 +30,7 @@ namespace sk_tools {
// Returns the last part of the path (file name or leaf directory name)
//
// This basically just looks for a foward slash or backslash (windows
- // only)
+ // only).
void get_basename(SkString* basename, const SkString& path);
// Returns true if the string ends with %
diff --git a/tools/render_pictures_main.cpp b/tools/render_pictures_main.cpp
index dfea915ed2..998123051c 100644
--- a/tools/render_pictures_main.cpp
+++ b/tools/render_pictures_main.cpp
@@ -7,9 +7,7 @@
#include "SkBitmap.h"
#include "SkCanvas.h"
-#include "SkColorPriv.h"
#include "SkDevice.h"
-#include "SkImageEncoder.h"
#include "SkOSFile.h"
#include "SkPicture.h"
#include "SkStream.h"
@@ -68,32 +66,11 @@ static void make_output_filepath(SkString* path, const SkString& dir,
path->append("png");
}
-/* since PNG insists on unpremultiplying our alpha, we take no precision chances
- and force all pixels to be 100% opaque, otherwise on compare we may not get
- a perfect match.
- */
-static void force_all_opaque(const SkBitmap& bitmap) {
- SkAutoLockPixels lock(bitmap);
- for (int y = 0; y < bitmap.height(); y++) {
- for (int x = 0; x < bitmap.width(); x++) {
- *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
- }
- }
-}
-
-static bool write_bitmap(const SkString& path, const SkBitmap& bitmap) {
- SkBitmap copy;
- bitmap.copyTo(&copy, SkBitmap::kARGB_8888_Config);
- force_all_opaque(copy);
- return SkImageEncoder::EncodeFile(path.c_str(), copy,
- SkImageEncoder::kPNG_Type, 100);
-}
-
static void write_output(const SkString& outputDir, const SkString& inputFilename,
- const SkBitmap& bitmap) {
+ const sk_tools::PictureRenderer& renderer) {
SkString outputPath;
make_output_filepath(&outputPath, outputDir, inputFilename);
- bool isWritten = write_bitmap(outputPath, bitmap);
+ bool isWritten = renderer.write(outputPath);
if (!isWritten) {
SkDebugf("Could not write to file %s\n", outputPath.c_str());
}
@@ -112,15 +89,12 @@ static void render_picture(const SkString& inputPath, const SkString& outputDir,
}
SkPicture picture(&inputStream);
- SkBitmap bitmap;
- sk_tools::setup_bitmap(&bitmap, picture.width(), picture.height());
renderer.init(&picture);
renderer.render();
- renderer.getCanvas()->readPixels(&bitmap, 0, 0);
- write_output(outputDir, inputFilename, bitmap);
+ write_output(outputDir, inputFilename, renderer);
renderer.end();
}