Make playback params use SkM44
Part of the greater effort to migrate cc and the paint_op_buffer away
from SkMatrix, which is 3x3 and relatively slow, compared to SkM44.
Playback parameters in the paint operation buffer currently stores the
transformation matrix that was on the canvas at the time of creation
(original_ctm). This is necessary so the recording can play nicely with
save/restore functions.
Playback parameters, like everything with the paint op buffer, used
SkMatrix to store transforms. SkMatrix is deprecated for the faster and
more capable (i.e. can store 3d and non-affine 2d transforms) SkM44.
This CL is a step in the migration away from SkMatrix towards SkM44.
Bug: 1155544
Change-Id: I26e7329b62d336d92d42b58966d70c112dac8dd9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2575760
Reviewed-by: Khushal <khushalsagar@chromium.org>
Reviewed-by: Juanmi Huertas <juanmihd@chromium.org>
Commit-Queue: Aaron Krajeski <aaronhk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835233}
diff --git a/cc/paint/discardable_image_map.cc b/cc/paint/discardable_image_map.cc
index c0ed817..5e461f0 100644
--- a/cc/paint/discardable_image_map.cc
+++ b/cc/paint/discardable_image_map.cc
@@ -96,7 +96,7 @@
// Prevent PaintOpBuffers from having side effects back into the canvas.
SkAutoCanvasRestore save_restore(canvas, true);
- PlaybackParams params(nullptr, canvas->getTotalMatrix());
+ PlaybackParams params(nullptr, canvas->getLocalToDevice());
// TODO(khushalsagar): Optimize out save/restore blocks if there are no
// images in the draw ops between them.
for (auto* op : PaintOpBuffer::Iterator(buffer)) {
diff --git a/cc/paint/display_item_list.cc b/cc/paint/display_item_list.cc
index aa047ab..6521f7c 100644
--- a/cc/paint/display_item_list.cc
+++ b/cc/paint/display_item_list.cc
@@ -253,7 +253,7 @@
if (include_items) {
state->BeginArray("items");
- PlaybackParams params(nullptr, SkMatrix::I());
+ PlaybackParams params(nullptr, SkM44());
std::map<size_t, gfx::Rect> visual_rects = rtree_.GetAllBoundsForTracing();
for (const PaintOp* op : PaintOpBuffer::Iterator(&paint_op_buffer_)) {
state->BeginDictionary();
diff --git a/cc/paint/paint_op_buffer.cc b/cc/paint/paint_op_buffer.cc
index ce783ca8..43a6995 100644
--- a/cc/paint/paint_op_buffer.cc
+++ b/cc/paint/paint_op_buffer.cc
@@ -311,10 +311,10 @@
}
PlaybackParams::PlaybackParams(ImageProvider* image_provider)
- : PlaybackParams(image_provider, SkMatrix::I()) {}
+ : PlaybackParams(image_provider, SkM44()) {}
PlaybackParams::PlaybackParams(ImageProvider* image_provider,
- const SkMatrix& original_ctm,
+ const SkM44& original_ctm,
CustomDataRasterCallback custom_callback,
DidDrawOpCallback did_draw_op_callback)
: image_provider(image_provider),
@@ -1740,17 +1740,13 @@
void SetMatrixOp::Raster(const SetMatrixOp* op,
SkCanvas* canvas,
const PlaybackParams& params) {
- canvas->setMatrix(SkMatrix::Concat(params.original_ctm, op->matrix));
+ canvas->setMatrix(SkM44(op->matrix) * params.original_ctm);
}
void SetMatrix44Op::Raster(const SetMatrix44Op* op,
SkCanvas* canvas,
const PlaybackParams& params) {
- // TODO(aaronhk) when PlaybackParams stores an SKM44:
- // setMatrix(op->matrix * params.original_ctm)
- SkM44 result_matrix = SkM44(params.original_ctm);
- result_matrix.postConcat(op->matrix);
- canvas->setMatrix(result_matrix);
+ canvas->setMatrix(op->matrix * params.original_ctm);
}
void SetNodeIdOp::Raster(const SetNodeIdOp* op,
@@ -2858,7 +2854,7 @@
// translate(x, y), then draw a paint record with a SetMatrix(identity),
// the translation should be preserved instead of clobbering the top level
// transform. This could probably be done more efficiently.
- PlaybackParams new_params(params.image_provider, canvas->getTotalMatrix(),
+ PlaybackParams new_params(params.image_provider, canvas->getLocalToDevice(),
params.custom_callback,
params.did_draw_op_callback);
new_params.save_layer_alpha_should_preserve_lcd_text =
diff --git a/cc/paint/paint_op_buffer.h b/cc/paint/paint_op_buffer.h
index 04533b66..1b5932b 100644
--- a/cc/paint/paint_op_buffer.h
+++ b/cc/paint/paint_op_buffer.h
@@ -44,6 +44,8 @@
class ImageProvider;
class ServicePaintCache;
+// TODO(aaronhk) I think this can be removed when the SkMatrix functions are
+// removed (crbug.com/1155544)
class CC_PAINT_EXPORT ThreadsafeMatrix : public SkMatrix {
public:
explicit ThreadsafeMatrix(const SkMatrix& matrix) : SkMatrix(matrix) {
@@ -122,7 +124,7 @@
explicit PlaybackParams(ImageProvider* image_provider);
PlaybackParams(
ImageProvider* image_provider,
- const SkMatrix& original_ctm,
+ const SkM44& original_ctm,
CustomDataRasterCallback custom_callback = CustomDataRasterCallback(),
DidDrawOpCallback did_draw_op_callback = DidDrawOpCallback());
~PlaybackParams();
@@ -131,8 +133,7 @@
PlaybackParams& operator=(const PlaybackParams& other);
ImageProvider* image_provider;
- // TODO(aaronhk) turn this into an SkM44
- SkMatrix original_ctm;
+ SkM44 original_ctm;
CustomDataRasterCallback custom_callback;
DidDrawOpCallback did_draw_op_callback;
base::Optional<bool> save_layer_alpha_should_preserve_lcd_text;
diff --git a/cc/paint/paint_op_buffer_fuzzer.cc b/cc/paint/paint_op_buffer_fuzzer.cc
index 562f62f..152b78b6 100644
--- a/cc/paint/paint_op_buffer_fuzzer.cc
+++ b/cc/paint/paint_op_buffer_fuzzer.cc
@@ -79,7 +79,7 @@
context_provider->GrContext(), SkBudgeted::kYes, image_info);
SkCanvas* canvas = surface->getCanvas();
- cc::PlaybackParams params(nullptr, canvas->getTotalMatrix());
+ cc::PlaybackParams params(nullptr, canvas->getLocalToDevice());
cc::TransferCacheTestHelper transfer_cache_helper;
std::vector<uint8_t> scratch_buffer;
cc::PaintOp::DeserializeOptions deserialize_options(
diff --git a/cc/paint/paint_op_buffer_serializer.cc b/cc/paint/paint_op_buffer_serializer.cc
index 1c54872..6b16039 100644
--- a/cc/paint/paint_op_buffer_serializer.cc
+++ b/cc/paint/paint_op_buffer_serializer.cc
@@ -35,7 +35,7 @@
PlaybackParams MakeParams(const SkCanvas* canvas) {
// We don't use an ImageProvider here since the ops are played onto a no-draw
// canvas for state tracking and don't need decoded images.
- return PlaybackParams(nullptr, canvas->getTotalMatrix());
+ return PlaybackParams(nullptr, canvas->getLocalToDevice());
}
// Use half of the max int as the extent for the SkNoDrawCanvas. The correct
diff --git a/cc/paint/paint_op_buffer_unittest.cc b/cc/paint/paint_op_buffer_unittest.cc
index 4542cc48..6f3e4b9 100644
--- a/cc/paint/paint_op_buffer_unittest.cc
+++ b/cc/paint/paint_op_buffer_unittest.cc
@@ -3545,7 +3545,7 @@
buffer.push<CustomDataOp>(9999u);
testing::StrictMock<MockCanvas> canvas;
EXPECT_CALL(canvas, onCustomCallback(&canvas, 9999)).Times(1);
- buffer.Playback(&canvas, PlaybackParams(nullptr, SkMatrix::I(),
+ buffer.Playback(&canvas, PlaybackParams(nullptr, SkM44(),
base::BindRepeating(
&MockCanvas::onCustomCallback,
base::Unretained(&canvas))));
diff --git a/cc/paint/skia_paint_canvas.cc b/cc/paint/skia_paint_canvas.cc
index fcda71d..98ca1561 100644
--- a/cc/paint/skia_paint_canvas.cc
+++ b/cc/paint/skia_paint_canvas.cc
@@ -270,7 +270,7 @@
}
const PaintFlags* raster_flags = scoped_flags ? scoped_flags->flags() : flags;
- PlaybackParams params(image_provider_, canvas_->getTotalMatrix());
+ PlaybackParams params(image_provider_, canvas_->getLocalToDevice());
DrawImageOp draw_image_op(image, left, top, nullptr);
DrawImageOp::RasterWithFlags(&draw_image_op, raster_flags, canvas_, params);
FlushAfterDrawIfNeeded();
@@ -290,7 +290,7 @@
}
const PaintFlags* raster_flags = scoped_flags ? scoped_flags->flags() : flags;
- PlaybackParams params(image_provider_, canvas_->getTotalMatrix());
+ PlaybackParams params(image_provider_, canvas_->getLocalToDevice());
DrawImageRectOp draw_image_rect_op(image, src, dst, flags, constraint);
DrawImageRectOp::RasterWithFlags(&draw_image_rect_op, raster_flags, canvas_,
params);
@@ -373,7 +373,7 @@
? base::BindRepeating(&SkiaPaintCanvas::FlushAfterDrawIfNeeded,
base::Unretained(this))
: PlaybackParams::DidDrawOpCallback();
- PlaybackParams params(image_provider_, canvas_->getTotalMatrix(),
+ PlaybackParams params(image_provider_, canvas_->getLocalToDevice(),
custom_raster_callback, did_draw_op_cb);
record->Playback(canvas_, params);
}
diff --git a/cc/paint/solid_color_analyzer.cc b/cc/paint/solid_color_analyzer.cc
index b50ef7e1..8063e05 100644
--- a/cc/paint/solid_color_analyzer.cc
+++ b/cc/paint/solid_color_analyzer.cc
@@ -236,6 +236,7 @@
: iter(iter), original_ctm(original_ctm), save_count(save_count) {}
PaintOpBuffer::CompositeIterator iter;
+ // TODO(aaronhk) should be an SkM44 crbug.com/1155544
const SkMatrix original_ctm;
int save_count = 0;
};
@@ -263,7 +264,7 @@
}
const PaintOp* op = *frame.iter;
- PlaybackParams params(nullptr, frame.original_ctm);
+ PlaybackParams params(nullptr, SkM44(frame.original_ctm));
switch (op->GetType()) {
case PaintOpType::DrawRecord: {
const DrawRecordOp* record_op = static_cast<const DrawRecordOp*>(op);
diff --git a/gpu/command_buffer/service/raster_decoder.cc b/gpu/command_buffer/service/raster_decoder.cc
index 93529a1..9c4cf19 100644
--- a/gpu/command_buffer/service/raster_decoder.cc
+++ b/gpu/command_buffer/service/raster_decoder.cc
@@ -3030,7 +3030,7 @@
alignas(
cc::PaintOpBuffer::PaintOpAlign) char data[sizeof(cc::LargestPaintOp)];
- cc::PlaybackParams playback_params(nullptr, SkMatrix::I());
+ cc::PlaybackParams playback_params(nullptr, SkM44());
TransferCacheDeserializeHelperImpl impl(raster_decoder_id_, transfer_cache());
cc::PaintOp::DeserializeOptions options(
&impl, paint_cache_.get(), font_manager_->strike_client(),