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
6
7#include <stdlib.h>
8
9#include "third_party/skia/include/core/SkBitmap.h"
10#include "third_party/skia/include/core/SkImage.h"
11
12namespace flutter {
13
14namespace {
15
16static std::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);
24 auto image = DlImage::Make(SkImages::RasterFromBitmap(bm));
28}
29
30} // anonymous namespace
31
32void DrawCheckerboard(DlCanvas* canvas, const DlRect& rect) {
33 // Draw a checkerboard
34 canvas->Save();
35 canvas->ClipRect(rect, DlClipOp::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
43 DlPaint paint;
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
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:32
virtual void ClipRect(const DlRect &rect, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false)=0
virtual void DrawPaint(const DlPaint &paint)=0
virtual void DrawRect(const DlRect &rect, const DlPaint &paint)=0
virtual void Restore()=0
virtual void Save()=0
static std::shared_ptr< DlColorSource > MakeImage(const sk_sp< const DlImage > &image, DlTileMode horizontal_tile_mode, DlTileMode vertical_tile_mode, DlImageSampling sampling=DlImageSampling::kLinear, const DlMatrix *matrix=nullptr)
static sk_sp< DlImage > Make(const SkImage *image)
Definition dl_image.cc:11
DlPaint & setColor(DlColor color)
Definition dl_paint.h:70
DlPaint & setStrokeWidth(float width)
Definition dl_paint.h:115
DlPaint & setDrawStyle(DlDrawStyle style)
Definition dl_paint.h:93
DlPaint & setColorSource(std::nullptr_t source)
Definition dl_paint.h:131
FlutterVulkanImage * image
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all 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
void DrawCheckerboard(DlCanvas *canvas, const DlRect &rect)
@ kStroke
strokes boundary of shapes