OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkAnimTimer.h" | 9 #include "SkAnimTimer.h" |
10 #include "SkView.h" | 10 #include "SkView.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 enum { | 120 enum { |
121 N = 50, | 121 N = 50, |
122 W = 640, | 122 W = 640, |
123 H = 480, | 123 H = 480, |
124 }; | 124 }; |
125 | 125 |
126 struct Rec { | 126 struct Rec { |
127 HTDrawable* fDrawable; | 127 HTDrawable* fDrawable; |
128 }; | 128 }; |
129 Rec fArray[N]; | 129 Rec fArray[N]; |
130 SkAutoTUnref<SkDrawable> fRoot; | 130 sk_sp<SkDrawable> fRoot; |
131 SkMSec fTime; | 131 SkMSec fTime; |
132 | 132 |
133 HTView() { | 133 HTView() { |
134 SkRandom rand; | 134 SkRandom rand; |
135 | 135 |
136 SkPictureRecorder recorder; | 136 SkPictureRecorder recorder; |
137 SkCanvas* canvas = recorder.beginRecording(SkRect::MakeWH(W, H)); | 137 SkCanvas* canvas = recorder.beginRecording(SkRect::MakeWH(W, H)); |
138 for (int i = 0; i < N; ++i) { | 138 for (int i = 0; i < N; ++i) { |
139 fArray[i].fDrawable = new HTDrawable(rand); | 139 fArray[i].fDrawable = new HTDrawable(rand); |
140 canvas->drawDrawable(fArray[i].fDrawable); | 140 canvas->drawDrawable(fArray[i].fDrawable); |
141 fArray[i].fDrawable->unref(); | 141 fArray[i].fDrawable->unref(); |
142 } | 142 } |
143 fRoot.reset(recorder.endRecordingAsDrawable()); | 143 fRoot = recorder.finishRecordingAsDrawable(); |
144 } | 144 } |
145 | 145 |
146 protected: | 146 protected: |
147 bool onQuery(SkEvent* evt) override { | 147 bool onQuery(SkEvent* evt) override { |
148 if (SampleCode::TitleQ(*evt)) { | 148 if (SampleCode::TitleQ(*evt)) { |
149 SampleCode::TitleR(evt, "HT"); | 149 SampleCode::TitleR(evt, "HT"); |
150 return true; | 150 return true; |
151 } | 151 } |
152 return this->INHERITED::onQuery(evt); | 152 return this->INHERITED::onQuery(evt); |
153 } | 153 } |
154 | 154 |
155 void onDrawContent(SkCanvas* canvas) override { | 155 void onDrawContent(SkCanvas* canvas) override { |
156 canvas->drawDrawable(fRoot); | 156 canvas->drawDrawable(fRoot.get()); |
157 } | 157 } |
158 | 158 |
159 bool onAnimate(const SkAnimTimer& timer) override { | 159 bool onAnimate(const SkAnimTimer& timer) override { |
160 fTime = timer.msec(); | 160 fTime = timer.msec(); |
161 for (int i = 0; i < N; ++i) { | 161 for (int i = 0; i < N; ++i) { |
162 fArray[i].fDrawable->setTime(fTime); | 162 fArray[i].fDrawable->setTime(fTime); |
163 } | 163 } |
164 return true; | 164 return true; |
165 } | 165 } |
166 | 166 |
(...skipping 10 matching lines...) Expand all Loading... |
177 } | 177 } |
178 | 178 |
179 private: | 179 private: |
180 typedef SampleView INHERITED; | 180 typedef SampleView INHERITED; |
181 }; | 181 }; |
182 | 182 |
183 ////////////////////////////////////////////////////////////////////////////// | 183 ////////////////////////////////////////////////////////////////////////////// |
184 | 184 |
185 static SkView* MyFactory() { return new HTView; } | 185 static SkView* MyFactory() { return new HTView; } |
186 static SkViewRegister reg(MyFactory); | 186 static SkViewRegister reg(MyFactory); |
OLD | NEW |