diff --git a/shell/BUILD.gn b/shell/BUILD.gn index 89852ea05dda9381a051865da331512f4c2f8c5d..96c676cad9028b3390e00f3a3a40d93895a0a610 100644 --- a/shell/BUILD.gn +++ b/shell/BUILD.gn @@ -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", diff --git a/shell/gpu/picture_serializer.cc b/shell/gpu/picture_serializer.cc new file mode 100644 index 0000000000000000000000000000000000000000..22ea6551daace3df561f7a31eba945c1d51e8542 --- /dev/null +++ b/shell/gpu/picture_serializer.cc @@ -0,0 +1,36 @@ +// 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 data; + + SkBitmap bm; + if (!bm.installPixels(info, const_cast(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 diff --git a/shell/gpu/picture_serializer.h b/shell/gpu/picture_serializer.h new file mode 100644 index 0000000000000000000000000000000000000000..f4300382ca55444abae75e8445910249e000c57c --- /dev/null +++ b/shell/gpu/picture_serializer.h @@ -0,0 +1,16 @@ +// 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_ diff --git a/shell/gpu/rasterizer.cc b/shell/gpu/rasterizer.cc index 4d4ded4aa4fe97094aa32983e145efedc5afe580..f679b8f813c73a76a4c538ff8c68566d4cac6e01 100644 --- a/shell/gpu/rasterizer.cc +++ b/shell/gpu/rasterizer.cc @@ -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 picture) { DrawPicture(picture.get()); surface_->SwapBuffers(); + + // SerializePicture("/data/data/org.domokit.sky.demo/cache/layer0.skp", picture.get()); } void Rasterizer::DrawPicture(SkPicture* picture) {