Flutter Engine
The Flutter Engine
transparency.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm/gm.h"
14#include "include/core/SkRect.h"
22
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}
48
49// http://crrev.com/834303005
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}
58
59// http://crrev.com/834303005
60static void checkerboard(SkCanvas* canvas, SkColor c1, SkColor c2, int size) {
62 paint.setShader(create_checkerboard_shader(c1, c2, size));
63 canvas->drawPaint(paint);
64}
65
66/**
67 * This GM verifies that a transparent bitmap drawn over a
68 * checkerboard pattern looks correct.
69 */
70DEF_SIMPLE_GM(transparency_check, canvas, 1792, 1080) {
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}
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 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
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
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)
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
float SkScalar
Definition: extension.cpp:12
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
const DlColor kColors[]
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SkSamplingOptions(SkFilterMode::kLinear))
int32_t height
int32_t width
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition: SkRect.h:91
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
static void make_transparency(SkCanvas *canvas, SkScalar width, SkScalar height)
static sk_sp< SkShader > create_checkerboard_shader(SkColor c1, SkColor c2, int size)
DEF_SIMPLE_GM(transparency_check, canvas, 1792, 1080)
static void checkerboard(SkCanvas *canvas, SkColor c1, SkColor c2, int size)