Hi
I have modified the
Serialize method to Record all PaintOp as SKPicture.
I want to replay this SKPicture on a remote browser. So, I am trying to save this SKPicture to a file, but I am not able to do so, since file.isOpen gives false.
Please help here
void PaintOpBufferSerializer::Serialize(const PaintOpBuffer& buffer,
const std::vector<size_t>* offsets,
const Preamble& preamble) {
DCHECK_EQ(serialized_op_count_, 0u);
std::unique_ptr<SkCanvas> canvas = MakeAnalysisCanvas(options_);
// These PlaybackParams use the initial (identity) canvas matrix, as they are
// only used for serializing the preamble and the initial save / final restore
// SerializeBuffer will create its own PlaybackParams based on the
SkPictureRecorder recorder;
SkCanvas* recordingCanvas = recorder.beginRecording(canvas->getLocalClipBounds());
// post-preamble canvas.
PlaybackParams params = MakeParams(canvas.get());
int save_count = canvas->getSaveCount();
Save(canvas.get(), params);
SerializePreamble(canvas.get(), preamble, params);
SerializeBuffer(canvas.get(), buffer, offsets);
SerializeBuffer(recordingCanvas, buffer, offsets);
sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
SkSerialProcs sProcs;
sk_sp<SkData> readableData = picture->serialize(&sProcs);
// Assuming the byte array is stored in the 'data' field of the SkData object
const void* data = readableData->data();
size_t size = readableData->size();
<HOW TO SAVE READABLE DATA TO A FILE>
/*sk_sp<SkData> receievedData = SkData::MakeWithoutCopy(data, size);
sk_sp<SkPicture> copy =
SkPicture::MakeFromData(receievedData->data(), receievedData->size());
copy->playback(recordingCanvas);*/
RestoreToCount(canvas.get(), save_count, params);
}