Flutter Engine
The Flutter Engine
Classes | Functions | Variables
pictureshader.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPicture.h"
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTextBlob.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypes.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"

Go to the source code of this file.

Classes

class  PictureShaderGM
 

Functions

 DEF_SIMPLE_GM (tiled_picture_shader, canvas, 400, 400)
 
 DEF_SIMPLE_GM (pictureshader_persp, canvas, 215, 110)
 

Variables

struct {
   SkTileMode   tmx
 
   SkTileMode   tmy
 
kTileConfigs []
 

Function Documentation

◆ DEF_SIMPLE_GM() [1/2]

DEF_SIMPLE_GM ( pictureshader_persp  ,
canvas  ,
215  ,
110   
)

Definition at line 239 of file pictureshader.cpp.

239 {
240 enum class DrawStrategy {
241 kDirect,
242 kPictureShader,
243 };
244
245 auto drawPicture = [](SkCanvas* canvas, sk_sp<SkPicture> picture, DrawStrategy strategy) {
246 // Only want local upper 50x50 of 'picture' before we apply decal (or clip)
247 SkRect bounds = {0.f, 0.f, 50.f, 50.f};
248 switch(strategy) {
249 case DrawStrategy::kDirect: {
250 canvas->clipRect(bounds, true);
251 canvas->drawPicture(picture);
252 break; }
253 case DrawStrategy::kPictureShader: {
256 SkFilterMode::kLinear, nullptr, &bounds));
257 canvas->drawRect({0.f, 0.f, 50.f, 50.f}, paint);
258 break; }
259 }
260 };
261
262 auto picture = []() {
264 SkASSERT(typeface);
265 SkFont font;
266 font.setTypeface(typeface);
267 font.setHinting(SkFontHinting::kNormal);
268 font.setSize(8.f);
269
271 paint.setColor(SK_ColorGREEN);
272 SkPictureRecorder recorder;
273 SkCanvas* record_canvas = recorder.beginRecording({0, 0, 100, 100});
274 record_canvas->drawTextBlob(SkTextBlob::MakeFromString("Hamburgefons", font),
275 0, 16.f, paint);
276 return recorder.finishRecordingAsPicture();
277 }();
278
279 SkM44 m;
280 m.preScale(2.f, 2.f);
281 SkM44 persp = SkM44::Perspective(0.01f, 10.f, SK_ScalarPI / 3.f);
282 persp.preTranslate(0.f, 5.f, -0.1f);
283 persp.preConcat(SkM44::Rotate({0.f, 1.f, 0.f}, 0.008f));
284 m.postConcat(persp);
285
286 canvas->clear(SK_ColorBLACK);
287 canvas->translate(5.f, 5.f);
288 for (auto strategy : { DrawStrategy::kDirect,
289 DrawStrategy::kPictureShader }) {
290 canvas->save();
291
292 SkPaint outline;
293 outline.setColor(SK_ColorWHITE);
295 outline.setStrokeWidth(1.f);
296 canvas->drawRect({-1, -1, 101, 101}, outline);
297
298 canvas->clipRect({0, 0, 100, 100});
299 canvas->concat(m);
300
301 drawPicture(canvas, picture, strategy);
302 canvas->restore();
303
304 canvas->translate(105.f, 0.f);
305 }
306}
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
@ kNormal
glyph outlines modified to improve constrast
#define SK_ScalarPI
Definition: SkScalar.h:21
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void clear(SkColor color)
Definition: SkCanvas.h:1199
int save()
Definition: SkCanvas.cpp:447
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
void drawPicture(const SkPicture *picture)
Definition: SkCanvas.h:1961
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2484
Definition: SkFont.h:35
Definition: SkM44.h:150
static SkM44 Rotate(SkV3 axis, SkScalar radians)
Definition: SkM44.h:239
SkM44 & preConcat(const SkM44 &m)
Definition: SkM44.h:351
static SkM44 Perspective(float near, float far, float angle)
Definition: SkM44.cpp:343
SkM44 & preTranslate(SkScalar x, SkScalar y, SkScalar z=0)
Definition: SkM44.cpp:89
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, SkFilterMode mode, const SkMatrix *localMatrix, const SkRect *tileRect) const
static sk_sp< SkTextBlob > MakeFromString(const char *string, const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
Definition: SkTextBlob.h:115
const Paint & paint
Definition: color_source.cc:38
Optional< SkRect > bounds
Definition: SkRecords.h:189
sk_sp< const SkPicture > picture
Definition: SkRecords.h:299
drawPicture(r.picture.get(), &r.matrix, r.paint)) DRAW(DrawTextBlob
sk_sp< SkTypeface > DefaultPortableTypeface()
font
Font Metadata and Metrics.

◆ DEF_SIMPLE_GM() [2/2]

DEF_SIMPLE_GM ( tiled_picture_shader  ,
canvas  ,
400  ,
400   
)

Definition at line 209 of file pictureshader.cpp.

209 {
210 // https://code.google.com/p/skia/issues/detail?id=3398
211 SkRect tile = SkRect::MakeWH(100, 100);
212
213 SkPictureRecorder recorder;
214 SkCanvas* c = recorder.beginRecording(tile);
215
216 SkRect r = tile;
217 r.inset(4, 4);
218 SkPaint p;
219 p.setColor(ToolUtils::color_to_565(0xFF303F9F)); // dark blue
220 c->drawRect(r, p);
221 p.setColor(ToolUtils::color_to_565(0xFFC5CAE9)); // light blue
222 p.setStrokeWidth(10);
223 c->drawLine(20, 20, 80, 80, p);
224
226
227 p.setColor(ToolUtils::color_to_565(0xFF8BC34A)); // green
228 canvas->drawPaint(p);
229
230 canvas->clipRect(SkRect::MakeXYWH(0, 0, 400, 350));
231 p.setColor(0xFFB6B6B6); // gray
232 canvas->drawPaint(p);
233
236 canvas->drawPaint(p);
237}
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
SkColor color_to_565(SkColor color)
Definition: ToolUtils.cpp:139
void inset(float dx, float dy)
Definition: SkRect.h:1060
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

Variable Documentation

◆ 

struct { ... } kTileConfigs[]

◆ tmx

Definition at line 30 of file pictureshader.cpp.

◆ tmy

Definition at line 31 of file pictureshader.cpp.