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.
|
|
|
|
*/
|
|
|
|
|
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/SkPath.h"
|
|
|
|
#include "include/core/SkStream.h"
|
|
|
|
#include "include/core/SkTime.h"
|
|
|
|
#include "include/effects/SkBlurMaskFilter.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "samplecode/DecodeFile.h"
|
|
|
|
#include "samplecode/Sample.h"
|
|
|
|
#include "src/core/SkClipOpPriv.h"
|
|
|
|
#include "tools/Resources.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;
|
|
|
|
|
2019-07-03 14:55:44 +00:00
|
|
|
SkString name() override { return SkString("IdentityScale"); }
|
2014-08-08 19:11:33 +00:00
|
|
|
|
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"); )
|