From d50cc95872a8a832faea0154f7ea1fd56cebc775 Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Thu, 5 Dec 2019 12:15:34 -0600 Subject: [PATCH] upgrade SkMiniRecorder to c++11 It had been manually std::move()ing without actually calling it by that name. GCC noticed. Oh hey, let's call ~T(). Change-Id: Ie54b8906e3a4334f73e46ca9d31dc8542289f238 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/258344 Commit-Queue: Mike Klein Reviewed-by: Brian Salomon --- src/core/SkMiniRecorder.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/core/SkMiniRecorder.cpp b/src/core/SkMiniRecorder.cpp index e75ecd04c3..76919a092e 100644 --- a/src/core/SkMiniRecorder.cpp +++ b/src/core/SkMiniRecorder.cpp @@ -47,9 +47,9 @@ static SkRect bounds(const DrawTextBlob& op) { template class SkMiniPicture final : public SkPicture { public: - SkMiniPicture(const SkRect* cull, T* op) : fCull(cull ? *cull : bounds(*op)) { - memcpy(&fOp, op, sizeof(fOp)); // We take ownership of op's guts. - } + SkMiniPicture(const SkRect* cull, T&& op) + : fCull(cull ? *cull : bounds(op)) + , fOp(std::move(op)) {} void playback(SkCanvas* c, AbortCallback*) const override { SkRecords::Draw(c, nullptr, nullptr, 0, nullptr)(fOp); @@ -96,10 +96,14 @@ bool SkMiniRecorder::drawTextBlob(const SkTextBlob* b, SkScalar x, SkScalar y, c sk_sp SkMiniRecorder::detachAsPicture(const SkRect* cull) { -#define CASE(Type) \ - case State::k##Type: \ - fState = State::kEmpty; \ - return sk_make_sp>(cull, reinterpret_cast(fBuffer.get())) +#define CASE(T) \ + case State::k##T: { \ + T* op = reinterpret_cast(fBuffer.get()); \ + auto pic = sk_make_sp>(cull, std::move(*op)); \ + op->~T(); \ + fState = State::kEmpty; \ + return pic; \ + } static SkOnce once; static SkPicture* empty; @@ -108,9 +112,9 @@ sk_sp SkMiniRecorder::detachAsPicture(const SkRect* cull) { case State::kEmpty: once([]{ empty = new SkEmptyPicture; }); return sk_ref_sp(empty); - CASE(DrawPath); - CASE(DrawRect); - CASE(DrawTextBlob); + CASE(DrawPath) + CASE(DrawRect) + CASE(DrawTextBlob) } SkASSERT(false); return nullptr;