Flutter Engine
The Flutter Engine
aarectmodes.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/SkPath.h"
19#include "include/core/SkRect.h"
25
26static void test4(SkCanvas* canvas) {
28 paint.setAntiAlias(true);
29 SkPoint pts[] = {
30 {10, 160}, {610, 160},
31 {610, 160}, {10, 160},
32
33 {610, 160}, {610, 160},
34 {610, 199}, {610, 199},
35
36 {10, 198}, {610, 198},
37 {610, 199}, {10, 199},
38
39 {10, 160}, {10, 160},
40 {10, 199}, {10, 199}
41 };
42 char verbs[] = {
43 0, 1, 1, 1, 4,
44 0, 1, 1, 1, 4,
45 0, 1, 1, 1, 4,
46 0, 1, 1, 1, 4
47 };
49 SkPoint* ptPtr = pts;
50 for (size_t i = 0; i < sizeof(verbs); ++i) {
51 switch ((SkPath::Verb) verbs[i]) {
53 path.moveTo(ptPtr->fX, ptPtr->fY);
54 ++ptPtr;
55 break;
57 path.lineTo(ptPtr->fX, ptPtr->fY);
58 ++ptPtr;
59 break;
61 path.close();
62 break;
63 default:
64 SkASSERT(false);
65 break;
66 }
67 }
68 SkRect clip = {0, 130, 772, 531};
69 canvas->clipRect(clip);
70 canvas->drawPath(path.detach(), paint);
71}
72
73constexpr SkBlendMode gModes[] = {
86};
87
88const int gWidth = 64;
89const int gHeight = 64;
92
94
96 paint.setAntiAlias(true);
97
99 r.inset(W/10, H/10);
100
101 paint.setColor(SK_ColorBLUE);
102 paint.setAlpha(a0);
103 canvas->drawOval(r, paint);
104
105 paint.setColor(SK_ColorRED);
106 paint.setAlpha(a1);
107 paint.setBlendMode(mode);
108
111 H / 4 + offset,
112 W / 2, H / 2);
113 canvas->drawRect(rect, paint);
114
115 return H;
116}
117
119 SkBitmap bm;
120 bm.allocN32Pixels(2, 2);
121 *bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = 0xFFFFFFFF;
122 *bm.getAddr32(1, 0) = *bm.getAddr32(0, 1) = SkPackARGB32(0xFF, 0xCE,
123 0xCF, 0xCE);
124
126 SkMatrix::Scale(6, 6));
127}
128
129DEF_SIMPLE_GM(aarectmodes, canvas, 640, 480) {
130 SkPaint bgPaint;
131 bgPaint.setShader(make_bg_shader());
132 if ((false)) { // avoid bit rot, suppress warning
133 test4(canvas);
134 }
135 const SkRect bounds = SkRect::MakeWH(W, H);
136 constexpr SkAlpha gAlphaValue[] = { 0xFF, 0x88, 0x88 };
137
138 canvas->translate(SkIntToScalar(4), SkIntToScalar(4));
139
140 for (int alpha = 0; alpha < 4; ++alpha) {
141 canvas->save();
142 canvas->save();
143 for (size_t i = 0; i < std::size(gModes); ++i) {
144 if (6 == i) {
145 canvas->restore();
146 canvas->translate(W * 5, 0);
147 canvas->save();
148 }
149 canvas->drawRect(bounds, bgPaint);
150 canvas->saveLayer(&bounds, nullptr);
151 SkScalar dy = drawCell(canvas, gModes[i],
152 gAlphaValue[alpha & 1],
153 gAlphaValue[alpha & 2]);
154 canvas->restore();
155
156 canvas->translate(0, dy * 5 / 4);
157 }
158 canvas->restore();
159 canvas->restore();
160 canvas->translate(W * 5 / 4, 0);
161 }
162}
#define SkASSERT(cond)
Definition: SkAssert.h:116
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
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
#define SK_Scalar1
Definition: SkScalar.h:18
#define SkIntToScalar(x)
Definition: SkScalar.h:57
const SkScalar H
Definition: aarectmodes.cpp:91
static sk_sp< SkShader > make_bg_shader()
const SkScalar W
Definition: aarectmodes.cpp:90
const int gWidth
Definition: aarectmodes.cpp:88
static SkScalar drawCell(SkCanvas *canvas, SkBlendMode mode, SkAlpha a0, SkAlpha a1)
Definition: aarectmodes.cpp:93
constexpr SkBlendMode gModes[]
Definition: aarectmodes.cpp:73
const int gHeight
Definition: aarectmodes.cpp:89
DEF_SIMPLE_GM(aarectmodes, canvas, 640, 480)
static void test4(SkCanvas *canvas)
Definition: aarectmodes.cpp:26
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
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 clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
void setShader(sk_sp< SkShader > shader)
@ kClose_Verb
Definition: SkPath.h:1471
@ kMove_Verb
Definition: SkPath.h:1466
@ kLine_Verb
Definition: SkPath.h:1467
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
Optional< SkRect > bounds
Definition: SkRecords.h:189
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
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
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
SkSamplingOptions(SkFilterMode::kLinear))
SeparatedVector2 offset
Definition: SkMD5.cpp:130
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
void inset(float dx, float dy)
Definition: SkRect.h:1060
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609