=== modified file 'src/android.cpp'
@@ -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'
@@ -27,7 +27,6 @@
#include "options.h"
#include "util.h"
#include "float.h"
-#include <dirent.h>
#include <fstream>
#include <sstream>
#include <memory>
@@ -603,34 +602,7 @@
namespace ModelPrivate
{
-
-void
-list_files(const string& dirName, vector<string>& 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<string> 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'
@@ -25,6 +25,8 @@
#include <fstream>
#ifdef ANDROID
#include <android/asset_manager.h>
+#else
+#include <dirent.h>
#endif
#include "log.h"
@@ -57,6 +59,31 @@
return static_cast<std::istream *>(ifs);
}
+void
+Util::list_files(const std::string& dirName, std::vector<std::string>& 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<std::istream *>(ss);
}
+
+void
+Util::list_files(const std::string& dirName, std::vector<std::string>& 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'
@@ -35,6 +35,7 @@
struct Util {
static void split(const std::string &s, char delim, std::vector<std::string> &elems);
static std::istream *get_resource(const std::string &path);
+ static void list_files(const std::string& dirName, std::vector<std::string>& fileVec);
template <class T> static void dispose_pointer_vector(std::vector<T*> &vec)
{
for (typename std::vector<T*>::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