Commit 3a3e8aa1e057bb6efb73368d390f394bf2e5e278

Authored by Adeel Kazmi
Committed by Gerrit Code Review
2 parents 801203c5 3ed8a2ec

Merge "Use FileStream API in demo." into devel/master

examples/fpp-game/game-utils.cpp
... ... @@ -18,7 +18,7 @@
18 18 #include <inttypes.h>
19 19 #include <stdio.h>
20 20 #include <dali/integration-api/debug.h>
21   -#include <dali/devel-api/adaptor-framework/file-loader.h>
  21 +#include <dali/devel-api/adaptor-framework/file-stream.h>
22 22  
23 23 #include "game-utils.h"
24 24  
... ... @@ -26,32 +26,25 @@ namespace GameUtils
26 26 {
27 27 bool LoadFile( const char* filename, ByteArray& bytes )
28 28 {
29   - std::streampos bufferSize = 0;
30   - Dali::Vector<char> fileBuffer;
31   - if( !Dali::FileLoader::ReadFile( filename, bufferSize, fileBuffer, Dali::FileLoader::FileType::BINARY ) )
32   - {
33   - return false;
34   - }
  29 + Dali::FileStream fileStream( filename, Dali::FileStream::READ | Dali::FileStream::BINARY );
  30 + FILE* fin = fileStream.GetFile();
35 31  
36   - FILE* fin = fmemopen( &fileBuffer[0], bufferSize, "rb" );
37 32 if( fin )
38 33 {
39 34 if( fseek( fin, 0, SEEK_END ) )
40 35 {
41   - fclose(fin);
42 36 return false;
43 37 }
44 38 bytes.resize( ftell( fin ) );
45 39 std::fill( bytes.begin(), bytes.end(), 0 );
46 40 if( fseek( fin, 0, SEEK_SET ) )
47 41 {
48   - fclose( fin );
49 42 return false;
50 43 }
51 44 size_t result = fread( bytes.data(), 1, bytes.size(), fin );
52   - fclose( fin );
53 45 return ( result != 0 );
54 46 }
  47 +
55 48 return false;
56 49 }
57 50  
... ...
examples/ray-marching/ray-marching-example.cpp
... ... @@ -21,7 +21,7 @@
21 21 #include "shared/utility.h"
22 22 #include <stdio.h>
23 23 #include <dali/integration-api/debug.h>
24   -#include <dali/devel-api/adaptor-framework/file-loader.h>
  24 +#include <dali/devel-api/adaptor-framework/file-stream.h>
25 25  
26 26 using namespace Dali;
27 27 using Dali::Toolkit::TextLabel;
... ... @@ -44,17 +44,15 @@ bool LoadShaderCode( const char* path, const char* filename, std::vector&lt;char&gt;&amp;
44 44 std::string fullpath( path );
45 45 fullpath += filename;
46 46  
47   - std::streampos bufferSize = 0;
48   - Dali::Vector<char> fileBuffer;
49   - if( !Dali::FileLoader::ReadFile( fullpath, bufferSize, fileBuffer, Dali::FileLoader::FileType::BINARY ) )
  47 + Dali::FileStream fileStream( fullpath, Dali::FileStream::READ | Dali::FileStream::BINARY );
  48 + FILE* file = fileStream.GetFile();
  49 + if( !file )
50 50 {
51 51 return false;
52 52 }
53 53  
54   - FILE* file = fmemopen( &fileBuffer[0], bufferSize, "rb" );
55   -
56 54 bool retValue = false;
57   - if( ! fseek( file, 0, SEEK_END ) )
  55 + if( !fseek( file, 0, SEEK_END ) )
58 56 {
59 57 long int size = ftell( file );
60 58  
... ... @@ -69,7 +67,6 @@ bool LoadShaderCode( const char* path, const char* filename, std::vector&lt;char&gt;&amp;
69 67 }
70 68 }
71 69  
72   - fclose( file );
73 70 return retValue;
74 71 }
75 72  
... ...
examples/rendering-basic-pbr/ktx-loader.cpp
... ... @@ -23,7 +23,7 @@
23 23 #include <stdio.h>
24 24 #include <stdint.h>
25 25 #include <dali/integration-api/debug.h>
26   -#include <dali/devel-api/adaptor-framework/file-loader.h>
  26 +#include <dali/devel-api/adaptor-framework/file-stream.h>
27 27  
28 28 namespace PbrDemo
29 29 {
... ... @@ -94,14 +94,8 @@ bool ConvertPixelFormat(const uint32_t ktxPixelFormat, Dali::Pixel::Format&amp; form
94 94  
95 95 bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata )
96 96 {
97   - std::streampos bufferSize = 0;
98   - Dali::Vector<char> fileBuffer;
99   - if( !Dali::FileLoader::ReadFile( path, bufferSize, fileBuffer, FileLoader::FileType::BINARY ) )
100   - {
101   - return false;
102   - }
103   -
104   - FILE* fp = fmemopen( &fileBuffer[0], bufferSize, "rb" );
  97 + Dali::FileStream fileStream( path, Dali::FileStream::READ | Dali::FileStream::BINARY );
  98 + FILE* fp = fileStream.GetFile();
105 99 if( NULL == fp )
106 100 {
107 101 return false;
... ... @@ -112,7 +106,6 @@ bool LoadCubeMapFromKtxFile( const std::string&amp; path, CubeData&amp; cubedata )
112 106 int result = fread(&header,1,sizeof(KtxFileHeader),fp);
113 107 if( 0 == result )
114 108 {
115   - fclose( fp );
116 109 return false;
117 110 }
118 111  
... ... @@ -123,14 +116,12 @@ bool LoadCubeMapFromKtxFile( const std::string&amp; path, CubeData&amp; cubedata )
123 116  
124 117 if( fseek(fp, imageSizeOffset, SEEK_END) )
125 118 {
126   - fclose( fp );
127 119 return false;
128 120 }
129 121  
130 122 lSize = ftell(fp);
131 123 if( lSize == -1L )
132 124 {
133   - fclose( fp );
134 125 return false;
135 126 }
136 127  
... ... @@ -138,7 +129,6 @@ bool LoadCubeMapFromKtxFile( const std::string&amp; path, CubeData&amp; cubedata )
138 129  
139 130 if( fseek(fp, imageSizeOffset, SEEK_SET) )
140 131 {
141   - fclose( fp );
142 132 return false;
143 133 }
144 134  
... ...
examples/rendering-basic-pbr/rendering-basic-pbr-example.cpp
... ... @@ -26,7 +26,7 @@
26 26 #include "model-skybox.h"
27 27 #include "model-pbr.h"
28 28 #include <dali/integration-api/debug.h>
29   -#include <dali/devel-api/adaptor-framework/file-loader.h>
  29 +#include <dali/devel-api/adaptor-framework/file-stream.h>
30 30  
31 31 using namespace Dali;
32 32 using namespace Toolkit;
... ... @@ -392,15 +392,8 @@ public:
392 392 */
393 393 bool LoadShaderCode( const std::string& fullpath, std::vector<char>& output )
394 394 {
395   - std::streampos bufferSize = 0;
396   - Dali::Vector<char> fileBuffer;
397   - if( !Dali::FileLoader::ReadFile( fullpath, bufferSize, fileBuffer, FileLoader::FileType::BINARY ) )
398   - {
399   - DALI_LOG_WARNING( "file open failed for: \"%s\"", fullpath );
400   - return false;
401   - }
402   -
403   - FILE* file = fmemopen( &fileBuffer[0], bufferSize, "rb" );
  395 + Dali::FileStream fileStream( fullpath, FileStream::READ | FileStream::BINARY );
  396 + FILE* file = fileStream.GetFile();
404 397 if( NULL == file )
405 398 {
406 399 return false;
... ... @@ -421,7 +414,7 @@ public:
421 414 retValue = ( result >= 0 );
422 415 }
423 416 }
424   - fclose( file );
  417 +
425 418 return retValue;
426 419 }
427 420  
... ...