1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/*
* 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/gm.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPicture.h"
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
static sk_sp<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.setBlendMode(SkBlendMode::kPlus);
canvas->drawRect(SkRect::MakeXYWH(25, 25, 50, 50), paint);
return rec.finishRecordingAsPicture();
}
// Exercise the optional arguments to drawPicture
//
class PictureGM : public skiagm::GM {
public:
PictureGM()
: fPicture(nullptr)
{}
protected:
void onOnceBeforeDraw() override {
fPicture = make_picture();
}
SkString onShortName() override {
return SkString("pictures");
}
SkISize onISize() override {
return SkISize::Make(450, 120);
}
void onDraw(SkCanvas* canvas) override {
canvas->translate(10, 10);
SkMatrix matrix;
SkPaint paint;
canvas->drawPicture(fPicture);
matrix.setTranslate(110, 0);
canvas->drawPicture(fPicture, &matrix, nullptr);
matrix.postTranslate(110, 0);
canvas->drawPicture(fPicture, &matrix, &paint);
paint.setAlphaf(0.5f);
matrix.postTranslate(110, 0);
canvas->drawPicture(fPicture, &matrix, &paint);
}
private:
sk_sp<SkPicture> fPicture;
typedef skiagm::GM INHERITED;
};
// 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;
typedef skiagm::GM INHERITED;
};
DEF_GM(return new PictureGM;)
DEF_GM(return new PictureCullRectGM;)
|