Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
TimingSlide Class Reference
Inheritance diagram for TimingSlide:
Slide SkRefCnt SkRefCntBase

Public Member Functions

 TimingSlide ()
 
void load (SkScalar w, SkScalar h) override
 
void draw (SkCanvas *canvas) override
 
- Public Member Functions inherited from Slide
virtual SkISize getDimensions () const
 
virtual void gpuTeardown ()
 
virtual void draw (SkCanvas *canvas)=0
 
virtual bool animate (double nanos)
 
virtual void load (SkScalar winWidth, SkScalar winHeight)
 
virtual void resize (SkScalar winWidth, SkScalar winHeight)
 
virtual void unload ()
 
virtual bool onChar (SkUnichar c)
 
virtual bool onMouse (SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifiers)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
const SkStringgetName ()
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Additional Inherited Members

- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 16 of file TimingSlide.cpp.

Constructor & Destructor Documentation

◆ TimingSlide()

TimingSlide::TimingSlide ( )
inline

Definition at line 18 of file TimingSlide.cpp.

18{ fName = "Timing";}
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ draw()

void TimingSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 26 of file TimingSlide.cpp.

26 {
27 canvas->scale(8,8);
28
29 // Draw normally.
30 canvas->drawImage(fImg, 0,0);
31
32 canvas->translate(0,H);
33
34 // Draw one pixel at a time with drawImageRect(),
35 // timing how long each drawImageRect() call takes.
36 double cost[H][W];
37 double min = +INFINITY,
38 max = -INFINITY;
39 for (int y = 0; y < H; y++)
40 for (int x = 0; x < W; x++) {
41 auto start = std::chrono::steady_clock::now();
42 canvas->drawImageRect(fImg.get(),
44 SkSamplingOptions(), /*paint=*/nullptr,
46 auto elapsed = std::chrono::steady_clock::now() - start;
47
48 cost[y][x] = elapsed.count();
49 min = std::min(min, cost[y][x]);
50 max = std::max(max, cost[y][x]);
51 }
52
53 canvas->translate(0,H);
54
55 // Draw using those per-pixel timings,
56 // with the slowest pixel scaled to alpha=1, the fastest to alpha=0.
57 for (int y = 0; y < H; y++)
58 for (int x = 0; x < W; x++) {
59 SkPaint p;
60 p.setAlphaf( (cost[y][x] - min) / (max - min) );
61 canvas->drawRect(SkRect::MakeXYWH(x,y,1,1), p);
62 }
63
64 canvas->translate(0,H);
65
66 // Draw each pixel into offscreen, timing each draw.
67 SkImageInfo info = canvas->imageInfo().makeWH(1024,1024);
68 if (sk_sp<SkSurface> offscreen = canvas->makeSurface(info)) {
69 min = +INFINITY;
70 max = -INFINITY;
71 for (int y = 0; y < H; y++)
72 for (int x = 0; x < W; x++) {
73 auto start = std::chrono::steady_clock::now();
74 offscreen->getCanvas()->drawImageRect(fImg,
75 SkRect::MakeXYWH(x,y,1,1),
76 SkRect::MakeXYWH(0,0,1024,1024),
78 /*paint=*/nullptr,
80 auto elapsed = std::chrono::steady_clock::now() - start;
81
82 cost[y][x] = elapsed.count();
83 min = std::min(min, cost[y][x]);
84 max = std::max(max, cost[y][x]);
85 }
86 for (int y = 0; y < H; y++)
87 for (int x = 0; x < W; x++) {
88 SkPaint p;
89 p.setAlphaf( (cost[y][x] - min) / (max - min) );
90 canvas->drawRect(SkRect::MakeXYWH(x,y,1,1), p);
91 }
92 }
93 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define W
Definition: aaa.cpp:17
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
sk_sp< SkSurface > makeSurface(const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
Definition: SkCanvas.cpp:1195
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition: SkCanvas.h:1542
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
SkImageInfo imageInfo() const
Definition: SkCanvas.cpp:1206
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
T * get() const
Definition: SkRefCnt.h:303
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48
double y
double x
SkSamplingOptions(SkFilterMode::kLinear))
Definition: SkMD5.cpp:130
SkImageInfo makeWH(int newWidth, int newHeight) const
Definition: SkImageInfo.h:444
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ load()

void TimingSlide::load ( SkScalar  w,
SkScalar  h 
)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 20 of file TimingSlide.cpp.

20 {
22 surf->getCanvas()->drawString("abc", 2,H-4, ToolUtils::DefaultFont(), SkPaint{});
23 fImg = surf->makeImageSnapshot();
24 }
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
SkCanvas * getCanvas()
Definition: SkSurface.cpp:82
sk_sp< SkImage > makeImageSnapshot()
Definition: SkSurface.cpp:90
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SkFont DefaultFont()
static SkImageInfo MakeN32Premul(int width, int height)

The documentation for this class was generated from the following file: