Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
transparency.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/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/SkSurface.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"

Go to the source code of this file.

Functions

static void make_transparency (SkCanvas *canvas, SkScalar width, SkScalar height)
 
static sk_sp< SkShadercreate_checkerboard_shader (SkColor c1, SkColor c2, int size)
 
static void checkerboard (SkCanvas *canvas, SkColor c1, SkColor c2, int size)
 
 DEF_SIMPLE_GM (transparency_check, canvas, 1792, 1080)
 

Function Documentation

◆ checkerboard()

static void checkerboard ( SkCanvas canvas,
SkColor  c1,
SkColor  c2,
int  size 
)
static

Definition at line 60 of file transparency.cpp.

60 {
62 paint.setShader(create_checkerboard_shader(c1, c2, size));
63 canvas->drawPaint(paint);
64}
void drawPaint(const SkPaint &paint)
const Paint & paint
static sk_sp< SkShader > create_checkerboard_shader(SkColor c1, SkColor c2, int size)

◆ create_checkerboard_shader()

static sk_sp< SkShader > create_checkerboard_shader ( SkColor  c1,
SkColor  c2,
int  size 
)
static

Definition at line 50 of file transparency.cpp.

50 {
51 SkBitmap bm;
52 bm.allocN32Pixels(2 * size, 2 * size);
53 bm.eraseColor(c1);
54 bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2);
55 bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2);
57}
void eraseArea(const SkIRect &area, SkColor c) const
Definition SkBitmap.h:854
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition SkBitmap.cpp:669
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition SkBitmap.cpp:232
void eraseColor(SkColor4f) const
Definition SkBitmap.cpp:442
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition SkRect.h:91

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( transparency_check  ,
canvas  ,
1792  ,
1080   
)

This GM verifies that a transparent bitmap drawn over a checkerboard pattern looks correct.

Definition at line 70 of file transparency.cpp.

70 {
71 checkerboard(canvas, 0xFF999999, 0xFF666666, 8);
72 {
73 SkAutoCanvasRestore autoCanvasRestore(canvas, true);
75 make_transparency(surface->getCanvas(), 256.0f, 9.0f);
76 canvas->scale(7.0f, 120.0f);
77 surface->draw(canvas, 0, 0);
78 }
79}
VkSurfaceKHR surface
Definition main.cc:49
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static SkImageInfo MakeN32Premul(int width, int height)
static void make_transparency(SkCanvas *canvas, SkScalar width, SkScalar height)
static void checkerboard(SkCanvas *canvas, SkColor c1, SkColor c2, int size)

◆ make_transparency()

static void make_transparency ( SkCanvas canvas,
SkScalar  width,
SkScalar  height 
)
static

Definition at line 23 of file transparency.cpp.

23 {
24 SkPoint pts[2];
25 pts[0] = SkPoint::Make(0, 0);
26 pts[1] = SkPoint::Make(width, 0);
27 const SkColor kColors[] = {
37 };
38 const SkScalar kRowHeight = height / std::size(kColors);
39 for (size_t i = 0; i < std::size(kColors); ++i) {
40 SkColor shaderColors[2];
41 shaderColors[0] = SK_AlphaTRANSPARENT;
42 shaderColors[1] = kColors[i];
43 SkPaint p;
44 p.setShader(SkGradientShader::MakeLinear(pts, shaderColors, nullptr, 2, SkTileMode::kClamp));
45 canvas->drawRect(SkRect::MakeXYWH(0, i * kRowHeight, width, kRowHeight), p);
46 }
47}
constexpr SkColor SK_ColorYELLOW
Definition SkColor.h:139
constexpr SkColor SK_ColorMAGENTA
Definition SkColor.h:147
uint32_t SkColor
Definition SkColor.h:37
constexpr SkColor SK_ColorCYAN
Definition SkColor.h:143
constexpr SkColor SK_ColorGRAY
Definition SkColor.h:113
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
constexpr SkAlpha SK_AlphaTRANSPARENT
Definition SkColor.h:89
void drawRect(const SkRect &rect, const SkPaint &paint)
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)
float SkScalar
Definition extension.cpp:12
const DlColor kColors[]
int32_t height
int32_t width
static constexpr SkPoint Make(float x, float y)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659