| 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" |
| 11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkCanvasDrawable.h" | 12 #include "SkDrawable.h" |
| 13 #include "SkInterpolator.h" | 13 #include "SkInterpolator.h" |
| 14 #include "SkPictureRecorder.h" | 14 #include "SkPictureRecorder.h" |
| 15 #include "SkRandom.h" | 15 #include "SkRandom.h" |
| 16 | 16 |
| 17 const SkRect gUnitSquare = { -1, -1, 1, 1 }; | 17 const SkRect gUnitSquare = { -1, -1, 1, 1 }; |
| 18 | 18 |
| 19 static void color_to_floats(SkColor c, SkScalar f[4]) { | 19 static void color_to_floats(SkColor c, SkScalar f[4]) { |
| 20 f[0] = SkIntToScalar(SkColorGetA(c)); | 20 f[0] = SkIntToScalar(SkColorGetA(c)); |
| 21 f[1] = SkIntToScalar(SkColorGetR(c)); | 21 f[1] = SkIntToScalar(SkColorGetR(c)); |
| 22 f[2] = SkIntToScalar(SkColorGetG(c)); | 22 f[2] = SkIntToScalar(SkColorGetG(c)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 36 SkPoint pt; | 36 SkPoint pt; |
| 37 m.mapXY(x, y, &pt); | 37 m.mapXY(x, y, &pt); |
| 38 return pt.lengthSqd() <= 1; | 38 return pt.lengthSqd() <= 1; |
| 39 } | 39 } |
| 40 | 40 |
| 41 static SkColor rand_opaque_color(uint32_t seed) { | 41 static SkColor rand_opaque_color(uint32_t seed) { |
| 42 SkRandom rand(seed); | 42 SkRandom rand(seed); |
| 43 return rand.nextU() | (0xFF << 24); | 43 return rand.nextU() | (0xFF << 24); |
| 44 } | 44 } |
| 45 | 45 |
| 46 class HTDrawable : public SkCanvasDrawable { | 46 class HTDrawable : public SkDrawable { |
| 47 SkRect fR; | 47 SkRect fR; |
| 48 SkColor fColor; | 48 SkColor fColor; |
| 49 SkInterpolator* fInterp; | 49 SkInterpolator* fInterp; |
| 50 SkMSec fTime; | 50 SkMSec fTime; |
| 51 | 51 |
| 52 public: | 52 public: |
| 53 HTDrawable(SkRandom& rand) { | 53 HTDrawable(SkRandom& rand) { |
| 54 fR = SkRect::MakeXYWH(rand.nextRangeF(0, 640), rand.nextRangeF(0, 480), | 54 fR = SkRect::MakeXYWH(rand.nextRangeF(0, 640), rand.nextRangeF(0, 480), |
| 55 rand.nextRangeF(20, 200), rand.nextRangeF(20, 200)
); | 55 rand.nextRangeF(20, 200), rand.nextRangeF(20, 200)
); |
| 56 fColor = rand_opaque_color(rand.nextU()); | 56 fColor = rand_opaque_color(rand.nextU()); |
| (...skipping 63 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<SkCanvasDrawable> fRoot; | 130 SkAutoTUnref<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->EXPERIMENTAL_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.EXPERIMENTAL_endRecordingAsDrawable()); | 143 fRoot.reset(recorder.endRecordingAsDrawable()); |
| 144 } | 144 } |
| 145 | 145 |
| 146 protected: | 146 protected: |
| 147 bool onQuery(SkEvent* evt) SK_OVERRIDE { | 147 bool onQuery(SkEvent* evt) SK_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) SK_OVERRIDE { | 155 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { |
| 156 canvas->EXPERIMENTAL_drawDrawable(fRoot); | 156 canvas->drawDrawable(fRoot); |
| 157 } | 157 } |
| 158 | 158 |
| 159 bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE { | 159 bool onAnimate(const SkAnimTimer& timer) SK_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 |