|
14 | 14 | #include "FileFinder.h" |
15 | 15 | #include "CacheUpdater.h" |
16 | 16 |
|
| 17 | +#include <utils/WorkQueue.h> |
| 18 | + |
17 | 19 | #if HAVE_PRINTF_ZD |
18 | 20 | # define ZD "%zd" |
19 | 21 | # define ZD_TYPE ssize_t |
|
24 | 26 |
|
25 | 27 | #define NOISY(x) // x |
26 | 28 |
|
| 29 | +// Number of threads to use for preprocessing images. |
| 30 | +static const size_t MAX_THREADS = 4; |
| 31 | + |
27 | 32 | // ========================================================================== |
28 | 33 | // ========================================================================== |
29 | 34 | // ========================================================================== |
@@ -302,21 +307,52 @@ static status_t makeFileResources(Bundle* bundle, const sp<AaptAssets>& assets, |
302 | 307 | return hasErrors ? UNKNOWN_ERROR : NO_ERROR; |
303 | 308 | } |
304 | 309 |
|
305 | | -static status_t preProcessImages(Bundle* bundle, const sp<AaptAssets>& assets, |
| 310 | +class PreProcessImageWorkUnit : public WorkQueue::WorkUnit { |
| 311 | +public: |
| 312 | + PreProcessImageWorkUnit(const Bundle* bundle, const sp<AaptAssets>& assets, |
| 313 | + const sp<AaptFile>& file, volatile bool* hasErrors) : |
| 314 | + mBundle(bundle), mAssets(assets), mFile(file), mHasErrors(hasErrors) { |
| 315 | + } |
| 316 | + |
| 317 | + virtual bool run() { |
| 318 | + status_t status = preProcessImage(mBundle, mAssets, mFile, NULL); |
| 319 | + if (status) { |
| 320 | + *mHasErrors = true; |
| 321 | + } |
| 322 | + return true; // continue even if there are errors |
| 323 | + } |
| 324 | + |
| 325 | +private: |
| 326 | + const Bundle* mBundle; |
| 327 | + sp<AaptAssets> mAssets; |
| 328 | + sp<AaptFile> mFile; |
| 329 | + volatile bool* mHasErrors; |
| 330 | +}; |
| 331 | + |
| 332 | +static status_t preProcessImages(const Bundle* bundle, const sp<AaptAssets>& assets, |
306 | 333 | const sp<ResourceTypeSet>& set, const char* type) |
307 | 334 | { |
308 | | - bool hasErrors = false; |
| 335 | + volatile bool hasErrors = false; |
309 | 336 | ssize_t res = NO_ERROR; |
310 | 337 | if (bundle->getUseCrunchCache() == false) { |
| 338 | + WorkQueue wq(MAX_THREADS, false); |
311 | 339 | ResourceDirIterator it(set, String8(type)); |
312 | | - Vector<sp<AaptFile> > newNameFiles; |
313 | | - Vector<String8> newNamePaths; |
314 | 340 | while ((res=it.next()) == NO_ERROR) { |
315 | | - res = preProcessImage(bundle, assets, it.getFile(), NULL); |
316 | | - if (res < NO_ERROR) { |
| 341 | + PreProcessImageWorkUnit* w = new PreProcessImageWorkUnit( |
| 342 | + bundle, assets, it.getFile(), &hasErrors); |
| 343 | + status_t status = wq.schedule(w); |
| 344 | + if (status) { |
| 345 | + fprintf(stderr, "preProcessImages failed: schedule() returned %d\n", status); |
317 | 346 | hasErrors = true; |
| 347 | + delete w; |
| 348 | + break; |
318 | 349 | } |
319 | 350 | } |
| 351 | + status_t status = wq.finish(); |
| 352 | + if (status) { |
| 353 | + fprintf(stderr, "preProcessImages failed: finish() returned %d\n", status); |
| 354 | + hasErrors = true; |
| 355 | + } |
320 | 356 | } |
321 | 357 | return (hasErrors || (res < NO_ERROR)) ? UNKNOWN_ERROR : NO_ERROR; |
322 | 358 | } |
|
0 commit comments