Flutter Engine
The Flutter Engine
Classes | Functions
imagefiltersbase.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkFlattenable.h"
#include "include/core/SkFont.h"
#include "include/core/SkImageFilter.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRSXform.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkImageFilters.h"
#include "include/utils/SkTextUtils.h"
#include "src/core/SkImageFilter_Base.h"
#include "src/core/SkSpecialImage.h"
#include "src/utils/SkPatchUtils.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include <utility>

Go to the source code of this file.

Classes

class  ImageFiltersBaseGM
 
class  ImageFiltersTextBaseGM
 
class  ImageFiltersText_IF
 
class  ImageFiltersText_CF
 

Functions

static void draw_paint (SkCanvas *canvas, SkImage *, const SkRect &r, sk_sp< SkImageFilter > imf)
 
static void draw_line (SkCanvas *canvas, SkImage *, const SkRect &r, sk_sp< SkImageFilter > imf)
 
static void draw_rect (SkCanvas *canvas, SkImage *, const SkRect &r, sk_sp< SkImageFilter > imf)
 
static void draw_path (SkCanvas *canvas, SkImage *, const SkRect &r, sk_sp< SkImageFilter > imf)
 
static void draw_text (SkCanvas *canvas, SkImage *, const SkRect &r, sk_sp< SkImageFilter > imf)
 
static void draw_bitmap (SkCanvas *canvas, SkImage *i, const SkRect &r, sk_sp< SkImageFilter > imf)
 
static void draw_patch (SkCanvas *canvas, SkImage *, const SkRect &r, sk_sp< SkImageFilter > imf)
 
static void draw_atlas (SkCanvas *canvas, SkImage *atlas, const SkRect &r, sk_sp< SkImageFilter > imf)
 

Function Documentation

◆ draw_atlas()

static void draw_atlas ( SkCanvas canvas,
SkImage atlas,
const SkRect r,
sk_sp< SkImageFilter imf 
)
static

Definition at line 125 of file imagefiltersbase.cpp.

126 {
127 const SkScalar rad = SkDegreesToRadians(15.0f);
128 SkRSXform xform = SkRSXform::Make(SkScalarCos(rad), SkScalarSin(rad), r.width() * 0.15f, 0);
129
131 paint.setImageFilter(std::move(imf));
132 paint.setAntiAlias(true);
134 canvas->drawAtlas(atlas, &xform, &r, /*colors=*/nullptr, /*count=*/1, SkBlendMode::kSrc,
135 sampling, /*cullRect=*/nullptr, &paint);
136}
#define SkDegreesToRadians(degrees)
Definition: SkScalar.h:77
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SkScalarCos(radians)
Definition: SkScalar.h:46
void drawAtlas(const SkImage *atlas, const SkRSXform xform[], const SkRect tex[], const SkColor colors[], int count, SkBlendMode mode, const SkSamplingOptions &sampling, const SkRect *cullRect, const SkPaint *paint)
Definition: SkCanvas.cpp:1810
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
sk_sp< const SkImage > atlas
Definition: SkRecords.h:331
SkSamplingOptions sampling
Definition: SkRecords.h:337
static constexpr SkCubicResampler Mitchell()
static SkRSXform Make(SkScalar scos, SkScalar ssin, SkScalar tx, SkScalar ty)
Definition: SkRSXform.h:24
constexpr float width() const
Definition: SkRect.h:762

◆ draw_bitmap()

static void draw_bitmap ( SkCanvas canvas,
SkImage i,
const SkRect r,
sk_sp< SkImageFilter imf 
)
static

Definition at line 83 of file imagefiltersbase.cpp.

83 {
85 paint.setImageFilter(std::move(imf));
86
88 r.roundOut(&bounds);
89
90 SkBitmap bm;
91 bm.allocN32Pixels(bounds.width(), bounds.height());
93 SkCanvas c(bm);
94 draw_path(&c, i, r, nullptr);
95
96 canvas->drawImage(bm.asImage(), 0, 0, SkSamplingOptions(), &paint);
97}
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
static void draw_path(SkCanvas *canvas, SkImage *, const SkRect &r, sk_sp< SkImageFilter > imf)
Optional< SkRect > bounds
Definition: SkRecords.h:189
Definition: SkRect.h:32
void roundOut(SkIRect *dst) const
Definition: SkRect.h:1241

◆ draw_line()

