Flutter Engine
The Flutter Engine
Classes | Functions | Variables
FilterBoundsSlide.cpp File Reference
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFont.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPathEffect.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/effects/SkDashPathEffect.h"
#include "include/effects/SkGradientShader.h"
#include "include/effects/SkImageFilters.h"
#include "src/core/SkImageFilterTypes.h"
#include "src/core/SkImageFilter_Base.h"
#include "src/core/SkMatrixPriv.h"
#include "src/core/SkRectPriv.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include "tools/viewer/Slide.h"

Go to the source code of this file.

Classes

class  FilterBoundsSample
 

Functions

static float print_size (SkCanvas *canvas, const char *prefix, std::optional< SkIRect > rect, float x, float y, const SkFont &font, const SkPaint &paint)
 
static float print_info (SkCanvas *canvas, const skif::LayerSpace< SkIRect > &layerContentBounds, const skif::DeviceSpace< SkIRect > &outputBounds, std::optional< skif::DeviceSpace< SkIRect > > hintedOutputBounds, const skif::LayerSpace< SkIRect > &unhintedLayerBounds)
 
static void print_label (SkCanvas *canvas, float x, float y, float value)
 
static SkPaint line_paint (SkColor color, bool dashed=false)
 
static SkPath create_axis_path (const SkRect &rect, float axisSpace)
 
static void draw_scale_key (SkCanvas *canvas, float y)
 
static void draw_scale_factors (SkCanvas *canvas, const skif::Mapping &mapping, const SkRect &rect)
 

Variables

static constexpr float kLineHeight = 16.f
 
static constexpr float kLineInset = 8.f
 
static const SkColor4f kScaleGradientColors []
 
static const SkScalar kLogScaleFactors [] = { -3.f, -1.f, 0.f, 1.f, 3.f }
 
static const SkScalar kGradientStops [] = { 0.f, 0.33333f, 0.5f, 0.66667f, 1.f }
 
static const int kStopCount = (int) std::size(kScaleGradientColors)
 

Function Documentation

◆ create_axis_path()

static SkPath create_axis_path ( const SkRect rect,
float  axisSpace 
)
static

Definition at line 98 of file FilterBoundsSlide.cpp.

98 {
99 SkPath localSpace;
100 for (float y = rect.fTop + axisSpace; y <= rect.fBottom; y += axisSpace) {
101 localSpace.moveTo(rect.fLeft, y);
102 localSpace.lineTo(rect.fRight, y);
103 }
104 for (float x = rect.fLeft + axisSpace; x <= rect.fRight; x += axisSpace) {
105 localSpace.moveTo(x, rect.fTop);
106 localSpace.lineTo(x, rect.fBottom);
107 }
108 return localSpace;
109}
Definition: SkPath.h:59
SkPath & moveTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:688
SkPath & lineTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:728
double y
double x
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350

◆ draw_scale_factors()

static void draw_scale_factors ( SkCanvas canvas,
const skif::Mapping mapping,
const SkRect rect 
)
static

Definition at line 136 of file FilterBoundsSlide.cpp.

136 {
137 SkPoint testPoints[5];
138 testPoints[0] = {rect.centerX(), rect.centerY()};
139 rect.toQuad(testPoints + 1);
140 for (int i = 0; i < 5; ++i) {
142 mapping.layerToDevice(),
143 SkPoint(mapping.paramToLayer(skif::ParameterSpace<SkPoint>(testPoints[i]))));
144 SkColor4f color = {0.f, 0.f, 0.f, 1.f};
145
146 if (SkIsFinite(scale)) {
147 float logScale = SkScalarLog2(scale);
148 for (int j = 0; j <= kStopCount; ++j) {
149 if (j == kStopCount) {
151 break;
152 } else if (kLogScaleFactors[j] >= logScale) {
153 if (j == 0) {
155 } else {
156 SkScalar t = (logScale - kLogScaleFactors[j - 1]) /
158
159 SkColor4f a = kScaleGradientColors[j - 1] * (1.f - t);
161 color = {a.fR + b.fR, a.fG + b.fG, a.fB + b.fB, a.fA + b.fA};
162 }
163 break;
164 }
165 }
166 }
167
168 SkPaint p;
169 p.setAntiAlias(true);
170 p.setColor4f(color, nullptr);
171 canvas->drawRect(SkRect::MakeLTRB(testPoints[i].fX - 4.f, testPoints[i].fY - 4.f,
172 testPoints[i].fX + 4.f, testPoints[i].fY + 4.f), p);
173 }
174}
static const int kStopCount
static const SkColor4f kScaleGradientColors[]
static const SkScalar kLogScaleFactors[]
static bool SkIsFinite(T x, Pack... values)
#define SkScalarLog2(x)
Definition: SkScalar.h:53
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
static SkScalar DifferentialAreaScale(const SkMatrix &m, const SkPoint &p)
Definition: SkMatrix.cpp:1786
const SkMatrix & layerToDevice() const
LayerSpace< T > paramToLayer(const ParameterSpace< T > &paramGeometry) const
DlColor color
float SkScalar
Definition: extension.cpp:12
static bool b
struct MyStruct a[10]
const Scalar scale
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646

◆ draw_scale_key()

static void draw_scale_key ( SkCanvas canvas,
float  y 
)
static

Definition at line 121 of file FilterBoundsSlide.cpp.

