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

Commit ee18427e authored by John Reck's avatar John Reck Committed by Nolan Scobie
Browse files

RESTRICT AUTOMERGE Add 1/16th pixel offset when drawing non-AA points/lines

This nudge ensures that pixel-aligned non-AA'd draws fill the desired
fragment.

Coupled with http://review.skia.org/665816, we're moving this logic from
Skia to Android so that the prerotation matrix can be properly accounted
for. Offseting only in Skia without accounting for prerotation  meant
the device-space Y offset could be applied in the wrong direction when
using Vulkan.

Equivalent change in T: Idfb5027fe3230f2c2b0cad224f2c7640e147ce4a

Bug: 254771190
Test: android.uirendering.cts.testclasses.ExactCanvasTests#testDrawLine
Change-Id: I975b62510a36312a395d1e254474bca726a9445d
(cherry picked from commit 7f785ebd)
parent 2b1526b1
Loading
Loading
Loading
Loading
+16 −1
Original line number Original line Diff line number Diff line
@@ -51,6 +51,9 @@
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrDirectContext.h"
#include "pipeline/skia/AnimatedDrawables.h"
#include "pipeline/skia/AnimatedDrawables.h"
#include "pipeline/skia/FunctorDrawable.h"
#include "pipeline/skia/FunctorDrawable.h"
#ifdef __ANDROID__
#include "renderthread/CanvasContext.h"
#endif


namespace android {
namespace android {
namespace uirenderer {
namespace uirenderer {
@@ -489,7 +492,19 @@ struct DrawPoints final : Op {
    size_t count;
    size_t count;
    SkPaint paint;
    SkPaint paint;
    void draw(SkCanvas* c, const SkMatrix&) const {
    void draw(SkCanvas* c, const SkMatrix&) const {
        if (paint.isAntiAlias()) {
            c->drawPoints(mode, count, pod<SkPoint>(this), paint);
            c->drawPoints(mode, count, pod<SkPoint>(this), paint);
        } else {
            c->save();
#ifdef __ANDROID__
            auto pixelSnap = renderthread::CanvasContext::getActiveContext()->getPixelSnapMatrix();
            auto transform = c->getLocalToDevice();
            transform.postConcat(pixelSnap);
            c->setMatrix(transform);
#endif
            c->drawPoints(mode, count, pod<SkPoint>(this), paint);
            c->restore();
        }
    }
    }
};
};
struct DrawVertices final : Op {
struct DrawVertices final : Op {
+8 −0
Original line number Original line Diff line number Diff line
@@ -53,6 +53,14 @@ public:
    bool isSurfaceReady() override;
    bool isSurfaceReady() override;
    bool isContextReady() override;
    bool isContextReady() override;


    const SkM44& getPixelSnapMatrix() const override {
        // Small (~1/16th) nudge to ensure that pixel-aligned non-AA'd draws fill the
        // desired fragment
        static const SkScalar kOffset = 0.063f;
        static const SkM44 sSnapMatrix = SkM44::Translate(kOffset, kOffset);
        return sSnapMatrix;
    }

    static void invokeFunctor(const renderthread::RenderThread& thread, Functor* functor);
    static void invokeFunctor(const renderthread::RenderThread& thread, Functor* functor);


protected:
protected:
+4 −0
Original line number Original line Diff line number Diff line
@@ -210,6 +210,10 @@ void SkiaVulkanPipeline::onContextDestroyed() {
    }
    }
}
}


const SkM44& SkiaVulkanPipeline::getPixelSnapMatrix() const {
    return mVkSurface->getPixelSnapMatrix();
}

} /* namespace skiapipeline */
} /* namespace skiapipeline */
} /* namespace uirenderer */
} /* namespace uirenderer */
} /* namespace android */
} /* namespace android */
+1 −0
Original line number Original line Diff line number Diff line
@@ -55,6 +55,7 @@ public:
    bool isContextReady() override;
    bool isContextReady() override;
    bool supportsExtendedRangeHdr() const override { return true; }
    bool supportsExtendedRangeHdr() const override { return true; }
    void setTargetSdrHdrRatio(float ratio) override;
    void setTargetSdrHdrRatio(float ratio) override;
    const SkM44& getPixelSnapMatrix() const override;


    static void invokeFunctor(const renderthread::RenderThread& thread, Functor* functor);
    static void invokeFunctor(const renderthread::RenderThread& thread, Functor* functor);
    static sk_sp<Bitmap> allocateHardwareBitmap(renderthread::RenderThread& thread,
    static sk_sp<Bitmap> allocateHardwareBitmap(renderthread::RenderThread& thread,
+4 −0
Original line number Original line Diff line number Diff line
@@ -871,6 +871,10 @@ SkISize CanvasContext::getNextFrameSize() const {
    return size;
    return size;
}
}


const SkM44& CanvasContext::getPixelSnapMatrix() const {
    return mRenderPipeline->getPixelSnapMatrix();
}

void CanvasContext::prepareAndDraw(RenderNode* node) {
void CanvasContext::prepareAndDraw(RenderNode* node) {
    ATRACE_CALL();
    ATRACE_CALL();


Loading