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

Commit 7fc1b034 authored by Chris Craik's avatar Chris Craik
Browse files

Fix ripple clipping + quick rejection

bug:26524690

Don't intersect the first clip with the viewport. Instead, the first
clip op should always be a replace op.

Additionally, only quick reject nodes that clip to bounds, since some
nodes (like ripples) draw outside their own bounds.

Change-Id: I96a52029f360328aba19af7349888cc0a026b5b1
parent d38308e4
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -213,6 +213,7 @@ void ClipArea::setClip(float left, float top, float right, float bottom) {

void ClipArea::clipRectWithTransform(const Rect& r, const mat4* transform,
        SkRegion::Op op) {
    if (!mPostViewportClipObserved && op == SkRegion::kIntersect_Op) op = SkRegion::kReplace_Op;
    onClipUpdated();
    switch (mMode) {
    case ClipMode::Rectangle:
@@ -228,6 +229,7 @@ void ClipArea::clipRectWithTransform(const Rect& r, const mat4* transform,
}

void ClipArea::clipRegion(const SkRegion& region, SkRegion::Op op) {
    if (!mPostViewportClipObserved && op == SkRegion::kIntersect_Op) op = SkRegion::kReplace_Op;
    onClipUpdated();
    enterRegionMode();
    mClipRegion.op(region, op);
@@ -236,6 +238,7 @@ void ClipArea::clipRegion(const SkRegion& region, SkRegion::Op op) {

void ClipArea::clipPathWithTransform(const SkPath& path, const mat4* transform,
        SkRegion::Op op) {
    if (!mPostViewportClipObserved && op == SkRegion::kIntersect_Op) op = SkRegion::kReplace_Op;
    onClipUpdated();
    SkMatrix skTransform;
    transform->copyTo(skTransform);
+3 −1
Original line number Diff line number Diff line
@@ -208,7 +208,9 @@ void FrameBuilder::deferNodePropsAndOps(RenderNode& node) {
        mCanvasState.setClippingOutline(mAllocator, &(properties.getOutline()));
    }

    if (!mCanvasState.quickRejectConservative(0, 0, width, height)) {
    bool quickRejected = properties.getClipToBounds()
            && mCanvasState.quickRejectConservative(0, 0, width, height);
    if (!quickRejected) {
        // not rejected, so defer render as either Layer, or direct (possibly wrapped in saveLayer)
        if (node.getLayer()) {
            // HW layer
+17 −0
Original line number Diff line number Diff line
@@ -455,6 +455,23 @@ TEST(RecordingCanvas, drawRenderNode_projection) {
    }
}

TEST(RecordingCanvas, firstClipWillReplace) {
    auto dl = TestUtils::createDisplayList<RecordingCanvas>(200, 200, [](RecordingCanvas& canvas) {
        canvas.save(SaveFlags::MatrixClip);
        // since no explicit clip set on canvas, this should be the one observed on op:
        canvas.clipRect(-100, -100, 300, 300, SkRegion::kIntersect_Op);

        SkPaint paint;
        paint.setColor(SK_ColorWHITE);
        canvas.drawRect(0, 0, 100, 100, paint);

        canvas.restore();
    });
    ASSERT_EQ(1u, dl->getOps().size()) << "Must have one op";
    // first clip must be preserved, even if it extends beyond canvas bounds
    EXPECT_CLIP_RECT(Rect(-100, -100, 300, 300), dl->getOps()[0]->localClip);
}

TEST(RecordingCanvas, insertReorderBarrier) {
    auto dl = TestUtils::createDisplayList<RecordingCanvas>(200, 200, [](RecordingCanvas& canvas) {
        canvas.drawRect(0, 0, 400, 400, SkPaint());