2013-07-14 01:44:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
|
2014-06-18 21:32:48 +00:00
|
|
|
#include "Resources.h"
|
|
|
|
#include "SkGradientShader.h"
|
2013-07-14 01:44:59 +00:00
|
|
|
#include "SkTypeface.h"
|
|
|
|
#include "SkStream.h"
|
2013-07-25 14:34:13 +00:00
|
|
|
#include "SkPaint.h"
|
2013-07-14 01:44:59 +00:00
|
|
|
|
2015-01-16 13:01:16 +00:00
|
|
|
static void make_checker(SkBitmap* bm, int size, int numChecks) {
|
|
|
|
bm->allocN32Pixels(size, size);
|
|
|
|
for (int y = 0; y < size; ++y) {
|
|
|
|
for (int x = 0; x < size; ++x) {
|
|
|
|
SkPMColor* s = bm->getAddr32(x, y);
|
|
|
|
int cx = (x * numChecks) / size;
|
|
|
|
int cy = (y * numChecks) / size;
|
|
|
|
if ((cx+cy)%2) {
|
|
|
|
*s = 0xFFFFFFFF;
|
|
|
|
} else {
|
|
|
|
*s = 0xFF000000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-14 01:44:59 +00:00
|
|
|
static void setTypeface(SkPaint* paint, const char name[], SkTypeface::Style style) {
|
2015-07-24 19:09:25 +00:00
|
|
|
sk_tool_utils::set_portable_typeface(paint, name, style);
|
2013-07-14 01:44:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class DownsampleBitmapGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
SkBitmap fBM;
|
|
|
|
SkString fName;
|
|
|
|
bool fBitmapMade;
|
2015-03-16 17:08:34 +00:00
|
|
|
SkFilterQuality fFilterQuality;
|
2013-07-14 01:44:59 +00:00
|
|
|
|
2015-03-16 17:08:34 +00:00
|
|
|
DownsampleBitmapGM(SkFilterQuality filterQuality)
|
|
|
|
: fFilterQuality(filterQuality)
|
2013-07-14 01:44:59 +00:00
|
|
|
{
|
2015-06-15 13:51:08 +00:00
|
|
|
this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
|
2013-07-14 01:44:59 +00:00
|
|
|
fBitmapMade = false;
|
|
|
|
}
|
|
|
|
|
2015-03-16 17:08:34 +00:00
|
|
|
const char* filterQualityToString() {
|
|
|
|
static const char *filterQualityNames[] = {
|
2013-07-25 19:14:37 +00:00
|
|
|
"none", "low", "medium", "high"
|
|
|
|
};
|
2015-03-16 17:08:34 +00:00
|
|
|
return filterQualityNames[fFilterQuality];
|
2013-07-25 14:34:13 +00:00
|
|
|
}
|
2013-07-14 01:44:59 +00:00
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-07-14 01:44:59 +00:00
|
|
|
return fName;
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2013-07-14 01:44:59 +00:00
|
|
|
make_bitmap_wrapper();
|
2014-09-03 20:40:52 +00:00
|
|
|
return SkISize::Make(fBM.width(), 4 * fBM.height());
|
2013-07-14 01:44:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void make_bitmap_wrapper() {
|
|
|
|
if (!fBitmapMade) {
|
|
|
|
fBitmapMade = true;
|
|
|
|
make_bitmap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void make_bitmap() = 0;
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2013-07-14 01:44:59 +00:00
|
|
|
make_bitmap_wrapper();
|
|
|
|
|
2014-09-03 20:40:52 +00:00
|
|
|
int curY = 0;
|
|
|
|
int curHeight;
|
2013-07-14 01:44:59 +00:00
|
|
|
float curScale = 1;
|
|
|
|
do {
|
|
|
|
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.setScale( curScale, curScale );
|
|
|
|
|
|
|
|
SkPaint paint;
|
2015-03-16 17:08:34 +00:00
|
|
|
paint.setFilterQuality(fFilterQuality);
|
2013-07-14 01:44:59 +00:00
|
|
|
|
|
|
|
canvas->save();
|
2014-09-03 20:40:52 +00:00
|
|
|
canvas->translate(0, (SkScalar)curY);
|
2014-12-10 17:02:16 +00:00
|
|
|
canvas->concat(matrix);
|
|
|
|
canvas->drawBitmap(fBM, 0, 0, &paint);
|
2013-07-14 01:44:59 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
2014-09-03 20:40:52 +00:00
|
|
|
curHeight = (int) (fBM.height() * curScale + 2);
|
|
|
|
curY += curHeight;
|
2013-07-14 01:44:59 +00:00
|
|
|
curScale *= 0.75f;
|
2014-09-03 20:40:52 +00:00
|
|
|
} while (curHeight >= 2 && curY < 4*fBM.height());
|
2013-07-14 01:44:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DownsampleBitmapTextGM: public DownsampleBitmapGM {
|
|
|
|
public:
|
2015-03-16 17:08:34 +00:00
|
|
|
DownsampleBitmapTextGM(float textSize, SkFilterQuality filterQuality)
|
|
|
|
: INHERITED(filterQuality), fTextSize(textSize)
|
2013-07-14 01:44:59 +00:00
|
|
|
{
|
2015-03-16 17:08:34 +00:00
|
|
|
fName.printf("downsamplebitmap_text_%s_%.2fpt", this->filterQualityToString(), fTextSize);
|
2013-07-14 01:44:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
float fTextSize;
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void make_bitmap() override {
|
2014-01-25 16:46:20 +00:00
|
|
|
fBM.allocN32Pixels(int(fTextSize * 8), int(fTextSize * 6));
|
2013-07-14 01:44:59 +00:00
|
|
|
SkCanvas canvas(fBM);
|
|
|
|
canvas.drawColor(SK_ColorWHITE);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setSubpixelText(true);
|
|
|
|
paint.setTextSize(fTextSize);
|
|
|
|
|
2015-06-15 13:51:08 +00:00
|
|
|
setTypeface(&paint, "serif", SkTypeface::kNormal);
|
2013-07-14 01:44:59 +00:00
|
|
|
canvas.drawText("Hamburgefons", 12, fTextSize/2, 1.2f*fTextSize, paint);
|
2015-06-15 13:51:08 +00:00
|
|
|
setTypeface(&paint, "serif", SkTypeface::kBold);
|
2013-07-14 01:44:59 +00:00
|
|
|
canvas.drawText("Hamburgefons", 12, fTextSize/2, 2.4f*fTextSize, paint);
|
2015-06-15 13:51:08 +00:00
|
|
|
setTypeface(&paint, "serif", SkTypeface::kItalic);
|
2013-07-14 01:44:59 +00:00
|
|
|
canvas.drawText("Hamburgefons", 12, fTextSize/2, 3.6f*fTextSize, paint);
|
2015-06-15 13:51:08 +00:00
|
|
|
setTypeface(&paint, "serif", SkTypeface::kBoldItalic);
|
2013-07-14 01:44:59 +00:00
|
|
|
canvas.drawText("Hamburgefons", 12, fTextSize/2, 4.8f*fTextSize, paint);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef DownsampleBitmapGM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DownsampleBitmapCheckerboardGM: public DownsampleBitmapGM {
|
|
|
|
public:
|
2015-03-16 17:08:34 +00:00
|
|
|
DownsampleBitmapCheckerboardGM(int size, int numChecks, SkFilterQuality filterQuality)
|
|
|
|
: INHERITED(filterQuality), fSize(size), fNumChecks(numChecks)
|
2013-07-14 01:44:59 +00:00
|
|
|
{
|
2015-03-16 17:08:34 +00:00
|
|
|
fName.printf("downsamplebitmap_checkerboard_%s_%d_%d", this->filterQualityToString(), fSize, fNumChecks);
|
2013-07-14 01:44:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int fSize;
|
|
|
|
int fNumChecks;
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void make_bitmap() override {
|
2015-01-16 13:01:16 +00:00
|
|
|
make_checker(&fBM, fSize, fNumChecks);
|
2013-07-14 01:44:59 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef DownsampleBitmapGM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DownsampleBitmapImageGM: public DownsampleBitmapGM {
|
|
|
|
public:
|
2015-03-16 17:08:34 +00:00
|
|
|
DownsampleBitmapImageGM(const char filename[], SkFilterQuality filterQuality)
|
|
|
|
: INHERITED(filterQuality), fFilename(filename)
|
2013-07-14 01:44:59 +00:00
|
|
|
{
|
2015-03-16 17:08:34 +00:00
|
|
|
fName.printf("downsamplebitmap_image_%s_%s", this->filterQualityToString(), filename);
|
2013-07-14 01:44:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString fFilename;
|
|
|
|
int fSize;
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void make_bitmap() override {
|
2016-03-18 19:13:47 +00:00
|
|
|
if (!GetResourceAsBitmap(fFilename.c_str(), &fBM)) {
|
|
|
|
fBM.allocN32Pixels(1, 1);
|
|
|
|
fBM.eraseARGB(255, 255, 0 , 0); // red == bad
|
|
|
|
}
|
|
|
|
fSize = fBM.height();
|
2013-07-14 01:44:59 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef DownsampleBitmapGM INHERITED;
|
|
|
|
};
|
|
|
|
|
2015-03-16 17:08:34 +00:00
|
|
|
DEF_GM( return new DownsampleBitmapTextGM(72, kHigh_SkFilterQuality); )
|
|
|
|
DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, kHigh_SkFilterQuality); )
|
|
|
|
DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", kHigh_SkFilterQuality); )
|
2013-07-25 14:34:13 +00:00
|
|
|
|
2015-03-16 17:08:34 +00:00
|
|
|
DEF_GM( return new DownsampleBitmapTextGM(72, kMedium_SkFilterQuality); )
|
|
|
|
DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, kMedium_SkFilterQuality); )
|
|
|
|
DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", kMedium_SkFilterQuality); )
|
2013-07-25 14:34:13 +00:00
|
|
|
|
2015-03-16 17:08:34 +00:00
|
|
|
DEF_GM( return new DownsampleBitmapTextGM(72, kLow_SkFilterQuality); )
|
|
|
|
DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, kLow_SkFilterQuality); )
|
|
|
|
DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", kLow_SkFilterQuality); )
|
2013-07-25 14:34:13 +00:00
|
|
|
|
2015-03-16 17:08:34 +00:00
|
|
|
DEF_GM( return new DownsampleBitmapTextGM(72, kNone_SkFilterQuality); )
|
|
|
|
DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, kNone_SkFilterQuality); )
|
|
|
|
DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", kNone_SkFilterQuality); )
|