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

Unified Diff: bench/BitmapBench.cpp

Issue 322963002: hide SkBitmap::setConfig (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | bench/BitmapRectBench.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/BitmapBench.cpp
diff --git a/bench/BitmapBench.cpp b/bench/BitmapBench.cpp
index 2b0cabfc37f7583b8986fbf9479dab0a9ab6bc54..e877bd472d80fadba1a546588509582b1af3847f 100644
--- a/bench/BitmapBench.cpp
+++ b/bench/BitmapBench.cpp
@@ -1,10 +1,10 @@
-
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+
#include "SkBenchmark.h"
#include "SkBitmap.h"
#include "SkPaint.h"
@@ -12,10 +12,7 @@
#include "SkColorPriv.h"
#include "SkRandom.h"
#include "SkString.h"
-
-static const char* gConfigName[] = {
- "ERROR", "a1", "a8", "index8", "565", "4444", "8888"
-};
+#include "sk_tool_utils.h"
static int conv6ToByte(int x) {
return x * 0xFF / 5;
@@ -33,7 +30,7 @@ static uint8_t compute666Index(SkPMColor c) {
return convByteTo6(r) * 36 + convByteTo6(g) * 6 + convByteTo6(b);
}
-static void convertToIndex666(const SkBitmap& src, SkBitmap* dst, bool isOpaque) {
+static void convertToIndex666(const SkBitmap& src, SkBitmap* dst, SkAlphaType aType) {
SkPMColor storage[216];
SkPMColor* colors = storage;
// rrr ggg bbb
@@ -47,10 +44,9 @@ static void convertToIndex666(const SkBitmap& src, SkBitmap* dst, bool isOpaque)
}
}
}
- SkColorTable* ctable = new SkColorTable(storage, 216,
- isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
- dst->setConfig(SkBitmap::kIndex8_Config, src.width(), src.height());
- dst->allocPixels(ctable);
+ SkColorTable* ctable = new SkColorTable(storage, 216, aType);
+ dst->allocPixels(SkImageInfo::Make(src.width(), src.height(), kIndex_8_SkColorType, aType),
+ NULL, ctable);
ctable->unref();
SkAutoLockPixels alps(src);
@@ -75,29 +71,30 @@ static void convertToIndex666(const SkBitmap& src, SkBitmap* dst, bool isOpaque)
*/
class BitmapBench : public SkBenchmark {
- SkBitmap fBitmap;
- SkPaint fPaint;
- bool fIsOpaque;
- bool fForceUpdate; //bitmap marked as dirty before each draw. forces bitmap to be updated on device cache
- bool fIsVolatile;
- SkBitmap::Config fConfig;
- SkString fName;
+ const SkColorType fColorType;
+ const SkAlphaType fAlphaType;
+ const bool fForceUpdate; //bitmap marked as dirty before each draw. forces bitmap to be updated on device cache
+ const bool fIsVolatile;
+
+ SkBitmap fBitmap;
+ SkPaint fPaint;
+ SkString fName;
+
enum { W = 128 };
enum { H = 128 };
public:
- BitmapBench(bool isOpaque, SkBitmap::Config c,
- bool forceUpdate = false, bool bitmapVolatile = false)
- : fIsOpaque(isOpaque)
+ BitmapBench(SkColorType ct, SkAlphaType at, bool forceUpdate = false, bool isVolatile = false)
+ : fColorType(ct)
+ , fAlphaType(at)
, fForceUpdate(forceUpdate)
- , fIsVolatile(bitmapVolatile)
- , fConfig(c) {
- }
+ , fIsVolatile(isVolatile)
+ {}
protected:
virtual const char* onGetName() {
fName.set("bitmap");
- fName.appendf("_%s%s", gConfigName[fConfig],
- fIsOpaque ? "" : "_A");
+ fName.appendf("_%s%s", sk_tool_utils::colortype_name(fColorType),
+ kOpaque_SkAlphaType == fAlphaType ? "" : "_A");
if (fForceUpdate)
fName.append("_update");
if (fIsVolatile)
@@ -109,24 +106,23 @@ protected:
virtual void onPreDraw() {
SkBitmap bm;
- if (SkBitmap::kIndex8_Config == fConfig) {
- bm.setConfig(SkBitmap::kARGB_8888_Config, W, H);
+ if (kIndex_8_SkColorType == fColorType) {
+ bm.setInfo(SkImageInfo::MakeN32(W, H, fAlphaType));
} else {
- bm.setConfig(fConfig, W, H);
+ bm.setInfo(SkImageInfo::Make(W, H, fColorType, fAlphaType));
}
bm.allocPixels();
- bm.eraseColor(fIsOpaque ? SK_ColorBLACK : 0);
+ bm.eraseColor(kOpaque_SkAlphaType == fAlphaType ? SK_ColorBLACK : 0);
onDrawIntoBitmap(bm);
- if (SkBitmap::kIndex8_Config == fConfig) {
- convertToIndex666(bm, &fBitmap, fIsOpaque);
+ if (kIndex_8_SkColorType == fColorType) {
+ convertToIndex666(bm, &fBitmap, fAlphaType);
} else {
fBitmap = bm;
}
- fBitmap.setAlphaType(fIsOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
fBitmap.setIsVolatile(fIsVolatile);
}
@@ -197,9 +193,9 @@ class FilterBitmapBench : public BitmapBench {
uint32_t fFlags;
SkString fFullName;
public:
- FilterBitmapBench(bool isOpaque, SkBitmap::Config c,
+ FilterBitmapBench(SkColorType ct, SkAlphaType at,
bool forceUpdate, bool isVolitile, uint32_t flags)
- : INHERITED(isOpaque, c, forceUpdate, isVolitile)
+ : INHERITED(ct, at, forceUpdate, isVolitile)
, fFlags(flags) {
}
@@ -276,9 +272,9 @@ private:
SkString fFullName;
SourceAlpha fSourceAlpha;
public:
- SourceAlphaBitmapBench(SourceAlpha alpha, SkBitmap::Config c,
+ SourceAlphaBitmapBench(SourceAlpha alpha, SkColorType ct,
bool forceUpdate = false, bool bitmapVolatile = false)
- : INHERITED(false, c, forceUpdate, bitmapVolatile)
+ : INHERITED(ct, kPremul_SkAlphaType, forceUpdate, bitmapVolatile)
, fSourceAlpha(alpha) {
}
@@ -355,31 +351,31 @@ private:
typedef BitmapBench INHERITED;
};
-DEF_BENCH( return new BitmapBench(false, SkBitmap::kARGB_8888_Config); )
-DEF_BENCH( return new BitmapBench(true, SkBitmap::kARGB_8888_Config); )
-DEF_BENCH( return new BitmapBench(true, SkBitmap::kRGB_565_Config); )
-DEF_BENCH( return new BitmapBench(false, SkBitmap::kIndex8_Config); )
-DEF_BENCH( return new BitmapBench(true, SkBitmap::kIndex8_Config); )
-DEF_BENCH( return new BitmapBench(true, SkBitmap::kARGB_8888_Config, true, true); )
-DEF_BENCH( return new BitmapBench(true, SkBitmap::kARGB_8888_Config, true, false); )
+DEF_BENCH( return new BitmapBench(kN32_SkColorType, kPremul_SkAlphaType); )
+DEF_BENCH( return new BitmapBench(kN32_SkColorType, kOpaque_SkAlphaType); )
+DEF_BENCH( return new BitmapBench(kRGB_565_SkColorType, kOpaque_SkAlphaType); )
+DEF_BENCH( return new BitmapBench(kIndex_8_SkColorType, kPremul_SkAlphaType); )
+DEF_BENCH( return new BitmapBench(kIndex_8_SkColorType, kOpaque_SkAlphaType); )
+DEF_BENCH( return new BitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, true, true); )
+DEF_BENCH( return new BitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, true, false); )
// scale filter -> S32_opaque_D32_filter_DX_{SSE2,SSSE3} and Fact9 is also for S32_D16_filter_DX_SSE2
-DEF_BENCH( return new FilterBitmapBench(false, SkBitmap::kARGB_8888_Config, false, false, kScale_Flag | kBilerp_Flag); )
-DEF_BENCH( return new FilterBitmapBench(true, SkBitmap::kARGB_8888_Config, false, false, kScale_Flag | kBilerp_Flag); )
-DEF_BENCH( return new FilterBitmapBench(true, SkBitmap::kARGB_8888_Config, true, true, kScale_Flag | kBilerp_Flag); )
-DEF_BENCH( return new FilterBitmapBench(true, SkBitmap::kARGB_8888_Config, true, false, kScale_Flag | kBilerp_Flag); )
+DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kPremul_SkAlphaType, false, false, kScale_Flag | kBilerp_Flag); )
+DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, false, false, kScale_Flag | kBilerp_Flag); )
+DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, true, true, kScale_Flag | kBilerp_Flag); )
+DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, true, false, kScale_Flag | kBilerp_Flag); )
// scale rotate filter -> S32_opaque_D32_filter_DXDY_{SSE2,SSSE3}
-DEF_BENCH( return new FilterBitmapBench(false, SkBitmap::kARGB_8888_Config, false, false, kScale_Flag | kRotate_Flag | kBilerp_Flag); )
-DEF_BENCH( return new FilterBitmapBench(true, SkBitmap::kARGB_8888_Config, false, false, kScale_Flag | kRotate_Flag | kBilerp_Flag); )
-DEF_BENCH( return new FilterBitmapBench(true, SkBitmap::kARGB_8888_Config, true, true, kScale_Flag | kRotate_Flag | kBilerp_Flag); )
-DEF_BENCH( return new FilterBitmapBench(true, SkBitmap::kARGB_8888_Config, true, false, kScale_Flag | kRotate_Flag | kBilerp_Flag); )
+DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kPremul_SkAlphaType, false, false, kScale_Flag | kRotate_Flag | kBilerp_Flag); )
+DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, false, false, kScale_Flag | kRotate_Flag | kBilerp_Flag); )
+DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, true, true, kScale_Flag | kRotate_Flag | kBilerp_Flag); )
+DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kOpaque_SkAlphaType, true, false, kScale_Flag | kRotate_Flag | kBilerp_Flag); )
-DEF_BENCH( return new FilterBitmapBench(false, SkBitmap::kARGB_8888_Config, false, false, kScale_Flag | kBilerp_Flag | kBicubic_Flag); )
-DEF_BENCH( return new FilterBitmapBench(false, SkBitmap::kARGB_8888_Config, false, false, kScale_Flag | kRotate_Flag | kBilerp_Flag | kBicubic_Flag); )
+DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kPremul_SkAlphaType, false, false, kScale_Flag | kBilerp_Flag | kBicubic_Flag); )
+DEF_BENCH( return new FilterBitmapBench(kN32_SkColorType, kPremul_SkAlphaType, false, false, kScale_Flag | kRotate_Flag | kBilerp_Flag | kBicubic_Flag); )
// source alpha tests -> S32A_Opaque_BlitRow32_{arm,neon}
-DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kOpaque_SourceAlpha, SkBitmap::kARGB_8888_Config); )
-DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kTransparent_SourceAlpha, SkBitmap::kARGB_8888_Config); )
-DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kTwoStripes_SourceAlpha, SkBitmap::kARGB_8888_Config); )
-DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kThreeStripes_SourceAlpha, SkBitmap::kARGB_8888_Config); )
+DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kOpaque_SourceAlpha, kN32_SkColorType); )
+DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kTransparent_SourceAlpha, kN32_SkColorType); )
+DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kTwoStripes_SourceAlpha, kN32_SkColorType); )
+DEF_BENCH( return new SourceAlphaBitmapBench(SourceAlphaBitmapBench::kThreeStripes_SourceAlpha, kN32_SkColorType); )
« no previous file with comments | « no previous file | bench/BitmapRectBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698