Debian Codegraph @

gm/simplerect.cpp

raw
1 /*
2 * Copyright 2016 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"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkPaint.h"
11 #include "include/core/SkRect.h"
12 #include "include/core/SkScalar.h"
13 #include "include/core/SkSize.h"
14 #include "include/core/SkString.h"
15 #include "src/base/SkRandom.h"
16 #include "tools/ToolUtils.h"
17
18 class SimpleRectGM : public skiagm::GM {
19 public:
20 SimpleRectGM() {}
21
22 protected:
23 SkString getName() const override {
24 SkString name;
25 name.printf("simplerect");
26 return name;
27 }
28
29 SkISize getISize() override { return SkISize::Make(800, 800); }
30
31 void onDraw(SkCanvas* canvas) override {
32 canvas->translate(1, 1); // want to exercise non-identity ctm performance
33
34 const SkScalar min = -20;
35 const SkScalar max = 800;
36 const SkScalar size = 20;
37
38 SkRandom rand;
39 SkPaint paint;
40 for (int i = 0; i < 10000; i++) {
41 paint.setColor(ToolUtils::color_to_565(rand.nextU() | (0xFF << 24)));
42 SkScalar x = rand.nextRangeScalar(min, max);
43 SkScalar y = rand.nextRangeScalar(min, max);
44 SkScalar w = rand.nextRangeScalar(0, size);
45 SkScalar h = rand.nextRangeScalar(0, size);
46 canvas->drawRect(SkRect::MakeXYWH(x, y, w, h), paint);
47 }
48 }
49
50 bool onAnimate(double nanos) override { return true; }
51
52 private:
53
54 using INHERITED = GM;
55 };
56 DEF_GM(return new SimpleRectGM;)