OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "Resources.h" | 10 #include "Resources.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "SkView.h" | 32 #include "SkView.h" |
33 #include "SkXMLParser.h" | 33 #include "SkXMLParser.h" |
34 #include "SkXfermode.h" | 34 #include "SkXfermode.h" |
35 | 35 |
36 /////////////////////////////////////////////////////////////////////////////// | 36 /////////////////////////////////////////////////////////////////////////////// |
37 | 37 |
38 static SkBitmap load_bitmap() { | 38 static SkBitmap load_bitmap() { |
39 SkBitmap bm; | 39 SkBitmap bm; |
40 SkString pngFilename = GetResourcePath("mandrill_512.png"); | 40 SkString pngFilename = GetResourcePath("mandrill_512.png"); |
41 SkAutoDataUnref data(SkData::NewFromFileName(pngFilename.c_str())); | 41 SkAutoDataUnref data(SkData::NewFromFileName(pngFilename.c_str())); |
42 if (data.get() != NULL) { | 42 if (data.get() != nullptr) { |
43 SkInstallDiscardablePixelRef(data, &bm); | 43 SkInstallDiscardablePixelRef(data, &bm); |
44 } | 44 } |
45 return bm; | 45 return bm; |
46 } | 46 } |
47 | 47 |
48 static void drawCircle(SkCanvas* canvas, int r, SkColor color) { | 48 static void drawCircle(SkCanvas* canvas, int r, SkColor color) { |
49 SkPaint paint; | 49 SkPaint paint; |
50 paint.setAntiAlias(true); | 50 paint.setAntiAlias(true); |
51 paint.setColor(color); | 51 paint.setColor(color); |
52 | 52 |
53 canvas->drawCircle(SkIntToScalar(r), SkIntToScalar(r), SkIntToScalar(r), | 53 canvas->drawCircle(SkIntToScalar(r), SkIntToScalar(r), SkIntToScalar(r), |
54 paint); | 54 paint); |
55 } | 55 } |
56 | 56 |
57 class PictureView : public SampleView { | 57 class PictureView : public SampleView { |
58 SkBitmap fBitmap; | 58 SkBitmap fBitmap; |
59 public: | 59 public: |
60 PictureView() { | 60 PictureView() { |
61 | 61 |
62 fBitmap = load_bitmap(); | 62 fBitmap = load_bitmap(); |
63 | 63 |
64 SkPictureRecorder recorder; | 64 SkPictureRecorder recorder; |
65 | 65 |
66 recorder.beginRecording(100, 100, NULL, 0); | 66 recorder.beginRecording(100, 100, nullptr, 0); |
67 fSubPicture = recorder.endRecording(); | 67 fSubPicture = recorder.endRecording(); |
68 | 68 |
69 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); | 69 SkCanvas* canvas = recorder.beginRecording(100, 100, nullptr, 0); |
70 SkPaint paint; | 70 SkPaint paint; |
71 paint.setAntiAlias(true); | 71 paint.setAntiAlias(true); |
72 | 72 |
73 canvas->drawBitmap(fBitmap, 0, 0, NULL); | 73 canvas->drawBitmap(fBitmap, 0, 0, nullptr); |
74 | 74 |
75 drawCircle(canvas, 50, SK_ColorBLACK); | 75 drawCircle(canvas, 50, SK_ColorBLACK); |
76 canvas->drawPicture(fSubPicture); | 76 canvas->drawPicture(fSubPicture); |
77 canvas->translate(SkIntToScalar(50), 0); | 77 canvas->translate(SkIntToScalar(50), 0); |
78 canvas->drawPicture(fSubPicture); | 78 canvas->drawPicture(fSubPicture); |
79 canvas->translate(0, SkIntToScalar(50)); | 79 canvas->translate(0, SkIntToScalar(50)); |
80 canvas->drawPicture(fSubPicture); | 80 canvas->drawPicture(fSubPicture); |
81 canvas->translate(SkIntToScalar(-50), 0); | 81 canvas->translate(SkIntToScalar(-50), 0); |
82 canvas->drawPicture(fSubPicture); | 82 canvas->drawPicture(fSubPicture); |
83 | 83 |
(...skipping 17 matching lines...) Expand all Loading... |
101 return true; | 101 return true; |
102 } | 102 } |
103 return this->INHERITED::onQuery(evt); | 103 return this->INHERITED::onQuery(evt); |
104 } | 104 } |
105 | 105 |
106 void drawSomething(SkCanvas* canvas) { | 106 void drawSomething(SkCanvas* canvas) { |
107 SkPaint paint; | 107 SkPaint paint; |
108 | 108 |
109 canvas->save(); | 109 canvas->save(); |
110 canvas->scale(0.5f, 0.5f); | 110 canvas->scale(0.5f, 0.5f); |
111 canvas->drawBitmap(fBitmap, 0, 0, NULL); | 111 canvas->drawBitmap(fBitmap, 0, 0, nullptr); |
112 canvas->restore(); | 112 canvas->restore(); |
113 | 113 |
114 paint.setAntiAlias(true); | 114 paint.setAntiAlias(true); |
115 | 115 |
116 paint.setColor(SK_ColorRED); | 116 paint.setColor(SK_ColorRED); |
117 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50), | 117 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50), |
118 SkIntToScalar(40), paint); | 118 SkIntToScalar(40), paint); |
119 paint.setColor(SK_ColorBLACK); | 119 paint.setColor(SK_ColorBLACK); |
120 paint.setTextSize(SkIntToScalar(40)); | 120 paint.setTextSize(SkIntToScalar(40)); |
121 canvas->drawText("Picture", 7, SkIntToScalar(50), SkIntToScalar(62), | 121 canvas->drawText("Picture", 7, SkIntToScalar(50), SkIntToScalar(62), |
122 paint); | 122 paint); |
123 | 123 |
124 } | 124 } |
125 | 125 |
126 void onDrawContent(SkCanvas* canvas) override { | 126 void onDrawContent(SkCanvas* canvas) override { |
127 this->drawSomething(canvas); | 127 this->drawSomething(canvas); |
128 | 128 |
129 SkPictureRecorder recorder; | 129 SkPictureRecorder recorder; |
130 this->drawSomething(recorder.beginRecording(100, 100, NULL, 0)); | 130 this->drawSomething(recorder.beginRecording(100, 100, nullptr, 0)); |
131 SkAutoTUnref<SkPicture> pict(recorder.endRecording()); | 131 SkAutoTUnref<SkPicture> pict(recorder.endRecording()); |
132 | 132 |
133 canvas->save(); | 133 canvas->save(); |
134 canvas->translate(SkIntToScalar(300), SkIntToScalar(50)); | 134 canvas->translate(SkIntToScalar(300), SkIntToScalar(50)); |
135 canvas->scale(-SK_Scalar1, -SK_Scalar1); | 135 canvas->scale(-SK_Scalar1, -SK_Scalar1); |
136 canvas->translate(-SkIntToScalar(100), -SkIntToScalar(50)); | 136 canvas->translate(-SkIntToScalar(100), -SkIntToScalar(50)); |
137 canvas->drawPicture(pict); | 137 canvas->drawPicture(pict); |
138 canvas->restore(); | 138 canvas->restore(); |
139 | 139 |
140 canvas->save(); | 140 canvas->save(); |
(...skipping 13 matching lines...) Expand all Loading... |
154 | 154 |
155 private: | 155 private: |
156 #define INVAL_ALL_TYPE "inval-all" | 156 #define INVAL_ALL_TYPE "inval-all" |
157 | 157 |
158 void delayInval(SkMSec delay) { | 158 void delayInval(SkMSec delay) { |
159 (new SkEvent(INVAL_ALL_TYPE, this->getSinkID()))->postDelay(delay); | 159 (new SkEvent(INVAL_ALL_TYPE, this->getSinkID()))->postDelay(delay); |
160 } | 160 } |
161 | 161 |
162 bool onEvent(const SkEvent& evt) override { | 162 bool onEvent(const SkEvent& evt) override { |
163 if (evt.isType(INVAL_ALL_TYPE)) { | 163 if (evt.isType(INVAL_ALL_TYPE)) { |
164 this->inval(NULL); | 164 this->inval(nullptr); |
165 return true; | 165 return true; |
166 } | 166 } |
167 return this->INHERITED::onEvent(evt); | 167 return this->INHERITED::onEvent(evt); |
168 } | 168 } |
169 | 169 |
170 SkPicture* fPicture; | 170 SkPicture* fPicture; |
171 SkPicture* fSubPicture; | 171 SkPicture* fSubPicture; |
172 | 172 |
173 typedef SampleView INHERITED; | 173 typedef SampleView INHERITED; |
174 }; | 174 }; |
175 | 175 |
176 ////////////////////////////////////////////////////////////////////////////// | 176 ////////////////////////////////////////////////////////////////////////////// |
177 | 177 |
178 static SkView* MyFactory() { return new PictureView; } | 178 static SkView* MyFactory() { return new PictureView; } |
179 static SkViewRegister reg(MyFactory); | 179 static SkViewRegister reg(MyFactory); |
OLD | NEW |