2014-08-08 19:11:33 +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-08-08 19:11:33 +00:00
|
|
|
#include "Resources.h"
|
2018-08-08 15:36:17 +00:00
|
|
|
#include "Sample.h"
|
2014-08-08 19:11:33 +00:00
|
|
|
#include "SkBlurMaskFilter.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkColorPriv.h"
|
2019-01-08 19:00:08 +00:00
|
|
|
#include "SkFont.h"
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkPath.h"
|
2014-08-08 19:11:33 +00:00
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkTime.h"
|
2016-12-12 15:02:12 +00:00
|
|
|
#include "SkClipOpPriv.h"
|
2014-08-08 19:11:33 +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 IdentityScaleView : public Sample {
|
2014-08-08 19:11:33 +00:00
|
|
|
public:
|
|
|
|
IdentityScaleView(const char imageFilename[]) {
|
2017-12-09 01:27:41 +00:00
|
|
|
if (!DecodeDataToBitmap(GetResourceAsData(imageFilename), &fBM)) {
|
|
|
|
fBM.allocN32Pixels(1, 1);
|
|
|
|
*(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
|
|
|
|
}
|
2014-08-08 19:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkBitmap fBM;
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
bool onQuery(Sample::Event* evt) override {
|
|
|
|
if (Sample::TitleQ(*evt)) {
|
|
|
|
Sample::TitleR(evt, "IdentityScale");
|
2014-08-08 19:11:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2014-08-08 19:11:33 +00:00
|
|
|
|
2019-01-08 19:00:08 +00:00
|
|
|
SkFont font(nullptr, 48);
|
2014-08-08 19:11:33 +00:00
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
paint.setAntiAlias(true);
|
2015-03-16 17:08:34 +00:00
|
|
|
paint.setFilterQuality(kHigh_SkFilterQuality);
|
2014-08-08 19:11:33 +00:00
|
|
|
|
|
|
|
SkTime::DateTime time;
|
|
|
|
SkTime::GetDateTime(&time);
|
|
|
|
|
|
|
|
bool use_scale = (time.fSecond % 2 == 1);
|
|
|
|
const char *text;
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
if (use_scale) {
|
|
|
|
text = "Scaled = 1";
|
|
|
|
} else {
|
|
|
|
|
|
|
|
SkRect r = { 100, 100, 356, 356 };
|
|
|
|
SkPath clipPath;
|
|
|
|
clipPath.addRoundRect(r, SkIntToScalar(5), SkIntToScalar(5));
|
2016-12-09 14:00:50 +00:00
|
|
|
canvas->clipPath(clipPath, kIntersect_SkClipOp, true);
|
2014-08-08 19:11:33 +00:00
|
|
|
text = "Scaled = 0";
|
|
|
|
}
|
|
|
|
canvas->drawBitmap( fBM, 100, 100, &paint );
|
|
|
|
canvas->restore();
|
2019-01-08 19:00:08 +00:00
|
|
|
canvas->drawString(text, 100, 400, font, paint);
|
2014-08-08 19:11:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2014-08-08 19:11:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new IdentityScaleView("images/mandrill_256.png"); )
|