Commit 883ad990 authored by Khushal's avatar Khushal Committed by Commit Bot

cc: Avoid SkData malloc and copy for SkTextBlobs.

PaintOpReader::Read for SkData is used by 2 code-paths, deserializing
SkTextBlobs and AnnotateOps. While AnnotateOp needs to copy the SkData,
the copy for SkTextBlobs is completely unnecessary.

This also uncovered skia caching keyed on text blob ids in
GrAtlasTextContext, which we'll miss in OOP by re-serializing the text
blobs each time. This should be addressed by caching these on the
service side in a follow up.

R=enne@chromium.org
BUG: 821584

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel
Change-Id: I77b47621e0f0bca225377968b02ca5f401804bc0
Reviewed-on: https://chromium-review.googlesource.com/959439
Commit-Queue: Khushal <khushalsagar@chromium.org>
Reviewed-by: default avatarenne <enne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543025}
parent 2472d9bb
......@@ -384,19 +384,21 @@ void PaintOpReader::Read(sk_sp<SkColorSpace>* color_space) {
}
void PaintOpReader::Read(scoped_refptr<PaintTextBlob>* paint_blob) {
sk_sp<SkData> data;
Read(&data);
if (!data || !valid_) {
size_t data_bytes = 0u;
ReadSimple(&data_bytes);
// Skia expects aligned data size, make sure we don't pass it incorrect data.
if (remaining_bytes_ < data_bytes || data_bytes == 0u ||
!SkIsAlign4(data_bytes)) {
SetInvalid();
return;
}
// Skia expects the following to be true, make sure we don't pass it incorrect
// data.
if (!data->data() || !SkIsAlign4(data->size())) {
SetInvalid();
if (!valid_)
return;
}
sk_sp<SkData> data =
SkData::MakeWithoutCopy(const_cast<const char*>(memory_), data_bytes);
memory_ += data_bytes;
remaining_bytes_ -= data_bytes;
TypefacesCatalog catalog;
catalog.transfer_cache = transfer_cache_;
......
......@@ -250,8 +250,13 @@ void PaintOpWriter::Write(const SkColorSpace* color_space) {
}
void PaintOpWriter::Write(const sk_sp<SkTextBlob>& blob) {
// TODO(khushalsagar): Change skia API to serialize directly into shared mem.
auto data = blob->serialize(&TypefaceCataloger, transfer_cache_);
Write(data);
DCHECK(data);
DCHECK_GT(data->size(), 0u);
WriteSize(data->size());
WriteData(data->size(), data->data());
}
void PaintOpWriter::Write(const scoped_refptr<PaintTextBlob>& blob) {
......
......@@ -22,7 +22,7 @@ class CC_PAINT_EXPORT PaintTextBlob
PaintTextBlob(sk_sp<SkTextBlob> blob, std::vector<PaintTypeface> typefaces);
const sk_sp<SkTextBlob>& ToSkTextBlob() const { return sk_blob_; }
const std::vector<PaintTypeface> typefaces() const { return typefaces_; }
const std::vector<PaintTypeface>& typefaces() const { return typefaces_; }
operator bool() const { return !!sk_blob_; }
......
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