2011-11-28 16:06:04 +00:00
|
|
|
/*
|
2012-02-22 21:00:42 +00:00
|
|
|
* Copyright 2012 Google Inc.
|
2011-11-28 16:06:04 +00:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2012-02-22 21:00:42 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkBlendMode.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkClipOp.h"
|
|
|
|
#include "include/core/SkColor.h"
|
2019-05-06 19:13:30 +00:00
|
|
|
#include "include/core/SkDocument.h"
|
|
|
|
#include "include/core/SkFlattenable.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImageFilter.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkPictureRecorder.h"
|
|
|
|
#include "include/core/SkPixmap.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkRegion.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkStream.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "include/core/SkVertices.h"
|
|
|
|
#include "include/docs/SkPDFDocument.h"
|
2019-08-05 14:41:10 +00:00
|
|
|
#include "include/effects/SkImageFilters.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/private/SkMalloc.h"
|
|
|
|
#include "include/private/SkTemplates.h"
|
|
|
|
#include "include/utils/SkNWayCanvas.h"
|
|
|
|
#include "include/utils/SkPaintFilterCanvas.h"
|
2020-09-15 18:10:52 +00:00
|
|
|
#include "src/core/SkBigPicture.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkClipOpPriv.h"
|
2019-08-02 13:57:04 +00:00
|
|
|
#include "src/core/SkImageFilter_Base.h"
|
2020-09-15 18:10:52 +00:00
|
|
|
#include "src/core/SkRecord.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkSpecialImage.h"
|
|
|
|
#include "src/utils/SkCanvasStack.h"
|
|
|
|
#include "tests/Test.h"
|
2011-11-28 16:06:04 +00:00
|
|
|
|
2018-03-12 17:46:21 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkColorSpace.h"
|
|
|
|
#include "include/private/SkColorData.h"
|
2018-03-12 17:46:21 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
class SkReadBuffer;
|
2020-09-15 18:10:52 +00:00
|
|
|
|
|
|
|
struct ClipRectVisitor {
|
|
|
|
skiatest::Reporter* r;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
SkRect operator()(const T&) {
|
|
|
|
REPORTER_ASSERT(r, false, "unexpected record");
|
|
|
|
return {1,1,0,0};
|
|
|
|
}
|
|
|
|
|
|
|
|
SkRect operator()(const SkRecords::ClipRect& op) {
|
|
|
|
return op.rect;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_TEST(canvas_unsorted_clip, r) {
|
|
|
|
// Test that sorted and unsorted clip rects are forwarded
|
|
|
|
// to picture subclasses and/or devices sorted.
|
|
|
|
//
|
|
|
|
// We can't just test this with an SkCanvas on stack and
|
|
|
|
// SkCanvas::getLocalClipBounds(), as that only tests the raster device,
|
|
|
|
// which sorts these rects itself.
|
|
|
|
for (SkRect clip : {SkRect{0,0,5,5}, SkRect{5,5,0,0}}) {
|
|
|
|
SkPictureRecorder rec;
|
|
|
|
rec.beginRecording({0,0,10,10})
|
|
|
|
->clipRect(clip);
|
|
|
|
sk_sp<SkPicture> pic = rec.finishRecordingAsPicture();
|
|
|
|
|
|
|
|
auto bp = (const SkBigPicture*)pic.get();
|
|
|
|
const SkRecord* record = bp->record();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, record->count() == 1);
|
|
|
|
REPORTER_ASSERT(r, record->visit(0, ClipRectVisitor{r})
|
|
|
|
.isSorted());
|
|
|
|
}
|
|
|
|
}
|
2018-03-12 17:46:21 +00:00
|
|
|
|
2017-01-23 16:39:45 +00:00
|
|
|
DEF_TEST(canvas_clipbounds, reporter) {
|
|
|
|
SkCanvas canvas(10, 10);
|
2017-01-24 14:13:40 +00:00
|
|
|
SkIRect irect, irect2;
|
|
|
|
SkRect rect, rect2;
|
2017-01-23 16:39:45 +00:00
|
|
|
|
|
|
|
irect = canvas.getDeviceClipBounds();
|
|
|
|
REPORTER_ASSERT(reporter, irect == SkIRect::MakeWH(10, 10));
|
2017-01-24 14:13:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, canvas.getDeviceClipBounds(&irect2));
|
|
|
|
REPORTER_ASSERT(reporter, irect == irect2);
|
|
|
|
|
2017-01-23 16:39:45 +00:00
|
|
|
// local bounds are always too big today -- can we trim them?
|
|
|
|
rect = canvas.getLocalClipBounds();
|
|
|
|
REPORTER_ASSERT(reporter, rect.contains(SkRect::MakeWH(10, 10)));
|
2017-01-24 14:13:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, canvas.getLocalClipBounds(&rect2));
|
|
|
|
REPORTER_ASSERT(reporter, rect == rect2);
|
2017-01-23 16:39:45 +00:00
|
|
|
|
|
|
|
canvas.clipRect(SkRect::MakeEmpty());
|
|
|
|
|
|
|
|
irect = canvas.getDeviceClipBounds();
|
|
|
|
REPORTER_ASSERT(reporter, irect == SkIRect::MakeEmpty());
|
2017-01-24 14:13:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, !canvas.getDeviceClipBounds(&irect2));
|
|
|
|
REPORTER_ASSERT(reporter, irect == irect2);
|
|
|
|
|
2017-01-23 16:39:45 +00:00
|
|
|
rect = canvas.getLocalClipBounds();
|
|
|
|
REPORTER_ASSERT(reporter, rect == SkRect::MakeEmpty());
|
2017-01-24 14:13:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, !canvas.getLocalClipBounds(&rect2));
|
|
|
|
REPORTER_ASSERT(reporter, rect == rect2);
|
2017-03-10 15:49:45 +00:00
|
|
|
|
|
|
|
// Test for wacky sizes that we (historically) have guarded against
|
|
|
|
{
|
|
|
|
SkCanvas c(-10, -20);
|
|
|
|
REPORTER_ASSERT(reporter, c.getBaseLayerSize() == SkISize::MakeEmpty());
|
2017-03-10 18:54:16 +00:00
|
|
|
|
|
|
|
SkPictureRecorder().beginRecording({ 5, 5, 4, 4 });
|
2017-03-10 15:49:45 +00:00
|
|
|
}
|
2017-01-23 16:39:45 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 19:25:47 +00:00
|
|
|
// Will call proc with multiple styles of canvas (recording, raster, pdf)
|
2017-03-23 16:34:15 +00:00
|
|
|
template <typename F> static void multi_canvas_driver(int w, int h, F proc) {
|
|
|
|
proc(SkPictureRecorder().beginRecording(SkRect::MakeIWH(w, h)));
|
|
|
|
|
|
|
|
SkNullWStream stream;
|
2018-09-07 18:33:14 +00:00
|
|
|
if (auto doc = SkPDF::MakeDocument(&stream)) {
|
2018-03-20 18:17:00 +00:00
|
|
|
proc(doc->beginPage(SkIntToScalar(w), SkIntToScalar(h)));
|
|
|
|
}
|
2017-03-23 16:34:15 +00:00
|
|
|
|
|
|
|
proc(SkSurface::MakeRasterN32Premul(w, h, nullptr)->getCanvas());
|
|
|
|
}
|
|
|
|
|
2017-03-22 14:01:53 +00:00
|
|
|
const SkIRect gBaseRestrictedR = { 0, 0, 10, 10 };
|
|
|
|
|
|
|
|
static void test_restriction(skiatest::Reporter* reporter, SkCanvas* canvas) {
|
|
|
|
REPORTER_ASSERT(reporter, canvas->getDeviceClipBounds() == gBaseRestrictedR);
|
|
|
|
|
|
|
|
const SkIRect restrictionR = { 2, 2, 8, 8 };
|
|
|
|
canvas->androidFramework_setDeviceClipRestriction(restrictionR);
|
|
|
|
REPORTER_ASSERT(reporter, canvas->getDeviceClipBounds() == restrictionR);
|
|
|
|
|
|
|
|
const SkIRect clipR = { 4, 4, 6, 6 };
|
|
|
|
canvas->clipRect(SkRect::Make(clipR), SkClipOp::kIntersect);
|
|
|
|
REPORTER_ASSERT(reporter, canvas->getDeviceClipBounds() == clipR);
|
|
|
|
|
2017-05-10 18:13:20 +00:00
|
|
|
#ifdef SK_SUPPORT_DEPRECATED_CLIPOPS
|
2017-03-22 14:01:53 +00:00
|
|
|
// now test that expanding clipops can't exceed the restriction
|
|
|
|
const SkClipOp expanders[] = {
|
|
|
|
SkClipOp::kUnion_deprecated,
|
|
|
|
SkClipOp::kXOR_deprecated,
|
|
|
|
SkClipOp::kReverseDifference_deprecated,
|
|
|
|
SkClipOp::kReplace_deprecated,
|
|
|
|
};
|
|
|
|
|
|
|
|
const SkRect expandR = { 0, 0, 5, 9 };
|
|
|
|
SkASSERT(!SkRect::Make(restrictionR).contains(expandR));
|
|
|
|
|
|
|
|
for (SkClipOp op : expanders) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(expandR, op);
|
|
|
|
REPORTER_ASSERT(reporter, gBaseRestrictedR.contains(canvas->getDeviceClipBounds()));
|
|
|
|
canvas->restore();
|
|
|
|
}
|
2017-05-10 18:13:20 +00:00
|
|
|
#endif
|
2017-03-22 14:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clip restriction logic exists in the canvas itself, and in various kinds of devices.
|
|
|
|
*
|
|
|
|
* This test explicitly tries to exercise that variety:
|
|
|
|
* - picture : empty device but exercises canvas itself
|
|
|
|
* - pdf : uses SkClipStack in its device (as does SVG and GPU)
|
|
|
|
* - raster : uses SkRasterClip in its device
|
|
|
|
*/
|
|
|
|
DEF_TEST(canvas_clip_restriction, reporter) {
|
2017-03-23 16:34:15 +00:00
|
|
|
multi_canvas_driver(gBaseRestrictedR.width(), gBaseRestrictedR.height(),
|
|
|
|
[reporter](SkCanvas* canvas) { test_restriction(reporter, canvas); });
|
|
|
|
}
|
2017-03-22 14:01:53 +00:00
|
|
|
|
2017-03-23 16:34:15 +00:00
|
|
|
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());
|
|
|
|
});
|
2017-03-22 14:01:53 +00:00
|
|
|
}
|
|
|
|
|
2019-05-06 19:13:30 +00:00
|
|
|
DEF_TEST(CanvasNewRasterTest, reporter) {
|
2014-02-27 20:32:51 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
|
2014-12-10 15:24:28 +00:00
|
|
|
const size_t minRowBytes = info.minRowBytes();
|
2017-10-03 18:47:21 +00:00
|
|
|
const size_t size = info.computeByteSize(minRowBytes);
|
2015-12-10 18:44:13 +00:00
|
|
|
SkAutoTMalloc<SkPMColor> storage(size);
|
|
|
|
SkPMColor* baseAddr = storage.get();
|
2014-12-10 15:24:28 +00:00
|
|
|
sk_bzero(baseAddr, size);
|
|
|
|
|
2016-11-12 14:06:55 +00:00
|
|
|
std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes);
|
2014-02-27 20:32:51 +00:00
|
|
|
REPORTER_ASSERT(reporter, canvas);
|
|
|
|
|
2016-03-09 22:26:26 +00:00
|
|
|
SkPixmap pmap;
|
|
|
|
const SkPMColor* addr = canvas->peekPixels(&pmap) ? pmap.addr32() : nullptr;
|
2014-02-27 20:32:51 +00:00
|
|
|
REPORTER_ASSERT(reporter, addr);
|
2016-03-09 22:26:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, info == pmap.info());
|
|
|
|
REPORTER_ASSERT(reporter, minRowBytes == pmap.rowBytes());
|
2014-02-27 20:32:51 +00:00
|
|
|
for (int y = 0; y < info.height(); ++y) {
|
|
|
|
for (int x = 0; x < info.width(); ++x) {
|
|
|
|
REPORTER_ASSERT(reporter, 0 == addr[x]);
|
|
|
|
}
|
2016-03-09 22:26:26 +00:00
|
|
|
addr = (const SkPMColor*)((const char*)addr + pmap.rowBytes());
|
2014-02-27 20:32:51 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 15:44:00 +00:00
|
|
|
// unaligned rowBytes
|
|
|
|
REPORTER_ASSERT(reporter, nullptr == SkCanvas::MakeRasterDirect(info, baseAddr,
|
|
|
|
minRowBytes + 1));
|
|
|
|
|
2014-02-27 20:32:51 +00:00
|
|
|
// now try a deliberately bad info
|
2014-09-03 18:54:58 +00:00
|
|
|
info = info.makeWH(-1, info.height());
|
2016-11-12 14:06:55 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes));
|
2014-02-27 20:32:51 +00:00
|
|
|
|
|
|
|
// too big
|
2014-09-03 18:54:58 +00:00
|
|
|
info = info.makeWH(1 << 30, 1 << 30);
|
2016-11-12 14:06:55 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes));
|
2014-02-28 03:02:05 +00:00
|
|
|
|
2014-02-27 20:32:51 +00:00
|
|
|
// not a valid pixel type
|
2014-09-03 18:54:58 +00:00
|
|
|
info = SkImageInfo::Make(10, 10, kUnknown_SkColorType, info.alphaType());
|
2016-11-12 14:06:55 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes));
|
2014-02-27 20:32:51 +00:00
|
|
|
|
2018-10-10 17:20:38 +00:00
|
|
|
// We should not succeed with a zero-sized valid info
|
2014-02-27 20:32:51 +00:00
|
|
|
info = SkImageInfo::MakeN32Premul(0, 0);
|
2016-11-12 14:06:55 +00:00
|
|
|
canvas = SkCanvas::MakeRasterDirect(info, baseAddr, minRowBytes);
|
2018-10-10 17:20:38 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == canvas);
|
2014-02-27 20:32:51 +00:00
|
|
|
}
|
|
|
|
|
2019-05-06 20:51:06 +00:00
|
|
|
static SkPath make_path_from_rect(SkRect r) {
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(r);
|
|
|
|
return path;
|
|
|
|
}
|
2019-05-06 19:13:30 +00:00
|
|
|
|
2019-05-06 20:51:06 +00:00
|
|
|
static SkRegion make_region_from_irect(SkIRect r) {
|
|
|
|
SkRegion region;
|
|
|
|
region.setRect(r);
|
|
|
|
return region;
|
|
|
|
}
|
2019-05-06 19:13:30 +00:00
|
|
|
|
2019-05-06 20:51:06 +00:00
|
|
|
static SkBitmap make_n32_bitmap(int w, int h, SkColor c = SK_ColorWHITE) {
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocN32Pixels(w, h);
|
|
|
|
bm.eraseColor(c);
|
|
|
|
return bm;
|
|
|
|
}
|
2019-05-06 19:13:30 +00:00
|
|
|
|
2019-05-06 20:51:06 +00:00
|
|
|
// Constants used by test steps
|
|
|
|
static constexpr SkRect kRect = {0, 0, 2, 1};
|
|
|
|
static constexpr SkColor kColor = 0x01020304;
|
|
|
|
static constexpr int kWidth = 2;
|
|
|
|
static constexpr int kHeight = 2;
|
|
|
|
|
|
|
|
using CanvasTest = void (*)(SkCanvas*, skiatest::Reporter*);
|
|
|
|
|
|
|
|
static CanvasTest kCanvasTests[] = {
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
c->translate(SkIntToScalar(1), SkIntToScalar(2));
|
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
c->scale(SkIntToScalar(1), SkIntToScalar(2));
|
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
c->rotate(SkIntToScalar(1));
|
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
c->skew(SkIntToScalar(1), SkIntToScalar(2));
|
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
2020-05-21 16:11:27 +00:00
|
|
|
c->concat(SkMatrix::Scale(2, 3));
|
2019-05-06 20:51:06 +00:00
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
2020-05-21 16:11:27 +00:00
|
|
|
c->setMatrix(SkMatrix::Scale(2, 3));
|
2019-05-06 20:51:06 +00:00
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
c->clipRect(kRect);
|
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
c->clipPath(make_path_from_rect(SkRect{0, 0, 2, 1}));
|
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
2020-09-16 17:55:05 +00:00
|
|
|
c->clipRegion(make_region_from_irect(SkIRect{0, 0, 2, 1}));
|
2019-05-06 20:51:06 +00:00
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
c->clear(kColor);
|
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
int saveCount = c->getSaveCount();
|
|
|
|
c->save();
|
|
|
|
c->translate(SkIntToScalar(1), SkIntToScalar(2));
|
|
|
|
c->clipRegion(make_region_from_irect(SkIRect{0, 0, 2, 1}));
|
|
|
|
c->restore();
|
|
|
|
REPORTER_ASSERT(r, c->getSaveCount() == saveCount);
|
|
|
|
REPORTER_ASSERT(r, c->getTotalMatrix().isIdentity());
|
|
|
|
//REPORTER_ASSERT(reporter, c->getTotalClip() != kTestRegion);
|
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
int saveCount = c->getSaveCount();
|
|
|
|
c->saveLayer(nullptr, nullptr);
|
|
|
|
c->restore();
|
|
|
|
REPORTER_ASSERT(r, c->getSaveCount() == saveCount);
|
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
int saveCount = c->getSaveCount();
|
|
|
|
c->saveLayer(&kRect, nullptr);
|
|
|
|
c->restore();
|
|
|
|
REPORTER_ASSERT(r, c->getSaveCount() == saveCount);
|
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
int saveCount = c->getSaveCount();
|
|
|
|
SkPaint p;
|
|
|
|
c->saveLayer(nullptr, &p);
|
|
|
|
c->restore();
|
|
|
|
REPORTER_ASSERT(r, c->getSaveCount() == saveCount);
|
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
// This test exercises a functionality in SkPicture that leads to the
|
|
|
|
// recording of restore offset placeholders. This test will trigger an
|
|
|
|
// assertion at playback time if the placeholders are not properly
|
|
|
|
// filled when the recording ends.
|
|
|
|
c->clipRect(kRect);
|
|
|
|
c->clipRegion(make_region_from_irect(SkIRect{0, 0, 2, 1}));
|
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
// exercise fix for http://code.google.com/p/skia/issues/detail?id=560
|
|
|
|
// ('SkPathStroker::lineTo() fails for line with length SK_ScalarNearlyZero')
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(1));
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(SkPoint{ 0, 0 });
|
|
|
|
path.lineTo(SkPoint{ 0, SK_ScalarNearlyZero });
|
|
|
|
path.lineTo(SkPoint{ SkIntToScalar(1), 0 });
|
|
|
|
path.lineTo(SkPoint{ SkIntToScalar(1), SK_ScalarNearlyZero/2 });
|
|
|
|
// test nearly zero length path
|
|
|
|
c->drawPath(path, paint);
|
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
SkPictureRecorder recorder;
|
2020-08-21 17:42:01 +00:00
|
|
|
SkCanvas* testCanvas = recorder.beginRecording(SkIntToScalar(kWidth),
|
|
|
|
SkIntToScalar(kHeight));
|
2019-05-06 20:51:06 +00:00
|
|
|
testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1));
|
|
|
|
testCanvas->clipRect(kRect);
|
|
|
|
testCanvas->drawRect(kRect, SkPaint());
|
|
|
|
c->drawPicture(recorder.finishRecordingAsPicture());
|
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
int baseSaveCount = c->getSaveCount();
|
|
|
|
int n = c->save();
|
|
|
|
REPORTER_ASSERT(r, baseSaveCount == n);
|
|
|
|
REPORTER_ASSERT(r, baseSaveCount + 1 == c->getSaveCount());
|
|
|
|
c->save();
|
|
|
|
c->save();
|
|
|
|
REPORTER_ASSERT(r, baseSaveCount + 3 == c->getSaveCount());
|
|
|
|
c->restoreToCount(baseSaveCount + 1);
|
|
|
|
REPORTER_ASSERT(r, baseSaveCount + 1 == c->getSaveCount());
|
|
|
|
|
|
|
|
// should this pin to 1, or be a no-op, or crash?
|
|
|
|
c->restoreToCount(0);
|
|
|
|
REPORTER_ASSERT(r, 1 == c->getSaveCount());
|
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
// This test step challenges the TestDeferredCanvasStateConsistency
|
|
|
|
// test cases because the opaque paint can trigger an optimization
|
|
|
|
// that discards previously recorded commands. The challenge is to maintain
|
|
|
|
// correct clip and matrix stack state.
|
|
|
|
c->resetMatrix();
|
|
|
|
c->rotate(SkIntToScalar(30));
|
|
|
|
c->save();
|
|
|
|
c->translate(SkIntToScalar(2), SkIntToScalar(1));
|
|
|
|
c->save();
|
|
|
|
c->scale(SkIntToScalar(3), SkIntToScalar(3));
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(0xFFFFFFFF);
|
|
|
|
c->drawPaint(paint);
|
|
|
|
c->restore();
|
|
|
|
c->restore();
|
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
// This test step challenges the TestDeferredCanvasStateConsistency
|
|
|
|
// test case because the canvas flush on a deferred canvas will
|
|
|
|
// reset the recording session. The challenge is to maintain correct
|
|
|
|
// clip and matrix stack state on the playback canvas.
|
|
|
|
c->resetMatrix();
|
|
|
|
c->rotate(SkIntToScalar(30));
|
|
|
|
c->save();
|
|
|
|
c->translate(SkIntToScalar(2), SkIntToScalar(1));
|
|
|
|
c->save();
|
|
|
|
c->scale(SkIntToScalar(3), SkIntToScalar(3));
|
|
|
|
c->drawRect(kRect, SkPaint());
|
|
|
|
c->flush();
|
|
|
|
c->restore();
|
|
|
|
c->restore();
|
|
|
|
},
|
|
|
|
[](SkCanvas* c, skiatest::Reporter* r) {
|
|
|
|
SkPoint pts[4];
|
|
|
|
pts[0].set(0, 0);
|
|
|
|
pts[1].set(SkIntToScalar(kWidth), 0);
|
|
|
|
pts[2].set(SkIntToScalar(kWidth), SkIntToScalar(kHeight));
|
|
|
|
pts[3].set(0, SkIntToScalar(kHeight));
|
|
|
|
SkPaint paint;
|
|
|
|
SkBitmap bitmap(make_n32_bitmap(kWidth, kHeight, 0x05060708));
|
|
|
|
paint.setShader(bitmap.makeShader());
|
|
|
|
c->drawVertices(
|
|
|
|
SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, 4, pts, pts, nullptr),
|
|
|
|
SkBlendMode::kModulate, paint);
|
|
|
|
}
|
|
|
|
};
|
2019-05-06 19:13:30 +00:00
|
|
|
|
2019-05-06 20:51:06 +00:00
|
|
|
DEF_TEST(Canvas_bitmap, reporter) {
|
|
|
|
for (const CanvasTest& test : kCanvasTests) {
|
|
|
|
SkBitmap referenceStore = make_n32_bitmap(kWidth, kHeight);
|
2019-05-06 19:13:30 +00:00
|
|
|
SkCanvas referenceCanvas(referenceStore);
|
2019-05-06 20:51:06 +00:00
|
|
|
test(&referenceCanvas, reporter);
|
|
|
|
}
|
|
|
|
}
|
2012-08-02 17:43:25 +00:00
|
|
|
|
2019-05-06 20:51:06 +00:00
|
|
|
DEF_TEST(Canvas_pdf, reporter) {
|
|
|
|
for (const CanvasTest& test : kCanvasTests) {
|
|
|
|
SkNullWStream outStream;
|
|
|
|
if (auto doc = SkPDF::MakeDocument(&outStream)) {
|
|
|
|
SkCanvas* canvas = doc->beginPage(SkIntToScalar(kWidth),
|
|
|
|
SkIntToScalar(kHeight));
|
|
|
|
REPORTER_ASSERT(reporter, canvas);
|
|
|
|
test(canvas, reporter);
|
2019-05-06 19:13:30 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-28 16:06:04 +00:00
|
|
|
}
|
2014-11-26 16:55:51 +00:00
|
|
|
|
|
|
|
DEF_TEST(Canvas_SaveState, reporter) {
|
|
|
|
SkCanvas canvas(10, 10);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount());
|
|
|
|
|
|
|
|
int n = canvas.save();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == n);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount());
|
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
n = canvas.saveLayer(nullptr, nullptr);
|
2014-11-26 16:55:51 +00:00
|
|
|
REPORTER_ASSERT(reporter, 2 == n);
|
|
|
|
REPORTER_ASSERT(reporter, 3 == canvas.getSaveCount());
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2014-11-26 16:55:51 +00:00
|
|
|
canvas.restore();
|
|
|
|
REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount());
|
|
|
|
canvas.restore();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount());
|
|
|
|
}
|
2015-03-13 15:48:26 +00:00
|
|
|
|
|
|
|
DEF_TEST(Canvas_ClipEmptyPath, reporter) {
|
|
|
|
SkCanvas canvas(10, 10);
|
|
|
|
canvas.save();
|
|
|
|
SkPath path;
|
|
|
|
canvas.clipPath(path);
|
|
|
|
canvas.restore();
|
|
|
|
canvas.save();
|
|
|
|
path.moveTo(5, 5);
|
|
|
|
canvas.clipPath(path);
|
|
|
|
canvas.restore();
|
|
|
|
canvas.save();
|
|
|
|
path.moveTo(7, 7);
|
|
|
|
canvas.clipPath(path); // should not assert here
|
|
|
|
canvas.restore();
|
|
|
|
}
|
2015-08-17 15:05:13 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class MockFilterCanvas : public SkPaintFilterCanvas {
|
|
|
|
public:
|
|
|
|
MockFilterCanvas(SkCanvas* canvas) : INHERITED(canvas) { }
|
|
|
|
|
|
|
|
protected:
|
2018-08-27 22:11:57 +00:00
|
|
|
bool onFilter(SkPaint&) const override { return true; }
|
2015-08-17 15:05:13 +00:00
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = SkPaintFilterCanvas;
|
2015-08-17 15:05:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
// SkPaintFilterCanvas should inherit the initial target canvas state.
|
|
|
|
DEF_TEST(PaintFilterCanvas_ConsistentState, reporter) {
|
|
|
|
SkCanvas canvas(100, 100);
|
|
|
|
canvas.clipRect(SkRect::MakeXYWH(12.7f, 12.7f, 75, 75));
|
|
|
|
canvas.scale(0.5f, 0.75f);
|
|
|
|
|
|
|
|
MockFilterCanvas filterCanvas(&canvas);
|
|
|
|
REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMatrix());
|
2017-01-23 16:39:45 +00:00
|
|
|
REPORTER_ASSERT(reporter, canvas.getLocalClipBounds() == filterCanvas.getLocalClipBounds());
|
2015-08-17 15:05:13 +00:00
|
|
|
|
|
|
|
filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100));
|
|
|
|
filterCanvas.scale(0.75f, 0.5f);
|
|
|
|
REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMatrix());
|
2017-01-23 16:39:45 +00:00
|
|
|
REPORTER_ASSERT(reporter, filterCanvas.getLocalClipBounds().contains(canvas.getLocalClipBounds()));
|
2015-08-17 15:05:13 +00:00
|
|
|
}
|
2016-07-08 15:43:27 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-05-06 19:13:30 +00:00
|
|
|
namespace {
|
|
|
|
|
2016-11-15 16:52:55 +00:00
|
|
|
// Subclass that takes a bool*, which it updates in its construct (true) and destructor (false)
|
|
|
|
// to allow the caller to know how long the object is alive.
|
|
|
|
class LifeLineCanvas : public SkCanvas {
|
|
|
|
bool* fLifeLine;
|
|
|
|
public:
|
|
|
|
LifeLineCanvas(int w, int h, bool* lifeline) : SkCanvas(w, h), fLifeLine(lifeline) {
|
|
|
|
*fLifeLine = true;
|
|
|
|
}
|
2020-07-21 21:03:56 +00:00
|
|
|
~LifeLineCanvas() override {
|
2016-11-15 16:52:55 +00:00
|
|
|
*fLifeLine = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace
|
2019-05-06 19:13:30 +00:00
|
|
|
|
2016-11-15 16:52:55 +00:00
|
|
|
// Check that NWayCanvas does NOT try to manage the lifetime of its sub-canvases
|
|
|
|
DEF_TEST(NWayCanvas, r) {
|
|
|
|
const int w = 10;
|
|
|
|
const int h = 10;
|
|
|
|
bool life[2];
|
|
|
|
{
|
|
|
|
LifeLineCanvas c0(w, h, &life[0]);
|
|
|
|
REPORTER_ASSERT(r, life[0]);
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(r, !life[0]);
|
|
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<SkCanvas> c0 = std::unique_ptr<SkCanvas>(new LifeLineCanvas(w, h, &life[0]));
|
|
|
|
std::unique_ptr<SkCanvas> c1 = std::unique_ptr<SkCanvas>(new LifeLineCanvas(w, h, &life[1]));
|
|
|
|
REPORTER_ASSERT(r, life[0]);
|
|
|
|
REPORTER_ASSERT(r, life[1]);
|
|
|
|
|
|
|
|
{
|
|
|
|
SkNWayCanvas nway(w, h);
|
|
|
|
nway.addCanvas(c0.get());
|
|
|
|
nway.addCanvas(c1.get());
|
|
|
|
REPORTER_ASSERT(r, life[0]);
|
|
|
|
REPORTER_ASSERT(r, life[1]);
|
|
|
|
}
|
|
|
|
// Now assert that the death of the nway has NOT also killed the sub-canvases
|
|
|
|
REPORTER_ASSERT(r, life[0]);
|
|
|
|
REPORTER_ASSERT(r, life[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that CanvasStack DOES manage the lifetime of its sub-canvases
|
|
|
|
DEF_TEST(CanvasStack, r) {
|
|
|
|
const int w = 10;
|
|
|
|
const int h = 10;
|
|
|
|
bool life[2];
|
|
|
|
std::unique_ptr<SkCanvas> c0 = std::unique_ptr<SkCanvas>(new LifeLineCanvas(w, h, &life[0]));
|
|
|
|
std::unique_ptr<SkCanvas> c1 = std::unique_ptr<SkCanvas>(new LifeLineCanvas(w, h, &life[1]));
|
|
|
|
REPORTER_ASSERT(r, life[0]);
|
|
|
|
REPORTER_ASSERT(r, life[1]);
|
|
|
|
|
|
|
|
{
|
|
|
|
SkCanvasStack stack(w, h);
|
|
|
|
stack.pushCanvas(std::move(c0), {0,0});
|
|
|
|
stack.pushCanvas(std::move(c1), {0,0});
|
|
|
|
REPORTER_ASSERT(r, life[0]);
|
|
|
|
REPORTER_ASSERT(r, life[1]);
|
|
|
|
}
|
|
|
|
// Now assert that the death of the canvasstack has also killed the sub-canvases
|
|
|
|
REPORTER_ASSERT(r, !life[0]);
|
|
|
|
REPORTER_ASSERT(r, !life[1]);
|
|
|
|
}
|
2017-03-02 20:21:11 +00:00
|
|
|
|
2017-03-03 01:07:46 +00:00
|
|
|
static void test_cliptype(SkCanvas* canvas, skiatest::Reporter* r) {
|
2017-03-02 20:21:11 +00:00
|
|
|
REPORTER_ASSERT(r, !canvas->isClipEmpty());
|
|
|
|
REPORTER_ASSERT(r, canvas->isClipRect());
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect({0, 0, 0, 0});
|
|
|
|
REPORTER_ASSERT(r, canvas->isClipEmpty());
|
|
|
|
REPORTER_ASSERT(r, !canvas->isClipRect());
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect({2, 2, 6, 6});
|
|
|
|
REPORTER_ASSERT(r, !canvas->isClipEmpty());
|
|
|
|
REPORTER_ASSERT(r, canvas->isClipRect());
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect({2, 2, 6, 6}, SkClipOp::kDifference); // punch a hole in the clip
|
|
|
|
REPORTER_ASSERT(r, !canvas->isClipEmpty());
|
|
|
|
REPORTER_ASSERT(r, !canvas->isClipRect());
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, !canvas->isClipEmpty());
|
|
|
|
REPORTER_ASSERT(r, canvas->isClipRect());
|
|
|
|
}
|
2017-03-03 01:07:46 +00:00
|
|
|
|
|
|
|
DEF_TEST(CanvasClipType, r) {
|
|
|
|
// test rasterclip backend
|
|
|
|
test_cliptype(SkSurface::MakeRasterN32Premul(10, 10)->getCanvas(), r);
|
|
|
|
|
|
|
|
// test clipstack backend
|
|
|
|
SkDynamicMemoryWStream stream;
|
2018-09-07 18:33:14 +00:00
|
|
|
if (auto doc = SkPDF::MakeDocument(&stream)) {
|
2018-03-20 18:17:00 +00:00
|
|
|
test_cliptype(doc->beginPage(100, 100), r);
|
|
|
|
}
|
2017-03-03 01:07:46 +00:00
|
|
|
}
|
2017-04-11 12:46:01 +00:00
|
|
|
|
|
|
|
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
|
|
|
DEF_TEST(Canvas_LegacyColorBehavior, r) {
|
2019-01-04 22:03:00 +00:00
|
|
|
sk_sp<SkColorSpace> cs = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB,
|
|
|
|
SkNamedGamut::kAdobeRGB);
|
2017-04-11 12:46:01 +00:00
|
|
|
|
|
|
|
// Make a Adobe RGB bitmap.
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kOpaque_SkAlphaType, cs));
|
|
|
|
bitmap.eraseColor(0xFF000000);
|
|
|
|
|
|
|
|
// Wrap it in a legacy canvas. Test that the canvas behaves like a legacy canvas.
|
|
|
|
SkCanvas canvas(bitmap, SkCanvas::ColorBehavior::kLegacy);
|
|
|
|
REPORTER_ASSERT(r, !canvas.imageInfo().colorSpace());
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorRED);
|
|
|
|
canvas.drawIRect(SkIRect::MakeWH(1, 1), p);
|
|
|
|
REPORTER_ASSERT(r, SK_ColorRED == SkSwizzle_BGRA_to_PMColor(*bitmap.getAddr32(0, 0)));
|
|
|
|
}
|
|
|
|
#endif
|
2018-01-22 17:51:13 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2019-08-02 13:57:04 +00:00
|
|
|
class ZeroBoundsImageFilter : public SkImageFilter_Base {
|
2018-01-22 17:51:13 +00:00
|
|
|
public:
|
|
|
|
static sk_sp<SkImageFilter> Make() { return sk_sp<SkImageFilter>(new ZeroBoundsImageFilter); }
|
|
|
|
|
|
|
|
protected:
|
2019-08-14 18:35:42 +00:00
|
|
|
sk_sp<SkSpecialImage> onFilterImage(const Context&, SkIPoint*) const override {
|
2018-01-22 17:51:13 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2018-05-17 15:17:39 +00:00
|
|
|
SkIRect onFilterNodeBounds(const SkIRect&, const SkMatrix&,
|
|
|
|
MapDirection, const SkIRect* inputRect) const override {
|
2018-01-22 17:51:13 +00:00
|
|
|
return SkIRect::MakeEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-10-18 21:27:16 +00:00
|
|
|
SK_FLATTENABLE_HOOKS(ZeroBoundsImageFilter)
|
|
|
|
|
2018-01-22 17:51:13 +00:00
|
|
|
ZeroBoundsImageFilter() : INHERITED(nullptr, 0, nullptr) {}
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = SkImageFilter_Base;
|
2018-01-22 17:51:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
sk_sp<SkFlattenable> ZeroBoundsImageFilter::CreateProc(SkReadBuffer& buffer) {
|
|
|
|
SkDEBUGFAIL("Should never get here");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
DEF_TEST(Canvas_SaveLayerWithNullBoundsAndZeroBoundsImageFilter, r) {
|
|
|
|
SkCanvas canvas(10, 10);
|
|
|
|
SkPaint p;
|
|
|
|
p.setImageFilter(ZeroBoundsImageFilter::Make());
|
|
|
|
// This should not fail any assert.
|
|
|
|
canvas.saveLayer(nullptr, &p);
|
|
|
|
REPORTER_ASSERT(r, canvas.getDeviceClipBounds().isEmpty());
|
|
|
|
canvas.restore();
|
|
|
|
}
|
2018-04-13 19:34:16 +00:00
|
|
|
|
|
|
|
// Test that we don't crash/assert when building a canvas with degenerate coordintes
|
|
|
|
// (esp. big ones, that might invoke tiling).
|
|
|
|
DEF_TEST(Canvas_degenerate_dimension, reporter) {
|
|
|
|
// Need a paint that will sneak us past the quickReject in SkCanvas, so we can test the
|
|
|
|
// raster code further downstream.
|
|
|
|
SkPaint paint;
|
Add SkImageFilters::Shader in place of Paint factory
SkImageFilters::Paint did not use every slot of the SkPaint, with only
its color, alpha, color filter, and shader having a meaningful effect on
the image filter result. It was always blended into a transparent dst,
so blend mode wasn't very relevant, and it was always filled to whatever
required geometry, so stroke style, path effect, and mask filters were
ignored or not well specified.
Color, alpha, and color filter can all be combined into an SkShader, so
a more constrained SkImageFilters::Shader provides the same useful
capabilities without as many surprises.
SkImageFilters::Paint still exists, but is deprecated to be removed
once I've confirmed clients aren't depending on it.
Bug: skia:9310
Change-Id: I11a82bda1a5d440726cf4e2b5bfaae4929568679
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/323680
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2020-10-07 19:27:20 +00:00
|
|
|
paint.setImageFilter(SkImageFilters::Shader(SkShaders::Color(SK_ColorBLACK), nullptr));
|
2018-04-13 19:34:16 +00:00
|
|
|
REPORTER_ASSERT(reporter, !paint.canComputeFastBounds());
|
|
|
|
|
|
|
|
const int big = 100 * 1024; // big enough to definitely trigger tiling
|
|
|
|
const SkISize sizes[] {SkISize{0, big}, {big, 0}, {0, 0}};
|
|
|
|
for (SkISize size : sizes) {
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.setInfo(SkImageInfo::MakeN32Premul(size.width(), size.height()));
|
|
|
|
SkCanvas canvas(bm);
|
|
|
|
canvas.drawRect({0, 0, 100, 90*1024}, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-20 14:27:27 +00:00
|
|
|
DEF_TEST(Canvas_ClippedOutImageFilter, reporter) {
|
|
|
|
SkCanvas canvas(100, 100);
|
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorGREEN);
|
2019-08-05 14:41:10 +00:00
|
|
|
p.setImageFilter(SkImageFilters::Blur(3.0f, 3.0f, nullptr, nullptr));
|
2018-04-20 14:27:27 +00:00
|
|
|
|
|
|
|
SkRect blurredRect = SkRect::MakeXYWH(60, 10, 30, 30);
|
|
|
|
|
|
|
|
SkMatrix invM;
|
|
|
|
invM.setRotate(-45);
|
|
|
|
invM.mapRect(&blurredRect);
|
|
|
|
|
|
|
|
const SkRect clipRect = SkRect::MakeXYWH(0, 50, 50, 50);
|
|
|
|
|
|
|
|
canvas.clipRect(clipRect);
|
|
|
|
|
|
|
|
canvas.rotate(45);
|
|
|
|
const SkMatrix preCTM = canvas.getTotalMatrix();
|
|
|
|
canvas.drawRect(blurredRect, p);
|
|
|
|
const SkMatrix postCTM = canvas.getTotalMatrix();
|
|
|
|
REPORTER_ASSERT(reporter, preCTM == postCTM);
|
|
|
|
}
|
|
|
|
|
2020-04-09 16:35:09 +00:00
|
|
|
DEF_TEST(canvas_markctm, reporter) {
|
|
|
|
SkCanvas canvas(10, 10);
|
|
|
|
|
|
|
|
SkM44 m;
|
2020-04-24 16:02:25 +00:00
|
|
|
const char* id_a = "a";
|
|
|
|
const char* id_b = "b";
|
2020-04-09 16:35:09 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, !canvas.findMarkedCTM(id_a, nullptr));
|
|
|
|
REPORTER_ASSERT(reporter, !canvas.findMarkedCTM(id_b, nullptr));
|
|
|
|
|
|
|
|
// remember the starting state
|
|
|
|
SkM44 b = canvas.getLocalToDevice();
|
|
|
|
canvas.markCTM(id_b);
|
|
|
|
|
|
|
|
// test add
|
|
|
|
canvas.concat(SkM44::Scale(2, 4, 6));
|
|
|
|
SkM44 a = canvas.getLocalToDevice();
|
|
|
|
canvas.markCTM(id_a);
|
|
|
|
REPORTER_ASSERT(reporter, canvas.findMarkedCTM(id_a, &m) && m == a);
|
|
|
|
|
|
|
|
// test replace
|
|
|
|
canvas.translate(1, 2);
|
|
|
|
SkM44 a1 = canvas.getLocalToDevice();
|
|
|
|
SkASSERT(a != a1);
|
|
|
|
canvas.markCTM(id_a);
|
|
|
|
REPORTER_ASSERT(reporter, canvas.findMarkedCTM(id_a, &m) && m == a1);
|
|
|
|
|
|
|
|
// test nested
|
|
|
|
canvas.save();
|
|
|
|
// no change
|
|
|
|
REPORTER_ASSERT(reporter, canvas.findMarkedCTM(id_b, &m) && m == b);
|
|
|
|
REPORTER_ASSERT(reporter, canvas.findMarkedCTM(id_a, &m) && m == a1);
|
|
|
|
canvas.translate(2, 3);
|
|
|
|
SkM44 a2 = canvas.getLocalToDevice();
|
|
|
|
SkASSERT(a2 != a1);
|
|
|
|
canvas.markCTM(id_a);
|
|
|
|
// found the new one
|
|
|
|
REPORTER_ASSERT(reporter, canvas.findMarkedCTM(id_a, &m) && m == a2);
|
|
|
|
canvas.restore();
|
|
|
|
// found the previous one
|
|
|
|
REPORTER_ASSERT(reporter, canvas.findMarkedCTM(id_a, &m) && m == a1);
|
|
|
|
}
|