Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1d155336 authored by Ben Wagner's avatar Ben Wagner
Browse files

Remove use of SkTLazy.

Skia is planning to make SkTLazy private to Skia. This changes uses of
SkTLazy to std::optional.

Test: refactoring CL. Existing unit tests still pass.
Change-Id: Id92c27cb8b3b41eb2e531b1a930511064a47a6f7
parent 7fd08795
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -21,7 +21,8 @@

#include <SkPicture.h>
#include <SkRefCnt.h>
#include <SkTLazy.h>

#include <optional>

namespace android {

@@ -126,13 +127,13 @@ AnimatedImageDrawable::Snapshot AnimatedImageDrawable::reset() {

// Only called on the RenderThread.
void AnimatedImageDrawable::onDraw(SkCanvas* canvas) {
    SkTLazy<SkPaint> lazyPaint;
    std::optional<SkPaint> lazyPaint;
    SkAutoCanvasRestore acr(canvas, false);
    if (mProperties.mAlpha != SK_AlphaOPAQUE || mProperties.mColorFilter.get()) {
        lazyPaint.init();
        lazyPaint.get()->setAlpha(mProperties.mAlpha);
        lazyPaint.get()->setColorFilter(mProperties.mColorFilter);
        lazyPaint.get()->setFilterQuality(kLow_SkFilterQuality);
        lazyPaint.emplace();
        lazyPaint->setAlpha(mProperties.mAlpha);
        lazyPaint->setColorFilter(mProperties.mColorFilter);
        lazyPaint->setFilterQuality(kLow_SkFilterQuality);
    }
    if (mProperties.mMirrored) {
        canvas->save();
@@ -147,8 +148,8 @@ void AnimatedImageDrawable::onDraw(SkCanvas* canvas) {
    if (drawDirectly) {
        // The image is not animating, and never was. Draw directly from
        // mSkAnimatedImage.
        if (lazyPaint.isValid()) {
            canvas->saveLayer(mSkAnimatedImage->getBounds(), lazyPaint.get());
        if (lazyPaint) {
            canvas->saveLayer(mSkAnimatedImage->getBounds(), &*lazyPaint);
        }

        std::unique_lock lock{mImageLock};
@@ -193,7 +194,7 @@ void AnimatedImageDrawable::onDraw(SkCanvas* canvas) {
    if (!drawDirectly) {
        // No other thread will modify mCurrentSnap so this should be safe to
        // use without locking.
        canvas->drawPicture(mSnapshot.mPic, nullptr, lazyPaint.getMaybeNull());
        canvas->drawPicture(mSnapshot.mPic, nullptr, lazyPaint ? &*lazyPaint : nullptr);
    }

    if (finalFrame) {
+4 −2
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@
#include "SkiaPipeline.h"
#include "utils/TraceUtils.h"

#include <optional>

namespace android {
namespace uirenderer {
namespace skiapipeline {
@@ -171,9 +173,9 @@ public:

protected:
    bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type t) const override {
        SkTLazy<SkPaint> defaultPaint;
        std::optional<SkPaint> defaultPaint;
        if (!*paint) {
            paint->init(*defaultPaint.init());
            paint->init(defaultPaint.emplace());
        }
        paint->writable()->setAlpha((uint8_t)(*paint)->getAlpha() * mAlpha);
        return true;