static void draw_line ( SkCanvas canvas,
SkImage ,
const SkRect r,
sk_sp< SkImageFilter imf 
)
static

Definition at line 49 of file imagefiltersbase.cpp.

49 {
51 paint.setColor(SK_ColorBLUE);
52 paint.setImageFilter(imf);
53 paint.setStrokeWidth(r.width()/10);
54 canvas->drawLine(r.fLeft, r.fTop, r.fRight, r.fBottom, paint);
55}
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
SkScalar fBottom
larger y-axis bounds
Definition: extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15

◆ draw_paint()

static void draw_paint ( SkCanvas canvas,
SkImage ,
const SkRect r,
sk_sp< SkImageFilter imf 
)
static

Definition at line 39 of file imagefiltersbase.cpp.

39 {
41 paint.setImageFilter(std::move(imf));
42 paint.setColor(SK_ColorGREEN);
43 canvas->save();
44 canvas->clipRect(r);
45 canvas->drawPaint(paint);
46 canvas->restore();
47}
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
int save()
Definition: SkCanvas.cpp:447

◆ draw_patch()

static void draw_patch ( SkCanvas canvas,
SkImage ,
const SkRect r,
sk_sp< SkImageFilter imf 
)
static

Definition at line 99 of file imagefiltersbase.cpp.

99 {
101 paint.setImageFilter(std::move(imf));
102
103 // The order of the colors and points is clockwise starting at upper-left corner.
104 static constexpr SkPoint gCubics[SkPatchUtils::kNumCtrlPts] = {
105 //top points
106 {100,100},{150,50},{250,150},{300,100},
107 //right points
108 {250,150},{350,250},
109 //bottom points
110 {300,300},{250,250},{150,350},{100,300},
111 //left points
112 {50,250},{150,150}
113 };
114
115 static constexpr SkColor colors[SkPatchUtils::kNumCorners] = {
117 };
118
119 SkAutoCanvasRestore acr(canvas, /*doSave=*/true);
120 canvas->translate(-r.fLeft, -r.fTop);
121 canvas->scale(r.width() / 400.0, r.height() / 400.0);
122 canvas->drawPatch(gCubics, colors, /*texCoords=*/nullptr, SkBlendMode::kDst, paint);
123}
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
void drawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkBlendMode mode, const SkPaint &paint)
Definition: SkCanvas.cpp:2529
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
PODArray< SkColor > colors
Definition: SkRecords.h:276
const SkPoint gCubics[SkPatchUtils::kNumCtrlPts]
Definition: patch.cpp:81
constexpr float height() const
Definition: SkRect.h:769

◆ draw_path()

static void draw_path ( SkCanvas canvas,
SkImage ,
const SkRect r,
sk_sp< SkImageFilter imf 
)
static

Definition at line 66 of file imagefiltersbase.cpp.

66 {
68 paint.setColor(SK_ColorMAGENTA);
69 paint.setImageFilter(imf);
70 paint.setAntiAlias(true);
71 canvas->drawCircle(r.centerX(), r.centerY(), r.width()*2/5, paint);
72}
constexpr SkColor SK_ColorMAGENTA
Definition: SkColor.h:147
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
constexpr float centerX() const
Definition: SkRect.h:776
constexpr float centerY() const
Definition: SkRect.h:785

◆ draw_rect()

static void draw_rect ( SkCanvas canvas,
SkImage ,
const SkRect r,
sk_sp< SkImageFilter imf 
)
static

Definition at line 57 of file imagefiltersbase.cpp.

57 {
59 paint.setColor(SK_ColorYELLOW);
60 paint.setImageFilter(imf);
61 SkRect rr(r);
62 rr.inset(r.width()/10, r.height()/10);
63 canvas->drawRect(rr, paint);
64}
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673

◆ draw_text()

static void draw_text ( SkCanvas canvas,
SkImage ,
const SkRect r,
sk_sp< SkImageFilter imf 
)
static

Definition at line 74 of file imagefiltersbase.cpp.

74 {
76 paint.setImageFilter(imf);
77 paint.setColor(SK_ColorCYAN);
79 SkTextUtils::DrawString(canvas, "Text", r.centerX(), r.centerY(), font, paint,
81}
Definition: SkFont.h:35
static void DrawString(SkCanvas *canvas, const char text[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint, Align align=kLeft_Align)
Definition: SkTextUtils.h:34
sk_sp< SkTypeface > DefaultPortableTypeface()
font
Font Metadata and Metrics.