提交 29154f00 编写于 作者: A Adam Barth

Add machinery for dumping SkPictures to disk

R=ianh@google.com

Review URL: https://codereview.chromium.org/1235813005 .
上级 50d089eb
......@@ -32,6 +32,8 @@ source_set("common") {
"gpu/ganesh_context.h",
"gpu/ganesh_surface.cc",
"gpu/ganesh_surface.h",
"gpu/picture_serializer.cc",
"gpu/picture_serializer.h",
"gpu/rasterizer.cc",
"gpu/rasterizer.h",
"gpu_delegate.cc",
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/shell/gpu/picture_serializer.h"
#include "third_party/skia/include/core/SkData.h"
#include "third_party/skia/include/core/SkPixelSerializer.h"
#include "third_party/skia/include/core/SkStream.h"
#include "ui/gfx/codec/png_codec.h"
namespace sky {
class PngPixelSerializer : public SkPixelSerializer {
public:
bool onUseEncodedData(const void*, size_t) override { return true; }
SkData* onEncodePixels(const SkImageInfo& info, const void* pixels,
size_t row_bytes) override {
std::vector<unsigned char> data;
SkBitmap bm;
if (!bm.installPixels(info, const_cast<void*>(pixels), row_bytes))
return nullptr;
if (!gfx::PNGCodec::EncodeBGRASkBitmap(bm, false, &data))
return nullptr;
return SkData::NewWithCopy(&data.front(), data.size());
}
};
void SerializePicture(const char* file_name, SkPicture* picture) {
SkFILEWStream stream(file_name);
PngPixelSerializer serializer;
picture->serialize(&stream, &serializer);
}
} // namespace sky
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_SHELL_GPU_PICTURE_SERIALIZER_H_
#define SKY_SHELL_GPU_PICTURE_SERIALIZER_H_
#include "third_party/skia/include/core/SkPicture.h"
namespace sky {
void SerializePicture(const char* file_name, SkPicture*);
} // namespace sky
#endif // SKY_SHELL_GPU_PICTURE_SERIALIZER_H_
......@@ -7,6 +7,7 @@
#include "base/trace_event/trace_event.h"
#include "sky/shell/gpu/ganesh_context.h"
#include "sky/shell/gpu/ganesh_surface.h"
#include "sky/shell/gpu/picture_serializer.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "ui/gl/gl_bindings.h"
......@@ -58,6 +59,8 @@ void Rasterizer::Draw(skia::RefPtr<SkPicture> picture) {
DrawPicture(picture.get());
surface_->SwapBuffers();
// SerializePicture("/data/data/org.domokit.sky.demo/cache/layer0.skp", picture.get());
}
void Rasterizer::DrawPicture(SkPicture* picture) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册