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 "gm.h" |
| 10 | |
| 11 | #include "Resources.h" |
| 12 | #include "SampleCode.h" |
| 13 | #include "SkBlurMaskFilter.h" |
| 14 | #include "SkCanvas.h" |
| 15 | #include "SkColorPriv.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 16 | #include "SkPath.h" |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 17 | #include "SkRandom.h" |
| 18 | #include "SkStream.h" |
| 19 | #include "SkTime.h" |
Mike Reed | ebfce6d | 2016-12-12 10:02:12 -0500 | [diff] [blame] | 20 | #include "SkClipOpPriv.h" |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 21 | |
| 22 | // Intended to exercise pixel snapping observed with scaled images (and |
| 23 | // with non-scaled images, but for a different reason): Bug 1145 |
| 24 | |
| 25 | class IdentityScaleView : public SampleView { |
| 26 | public: |
| 27 | IdentityScaleView(const char imageFilename[]) { |
Mike Reed | 0933bc9 | 2017-12-09 01:27:41 +0000 | [diff] [blame] | 28 | if (!DecodeDataToBitmap(GetResourceAsData(imageFilename), &fBM)) { |
| 29 | fBM.allocN32Pixels(1, 1); |
| 30 | *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad |
| 31 | } |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | protected: |
| 35 | SkBitmap fBM; |
| 36 | |
| 37 | // overrides from SkEventSink |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 38 | bool onQuery(SkEvent* evt) override { |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 39 | if (SampleCode::TitleQ(*evt)) { |
| 40 | SampleCode::TitleR(evt, "IdentityScale"); |
| 41 | return true; |
| 42 | } |
| 43 | return this->INHERITED::onQuery(evt); |
| 44 | } |
| 45 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 46 | void onDrawContent(SkCanvas* canvas) override { |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 47 | |
| 48 | SkPaint paint; |
| 49 | |
| 50 | paint.setAntiAlias(true); |
| 51 | paint.setTextSize(48); |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 52 | paint.setFilterQuality(kHigh_SkFilterQuality); |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 53 | |
| 54 | SkTime::DateTime time; |
| 55 | SkTime::GetDateTime(&time); |
| 56 | |
| 57 | bool use_scale = (time.fSecond % 2 == 1); |
| 58 | const char *text; |
| 59 | |
| 60 | canvas->save(); |
| 61 | if (use_scale) { |
| 62 | text = "Scaled = 1"; |
| 63 | } else { |
| 64 | |
| 65 | SkRect r = { 100, 100, 356, 356 }; |
| 66 | SkPath clipPath; |
| 67 | clipPath.addRoundRect(r, SkIntToScalar(5), SkIntToScalar(5)); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 68 | canvas->clipPath(clipPath, kIntersect_SkClipOp, true); |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 69 | text = "Scaled = 0"; |
| 70 | } |
| 71 | canvas->drawBitmap( fBM, 100, 100, &paint ); |
| 72 | canvas->restore(); |
Cary Clark | 2a475ea | 2017-04-28 15:35:12 -0400 | [diff] [blame] | 73 | canvas->drawString(text, 100, 400, paint ); |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | private: |
| 77 | typedef SampleView INHERITED; |
| 78 | }; |
| 79 | |
| 80 | ////////////////////////////////////////////////////////////////////////////// |
| 81 | |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 82 | static SkView* MyFactory() { return new IdentityScaleView("images/mandrill_256.png"); } |
humper | d1d3bae | 2014-08-08 12:11:33 -0700 | [diff] [blame] | 83 | static SkViewRegister reg(MyFactory); |