| OLD | NEW |
| 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/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 if (args->PeekNext()->IsUndefined()) { | 136 if (args->PeekNext()->IsUndefined()) { |
| 137 args->Skip(); | 137 args->Skip(); |
| 138 return true; | 138 return true; |
| 139 } | 139 } |
| 140 return GetArg(args, value); | 140 return GetArg(args, value); |
| 141 } | 141 } |
| 142 | 142 |
| 143 class CallbackAndContext : public base::RefCounted<CallbackAndContext> { | 143 class CallbackAndContext : public base::RefCounted<CallbackAndContext> { |
| 144 public: | 144 public: |
| 145 CallbackAndContext(v8::Isolate* isolate, | 145 CallbackAndContext(v8::Isolate* isolate, |
| 146 v8::Handle<v8::Function> callback, | 146 v8::Local<v8::Function> callback, |
| 147 v8::Handle<v8::Context> context) | 147 v8::Local<v8::Context> context) |
| 148 : isolate_(isolate) { | 148 : isolate_(isolate) { |
| 149 callback_.Reset(isolate_, callback); | 149 callback_.Reset(isolate_, callback); |
| 150 context_.Reset(isolate_, context); | 150 context_.Reset(isolate_, context); |
| 151 } | 151 } |
| 152 | 152 |
| 153 v8::Isolate* isolate() { | 153 v8::Isolate* isolate() { |
| 154 return isolate_; | 154 return isolate_; |
| 155 } | 155 } |
| 156 | 156 |
| 157 v8::Handle<v8::Function> GetCallback() { | 157 v8::Local<v8::Function> GetCallback() { |
| 158 return v8::Local<v8::Function>::New(isolate_, callback_); | 158 return v8::Local<v8::Function>::New(isolate_, callback_); |
| 159 } | 159 } |
| 160 | 160 |
| 161 v8::Handle<v8::Context> GetContext() { | 161 v8::Local<v8::Context> GetContext() { |
| 162 return v8::Local<v8::Context>::New(isolate_, context_); | 162 return v8::Local<v8::Context>::New(isolate_, context_); |
| 163 } | 163 } |
| 164 | 164 |
| 165 private: | 165 private: |
| 166 friend class base::RefCounted<CallbackAndContext>; | 166 friend class base::RefCounted<CallbackAndContext>; |
| 167 | 167 |
| 168 virtual ~CallbackAndContext() { | 168 virtual ~CallbackAndContext() { |
| 169 callback_.Reset(); | 169 callback_.Reset(); |
| 170 context_.Reset(); | 170 context_.Reset(); |
| 171 } | 171 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 RenderWidgetCompositor* compositor_; | 240 RenderWidgetCompositor* compositor_; |
| 241 | 241 |
| 242 DISALLOW_COPY_AND_ASSIGN(GpuBenchmarkingContext); | 242 DISALLOW_COPY_AND_ASSIGN(GpuBenchmarkingContext); |
| 243 }; | 243 }; |
| 244 | 244 |
| 245 void OnMicroBenchmarkCompleted( | 245 void OnMicroBenchmarkCompleted( |
| 246 CallbackAndContext* callback_and_context, | 246 CallbackAndContext* callback_and_context, |
| 247 scoped_ptr<base::Value> result) { | 247 scoped_ptr<base::Value> result) { |
| 248 v8::Isolate* isolate = callback_and_context->isolate(); | 248 v8::Isolate* isolate = callback_and_context->isolate(); |
| 249 v8::HandleScope scope(isolate); | 249 v8::HandleScope scope(isolate); |
| 250 v8::Handle<v8::Context> context = callback_and_context->GetContext(); | 250 v8::Local<v8::Context> context = callback_and_context->GetContext(); |
| 251 v8::Context::Scope context_scope(context); | 251 v8::Context::Scope context_scope(context); |
| 252 WebLocalFrame* frame = WebLocalFrame::frameForContext(context); | 252 WebLocalFrame* frame = WebLocalFrame::frameForContext(context); |
| 253 if (frame) { | 253 if (frame) { |
| 254 scoped_ptr<V8ValueConverter> converter = | 254 scoped_ptr<V8ValueConverter> converter = |
| 255 make_scoped_ptr(V8ValueConverter::create()); | 255 make_scoped_ptr(V8ValueConverter::create()); |
| 256 v8::Handle<v8::Value> value = converter->ToV8Value(result.get(), context); | 256 v8::Local<v8::Value> value = converter->ToV8Value(result.get(), context); |
| 257 v8::Handle<v8::Value> argv[] = { value }; | 257 v8::Local<v8::Value> argv[] = { value }; |
| 258 | 258 |
| 259 frame->callFunctionEvenIfScriptDisabled( | 259 frame->callFunctionEvenIfScriptDisabled( |
| 260 callback_and_context->GetCallback(), | 260 callback_and_context->GetCallback(), |
| 261 v8::Object::New(isolate), | 261 v8::Object::New(isolate), |
| 262 1, | 262 1, |
| 263 argv); | 263 argv); |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 | 266 |
| 267 void OnSyntheticGestureCompleted(CallbackAndContext* callback_and_context) { | 267 void OnSyntheticGestureCompleted(CallbackAndContext* callback_and_context) { |
| 268 v8::Isolate* isolate = callback_and_context->isolate(); | 268 v8::Isolate* isolate = callback_and_context->isolate(); |
| 269 v8::HandleScope scope(isolate); | 269 v8::HandleScope scope(isolate); |
| 270 v8::Handle<v8::Context> context = callback_and_context->GetContext(); | 270 v8::Local<v8::Context> context = callback_and_context->GetContext(); |
| 271 v8::Context::Scope context_scope(context); | 271 v8::Context::Scope context_scope(context); |
| 272 WebLocalFrame* frame = WebLocalFrame::frameForContext(context); | 272 WebLocalFrame* frame = WebLocalFrame::frameForContext(context); |
| 273 if (frame) { | 273 if (frame) { |
| 274 frame->callFunctionEvenIfScriptDisabled( | 274 frame->callFunctionEvenIfScriptDisabled( |
| 275 callback_and_context->GetCallback(), v8::Object::New(isolate), 0, NULL); | 275 callback_and_context->GetCallback(), v8::Object::New(isolate), 0, NULL); |
| 276 } | 276 } |
| 277 } | 277 } |
| 278 | 278 |
| 279 bool BeginSmoothScroll(v8::Isolate* isolate, | 279 bool BeginSmoothScroll(v8::Isolate* isolate, |
| 280 float pixels_to_scroll, | 280 float pixels_to_scroll, |
| 281 v8::Handle<v8::Function> callback, | 281 v8::Local<v8::Function> callback, |
| 282 int gesture_source_type, | 282 int gesture_source_type, |
| 283 const std::string& direction, | 283 const std::string& direction, |
| 284 float speed_in_pixels_s, | 284 float speed_in_pixels_s, |
| 285 bool prevent_fling, | 285 bool prevent_fling, |
| 286 float start_x, | 286 float start_x, |
| 287 float start_y) { | 287 float start_y) { |
| 288 GpuBenchmarkingContext context; | 288 GpuBenchmarkingContext context; |
| 289 if (!context.Init(false)) | 289 if (!context.Init(false)) |
| 290 return false; | 290 return false; |
| 291 | 291 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 base::Bind(&OnSyntheticGestureCompleted, callback_and_context)); | 348 base::Bind(&OnSyntheticGestureCompleted, callback_and_context)); |
| 349 | 349 |
| 350 return true; | 350 return true; |
| 351 } | 351 } |
| 352 | 352 |
| 353 bool BeginSmoothDrag(v8::Isolate* isolate, | 353 bool BeginSmoothDrag(v8::Isolate* isolate, |
| 354 float start_x, | 354 float start_x, |
| 355 float start_y, | 355 float start_y, |
| 356 float end_x, | 356 float end_x, |
| 357 float end_y, | 357 float end_y, |
| 358 v8::Handle<v8::Function> callback, | 358 v8::Local<v8::Function> callback, |
| 359 int gesture_source_type, | 359 int gesture_source_type, |
| 360 float speed_in_pixels_s) { | 360 float speed_in_pixels_s) { |
| 361 GpuBenchmarkingContext context; | 361 GpuBenchmarkingContext context; |
| 362 if (!context.Init(false)) | 362 if (!context.Init(false)) |
| 363 return false; | 363 return false; |
| 364 scoped_refptr<CallbackAndContext> callback_and_context = | 364 scoped_refptr<CallbackAndContext> callback_and_context = |
| 365 new CallbackAndContext(isolate, callback, | 365 new CallbackAndContext(isolate, callback, |
| 366 context.web_frame()->mainWorldScriptContext()); | 366 context.web_frame()->mainWorldScriptContext()); |
| 367 | 367 |
| 368 scoped_ptr<SyntheticSmoothDragGestureParams> gesture_params( | 368 scoped_ptr<SyntheticSmoothDragGestureParams> gesture_params( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 393 } | 393 } |
| 394 | 394 |
| 395 } // namespace | 395 } // namespace |
| 396 | 396 |
| 397 gin::WrapperInfo GpuBenchmarking::kWrapperInfo = {gin::kEmbedderNativeGin}; | 397 gin::WrapperInfo GpuBenchmarking::kWrapperInfo = {gin::kEmbedderNativeGin}; |
| 398 | 398 |
| 399 // static | 399 // static |
| 400 void GpuBenchmarking::Install(blink::WebFrame* frame) { | 400 void GpuBenchmarking::Install(blink::WebFrame* frame) { |
| 401 v8::Isolate* isolate = blink::mainThreadIsolate(); | 401 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 402 v8::HandleScope handle_scope(isolate); | 402 v8::HandleScope handle_scope(isolate); |
| 403 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); | 403 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
| 404 if (context.IsEmpty()) | 404 if (context.IsEmpty()) |
| 405 return; | 405 return; |
| 406 | 406 |
| 407 v8::Context::Scope context_scope(context); | 407 v8::Context::Scope context_scope(context); |
| 408 | 408 |
| 409 gin::Handle<GpuBenchmarking> controller = | 409 gin::Handle<GpuBenchmarking> controller = |
| 410 gin::CreateHandle(isolate, new GpuBenchmarking()); | 410 gin::CreateHandle(isolate, new GpuBenchmarking()); |
| 411 if (controller.IsEmpty()) | 411 if (controller.IsEmpty()) |
| 412 return; | 412 return; |
| 413 | 413 |
| 414 v8::Handle<v8::Object> chrome = GetOrCreateChromeObject(isolate, | 414 v8::Local<v8::Object> chrome = GetOrCreateChromeObject(isolate, |
| 415 context->Global()); | 415 context->Global()); |
| 416 chrome->Set(gin::StringToV8(isolate, "gpuBenchmarking"), controller.ToV8()); | 416 chrome->Set(gin::StringToV8(isolate, "gpuBenchmarking"), controller.ToV8()); |
| 417 } | 417 } |
| 418 | 418 |
| 419 GpuBenchmarking::GpuBenchmarking() { | 419 GpuBenchmarking::GpuBenchmarking() { |
| 420 } | 420 } |
| 421 | 421 |
| 422 GpuBenchmarking::~GpuBenchmarking() { | 422 GpuBenchmarking::~GpuBenchmarking() { |
| 423 } | 423 } |
| 424 | 424 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 | 504 |
| 505 bool GpuBenchmarking::SmoothScrollBy(gin::Arguments* args) { | 505 bool GpuBenchmarking::SmoothScrollBy(gin::Arguments* args) { |
| 506 GpuBenchmarkingContext context; | 506 GpuBenchmarkingContext context; |
| 507 if (!context.Init(true)) | 507 if (!context.Init(true)) |
| 508 return false; | 508 return false; |
| 509 | 509 |
| 510 float page_scale_factor = context.web_view()->pageScaleFactor(); | 510 float page_scale_factor = context.web_view()->pageScaleFactor(); |
| 511 blink::WebRect rect = context.render_view_impl()->windowRect(); | 511 blink::WebRect rect = context.render_view_impl()->windowRect(); |
| 512 | 512 |
| 513 float pixels_to_scroll = 0; | 513 float pixels_to_scroll = 0; |
| 514 v8::Handle<v8::Function> callback; | 514 v8::Local<v8::Function> callback; |
| 515 float start_x = rect.width / (page_scale_factor * 2); | 515 float start_x = rect.width / (page_scale_factor * 2); |
| 516 float start_y = rect.height / (page_scale_factor * 2); | 516 float start_y = rect.height / (page_scale_factor * 2); |
| 517 int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT; | 517 int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT; |
| 518 std::string direction = "down"; | 518 std::string direction = "down"; |
| 519 float speed_in_pixels_s = 800; | 519 float speed_in_pixels_s = 800; |
| 520 | 520 |
| 521 if (!GetOptionalArg(args, &pixels_to_scroll) || | 521 if (!GetOptionalArg(args, &pixels_to_scroll) || |
| 522 !GetOptionalArg(args, &callback) || | 522 !GetOptionalArg(args, &callback) || |
| 523 !GetOptionalArg(args, &start_x) || | 523 !GetOptionalArg(args, &start_x) || |
| 524 !GetOptionalArg(args, &start_y) || | 524 !GetOptionalArg(args, &start_y) || |
| (...skipping 16 matching lines...) Expand all Loading... |
| 541 | 541 |
| 542 bool GpuBenchmarking::SmoothDrag(gin::Arguments* args) { | 542 bool GpuBenchmarking::SmoothDrag(gin::Arguments* args) { |
| 543 GpuBenchmarkingContext context; | 543 GpuBenchmarkingContext context; |
| 544 if (!context.Init(true)) | 544 if (!context.Init(true)) |
| 545 return false; | 545 return false; |
| 546 | 546 |
| 547 float start_x; | 547 float start_x; |
| 548 float start_y; | 548 float start_y; |
| 549 float end_x; | 549 float end_x; |
| 550 float end_y; | 550 float end_y; |
| 551 v8::Handle<v8::Function> callback; | 551 v8::Local<v8::Function> callback; |
| 552 int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT; | 552 int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT; |
| 553 float speed_in_pixels_s = 800; | 553 float speed_in_pixels_s = 800; |
| 554 | 554 |
| 555 if (!GetArg(args, &start_x) || | 555 if (!GetArg(args, &start_x) || |
| 556 !GetArg(args, &start_y) || | 556 !GetArg(args, &start_y) || |
| 557 !GetArg(args, &end_x) || | 557 !GetArg(args, &end_x) || |
| 558 !GetArg(args, &end_y) || | 558 !GetArg(args, &end_y) || |
| 559 !GetOptionalArg(args, &callback) || | 559 !GetOptionalArg(args, &callback) || |
| 560 !GetOptionalArg(args, &gesture_source_type) || | 560 !GetOptionalArg(args, &gesture_source_type) || |
| 561 !GetOptionalArg(args, &speed_in_pixels_s)) { | 561 !GetOptionalArg(args, &speed_in_pixels_s)) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 575 bool GpuBenchmarking::Swipe(gin::Arguments* args) { | 575 bool GpuBenchmarking::Swipe(gin::Arguments* args) { |
| 576 GpuBenchmarkingContext context; | 576 GpuBenchmarkingContext context; |
| 577 if (!context.Init(true)) | 577 if (!context.Init(true)) |
| 578 return false; | 578 return false; |
| 579 | 579 |
| 580 float page_scale_factor = context.web_view()->pageScaleFactor(); | 580 float page_scale_factor = context.web_view()->pageScaleFactor(); |
| 581 blink::WebRect rect = context.render_view_impl()->windowRect(); | 581 blink::WebRect rect = context.render_view_impl()->windowRect(); |
| 582 | 582 |
| 583 std::string direction = "up"; | 583 std::string direction = "up"; |
| 584 float pixels_to_scroll = 0; | 584 float pixels_to_scroll = 0; |
| 585 v8::Handle<v8::Function> callback; | 585 v8::Local<v8::Function> callback; |
| 586 float start_x = rect.width / (page_scale_factor * 2); | 586 float start_x = rect.width / (page_scale_factor * 2); |
| 587 float start_y = rect.height / (page_scale_factor * 2); | 587 float start_y = rect.height / (page_scale_factor * 2); |
| 588 float speed_in_pixels_s = 800; | 588 float speed_in_pixels_s = 800; |
| 589 | 589 |
| 590 if (!GetOptionalArg(args, &direction) || | 590 if (!GetOptionalArg(args, &direction) || |
| 591 !GetOptionalArg(args, &pixels_to_scroll) || | 591 !GetOptionalArg(args, &pixels_to_scroll) || |
| 592 !GetOptionalArg(args, &callback) || | 592 !GetOptionalArg(args, &callback) || |
| 593 !GetOptionalArg(args, &start_x) || | 593 !GetOptionalArg(args, &start_x) || |
| 594 !GetOptionalArg(args, &start_y) || | 594 !GetOptionalArg(args, &start_y) || |
| 595 !GetOptionalArg(args, &speed_in_pixels_s)) { | 595 !GetOptionalArg(args, &speed_in_pixels_s)) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 612 if (!context.Init(false)) | 612 if (!context.Init(false)) |
| 613 return false; | 613 return false; |
| 614 | 614 |
| 615 float page_scale_factor = context.web_view()->pageScaleFactor(); | 615 float page_scale_factor = context.web_view()->pageScaleFactor(); |
| 616 blink::WebRect rect = context.render_view_impl()->windowRect(); | 616 blink::WebRect rect = context.render_view_impl()->windowRect(); |
| 617 | 617 |
| 618 std::string direction = "down"; | 618 std::string direction = "down"; |
| 619 float distance_length = 0; | 619 float distance_length = 0; |
| 620 float overscroll_length = 0; | 620 float overscroll_length = 0; |
| 621 int repeat_count = 1; | 621 int repeat_count = 1; |
| 622 v8::Handle<v8::Function> callback; | 622 v8::Local<v8::Function> callback; |
| 623 float start_x = rect.width / (page_scale_factor * 2); | 623 float start_x = rect.width / (page_scale_factor * 2); |
| 624 float start_y = rect.height / (page_scale_factor * 2); | 624 float start_y = rect.height / (page_scale_factor * 2); |
| 625 float speed_in_pixels_s = 800; | 625 float speed_in_pixels_s = 800; |
| 626 | 626 |
| 627 if (!GetOptionalArg(args, &direction) || | 627 if (!GetOptionalArg(args, &direction) || |
| 628 !GetOptionalArg(args, &distance_length) || | 628 !GetOptionalArg(args, &distance_length) || |
| 629 !GetOptionalArg(args, &overscroll_length) || | 629 !GetOptionalArg(args, &overscroll_length) || |
| 630 !GetOptionalArg(args, &repeat_count) || | 630 !GetOptionalArg(args, &repeat_count) || |
| 631 !GetOptionalArg(args, &callback) || | 631 !GetOptionalArg(args, &callback) || |
| 632 !GetOptionalArg(args, &start_x) || | 632 !GetOptionalArg(args, &start_x) || |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 } | 684 } |
| 685 | 685 |
| 686 bool GpuBenchmarking::PinchBy(gin::Arguments* args) { | 686 bool GpuBenchmarking::PinchBy(gin::Arguments* args) { |
| 687 GpuBenchmarkingContext context; | 687 GpuBenchmarkingContext context; |
| 688 if (!context.Init(false)) | 688 if (!context.Init(false)) |
| 689 return false; | 689 return false; |
| 690 | 690 |
| 691 float scale_factor; | 691 float scale_factor; |
| 692 float anchor_x; | 692 float anchor_x; |
| 693 float anchor_y; | 693 float anchor_y; |
| 694 v8::Handle<v8::Function> callback; | 694 v8::Local<v8::Function> callback; |
| 695 float relative_pointer_speed_in_pixels_s = 800; | 695 float relative_pointer_speed_in_pixels_s = 800; |
| 696 | 696 |
| 697 | 697 |
| 698 if (!GetArg(args, &scale_factor) || | 698 if (!GetArg(args, &scale_factor) || |
| 699 !GetArg(args, &anchor_x) || | 699 !GetArg(args, &anchor_x) || |
| 700 !GetArg(args, &anchor_y) || | 700 !GetArg(args, &anchor_y) || |
| 701 !GetOptionalArg(args, &callback) || | 701 !GetOptionalArg(args, &callback) || |
| 702 !GetOptionalArg(args, &relative_pointer_speed_in_pixels_s)) { | 702 !GetOptionalArg(args, &relative_pointer_speed_in_pixels_s)) { |
| 703 return false; | 703 return false; |
| 704 } | 704 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 731 return true; | 731 return true; |
| 732 } | 732 } |
| 733 | 733 |
| 734 bool GpuBenchmarking::Tap(gin::Arguments* args) { | 734 bool GpuBenchmarking::Tap(gin::Arguments* args) { |
| 735 GpuBenchmarkingContext context; | 735 GpuBenchmarkingContext context; |
| 736 if (!context.Init(false)) | 736 if (!context.Init(false)) |
| 737 return false; | 737 return false; |
| 738 | 738 |
| 739 float position_x; | 739 float position_x; |
| 740 float position_y; | 740 float position_y; |
| 741 v8::Handle<v8::Function> callback; | 741 v8::Local<v8::Function> callback; |
| 742 int duration_ms = 50; | 742 int duration_ms = 50; |
| 743 int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT; | 743 int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT; |
| 744 | 744 |
| 745 if (!GetArg(args, &position_x) || | 745 if (!GetArg(args, &position_x) || |
| 746 !GetArg(args, &position_y) || | 746 !GetArg(args, &position_y) || |
| 747 !GetOptionalArg(args, &callback) || | 747 !GetOptionalArg(args, &callback) || |
| 748 !GetOptionalArg(args, &duration_ms) || | 748 !GetOptionalArg(args, &duration_ms) || |
| 749 !GetOptionalArg(args, &gesture_source_type)) { | 749 !GetOptionalArg(args, &gesture_source_type)) { |
| 750 return false; | 750 return false; |
| 751 } | 751 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 void GpuBenchmarking::ClearImageCache() { | 786 void GpuBenchmarking::ClearImageCache() { |
| 787 WebImageCache::clear(); | 787 WebImageCache::clear(); |
| 788 } | 788 } |
| 789 | 789 |
| 790 int GpuBenchmarking::RunMicroBenchmark(gin::Arguments* args) { | 790 int GpuBenchmarking::RunMicroBenchmark(gin::Arguments* args) { |
| 791 GpuBenchmarkingContext context; | 791 GpuBenchmarkingContext context; |
| 792 if (!context.Init(true)) | 792 if (!context.Init(true)) |
| 793 return 0; | 793 return 0; |
| 794 | 794 |
| 795 std::string name; | 795 std::string name; |
| 796 v8::Handle<v8::Function> callback; | 796 v8::Local<v8::Function> callback; |
| 797 v8::Handle<v8::Object> arguments; | 797 v8::Local<v8::Object> arguments; |
| 798 | 798 |
| 799 if (!GetArg(args, &name) || !GetArg(args, &callback) || | 799 if (!GetArg(args, &name) || !GetArg(args, &callback) || |
| 800 !GetOptionalArg(args, &arguments)) { | 800 !GetOptionalArg(args, &arguments)) { |
| 801 return 0; | 801 return 0; |
| 802 } | 802 } |
| 803 | 803 |
| 804 scoped_refptr<CallbackAndContext> callback_and_context = | 804 scoped_refptr<CallbackAndContext> callback_and_context = |
| 805 new CallbackAndContext(args->isolate(), | 805 new CallbackAndContext(args->isolate(), |
| 806 callback, | 806 callback, |
| 807 context.web_frame()->mainWorldScriptContext()); | 807 context.web_frame()->mainWorldScriptContext()); |
| 808 | 808 |
| 809 scoped_ptr<V8ValueConverter> converter = | 809 scoped_ptr<V8ValueConverter> converter = |
| 810 make_scoped_ptr(V8ValueConverter::create()); | 810 make_scoped_ptr(V8ValueConverter::create()); |
| 811 v8::Handle<v8::Context> v8_context = callback_and_context->GetContext(); | 811 v8::Local<v8::Context> v8_context = callback_and_context->GetContext(); |
| 812 scoped_ptr<base::Value> value = | 812 scoped_ptr<base::Value> value = |
| 813 make_scoped_ptr(converter->FromV8Value(arguments, v8_context)); | 813 make_scoped_ptr(converter->FromV8Value(arguments, v8_context)); |
| 814 | 814 |
| 815 return context.compositor()->ScheduleMicroBenchmark( | 815 return context.compositor()->ScheduleMicroBenchmark( |
| 816 name, | 816 name, |
| 817 value.Pass(), | 817 value.Pass(), |
| 818 base::Bind(&OnMicroBenchmarkCompleted, callback_and_context)); | 818 base::Bind(&OnMicroBenchmarkCompleted, callback_and_context)); |
| 819 } | 819 } |
| 820 | 820 |
| 821 bool GpuBenchmarking::SendMessageToMicroBenchmark( | 821 bool GpuBenchmarking::SendMessageToMicroBenchmark( |
| 822 int id, | 822 int id, |
| 823 v8::Handle<v8::Object> message) { | 823 v8::Local<v8::Object> message) { |
| 824 GpuBenchmarkingContext context; | 824 GpuBenchmarkingContext context; |
| 825 if (!context.Init(true)) | 825 if (!context.Init(true)) |
| 826 return false; | 826 return false; |
| 827 | 827 |
| 828 scoped_ptr<V8ValueConverter> converter = | 828 scoped_ptr<V8ValueConverter> converter = |
| 829 make_scoped_ptr(V8ValueConverter::create()); | 829 make_scoped_ptr(V8ValueConverter::create()); |
| 830 v8::Handle<v8::Context> v8_context = | 830 v8::Local<v8::Context> v8_context = |
| 831 context.web_frame()->mainWorldScriptContext(); | 831 context.web_frame()->mainWorldScriptContext(); |
| 832 scoped_ptr<base::Value> value = | 832 scoped_ptr<base::Value> value = |
| 833 make_scoped_ptr(converter->FromV8Value(message, v8_context)); | 833 make_scoped_ptr(converter->FromV8Value(message, v8_context)); |
| 834 | 834 |
| 835 return context.compositor()->SendMessageToMicroBenchmark(id, value.Pass()); | 835 return context.compositor()->SendMessageToMicroBenchmark(id, value.Pass()); |
| 836 } | 836 } |
| 837 | 837 |
| 838 bool GpuBenchmarking::HasGpuProcess() { | 838 bool GpuBenchmarking::HasGpuProcess() { |
| 839 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel(); | 839 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel(); |
| 840 return !!gpu_channel; | 840 return !!gpu_channel; |
| 841 } | 841 } |
| 842 | 842 |
| 843 } // namespace content | 843 } // namespace content |
| OLD | NEW |