Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
simplerect.cpp
Go to the documentation of this file.
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"
11#include "include/core/SkRect.h"
13#include "include/core/SkSize.h"
15#include "src/base/SkRandom.h"
16#include "tools/ToolUtils.h"
17
18class SimpleRectGM : public skiagm::GM {
19public:
21
22protected:
23 SkString getName() const override {
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;
40 for (int i = 0; i < 10000; i++) {
41 paint.setColor(ToolUtils::color_to_565(rand.nextU() | (0xFF << 24)));
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
52private:
53
54 using INHERITED = GM;
55};
56DEF_GM(return new SimpleRectGM;)
SkString getName() const override
SkISize getISize() override
bool onAnimate(double nanos) override
void onDraw(SkCanvas *canvas) override
void drawRect(const SkRect &rect, const SkPaint &paint)
void translate(SkScalar dx, SkScalar dy)
uint32_t nextU()
Definition SkRandom.h:42
SkScalar nextRangeScalar(SkScalar min, SkScalar max)
Definition SkRandom.h:106
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:534
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition gm.cpp:81
const Paint & paint
float SkScalar
Definition extension.cpp:12
const char * name
Definition fuchsia.cc:50
#define DEF_GM(CODE)
Definition gm.h:40
static float max(float r, float g, float b)
Definition hsl.cpp:49
static float min(float r, float g, float b)
Definition hsl.cpp:48
double y
double x
SkColor color_to_565(SkColor color)
SkScalar w
SkScalar h
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659