Serialize SkPictures to the file system

This CL teaches the Sky compositor how to serialize SkPictures to the file
system so that we can study them in the Skia picture debugger.

R=esprehn@chromium.org

Review URL: https://codereview.chromium.org/853863003
This commit is contained in:
Adam Barth
2015-01-21 16:27:28 -08:00
parent 8be2c7c168
commit 90623b7870
4 changed files with 63 additions and 0 deletions

View File

@@ -12,6 +12,8 @@ source_set("compositor") {
"layer_host.h",
"layer_host_client.cc",
"layer_host_client.h",
"picture_serializer.cc",
"picture_serializer.h",
"rasterizer.cc",
"rasterizer.h",
"rasterizer_bitmap.cc",
@@ -44,6 +46,8 @@ source_set("compositor") {
"//mojo/services/surfaces/public/interfaces:surface_id",
"//mojo/skia",
"//skia",
"//third_party/libpng",
"//ui/gfx",
"//ui/gfx/geometry",
]
}

View File

@@ -6,6 +6,7 @@
#include "base/debug/trace_event.h"
#include "sky/compositor/layer_host.h"
#include "sky/compositor/picture_serializer.h"
#include "sky/compositor/rasterizer.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
@@ -26,6 +27,12 @@ void Layer::Display() {
TRACE_EVENT0("sky", "Layer::Display");
DCHECK(rasterizer_);
auto picture = RecordPicture();
#if 0
SerializePicture(
"/data/data/org.chromium.mojo.shell/cache/layer0.skp", picture.get());
#endif
texture_ = rasterizer_->Rasterize(picture.get());
}

View File

@@ -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/compositor/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

View File

@@ -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_COMPOSITOR_PICTURE_SERIALIZER_H_
#define SKY_COMPOSITOR_PICTURE_SERIALIZER_H_
#include "third_party/skia/include/core/SkPicture.h"
namespace sky {
void SerializePicture(const char* file_name, SkPicture*);
} // namespace sky
#endif // SKY_COMPOSITOR_PICTURE_SERIALIZER_H_