Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
colorwheel.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontStyle.h"
#include "include/core/SkImage.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "tools/DecodeUtils.h"
#include "tools/GpuToolUtils.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"

Go to the source code of this file.

Functions

static void draw_image (SkCanvas *canvas, const char *resource, int x, int y)
 
 DEF_SIMPLE_GM (colorwheel, canvas, 256, 256)
 
 DEF_SIMPLE_GM (colorwheelnative, canvas, 128, 28)
 
 DEF_SIMPLE_GM (colorwheel_alphatypes, canvas, 256, 128)
 

Function Documentation

◆ DEF_SIMPLE_GM() [1/3]

DEF_SIMPLE_GM ( colorwheel  ,
canvas  ,
256  ,
256   
)

Definition at line 44 of file colorwheel.cpp.

44 {
46 draw_image(canvas, "images/color_wheel.png", 0, 0); // top left
47 draw_image(canvas, "images/color_wheel.gif", 128, 0); // top right
48 draw_image(canvas, "images/color_wheel.webp", 0, 128); // bottom left
49 draw_image(canvas, "images/color_wheel.jpg", 128, 128); // bottom right
50}
static void draw_image(SkCanvas *canvas, const char *resource, int x, int y)
void draw_checkerboard(SkCanvas *canvas, SkColor c1, SkColor c2, int size)

◆ DEF_SIMPLE_GM() [2/3]

DEF_SIMPLE_GM ( colorwheel_alphatypes  ,
canvas  ,
256  ,
128   
)

This GM tests decoding images with non-default (overridden) alpha types.

Definition at line 69 of file colorwheel.cpp.

69 {
70 canvas->clear(SK_ColorWHITE);
71
72 sk_sp<SkData> imgData = GetResourceAsData("images/color_wheel.png");
73
74 auto pmImg = ToolUtils::MakeTextureImage(
76 auto upmImg = ToolUtils::MakeTextureImage(
78
80
81 // We draw a tiny (8x8) section of the image that falls right on the edge of transparency,
82 // and blow it up so we can really see the impact of filtering in premul or unpremul.
83 SkRect srcRect = SkRect::MakeXYWH(12, 102, 8, 8);
84 SkRect dstRect = SkRect::MakeLTRB(0, 0, 128, 128);
85
86 // First, we draw the normal (premul-then-filter) image, which looks good. The yellow image
87 // transitions to the white background like you'd expect.
88 canvas->drawImageRect(pmImg, srcRect, dstRect,
90 // Next, we draw the unpremul (filter-then-premul) image, which looks bad. Filtering in unpremul
91 // causes the implicit black of the transparent pixels to be bleed into the filtered edge,
92 // creating a dark "fringe" at the boundary between the yellow image and white background.
93 canvas->drawImageRect(upmImg, srcRect, dstRect.makeOffset(128, 0),
95}
kUnpremul_SkAlphaType
sk_sp< SkData > GetResourceAsData(const char *resource)
Definition Resources.cpp:42
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
@ kFast_SrcRectConstraint
sample outside bounds; faster
Definition SkCanvas.h:1543
SK_API sk_sp< SkImage > DeferredFromEncodedData(sk_sp< SkData > encoded, std::optional< SkAlphaType > alphaType=std::nullopt)
sk_sp< SkImage > MakeTextureImage(SkCanvas *canvas, sk_sp< SkImage > orig)
constexpr SkRect makeOffset(float dx, float dy) const
Definition SkRect.h:965
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646
static sk_sp< SkShader > linear(sk_sp< SkShader > shader)

◆ DEF_SIMPLE_GM() [3/3]

DEF_SIMPLE_GM ( colorwheelnative  ,
canvas  ,
128  ,
28   
)

Definition at line 52 of file colorwheel.cpp.

52 {
55
56 canvas->clear(SK_ColorLTGRAY);
57 canvas->drawString("R", 8.0f, 20.0f, font, SkPaint(SkColors::kRed));
58 canvas->drawString("G", 24.0f, 20.0f, font, SkPaint(SkColors::kGreen));
59 canvas->drawString("B", 40.0f, 20.0f, font, SkPaint(SkColors::kBlue));
60 canvas->drawString("C", 56.0f, 20.0f, font, SkPaint(SkColors::kCyan));
61 canvas->drawString("M", 72.0f, 20.0f, font, SkPaint(SkColors::kMagenta));
62 canvas->drawString("Y", 88.0f, 20.0f, font, SkPaint(SkColors::kYellow));
63 canvas->drawString("K", 104.0f, 20.0f, font, SkPaint(SkColors::kBlack));
64}
constexpr SkColor SK_ColorLTGRAY
Definition SkColor.h:118
static constexpr SkFontStyle Bold()
Definition SkFontStyle.h:69
@ kAlias
no transparent pixels on glyph edges
constexpr SkColor4f kMagenta
Definition SkColor.h:445
constexpr SkColor4f kGreen
Definition SkColor.h:441
constexpr SkColor4f kRed
Definition SkColor.h:440
constexpr SkColor4f kCyan
Definition SkColor.h:444
constexpr SkColor4f kBlack
Definition SkColor.h:435
constexpr SkColor4f kBlue
Definition SkColor.h:442
constexpr SkColor4f kYellow
Definition SkColor.h:443
sk_sp< SkTypeface > CreatePortableTypeface(const char *name, SkFontStyle style)
font
Font Metadata and Metrics.

◆ draw_image()

static void draw_image ( SkCanvas canvas,
const char *  resource,
int  x,
int  y 
)
static

Definition at line 25 of file colorwheel.cpp.

25 {
27 if (image) {
29 } else {
30 SkDebugf("\nCould not decode file '%s'. Did you forget"
31 " to set the resourcePath?\n", resource);
32 }
33}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define SkIntToScalar(x)
Definition SkScalar.h:57
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
sk_sp< SkImage > image
Definition examples.cpp:29
double y
double x
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition DecodeUtils.h:25