Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
tilemodes.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFont.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.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/utils/SkTextUtils.h"
#include "tools/DecodeUtils.h"
#include "tools/GpuToolUtils.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include <functional>

Go to the source code of this file.

Classes

class  TilingGM
 
class  Tiling2GM
 

Typedefs

typedef sk_sp< SkShader >(* ShaderProc) (SkTileMode, SkTileMode)
 

Functions

static void makebm (SkBitmap *bm, SkColorType ct, int w, int h)
 
static void setup (SkCanvas *canvas, SkPaint *paint, const SkBitmap &bm, SkFilterMode fm, SkTileMode tmx, SkTileMode tmy)
 
static sk_sp< SkShadermake_bm (SkTileMode tx, SkTileMode ty)
 
static sk_sp< SkShadermake_grad (SkTileMode tx, SkTileMode ty)
 
 DEF_SIMPLE_GM (tilemode_decal, canvas, 720, 1100)
 

Variables

constexpr SkColorType gColorTypes []
 
constexpr int gWidth = 32
 
constexpr int gHeight = 32
 

Typedef Documentation

◆ ShaderProc

typedef sk_sp< SkShader >(* ShaderProc) (SkTileMode, SkTileMode)

Definition at line 201 of file tilemodes.cpp.

Function Documentation

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( tilemode_decal  ,
canvas  ,
720  ,
1100   
)

Definition at line 272 of file tilemodes.cpp.

272 {
273 auto img = ToolUtils::GetResourceAsImage("images/mandrill_128.png");
274 SkPaint bgpaint;
275 bgpaint.setColor(SK_ColorYELLOW);
276
277 SkRect r = { -20, -20, img->width() + 20.0f, img->height() + 20.0f };
278 canvas->translate(45, 45);
279
280 std::function<void(SkPaint*, SkTileMode, SkTileMode)> shader_procs[] = {
281 [img](SkPaint* paint, SkTileMode tx, SkTileMode ty) {
282 // Test no filtering with decal mode
283 paint->setShader(img->makeShader(tx, ty, SkSamplingOptions(SkFilterMode::kNearest)));
284 },
285 [img](SkPaint* paint, SkTileMode tx, SkTileMode ty) {
286 // Test bilerp approximation for decal mode (or clamp to border HW)
287 paint->setShader(img->makeShader(tx, ty, SkSamplingOptions(SkFilterMode::kLinear)));
288 },
289 [img](SkPaint* paint, SkTileMode tx, SkTileMode ty) {
290 // Test bicubic filter with decal mode
291 paint->setShader(img->makeShader(tx, ty, SkSamplingOptions(SkCubicResampler::Mitchell())));
292 },
293 [img](SkPaint* paint, SkTileMode tx, SkTileMode ty) {
295 const SkPoint pts[] = {{ 0, 0 }, {img->width()*1.0f, img->height()*1.0f }};
296 const SkScalar* pos = nullptr;
297 const int count = std::size(colors);
298 paint->setShader(SkGradientShader::MakeLinear(pts, colors, pos, count, tx));
299 },
300 [img](SkPaint* paint, SkTileMode tx, SkTileMode ty) {
302 const SkScalar* pos = nullptr;
303 const int count = std::size(colors);
304 paint->setShader(SkGradientShader::MakeRadial({ img->width()*0.5f, img->width()*0.5f },
305 img->width()*0.5f, colors, pos, count, tx));
306 },
307 };
308
309 const struct XY {
310 SkTileMode fX;
311 SkTileMode fY;
312 } pairs[] = {
317 };
318 for (const auto& p : pairs) {
320 canvas->save();
321 for (const auto& proc : shader_procs) {
322 canvas->save();
323 // Apply a slight rotation to highlight the differences between filtered and unfiltered
324 // decal edges
325 canvas->rotate(4);
326 canvas->drawRect(r, bgpaint);
327 proc(&paint, p.fX, p.fY);
328 canvas->drawRect(r, paint);
329 canvas->restore();
330 canvas->translate(0, r.height() + 20);
331 }
332 canvas->restore();
333 canvas->translate(r.width() + 10, 0);
334 }
335}
int count
SkPoint pos
constexpr SkColor SK_ColorYELLOW
Definition SkColor.h:139
uint32_t SkColor
Definition SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
SkTileMode
Definition SkTileMode.h:13
static sk_sp< SkShader > MakeRadial(const SkPoint &center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
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 setColor(SkColor color)
Definition SkPaint.cpp:119
const Paint & paint
float SkScalar
Definition extension.cpp:12
PODArray< SkColor > colors
Definition SkRecords.h:276
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition DecodeUtils.h:25
static constexpr SkCubicResampler Mitchell()
constexpr float height() const
Definition SkRect.h:769
constexpr float width() const
Definition SkRect.h:762

◆ make_bm()

static sk_sp< SkShader > make_bm ( SkTileMode  tx,
SkTileMode  ty 
)
static

Definition at line 176 of file tilemodes.cpp.

176 {
177 SkBitmap bm;
178 makebm(&bm, kN32_SkColorType, gWidth, gHeight);
179 return bm.makeShader(tx, ty, SkSamplingOptions());
180}
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition SkBitmap.cpp:669
static void makebm(SkBitmap *bm, SkColorType ct, int w, int h)
Definition tilemodes.cpp:36
constexpr int gHeight
constexpr int gWidth

◆ make_grad()

static sk_sp< SkShader > make_grad ( SkTileMode  tx,
SkTileMode  ty 
)
static

Definition at line 182 of file tilemodes.cpp.

182 {
183 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)} };
186 SkColor colors[] = {0xFFFF0000, ToolUtils::color_to_565(0xFF0044FF)};
187
188 int index = (int)ty;
189 switch (index % 3) {
190 case 0:
191 return SkGradientShader::MakeLinear(pts, colors, nullptr, std::size(colors), tx);
192 case 1:
193 return SkGradientShader::MakeRadial(center, rad, colors, nullptr, std::size(colors), tx);
194 case 2:
195 return SkGradientShader::MakeSweep(center.fX, center.fY, colors, nullptr,
196 std::size(colors), tx, 135, 225, 0, nullptr);
197 }
198 return nullptr;
199}
#define SkIntToScalar(x)
Definition SkScalar.h:57
static SkScalar center(float pos0, float pos1)
Type::kYUV Type::kRGBA() int(0.7 *637)
static sk_sp< SkShader > MakeSweep(SkScalar cx, SkScalar cy, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, SkScalar startAngle, SkScalar endAngle, uint32_t flags, const SkMatrix *localMatrix)
SkColor color_to_565(SkColor color)

