[go: nahoru, domu]

Prepare for removing sk_sp<PaintOpBuffer>

This CL separates PaintOpBuffer and PaintRecord:
- PaintOpBuffer can be mutable. When it's mutable, it should have
  a unique owner.
- PaintRecord is imutable and can be cheaply moved and copied (with
  internal data shared). It wraps a sk_sp<PaintOpBuffer>
  (temporarily[1]) and exposes read-only methods of PaintOpBuffer.

PaintOpBuffer::ReleaseAsRecord() returns a PaintRecord. This ensures
we can get a PaintRecord from a PaintOpBuffer only when the
PaintOpBuffer finishes recording. The PaintRecord shares nothing with
the original PaintOpBuffer, so that PaintOpBuffer can start a new
recording from scratch.

PaintRecord::buffer() returns `const PaintOpBuffer&` to meet
requirements of APIs needing a `const PaintOpBuffer&`.

sk_sp<PaintRecord> usages are changed to:
- PaintRecord: in most places;
- const PaintRecord&: where we don't need to transfer/share ownership
  of the PaintRecord;
- absl::optional<PaintRecord>: where previously nullptr was allowed
  and nullptr was distinguished from an empty PaintRecord.

Most sk_sp<PaintOpBuffer> usages are changed to use PaintOpBuffer
directly or under absl::optional<>, except where ref-counting is
really needed (i.e. in PaintRecord).

[1] In a followup, sk_sp<PaintOpBuffer> will also be removed, and
    PaintRecord will wrap PaintOpBuffer directly.

Bug: 1385848
Change-Id: I5be6ef1d37d0a2bda48e86adc62a35b13c81a48e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4094931
Reviewed-by: Vladimir Levin <vmpstr@chromium.org>
Reviewed-by: Philip Rogers <pdr@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Owners-Override: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1085138}
diff --git a/cc/paint/paint_canvas.h b/cc/paint/paint_canvas.h
index bd09dc5..1f8871b 100644
--- a/cc/paint/paint_canvas.h
+++ b/cc/paint/paint_canvas.h
@@ -30,12 +30,10 @@
 namespace cc {
 class SkottieWrapper;
 class PaintFlags;
-class PaintOpBuffer;
+class PaintRecord;
 
 enum class UsePaintCache { kDisabled = 0, kEnabled };
 
-using PaintRecord = PaintOpBuffer;
-
 // PaintCanvas is the cc/paint wrapper of SkCanvas.  It has a more restricted
 // interface than SkCanvas (trimmed back to only what Chrome uses).  Its reason
 // for existence is so that it can do custom serialization logic into a
@@ -205,7 +203,7 @@
 
   // Unlike SkCanvas::drawPicture, this only plays back the PaintRecord and does
   // not add an additional clip.  This is closer to SkPicture::playback.
-  virtual void drawPicture(sk_sp<const PaintRecord> record) = 0;
+  virtual void drawPicture(PaintRecord record) = 0;
 
   virtual bool isClipEmpty() const = 0;
   virtual SkM44 getLocalToDevice() const = 0;