Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
PremulAndUnpremulAlphaOpsBench.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"
12#include "tools/ToolUtils.h"
13
15 enum {
16 W = 256,
17 H = 256,
18 };
19 SkBitmap fBmp1, fBmp2;
20
21public:
23 fColorType = ct;
24 fName.printf("premul_and_unpremul_alpha_%s", ToolUtils::colortype_name(ct));
25 }
26
27protected:
28 const char* onGetName() override {
29 return fName.c_str();
30 }
31
32 void onDelayedSetup() override {
34 fBmp1.allocPixels(info); // used in writePixels
35
36 for (int h = 0; h < H; ++h) {
37 for (int w = 0; w < W; ++w) {
38 // SkColor places A in the right slot for either RGBA or BGRA
39 *fBmp1.getAddr32(w, h) = SkColorSetARGB(h & 0xFF, w & 0xFF, w & 0xFF, w & 0xFF);
40 }
41 }
42
43 fBmp2.allocPixels(info); // used in readPixels()
44 }
45
46 void onDraw(int loops, SkCanvas* canvas) override {
47 canvas->clear(SK_ColorBLACK);
48
49 for (int loop = 0; loop < loops; ++loop) {
50 // Unpremul -> Premul
51 canvas->writePixels(fBmp1.info(), fBmp1.getPixels(), fBmp1.rowBytes(), 0, 0);
52 // Premul -> Unpremul
53 canvas->readPixels(fBmp2.info(), fBmp2.getPixels(), fBmp2.rowBytes(), 0, 0);
54 }
55 }
56
57private:
58 SkColorType fColorType;
59 SkString fName;
60
61 using INHERITED = Benchmark;
62};
63
64
#define DEF_BENCH(code)
Definition Benchmark.h:20
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
kUnpremul_SkAlphaType
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
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition SkColor.h:49
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
void onDraw(int loops, SkCanvas *canvas) override
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
const SkImageInfo & info() const
Definition SkBitmap.h:139
uint32_t * getAddr32(int x, int y) const
Definition SkBitmap.h:1260
bool writePixels(const SkImageInfo &info, const void *pixels, size_t rowBytes, int x, int y)
Definition SkCanvas.cpp:403
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:386
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:534
const char * c_str() const
Definition SkString.h:133
const char * colortype_name(SkColorType ct)
Definition ToolUtils.cpp:65
SkScalar w
SkScalar h
Definition SkMD5.cpp:130
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)