2014-08-09 18:08:05 +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 "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBlendMode.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPath.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkPicture.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPictureRecorder.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2014-08-09 18:08:05 +00:00
|
|
|
|
2016-03-18 14:25:55 +00:00
|
|
|
static sk_sp<SkPicture> make_picture() {
|
2014-08-09 18:08:05 +00:00
|
|
|
SkPictureRecorder rec;
|
|
|
|
SkCanvas* canvas = rec.beginRecording(100, 100);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
|
|
|
paint.setColor(0x800000FF);
|
|
|
|
canvas->drawRect(SkRect::MakeWH(100, 100), paint);
|
|
|
|
|
|
|
|
paint.setColor(0x80FF0000);
|
2020-08-26 16:56:51 +00:00
|
|
|
canvas->drawPath(SkPath::Polygon({{0, 0}, {100, 0}, {100, 100}}, false), paint);
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2014-08-09 18:08:05 +00:00
|
|
|
paint.setColor(0x8000FF00);
|
2020-08-26 16:56:51 +00:00
|
|
|
canvas->drawPath(SkPath::Polygon({{0, 0}, {100, 0}, {0, 100}}, false), paint);
|
2014-08-09 18:08:05 +00:00
|
|
|
|
|
|
|
paint.setColor(0x80FFFFFF);
|
2016-10-06 00:33:02 +00:00
|
|
|
paint.setBlendMode(SkBlendMode::kPlus);
|
2014-08-09 18:08:05 +00:00
|
|
|
canvas->drawRect(SkRect::MakeXYWH(25, 25, 50, 50), paint);
|
|
|
|
|
2016-03-18 14:25:55 +00:00
|
|
|
return rec.finishRecordingAsPicture();
|
2014-08-09 18:08:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Exercise the optional arguments to drawPicture
|
|
|
|
//
|
|
|
|
class PictureGM : public skiagm::GM {
|
|
|
|
public:
|
2015-02-25 17:04:04 +00:00
|
|
|
PictureGM()
|
2015-08-27 14:41:13 +00:00
|
|
|
: fPicture(nullptr)
|
2015-02-25 17:04:04 +00:00
|
|
|
{}
|
2014-08-09 18:08:05 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2016-03-18 14:25:55 +00:00
|
|
|
fPicture = make_picture();
|
2015-02-25 17:04:04 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2014-08-09 18:08:05 +00:00
|
|
|
return SkString("pictures");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-08-09 18:08:05 +00:00
|
|
|
return SkISize::Make(450, 120);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-08-09 18:08:05 +00:00
|
|
|
canvas->translate(10, 10);
|
|
|
|
|
|
|
|
SkMatrix matrix;
|
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
canvas->drawPicture(fPicture);
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2014-08-09 18:08:05 +00:00
|
|
|
matrix.setTranslate(110, 0);
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->drawPicture(fPicture, &matrix, nullptr);
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2014-08-09 18:08:05 +00:00
|
|
|
matrix.postTranslate(110, 0);
|
|
|
|
canvas->drawPicture(fPicture, &matrix, &paint);
|
|
|
|
|
2019-02-15 21:13:57 +00:00
|
|
|
paint.setAlphaf(0.5f);
|
2014-08-09 18:08:05 +00:00
|
|
|
matrix.postTranslate(110, 0);
|
|
|
|
canvas->drawPicture(fPicture, &matrix, &paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-03-18 14:25:55 +00:00
|
|
|
sk_sp<SkPicture> fPicture;
|
2014-08-09 18:08:05 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = skiagm::GM;
|
2014-08-09 18:08:05 +00:00
|
|
|
};
|
|
|
|
|
2019-08-14 19:45:17 +00:00
|
|
|
// Exercise drawing a picture with a cull rect of non-zero top-left corner.
|
|
|
|
//
|
|
|
|
// See skbug.com/9334, which would fail
|
|
|
|
// ```
|
|
|
|
// dm -m picture_cull_rect --config serialize-8888
|
|
|
|
// ```
|
|
|
|
// until that bug is fixed.
|
|
|
|
class PictureCullRectGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
PictureCullRectGM()
|
|
|
|
: fPicture(nullptr)
|
|
|
|
{}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
SkPictureRecorder rec;
|
|
|
|
SkRTreeFactory rtreeFactory;
|
|
|
|
SkCanvas* canvas = rec.beginRecording(100, 100, &rtreeFactory);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(false);
|
|
|
|
|
|
|
|
SkRect rect = SkRect::MakeLTRB(0, 80, 100, 100);
|
|
|
|
|
|
|
|
// Make picture complex enough to trigger the cull rect and bbh (RTree) computations.
|
|
|
|
// (A single drawRect won't trigger it.)
|
|
|
|
paint.setColor(0x800000FF);
|
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
canvas->drawOval(rect, paint);
|
|
|
|
|
|
|
|
fPicture = rec.finishRecordingAsPicture();
|
|
|
|
|
|
|
|
SkASSERT(fPicture->cullRect().top() == 80);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("picture_cull_rect");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(120, 120);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
canvas->clipRect(SkRect::MakeLTRB(0, 60, 120, 120));
|
|
|
|
canvas->translate(10, 10);
|
|
|
|
canvas->drawPicture(fPicture);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
sk_sp<SkPicture> fPicture;
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = skiagm::GM;
|
2019-08-14 19:45:17 +00:00
|
|
|
};
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new PictureGM;)
|
2019-08-14 19:45:17 +00:00
|
|
|
DEF_GM(return new PictureCullRectGM;)
|