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
This commit is contained in:
keyar@chromium.org 2012-08-21 19:05:08 +00:00
Родитель db9a5fb55f
Коммит 9299eded38
6 изменённых файлов: 52 добавлений и 37 удалений

Просмотреть файл

@ -76,7 +76,6 @@
],
'dependencies': [
'core.gyp:core',
'images.gyp:images',
'ports.gyp:ports',
'tools.gyp:picture_renderer',
'tools.gyp:picture_utils',
@ -94,10 +93,8 @@
'dependencies': [
'core.gyp:core',
'ports.gyp:ports',
'images.gyp:images',
'tools.gyp:picture_utils',
'tools.gyp:picture_benchmark',
'bench.gyp:bench_timer',
],
},
{
@ -132,8 +129,12 @@
],
'dependencies': [
'core.gyp:core',
'images.gyp:images',
'tools.gyp:picture_utils',
],
'export_dependent_settings': [
'images.gyp:images',
],
'conditions': [
['skia_gpu == 1', {
'dependencies': [

Просмотреть файл

@ -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);

Просмотреть файл

@ -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();

Просмотреть файл

@ -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();

Просмотреть файл

@ -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 %

Просмотреть файл

@ -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();
}