Support clipRegion on GPU backend

Bug: skia:9580
Change-Id: I663549dafc4239248e265bee8d6927bf5b259303
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259804
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2019-12-13 10:48:33 -05:00 committed by Skia Commit-Bot
parent 81b98978bc
commit a6069a154d
5 changed files with 47 additions and 7 deletions

View File

@ -9,6 +9,8 @@ Milestone 81
<Insert new notes here- top is most recent.>
* * *
* Added SkMatrix::MakeTrans(SkIVector)
https://review.skia.org/259804
Milestone 80

View File

@ -0,0 +1,39 @@
/*
* Copyright 2019 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRegion.h"
static constexpr int kSize = 3*3*3*3*3;
static constexpr int kTrans = 10;
DEF_SIMPLE_GM(clip_sierpinski_region, canvas, 2*kTrans + kSize, 2*kTrans + kSize) {
SkRegion region;
static constexpr int kSteps = 4;
int n = 1;
SkScalar s = kSize/3.f;
for (int i = 0; i < kSteps; ++i, n*=3, s/=3.f) {
for (int x = 0; x < n; ++x) {
for (int y = 0; y < n; ++y) {
region.op(SkIRect::MakeXYWH((3*x + 1)*s, (3*y + 1)*s, s, s), SkRegion::kUnion_Op);
}
}
}
// Test that a save layer with an offset works as expected.
region.translate(kTrans, kTrans);
canvas->saveLayer(SkRect::MakeXYWH(kTrans, kTrans, 1000, 1000), nullptr);
// Make sure the clip call ignores the CTM.
canvas->rotate(25.f, 50.f, 50.f);
canvas->clipRegion(region);
SkPaint red;
red.setColor(SK_ColorRED);
canvas->drawPaint(red);
canvas->restore();
}

View File

@ -72,6 +72,7 @@ gm_sources = [
"$_gm/circulararcs.cpp",
"$_gm/circularclips.cpp",
"$_gm/clip_error.cpp",
"$_gm/clip_sierpinski_region.cpp",
"$_gm/clip_strokerect.cpp",
"$_gm/clipdrawdraw.cpp",
"$_gm/clippedbitmapshaders.cpp",

View File

@ -110,6 +110,7 @@ public:
@return SkMatrix with translation
*/
static SkMatrix SK_WARN_UNUSED_RESULT MakeTrans(SkVector t) { return MakeTrans(t.x(), t.y()); }
static SkMatrix SK_WARN_UNUSED_RESULT MakeTrans(SkIVector t) { return MakeTrans(t.x(), t.y()); }
/** Sets SkMatrix to:

View File

@ -42,13 +42,10 @@ void SkClipStackDevice::onClipPath(const SkPath& path, SkClipOp op, bool aa) {
void SkClipStackDevice::onClipRegion(const SkRegion& rgn, SkClipOp op) {
SkIPoint origin = this->getOrigin();
SkRegion tmp;
const SkRegion* ptr = &rgn;
if (origin.fX | origin.fY) {
// translate from "global/canvas" coordinates to relative to this device
rgn.translate(-origin.fX, -origin.fY, &tmp);
ptr = &tmp;
}
fClipStack.clipDevRect(ptr->getBounds(), op);
SkPath path;
rgn.getBoundaryPath(&path);
path.transform(SkMatrix::MakeTrans(-origin));
fClipStack.clipPath(path, SkMatrix::I(), op, false);
}
void SkClipStackDevice::onSetDeviceClipRestriction(SkIRect* clipRestriction) {