Commit ee0efa70 authored by Peng Huang's avatar Peng Huang Committed by Commit Bot

Add PaintOpBuffer::Deserialize()

This method is for deserializing paint ops from binary data, and append
paint ops to the PaintOpBuffer. It can be used for reusing
PaintOpBuffer to avoid re-allocating PaintOpBuffers.

It will be useful for multithread chrome GPU experimental. It needs to
deserialize paint ops from command buffer, and store it in shared image.
This change allows reusing existing PaintOpBuffer.

Bug: None
Change-Id: I2f86b6c62f454495e591bbd841b8aa7156780e97
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1906938Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715042}
parent 6a4de4d0
...@@ -2480,14 +2480,10 @@ void PaintOpBuffer::Playback(SkCanvas* canvas, ...@@ -2480,14 +2480,10 @@ void PaintOpBuffer::Playback(SkCanvas* canvas,
} }
} }
sk_sp<PaintOpBuffer> PaintOpBuffer::MakeFromMemory( bool PaintOpBuffer::Deserialize(const volatile void* input,
const volatile void* input, size_t input_size,
size_t input_size, const PaintOp::DeserializeOptions& options) {
const PaintOp::DeserializeOptions& options) { Reset();
auto buffer = sk_make_sp<PaintOpBuffer>();
if (input_size == 0)
return buffer;
size_t total_bytes_read = 0u; size_t total_bytes_read = 0u;
while (total_bytes_read < input_size) { while (total_bytes_read < input_size) {
const volatile void* next_op = const volatile void* next_op =
...@@ -2497,26 +2493,39 @@ sk_sp<PaintOpBuffer> PaintOpBuffer::MakeFromMemory( ...@@ -2497,26 +2493,39 @@ sk_sp<PaintOpBuffer> PaintOpBuffer::MakeFromMemory(
uint32_t skip; uint32_t skip;
if (!PaintOpReader::ReadAndValidateOpHeader( if (!PaintOpReader::ReadAndValidateOpHeader(
next_op, input_size - total_bytes_read, &type, &skip)) { next_op, input_size - total_bytes_read, &type, &skip)) {
return nullptr; return false;
} }
size_t op_skip = ComputeOpSkip(g_type_to_size[type]); size_t op_skip = ComputeOpSkip(g_type_to_size[type]);
const auto* op = g_deserialize_functions[type]( const auto* op = g_deserialize_functions[type](
next_op, skip, buffer->AllocatePaintOp(op_skip), op_skip, options); next_op, skip, AllocatePaintOp(op_skip), op_skip, options);
if (!op) { if (!op) {
// The last allocated op has already been destroyed if it failed to // The last allocated op has already been destroyed if it failed to
// deserialize. Update the buffer's op tracking to exclude it to avoid // deserialize. Update the buffer's op tracking to exclude it to avoid
// access during cleanup at destruction. // access during cleanup at destruction.
buffer->used_ -= op_skip; used_ -= op_skip;
buffer->op_count_--; op_count_--;
return nullptr; return false;
} }
g_analyze_op_functions[type](buffer.get(), op); g_analyze_op_functions[type](this, op);
total_bytes_read += skip; total_bytes_read += skip;
} }
DCHECK_GT(buffer->size(), 0u); DCHECK_GT(size(), 0u);
return true;
}
// static
sk_sp<PaintOpBuffer> PaintOpBuffer::MakeFromMemory(
const volatile void* input,
size_t input_size,
const PaintOp::DeserializeOptions& options) {
auto buffer = sk_make_sp<PaintOpBuffer>();
if (input_size == 0)
return buffer;
if (!buffer->Deserialize(input, input_size, options))
return nullptr;
return buffer; return buffer;
} }
......
...@@ -937,6 +937,12 @@ class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt { ...@@ -937,6 +937,12 @@ class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt {
void Playback(SkCanvas* canvas) const; void Playback(SkCanvas* canvas) const;
void Playback(SkCanvas* canvas, const PlaybackParams& params) const; void Playback(SkCanvas* canvas, const PlaybackParams& params) const;
// Deserialize PaintOps from |input|. The original content will be
// overwritten.
bool Deserialize(const volatile void* input,
size_t input_size,
const PaintOp::DeserializeOptions& options);
static sk_sp<PaintOpBuffer> MakeFromMemory( static sk_sp<PaintOpBuffer> MakeFromMemory(
const volatile void* input, const volatile void* input,
size_t input_size, size_t input_size,
...@@ -949,6 +955,8 @@ class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt { ...@@ -949,6 +955,8 @@ class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt {
size_t bytes_used() const { size_t bytes_used() const {
return sizeof(*this) + reserved_ + subrecord_bytes_used_; return sizeof(*this) + reserved_ + subrecord_bytes_used_;
} }
// Returns the number of bytes used by paint ops.
size_t paint_ops_size() const { return used_ + subrecord_bytes_used_; }
// Returns the total number of ops including sub-records. // Returns the total number of ops including sub-records.
size_t total_op_count() const { return op_count_ + subrecord_op_count_; } size_t total_op_count() const { return op_count_ + subrecord_op_count_; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment