Commit 06f34304 authored by Adrienne Walker's avatar Adrienne Walker Committed by Commit Bot

cc: Serialize SkPaths using the transfer cache

Bug: 815022
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I0856659a87a07369049902f2a1adb7d82fc4bc4a
Reviewed-on: https://chromium-review.googlesource.com/1012187
Commit-Queue: enne <enne@chromium.org>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552542}
parent 2564c15a
......@@ -67,6 +67,8 @@ cc_component("paint") {
"paint_typeface.h",
"paint_typeface_transfer_cache_entry.cc",
"paint_typeface_transfer_cache_entry.h",
"path_transfer_cache_entry.cc",
"path_transfer_cache_entry.h",
"raw_memory_transfer_cache_entry.cc",
"raw_memory_transfer_cache_entry.h",
"record_paint_canvas.cc",
......
......@@ -14,6 +14,7 @@
#include "cc/paint/paint_op_buffer.h"
#include "cc/paint/paint_shader.h"
#include "cc/paint/paint_typeface_transfer_cache_entry.h"
#include "cc/paint/path_transfer_cache_entry.h"
#include "cc/paint/transfer_cache_deserialize_helper.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkRRect.h"
......@@ -213,21 +214,17 @@ void PaintOpReader::Read(SkRRect* rect) {
}
void PaintOpReader::Read(SkPath* path) {
AlignMemory(4);
uint32_t transfer_cache_entry_id;
ReadSimple(&transfer_cache_entry_id);
if (!valid_)
return;
// This is assumed safe from TOCTOU violations as the SkPath deserializing
// function uses an SkRBuffer which reads each piece of memory once much
// like PaintOpReader does. Additionally, paths are later validated in
// PaintOpBuffer.
size_t read_bytes =
path->readFromMemory(const_cast<const char*>(memory_), remaining_bytes_);
if (!read_bytes)
SetInvalid();
memory_ += read_bytes;
remaining_bytes_ -= read_bytes;
auto* entry = transfer_cache_->GetEntryAs<ServicePathTransferCacheEntry>(
transfer_cache_entry_id);
if (entry) {
*path = entry->path();
} else {
valid_ = false;
}
}
void PaintOpReader::Read(PaintFlags* flags) {
......
......@@ -11,6 +11,7 @@
#include "cc/paint/paint_op_buffer_serializer.h"
#include "cc/paint/paint_shader.h"
#include "cc/paint/paint_typeface_transfer_cache_entry.h"
#include "cc/paint/path_transfer_cache_entry.h"
#include "cc/paint/transfer_cache_serialize_helper.h"
#include "third_party/skia/include/core/SkSerialProcs.h"
#include "third_party/skia/include/core/SkTextBlob.h"
......@@ -169,16 +170,13 @@ void PaintOpWriter::Write(const SkRRect& rect) {
}
void PaintOpWriter::Write(const SkPath& path) {
AlignMemory(4);
size_t bytes = path.writeToMemory(nullptr);
EnsureBytes(bytes);
if (!valid_)
return;
size_t bytes_written = path.writeToMemory(memory_);
DCHECK_LE(bytes_written, bytes);
memory_ += bytes;
remaining_bytes_ -= bytes;
auto id = path.getGenerationID();
auto locked = transfer_cache_->LockEntry(TransferCacheEntryType::kPath, id);
if (!locked) {
transfer_cache_->CreateEntry(ClientPathTransferCacheEntry(path));
transfer_cache_->AssertLocked(TransferCacheEntryType::kPath, id);
}
Write(id);
}
void PaintOpWriter::Write(const PaintFlags& flags) {
......
// 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/path_transfer_cache_entry.h"
namespace cc {
ClientPathTransferCacheEntry::ClientPathTransferCacheEntry(const SkPath& path)
: path_(path) {
size_ = path_.writeToMemory(nullptr);
}
ClientPathTransferCacheEntry::~ClientPathTransferCacheEntry() = default;
uint32_t ClientPathTransferCacheEntry::Id() const {
return path_.getGenerationID();
}
size_t ClientPathTransferCacheEntry::SerializedSize() const {
return size_;
}
bool ClientPathTransferCacheEntry::Serialize(base::span<uint8_t> data) const {
DCHECK_EQ(data.size(), size_);
size_t bytes_written = path_.writeToMemory(data.data());
CHECK_LE(bytes_written, size_);
return true;
}
ServicePathTransferCacheEntry::ServicePathTransferCacheEntry() = default;
ServicePathTransferCacheEntry::~ServicePathTransferCacheEntry() = default;
size_t ServicePathTransferCacheEntry::CachedSize() const {
return size_;
}
bool ServicePathTransferCacheEntry::Deserialize(
GrContext* context,
base::span<const uint8_t> data) {
size_t read_bytes = path_.readFromMemory(data.data(), data.size());
// Invalid path.
if (read_bytes == 0)
return false;
if (read_bytes > data.size())
return false;
size_ = read_bytes;
return true;
}
} // namespace cc
// Copyright 2017 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_PATH_TRANSFER_CACHE_ENTRY_H_
#define CC_PAINT_PATH_TRANSFER_CACHE_ENTRY_H_
#include "base/containers/span.h"
#include "cc/paint/paint_export.h"
#include "cc/paint/transfer_cache_entry.h"
#include "third_party/skia/include/core/SkPath.h"
namespace cc {
class CC_PAINT_EXPORT ClientPathTransferCacheEntry
: public ClientTransferCacheEntryBase<TransferCacheEntryType::kPath> {
public:
explicit ClientPathTransferCacheEntry(const SkPath& path);
~ClientPathTransferCacheEntry() final;
uint32_t Id() const final;
size_t SerializedSize() const final;
bool Serialize(base::span<uint8_t> data) const final;
private:
SkPath path_;
size_t size_ = 0u;
};
class CC_PAINT_EXPORT ServicePathTransferCacheEntry
: public ServiceTransferCacheEntryBase<TransferCacheEntryType::kPath> {
public:
ServicePathTransferCacheEntry();
~ServicePathTransferCacheEntry() final;
size_t CachedSize() const final;
bool Deserialize(GrContext* context, base::span<const uint8_t> data) final;
const SkPath& path() const { return path_; }
private:
SkPath path_;
size_t size_ = 0;
};
} // namespace cc
#endif // CC_PAINT_PATH_TRANSFER_CACHE_ENTRY_H_
......@@ -10,6 +10,7 @@
#include "cc/paint/color_space_transfer_cache_entry.h"
#include "cc/paint/image_transfer_cache_entry.h"
#include "cc/paint/paint_typeface_transfer_cache_entry.h"
#include "cc/paint/path_transfer_cache_entry.h"
#include "cc/paint/raw_memory_transfer_cache_entry.h"
namespace cc {
......@@ -25,6 +26,8 @@ std::unique_ptr<ServiceTransferCacheEntry> ServiceTransferCacheEntry::Create(
return std::make_unique<ServicePaintTypefaceTransferCacheEntry>();
case TransferCacheEntryType::kColorSpace:
return std::make_unique<ServiceColorSpaceTransferCacheEntry>();
case TransferCacheEntryType::kPath:
return std::make_unique<ServicePathTransferCacheEntry>();
}
return nullptr;
......
......@@ -24,8 +24,9 @@ enum class TransferCacheEntryType : uint32_t {
kImage,
kPaintTypeface,
kColorSpace,
kPath,
// Add new entries above this line, make sure to update kLast.
kLast = kColorSpace,
kLast = kPath,
};
// 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