Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: samplecode/SampleMipMap.cpp

Issue 901933004: migrate more samples over to SkAnimTImer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix warning Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « samplecode/SampleFilterQuality.cpp ('k') | samplecode/SampleMovie.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
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:
44 MipMapView() {
45 fOnce = false;
46 }
47
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
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
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
100 static SkView* MyFactory() { return new MipMapView; }
101 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleFilterQuality.cpp ('k') | samplecode/SampleMovie.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698