Flutter Engine
The Flutter Engine
hairmodes.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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"
16#include "include/core/SkRect.h"
20#include "include/core/SkSize.h"
24
25constexpr SkBlendMode gModes[] = {
38};
39
40const int gWidth = 64;
41const int gHeight = 64;
44
46
48 paint.setAntiAlias(true);
49
51 r.inset(W/10, H/10);
52
53 paint.setColor(SK_ColorBLUE);
54 paint.setAlpha(a0);
55 canvas->drawOval(r, paint);
56
57 paint.setColor(SK_ColorRED);
58 paint.setAlpha(a1);
59 paint.setBlendMode(mode);
60 for (int angle = 0; angle < 24; ++angle) {
61 SkScalar x = SkScalarCos(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gWidth;
62 SkScalar y = SkScalarSin(SkIntToScalar(angle) * (SK_ScalarPI * 2) / 24) * gHeight;
63 paint.setStrokeWidth(SK_Scalar1 * angle * 2 / 24);
64 canvas->drawLine(W/2, H/2, W/2 + x, H/2 + y, paint);
65 }
66
67 return H;
68}
69
71 SkBitmap bm;
72 bm.allocN32Pixels(2, 2);
73 *bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = 0xFFFFFFFF;
74 *bm.getAddr32(1, 0) = *bm.getAddr32(0, 1) = SkPackARGB32(0xFF, 0xCE, 0xCF, 0xCE);
75
76 SkMatrix m;
77 m.setScale(SkIntToScalar(6), SkIntToScalar(6));
79}
80
81namespace skiagm {
82
83 class HairModesGM : public GM {
84 SkPaint fBGPaint;
85
86 protected:
87 SkString getName() const override { return SkString("hairmodes"); }
88
89 SkISize getISize() override { return SkISize::Make(640, 480); }
90
91 void onOnceBeforeDraw() override {
92 fBGPaint.setShader(make_bg_shader());
93 }
94
95 void onDraw(SkCanvas* canvas) override {
96 const SkRect bounds = SkRect::MakeWH(W, H);
97 constexpr SkAlpha gAlphaValue[] = { 0xFF, 0x88, 0x88 };
98
100
101 for (int alpha = 0; alpha < 4; ++alpha) {
102 canvas->save();
103 canvas->save();
104 for (size_t i = 0; i < std::size(gModes); ++i) {
105 if (6 == i) {
106 canvas->restore();
107 canvas->translate(W * 5, 0);
108 canvas->save();
109 }
110
111 canvas->drawRect(bounds, fBGPaint);
112 canvas->saveLayer(&bounds, nullptr);
113 SkScalar dy = drawCell(canvas, gModes[i],
114 gAlphaValue[alpha & 1],
115 gAlphaValue[alpha & 2]);
116 canvas->restore();
117
118 canvas->translate(0, dy * 5 / 4);
119 }
120 canvas->restore();
121 canvas->restore();
122 canvas->translate(W * 5 / 4, 0);
123 }
124 }
125
126 private:
127 using INHERITED = GM;
128 };
129
130 //////////////////////////////////////////////////////////////////////////////
131
132 DEF_GM( return new HairModesGM; )
133} // namespace skiagm
SkBlendMode
Definition: SkBlendMode.h:38
@ kSrcOut
r = s * (1-da)
@ kDstIn
r = d * sa
@ kSrcOver
r = s + (1-sa)*d
@ kXor
r = s*(1-da) + d*(1-sa)
@ kSrcATop
r = s*da + d*(1-sa)
@ kDstATop
r = d*sa + s*(1-da)
@ kDstOver
r = d + (1-da)*s
@ kDstOut
r = d * (1-sa)
@ kSrcIn
r = s * da
@ kClear
r = 0
static SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColorPriv.h:106
uint8_t SkAlpha
Definition: SkColor.h:26
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SK_Scalar1
Definition: SkScalar.h:18
#define SkIntToScalar(x)
Definition: SkScalar.h:57
#define SkScalarCos(radians)
Definition: SkScalar.h:46
#define SK_ScalarPI
Definition: SkScalar.h:21
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkBitmap.cpp:669
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
uint32_t * getAddr32(int x, int y) const
Definition: SkBitmap.h:1260
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawOval(const SkRect &oval, const SkPaint &paint)
Definition: SkCanvas.cpp:1698
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
int save()
Definition: SkCanvas.cpp:447
void setShader(sk_sp< SkShader > shader)
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
SkString getName() const override
Definition: hairmodes.cpp:87
void onDraw(SkCanvas *canvas) override
Definition: hairmodes.cpp:95
void onOnceBeforeDraw() override
Definition: hairmodes.cpp:91
SkISize getISize() override
Definition: hairmodes.cpp:89
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
const SkScalar H
Definition: hairmodes.cpp:43
static sk_sp< SkShader > make_bg_shader()
Definition: hairmodes.cpp:70
const SkScalar W
Definition: hairmodes.cpp:42
const int gWidth
Definition: hairmodes.cpp:40
static SkScalar drawCell(SkCanvas *canvas, SkBlendMode mode, SkAlpha a0, SkAlpha a1)
Definition: hairmodes.cpp:45
constexpr SkBlendMode gModes[]
Definition: hairmodes.cpp:25
const int gHeight
Definition: hairmodes.cpp:41
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
static sk_sp< SkShader > make_bg_shader(int checkSize)
SkSamplingOptions(SkFilterMode::kLinear))
Definition: SkMD5.cpp:130
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
void inset(float dx, float dy)
Definition: SkRect.h:1060
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609