Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
WritePixelsBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 Google Inc.
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 write-pixels
15// [ colortype ][ alphatype ][ colorspace ]
16// Different combinations can trigger fast or slow paths in the impls
17//
19public:
21 : fColorType(ct)
22 , fAlphaType(at)
23 , fCS(cs)
24 {
25 fName.printf("writepix_%s_%s_%s",
26 at == kPremul_SkAlphaType ? "pm" : "um",
27 ct == kRGBA_8888_SkColorType ? "rgba" : "bgra",
28 cs ? "srgb" : "null");
29 }
30
31protected:
32 const char* onGetName() override {
33 return fName.c_str();
34 }
35
36 void onDraw(int loops, SkCanvas* canvas) override {
37 SkISize size = canvas->getBaseLayerSize();
38
39 SkImageInfo info = SkImageInfo::Make(size, fColorType, fAlphaType, fCS);
40 SkBitmap bmp;
41 bmp.allocPixels(info);
43
44 for (int loop = 0; loop < loops; ++loop) {
45 canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0);
46 }
47 }
48
49private:
50 SkColorType fColorType;
51 SkAlphaType fAlphaType;
53 SkString fName;
54
55 using INHERITED = Benchmark;
56};
57
58//////////////////////////////////////////////////////////////////////////////
59
64
#define DEF_BENCH(code)
Definition Benchmark.h:20
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
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_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
kUnpremul_SkAlphaType
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:258
size_t rowBytes() const
Definition SkBitmap.h:238
void * getPixels() const
Definition SkBitmap.h:283
void eraseColor(SkColor4f) const
Definition SkBitmap.cpp:442
bool writePixels(const SkImageInfo &info, const void *pixels, size_t rowBytes, int x, int y)
Definition SkCanvas.cpp:403
virtual SkISize getBaseLayerSize() const
Definition SkCanvas.cpp:373
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
void onDraw(int loops, SkCanvas *canvas) override
WritePixelsBench(SkColorType ct, SkAlphaType at, sk_sp< SkColorSpace > cs)
const char * onGetName() override
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)