2a3009931d
This reverts commit c822672854
.
Reason for revert: broke old skps
Original change's description:
> impl SkSerial picture procs
>
> The picture serialization code is a bit of a mess, with duplicated functions for streams and buffers.
> Could not see how to fix that and land this at the same time, but I will try to circle back and
> simplify if possible afterwards.
>
> Bug: skia:
> Change-Id: I9053fdc476c60f483df013d021e248258181c199
> Reviewed-on: https://skia-review.googlesource.com/83943
> Reviewed-by: Florin Malita <fmalita@chromium.org>
> Commit-Queue: Mike Reed <reed@google.com>
TBR=mtklein@google.com,fmalita@chromium.org,reed@google.com
Change-Id: I68ae019a286691b65cc373cb29c941d6620fd34a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/84460
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
84 lines
2.6 KiB
C++
84 lines
2.6 KiB
C++
/*
|
|
* Copyright 2017 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "Test.h"
|
|
#include "Resources.h"
|
|
#include "sk_tool_utils.h"
|
|
#include "SkCanvas.h"
|
|
#include "SkPicture.h"
|
|
#include "SkPictureRecorder.h"
|
|
#include "SkSerialProcs.h"
|
|
#include "SkSurface.h"
|
|
|
|
static sk_sp<SkImage> picture_to_image(sk_sp<SkPicture> pic) {
|
|
SkIRect r = pic->cullRect().round();
|
|
auto surf = SkSurface::MakeRasterN32Premul(r.width(), r.height());
|
|
surf->getCanvas()->drawPicture(pic);
|
|
return surf->makeImageSnapshot();
|
|
}
|
|
|
|
struct State {
|
|
const char* fStr;
|
|
SkImage* fImg;
|
|
};
|
|
|
|
DEF_TEST(serial_procs_image, reporter) {
|
|
auto src_img = GetResourceAsImage("images/mandrill_128.png");
|
|
const char magic_str[] = "magic signature";
|
|
|
|
const SkSerialImageProc sprocs[] = {
|
|
[](SkImage* img, void* ctx) -> sk_sp<SkData> { return nullptr; },
|
|
[](SkImage* img, void* ctx) { return img->encodeToData(); },
|
|
[](SkImage* img, void* ctx) { return SkData::MakeWithCString(((State*)ctx)->fStr); },
|
|
};
|
|
const SkDeserialImageProc dprocs[] = {
|
|
[](const void* data, size_t length, void*) -> sk_sp<SkImage> {
|
|
SK_ABORT("should not get called");
|
|
return nullptr;
|
|
},
|
|
[](const void* data, size_t length, void*) {
|
|
return SkImage::MakeFromEncoded(SkData::MakeWithCopy(data, length));
|
|
},
|
|
[](const void* data, size_t length, void* ctx) -> sk_sp<SkImage> {
|
|
State* state = (State*)ctx;
|
|
if (length != strlen(state->fStr)+1 || memcmp(data, state->fStr, length)) {
|
|
return nullptr;
|
|
}
|
|
return sk_ref_sp(state->fImg);
|
|
},
|
|
};
|
|
|
|
sk_sp<SkPicture> pic;
|
|
{
|
|
SkPictureRecorder rec;
|
|
SkCanvas* canvas = rec.beginRecording(128, 128);
|
|
canvas->drawImage(src_img, 0, 0, nullptr);
|
|
pic = rec.finishRecordingAsPicture();
|
|
}
|
|
|
|
State state = { magic_str, src_img.get() };
|
|
|
|
SkSerialProcs sproc;
|
|
sproc.fImageCtx = &state;
|
|
SkDeserialProcs dproc;
|
|
dproc.fImageCtx = &state;
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(sprocs); ++i) {
|
|
sproc.fImageProc = sprocs[i];
|
|
auto data = pic->serialize(sproc);
|
|
REPORTER_ASSERT(reporter, data);
|
|
|
|
dproc.fImageProc = dprocs[i];
|
|
auto new_pic = SkPicture::MakeFromData(data, dproc);
|
|
REPORTER_ASSERT(reporter, data);
|
|
|
|
auto dst_img = picture_to_image(new_pic);
|
|
REPORTER_ASSERT(reporter, sk_tool_utils::equal_pixels(src_img.get(), dst_img.get()));
|
|
}
|
|
}
|
|
|