From patchwork Thu Oct 13 14:05:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexandros.frantzis@linaro.org X-Patchwork-Id: 4659 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id D5A4D23FB1 for ; Thu, 13 Oct 2011 14:13:31 +0000 (UTC) Received: from mail-gy0-f180.google.com (mail-gy0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id 8F54AA1855B for ; Thu, 13 Oct 2011 14:13:31 +0000 (UTC) Received: by gyf1 with SMTP id 1so67326gyf.11 for ; Thu, 13 Oct 2011 07:13:31 -0700 (PDT) Received: by 10.223.92.144 with SMTP id r16mr6367823fam.23.1318515210813; Thu, 13 Oct 2011 07:13:30 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.24.41 with SMTP id r9cs262256laf; Thu, 13 Oct 2011 07:13:30 -0700 (PDT) Received: by 10.213.32.10 with SMTP id a10mr1400387ebd.76.1318515207354; Thu, 13 Oct 2011 07:13:27 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id t9si4601001weq.104.2011.10.13.07.13.27 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 13 Oct 2011 07:13:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1REM2I-0006Wa-HD for ; Thu, 13 Oct 2011 14:13:26 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 91904E24EB for ; Thu, 13 Oct 2011 14:05:20 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: glmark2 X-Launchpad-Branch: ~glmark2-dev/glmark2/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 154 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 154: Android, Model: Fix model listing and discovery on Android. Message-Id: <20111013140520.8587.15248.launchpad@ackee.canonical.com> Date: Thu, 13 Oct 2011 14:05:20 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="14124"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: 17fdf8640908303dcaf4714328d1b6b31c2468c9 Merge authors: Alexandros Frantzis (afrantzis) ------------------------------------------------------------ revno: 154 [merge] committer: Alexandros Frantzis branch nick: trunk timestamp: Thu 2011-10-13 17:00:10 +0300 message: Android,Model: Fix model listing and discovery on Android. modified: src/android.cpp src/model.cpp src/util.cpp src/util.h --- lp:glmark2 https://code.launchpad.net/~glmark2-dev/glmark2/trunk You are subscribed to branch lp:glmark2. To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription === modified file 'src/android.cpp' --- src/android.cpp 2011-10-10 16:10:04 +0000 +++ src/android.cpp 2011-10-13 13:44:52 +0000 @@ -73,6 +73,8 @@ Java_org_linaro_glmark2_Glmark2Renderer_nativeInit(JNIEnv* env, jclass clazz, jobject asset_manager) { + Util::android_set_asset_manager(AAssetManager_fromJava(env, asset_manager)); + g_canvas = new CanvasAndroid(100, 100); g_canvas->init(); @@ -93,8 +95,6 @@ Benchmark::register_scene(*new SceneBuffer(*g_canvas)); add_default_benchmarks(g_benchmarks); - - Util::android_set_asset_manager(AAssetManager_fromJava(env, asset_manager)); } void === modified file 'src/model.cpp' --- src/model.cpp 2011-10-07 18:19:11 +0000 +++ src/model.cpp 2011-10-13 13:56:26 +0000 @@ -27,7 +27,6 @@ #include "options.h" #include "util.h" #include "float.h" -#include #include #include #include @@ -603,34 +602,7 @@ namespace ModelPrivate { - -void -list_files(const string& dirName, vector& fileVec) -{ - DIR* dir = opendir(dirName.c_str()); - if (!dir) - { - Log::error("Failed to open models directory '%s'\n", dirName.c_str()); - return; - } - - struct dirent* entry = readdir(dir); - while (entry) - { - string pathname(dirName + "/"); - pathname += string(entry->d_name); - // Skip '.' and '..' - if (entry->d_name[0] != '.') - { - fileVec.push_back(pathname); - } - entry = readdir(dir); - } - closedir(dir); -} - ModelMap modelMap; - } const ModelMap& @@ -642,10 +614,10 @@ } vector pathVec; string dataDir(GLMARK_DATA_PATH"/models"); - ModelPrivate::list_files(dataDir, pathVec); + Util::list_files(dataDir, pathVec); #ifdef GLMARK_EXTRAS_PATH string extrasDir(GLMARK_EXTRAS_PATH"/models"); - ModelPrivate::list_files(extrasDir, pathVec); + Util::list_files(extrasDir, pathVec); #endif // Now that we have a list of all of the model files available to us, === modified file 'src/util.cpp' --- src/util.cpp 2011-08-10 17:58:47 +0000 +++ src/util.cpp 2011-10-13 13:56:26 +0000 @@ -25,6 +25,8 @@ #include #ifdef ANDROID #include +#else +#include #endif #include "log.h" @@ -57,6 +59,31 @@ return static_cast(ifs); } +void +Util::list_files(const std::string& dirName, std::vector& fileVec) +{ + DIR* dir = opendir(dirName.c_str()); + if (!dir) + { + Log::error("Failed to open models directory '%s'\n", dirName.c_str()); + return; + } + + struct dirent* entry = readdir(dir); + while (entry) + { + std::string pathname(dirName + "/"); + pathname += std::string(entry->d_name); + // Skip '.' and '..' + if (entry->d_name[0] != '.') + { + fileVec.push_back(pathname); + } + entry = readdir(dir); + } + closedir(dir); +} + #else AAssetManager *Util::android_asset_manager = 0; @@ -67,12 +94,19 @@ Util::android_asset_manager = asset_manager; } +AAssetManager * +Util::android_get_asset_manager() +{ + return Util::android_asset_manager; +} + std::istream * Util::get_resource(const std::string &path) { std::string path2(path); - /* Remove leading '/' */ - path2.erase(0, 1); + /* Remove leading '/' from path name, it confuses the AssetManager */ + if (path2.size() > 0 && path2[0] == '/') + path2.erase(0, 1); std::stringstream *ss = new std::stringstream; AAsset *asset = AAssetManager_open(Util::android_asset_manager, @@ -89,4 +123,31 @@ return static_cast(ss); } + +void +Util::list_files(const std::string& dirName, std::vector& fileVec) +{ + AAssetManager *mgr(Util::android_get_asset_manager()); + std::string dir_name(dirName); + + /* Remove leading '/' from path, it confuses the AssetManager */ + if (dir_name.size() > 0 && dir_name[0] == '/') + dir_name.erase(0, 1); + + AAssetDir* dir = AAssetManager_openDir(mgr, dir_name.c_str()); + if (!dir) + { + Log::error("Failed to open models directory '%s'\n", dir_name.c_str()); + return; + } + + const char *filename(0); + while ((filename = AAssetDir_getNextFileName(dir)) != 0) + { + std::string pathname(dir_name + "/"); + pathname += std::string(filename); + fileVec.push_back(pathname); + } + AAssetDir_close(dir); +} #endif === modified file 'src/util.h' --- src/util.h 2011-09-07 09:40:57 +0000 +++ src/util.h 2011-10-13 13:56:26 +0000 @@ -35,6 +35,7 @@ struct Util { static void split(const std::string &s, char delim, std::vector &elems); static std::istream *get_resource(const std::string &path); + static void list_files(const std::string& dirName, std::vector& fileVec); template static void dispose_pointer_vector(std::vector &vec) { for (typename std::vector::const_iterator iter = vec.begin(); @@ -49,6 +50,7 @@ #ifdef ANDROID static void android_set_asset_manager(AAssetManager *asset_manager); + static AAssetManager *android_get_asset_manager(void); private: static AAssetManager *android_asset_manager; #endif