• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2011 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 #include "SampleCode.h"
9 #include "SkView.h"
10 #include "SkCanvas.h"
11 #include "SkDevice.h"
12 #include "SkPaint.h"
13 #include "SkShader.h"
14 
createBitmap(int n)15 static SkBitmap createBitmap(int n) {
16     SkBitmap bitmap;
17     bitmap.allocN32Pixels(n, n);
18     bitmap.eraseColor(SK_ColorTRANSPARENT);
19 
20     SkCanvas canvas(bitmap);
21     SkRect r;
22     r.set(0, 0, SkIntToScalar(n), SkIntToScalar(n));
23     SkPaint paint;
24     paint.setAntiAlias(true);
25 
26     paint.setColor(SK_ColorRED);
27     canvas.drawOval(r, paint);
28     paint.setColor(SK_ColorBLUE);
29     paint.setStrokeWidth(SkIntToScalar(n)/15);
30     paint.setStyle(SkPaint::kStroke_Style);
31     canvas.drawLine(0, 0, r.fRight, r.fBottom, paint);
32     canvas.drawLine(0, r.fBottom, r.fRight, 0, paint);
33 
34     return bitmap;
35 }
36 
37 class MipMapView : public SampleView {
38     SkBitmap fBitmap;
39     enum {
40         N = 64
41     };
42     bool fOnce;
43 public:
MipMapView()44     MipMapView() {
45         fOnce = false;
46     }
47 
init()48     void init() {
49         if (fOnce) {
50             return;
51         }
52         fOnce = true;
53 
54         fBitmap = createBitmap(N);
55 
56         fWidth = N;
57     }
58 
59 protected:
60     // overrides from SkEventSink
onQuery(SkEvent * evt)61     virtual bool onQuery(SkEvent* evt) {
62         if (SampleCode::TitleQ(*evt)) {
63             SampleCode::TitleR(evt, "MipMaps");
64             return true;
65         }
66         return this->INHERITED::onQuery(evt);
67     }
68 
onDrawContent(SkCanvas * canvas)69     virtual void onDrawContent(SkCanvas* canvas) {
70         this->init();
71 
72         static const SkPaint::FilterLevel gLevel[] = {
73             SkPaint::kNone_FilterLevel,
74             SkPaint::kLow_FilterLevel,
75             SkPaint::kMedium_FilterLevel,
76             SkPaint::kHigh_FilterLevel,
77         };
78 
79         SkPaint paint;
80 
81         for (size_t i = 0; i < SK_ARRAY_COUNT(gLevel); ++i) {
82             SkScalar x = 10.0f + i * 100;
83             SkScalar y = 10.0f;
84 
85             paint.setFilterLevel(gLevel[i]);
86 
87             canvas->drawBitmap(fBitmap, x, y, &paint);
88         }
89         this->inval(NULL);
90     }
91 
92 private:
93     int fWidth;
94 
95     typedef SampleView INHERITED;
96 };
97 
98 //////////////////////////////////////////////////////////////////////////////
99 
MyFactory()100 static SkView* MyFactory() { return new MipMapView; }
101 static SkViewRegister reg(MyFactory);
102