Chromium Code Reviews| 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 "LazyDecodeBitmap.h" | 8 #include "LazyDecodeBitmap.h" |
| 9 #include "SkLua.h" | 9 #include "SkLua.h" |
| 10 #include "SkLuaCanvas.h" | 10 #include "SkLuaCanvas.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 | 40 |
| 41 static SkPicture* load_picture(const char path[]) { | 41 static SkPicture* load_picture(const char path[]) { |
| 42 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | 42 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); |
| 43 SkPicture* pic = NULL; | 43 SkPicture* pic = NULL; |
| 44 if (stream.get()) { | 44 if (stream.get()) { |
| 45 pic = SkPicture::CreateFromStream(stream.get(), &sk_tools::LazyDecodeBit map); | 45 pic = SkPicture::CreateFromStream(stream.get(), &sk_tools::LazyDecodeBit map); |
| 46 } | 46 } |
| 47 return pic; | 47 return pic; |
| 48 } | 48 } |
| 49 | 49 |
| 50 static SkData* read_into_data(const char file[]) { | |
| 51 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(file)); | |
| 52 if (!stream.get()) { | |
| 53 return SkData::NewEmpty(); | |
| 54 } | |
| 55 size_t len = stream->getLength(); | |
| 56 void* buffer = sk_malloc_throw(len); | |
| 57 stream->read(buffer, len); | |
| 58 return SkData::NewFromMalloc(buffer, len); | |
| 59 } | |
| 60 | |
| 61 static void call_canvas(lua_State* L, SkLuaCanvas* canvas, | 50 static void call_canvas(lua_State* L, SkLuaCanvas* canvas, |
| 62 const char pictureFile[], const char funcName[]) { | 51 const char pictureFile[], const char funcName[]) { |
| 63 lua_getglobal(L, funcName); | 52 lua_getglobal(L, funcName); |
| 64 if (!lua_isfunction(L, -1)) { | 53 if (!lua_isfunction(L, -1)) { |
| 65 int t = lua_type(L, -1); | 54 int t = lua_type(L, -1); |
| 66 SkDebugf("--- expected %s function %d, ignoring.\n", funcName, t); | 55 SkDebugf("--- expected %s function %d, ignoring.\n", funcName, t); |
| 67 lua_settop(L, -2); | 56 lua_settop(L, -2); |
| 68 } else { | 57 } else { |
| 69 canvas->pushThis(); | 58 canvas->pushThis(); |
| 70 lua_pushstring(L, pictureFile); | 59 lua_pushstring(L, pictureFile); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 90 | 79 |
| 91 const char* summary = gSummarizeFunc; | 80 const char* summary = gSummarizeFunc; |
| 92 if (!FLAGS_tailFunc.isEmpty()) { | 81 if (!FLAGS_tailFunc.isEmpty()) { |
| 93 summary = FLAGS_tailFunc[0]; | 82 summary = FLAGS_tailFunc[0]; |
| 94 } | 83 } |
| 95 | 84 |
| 96 SkAutoGraphics ag; | 85 SkAutoGraphics ag; |
| 97 SkLua L(summary); | 86 SkLua L(summary); |
| 98 | 87 |
| 99 for (int i = 0; i < FLAGS_luaFile.count(); ++i) { | 88 for (int i = 0; i < FLAGS_luaFile.count(); ++i) { |
| 100 SkAutoDataUnref data(read_into_data(FLAGS_luaFile[i])); | 89 SkAutoDataUnref data(SkData::NewFromFileName(FLAGS_luaFile[i])); |
|
bungeman-skia
2014/09/12 14:50:27
Seems that you still need to test for non NULL dat
reed1
2014/09/12 18:55:17
Done.
| |
| 101 if (!FLAGS_quiet) { | 90 if (!FLAGS_quiet) { |
| 102 SkDebugf("loading %s...\n", FLAGS_luaFile[i]); | 91 SkDebugf("loading %s...\n", FLAGS_luaFile[i]); |
| 103 } | 92 } |
| 104 if (!L.runCode(data->data(), data->size())) { | 93 if (!L.runCode(data->data(), data->size())) { |
| 105 SkDebugf("failed to load luaFile %s\n", FLAGS_luaFile[i]); | 94 SkDebugf("failed to load luaFile %s\n", FLAGS_luaFile[i]); |
| 106 exit(-1); | 95 exit(-1); |
| 107 } | 96 } |
| 108 } | 97 } |
| 109 | 98 |
| 110 if (!FLAGS_headCode.isEmpty()) { | 99 if (!FLAGS_headCode.isEmpty()) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 } | 157 } |
| 169 } | 158 } |
| 170 return 0; | 159 return 0; |
| 171 } | 160 } |
| 172 | 161 |
| 173 #if !defined SK_BUILD_FOR_IOS | 162 #if !defined SK_BUILD_FOR_IOS |
| 174 int main(int argc, char * const argv[]) { | 163 int main(int argc, char * const argv[]) { |
| 175 return tool_main(argc, (char**) argv); | 164 return tool_main(argc, (char**) argv); |
| 176 } | 165 } |
| 177 #endif | 166 #endif |
| OLD | NEW |