humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
msarett | d15750c | 2016-03-18 15:48:49 -0700 | [diff] [blame] | 8 | #include "DecodeFile.h" |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 9 | #include "Resources.h" |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 10 | #include "Sample.h" |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 11 | #include "SkBlurMaskFilter.h" |
| 12 | #include "SkCanvas.h" |
| 13 | #include "SkColorPriv.h" |
Hal Canary | 4484b8f | 2019-01-08 14:00:08 -0500 | [diff] [blame] | 14 | #include "SkFont.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 15 | #include "SkPath.h" |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 16 | #include "SkRandom.h" |
| 17 | #include "SkStream.h" |
| 18 | #include "SkTime.h" |
Mike Reed | ebfce6d | 2016-12-12 10:02:12 -0500 | [diff] [blame] | 19 | #include "SkClipOpPriv.h" |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 20 | |
| 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 Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 24 | class IdentityScaleView : public Sample { |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 25 | public: |
| 26 | IdentityScaleView(const char imageFilename[]) { |
Mike Reed | 0933bc9 | 2017-12-09 01:27:41 +0000 | [diff] [blame] | 27 | if (!DecodeDataToBitmap(GetResourceAsData(imageFilename), &fBM)) { |
| 28 | fBM.allocN32Pixels(1, 1); |
| 29 | *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad |
| 30 | } |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | protected: |
| 34 | SkBitmap fBM; |
| 35 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 36 | bool onQuery(Sample::Event* evt) override { |
| 37 | if (Sample::TitleQ(*evt)) { |
| 38 | Sample::TitleR(evt, "IdentityScale"); |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 39 | return true; |
| 40 | } |
| 41 | return this->INHERITED::onQuery(evt); |
| 42 | } |
| 43 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 44 | void onDrawContent(SkCanvas* canvas) override { |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 45 | |
Hal Canary | 4484b8f | 2019-01-08 14:00:08 -0500 | [diff] [blame] | 46 | SkFont font(nullptr, 48); |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 47 | SkPaint paint; |
| 48 | |
| 49 | paint.setAntiAlias(true); |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 50 | paint.setFilterQuality(kHigh_SkFilterQuality); |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 51 | |
| 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 Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 66 | canvas->clipPath(clipPath, kIntersect_SkClipOp, true); |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 67 | text = "Scaled = 0"; |
| 68 | } |
| 69 | canvas->drawBitmap( fBM, 100, 100, &paint ); |
| 70 | canvas->restore(); |
Hal Canary | 4484b8f | 2019-01-08 14:00:08 -0500 | [diff] [blame] | 71 | canvas->drawString(text, 100, 400, font, paint); |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | private: |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 75 | typedef Sample INHERITED; |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | ////////////////////////////////////////////////////////////////////////////// |
| 79 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 80 | DEF_SAMPLE( return new IdentityScaleView("images/mandrill_256.png"); ) |