blob: bb3ff54b930711d4c4278828872ceff15f3b1663 [file] [log] [blame]
humperd1d3bae2014-08-08 12:11:33 -07001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
msarettd15750c2016-03-18 15:48:49 -07008#include "DecodeFile.h"
humperd1d3bae2014-08-08 12:11:33 -07009#include "Resources.h"
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040010#include "Sample.h"
humperd1d3bae2014-08-08 12:11:33 -070011#include "SkBlurMaskFilter.h"
12#include "SkCanvas.h"
13#include "SkColorPriv.h"
Hal Canary4484b8f2019-01-08 14:00:08 -050014#include "SkFont.h"
bungemand3ebb482015-08-05 13:57:49 -070015#include "SkPath.h"
humperd1d3bae2014-08-08 12:11:33 -070016#include "SkRandom.h"
17#include "SkStream.h"
18#include "SkTime.h"
Mike Reedebfce6d2016-12-12 10:02:12 -050019#include "SkClipOpPriv.h"
humperd1d3bae2014-08-08 12:11:33 -070020
21// Intended to exercise pixel snapping observed with scaled images (and
22// with non-scaled images, but for a different reason): Bug 1145
23
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040024class IdentityScaleView : public Sample {
humperd1d3bae2014-08-08 12:11:33 -070025public:
26 IdentityScaleView(const char imageFilename[]) {
Mike Reed0933bc92017-12-09 01:27:41 +000027 if (!DecodeDataToBitmap(GetResourceAsData(imageFilename), &fBM)) {
28 fBM.allocN32Pixels(1, 1);
29 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
30 }
humperd1d3bae2014-08-08 12:11:33 -070031 }
32
33protected:
34 SkBitmap fBM;
35
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040036 bool onQuery(Sample::Event* evt) override {
37 if (Sample::TitleQ(*evt)) {
38 Sample::TitleR(evt, "IdentityScale");
humperd1d3bae2014-08-08 12:11:33 -070039 return true;
40 }
41 return this->INHERITED::onQuery(evt);
42 }
43
mtklein36352bf2015-03-25 18:17:31 -070044 void onDrawContent(SkCanvas* canvas) override {
humperd1d3bae2014-08-08 12:11:33 -070045
Hal Canary4484b8f2019-01-08 14:00:08 -050046 SkFont font(nullptr, 48);
humperd1d3bae2014-08-08 12:11:33 -070047 SkPaint paint;
48
49 paint.setAntiAlias(true);
reed93a12152015-03-16 10:08:34 -070050 paint.setFilterQuality(kHigh_SkFilterQuality);
humperd1d3bae2014-08-08 12:11:33 -070051
52 SkTime::DateTime time;
53 SkTime::GetDateTime(&time);
54
55 bool use_scale = (time.fSecond % 2 == 1);
56 const char *text;
57
58 canvas->save();
59 if (use_scale) {
60 text = "Scaled = 1";
61 } else {
62
63 SkRect r = { 100, 100, 356, 356 };
64 SkPath clipPath;
65 clipPath.addRoundRect(r, SkIntToScalar(5), SkIntToScalar(5));
Mike Reedc1f77742016-12-09 09:00:50 -050066 canvas->clipPath(clipPath, kIntersect_SkClipOp, true);
humperd1d3bae2014-08-08 12:11:33 -070067 text = "Scaled = 0";
68 }
69 canvas->drawBitmap( fBM, 100, 100, &paint );
70 canvas->restore();
Hal Canary4484b8f2019-01-08 14:00:08 -050071 canvas->drawString(text, 100, 400, font, paint);
humperd1d3bae2014-08-08 12:11:33 -070072 }
73
74private:
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040075 typedef Sample INHERITED;
humperd1d3bae2014-08-08 12:11:33 -070076};
77
78//////////////////////////////////////////////////////////////////////////////
79
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040080DEF_SAMPLE( return new IdentityScaleView("images/mandrill_256.png"); )