| 1 |
/* |
| 2 |
* Copyright 2021 Google LLC |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "include/private/chromium/Slug.h" |
| 9 |
|
| 10 |
#include "include/core/SkCanvas.h" |
| 11 |
#include "include/core/SkPoint.h" |
| 12 |
#include "include/core/SkSerialProcs.h" |
| 13 |
#include "src/core/SkReadBuffer.h" |
| 14 |
#include "src/core/SkWriteBuffer.h" |
| 15 |
|
| 16 |
class SkData; |
| 17 |
|
| 18 |
namespace sktext::gpu { |
| 19 |
|
| 20 |
sk_sp<Slug> Slug::ConvertBlob( |
| 21 |
SkCanvas* canvas, const SkTextBlob& blob, SkPoint origin, const SkPaint& paint) { |
| 22 |
return canvas->convertBlobToSlug(blob, origin, paint); |
| 23 |
} |
| 24 |
|
| 25 |
sk_sp<SkData> Slug::serialize() const { |
| 26 |
SkBinaryWriteBuffer buffer({}); |
| 27 |
this->doFlatten(buffer); |
| 28 |
return buffer.snapshotAsData(); |
| 29 |
} |
| 30 |
|
| 31 |
size_t Slug::serialize(void* buffer, size_t size) const { |
| 32 |
SkBinaryWriteBuffer writeBuffer{buffer, size, {}}; |
| 33 |
this->doFlatten(writeBuffer); |
| 34 |
|
| 35 |
// If we overflow the given buffer, then SkWriteBuffer allocates a new larger buffer. Check |
| 36 |
// to see if an additional buffer was allocated, if it wasn't then everything fit, else |
| 37 |
// return 0 signaling the buffer overflowed. |
| 38 |
// N.B. This is the idiom from SkTextBlob. |
| 39 |
return writeBuffer.usingInitialStorage() ? writeBuffer.bytesWritten() : 0u; |
| 40 |
} |
| 41 |
|
| 42 |
sk_sp<Slug> Slug::Deserialize(const void* data, size_t size, const SkStrikeClient* client) { |
| 43 |
SkReadBuffer buffer{data, size}; |
| 44 |
SkDeserialProcs procs; |
| 45 |
Slug::AddDeserialProcs(&procs, client); |
| 46 |
buffer.setDeserialProcs(procs); |
| 47 |
return MakeFromBuffer(buffer); |
| 48 |
} |
| 49 |
|
| 50 |
void Slug::draw(SkCanvas* canvas, const SkPaint& paint) const { |
| 51 |
canvas->drawSlug(this, paint); |
| 52 |
} |
| 53 |
|
| 54 |
} // namespace sktext::gpu |
| 55 |
|