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

Side by Side Diff: bench/PremulAndUnpremulAlphaOpsBench.cpp

Issue 199413013: add new readPixels with direct memory parameters (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | gyp/skia_for_chromium_defines.gypi » ('j') | include/core/SkDevice.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBenchmark.h" 8 #include "SkBenchmark.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkConfig8888.h" 10 #include "SkConfig8888.h"
11 #include "SkString.h" 11 #include "SkString.h"
12 #include "sk_tool_utils.h" 12 #include "sk_tool_utils.h"
13 13
14 class PremulAndUnpremulAlphaOpsBench : public SkBenchmark { 14 class PremulAndUnpremulAlphaOpsBench : public SkBenchmark {
15 enum {
16 W = 256,
17 H = 256,
18 };
19 SkBitmap fBmp1, fBmp2;
20
15 public: 21 public:
16 PremulAndUnpremulAlphaOpsBench(SkCanvas::Config8888 config) { 22 PremulAndUnpremulAlphaOpsBench(SkColorType ct) {
17 fUnPremulConfig = config; 23 fColorType = ct;
18 fName.printf("premul_and_unpremul_alpha_%s", 24 fName.printf("premul_and_unpremul_alpha_%s", sk_tool_utils::colortype_na me(ct));
19 (config == SkCanvas::kRGBA_Unpremul_Config8888) ?
20 "RGBA8888" : "Native8888");
21 } 25 }
22 26
23 protected: 27 protected:
24 virtual const char* onGetName() SK_OVERRIDE { 28 virtual const char* onGetName() SK_OVERRIDE {
25 return fName.c_str(); 29 return fName.c_str();
26 } 30 }
27 31
32 virtual void onPreDraw() {
33 SkImageInfo info = SkImageInfo::Make(W, H, fColorType, kPremul_SkAlphaTy pe);
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);
scroggo 2014/07/11 15:21:25 Can't this result in an invalid premultiplied colo
bsalomon 2014/07/11 15:30:39 Yeah, I think the intention was for bmp1 to be unp
40 }
41 }
42
43 fBmp2.allocPixels(info); // used in readPixels()
44 }
45
28 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { 46 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
29 canvas->clear(SK_ColorBLACK); 47 canvas->clear(SK_ColorBLACK);
30 SkISize size = canvas->getDeviceSize();
31
32 SkBitmap bmp1;
33 bmp1.setConfig(SkBitmap::kARGB_8888_Config, size.width(),
34 size.height());
35 bmp1.allocPixels();
36 SkAutoLockPixels alp(bmp1);
37 uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp1.getPixels());
38 for (int h = 0; h < size.height(); ++h) {
39 for (int w = 0; w < size.width(); ++w)
40 pixels[h * size.width() + w] = SkPackConfig8888(fUnPremulConfig,
41 h & 0xFF, w & 0xFF, w & 0xFF, w & 0xFF);
42 }
43
44 SkBitmap bmp2;
45 bmp2.setConfig(SkBitmap::kARGB_8888_Config, size.width(),
46 size.height());
47
48 SkColorType ct;
49 SkAlphaType at;
50 sk_tool_utils::config8888_to_imagetypes(fUnPremulConfig, &ct, &at);
51 if (bmp1.isOpaque()) {
52 at = kOpaque_SkAlphaType;
53 }
54 48
55 for (int loop = 0; loop < loops; ++loop) { 49 for (int loop = 0; loop < loops; ++loop) {
56 // Unpremul -> Premul 50 // Unpremul -> Premul
57 sk_tool_utils::write_pixels(canvas, bmp1, 0, 0, ct, at); 51 canvas->writePixels(fBmp1.info(), fBmp1.getPixels(), fBmp1.rowBytes( ), 0, 0);
58 // Premul -> Unpremul 52 // Premul -> Unpremul
59 canvas->readPixels(&bmp2, 0, 0, fUnPremulConfig); 53 canvas->readPixels(fBmp2.info(), fBmp2.getPixels(), fBmp2.rowBytes() , 0, 0);
60 } 54 }
61 } 55 }
62 56
63 private: 57 private:
64 SkCanvas::Config8888 fUnPremulConfig; 58 SkColorType fColorType;
65 SkString fName; 59 SkString fName;
60
66 typedef SkBenchmark INHERITED; 61 typedef SkBenchmark INHERITED;
67 }; 62 };
68 63
69 64
70 DEF_BENCH(return new PremulAndUnpremulAlphaOpsBench(SkCanvas::kRGBA_Unpremul_Con fig8888)); 65 DEF_BENCH(return new PremulAndUnpremulAlphaOpsBench(kRGBA_8888_SkColorType));
71 DEF_BENCH(return new PremulAndUnpremulAlphaOpsBench(SkCanvas::kNative_Unpremul_C onfig8888)); 66 DEF_BENCH(return new PremulAndUnpremulAlphaOpsBench(kBGRA_8888_SkColorType));
OLDNEW
« no previous file with comments | « no previous file | gyp/skia_for_chromium_defines.gypi » ('j') | include/core/SkDevice.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698