Flutter Engine
The Flutter Engine
hardstop_gradients_many.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google LLC
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/*
9 * This GM presents different gradients with an increasing number of
10 * hardstops, from 1 to 100.
11 */
12
13#include "gm/gm.h"
18#include "include/core/SkRect.h"
22#include "include/core/SkSize.h"
26
27#include <vector>
28
29const int kWidth = 1000;
30const int kHeight = 2000;
31const int kNumRows = 100;
33const int kPadHeight = 1;
35
37public:
39
40protected:
41 SkString getName() const override { return SkString("hardstop_gradients_many"); }
42
43 SkISize getISize() override { return SkISize::Make(kWidth, kHeight); }
44
45 void onDraw(SkCanvas* canvas) override {
46 static constexpr SkPoint points[] = {
49 };
50
51 std::vector<SkColor> colors;
52 std::vector<SkScalar> positions;
53
54 for (int row = 1; row <= kNumRows; ++row) {
55 // Assemble a gradient containing a blue-to-white blend, repeated N times per row.
56 colors.push_back(SK_ColorBLUE);
57 colors.push_back(SK_ColorWHITE);
58
59 positions = {0.0f};
60 for (int pos = 1; pos < row; ++pos) {
61 float place = SkScalar(pos) / SkScalar(row);
62 positions.push_back(place);
63 positions.push_back(place);
64 }
65 positions.push_back(1.0f);
66 SkASSERT(positions.size() == colors.size());
67
68 // Draw it.
70 colors.data(),
71 positions.data(),
72 colors.size(),
74 /*flags=*/0,
75 /*localMatrix=*/nullptr);
77 paint.setShader(shader);
79
80 canvas->translate(0, kCellHeight);
81 }
82 }
83
84private:
85 using INHERITED = skiagm::GM;
86};
87
static const int points[]
SkPoint pos
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
SkString getName() const override
void onDraw(SkCanvas *canvas) override
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
Definition: gm.h:110
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
#define DEF_GM(CODE)
Definition: gm.h:40
const int kNumRows
const int kRectHeight
const int kHeight
const int kWidth
const int kCellHeight
const int kPadHeight
PODArray< SkColor > colors
Definition: SkRecords.h:276
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659