blob: 3847ba5a3228ee33f11df29d83524a111b02964e [file] [log] [blame]
mtkleind2baa902015-07-07 09:43:28 -07001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
9#include "SkCanvas.h"
10#include "SkDrawable.h"
11
12struct MyDrawable : public SkDrawable {
reeda8db7282015-07-07 10:22:31 -070013 SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); }
mtkleind2baa902015-07-07 09:43:28 -070014
15 void onDraw(SkCanvas* canvas) override {
16 SkPath path;
17 path.moveTo(10, 10);
18 path.conicTo(10, 90, 50, 90, 0.9f);
19
20 SkPaint paint;
21 paint.setColor(SK_ColorBLUE);
22 canvas->drawRect(path.getBounds(), paint);
23
24 paint.setAntiAlias(true);
25 paint.setColor(SK_ColorWHITE);
26 canvas->drawPath(path, paint);
27 }
28};
29
reeda8db7282015-07-07 10:22:31 -070030/*
31 * Test calling drawables w/ translate and matrices
32 */
33DEF_SIMPLE_GM(drawable, canvas, 180, 275) {
34 SkAutoTUnref<SkDrawable> drawable(new MyDrawable);
35
36 canvas->translate(10, 10);
37 canvas->drawDrawable(drawable);
38 canvas->drawDrawable(drawable, 0, 150);
39
40 SkMatrix m = SkMatrix::MakeScale(1.5f, 0.8f);
41 m.postTranslate(70, 0);
42 canvas->drawDrawable(drawable, &m);
43
44 m.postTranslate(0, 150);
45 canvas->drawDrawable(drawable, &m);
mtkleind2baa902015-07-07 09:43:28 -070046}