Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
paint_utils.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/flow/paint_utils.h"
6
7#include <stdlib.h>
8
11
12namespace flutter {
13
14namespace {
15
16std::shared_ptr<DlColorSource> CreateCheckerboardShader(SkColor c1,
17 SkColor c2,
18 int size) {
19 SkBitmap bm;
20 bm.allocN32Pixels(2 * size, 2 * size);
21 bm.eraseColor(c1);
22 bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2);
23 bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2);
25 return std::make_shared<DlImageColorSource>(
28}
29
30} // anonymous namespace
31
32void DrawCheckerboard(DlCanvas* canvas, const SkRect& rect) {
33 // Draw a checkerboard
34 canvas->Save();
35 canvas->ClipRect(rect, DlCanvas::ClipOp::kIntersect, false);
36
37 // Secure random number generation isn't needed here.
38 // NOLINTBEGIN(clang-analyzer-security.insecureAPI.rand)
39 auto checkerboard_color =
40 SkColorSetARGB(64, rand() % 256, rand() % 256, rand() % 256);
41 // NOLINTEND(clang-analyzer-security.insecureAPI.rand)
42
44 paint.setColorSource(
45 CreateCheckerboardShader(checkerboard_color, 0x00000000, 12));
46 canvas->DrawPaint(paint);
47 canvas->Restore();
48
49 // Stroke the drawn area
50 DlPaint debug_paint;
51 debug_paint.setStrokeWidth(8);
52 debug_paint.setColor(DlColor(SkColorSetA(checkerboard_color, 255)));
54 canvas->DrawRect(rect, debug_paint);
55}
56
57} // namespace flutter
uint32_t SkColor
Definition SkColor.h:37
static constexpr SkColor SkColorSetA(SkColor c, U8CPU a)
Definition SkColor.h:82
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition SkColor.h:49
void eraseArea(const SkIRect &area, SkColor c) const
Definition SkBitmap.h:854
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition SkBitmap.cpp:232
void eraseColor(SkColor4f) const
Definition SkBitmap.cpp:442
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:37
virtual void DrawPaint(const DlPaint &paint)=0
virtual void DrawRect(const SkRect &rect, const DlPaint &paint)=0
virtual void ClipRect(const SkRect &rect, ClipOp clip_op=ClipOp::kIntersect, bool is_aa=false)=0
virtual void Restore()=0
virtual void Save()=0
static sk_sp< DlImage > Make(const SkImage *image)
Definition dl_image.cc:11
DlPaint & setColor(DlColor color)
Definition dl_paint.h:71
DlPaint & setStrokeWidth(float width)
Definition dl_paint.h:117
DlPaint & setDrawStyle(DlDrawStyle style)
Definition dl_paint.h:95
const Paint & paint
sk_sp< SkImage > image
Definition examples.cpp:29
SK_API sk_sp< SkImage > RasterFromBitmap(const SkBitmap &bitmap)
@ kStroke
strokes boundary of shapes
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
void DrawCheckerboard(DlCanvas *canvas, const SkRect &rect)
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition SkRect.h:91