diff options
author | 2011-06-06 17:00:35 -0700 | |
---|---|---|
committer | 2011-07-20 15:20:26 -0700 | |
commit | 8a39da80b33691b0c82458c3b7727e13ff71277e (patch) | |
tree | b6fa94370ecb2dba85d5fdb45c83729cef8708e1 /tools/aapt/Resource.cpp | |
parent | 1e24ccbdd56a45c8bb5f2eba94af5aecd2d02554 (diff) |
Added Caching for PreProcessed PNGs
Added a cache management system for pre-processed PNG files
along with unit tests. The cache system will be used if
the --no-crunch flag is passed to AAPT during the package
phase. The cache can be updated by a call to 'aapt crunch'
(see usage statement). Also put in benchmarking code.
Change-Id: I58271fb2ee2f5f9075fd74d4ff6f15e7afabd05c
Diffstat (limited to 'tools/aapt/Resource.cpp')
-rw-r--r-- | tools/aapt/Resource.cpp | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/tools/aapt/Resource.cpp b/tools/aapt/Resource.cpp index 6e86112a3756..5152d3b5ed3f 100644 --- a/tools/aapt/Resource.cpp +++ b/tools/aapt/Resource.cpp @@ -10,6 +10,10 @@ #include "ResourceTable.h" #include "Images.h" +#include "CrunchCache.h" +#include "FileFinder.h" +#include "CacheUpdater.h" + #define NOISY(x) // x // ========================================================================== @@ -292,18 +296,19 @@ static status_t makeFileResources(Bundle* bundle, const sp<AaptAssets>& assets, static status_t preProcessImages(Bundle* bundle, const sp<AaptAssets>& assets, const sp<ResourceTypeSet>& set) { - ResourceDirIterator it(set, String8("drawable")); - Vector<sp<AaptFile> > newNameFiles; - Vector<String8> newNamePaths; bool hasErrors = false; - ssize_t res; - while ((res=it.next()) == NO_ERROR) { - res = preProcessImage(bundle, assets, it.getFile(), NULL); - if (res < NO_ERROR) { - hasErrors = true; + ssize_t res = NO_ERROR; + if (bundle->getUseCrunchCache() == false) { + ResourceDirIterator it(set, String8("drawable")); + Vector<sp<AaptFile> > newNameFiles; + Vector<String8> newNamePaths; + while ((res=it.next()) == NO_ERROR) { + res = preProcessImage(bundle, assets, it.getFile(), NULL); + if (res < NO_ERROR) { + hasErrors = true; + } } } - return (hasErrors || (res < NO_ERROR)) ? UNKNOWN_ERROR : NO_ERROR; } @@ -753,6 +758,35 @@ status_t massageManifest(Bundle* bundle, sp<XMLNode> root) } \ } while (0) +status_t updatePreProcessedCache(Bundle* bundle) +{ + #if BENCHMARK + fprintf(stdout, "BENCHMARK: Starting PNG PreProcessing \n"); + long startPNGTime = clock(); + #endif /* BENCHMARK */ + + String8 source(bundle->getResourceSourceDirs()[0]); + String8 dest(bundle->getCrunchedOutputDir()); + + FileFinder* ff = new SystemFileFinder(); + CrunchCache cc(source,dest,ff); + + CacheUpdater* cu = new SystemCacheUpdater(bundle); + size_t numFiles = cc.crunch(cu); + + if (bundle->getVerbose()) + fprintf(stdout, "Crunched %d PNG files to update cache\n", (int)numFiles); + + delete ff; + delete cu; + + #if BENCHMARK + fprintf(stdout, "BENCHMARK: End PNG PreProcessing. Time Elapsed: %f ms \n" + ,(clock() - startPNGTime)/1000.0); + #endif /* BENCHMARK */ + return 0; +} + status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets) { // First, look for a package file to parse. This is required to |