121 {
122 SkRect key = SkRect::MakeXYWH(15.f, y + 30.f, 15.f, 100.f);
123 SkPoint pts[] = {{key.centerX(), key.fTop}, {key.centerX(), key.fBottom}};
127 SkPaint keyPaint;
128 keyPaint.setShader(gradient);
129 canvas->drawRect(key, keyPaint);
130 for (int i = 0; i < kStopCount; ++i) {
131 print_label(canvas, key.fRight + 5.f, key.fTop + kGradientStops[i] * key.height(),
133 }
134}
static void print_label(SkCanvas *canvas, float x, float y, float value)
static const SkScalar kGradientStops[]
#define SkScalarPow(b, e)
Definition: SkScalar.h:43
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 setShader(sk_sp< SkShader > shader)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ line_paint()

static SkPaint line_paint ( SkColor  color,
bool  dashed = false 
)
static

Definition at line 85 of file FilterBoundsSlide.cpp.

85 {
87 paint.setColor(color);
88 paint.setStrokeWidth(0.f);
90 paint.setAntiAlias(true);
91 if (dashed) {
92 SkScalar dash[2] = {10.f, 10.f};
93 paint.setPathEffect(SkDashPathEffect::Make(dash, 2, 0.f));
94 }
95 return paint;
96}
static sk_sp< SkPathEffect > Make(const SkScalar intervals[], int count, SkScalar phase)
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
const Paint & paint
Definition: color_source.cc:38

◆ print_info()

static float print_info ( SkCanvas canvas,
const skif::LayerSpace< SkIRect > &  layerContentBounds,
const skif::DeviceSpace< SkIRect > &  outputBounds,
std::optional< skif::DeviceSpace< SkIRect > >  hintedOutputBounds,
const skif::LayerSpace< SkIRect > &  unhintedLayerBounds 
)
static

Definition at line 46 of file FilterBoundsSlide.cpp.

50 {
53 text.setAntiAlias(true);
54
55 float y = kLineHeight;
56
57 text.setColor(SK_ColorRED);
58 y = print_size(canvas, "Content (in layer)", SkIRect(layerContentBounds),
60 text.setColor(SK_ColorDKGRAY);
61 y = print_size(canvas, "Target (in device)", SkIRect(outputBounds),
63 text.setColor(SK_ColorBLUE);
64 y = print_size(canvas, "Output (w/ hint)",
65 hintedOutputBounds ? SkIRect(*hintedOutputBounds) : std::optional<SkIRect>{},
67 text.setColor(SK_ColorGREEN);
68 y = print_size(canvas, "Input (w/ no hint)", SkIRect(unhintedLayerBounds),
70
71 return y;
72}
static float print_size(SkCanvas *canvas, const char *prefix, std::optional< SkIRect > rect, float x, float y, const SkFont &font, const SkPaint &paint)
static constexpr float kLineHeight
static constexpr float kLineInset
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
constexpr SkColor SK_ColorDKGRAY
Definition: SkColor.h:108
Definition: SkFont.h:35
std::u16string text
sk_sp< SkTypeface > DefaultTypeface()
font
Font Metadata and Metrics.
Definition: SkRect.h:32

◆ print_label()

static void print_label ( SkCanvas canvas,
float  x,
float  y,
float  value 
)
static

Definition at line 74 of file FilterBoundsSlide.cpp.

74 {
77 text.setAntiAlias(true);
78
79 SkString label;
80 label.printf("%.3f", value);
81
82 canvas->drawString(label, x, y + kLineHeight / 2.f, font, text);
83}
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
uint8_t value

◆ print_size()

static float print_size ( SkCanvas canvas,
const char *  prefix,
std::optional< SkIRect rect,
float  x,
float  y,
const SkFont font,
const SkPaint paint 
)
static

Definition at line 31 of file FilterBoundsSlide.cpp.

33 {
34 canvas->drawString(prefix, x, y, font, paint);
35 y += kLineHeight;
36 SkString sz;
37 if (rect) {
38 sz.appendf("%d x %d", rect->width(), rect->height());
39 } else {
40 sz.appendf("infinite");
41 }
42 canvas->drawString(sz, x, y, font, paint);
43 return y + kLineHeight;
44}
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550

Variable Documentation

◆ kGradientStops

const SkScalar kGradientStops[] = { 0.f, 0.33333f, 0.5f, 0.66667f, 1.f }
static

Definition at line 118 of file FilterBoundsSlide.cpp.

◆ kLineHeight

constexpr float kLineHeight = 16.f
staticconstexpr

Definition at line 28 of file FilterBoundsSlide.cpp.

◆ kLineInset

constexpr float kLineInset = 8.f
staticconstexpr

Definition at line 29 of file FilterBoundsSlide.cpp.

◆ kLogScaleFactors

const SkScalar kLogScaleFactors[] = { -3.f, -1.f, 0.f, 1.f, 3.f }
static

Definition at line 117 of file FilterBoundsSlide.cpp.

◆ kScaleGradientColors

const SkColor4f kScaleGradientColors[]
static
Initial value:
=
{ { 0.05f, 0.0f, 6.f, 1.f },
{ 0.6f, 0.6f, 0.8f, 0.6f },
{ 1.f, 1.f, 1.f, 0.2f },
{ 0.95f, 0.6f, 0.5f, 0.6f },
{ 0.8f, 0.1f, 0.f, 1.f } }

Definition at line 111 of file FilterBoundsSlide.cpp.

◆ kStopCount

const int kStopCount = (int) std::size(kScaleGradientColors)
static

Definition at line 119 of file FilterBoundsSlide.cpp.