Flutter Engine
The Flutter Engine
Classes | Typedefs | Functions | Variables
highcontrastfilter.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"
#include "include/effects/SkHighContrastFilter.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Classes

class  HighContrastFilterGM
 

Typedefs

using InvertStyle = SkHighContrastConfig::InvertStyle
 

Functions

static void draw_label (SkCanvas *canvas, const SkHighContrastConfig &config)
 
static void draw_scene (SkCanvas *canvas, const SkHighContrastConfig &config)
 

Variables

static SkScalar kSize = 200
 
static SkColor kColor1 = SkColorSetARGB(0xff, 0xff, 0xff, 0)
 
static SkColor kColor2 = SkColorSetARGB(0xff, 0x82, 0xff, 0)
 

Typedef Documentation

◆ InvertStyle

Definition at line 33 of file highcontrastfilter.cpp.

Function Documentation

◆ draw_label()

static void draw_label ( SkCanvas canvas,
const SkHighContrastConfig config 
)
static

Definition at line 39 of file highcontrastfilter.cpp.

39 {
40 char labelBuffer[256];
41 const char* invertStr =
43 "InvBright" :
45 "InvLight" : "NoInvert"));
46
47 snprintf(labelBuffer, sizeof(labelBuffer), "%s%s contrast=%.1f",
48 config.fGrayscale ? "Gray " : "",
49 invertStr,
50 config.fContrast);
51
53 font.setSize(0.075f);
55
56 size_t len = strlen(labelBuffer);
57
58 SkScalar width = font.measureText(labelBuffer, len, SkTextEncoding::kUTF8);
59 canvas->drawSimpleText(labelBuffer, len, SkTextEncoding::kUTF8, 0.5f - width / 2, 0.16f, font, SkPaint());
60}
@ kUTF8
uses bytes to represent UTF-8 or ASCII
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.cpp:2413
Definition: SkFont.h:35
@ kAntiAlias
may have transparent pixels on glyph edges
float SkScalar
Definition: extension.cpp:12
SkFont DefaultPortableFont()
font
Font Metadata and Metrics.
int32_t width

◆ draw_scene()

static void draw_scene ( SkCanvas canvas,
const SkHighContrastConfig config 
)
static

Definition at line 62 of file highcontrastfilter.cpp.

62 {
63 SkRect bounds = SkRect::MakeLTRB(0.0f, 0.0f, 1.0f, 1.0f);
64 SkPaint xferPaint;
66 canvas->saveLayer(&bounds, &xferPaint);
67
69 bounds = SkRect::MakeLTRB(0.1f, 0.2f, 0.9f, 0.4f);
70 paint.setARGB(0xff, 0x66, 0x11, 0x11);
71 canvas->drawRect(bounds, paint);
72
74 font.setSize(0.15f);
76
77 paint.setARGB(0xff, 0xbb, 0x77, 0x77);
78 canvas->drawString("A", 0.15f, 0.35f, font, paint);
79
80 bounds = SkRect::MakeLTRB(0.1f, 0.8f, 0.9f, 1.0f);
81 paint.setARGB(0xff, 0xcc, 0xcc, 0xff);
82 canvas->drawRect(bounds, paint);
83
84 paint.setARGB(0xff, 0x88, 0x88, 0xbb);
85 canvas->drawString("Z", 0.75f, 0.95f, font, paint);
86
87 bounds = SkRect::MakeLTRB(0.1f, 0.4f, 0.9f, 0.6f);
88 SkPoint pts[] = { { 0, 0 }, { 1, 0 } };
90 SkScalar pos[] = { 0.2f, 0.8f };
92 pts, colors, pos,
94 canvas->drawRect(bounds, paint);
95
96 bounds = SkRect::MakeLTRB(0.1f, 0.6f, 0.9f, 0.8f);
97 SkColor colors2[] = { SK_ColorGREEN, SK_ColorWHITE };
99 pts, colors2, pos,
100 std::size(colors2), SkTileMode::kClamp));
101 canvas->drawRect(bounds, paint);
102
103 canvas->restore();
104}
SkPoint pos
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
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 restore()
Definition: SkCanvas.cpp:461
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
@ kAlias
no transparent pixels on glyph edges
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)
void setColorFilter(sk_sp< SkColorFilter > colorFilter)
const Paint & paint
Definition: color_source.cc:38
Optional< SkRect > bounds
Definition: SkRecords.h:189
PODArray< SkColor > colors
Definition: SkRecords.h:276
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
static sk_sp< SkColorFilter > Make(const SkHighContrastConfig &config)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646

Variable Documentation

◆ kColor1

SkColor kColor1 = SkColorSetARGB(0xff, 0xff, 0xff, 0)
static

Definition at line 36 of file highcontrastfilter.cpp.

◆ kColor2

SkColor kColor2 = SkColorSetARGB(0xff, 0x82, 0xff, 0)
static

Definition at line 37 of file highcontrastfilter.cpp.

◆ kSize

SkScalar kSize = 200
static

Definition at line 35 of file highcontrastfilter.cpp.