From b3731211b6940278d80b438d55c82d22c36506aa Mon Sep 17 00:00:00 2001 From: Kevin Lubick Date: Thu, 5 Jan 2023 19:52:09 +0000 Subject: [PATCH] Replace SkDeque with std::deque in SkiaCanvas SkDeque is private to Skia and the std library one should be sufficient. This change was started by kjlubick@ and continued by nscobie@. Test: existing presubmits (functionality unchanged) Change-Id: I60751aa77337c1601428d00d3ba4bc4b8ccb67a9 --- libs/hwui/SkiaCanvas.cpp | 40 ++++++++++++++++++++-------------------- libs/hwui/SkiaCanvas.h | 31 +++++++++++++++++-------------- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp index d83d78f650aad..5348d67427f9b 100644 --- a/libs/hwui/SkiaCanvas.cpp +++ b/libs/hwui/SkiaCanvas.cpp @@ -16,23 +16,12 @@ #include "SkiaCanvas.h" -#include "CanvasProperty.h" -#include "NinePatchUtils.h" -#include "SkBlendMode.h" -#include "VectorDrawable.h" -#include "hwui/Bitmap.h" -#include "hwui/MinikinUtils.h" -#include "hwui/PaintFilter.h" -#include "pipeline/skia/AnimatedDrawables.h" -#include "pipeline/skia/HolePunch.h" - #include #include #include #include #include #include -#include #include #include #include @@ -41,8 +30,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -54,6 +43,16 @@ #include #include +#include "CanvasProperty.h" +#include "NinePatchUtils.h" +#include "SkBlendMode.h" +#include "VectorDrawable.h" +#include "hwui/Bitmap.h" +#include "hwui/MinikinUtils.h" +#include "hwui/PaintFilter.h" +#include "pipeline/skia/AnimatedDrawables.h" +#include "pipeline/skia/HolePunch.h" + namespace android { using uirenderer::PaintUtils; @@ -176,7 +175,7 @@ int SkiaCanvas::save(SaveFlags::Flags flags) { // operation. It does this by explicitly saving off the clip & matrix state // when requested and playing it back after the SkCanvas::restore. void SkiaCanvas::restore() { - const auto* rec = this->currentSaveRec(); + const SaveRec* rec = this->currentSaveRec(); if (!rec) { // Fast path - no record for this frame. mCanvas->restore(); @@ -245,7 +244,9 @@ void SkiaCanvas::restoreUnclippedLayer(int restoreCount, const Paint& paint) { } const SkiaCanvas::SaveRec* SkiaCanvas::currentSaveRec() const { - const SaveRec* rec = mSaveStack ? static_cast(mSaveStack->back()) : nullptr; + const SaveRec* rec = (mSaveStack && !mSaveStack->empty()) + ? static_cast(&mSaveStack->back()) + : nullptr; int currentSaveCount = mCanvas->getSaveCount(); SkASSERT(!rec || currentSaveCount >= rec->saveCount); @@ -277,13 +278,12 @@ void SkiaCanvas::recordPartialSave(SaveFlags::Flags flags) { } if (!mSaveStack) { - mSaveStack.reset(new SkDeque(sizeof(struct SaveRec), 8)); + mSaveStack.reset(new std::deque()); } - SaveRec* rec = static_cast(mSaveStack->push_back()); - rec->saveCount = mCanvas->getSaveCount(); - rec->saveFlags = flags; - rec->clipIndex = mClipStack.size(); + mSaveStack->emplace_back(mCanvas->getSaveCount(), // saveCount + flags, // saveFlags + mClipStack.size()); // clipIndex } template @@ -314,7 +314,7 @@ void SkiaCanvas::applyPersistentClips(size_t clipStartIndex) { // If the current/post-restore save rec is also persisting clips, we // leave them on the stack to be reapplied part of the next restore(). // Otherwise we're done and just pop them. - const auto* rec = this->currentSaveRec(); + const SaveRec* rec = this->currentSaveRec(); if (!rec || (rec->saveFlags & SaveFlags::Clip)) { mClipStack.erase(begin, end); } diff --git a/libs/hwui/SkiaCanvas.h b/libs/hwui/SkiaCanvas.h index 31e3b4c3c7e22..3ad4dc6421b43 100644 --- a/libs/hwui/SkiaCanvas.h +++ b/libs/hwui/SkiaCanvas.h @@ -19,20 +19,20 @@ #ifdef __ANDROID__ // Layoutlib does not support hardware acceleration #include "DeferredLayerUpdater.h" #endif -#include "RenderNode.h" -#include "VectorDrawable.h" -#include "hwui/Canvas.h" -#include "hwui/Paint.h" -#include "hwui/BlurDrawLooper.h" - #include -#include -#include "pipeline/skia/AnimatedDrawables.h" -#include "src/core/SkArenaAlloc.h" #include +#include #include +#include "RenderNode.h" +#include "VectorDrawable.h" +#include "hwui/BlurDrawLooper.h" +#include "hwui/Canvas.h" +#include "hwui/Paint.h" +#include "pipeline/skia/AnimatedDrawables.h" +#include "src/core/SkArenaAlloc.h" + enum class SkBlendMode; class SkRRect; @@ -211,6 +211,9 @@ private: int saveCount; SaveFlags::Flags saveFlags; size_t clipIndex; + + SaveRec(int saveCount, SaveFlags::Flags saveFlags, size_t clipIndex) + : saveCount(saveCount), saveFlags(saveFlags), clipIndex(clipIndex) {} }; const SaveRec* currentSaveRec() const; @@ -224,11 +227,11 @@ private: class Clip; - std::unique_ptr mCanvasOwned; // might own a canvas we allocated - SkCanvas* mCanvas; // we do NOT own this canvas, it must survive us - // unless it is the same as mCanvasOwned.get() - std::unique_ptr mSaveStack; // lazily allocated, tracks partial saves. - std::vector mClipStack; // tracks persistent clips. + std::unique_ptr mCanvasOwned; // Might own a canvas we allocated. + SkCanvas* mCanvas; // We do NOT own this canvas, it must survive us + // unless it is the same as mCanvasOwned.get(). + std::unique_ptr> mSaveStack; // Lazily allocated, tracks partial saves. + std::vector mClipStack; // Tracks persistent clips. sk_sp mPaintFilter; };