Use dali-adaptor api to read files from inside apk 75/245775/4
authorCheng-Shiun Tsai <cheng.tsai@samsung.com>
Thu, 15 Oct 2020 13:23:03 +0000 (14:23 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Sat, 17 Oct 2020 11:42:19 +0000 (12:42 +0100)
Android asset files are not extracted to file system directly,
cannot use fopen, but need to use asset specific api to read,
which is wrapped by dali-adaptor api.

Change-Id: If775e04e4e2d562755bce3eeb9f79fa279e5da70

examples/rendering-basic-pbr/ktx-loader.cpp

index 5b34fda..bdd45e9 100644 (file)
@@ -93,26 +93,22 @@ bool ConvertPixelFormat(const uint32_t ktxPixelFormat, Dali::Pixel::Format& form
 
 bool LoadCubeMapFromKtxFile(const std::string& path, CubeData& cubedata)
 {
-  std::unique_ptr<FILE, void (*)(FILE*)> fp(fopen(path.c_str(), "rb"), [](FILE* fp) {
-    if(fp)
-    {
-      fclose(fp);
-    }
-  });
+  Dali::FileStream daliFileStream(path);
+  FILE* fp(daliFileStream.GetFile());
   if(!fp)
   {
     return false;
   }
 
   KtxFileHeader header;
-  int           result = fread(&header, sizeof(KtxFileHeader), 1u, fp.get());
+  int           result = fread(&header, sizeof(KtxFileHeader), 1u, fp);
   if(0 == result)
   {
     return false;
   }
 
   // Skip the key-values:
-  if(fseek(fp.get(), header.bytesOfKeyValueData, SEEK_CUR))
+  if(fseek(fp, header.bytesOfKeyValueData, SEEK_CUR))
   {
     return false;
   }
@@ -151,7 +147,7 @@ bool LoadCubeMapFromKtxFile(const std::string& path, CubeData& cubedata)
   for(unsigned int mipmapLevel = 0; mipmapLevel < header.numberOfMipmapLevels; ++mipmapLevel)
   {
     uint32_t byteSize = 0;
-    if(fread(&byteSize, sizeof(byteSize), 1u, fp.get()) != 1)
+    if(fread(&byteSize, sizeof(byteSize), 1u, fp) != 1)
     {
       return false;
     }
@@ -166,7 +162,7 @@ bool LoadCubeMapFromKtxFile(const std::string& path, CubeData& cubedata)
       for(unsigned int face = 0; face < header.numberOfFaces; ++face)
       {
         std::unique_ptr<uint8_t, void (*)(void*)> img(static_cast<unsigned char*>(malloc(byteSize)), free); // resources will be freed when the PixelData is destroyed.
-        if(fread(img.get(), byteSize, 1u, fp.get()) != 1)
+        if(fread(img.get(), byteSize, 1u, fp) != 1)
         {
           return false;
         }