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

Side by Side Diff: content/renderer/gpu/gpu_benchmarking_extension.cc

Issue 10837330: Add a completion callback to gpuBenchmarking.beginSmoothScroll (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: virtual and todo note Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « content/port/browser/smooth_scroll_gesture.h ('k') | content/renderer/render_widget.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/gpu/gpu_benchmarking_extension.h" 5 #include "content/renderer/gpu/gpu_benchmarking_extension.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 "};" 128 "};"
129 "chrome.gpuBenchmarking.renderingStats = function() {" 129 "chrome.gpuBenchmarking.renderingStats = function() {"
130 " native function GetRenderingStats();" 130 " native function GetRenderingStats();"
131 " return GetRenderingStats();" 131 " return GetRenderingStats();"
132 "};" 132 "};"
133 "chrome.gpuBenchmarking.printToSkPicture = function(dirname) {" 133 "chrome.gpuBenchmarking.printToSkPicture = function(dirname) {"
134 " native function PrintToSkPicture();" 134 " native function PrintToSkPicture();"
135 " return PrintToSkPicture(dirname);" 135 " return PrintToSkPicture(dirname);"
136 "};" 136 "};"
137 "chrome.gpuBenchmarking.beginSmoothScrollDown = " 137 "chrome.gpuBenchmarking.beginSmoothScrollDown = "
138 " function(scroll_far) {" 138 " function(scroll_far, opt_callback) {"
139 " scroll_far = scroll_far || false;" 139 " scroll_far = scroll_far || false;"
140 " callback = opt_callback || function() { };"
140 " native function BeginSmoothScroll();" 141 " native function BeginSmoothScroll();"
141 " return BeginSmoothScroll(true, scroll_far);" 142 " return BeginSmoothScroll(true, scroll_far, callback);"
142 "};" 143 "};"
143 "chrome.gpuBenchmarking.beginSmoothScrollUp = function(scroll_far) {" 144 "chrome.gpuBenchmarking.beginSmoothScrollUp = "
145 " function(scroll_far, opt_callback) {"
144 " scroll_far = scroll_far || false;" 146 " scroll_far = scroll_far || false;"
147 " callback = opt_callback || function() { };"
145 " native function BeginSmoothScroll();" 148 " native function BeginSmoothScroll();"
146 " return BeginSmoothScroll(false, scroll_far);" 149 " return BeginSmoothScroll(false, scroll_far, callback);"
147 "};" 150 "};"
148 "chrome.gpuBenchmarking.runRenderingBenchmarks = function(filter) {" 151 "chrome.gpuBenchmarking.runRenderingBenchmarks = function(filter) {"
149 " native function RunRenderingBenchmarks();" 152 " native function RunRenderingBenchmarks();"
150 " return RunRenderingBenchmarks(filter);" 153 " return RunRenderingBenchmarks(filter);"
151 "};") {} 154 "};") {}
152 155
153 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 156 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
154 v8::Handle<v8::String> name) { 157 v8::Handle<v8::String> name) {
155 if (name->Equals(v8::String::New("GetRenderingStats"))) 158 if (name->Equals(v8::String::New("GetRenderingStats")))
156 return v8::FunctionTemplate::New(GetRenderingStats); 159 return v8::FunctionTemplate::New(GetRenderingStats);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 return v8::ThrowException(v8::Exception::Error( 226 return v8::ThrowException(v8::Exception::Error(
224 v8::String::New(msg.c_str(), msg.length()))); 227 v8::String::New(msg.c_str(), msg.length())));
225 } 228 }
226 229
227 SkPictureRecorder recorder(dirpath); 230 SkPictureRecorder recorder(dirpath);
228 benchmark_support->paint(&recorder, 231 benchmark_support->paint(&recorder,
229 WebViewBenchmarkSupport::PaintModeEverything); 232 WebViewBenchmarkSupport::PaintModeEverything);
230 return v8::Undefined(); 233 return v8::Undefined();
231 } 234 }
232 235
236 static void OnSmoothScrollCompleted(v8::Persistent<v8::Function> callback,
237 v8::Persistent<v8::Context> context) {
238 v8::HandleScope scope;
239 v8::Context::Scope context_scope(context);
240 WebFrame* frame = WebFrame::frameForContext(context);
241 if (frame) {
242 frame->callFunctionEvenIfScriptDisabled(callback,
243 v8::Object::New(),
244 0,
245 NULL);
246 }
247 callback.Dispose();
248 context.Dispose();
249 }
250
233 static v8::Handle<v8::Value> BeginSmoothScroll(const v8::Arguments& args) { 251 static v8::Handle<v8::Value> BeginSmoothScroll(const v8::Arguments& args) {
234 WebFrame* web_frame = WebFrame::frameForEnteredContext(); 252 WebFrame* web_frame = WebFrame::frameForEnteredContext();
235 if (!web_frame) 253 if (!web_frame)
236 return v8::Undefined(); 254 return v8::Undefined();
237 255
238 WebView* web_view = web_frame->view(); 256 WebView* web_view = web_frame->view();
239 if (!web_view) 257 if (!web_view)
240 return v8::Undefined(); 258 return v8::Undefined();
241 259
242 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view); 260 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view);
243 if (!render_view_impl) 261 if (!render_view_impl)
244 return v8::Undefined(); 262 return v8::Undefined();
245 263
246 if (args.Length() != 2 || !args[0]->IsBoolean() || !args[1]->IsBoolean()) 264 if (args.Length() != 3 ||
265 !args[0]->IsBoolean() ||
266 !args[1]->IsBoolean() ||
267 !args[2]->IsFunction())
247 return v8::False(); 268 return v8::False();
248 269
249 bool scroll_down = args[0]->BooleanValue(); 270 bool scroll_down = args[0]->BooleanValue();
250 bool scroll_far = args[1]->BooleanValue(); 271 bool scroll_far = args[1]->BooleanValue();
272 v8::Local<v8::Function> callback_local =
273 v8::Local<v8::Function>(v8::Function::Cast(*args[2]));
274 v8::Persistent<v8::Function> callback =
275 v8::Persistent<v8::Function>::New(callback_local);
276 v8::Persistent<v8::Context> context =
277 v8::Persistent<v8::Context>::New(web_frame->mainWorldScriptContext());
251 278
252 render_view_impl->BeginSmoothScroll(scroll_down, scroll_far); 279 // TODO(nduca): If the render_view_impl is destroyed while the gesture is in
280 // progress, we will leak the callback and context. This needs to be fixed,
281 // somehow.
282 render_view_impl->BeginSmoothScroll(
283 scroll_down,
284 scroll_far,
285 base::Bind(&OnSmoothScrollCompleted,
286 callback,
287 context));
288
253 return v8::True(); 289 return v8::True();
254 } 290 }
255 291
256 static v8::Handle<v8::Value> RunRenderingBenchmarks( 292 static v8::Handle<v8::Value> RunRenderingBenchmarks(
257 const v8::Arguments& args) { 293 const v8::Arguments& args) {
258 // For our name filter, the argument can be undefined or null to run 294 // For our name filter, the argument can be undefined or null to run
259 // all benchmarks, or a string for filtering by name. 295 // all benchmarks, or a string for filtering by name.
260 if (!args.Length() || 296 if (!args.Length() ||
261 (!args[0]->IsString() && 297 (!args[0]->IsString() &&
262 !(args[0]->IsNull() || args[0]->IsUndefined()))) { 298 !(args[0]->IsNull() || args[0]->IsUndefined()))) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 338
303 return results.results_array(); 339 return results.results_array();
304 } 340 }
305 }; 341 };
306 342
307 v8::Extension* GpuBenchmarkingExtension::Get() { 343 v8::Extension* GpuBenchmarkingExtension::Get() {
308 return new GpuBenchmarkingWrapper(); 344 return new GpuBenchmarkingWrapper();
309 } 345 }
310 346
311 } // namespace content 347 } // namespace content
OLDNEW
« no previous file with comments | « content/port/browser/smooth_scroll_gesture.h ('k') | content/renderer/render_widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698