Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: tools/lua/lua_pictures.cpp

Issue 1811703002: return pictures as sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rely on RVO in picturerecorder Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/kilobench/kilobench.cpp ('k') | tools/pinspect.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkLuaCanvas.h" 9 #include "SkLuaCanvas.h"
10 #include "SkPicture.h" 10 #include "SkPicture.h"
(...skipping 20 matching lines...) Expand all
31 // Example usage for the modulo flag: 31 // Example usage for the modulo flag:
32 // for i in {0..5}; do lua_pictures --skpPath SKP_PATH -l YOUR_SCRIPT --modulo $ i 6 &; done 32 // for i in {0..5}; do lua_pictures --skpPath SKP_PATH -l YOUR_SCRIPT --modulo $ i 6 &; done
33 DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which " 33 DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which "
34 "testIndex %% divisor == remainder."); 34 "testIndex %% divisor == remainder.");
35 DEFINE_string2(skpPath, r, "", "Read this .skp file or .skp files from this dir" ); 35 DEFINE_string2(skpPath, r, "", "Read this .skp file or .skp files from this dir" );
36 DEFINE_string2(luaFile, l, "", "File containing lua script to run"); 36 DEFINE_string2(luaFile, l, "", "File containing lua script to run");
37 DEFINE_string2(headCode, s, "", "Optional lua code to call at beginning"); 37 DEFINE_string2(headCode, s, "", "Optional lua code to call at beginning");
38 DEFINE_string2(tailFunc, s, "", "Optional lua function to call at end"); 38 DEFINE_string2(tailFunc, s, "", "Optional lua function to call at end");
39 DEFINE_bool2(quiet, q, false, "Silence all non-error related output"); 39 DEFINE_bool2(quiet, q, false, "Silence all non-error related output");
40 40
41 static SkPicture* load_picture(const char path[]) { 41 static sk_sp<SkPicture> load_picture(const char path[]) {
42 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); 42 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
43 SkPicture* pic = nullptr;
44 if (stream.get()) { 43 if (stream.get()) {
45 pic = SkPicture::CreateFromStream(stream.get()); 44 return SkPicture::MakeFromStream(stream.get());
46 } 45 }
47 return pic; 46 return nullptr;
48 } 47 }
49 48
50 static void call_canvas(lua_State* L, SkLuaCanvas* canvas, 49 static void call_canvas(lua_State* L, SkLuaCanvas* canvas,
51 const char pictureFile[], const char funcName[]) { 50 const char pictureFile[], const char funcName[]) {
52 lua_getglobal(L, funcName); 51 lua_getglobal(L, funcName);
53 if (!lua_isfunction(L, -1)) { 52 if (!lua_isfunction(L, -1)) {
54 int t = lua_type(L, -1); 53 int t = lua_type(L, -1);
55 SkDebugf("--- expected %s function %d, ignoring.\n", funcName, t); 54 SkDebugf("--- expected %s function %d, ignoring.\n", funcName, t);
56 lua_settop(L, -2); 55 lua_settop(L, -2);
57 } else { 56 } else {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 if ((i % moduloDivisor) != moduloRemainder) { 135 if ((i % moduloDivisor) != moduloRemainder) {
137 continue; 136 continue;
138 } 137 }
139 moduloStr.printf("[%d.%d] ", i, moduloDivisor); 138 moduloStr.printf("[%d.%d] ", i, moduloDivisor);
140 } 139 }
141 const char* path = paths[i].c_str(); 140 const char* path = paths[i].c_str();
142 if (!FLAGS_quiet) { 141 if (!FLAGS_quiet) {
143 SkDebugf("scraping %s %s\n", path, moduloStr.c_str()); 142 SkDebugf("scraping %s %s\n", path, moduloStr.c_str());
144 } 143 }
145 144
146 SkAutoTUnref<SkPicture> pic(load_picture(path)); 145 auto pic(load_picture(path));
147 if (pic.get()) { 146 if (pic.get()) {
148 SkAutoTUnref<SkLuaCanvas> canvas( 147 SkAutoTUnref<SkLuaCanvas> canvas(
149 new SkLuaCanvas(SkScalarCeilToInt(pic->cullR ect().width()), 148 new SkLuaCanvas(SkScalarCeilToInt(pic->cullR ect().width()),
150 SkScalarCeilToInt(pic->cullR ect().height()), 149 SkScalarCeilToInt(pic->cullR ect().height()),
151 L.get(), gAccumulateFunc)); 150 L.get(), gAccumulateFunc));
152 151
153 call_canvas(L.get(), canvas.get(), path, gStartCanvasFunc); 152 call_canvas(L.get(), canvas.get(), path, gStartCanvasFunc);
154 canvas->drawPicture(pic); 153 canvas->drawPicture(pic);
155 call_canvas(L.get(), canvas.get(), path, gEndCanvasFunc); 154 call_canvas(L.get(), canvas.get(), path, gEndCanvasFunc);
156 155
157 } else { 156 } else {
158 SkDebugf("failed to load\n"); 157 SkDebugf("failed to load\n");
159 } 158 }
160 } 159 }
161 } 160 }
162 return 0; 161 return 0;
163 } 162 }
164 163
165 #if !defined SK_BUILD_FOR_IOS 164 #if !defined SK_BUILD_FOR_IOS
166 int main(int argc, char * const argv[]) { 165 int main(int argc, char * const argv[]) {
167 return tool_main(argc, (char**) argv); 166 return tool_main(argc, (char**) argv);
168 } 167 }
169 #endif 168 #endif
OLDNEW
« no previous file with comments | « tools/kilobench/kilobench.cpp ('k') | tools/pinspect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698