Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Macros | Functions | Variables
overdrawcanvas.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkOverdrawCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkOverdrawColorFilter.h"
#include "tools/fonts/FontToolUtils.h"

Go to the source code of this file.

Macros

#define WIDTH   500
 
#define HEIGHT   500
 

Functions

 DEF_SIMPLE_GM_BG (overdraw_canvas, canvas, WIDTH, HEIGHT, SK_ColorWHITE)
 
static sk_sp< SkImageoverdraw_text_grid (bool useCTM)
 
 DEF_SIMPLE_GM_BG (overdraw_text_xform, canvas, 512, 512, SK_ColorBLACK)
 

Variables

static const SkColor kOverdrawColors [6]
 

Macro Definition Documentation

◆ HEIGHT

#define HEIGHT   500

Definition at line 26 of file overdrawcanvas.cpp.

◆ WIDTH

#define WIDTH   500

Definition at line 25 of file overdrawcanvas.cpp.

Function Documentation

◆ DEF_SIMPLE_GM_BG() [1/2]

DEF_SIMPLE_GM_BG ( overdraw_canvas  ,
canvas  ,
WIDTH  ,
HEIGHT  ,
SK_ColorWHITE   
)

Definition at line 33 of file overdrawcanvas.cpp.

33 {
34 // Set up the overdraw canvas.
36 sk_sp<SkSurface> offscreen = SkSurfaces::Raster(offscreenInfo);
38 auto c = offscreen->getCanvas();
39
40 SkOverdrawCanvas overdrawCanvas(c);
41
42 overdrawCanvas.drawRect(SkRect::MakeLTRB(10, 10, 200, 200), SkPaint());
43 overdrawCanvas.drawRect(SkRect::MakeLTRB(20, 20, 190, 190), SkPaint());
44 overdrawCanvas.drawRect(SkRect::MakeLTRB(30, 30, 180, 180), SkPaint());
45 overdrawCanvas.drawRect(SkRect::MakeLTRB(40, 40, 170, 170), SkPaint());
46 overdrawCanvas.drawRect(SkRect::MakeLTRB(50, 50, 160, 160), SkPaint());
47 overdrawCanvas.drawRect(SkRect::MakeLTRB(60, 60, 150, 150), SkPaint());
48
49 char text[] = "Ae_p";
50 overdrawCanvas.drawSimpleText(text, 4, SkTextEncoding::kUTF8, 300, 300, font, SkPaint());
51
52 sk_sp<SkImage> counts = offscreen->makeImageSnapshot();
53
54 // Draw overdraw colors to the canvas. The color filter will convert counts to colors.
57 canvas->drawImage(counts.get(), 0.0f, 0.0f, SkSamplingOptions(), &paint);
58 canvas->drawString("This is some text:", 180, 300, font, SkPaint());
59}
@ kUTF8
uses bytes to represent UTF-8 or ASCII
static sk_sp< SkColorFilter > MakeWithSkColors(const SkColor[kNumColors])
const Paint & paint
std::u16string text
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SkFont DefaultPortableFont()
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 counts
Definition switches.h:239
font
Font Metadata and Metrics.
#define WIDTH
static const SkColor kOverdrawColors[6]
#define HEIGHT
static SkImageInfo MakeA8(int width, int height)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646

◆ DEF_SIMPLE_GM_BG() [2/2]

DEF_SIMPLE_GM_BG ( overdraw_text_xform  ,
canvas  ,
512  ,
512  ,
SK_ColorBLACK   
)

Definition at line 93 of file overdrawcanvas.cpp.

93 {
94 SkPaint imgPaint;
95 imgPaint.setColor(SK_ColorWHITE);
96 canvas->drawImage(overdraw_text_grid(false), 0, 0, SkFilterMode::kNearest, &imgPaint);
97 canvas->drawImage(overdraw_text_grid( true), 256, 0, SkFilterMode::kNearest, &imgPaint);
98}
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
void setColor(SkColor color)
Definition SkPaint.cpp:119
static sk_sp< SkImage > overdraw_text_grid(bool useCTM)

◆ overdraw_text_grid()

static sk_sp< SkImage > overdraw_text_grid ( bool  useCTM)
static

Definition at line 61 of file overdrawcanvas.cpp.

61 {
63 auto canvas = SkOverdrawCanvas(surface->getCanvas());
64
66 paint.setColor(SK_ColorWHITE);
67
69
70 for (int n = 1; n <= 20; n++) {
71 const float x = 10.0f;
72 const float y = n * 20.0f;
73
74 for (int i = 0; i < n * 10; i++) {
75 const char* text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
76 if (useCTM) {
77 canvas.save();
78 canvas.translate(x, y);
79 canvas.drawString(text, 0, 0, font, paint);
80 canvas.restore();
81 } else {
82 canvas.drawString(text, x, y, font, paint);
83 }
84 }
85 }
86 return surface->makeImageSnapshot();
87}
VkSurfaceKHR surface
Definition main.cc:49
double y
double x

Variable Documentation

◆ kOverdrawColors

const SkColor kOverdrawColors[6]
static
Initial value:
= {
0x00000000, 0x5fff0000, 0x2f0000ff, 0x2f00ff00, 0x3fff0000, 0x7fff0000,
}

Definition at line 28 of file overdrawcanvas.cpp.

28 {
29 0x00000000, 0x5fff0000, 0x2f0000ff, 0x2f00ff00, 0x3fff0000, 0x7fff0000,
30};