Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: bench/EncoderBench.cpp

Issue 1890643003: Add bench for image encodes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Response to comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 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 "Benchmark.h"
9 #include "Resources.h"
10 #include "SkBitmap.h"
11 #include "SkData.h"
12 #include "SkImageEncoder.h"
13
14 class EncodeBench : public Benchmark {
15 public:
16 EncodeBench(const char* filename, SkImageEncoder::Type type, int quality)
17 : fFilename(filename)
18 , fType(type)
19 , fQuality(quality)
20 {
21 // Set the name of the bench
22 SkString name("Encode_");
23 name.append(filename);
24 name.append("_");
25 switch (type) {
26 case SkImageEncoder::kJPEG_Type:
27 name.append("JPEG");
28 break;
29 case SkImageEncoder::kPNG_Type:
30 name.append("PNG");
31 break;
32 case SkImageEncoder::kWEBP_Type:
33 name.append("WEBP");
34 break;
35 default:
36 name.append("Unknown");
37 break;
38 }
39
40 fName = name;
41 }
42
43 bool isSuitableFor(Backend backend) override { return backend == kNonRenderi ng_Backend; }
44
45 const char* onGetName() override { return fName.c_str(); }
46
47 void onPreDraw(SkCanvas*) override {
48 #ifdef SK_DEBUG
49 bool result =
50 #endif
51 GetResourceAsBitmap(fFilename, &fBitmap);
52 SkASSERT(result);
53 }
54
55 void onDraw(int loops, SkCanvas*) override {
56 for (int i = 0; i < loops; i++) {
57 SkAutoTUnref<SkData> data(SkImageEncoder::EncodeData(fBitmap, fType, fQuality));
58 SkASSERT(data);
59 }
60 }
61
62 private:
63 const char* fFilename;
64 const SkImageEncoder::Type fType;
65 const int fQuality;
66 SkString fName;
67 SkBitmap fBitmap;
68 };
69
70
71 // The Android Photos app uses a quality of 90 on JPEG encodes
72 DEF_BENCH(return new EncodeBench("mandrill_512.png", SkImageEncoder::kJPEG_Type, 90));
73 DEF_BENCH(return new EncodeBench("color_wheel.jpg", SkImageEncoder::kJPEG_Type, 90));
74
75 // PNG encodes are lossless so quality should be ignored
76 DEF_BENCH(return new EncodeBench("mandrill_512.png", SkImageEncoder::kPNG_Type, 90));
77 DEF_BENCH(return new EncodeBench("color_wheel.jpg", SkImageEncoder::kPNG_Type, 9 0));
78
79 // TODO: What is the appropriate quality to use to benchmark WEBP encodes?
80 DEF_BENCH(return new EncodeBench("mandrill_512.png", SkImageEncoder::kWEBP_Type, 90));
81 DEF_BENCH(return new EncodeBench("color_wheel.jpg", SkImageEncoder::kWEBP_Type, 90));
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698