diff options
author | 2015-03-23 05:46:51 -0700 | |
---|---|---|
committer | 2015-03-23 05:46:51 -0700 | |
commit | 3e5c2b1041b15641931638d1d78b30d3c435fc71 (patch) | |
tree | e99928b5b2bf3d17f050bbe9df5d177319f0e16c | |
parent | 8dcb8b04f80eff810e63c2696c01f6150d104109 (diff) |
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
-rw-r--r-- | debugger/QT/SkDebuggerGUI.cpp | 4 | ||||
-rw-r--r-- | gm/colorwheel.cpp | 1 | ||||
-rw-r--r-- | gm/displacement.cpp | 2 | ||||
-rw-r--r-- | tests/PictureTest.cpp | 15 | ||||
-rw-r--r-- | tools/PictureRenderer.cpp | 16 | ||||
-rw-r--r-- | tools/sk_tool_utils.h | 14 |
6 files changed, 22 insertions, 30 deletions
diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp index a8d8f14c21..ea3564ca0d 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 @@ void SkDebuggerGUI::saveToFile(const SkString& filename) { 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 db2924da6f..6b9c149684 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 bcf759a4bf..91405d6592 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 ac750e9a85..12d9b1559b 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 @@ static void test_bad_bitmap() { } #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 @@ static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { 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 6acd13ca0f..aec153d953 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 @@ SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) { 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 @@ bool RecordPictureRenderer::render(SkBitmap** out) { // 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 48c71e7e74..8754de69af 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 @@ namespace sk_tool_utils { 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 |