3 * Copyright 2011 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
11 #include "SkColorPriv.h"
16 static void draw_into_bitmap(const SkBitmap& bm) {
17 const int w = bm.width();
18 const int h = bm.height();
23 p.setColor(SK_ColorRED);
24 canvas.drawCircle(SkIntToScalar(w)/2, SkIntToScalar(h)/2,
25 SkIntToScalar(SkMin32(w, h))*3/8, p);
28 r.set(0, 0, SkIntToScalar(w), SkIntToScalar(h));
29 p.setStyle(SkPaint::kStroke_Style);
30 p.setStrokeWidth(SkIntToScalar(4));
31 p.setColor(SK_ColorBLUE);
32 canvas.drawRect(r, p);
35 /* Variants for bitmaprect
36 src : entire bitmap, subset, fractional subset
37 dst : same size as src, diff size
41 class BitmapRectBench : public Benchmark {
45 SkFilterQuality fFilterQuality;
49 static const int kWidth = 128;
50 static const int kHeight = 128;
52 BitmapRectBench(U8CPU alpha, SkFilterQuality filterQuality,
54 fAlpha = SkToU8(alpha);
55 fFilterQuality = filterQuality;
56 fSlightMatrix = slightMatrix;
58 fBitmap.setInfo(SkImageInfo::MakeN32Premul(kWidth, kHeight));
62 const char* onGetName() SK_OVERRIDE {
63 fName.printf("bitmaprect_%02X_%sfilter_%s",
65 kNone_SkFilterQuality == fFilterQuality ? "no" : "",
66 fSlightMatrix ? "trans" : "identity");
70 void onPreDraw() SK_OVERRIDE {
71 fBitmap.allocPixels();
72 fBitmap.setAlphaType(kOpaque_SkAlphaType);
73 fBitmap.eraseColor(SK_ColorBLACK);
74 draw_into_bitmap(fBitmap);
76 fSrcR.iset(0, 0, kWidth, kHeight);
77 fDstR.iset(0, 0, kWidth, kHeight);
80 // want fractional translate
81 fDstR.offset(SK_Scalar1 / 3, SK_Scalar1 * 5 / 7);
82 // want enough to create a scale matrix, but not enough to scare
83 // off our sniffer which tries to see if the matrix is "effectively"
85 fDstR.fRight += SK_Scalar1 / (kWidth * 60);
90 void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
94 this->setupPaint(&paint);
95 paint.setFilterQuality(fFilterQuality);
96 paint.setAlpha(fAlpha);
98 for (int i = 0; i < loops; i++) {
99 canvas->drawBitmapRectToRect(fBitmap, &fSrcR, fDstR, &paint);
104 typedef Benchmark INHERITED;
107 DEF_BENCH(return new BitmapRectBench(0xFF, kNone_SkFilterQuality, false))
108 DEF_BENCH(return new BitmapRectBench(0x80, kNone_SkFilterQuality, false))
109 DEF_BENCH(return new BitmapRectBench(0xFF, kLow_SkFilterQuality, false))
110 DEF_BENCH(return new BitmapRectBench(0x80, kLow_SkFilterQuality, false))
112 DEF_BENCH(return new BitmapRectBench(0xFF, kNone_SkFilterQuality, true))
113 DEF_BENCH(return new BitmapRectBench(0xFF, kLow_SkFilterQuality, true))