2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2009-06-23 12:19:41 +00:00
|
|
|
#include "gm.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
static void make_bm(SkBitmap* bm) {
|
2011-05-18 18:54:23 +00:00
|
|
|
const SkColor colors[4] = {
|
2009-06-23 12:19:41 +00:00
|
|
|
SK_ColorRED, SK_ColorGREEN,
|
|
|
|
SK_ColorBLUE, SK_ColorWHITE
|
|
|
|
};
|
2011-05-18 18:54:23 +00:00
|
|
|
SkPMColor colorsPM[4];
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(colors); ++i) {
|
|
|
|
colorsPM[i] = SkPreMultiplyColor(colors[i]);
|
|
|
|
}
|
|
|
|
SkColorTable* ctable = new SkColorTable(colorsPM, 4);
|
|
|
|
|
2014-02-17 21:21:46 +00:00
|
|
|
bm->allocPixels(SkImageInfo::Make(2, 2, kIndex_8_SkColorType,
|
|
|
|
kPremul_SkAlphaType),
|
|
|
|
NULL, ctable);
|
2009-06-23 12:19:41 +00:00
|
|
|
ctable->unref();
|
2011-05-18 18:54:23 +00:00
|
|
|
|
2009-06-23 12:19:41 +00:00
|
|
|
*bm->getAddr8(0, 0) = 0;
|
|
|
|
*bm->getAddr8(1, 0) = 1;
|
|
|
|
*bm->getAddr8(0, 1) = 2;
|
|
|
|
*bm->getAddr8(1, 1) = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkScalar draw_bm(SkCanvas* canvas, const SkBitmap& bm,
|
|
|
|
SkScalar x, SkScalar y, SkPaint* paint) {
|
|
|
|
canvas->drawBitmap(bm, x, y, paint);
|
|
|
|
return SkIntToScalar(bm.width()) * 5/4;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkScalar draw_set(SkCanvas* c, const SkBitmap& bm, SkScalar x,
|
|
|
|
SkPaint* p) {
|
|
|
|
x += draw_bm(c, bm, x, 0, p);
|
2013-10-31 17:28:30 +00:00
|
|
|
p->setFilterLevel(SkPaint::kLow_FilterLevel);
|
2009-06-23 12:19:41 +00:00
|
|
|
x += draw_bm(c, bm, x, 0, p);
|
|
|
|
p->setDither(true);
|
|
|
|
return x + draw_bm(c, bm, x, 0, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* gConfigNames[] = {
|
|
|
|
"unknown config",
|
|
|
|
"A8",
|
|
|
|
"Index8",
|
|
|
|
"565",
|
|
|
|
"4444",
|
|
|
|
"8888"
|
|
|
|
};
|
|
|
|
|
|
|
|
static SkScalar draw_row(SkCanvas* canvas, const SkBitmap& bm) {
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
SkScalar x = 0;
|
|
|
|
const int scale = 32;
|
|
|
|
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
const char* name = gConfigNames[bm.config()];
|
|
|
|
canvas->drawText(name, strlen(name), x, SkIntToScalar(bm.height())*scale*5/8,
|
|
|
|
paint);
|
|
|
|
canvas->translate(SkIntToScalar(48), 0);
|
|
|
|
|
|
|
|
canvas->scale(SkIntToScalar(scale), SkIntToScalar(scale));
|
2011-05-18 18:54:23 +00:00
|
|
|
|
2009-06-23 12:19:41 +00:00
|
|
|
x += draw_set(canvas, bm, 0, &paint);
|
|
|
|
paint.reset();
|
|
|
|
paint.setAlpha(0x80);
|
|
|
|
draw_set(canvas, bm, x, &paint);
|
|
|
|
return x * scale / 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
class FilterGM : public GM {
|
2012-03-08 22:13:04 +00:00
|
|
|
bool fOnce;
|
|
|
|
void init() {
|
|
|
|
if (fOnce) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fOnce = true;
|
2009-06-23 12:19:41 +00:00
|
|
|
make_bm(&fBM8);
|
2014-02-23 03:59:35 +00:00
|
|
|
fBM8.copyTo(&fBM4444, kARGB_4444_SkColorType);
|
|
|
|
fBM8.copyTo(&fBM16, kRGB_565_SkColorType);
|
2014-04-11 17:15:40 +00:00
|
|
|
fBM8.copyTo(&fBM32, kN32_SkColorType);
|
2012-03-08 22:13:04 +00:00
|
|
|
}
|
|
|
|
public:
|
|
|
|
SkBitmap fBM8, fBM4444, fBM16, fBM32;
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
FilterGM() : fOnce(false) {
|
2011-10-31 14:18:20 +00:00
|
|
|
this->setBGColor(0xFFDDDDDD);
|
2009-06-23 12:19:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual SkString onShortName() {
|
|
|
|
return SkString("bitmapfilters");
|
|
|
|
}
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
virtual SkISize onISize() {
|
2009-06-23 12:19:41 +00:00
|
|
|
return make_isize(540, 330);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
2012-03-08 22:13:04 +00:00
|
|
|
this->init();
|
2009-06-23 12:19:41 +00:00
|
|
|
|
|
|
|
SkScalar x = SkIntToScalar(10);
|
|
|
|
SkScalar y = SkIntToScalar(10);
|
2011-05-18 18:54:23 +00:00
|
|
|
|
2009-06-23 12:19:41 +00:00
|
|
|
canvas->translate(x, y);
|
|
|
|
y = draw_row(canvas, fBM8);
|
|
|
|
canvas->translate(0, y);
|
|
|
|
y = draw_row(canvas, fBM4444);
|
|
|
|
canvas->translate(0, y);
|
|
|
|
y = draw_row(canvas, fBM16);
|
|
|
|
canvas->translate(0, y);
|
|
|
|
draw_row(canvas, fBM32);
|
|
|
|
}
|
2011-05-18 18:54:23 +00:00
|
|
|
|
2009-06-23 12:19:41 +00:00
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new FilterGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|