Commit 57df0676 authored by Khushal's avatar Khushal Committed by Commit Bot

cc: Cache text blobs in the GPU service.

Since skia's internal caching is keyed on text blobs, its important to
reuse the same object. Make sure we cache text blobs in the
ServiceTransferCache to get a cache hit in skia.

R=enne@chromium.org

Bug: 894200
Change-Id: I8808d649ca3520211d034e07e7d4670ffb39094c
Reviewed-on: https://chromium-review.googlesource.com/c/1292722
Commit-Queue: Khushal <khushalsagar@chromium.org>
Reviewed-by: default avatarenne <enne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601404}
parent 65be2351
...@@ -77,6 +77,8 @@ cc_component("paint") { ...@@ -77,6 +77,8 @@ cc_component("paint") {
"skottie_wrapper.h", "skottie_wrapper.h",
"solid_color_analyzer.cc", "solid_color_analyzer.cc",
"solid_color_analyzer.h", "solid_color_analyzer.h",
"textblob_transfer_cache_entry.cc",
"textblob_transfer_cache_entry.h",
"transfer_cache_deserialize_helper.h", "transfer_cache_deserialize_helper.h",
"transfer_cache_entry.cc", "transfer_cache_entry.cc",
"transfer_cache_entry.h", "transfer_cache_entry.h",
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "cc/paint/paint_shader.h" #include "cc/paint/paint_shader.h"
#include "cc/paint/path_transfer_cache_entry.h" #include "cc/paint/path_transfer_cache_entry.h"
#include "cc/paint/shader_transfer_cache_entry.h" #include "cc/paint/shader_transfer_cache_entry.h"
#include "cc/paint/textblob_transfer_cache_entry.h"
#include "cc/paint/transfer_cache_deserialize_helper.h" #include "cc/paint/transfer_cache_deserialize_helper.h"
#include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkRRect.h" #include "third_party/skia/include/core/SkRRect.h"
...@@ -376,6 +377,11 @@ void PaintOpReader::Read(sk_sp<SkColorSpace>* color_space) { ...@@ -376,6 +377,11 @@ void PaintOpReader::Read(sk_sp<SkColorSpace>* color_space) {
void PaintOpReader::Read(sk_sp<SkTextBlob>* blob) { void PaintOpReader::Read(sk_sp<SkTextBlob>* blob) {
AlignMemory(4); AlignMemory(4);
uint32_t blob_id = 0u;
Read(&blob_id);
if (!valid_)
return;
size_t data_bytes = 0u; size_t data_bytes = 0u;
ReadSize(&data_bytes); ReadSize(&data_bytes);
if (remaining_bytes_ < data_bytes || data_bytes == 0u) if (remaining_bytes_ < data_bytes || data_bytes == 0u)
...@@ -383,6 +389,16 @@ void PaintOpReader::Read(sk_sp<SkTextBlob>* blob) { ...@@ -383,6 +389,16 @@ void PaintOpReader::Read(sk_sp<SkTextBlob>* blob) {
if (!valid_) if (!valid_)
return; return;
auto* entry =
options_.transfer_cache->GetEntryAs<ServiceTextBlobTransferCacheEntry>(
blob_id);
if (entry) {
*blob = entry->blob();
memory_ += data_bytes;
remaining_bytes_ -= data_bytes;
return;
}
DCHECK(options_.strike_client); DCHECK(options_.strike_client);
SkDeserialProcs procs; SkDeserialProcs procs;
TypefaceCtx typeface_ctx(options_.strike_client); TypefaceCtx typeface_ctx(options_.strike_client);
...@@ -394,6 +410,9 @@ void PaintOpReader::Read(sk_sp<SkTextBlob>* blob) { ...@@ -394,6 +410,9 @@ void PaintOpReader::Read(sk_sp<SkTextBlob>* blob) {
SetInvalid(); SetInvalid();
return; return;
} }
options_.transfer_cache->CreateLocalEntry(
blob_id, std::make_unique<ServiceTextBlobTransferCacheEntry>(
deserialized_blob, data_bytes));
*blob = std::move(deserialized_blob); *blob = std::move(deserialized_blob);
memory_ += data_bytes; memory_ += data_bytes;
......
...@@ -291,6 +291,10 @@ void PaintOpWriter::Write(const sk_sp<SkTextBlob>& blob) { ...@@ -291,6 +291,10 @@ void PaintOpWriter::Write(const sk_sp<SkTextBlob>& blob) {
if (!valid_) if (!valid_)
return; return;
AlignMemory(4);
uint32_t blob_id = blob->uniqueID();
Write(blob_id);
uint64_t* size_memory = WriteSize(0u); uint64_t* size_memory = WriteSize(0u);
if (!valid_) if (!valid_)
return; return;
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/paint/textblob_transfer_cache_entry.h"
namespace cc {
ServiceTextBlobTransferCacheEntry::ServiceTextBlobTransferCacheEntry(
sk_sp<SkTextBlob> blob,
size_t size)
: blob_(std::move(blob)), size_(size) {}
ServiceTextBlobTransferCacheEntry::~ServiceTextBlobTransferCacheEntry() =
default;
size_t ServiceTextBlobTransferCacheEntry::CachedSize() const {
return size_;
}
bool ServiceTextBlobTransferCacheEntry::Deserialize(
GrContext* context,
base::span<const uint8_t> data) {
NOTREACHED();
return false;
}
} // namespace cc
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_PAINT_TEXTBLOB_TRANSFER_CACHE_ENTRY_H_
#define CC_PAINT_TEXTBLOB_TRANSFER_CACHE_ENTRY_H_
#include "cc/paint/paint_export.h"
#include "cc/paint/transfer_cache_entry.h"
#include "third_party/skia/include/core/SkTextBlob.h"
namespace cc {
class CC_PAINT_EXPORT ServiceTextBlobTransferCacheEntry
: public ServiceTransferCacheEntryBase<TransferCacheEntryType::kTextBlob> {
public:
ServiceTextBlobTransferCacheEntry(sk_sp<SkTextBlob> blob, size_t size);
~ServiceTextBlobTransferCacheEntry() final;
size_t CachedSize() const final;
bool Deserialize(GrContext* context, base::span<const uint8_t> data) final;
const sk_sp<SkTextBlob>& blob() const { return blob_; }
private:
sk_sp<SkTextBlob> blob_;
const size_t size_;
};
} // namespace cc
#endif // CC_PAINT_TEXTBLOB_TRANSFER_CACHE_ENTRY_H_
...@@ -27,8 +27,9 @@ std::unique_ptr<ServiceTransferCacheEntry> ServiceTransferCacheEntry::Create( ...@@ -27,8 +27,9 @@ std::unique_ptr<ServiceTransferCacheEntry> ServiceTransferCacheEntry::Create(
case TransferCacheEntryType::kPath: case TransferCacheEntryType::kPath:
return std::make_unique<ServicePathTransferCacheEntry>(); return std::make_unique<ServicePathTransferCacheEntry>();
case TransferCacheEntryType::kShader: case TransferCacheEntryType::kShader:
// ServiceShaderTransferCache is only created via CreateLocalEntry case TransferCacheEntryType::kTextBlob:
// and is never serialized/deserialized. // ServiceShader/TextBlobTransferCache is only created via
// CreateLocalEntry and is never serialized/deserialized.
return nullptr; return nullptr;
} }
......
...@@ -25,8 +25,9 @@ enum class TransferCacheEntryType : uint32_t { ...@@ -25,8 +25,9 @@ enum class TransferCacheEntryType : uint32_t {
kColorSpace, kColorSpace,
kPath, kPath,
kShader, kShader,
kTextBlob,
// Add new entries above this line, make sure to update kLast. // Add new entries above this line, make sure to update kLast.
kLast = kShader, kLast = kTextBlob,
}; };
// An interface used on the client to serialize a transfer cache entry // An interface used on the client to serialize a transfer cache entry
......
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