2014-10-30 18:44:19 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPicture.h"
|
|
|
|
#include "include/core/SkPictureRecorder.h"
|
|
|
|
#include "src/core/SkBBoxHierarchy.h"
|
|
|
|
#include "src/core/SkRectPriv.h"
|
|
|
|
|
|
|
|
#include "tests/Test.h"
|
2014-10-30 18:44:19 +00:00
|
|
|
|
|
|
|
class PictureBBHTestBase {
|
|
|
|
public:
|
|
|
|
PictureBBHTestBase(int playbackWidth, int playbackHeight,
|
|
|
|
int recordWidth, int recordHeight) {
|
|
|
|
|
|
|
|
fResultBitmap.allocN32Pixels(playbackWidth, playbackHeight);
|
|
|
|
fPictureWidth = recordWidth;
|
|
|
|
fPictureHeight = recordHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~PictureBBHTestBase() { }
|
|
|
|
|
|
|
|
virtual void doTest(SkCanvas& playbackCanvas, SkCanvas& recordingCanvas) = 0;
|
|
|
|
|
|
|
|
void run(skiatest::Reporter* reporter) {
|
|
|
|
// No BBH
|
2015-08-27 14:41:13 +00:00
|
|
|
this->run(nullptr, reporter);
|
2014-10-30 18:44:19 +00:00
|
|
|
|
|
|
|
// With an R-Tree
|
|
|
|
SkRTreeFactory RTreeFactory;
|
|
|
|
this->run(&RTreeFactory, reporter);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void run(SkBBHFactory* factory, skiatest::Reporter* reporter) {
|
|
|
|
SkCanvas playbackCanvas(fResultBitmap);
|
|
|
|
playbackCanvas.clear(SK_ColorGREEN);
|
|
|
|
SkPictureRecorder recorder;
|
2014-11-20 16:01:09 +00:00
|
|
|
SkCanvas* recordCanvas = recorder.beginRecording(SkIntToScalar(fPictureWidth),
|
|
|
|
SkIntToScalar(fPictureHeight),
|
|
|
|
factory);
|
2014-10-30 18:44:19 +00:00
|
|
|
this->doTest(playbackCanvas, *recordCanvas);
|
2016-03-18 14:25:55 +00:00
|
|
|
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
|
2014-10-30 18:44:19 +00:00
|
|
|
playbackCanvas.drawPicture(picture);
|
|
|
|
REPORTER_ASSERT(reporter, SK_ColorGREEN == fResultBitmap.getColor(0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
SkBitmap fResultBitmap;
|
|
|
|
int fPictureWidth, fPictureHeight;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test to verify the playback of an empty picture
|
2015-01-05 15:02:45 +00:00
|
|
|
//
|
2014-10-30 18:44:19 +00:00
|
|
|
class DrawEmptyPictureBBHTest : public PictureBBHTestBase {
|
|
|
|
public:
|
|
|
|
DrawEmptyPictureBBHTest()
|
2017-03-22 16:05:03 +00:00
|
|
|
: PictureBBHTestBase(2, 2, 1, 1) {}
|
|
|
|
~DrawEmptyPictureBBHTest() override {}
|
2014-10-30 18:44:19 +00:00
|
|
|
|
2017-03-22 16:05:03 +00:00
|
|
|
void doTest(SkCanvas&, SkCanvas&) override {}
|
2014-10-30 18:44:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Test to verify the playback of a picture into a canvas that has
|
|
|
|
// an empty clip.
|
|
|
|
//
|
|
|
|
class EmptyClipPictureBBHTest : public PictureBBHTestBase {
|
|
|
|
public:
|
2015-01-05 15:02:45 +00:00
|
|
|
EmptyClipPictureBBHTest()
|
2017-03-22 16:05:03 +00:00
|
|
|
: PictureBBHTestBase(2, 2, 3, 3) {}
|
2014-10-30 18:44:19 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void doTest(SkCanvas& playbackCanvas, SkCanvas& recordingCanvas) override {
|
2014-10-30 18:44:19 +00:00
|
|
|
// intersect with out of bounds rect -> empty clip.
|
2016-09-20 15:42:38 +00:00
|
|
|
playbackCanvas.clipRect(SkRect::MakeXYWH(10, 10, 1, 1));
|
2014-10-30 18:44:19 +00:00
|
|
|
SkPaint paint;
|
2016-09-20 15:42:38 +00:00
|
|
|
recordingCanvas.drawRect(SkRect::MakeWH(3, 3), paint);
|
2014-10-30 18:44:19 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 16:05:03 +00:00
|
|
|
~EmptyClipPictureBBHTest() override {}
|
2014-10-30 18:44:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEF_TEST(PictureBBH, reporter) {
|
|
|
|
|
|
|
|
DrawEmptyPictureBBHTest emptyPictureTest;
|
|
|
|
emptyPictureTest.run(reporter);
|
|
|
|
|
|
|
|
EmptyClipPictureBBHTest emptyClipPictureTest;
|
|
|
|
emptyClipPictureTest.run(reporter);
|
|
|
|
}
|
2017-04-07 14:46:39 +00:00
|
|
|
|
2018-05-04 17:51:11 +00:00
|
|
|
DEF_TEST(PictureNegativeSpace, r) {
|
|
|
|
SkRTreeFactory factory;
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
|
|
|
|
SkRect cull = {-200,-200,+200,+200};
|
|
|
|
|
|
|
|
{
|
|
|
|
auto canvas = recorder.beginRecording(cull, &factory);
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(cull);
|
|
|
|
canvas->drawRect({-20,-20,-10,-10}, SkPaint{});
|
|
|
|
canvas->drawRect({-20,-20,-10,-10}, SkPaint{});
|
|
|
|
canvas->restore();
|
|
|
|
auto pic = recorder.finishRecordingAsPicture();
|
|
|
|
REPORTER_ASSERT(r, pic->approximateOpCount() == 5);
|
|
|
|
REPORTER_ASSERT(r, pic->cullRect() == (SkRect{-20,-20,-10,-10}));
|
|
|
|
}
|
|
|
|
|
2018-05-07 14:56:40 +00:00
|
|
|
{
|
2018-05-04 17:51:11 +00:00
|
|
|
auto canvas = recorder.beginRecording(cull, &factory);
|
|
|
|
canvas->clipRect(cull);
|
|
|
|
canvas->drawRect({-20,-20,-10,-10}, SkPaint{});
|
|
|
|
canvas->drawRect({-20,-20,-10,-10}, SkPaint{});
|
|
|
|
auto pic = recorder.finishRecordingAsPicture();
|
|
|
|
REPORTER_ASSERT(r, pic->approximateOpCount() == 3);
|
|
|
|
REPORTER_ASSERT(r, pic->cullRect() == (SkRect{-20,-20,-10,-10}));
|
|
|
|
}
|
|
|
|
}
|