Preserve texture compression when saving a revised skp from debugger
Without this CL, saving a revised skp out the debugger can greatly expand the memory it requires.
Review URL: https://codereview.chromium.org/1020103005
diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp
index a8d8f14..ea3564c 100644
--- a/debugger/QT/SkDebuggerGUI.cpp
+++ b/debugger/QT/SkDebuggerGUI.cpp
@@ -12,6 +12,7 @@
#include "SkPictureRecord.h"
#include <QListWidgetItem>
#include <QtGui>
+#include "sk_tool_utils.h"
#if defined(SK_BUILD_FOR_WIN32)
#include "SysTimer_windows.h"
@@ -359,7 +360,8 @@
SkFILEWStream file(filename.c_str());
SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
- copy->serialize(&file);
+ sk_tool_utils::PngPixelSerializer serializer;
+ copy->serialize(&file, &serializer);
}
void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
diff --git a/gm/colorwheel.cpp b/gm/colorwheel.cpp
index db2924d..6b9c149 100644
--- a/gm/colorwheel.cpp
+++ b/gm/colorwheel.cpp
@@ -5,7 +5,6 @@
* found in the LICENSE file.
*/
-#include "sk_tool_utils.h"
#include "Resources.h"
#include "SkData.h"
#include "gm.h"
diff --git a/gm/displacement.cpp b/gm/displacement.cpp
index bcf759a..91405d6 100644
--- a/gm/displacement.cpp
+++ b/gm/displacement.cpp
@@ -5,10 +5,10 @@
* found in the LICENSE file.
*/
-#include "sk_tool_utils.h"
#include "SkBitmapSource.h"
#include "SkDisplacementMapEffect.h"
#include "gm.h"
+#include "sk_tool_utils.h"
namespace skiagm {
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index ac750e9..12d9b15 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -28,6 +28,7 @@
#include "SkRecord.h"
#include "SkShader.h"
#include "SkStream.h"
+#include "sk_tool_utils.h"
#if SK_SUPPORT_GPU
#include "SkSurface.h"
@@ -830,18 +831,6 @@
}
#endif
-// Encodes to PNG, unless there is already encoded data, in which case that gets
-// used.
-// FIXME: Share with PictureRenderer.cpp?
-class PngPixelSerializer : public SkPixelSerializer {
-public:
- bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; }
- SkData* onEncodePixels(const SkImageInfo& info, const void* pixels,
- size_t rowBytes) SK_OVERRIDE {
- return SkImageEncoder::EncodeData(info, pixels, rowBytes, SkImageEncoder::kPNG_Type, 100);
- }
-};
-
static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) {
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()),
@@ -850,7 +839,7 @@
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
SkDynamicMemoryWStream wStream;
- PngPixelSerializer serializer;
+ sk_tool_utils::PngPixelSerializer serializer;
picture->serialize(&wStream, &serializer);
return wStream.copyToData();
}
diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp
index 6acd13c..aec153d 100644
--- a/tools/PictureRenderer.cpp
+++ b/tools/PictureRenderer.cpp
@@ -37,6 +37,7 @@
#include "SkTDArray.h"
#include "SkThreadUtils.h"
#include "SkTypes.h"
+#include "sk_tool_utils.h"
static inline SkScalar scalar_log2(SkScalar x) {
static const SkScalar log2_conversion_factor = SkScalarDiv(1, SkScalarLog(2));
@@ -358,19 +359,6 @@
return NULL;
}
-// Encodes to PNG, unless there is already encoded data, in which case that gets
-// used.
-// FIXME: Share with PictureTest.cpp?
-
-class PngPixelSerializer : public SkPixelSerializer {
-public:
- bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; }
- SkData* onEncodePixels(const SkImageInfo& info, const void* pixels,
- size_t rowBytes) SK_OVERRIDE {
- return SkImageEncoder::EncodeData(info, pixels, rowBytes, SkImageEncoder::kPNG_Type, 100);
- }
-};
-
bool RecordPictureRenderer::render(SkBitmap** out) {
SkAutoTDelete<SkBBHFactory> factory(this->getFactory());
SkPictureRecorder recorder;
@@ -385,7 +373,7 @@
// Record the new picture as a new SKP with PNG encoded bitmaps.
SkString skpPath = SkOSPath::Join(fWritePath.c_str(), fInputFilename.c_str());
SkFILEWStream stream(skpPath.c_str());
- PngPixelSerializer serializer;
+ sk_tool_utils::PngPixelSerializer serializer;
picture->serialize(&stream, &serializer);
return true;
}
diff --git a/tools/sk_tool_utils.h b/tools/sk_tool_utils.h
index 48c71e7..8754de6 100644
--- a/tools/sk_tool_utils.h
+++ b/tools/sk_tool_utils.h
@@ -9,7 +9,9 @@
#define sk_tool_utils_DEFINED
#include "SkColor.h"
+#include "SkImageEncoder.h"
#include "SkImageInfo.h"
+#include "SkPixelSerializer.h"
#include "SkTypeface.h"
class SkBitmap;
@@ -55,6 +57,18 @@
sk_tool_utils::draw_checkerboard(canvas, 0xFF999999, 0xFF666666, 8);
}
+ // Encodes to PNG, unless there is already encoded data, in which case that gets
+ // used.
+ class PngPixelSerializer : public SkPixelSerializer {
+ public:
+ bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; }
+ SkData* onEncodePixels(const SkImageInfo& info, const void* pixels,
+ size_t rowBytes) SK_OVERRIDE {
+ return SkImageEncoder::EncodeData(info, pixels, rowBytes,
+ SkImageEncoder::kPNG_Type, 100);
+ }
+ };
+
} // namespace sk_tool_utils
#endif // sk_tool_utils_DEFINED