Commit f66bc9a8 authored by Michael Ludwig's avatar Michael Ludwig Committed by Chromium LUCI CQ

Add dedicated Read/Write overrides for SkTileMode

This simplification was requested as part of feedback to:
https://chromium-review.googlesource.com/c/chromium/src/+/2527768

Bug: skia:9310
Change-Id: I487d38decc258201767e8a7849f1051ced983163
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2600380Reviewed-by: default avatardanakj <danakj@chromium.org>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Cr-Commit-Position: refs/heads/master@{#839642}
parent 7f967e5e
...@@ -41,18 +41,6 @@ bool IsValidPaintShaderType(PaintShader::Type type) { ...@@ -41,18 +41,6 @@ bool IsValidPaintShaderType(PaintShader::Type type) {
static_cast<uint8_t>(PaintShader::Type::kShaderCount); static_cast<uint8_t>(PaintShader::Type::kShaderCount);
} }
// SkTileMode has no defined backing type, so read/write int32_t's.
// If read_mode is a valid tile mode, this returns true and updates mode to the
// equivalent enum value. Otherwise false is returned and mode is not modified.
bool ValidateAndGetSkShaderTileMode(int32_t read_mode, SkTileMode* mode) {
if (read_mode < 0 || read_mode >= kSkTileModeCount) {
return false;
}
*mode = static_cast<SkTileMode>(read_mode);
return true;
}
bool IsValidPaintShaderScalingBehavior(PaintShader::ScalingBehavior behavior) { bool IsValidPaintShaderScalingBehavior(PaintShader::ScalingBehavior behavior) {
return behavior == PaintShader::ScalingBehavior::kRasterAtScale || return behavior == PaintShader::ScalingBehavior::kRasterAtScale ||
behavior == PaintShader::ScalingBehavior::kFixedScale; behavior == PaintShader::ScalingBehavior::kFixedScale;
...@@ -523,16 +511,8 @@ void PaintOpReader::Read(sk_sp<PaintShader>* shader) { ...@@ -523,16 +511,8 @@ void PaintOpReader::Read(sk_sp<PaintShader>* shader) {
ReadSimple(&ref.flags_); ReadSimple(&ref.flags_);
ReadSimple(&ref.end_radius_); ReadSimple(&ref.end_radius_);
ReadSimple(&ref.start_radius_); ReadSimple(&ref.start_radius_);
Read(&ref.tx_);
// See ValidateAndGetSkShaderTileMode Read(&ref.ty_);
int32_t tx = 0;
int32_t ty = 0;
Read(&tx);
Read(&ty);
if (!ValidateAndGetSkShaderTileMode(tx, &ref.tx_) ||
!ValidateAndGetSkShaderTileMode(ty, &ref.ty_)) {
SetInvalid();
}
ReadSimple(&ref.fallback_color_); ReadSimple(&ref.fallback_color_);
ReadSimple(&ref.scaling_behavior_); ReadSimple(&ref.scaling_behavior_);
if (!IsValidPaintShaderScalingBehavior(ref.scaling_behavior_)) if (!IsValidPaintShaderScalingBehavior(ref.scaling_behavior_))
......
...@@ -117,6 +117,15 @@ class CC_PAINT_EXPORT PaintOpReader { ...@@ -117,6 +117,15 @@ class CC_PAINT_EXPORT PaintOpReader {
} }
*blend_mode = static_cast<SkBlendMode>(value); *blend_mode = static_cast<SkBlendMode>(value);
} }
void Read(SkTileMode* tile_mode) {
uint8_t value = 0u;
Read(&value);
if (value >= kSkTileModeCount) {
SetInvalid();
return;
}
*tile_mode = static_cast<SkTileMode>(value);
}
void Read(bool* data) { void Read(bool* data) {
uint8_t value = 0u; uint8_t value = 0u;
Read(&value); Read(&value);
......
...@@ -480,10 +480,8 @@ void PaintOpWriter::Write(const PaintShader* shader, SkFilterQuality quality) { ...@@ -480,10 +480,8 @@ void PaintOpWriter::Write(const PaintShader* shader, SkFilterQuality quality) {
WriteSimple(shader->flags_); WriteSimple(shader->flags_);
WriteSimple(shader->end_radius_); WriteSimple(shader->end_radius_);
WriteSimple(shader->start_radius_); WriteSimple(shader->start_radius_);
// SkTileMode does not have an explicitly defined backing type, so Write(shader->tx_);
// write a consistently sized value. Write(shader->ty_);
Write(static_cast<int32_t>(shader->tx_));
Write(static_cast<int32_t>(shader->ty_));
WriteSimple(shader->fallback_color_); WriteSimple(shader->fallback_color_);
WriteSimple(shader->scaling_behavior_); WriteSimple(shader->scaling_behavior_);
if (shader->local_matrix_) { if (shader->local_matrix_) {
......
...@@ -88,6 +88,7 @@ class CC_PAINT_EXPORT PaintOpWriter { ...@@ -88,6 +88,7 @@ class CC_PAINT_EXPORT PaintOpWriter {
void Write(SkBlendMode blend_mode) { void Write(SkBlendMode blend_mode) {
Write(static_cast<uint8_t>(blend_mode)); Write(static_cast<uint8_t>(blend_mode));
} }
void Write(SkTileMode tile_mode) { Write(static_cast<uint8_t>(tile_mode)); }
void Write(bool data) { Write(static_cast<uint8_t>(data)); } void Write(bool data) { Write(static_cast<uint8_t>(data)); }
// Aligns the memory to the given alignment. // Aligns the memory to the given alignment.
......
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