Add machinery for dumping SkPictures to disk
R=ianh@google.com Review URL: https://codereview.chromium.org/1235813005 .
This commit is contained in:
@@ -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",
|
||||
|
||||
36
engine/src/flutter/shell/gpu/picture_serializer.cc
Normal file
36
engine/src/flutter/shell/gpu/picture_serializer.cc
Normal 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/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
|
||||
16
engine/src/flutter/shell/gpu/picture_serializer.h
Normal file
16
engine/src/flutter/shell/gpu/picture_serializer.h
Normal 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_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) {
|
||||
|
||||
Reference in New Issue
Block a user