OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkLua.h" | 8 #include "SkLua.h" |
9 #include "SkGraphics.h" | 9 #include "SkGraphics.h" |
10 #include "SkStream.h" | 10 #include "SkStream.h" |
11 #include "SkData.h" | 11 #include "SkData.h" |
12 #include "SkOSFile.h" | 12 #include "SkOSFile.h" |
13 | 13 |
14 extern "C" { | 14 extern "C" { |
15 #include "lua.h" | 15 #include "lua.h" |
16 #include "lualib.h" | 16 #include "lualib.h" |
17 #include "lauxlib.h" | 17 #include "lauxlib.h" |
18 } | 18 } |
19 | 19 |
20 static SkData* read_into_data(const char file[]) { | 20 static SkData* read_into_data(const char file[]) { |
21 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(file)); | 21 SkData* data = SkData::NewFromFileName(file); |
22 if (!stream.get()) { | 22 if (!data) { |
23 return SkData::NewEmpty(); | 23 data = SkData::NewEmpty(); |
24 } | 24 } |
25 size_t len = stream->getLength(); | 25 return data; |
26 void* buffer = sk_malloc_throw(len); | |
27 stream->read(buffer, len); | |
28 return SkData::NewFromMalloc(buffer, len); | |
29 } | 26 } |
30 | 27 |
31 int tool_main(int argc, char** argv); | 28 int tool_main(int argc, char** argv); |
32 int tool_main(int argc, char** argv) { | 29 int tool_main(int argc, char** argv) { |
33 SkAutoGraphics ag; | 30 SkAutoGraphics ag; |
34 SkLua L; | 31 SkLua L; |
35 | 32 |
36 for (int i = 1; i < argc; ++i) { | 33 for (int i = 1; i < argc; ++i) { |
37 SkData* data = NULL; | 34 SkData* data = NULL; |
38 const void* ptr; | 35 const void* ptr; |
(...skipping 15 matching lines...) Expand all Loading... |
54 SkSafeUnref(data); | 51 SkSafeUnref(data); |
55 } | 52 } |
56 return 0; | 53 return 0; |
57 } | 54 } |
58 | 55 |
59 #if !defined SK_BUILD_FOR_IOS | 56 #if !defined SK_BUILD_FOR_IOS |
60 int main(int argc, char * const argv[]) { | 57 int main(int argc, char * const argv[]) { |
61 return tool_main(argc, (char**) argv); | 58 return tool_main(argc, (char**) argv); |
62 } | 59 } |
63 #endif | 60 #endif |
OLD | NEW |