add test and fix for canvas::isClipEmpty
BUG=skia: Change-Id: I4e57e0da7111e861fbae1b88574bc1803442243c Reviewed-on: https://skia-review.googlesource.com/10046 Reviewed-by: Derek Sollenberger <djsollen@google.com> Commit-Queue: Derek Sollenberger <djsollen@google.com>
This commit is contained in:
parent
78075804c1
commit
02be3c1c3f
@ -1610,9 +1610,14 @@ void SkCanvas::temporary_internal_getRgnClip(SkRegion* rgn) {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool SkCanvas::isClipEmpty() const {
|
||||
return fMCRec->fRasterClip.isEmpty();
|
||||
|
||||
// TODO: should we only use the conservative answer in a recording canvas?
|
||||
#if 0
|
||||
SkBaseDevice* dev = this->getTopDevice();
|
||||
// if no device we return true
|
||||
return !dev || dev->onGetClipType() == SkBaseDevice::kEmpty_ClipType;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool SkCanvas::isClipRect() const {
|
||||
|
@ -108,10 +108,8 @@ void SkConservativeClip::op(const SkRegion& rgn, SkRegion::Op op) {
|
||||
|
||||
void SkConservativeClip::op(const SkIRect& devRect, SkRegion::Op op) {
|
||||
if (SkRegion::kIntersect_Op == op) {
|
||||
if (devRect.isEmpty()) {
|
||||
if (!fBounds.intersect(devRect)) {
|
||||
fBounds.setEmpty();
|
||||
} else {
|
||||
(void)fBounds.intersect(devRect);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -104,6 +104,18 @@ DEF_TEST(canvas_clipbounds, reporter) {
|
||||
}
|
||||
}
|
||||
|
||||
// Will call proc with multiple styles of canse (recording, raster, pdf)
|
||||
//
|
||||
template <typename F> static void multi_canvas_driver(int w, int h, F proc) {
|
||||
proc(SkPictureRecorder().beginRecording(SkRect::MakeIWH(w, h)));
|
||||
|
||||
SkNullWStream stream;
|
||||
proc(SkDocument::MakePDF(&stream)->beginPage(SkIntToScalar(w), SkIntToScalar(h)));
|
||||
|
||||
proc(SkSurface::MakeRasterN32Premul(w, h, nullptr)->getCanvas());
|
||||
}
|
||||
|
||||
|
||||
const SkIRect gBaseRestrictedR = { 0, 0, 10, 10 };
|
||||
|
||||
static void test_restriction(skiatest::Reporter* reporter, SkCanvas* canvas) {
|
||||
@ -145,16 +157,18 @@ static void test_restriction(skiatest::Reporter* reporter, SkCanvas* canvas) {
|
||||
* - raster : uses SkRasterClip in its device
|
||||
*/
|
||||
DEF_TEST(canvas_clip_restriction, reporter) {
|
||||
test_restriction(reporter, SkPictureRecorder().beginRecording(SkRect::Make(gBaseRestrictedR)));
|
||||
multi_canvas_driver(gBaseRestrictedR.width(), gBaseRestrictedR.height(),
|
||||
[reporter](SkCanvas* canvas) { test_restriction(reporter, canvas); });
|
||||
}
|
||||
|
||||
SkNullWStream stream;
|
||||
auto doc = SkDocument::MakePDF(&stream);
|
||||
test_restriction(reporter, doc->beginPage(SkIntToScalar(gBaseRestrictedR.width()),
|
||||
SkIntToScalar(gBaseRestrictedR.height())));
|
||||
|
||||
auto surf = SkSurface::MakeRasterN32Premul(gBaseRestrictedR.width(),
|
||||
gBaseRestrictedR.height(), nullptr);
|
||||
test_restriction(reporter, surf->getCanvas());
|
||||
DEF_TEST(canvas_empty_clip, reporter) {
|
||||
multi_canvas_driver(50, 50, [reporter](SkCanvas* canvas) {
|
||||
canvas->save();
|
||||
canvas->clipRect({0, 0, 20, 40 });
|
||||
REPORTER_ASSERT(reporter, !canvas->isClipEmpty());
|
||||
canvas->clipRect({30, 0, 50, 40 });
|
||||
REPORTER_ASSERT(reporter, canvas->isClipEmpty());
|
||||
});
|
||||
}
|
||||
|
||||
static const int kWidth = 2, kHeight = 2;
|
||||
|
Loading…
Reference in New Issue
Block a user