◆ makebm()

static void makebm ( SkBitmap bm,
SkColorType  ct,
int  w,
int  h 
)
static

Definition at line 36 of file tilemodes.cpp.

36 {
39
40 SkCanvas canvas(*bm);
41 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(w), SkIntToScalar(h)} };
43 SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
45
46 paint.setDither(true);
47 paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, std::size(colors),
49 canvas.drawPaint(paint);
50}
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
constexpr SkColor SK_ColorTRANSPARENT
Definition SkColor.h:99
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
#define SK_Scalar1
Definition SkScalar.h:18
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:258
void eraseColor(SkColor4f) const
Definition SkBitmap.cpp:442
SkScalar w
SkScalar h
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ setup()

static void setup ( SkCanvas canvas,
SkPaint paint,
const SkBitmap bm,
SkFilterMode  fm,
SkTileMode  tmx,
SkTileMode  tmy 
)
static

Definition at line 52 of file tilemodes.cpp.

53 {
55 img = ToolUtils::MakeTextureImage(canvas, std::move(img));
56 if (img) {
57 // img can be null if the GPU context has been abandoned.
58 paint->setShader(img->makeShader(tmx, tmy, SkSamplingOptions(fm)));
59 }
60}
SK_API sk_sp< SkImage > RasterFromBitmap(const SkBitmap &bitmap)
sk_sp< SkImage > MakeTextureImage(SkCanvas *canvas, sk_sp< SkImage > orig)
SkTileMode tmy
SkTileMode tmx

Variable Documentation

◆ gColorTypes

constexpr SkColorType gColorTypes[]
constexpr
Initial value:
= {
kN32_SkColorType,
}
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition SkColorType.h:22

Definition at line 62 of file tilemodes.cpp.

62 {
63 kN32_SkColorType,
65};

◆ gHeight

constexpr int gHeight = 32
constexpr

Definition at line 174 of file tilemodes.cpp.

◆ gWidth

constexpr int gWidth = 32
constexpr

Definition at line 173 of file tilemodes.cpp.