2014-05-29 22:01:08 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "samplecode/Sample.h"
|
2019-01-08 19:00:08 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColorPriv.h"
|
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkStream.h"
|
|
|
|
#include "include/effects/SkBlurMaskFilter.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "samplecode/DecodeFile.h"
|
|
|
|
#include "tools/Resources.h"
|
2014-05-29 22:01:08 +00:00
|
|
|
|
|
|
|
// Intended to exercise pixel snapping observed with scaled images (and
|
|
|
|
// with non-scaled images, but for a different reason): Bug 1145
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class SubpixelTranslateView : public Sample {
|
2014-05-29 22:01:08 +00:00
|
|
|
public:
|
|
|
|
SubpixelTranslateView(const char imageFilename[],
|
|
|
|
float horizontalVelocity,
|
|
|
|
float verticalVelocity)
|
2017-12-09 01:27:41 +00:00
|
|
|
: fHorizontalVelocity(horizontalVelocity)
|
|
|
|
, fVerticalVelocity(verticalVelocity)
|
|
|
|
{
|
|
|
|
if (!DecodeDataToBitmap(GetResourceAsData(imageFilename), &fBM)) {
|
|
|
|
fBM.allocN32Pixels(1, 1);
|
|
|
|
*(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
|
|
|
|
}
|
|
|
|
fCurPos = SkPoint::Make(0,0);
|
|
|
|
fSize = 200;
|
2014-05-29 22:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkBitmap fBM;
|
2014-05-30 13:45:36 +00:00
|
|
|
SkScalar fSize;
|
2014-05-29 22:01:08 +00:00
|
|
|
float fHorizontalVelocity, fVerticalVelocity;
|
|
|
|
|
|
|
|
SkPoint fCurPos;
|
|
|
|
|
2019-07-03 14:55:44 +00:00
|
|
|
SkString name() override { return SkString("SubpixelTranslate"); }
|
2014-05-29 22:01:08 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2014-05-29 22:01:08 +00:00
|
|
|
|
2015-03-16 17:08:34 +00:00
|
|
|
static const SkFilterQuality gQualitys[] = {
|
|
|
|
kNone_SkFilterQuality,
|
|
|
|
kLow_SkFilterQuality,
|
|
|
|
kMedium_SkFilterQuality,
|
|
|
|
kHigh_SkFilterQuality
|
2014-05-29 22:01:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SkPaint paint;
|
2019-01-08 19:00:08 +00:00
|
|
|
SkFont font(nullptr, 48);
|
|
|
|
font.setSubpixel(true);
|
2014-05-29 22:01:08 +00:00
|
|
|
|
|
|
|
paint.setAntiAlias(true);
|
2015-03-16 17:08:34 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gQualitys); ++i) {
|
|
|
|
paint.setFilterQuality(gQualitys[i]);
|
2014-05-29 22:01:08 +00:00
|
|
|
SkRect r = SkRect::MakeXYWH( fCurPos.fX + i * (fSize + 10), fCurPos.fY, fSize, fSize );
|
|
|
|
canvas->drawBitmapRect( fBM, r, &paint );
|
|
|
|
}
|
|
|
|
|
2019-01-08 19:00:08 +00:00
|
|
|
canvas->drawString("AA Scaled", fCurPos.fX + SK_ARRAY_COUNT(gQualitys) * (fSize + 10),
|
|
|
|
fCurPos.fY + fSize/2, font, paint);
|
2014-05-29 22:01:08 +00:00
|
|
|
|
|
|
|
paint.setAntiAlias(false);
|
2019-01-08 19:00:08 +00:00
|
|
|
font.setEdging(SkFont::Edging::kAlias);
|
2015-03-16 17:08:34 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gQualitys); ++i) {
|
|
|
|
paint.setFilterQuality(gQualitys[i]);
|
2014-05-29 22:01:08 +00:00
|
|
|
SkRect r = SkRect::MakeXYWH( fCurPos.fX + i * (fSize + 10), fCurPos.fY + fSize + 10, fSize, fSize );
|
|
|
|
canvas->drawBitmapRect( fBM, r, &paint );
|
|
|
|
}
|
2019-01-08 19:00:08 +00:00
|
|
|
canvas->drawString("Scaled", fCurPos.fX + SK_ARRAY_COUNT(gQualitys) * (fSize + 10),
|
|
|
|
fCurPos.fY + fSize + 10 + fSize/2, font, paint);
|
2014-05-29 22:01:08 +00:00
|
|
|
|
|
|
|
paint.setAntiAlias(true);
|
2019-01-08 19:00:08 +00:00
|
|
|
font.setEdging(SkFont::Edging::kAntiAlias);
|
2015-03-16 17:08:34 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gQualitys); ++i) {
|
|
|
|
paint.setFilterQuality(gQualitys[i]);
|
2014-05-29 22:01:08 +00:00
|
|
|
canvas->drawBitmap( fBM, fCurPos.fX + i * (fBM.width() + 10), fCurPos.fY + 2*(fSize + 10), &paint );
|
|
|
|
}
|
|
|
|
|
2019-01-08 19:00:08 +00:00
|
|
|
canvas->drawString("AA No Scale",
|
|
|
|
fCurPos.fX + SK_ARRAY_COUNT(gQualitys) * (fBM.width() + 10),
|
|
|
|
fCurPos.fY + 2*(fSize + 10) + fSize/2, font, paint);
|
2014-05-29 22:01:08 +00:00
|
|
|
|
|
|
|
paint.setAntiAlias(false);
|
2019-01-08 19:00:08 +00:00
|
|
|
font.setEdging(SkFont::Edging::kAlias);
|
2015-03-16 17:08:34 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gQualitys); ++i) {
|
|
|
|
paint.setFilterQuality(gQualitys[i]);
|
2014-05-29 22:01:08 +00:00
|
|
|
canvas->drawBitmap( fBM, fCurPos.fX + i * (fBM.width() + 10), fCurPos.fY + 2*(fSize + 10) + fBM.height() + 10, &paint );
|
|
|
|
}
|
|
|
|
|
2019-01-08 19:00:08 +00:00
|
|
|
canvas->drawString("No Scale", fCurPos.fX + SK_ARRAY_COUNT(gQualitys) * (fBM.width() + 10),
|
|
|
|
fCurPos.fY + 2*(fSize + 10) + fBM.height() + 10 + fSize/2, font, paint);
|
2014-05-29 22:01:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
fCurPos.fX += fHorizontalVelocity;
|
|
|
|
fCurPos.fY += fVerticalVelocity;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2014-05-29 22:01:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new SubpixelTranslateView("images/mandrill_256.png", .05f, .05f); )
|