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.
|
|
|
|
*/
|
|
|
|
|
2016-03-18 22:48:49 +00:00
|
|
|
#include "DecodeFile.h"
|
2014-05-29 22:01:08 +00:00
|
|
|
#include "gm.h"
|
2014-06-18 21:32:48 +00:00
|
|
|
|
|
|
|
#include "Resources.h"
|
2014-05-29 22:01:08 +00:00
|
|
|
#include "SampleCode.h"
|
|
|
|
#include "SkBlurMaskFilter.h"
|
|
|
|
#include "SkCanvas.h"
|
2014-06-18 21:32:48 +00:00
|
|
|
#include "SkColorPriv.h"
|
2014-05-29 22:01:08 +00:00
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
|
|
|
|
// Intended to exercise pixel snapping observed with scaled images (and
|
|
|
|
// with non-scaled images, but for a different reason): Bug 1145
|
|
|
|
|
|
|
|
class SubpixelTranslateView : public SampleView {
|
|
|
|
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;
|
|
|
|
|
|
|
|
// overrides from SkEventSink
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onQuery(SkEvent* evt) override {
|
2014-05-29 22:01:08 +00:00
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
|
|
|
SampleCode::TitleR(evt, "SubpixelTranslate");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
paint.setTextSize(48);
|
2015-01-29 18:26:37 +00:00
|
|
|
paint.setSubpixelText(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 );
|
|
|
|
}
|
|
|
|
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString( "AA Scaled", fCurPos.fX + SK_ARRAY_COUNT(gQualitys) * (fSize + 10), fCurPos.fY + fSize/2, paint );
|
2014-05-29 22:01:08 +00:00
|
|
|
|
|
|
|
paint.setAntiAlias(false);
|
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 );
|
|
|
|
}
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString( "Scaled", fCurPos.fX + SK_ARRAY_COUNT(gQualitys) * (fSize + 10), fCurPos.fY + fSize + 10 + fSize/2, paint );
|
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
|
|
|
canvas->drawBitmap( fBM, fCurPos.fX + i * (fBM.width() + 10), fCurPos.fY + 2*(fSize + 10), &paint );
|
|
|
|
}
|
|
|
|
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString( "AA No Scale", fCurPos.fX + SK_ARRAY_COUNT(gQualitys) * (fBM.width() + 10), fCurPos.fY + 2*(fSize + 10) + fSize/2, paint );
|
2014-05-29 22:01:08 +00:00
|
|
|
|
|
|
|
paint.setAntiAlias(false);
|
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 );
|
|
|
|
}
|
|
|
|
|
2017-04-28 19:35:12 +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, paint );
|
2014-05-29 22:01:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
fCurPos.fX += fHorizontalVelocity;
|
|
|
|
fCurPos.fY += fVerticalVelocity;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SampleView INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-12-08 15:21:31 +00:00
|
|
|
static SkView* MyFactory() { return new SubpixelTranslateView("images/mandrill_256.png", .05f, .05f); }
|
2014-05-29 22:01:08 +00:00
|
|
|
static SkViewRegister reg(MyFactory);
|