• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "include/core/SkCanvas.h"
9 #include "include/core/SkColorPriv.h"
10 #include "include/core/SkFont.h"
11 #include "include/core/SkPath.h"
12 #include "include/core/SkStream.h"
13 #include "include/core/SkTime.h"
14 #include "include/effects/SkBlurMaskFilter.h"
15 #include "include/utils/SkRandom.h"
16 #include "samplecode/DecodeFile.h"
17 #include "samplecode/Sample.h"
18 #include "src/core/SkClipOpPriv.h"
19 #include "tools/Resources.h"
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 
24 class IdentityScaleView : public Sample {
25 public:
IdentityScaleView(const char imageFilename[])26     IdentityScaleView(const char imageFilename[]) {
27         if (!DecodeDataToBitmap(GetResourceAsData(imageFilename), &fBM)) {
28             fBM.allocN32Pixels(1, 1);
29             *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
30         }
31     }
32 
33 protected:
34     SkBitmap fBM;
35 
name()36     SkString name() override { return SkString("IdentityScale"); }
37 
onDrawContent(SkCanvas * canvas)38     void onDrawContent(SkCanvas* canvas) override {
39 
40         SkFont font(nullptr, 48);
41         SkPaint paint;
42 
43         paint.setAntiAlias(true);
44         paint.setFilterQuality(kHigh_SkFilterQuality);
45 
46         SkTime::DateTime time;
47         SkTime::GetDateTime(&time);
48 
49         bool use_scale = (time.fSecond % 2 == 1);
50         const char *text;
51 
52         canvas->save();
53         if (use_scale) {
54           text = "Scaled = 1";
55         } else {
56 
57           SkRect r = { 100, 100, 356, 356 };
58           SkPath clipPath;
59           clipPath.addRoundRect(r, SkIntToScalar(5), SkIntToScalar(5));
60           canvas->clipPath(clipPath, kIntersect_SkClipOp, true);
61           text = "Scaled = 0";
62         }
63         canvas->drawBitmap( fBM, 100, 100, &paint );
64         canvas->restore();
65         canvas->drawString(text, 100, 400, font, paint);
66     }
67 
68 private:
69     typedef Sample INHERITED;
70 };
71 
72 //////////////////////////////////////////////////////////////////////////////
73 
74 DEF_SAMPLE( return new IdentityScaleView("images/mandrill_256.png"); )
75