Flutter Engine
The Flutter Engine
ReadPixBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2012 The Android Open Source Project
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 "bench/Benchmark.h"
13
14// Time variants of read-pixels
15// [ colortype ][ alphatype ][ colorspace ]
16// Different combinations can trigger fast or slow paths in the impls
17//
18class ReadPixBench : public Benchmark {
19public:
21 : fCT(ct), fAT(at), fCS(cs)
22 {
23 fName.printf("readpix_%s_%s_%s",
24 at == kPremul_SkAlphaType ? "pm" : "um",
25 ct == kRGBA_8888_SkColorType ? "rgba" : "bgra",
26 cs ? "srgb" : "null");
27 }
28
29protected:
30 const char* onGetName() override {
31 return fName.c_str();
32 }
33
34 void onDraw(int loops, SkCanvas* canvas) override {
35 canvas->clear(0x80000000);
36
37 SkISize size = canvas->getBaseLayerSize();
38
39 auto info = SkImageInfo::Make(size, fCT, fAT, fCS);
41 bitmap.allocPixels(info);
42
43 for (int i = 0; i < loops; i++) {
44 canvas->readPixels(bitmap.info(), bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
45 }
46 }
47
48private:
49 SkColorType fCT;
50 SkAlphaType fAT;
52 SkString fName;
53 using INHERITED = Benchmark;
54};
59
64
65////////////////////////////////////////////////////////////////////////////////
66
68public:
70
71protected:
72 void onDelayedSetup() override {
74 fSrc.allocPixels(info);
75 fSrc.eraseColor(SK_ColorBLACK);
76 fDst.allocPixels(info.makeDimensions(info.dimensions()));
77 }
78
79 const char* onGetName() override {
80 return "orient_pixmap";
81 }
82
83 bool isSuitableFor(Backend backend) override {
84 return backend == Backend::kNonRendering;
85 }
86
87 void onDraw(int loops, SkCanvas*) override {
89 fSrc.peekPixels(&src);
90 fDst.peekPixels(&dst);
91 for (int i = 0; i < loops; ++i) {
93 }
94 }
95
96private:
97 SkBitmap fSrc, fDst;
98
99 using INHERITED = Benchmark;
100};
101DEF_BENCH( return new PixmapOrientBench(); )
102
103
104class GetAlphafBench : public Benchmark {
106 SkColorType fCT;
107public:
108 GetAlphafBench(SkColorType ct, const char label[]) : fCT(ct) {
109 fName.printf("getalphaf_%s", label);
110 }
111
112protected:
113 void onDelayedSetup() override {
114 fBM.allocPixels(SkImageInfo::Make(1024, 1024, fCT, kPremul_SkAlphaType));
115 fBM.eraseColor(0x88112233);
116 }
117
118 const char* onGetName() override {
119 return fName.c_str();
120 }
121
123 return backend == Backend::kNonRendering;
124 }
125
126 void onDraw(int loops, SkCanvas*) override {
127 for (int i = 0; i < loops; ++i) {
128 for (int y = 0; y < fBM.height(); ++y) {
129 for (int x = 0; x < fBM.width(); ++x) {
130 fBM.getAlphaf(x, y);
131 }
132 }
133 }
134 }
135
136private:
137 SkBitmap fBM;
138
139 using INHERITED = Benchmark;
140};
141DEF_BENCH( return new GetAlphafBench(kN32_SkColorType, "rgba"); )
142DEF_BENCH( return new GetAlphafBench(kRGB_888x_SkColorType, "rgbx"); )
145
const char * backend
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
const char * fName
SkRect fDst
Definition: LatticeOp.cpp:381
DEF_BENCH(return new ReadPixBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());) DEF_BENCH(return new ReadPixBench(kRGBA_8888_SkColorType
kUnpremul_SkAlphaType
SkAlphaType
Definition: SkAlphaType.h:26
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
SkColorType
Definition: SkColorType.h:19
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition: SkColorType.h:38
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
Definition: SkColorType.h:25
@ kRGBA_F32_SkColorType
pixel using C float for red, green, blue, alpha; in 128-bit word
Definition: SkColorType.h:40
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
@ kTopRight_SkEncodedOrigin
#define INHERITED(method,...)
Definition: SkRecorder.cpp:128
const char * onGetName() override
GetAlphafBench(SkColorType ct, const char label[])
void onDelayedSetup() override
void onDraw(int loops, SkCanvas *) override
bool isSuitableFor(Backend backend) override
bool isSuitableFor(Backend backend) override
const char * onGetName() override
void onDraw(int loops, SkCanvas *) override
void onDelayedSetup() override
const char * onGetName() override
ReadPixBench(SkColorType ct, SkAlphaType at, sk_sp< SkColorSpace > cs)
void onDraw(int loops, SkCanvas *canvas) override
virtual SkISize getBaseLayerSize() const
Definition: SkCanvas.cpp:369
void clear(SkColor color)
Definition: SkCanvas.h:1199
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY)
Definition: SkCanvas.cpp:382
static sk_sp< SkColorSpace > MakeSRGB()
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
const char * c_str() const
Definition: SkString.h:133
double y
double x
SK_API bool Orient(const SkPixmap &dst, const SkPixmap &src, SkEncodedOrigin origin)
Definition: bitmap.py:1
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
dst
Definition: cp.py:12
Definition: SkSize.h:16
static SkImageInfo MakeN32Premul(int width, int height)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)