From 460ed1b2ca88533065cacf04126c5813a21f5c29 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Mon, 22 Nov 2010 22:28:37 -0800 Subject: [PATCH] Add knowledge of mipmap to aapt New mipmap drawable type that does not get filtered according to configuration. Useful for things that get built as part of the system. Change-Id: I556033d065e504079271dce79c23c90d3c387ce4 --- Package.cpp | 29 ++++++++++++++++++++--------- Resource.cpp | 27 ++++++++++++++++++++++----- ResourceTable.cpp | 23 +++++++++++++++-------- ResourceTable.h | 6 +++--- 4 files changed, 60 insertions(+), 25 deletions(-) diff --git a/Package.cpp b/Package.cpp index 3cb614f..faae89b 100644 --- a/Package.cpp +++ b/Package.cpp @@ -33,8 +33,8 @@ static const char* kNoCompressExt[] = { /* fwd decls, so I can write this downward */ ssize_t processAssets(Bundle* bundle, ZipFile* zip, const sp& assets); -ssize_t processAssets(Bundle* bundle, ZipFile* zip, - const sp& dir, const AaptGroupEntry& ge); +ssize_t processAssets(Bundle* bundle, ZipFile* zip, const sp& dir, + const AaptGroupEntry& ge, const ResourceFilter* filter); bool processFile(Bundle* bundle, ZipFile* zip, const sp& group, const sp& file); bool okayToCompress(Bundle* bundle, const String8& pathName); @@ -204,34 +204,45 @@ ssize_t processAssets(Bundle* bundle, ZipFile* zip, const size_t N = assets->getGroupEntries().size(); for (size_t i=0; igetGroupEntries()[i]; - if (!filter.match(ge.toParams())) { - continue; - } - ssize_t res = processAssets(bundle, zip, assets, ge); + + ssize_t res = processAssets(bundle, zip, assets, ge, &filter); if (res < 0) { return res; } + count += res; } return count; } -ssize_t processAssets(Bundle* bundle, ZipFile* zip, - const sp& dir, const AaptGroupEntry& ge) +ssize_t processAssets(Bundle* bundle, ZipFile* zip, const sp& dir, + const AaptGroupEntry& ge, const ResourceFilter* filter) { ssize_t count = 0; const size_t ND = dir->getDirs().size(); size_t i; for (i=0; igetDirs().valueAt(i), ge); + const sp& subDir = dir->getDirs().valueAt(i); + + const bool filterable = filter != NULL && subDir->getLeaf().find("mipmap-") != 0; + + if (filterable && subDir->getLeaf() != subDir->getPath() && !filter->match(ge.toParams())) { + continue; + } + + ssize_t res = processAssets(bundle, zip, subDir, ge, filterable ? filter : NULL); if (res < 0) { return res; } count += res; } + if (filter != NULL && !filter->match(ge.toParams())) { + return count; + } + const size_t NF = dir->getFiles().size(); for (i=0; i gp = dir->getFiles().valueAt(i); diff --git a/Resource.cpp b/Resource.cpp index 822262e..7b74506 100644 --- a/Resource.cpp +++ b/Resource.cpp @@ -150,7 +150,7 @@ bool isValidResourceType(const String8& type) { return type == "anim" || type == "drawable" || type == "layout" || type == "values" || type == "xml" || type == "raw" - || type == "color" || type == "menu"; + || type == "color" || type == "menu" || type == "mipmap"; } static sp getResourceFile(const sp& assets, bool makeIfNecessary=true) @@ -284,9 +284,9 @@ static status_t makeFileResources(Bundle* bundle, const sp& assets, } static status_t preProcessImages(Bundle* bundle, const sp& assets, - const sp& set) + const sp& set, const char* type) { - ResourceDirIterator it(set, String8("drawable")); + ResourceDirIterator it(set, String8(type)); Vector > newNameFiles; Vector newNamePaths; bool hasErrors = false; @@ -802,6 +802,7 @@ status_t buildResources(Bundle* bundle, const sp& assets) sp raws; sp colors; sp menus; + sp mipmaps; ASSIGN_IT(drawable); ASSIGN_IT(layout); @@ -810,6 +811,7 @@ status_t buildResources(Bundle* bundle, const sp& assets) ASSIGN_IT(raw); ASSIGN_IT(color); ASSIGN_IT(menu); + ASSIGN_IT(mipmap); assets->setResources(resources); // now go through any resource overlays and collect their files @@ -828,7 +830,8 @@ status_t buildResources(Bundle* bundle, const sp& assets) !applyFileOverlay(bundle, assets, &xmls, "xml") || !applyFileOverlay(bundle, assets, &raws, "raw") || !applyFileOverlay(bundle, assets, &colors, "color") || - !applyFileOverlay(bundle, assets, &menus, "menu")) { + !applyFileOverlay(bundle, assets, &menus, "menu") || + !applyFileOverlay(bundle, assets, &mipmaps, "mipmap")) { return UNKNOWN_ERROR; } @@ -836,7 +839,7 @@ status_t buildResources(Bundle* bundle, const sp& assets) if (drawables != NULL) { if (bundle->getOutputAPKFile() != NULL) { - err = preProcessImages(bundle, assets, drawables); + err = preProcessImages(bundle, assets, drawables, "drawable"); } if (err == NO_ERROR) { err = makeFileResources(bundle, assets, &table, drawables, "drawable"); @@ -848,6 +851,20 @@ status_t buildResources(Bundle* bundle, const sp& assets) } } + if (mipmaps != NULL) { + if (bundle->getOutputAPKFile() != NULL) { + err = preProcessImages(bundle, assets, mipmaps, "mipmap"); + } + if (err == NO_ERROR) { + err = makeFileResources(bundle, assets, &table, mipmaps, "mipmap"); + if (err != NO_ERROR) { + hasErrors = true; + } + } else { + hasErrors = true; + } + } + if (layouts != NULL) { err = makeFileResources(bundle, assets, &table, layouts, "layout"); if (err != NO_ERROR) { diff --git a/ResourceTable.cpp b/ResourceTable.cpp index a77042a..196b06c 100644 --- a/ResourceTable.cpp +++ b/ResourceTable.cpp @@ -2539,7 +2539,7 @@ ResourceFilter::parse(const char* arg) } bool -ResourceFilter::match(int axis, uint32_t value) +ResourceFilter::match(int axis, uint32_t value) const { if (value == 0) { // they didn't specify anything so take everything @@ -2555,7 +2555,7 @@ ResourceFilter::match(int axis, uint32_t value) } bool -ResourceFilter::match(const ResTable_config& config) +ResourceFilter::match(const ResTable_config& config) const { if (config.locale) { uint32_t locale = (config.country[1] << 24) | (config.country[0] << 16) @@ -2608,6 +2608,8 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp& dest) const size_t N = mOrderedPackages.size(); size_t pi; + const static String16 mipmap16("mipmap"); + bool useUTF8 = !bundle->getWantUTF16() && bundle->isMinSdkAtLeast(SDK_FROYO); // Iterate through all data, collecting all values (strings, @@ -2630,7 +2632,10 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp& dest) typeStrings.add(String16(""), false); continue; } - typeStrings.add(t->getName(), false); + const String16 typeName(t->getName()); + typeStrings.add(typeName, false); + + const bool filterable = (typeName != mipmap16); const size_t N = t->getOrderedConfigs().size(); for (size_t ci=0; ci& dest) const size_t N = c->getEntries().size(); for (size_t ei=0; eigetEntries().keyAt(ei); - if (!filter.match(config)) { + if (filterable && !filter.match(config)) { continue; } sp e = c->getEntries().valueAt(ei); @@ -2721,6 +2726,8 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp& dest) "Type name %s not found", String8(typeName).string()); + const bool filterable = (typeName != mipmap16); + const size_t N = t != NULL ? t->getOrderedConfigs().size() : 0; // First write the typeSpec chunk, containing information about @@ -2745,7 +2752,7 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp& dest) (((uint8_t*)data->editData()) + typeSpecStart + sizeof(ResTable_typeSpec)); memset(typeSpecFlags, 0, sizeof(uint32_t)*N); - + for (size_t ei=0; ei cl = t->getOrderedConfigs().itemAt(ei); if (cl->getPublic()) { @@ -2753,11 +2760,11 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp& dest) } const size_t CN = cl->getEntries().size(); for (size_t ci=0; cigetEntries().keyAt(ci))) { + if (filterable && !filter.match(cl->getEntries().keyAt(ci))) { continue; } for (size_t cj=ci+1; cjgetEntries().keyAt(cj))) { + if (filterable && !filter.match(cl->getEntries().keyAt(cj))) { continue; } typeSpecFlags[ei] |= htodl( @@ -2794,7 +2801,7 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp& dest) config.screenWidth, config.screenHeight)); - if (!filter.match(config)) { + if (filterable && !filter.match(config)) { continue; } diff --git a/ResourceTable.h b/ResourceTable.h index 186c7ca..bbb8140 100644 --- a/ResourceTable.h +++ b/ResourceTable.h @@ -549,9 +549,9 @@ class ResourceFilter public: ResourceFilter() : mData(), mContainsPseudo(false) {} status_t parse(const char* arg); - bool match(int axis, uint32_t value); - bool match(const ResTable_config& config); - inline bool containsPseudo() { return mContainsPseudo; } + bool match(int axis, uint32_t value) const; + bool match(const ResTable_config& config) const; + inline bool containsPseudo() const { return mContainsPseudo; } private: KeyedVector > mData; -- 2.45.2