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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkPictureRecorder.h"
|
|
|
|
|
|
|
|
static SkPicture* make_picture() {
|
|
|
|
SkPictureRecorder rec;
|
|
|
|
SkCanvas* canvas = rec.beginRecording(100, 100);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
SkPath path;
|
|
|
|
|
|
|
|
paint.setColor(0x800000FF);
|
|
|
|
canvas->drawRect(SkRect::MakeWH(100, 100), paint);
|
|
|
|
|
|
|
|
paint.setColor(0x80FF0000);
|
|
|
|
path.moveTo(0, 0); path.lineTo(100, 0); path.lineTo(100, 100);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
|
|
|
|
paint.setColor(0x8000FF00);
|
|
|
|
path.reset(); path.moveTo(0, 0); path.lineTo(100, 0); path.lineTo(0, 100);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
|
|
|
|
paint.setColor(0x80FFFFFF);
|
|
|
|
paint.setXfermodeMode(SkXfermode::kPlus_Mode);
|
|
|
|
canvas->drawRect(SkRect::MakeXYWH(25, 25, 50, 50), paint);
|
|
|
|
|
|
|
|
return rec.endRecording();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
2015-02-25 17:04:04 +00:00
|
|
|
fPicture.reset(make_picture());
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
matrix.setTranslate(110, 0);
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->drawPicture(fPicture, &matrix, nullptr);
|
2014-08-09 18:08:05 +00:00
|
|
|
|
|
|
|
matrix.postTranslate(110, 0);
|
|
|
|
canvas->drawPicture(fPicture, &matrix, &paint);
|
|
|
|
|
|
|
|
paint.setAlpha(0x80);
|
|
|
|
matrix.postTranslate(110, 0);
|
|
|
|
canvas->drawPicture(fPicture, &matrix, &paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkAutoTUnref<SkPicture> fPicture;
|
|
|
|
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new PictureGM;)
|