OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 y += m.fDescent - m.fAscent; | 56 y += m.fDescent - m.fAscent; |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 static bool gDone; | 60 static bool gDone; |
61 | 61 |
62 static void* measure_proc(void* context) { | 62 static void* measure_proc(void* context) { |
63 while (!gDone) { | 63 while (!gDone) { |
64 call_measure(); | 64 call_measure(); |
65 } | 65 } |
66 return NULL; | 66 return nullptr; |
67 } | 67 } |
68 | 68 |
69 static void* draw_proc(void* context) { | 69 static void* draw_proc(void* context) { |
70 SkBitmap* bm = (SkBitmap*)context; | 70 SkBitmap* bm = (SkBitmap*)context; |
71 SkCanvas canvas(*bm); | 71 SkCanvas canvas(*bm); |
72 | 72 |
73 while (!gDone) { | 73 while (!gDone) { |
74 call_draw(&canvas); | 74 call_draw(&canvas); |
75 } | 75 } |
76 return NULL; | 76 return nullptr; |
77 } | 77 } |
78 | 78 |
79 class FontCacheView : public SampleView { | 79 class FontCacheView : public SampleView { |
80 public: | 80 public: |
81 enum { N = 4 }; | 81 enum { N = 4 }; |
82 | 82 |
83 pthread_t fMThreads[N]; | 83 pthread_t fMThreads[N]; |
84 pthread_t fDThreads[N]; | 84 pthread_t fDThreads[N]; |
85 SkBitmap fBitmaps[N]; | 85 SkBitmap fBitmaps[N]; |
86 | 86 |
87 FontCacheView() { | 87 FontCacheView() { |
88 gDone = false; | 88 gDone = false; |
89 for (int i = 0; i < N; i++) { | 89 for (int i = 0; i < N; i++) { |
90 int status; | 90 int status; |
91 | 91 |
92 status = pthread_create(&fMThreads[i], NULL, measure_proc, NULL); | 92 status = pthread_create(&fMThreads[i], nullptr, measure_proc, nullp
tr); |
93 SkASSERT(0 == status); | 93 SkASSERT(0 == status); |
94 | 94 |
95 fBitmaps[i].allocPixels(SkImageInfo::Make(320, 240, | 95 fBitmaps[i].allocPixels(SkImageInfo::Make(320, 240, |
96 kRGB_565_SkColorType, | 96 kRGB_565_SkColorType, |
97 kOpaque_SkAlphaType)); | 97 kOpaque_SkAlphaType)); |
98 status = pthread_create(&fDThreads[i], NULL, draw_proc, &fBitmaps[i
]); | 98 status = pthread_create(&fDThreads[i], nullptr, draw_proc, &fBitmap
s[i]); |
99 SkASSERT(0 == status); | 99 SkASSERT(0 == status); |
100 } | 100 } |
101 this->setBGColor(0xFFDDDDDD); | 101 this->setBGColor(0xFFDDDDDD); |
102 } | 102 } |
103 | 103 |
104 virtual ~FontCacheView() { | 104 virtual ~FontCacheView() { |
105 gDone = true; | 105 gDone = true; |
106 for (int i = 0; i < N; i++) { | 106 for (int i = 0; i < N; i++) { |
107 void* ret; | 107 void* ret; |
108 int status = pthread_join(fMThreads[i], &ret); | 108 int status = pthread_join(fMThreads[i], &ret); |
(...skipping 13 matching lines...) Expand all Loading... |
122 return this->INHERITED::onQuery(evt); | 122 return this->INHERITED::onQuery(evt); |
123 } | 123 } |
124 | 124 |
125 virtual void onDrawContent(SkCanvas* canvas) { | 125 virtual void onDrawContent(SkCanvas* canvas) { |
126 SkScalar x = 0; | 126 SkScalar x = 0; |
127 SkScalar y = 0; | 127 SkScalar y = 0; |
128 for (int i = 0; i < N; i++) { | 128 for (int i = 0; i < N; i++) { |
129 canvas->drawBitmap(fBitmaps[i], x, y); | 129 canvas->drawBitmap(fBitmaps[i], x, y); |
130 x += SkIntToScalar(fBitmaps[i].width()); | 130 x += SkIntToScalar(fBitmaps[i].width()); |
131 } | 131 } |
132 this->inval(NULL); | 132 this->inval(nullptr); |
133 } | 133 } |
134 | 134 |
135 private: | 135 private: |
136 typedef SampleView INHERITED; | 136 typedef SampleView INHERITED; |
137 }; | 137 }; |
138 | 138 |
139 ////////////////////////////////////////////////////////////////////////////// | 139 ////////////////////////////////////////////////////////////////////////////// |
140 | 140 |
141 static SkView* MyFactory() { return new FontCacheView; } | 141 static SkView* MyFactory() { return new FontCacheView; } |
142 static SkViewRegister reg(MyFactory); | 142 static SkViewRegister reg(MyFactory); |
OLD | NEW |