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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkBBoxHierarchy.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkPicture.h"
|
|
|
|
#include "SkPictureRecorder.h"
|
|
|
|
|
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
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()
|
|
|
|
: PictureBBHTestBase(2, 2, 1, 1) { }
|
|
|
|
virtual ~DrawEmptyPictureBBHTest() { }
|
|
|
|
|
2015-03-26 01:17:31 +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()
|
2014-10-30 18:44:19 +00:00
|
|
|
: PictureBBHTestBase(2, 2, 3, 3) { }
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~EmptyClipPictureBBHTest() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_TEST(PictureBBH, reporter) {
|
|
|
|
|
|
|
|
DrawEmptyPictureBBHTest emptyPictureTest;
|
|
|
|
emptyPictureTest.run(reporter);
|
|
|
|
|
|
|
|
EmptyClipPictureBBHTest emptyClipPictureTest;
|
|
|
|
emptyClipPictureTest.run(reporter);
|
|
|
|
}
|