Flutter Engine
The Flutter Engine
drawable.cpp
Go to the documentation of this file.
1/*
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/gm.h"
15#include "include/core/SkRect.h"
17
18struct MyDrawable : public SkDrawable {
19 SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); }
20
21 void onDraw(SkCanvas* canvas) override {
23 .conicTo(10, 90, 50, 90, 0.9f)
24 .detach();
25
27 paint.setColor(SK_ColorBLUE);
28 canvas->drawRect(path.getBounds(), paint);
29
30 paint.setAntiAlias(true);
31 paint.setColor(SK_ColorWHITE);
32 canvas->drawPath(path, paint);
33 }
34};
35
36/*
37 * Test calling drawables w/ translate and matrices
38 */
39DEF_SIMPLE_GM(drawable, canvas, 180, 275) {
40 sk_sp<SkDrawable> drawable(new MyDrawable);
41
42 canvas->translate(10, 10);
43 canvas->drawDrawable(drawable.get());
44 canvas->drawDrawable(drawable.get(), 0, 150);
45
46 SkMatrix m = SkMatrix::Scale(1.5f, 0.8f);
47 m.postTranslate(70, 0);
48 canvas->drawDrawable(drawable.get(), &m);
49
50 m.postTranslate(0, 150);
51 canvas->drawDrawable(drawable.get(), &m);
52}
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
SkPathBuilder & conicTo(SkPoint pt1, SkPoint pt2, SkScalar w)
SkPathBuilder & moveTo(SkPoint pt)
Definition: SkPath.h:59
T * get() const
Definition: SkRefCnt.h:303
const Paint & paint
Definition: color_source.cc:38
DEF_SIMPLE_GM(drawable, canvas, 180, 275)
Definition: drawable.cpp:39
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
void onDraw(SkCanvas *canvas) override
Definition: drawable.cpp:21
SkRect onGetBounds() override
Definition: drawable.cpp:19
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609