Commit dd4145d4 authored by Vladimir Levin's avatar Vladimir Levin Committed by Commit Bot

oop: Serialize PaintImage backed shaders.

This patch serializes PaintShaders of kImage type (backed by
PaintImages).

R=enne@chromium.org, ericrk@chromium.org

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel
Change-Id: I46384a879aac0b4bff7321b3ad20aac97dd8e069
Reviewed-on: https://chromium-review.googlesource.com/865879
Commit-Queue: vmpstr <vmpstr@chromium.org>
Reviewed-by: default avatarenne <enne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#529159}
parent 49a01149
......@@ -358,7 +358,7 @@ void PaintOpReader::Read(sk_sp<PaintShader>* shader) {
ReadSimple(&ref.end_point_);
ReadSimple(&ref.start_degrees_);
ReadSimple(&ref.end_degrees_);
// TODO(vmpstr): Read PaintImage image_. http://crbug.com/737629
Read(&ref.image_);
bool has_record = false;
ReadSimple(&has_record);
if (has_record)
......@@ -396,15 +396,6 @@ void PaintOpReader::Read(sk_sp<PaintShader>* shader) {
// We don't write the cached shader, so don't attempt to read it either.
// TODO(vmpstr): add serialization of this shader type. For the moment
// pretend that this shader doesn't exist and that the serialization is
// successful. Valid ops pre-serialization should not cause deserialization
// failures.
if (shader_type == PaintShader::Type::kImage) {
*shader = nullptr;
return;
}
if (!(*shader)->IsValid()) {
SetInvalid();
return;
......
......@@ -217,7 +217,7 @@ void PaintOpWriter::Write(const PaintShader* shader) {
WriteSimple(shader->end_point_);
WriteSimple(shader->start_degrees_);
WriteSimple(shader->end_degrees_);
// TODO(vmpstr): Write PaintImage image_. http://crbug.com/737629
Write(shader->image_);
if (shader->record_) {
Write(true);
Write(shader->record_.get());
......@@ -588,4 +588,18 @@ void PaintOpWriter::Write(const PaintRecord* record) {
remaining_bytes_ -= serializer.written();
}
void PaintOpWriter::Write(const PaintImage& image) {
if (!image) {
Write(kInvalidImageTransferCacheEntryId);
return;
}
// Note that the filter quality doesn't matter here, since it's not
// serialized. It's only used to determine the decoded draw image that we will
// get. However, since we're requesting a full-sized image decode, the filter
// quality is essentially ignored.
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
kLow_SkFilterQuality, SkMatrix::I());
Write(draw_image);
}
} // namespace cc
......@@ -120,6 +120,7 @@ class CC_PAINT_EXPORT PaintOpWriter {
void Write(const LightingSpotPaintFilter& filter);
void Write(const PaintRecord* record);
void Write(const PaintImage& image);
char* memory_ = nullptr;
size_t size_ = 0u;
......
......@@ -293,8 +293,10 @@ void PaintShader::CreateSkShader(ImageProvider* image_provider,
flags_, local_matrix_ ? &*local_matrix_ : nullptr);
break;
case Type::kImage:
cached_shader_ = image_.GetSkImage()->makeShader(
tx_, ty_, local_matrix_ ? &*local_matrix_ : nullptr);
if (image_) {
cached_shader_ = image_.GetSkImage()->makeShader(
tx_, ty_, local_matrix_ ? &*local_matrix_ : nullptr);
}
break;
case Type::kPaintRecord: {
// Create a recording at the desired scale if this record has images which
......@@ -385,7 +387,9 @@ bool PaintShader::IsValid() const {
return colors_.size() >= 2 &&
(positions_.empty() || positions_.size() == colors_.size());
case Type::kImage:
return !!image_;
// We may not be able to decode the image, in which case it would be
// false, but that would still make a valid shader.
return true;
case Type::kPaintRecord:
return !!record_;
case Type::kShaderCount:
......
......@@ -61,7 +61,19 @@ void ScopedRasterFlags::DecodeImageShader(const SkMatrix& ctm) {
}
const auto& decoded_image = decoded_draw_image.decoded_image();
DCHECK(decoded_image.image() || decoded_image.transfer_cache_entry_id());
// If this image is backed by a transfer cache entry id, then it's suitable
// for serialization. We don't need to do anything here, because the image
// provider (accessed via PaintOpWriter) will get the decode and serialize the
// transfer cache id.
// Note that if we replace this with the decoded paint image, the
// serialization will fail, because a transfer cache backed image cannot on
// its own construct an SkImage which is needed to create an underlying
// SkShader.
if (decoded_image.transfer_cache_entry_id()) {
DCHECK(!decoded_image.image());
return;
}
DCHECK(decoded_image.image());
bool need_scale = !decoded_image.is_scale_adjustment_identity();
if (need_scale) {
......
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