| 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 "SampleCode.h" | 8 #include "SampleCode.h" | 
| 9 #include "SkView.h" | 9 #include "SkView.h" | 
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 23 #include "SkTypeface.h" | 23 #include "SkTypeface.h" | 
| 24 #include "SkXfermode.h" | 24 #include "SkXfermode.h" | 
| 25 | 25 | 
| 26 #include "SkStream.h" | 26 #include "SkStream.h" | 
| 27 #include "SkXMLParser.h" | 27 #include "SkXMLParser.h" | 
| 28 #include "SkColorPriv.h" | 28 #include "SkColorPriv.h" | 
| 29 #include "SkImageDecoder.h" | 29 #include "SkImageDecoder.h" | 
| 30 | 30 | 
| 31 static SkRandom gRand; | 31 static SkRandom gRand; | 
| 32 | 32 | 
| 33 static void test_chromium_9005() { |  | 
| 34     SkBitmap bm; |  | 
| 35     bm.allocN32Pixels(800, 600); |  | 
| 36 |  | 
| 37     SkCanvas canvas(bm); |  | 
| 38 |  | 
| 39     SkPoint pt0 = { 799.33374f, 1.2360189f }; |  | 
| 40     SkPoint pt1 = { 808.49969f, -7.4338055f }; |  | 
| 41 |  | 
| 42     SkPaint paint; |  | 
| 43     paint.setAntiAlias(true); |  | 
| 44     canvas.drawLine(pt0.fX, pt0.fY, pt1.fX, pt1.fY, paint); |  | 
| 45 } |  | 
| 46 |  | 
| 47 static void generate_pts(SkPoint pts[], int count, int w, int h) { | 33 static void generate_pts(SkPoint pts[], int count, int w, int h) { | 
| 48     for (int i = 0; i < count; i++) { | 34     for (int i = 0; i < count; i++) { | 
| 49         pts[i].set(gRand.nextUScalar1() * 3 * w - SkIntToScalar(w), | 35         pts[i].set(gRand.nextUScalar1() * 3 * w - SkIntToScalar(w), | 
| 50                    gRand.nextUScalar1() * 3 * h - SkIntToScalar(h)); | 36                    gRand.nextUScalar1() * 3 * h - SkIntToScalar(h)); | 
| 51     } | 37     } | 
| 52 } | 38 } | 
| 53 | 39 | 
| 54 static bool check_zeros(const SkPMColor pixels[], int count, int skip) { | 40 static bool check_zeros(const SkPMColor pixels[], int count, int skip) { | 
| 55     for (int i = 0; i < count; i++) { | 41     for (int i = 0; i < count; i++) { | 
| 56         if (*pixels) { | 42         if (*pixels) { | 
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 184 static int cycle_hairproc_index(int index) { | 170 static int cycle_hairproc_index(int index) { | 
| 185     return (index + 1) % SK_ARRAY_COUNT(gProcs); | 171     return (index + 1) % SK_ARRAY_COUNT(gProcs); | 
| 186 } | 172 } | 
| 187 | 173 | 
| 188 class HairlineView : public SampleView { | 174 class HairlineView : public SampleView { | 
| 189     SkMSec fNow; | 175     SkMSec fNow; | 
| 190     int fProcIndex; | 176     int fProcIndex; | 
| 191     bool fDoAA; | 177     bool fDoAA; | 
| 192 public: | 178 public: | 
| 193     HairlineView() { | 179     HairlineView() { | 
| 194         fCounter = 0; |  | 
| 195         fProcIndex = 0; | 180         fProcIndex = 0; | 
| 196         fDoAA = true; | 181         fDoAA = true; | 
| 197         fNow = 0; | 182         fNow = 0; | 
| 198     } | 183     } | 
| 199 | 184 | 
| 200 protected: | 185 protected: | 
| 201     // overrides from SkEventSink | 186     // overrides from SkEventSink | 
| 202     virtual bool onQuery(SkEvent* evt) { | 187     bool onQuery(SkEvent* evt) SK_OVERRIDE { | 
| 203         if (SampleCode::TitleQ(*evt)) { | 188         if (SampleCode::TitleQ(*evt)) { | 
| 204             SkString str; | 189             SkString str; | 
| 205             str.printf("Hair-%s", gProcs[fProcIndex].fName); | 190             str.printf("Hair-%s", gProcs[fProcIndex].fName); | 
| 206             SampleCode::TitleR(evt, str.c_str()); | 191             SampleCode::TitleR(evt, str.c_str()); | 
| 207             return true; | 192             return true; | 
| 208         } | 193         } | 
| 209         return this->INHERITED::onQuery(evt); | 194         return this->INHERITED::onQuery(evt); | 
| 210     } | 195     } | 
| 211 | 196 | 
| 212     void show_bitmaps(SkCanvas* canvas, const SkBitmap& b0, const SkBitmap& b1, | 197     void show_bitmaps(SkCanvas* canvas, const SkBitmap& b0, const SkBitmap& b1, | 
| 213                       const SkIRect& inset) { | 198                       const SkIRect& inset) { | 
| 214         canvas->drawBitmap(b0, 0, 0, NULL); | 199         canvas->drawBitmap(b0, 0, 0, NULL); | 
| 215         canvas->drawBitmap(b1, SkIntToScalar(b0.width()), 0, NULL); | 200         canvas->drawBitmap(b1, SkIntToScalar(b0.width()), 0, NULL); | 
| 216     } | 201     } | 
| 217 | 202 | 
| 218     int fCounter; | 203     void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { | 
| 219 |  | 
| 220     virtual void onDrawContent(SkCanvas* canvas) { |  | 
| 221         gRand.setSeed(fNow); | 204         gRand.setSeed(fNow); | 
| 222 | 205 | 
| 223         if (false) { // avoid bit rot, suppress warning |  | 
| 224             test_chromium_9005(); |  | 
| 225         } |  | 
| 226 |  | 
| 227         SkBitmap bm, bm2; | 206         SkBitmap bm, bm2; | 
| 228         bm.allocN32Pixels(WIDTH + MARGIN*2, HEIGHT + MARGIN*2); | 207         bm.allocN32Pixels(WIDTH + MARGIN*2, HEIGHT + MARGIN*2); | 
| 229         // this will erase our margin, which we want to always stay 0 | 208         // this will erase our margin, which we want to always stay 0 | 
| 230         bm.eraseColor(SK_ColorTRANSPARENT); | 209         bm.eraseColor(SK_ColorTRANSPARENT); | 
| 231 | 210 | 
| 232         bm2.installPixels(SkImageInfo::MakeN32Premul(WIDTH, HEIGHT), | 211         bm2.installPixels(SkImageInfo::MakeN32Premul(WIDTH, HEIGHT), | 
| 233                           bm.getAddr32(MARGIN, MARGIN), bm.rowBytes()); | 212                           bm.getAddr32(MARGIN, MARGIN), bm.rowBytes()); | 
| 234 | 213 | 
| 235         SkCanvas c2(bm2); | 214         SkCanvas c2(bm2); | 
| 236         SkPaint paint; | 215         SkPaint paint; | 
| 237         paint.setAntiAlias(fDoAA); | 216         paint.setAntiAlias(fDoAA); | 
| 238         paint.setStyle(SkPaint::kStroke_Style); | 217         paint.setStyle(SkPaint::kStroke_Style); | 
| 239 | 218 | 
| 240         bm2.eraseColor(SK_ColorTRANSPARENT); | 219         bm2.eraseColor(SK_ColorTRANSPARENT); | 
| 241         gProcs[fProcIndex].fProc(&c2, paint, bm); | 220         gProcs[fProcIndex].fProc(&c2, paint, bm); | 
| 242         canvas->drawBitmap(bm2, SkIntToScalar(10), SkIntToScalar(10), NULL); | 221         canvas->drawBitmap(bm2, SkIntToScalar(10), SkIntToScalar(10), NULL); | 
| 243 |  | 
| 244         SkMSec now = SampleCode::GetAnimTime(); |  | 
| 245         if (fNow != now) { |  | 
| 246             fNow = now; |  | 
| 247             fCounter += 1; |  | 
| 248             fDoAA = !fDoAA; |  | 
| 249             if (fCounter > 50) { |  | 
| 250                 fProcIndex = cycle_hairproc_index(fProcIndex); |  | 
| 251                 // todo: signal that we want to rebuild our TITLE |  | 
| 252                 fCounter = 0; |  | 
| 253             } |  | 
| 254             this->inval(NULL); |  | 
| 255         } |  | 
| 256     } | 222     } | 
| 257 | 223 | 
| 258     virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, | 224     bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE { | 
| 259                                               unsigned modi) { | 225         if (fDoAA) { | 
|  | 226             fProcIndex = cycle_hairproc_index(fProcIndex); | 
|  | 227             // todo: signal that we want to rebuild our TITLE | 
|  | 228         } | 
|  | 229         fDoAA = !fDoAA; | 
|  | 230         return true; | 
|  | 231     } | 
|  | 232 | 
|  | 233     SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) SK_
     OVERRIDE { | 
| 260         fDoAA = !fDoAA; | 234         fDoAA = !fDoAA; | 
| 261         this->inval(NULL); | 235         this->inval(NULL); | 
| 262         return this->INHERITED::onFindClickHandler(x, y, modi); | 236         return this->INHERITED::onFindClickHandler(x, y, modi); | 
| 263     } | 237     } | 
| 264 | 238 | 
| 265 | 239 | 
| 266 private: | 240 private: | 
| 267     typedef SampleView INHERITED; | 241     typedef SampleView INHERITED; | 
| 268 }; | 242 }; | 
| 269 | 243 | 
| 270 ////////////////////////////////////////////////////////////////////////////// | 244 ////////////////////////////////////////////////////////////////////////////// | 
| 271 | 245 | 
| 272 static SkView* MyFactory() { return new HairlineView; } | 246 static SkView* MyFactory() { return new HairlineView; } | 
| 273 static SkViewRegister reg(MyFactory); | 247 static SkViewRegister reg(MyFactory); | 
| OLD | NEW | 
|---|