| OLD | NEW |
| 1 #include "SampleCode.h" | 1 #include "SampleCode.h" |
| 2 #include "SkView.h" | 2 #include "SkView.h" |
| 3 #include "SkCanvas.h" | 3 #include "SkCanvas.h" |
| 4 #include "SkGraphics.h" | 4 #include "SkGraphics.h" |
| 5 #include "SkRandom.h" | 5 #include "SkRandom.h" |
| 6 #include "SkFlipPixelRef.h" | 6 #include "SkFlipPixelRef.h" |
| 7 #include "SkPageFlipper.h" | 7 #include "SkPageFlipper.h" |
| 8 | 8 |
| 9 #include <pthread.h> | 9 #include <pthread.h> |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 const SkBitmap* bm = static_cast<const SkBitmap*>(context); | 35 const SkBitmap* bm = static_cast<const SkBitmap*>(context); |
| 36 SkFlipPixelRef* ref = static_cast<SkFlipPixelRef*>(bm->pixelRef()); | 36 SkFlipPixelRef* ref = static_cast<SkFlipPixelRef*>(bm->pixelRef()); |
| 37 | 37 |
| 38 const int DSCALE = 1; | 38 const int DSCALE = 1; |
| 39 SkScalar dx = SkIntToScalar(7) / DSCALE; | 39 SkScalar dx = SkIntToScalar(7) / DSCALE; |
| 40 SkScalar dy = SkIntToScalar(5) / DSCALE; | 40 SkScalar dy = SkIntToScalar(5) / DSCALE; |
| 41 SkScalar x = 0; | 41 SkScalar x = 0; |
| 42 SkScalar y = 0; | 42 SkScalar y = 0; |
| 43 | 43 |
| 44 SkPaint paint; | 44 SkPaint paint; |
| 45 | 45 |
| 46 paint.setAntiAlias(true); | 46 paint.setAntiAlias(true); |
| 47 paint.setColor(SK_ColorRED); | 47 paint.setColor(SK_ColorRED); |
| 48 | 48 |
| 49 SkRect oval; | 49 SkRect oval; |
| 50 oval.setEmpty(); | 50 oval.setEmpty(); |
| 51 | 51 |
| 52 while (!gDone) { | 52 while (!gDone) { |
| 53 ref->inval(oval, true); | 53 ref->inval(oval, true); |
| 54 oval.set(x, y, x + SkIntToScalar(OVALW), y + SkIntToScalar(OVALH)); | 54 oval.set(x, y, x + SkIntToScalar(OVALW), y + SkIntToScalar(OVALH)); |
| 55 ref->inval(oval, true); | 55 ref->inval(oval, true); |
| 56 | 56 |
| 57 SkAutoFlipUpdate update(ref); | 57 SkAutoFlipUpdate update(ref); |
| 58 | 58 |
| 59 if (!update.dirty().isEmpty()) { | 59 if (!update.dirty().isEmpty()) { |
| 60 // this must be local to the loop, since it needs to forget the pixe
ls | 60 // this must be local to the loop, since it needs to forget the pixe
ls |
| 61 // its writing to after each iteration, since we do the swap | 61 // its writing to after each iteration, since we do the swap |
| 62 SkCanvas canvas(update.bitmap()); | 62 SkCanvas canvas(update.bitmap()); |
| 63 | 63 |
| 64 // SkDebugf("----- dirty [%d %d %d %d]\n", dirty.getBounds().fLeft, d
irty.getBounds().fTop, dirty.getBounds().width(), dirty.getBounds().height()); | 64 // SkDebugf("----- dirty [%d %d %d %d]\n", dirty.getBounds().fLeft, d
irty.getBounds().fTop, dirty.getBounds().width(), dirty.getBounds().height()); |
| 65 canvas.clipRegion(update.dirty()); | 65 canvas.clipRegion(update.dirty()); |
| 66 | 66 |
| 67 canvas.drawColor(0, SkXfermode::kClear_Mode); | 67 canvas.drawColor(0, SkXfermode::kClear_Mode); |
| 68 canvas.drawOval(oval, paint); | 68 canvas.drawOval(oval, paint); |
| 69 } | 69 } |
| 70 bounce(&x, &dx, WIDTH-OVALW); | 70 bounce(&x, &dx, WIDTH-OVALW); |
| 71 bounce(&y, &dy, HEIGHT-OVALH); | 71 bounce(&y, &dy, HEIGHT-OVALH); |
| 72 | 72 |
| 73 #if 1 | 73 #if 1 |
| 74 for (int i = 0; i < 1000; i++) { | 74 for (int i = 0; i < 1000; i++) { |
| 75 for (int j = 0; j < 10000; j++) { | 75 for (int j = 0; j < 10000; j++) { |
| 76 SkFixedMul(j, 10); | 76 SkFixedMul(j, 10); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 #endif | 79 #endif |
| 80 } | 80 } |
| 81 return NULL; | 81 return NULL; |
| 82 } | 82 } |
| 83 | 83 |
| 84 static const SkBitmap::Config gConfigs[] = { | 84 static const SkBitmap::Config gConfigs[] = { |
| 85 SkBitmap::kARGB_8888_Config, | 85 SkBitmap::kARGB_8888_Config, |
| 86 #if 1 | 86 #if 1 |
| 87 SkBitmap::kRGB_565_Config, | 87 SkBitmap::kRGB_565_Config, |
| 88 SkBitmap::kARGB_4444_Config, | 88 SkBitmap::kARGB_4444_Config, |
| 89 SkBitmap::kA8_Config | 89 SkBitmap::kA8_Config |
| 90 #endif | 90 #endif |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 class PageFlipView : public SkView { | 93 class PageFlipView : public SkView { |
| 94 public: | 94 public: |
| 95 | 95 |
| 96 enum { N = SK_ARRAY_COUNT(gConfigs) }; | 96 enum { N = SK_ARRAY_COUNT(gConfigs) }; |
| 97 | 97 |
| 98 pthread_t fThreads[N]; | 98 pthread_t fThreads[N]; |
| 99 SkBitmap fBitmaps[N]; | 99 SkBitmap fBitmaps[N]; |
| 100 | 100 |
| 101 PageFlipView() { | 101 PageFlipView() { |
| 102 gDone = false; | 102 gDone = false; |
| 103 for (int i = 0; i < N; i++) { | 103 for (int i = 0; i < N; i++) { |
| 104 int status; | 104 int status; |
| 105 pthread_attr_t attr; | 105 pthread_attr_t attr; |
| 106 | 106 |
| 107 status = pthread_attr_init(&attr); | 107 status = pthread_attr_init(&attr); |
| 108 SkASSERT(0 == status); | 108 SkASSERT(0 == status); |
| 109 | 109 |
| 110 fBitmaps[i].setConfig(gConfigs[i], WIDTH, HEIGHT); | 110 fBitmaps[i].setConfig(gConfigs[i], WIDTH, HEIGHT); |
| 111 SkFlipPixelRef* pr = new SkFlipPixelRef(gConfigs[i], WIDTH, HEIGHT); | 111 SkFlipPixelRef* pr = new SkFlipPixelRef(gConfigs[i], WIDTH, HEIGHT); |
| 112 fBitmaps[i].setPixelRef(pr)->unref(); | 112 fBitmaps[i].setPixelRef(pr)->unref(); |
| 113 fBitmaps[i].eraseColor(0); | 113 fBitmaps[i].eraseColor(0); |
| 114 | 114 |
| 115 status = pthread_create(&fThreads[i], &attr, draw_proc, &fBitmaps[i
]); | 115 status = pthread_create(&fThreads[i], &attr, draw_proc, &fBitmaps[i
]); |
| 116 SkASSERT(0 == status); | 116 SkASSERT(0 == status); |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 virtual ~PageFlipView() { | 120 virtual ~PageFlipView() { |
| 121 gDone = true; | 121 gDone = true; |
| 122 for (int i = 0; i < N; i++) { | 122 for (int i = 0; i < N; i++) { |
| 123 void* ret; | 123 void* ret; |
| 124 int status = pthread_join(fThreads[i], &ret); | 124 int status = pthread_join(fThreads[i], &ret); |
| 125 SkASSERT(0 == status); | 125 SkASSERT(0 == status); |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 protected: | 129 protected: |
| 130 // overrides from SkEventSink | 130 // overrides from SkEventSink |
| 131 virtual bool onQuery(SkEvent* evt) { | 131 virtual bool onQuery(SkEvent* evt) { |
| 132 if (SampleCode::TitleQ(*evt)) { | 132 if (SampleCode::TitleQ(*evt)) { |
| 133 SampleCode::TitleR(evt, "PageFlip"); | 133 SampleCode::TitleR(evt, "PageFlip"); |
| 134 return true; | 134 return true; |
| 135 } | 135 } |
| 136 return this->INHERITED::onQuery(evt); | 136 return this->INHERITED::onQuery(evt); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void drawBG(SkCanvas* canvas) { | 139 void drawBG(SkCanvas* canvas) { |
| 140 canvas->drawColor(0xFFDDDDDD); | 140 canvas->drawColor(0xFFDDDDDD); |
| 141 // canvas->drawColor(SK_ColorWHITE); | 141 // canvas->drawColor(SK_ColorWHITE); |
| 142 } | 142 } |
| 143 | 143 |
| 144 virtual void onDraw(SkCanvas* canvas) { | 144 virtual void onDraw(SkCanvas* canvas) { |
| 145 this->drawBG(canvas); | 145 this->drawBG(canvas); |
| 146 | 146 |
| 147 SkScalar x = SkIntToScalar(10); | 147 SkScalar x = SkIntToScalar(10); |
| 148 SkScalar y = SkIntToScalar(10); | 148 SkScalar y = SkIntToScalar(10); |
| 149 for (int i = 0; i < N; i++) { | 149 for (int i = 0; i < N; i++) { |
| 150 canvas->drawBitmap(fBitmaps[i], x, y); | 150 canvas->drawBitmap(fBitmaps[i], x, y); |
| 151 x += SkIntToScalar(fBitmaps[i].width() + 20); | 151 x += SkIntToScalar(fBitmaps[i].width() + 20); |
| 152 } | 152 } |
| 153 this->inval(NULL); | 153 this->inval(NULL); |
| 154 } | 154 } |
| 155 | 155 |
| 156 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) { | 156 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) { |
| 157 this->inval(NULL); | 157 this->inval(NULL); |
| 158 return this->INHERITED::onFindClickHandler(x, y); | 158 return this->INHERITED::onFindClickHandler(x, y); |
| 159 } | 159 } |
| 160 | 160 |
| 161 virtual bool onClick(Click* click) { | 161 virtual bool onClick(Click* click) { |
| 162 return this->INHERITED::onClick(click); | 162 return this->INHERITED::onClick(click); |
| 163 } | 163 } |
| 164 | 164 |
| 165 private: | 165 private: |
| 166 typedef SkView INHERITED; | 166 typedef SkView INHERITED; |
| 167 }; | 167 }; |
| 168 | 168 |
| 169 ////////////////////////////////////////////////////////////////////////////// | 169 ////////////////////////////////////////////////////////////////////////////// |
| 170 | 170 |
| 171 static SkView* MyFactory() { return new PageFlipView; } | 171 static SkView* MyFactory() { return new PageFlipView; } |
| 172 static SkViewRegister reg(MyFactory); | 172 static SkViewRegister reg(MyFactory); |
| 173 | 173 |
| OLD | NEW |