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 <stddef.h> | 7 #include <stddef.h> |
| 8 |
8 #include <string> | 9 #include <string> |
9 #include <utility> | 10 #include <utility> |
10 | 11 |
11 #include "base/base64.h" | 12 #include "base/base64.h" |
12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
14 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" |
16 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
17 #include "cc/layers/layer.h" | 19 #include "cc/layers/layer.h" |
18 #include "content/common/child_process_messages.h" | 20 #include "content/common/child_process_messages.h" |
19 #include "content/common/input/synthetic_gesture_params.h" | 21 #include "content/common/input/synthetic_gesture_params.h" |
20 #include "content/common/input/synthetic_pinch_gesture_params.h" | 22 #include "content/common/input/synthetic_pinch_gesture_params.h" |
21 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" | 23 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" |
22 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" | 24 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
23 #include "content/common/input/synthetic_tap_gesture_params.h" | 25 #include "content/common/input/synthetic_tap_gesture_params.h" |
24 #include "content/public/child/v8_value_converter.h" | 26 #include "content/public/child/v8_value_converter.h" |
25 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 277 |
276 private: | 278 private: |
277 WebLocalFrame* web_frame_; | 279 WebLocalFrame* web_frame_; |
278 WebView* web_view_; | 280 WebView* web_view_; |
279 RenderViewImpl* render_view_impl_; | 281 RenderViewImpl* render_view_impl_; |
280 RenderWidgetCompositor* compositor_; | 282 RenderWidgetCompositor* compositor_; |
281 | 283 |
282 DISALLOW_COPY_AND_ASSIGN(GpuBenchmarkingContext); | 284 DISALLOW_COPY_AND_ASSIGN(GpuBenchmarkingContext); |
283 }; | 285 }; |
284 | 286 |
285 void OnMicroBenchmarkCompleted( | 287 void OnMicroBenchmarkCompleted(CallbackAndContext* callback_and_context, |
286 CallbackAndContext* callback_and_context, | 288 std::unique_ptr<base::Value> result) { |
287 scoped_ptr<base::Value> result) { | |
288 v8::Isolate* isolate = callback_and_context->isolate(); | 289 v8::Isolate* isolate = callback_and_context->isolate(); |
289 v8::HandleScope scope(isolate); | 290 v8::HandleScope scope(isolate); |
290 v8::Local<v8::Context> context = callback_and_context->GetContext(); | 291 v8::Local<v8::Context> context = callback_and_context->GetContext(); |
291 v8::Context::Scope context_scope(context); | 292 v8::Context::Scope context_scope(context); |
292 WebLocalFrame* frame = WebLocalFrame::frameForContext(context); | 293 WebLocalFrame* frame = WebLocalFrame::frameForContext(context); |
293 if (frame) { | 294 if (frame) { |
294 scoped_ptr<V8ValueConverter> converter = | 295 std::unique_ptr<V8ValueConverter> converter = |
295 make_scoped_ptr(V8ValueConverter::create()); | 296 base::WrapUnique(V8ValueConverter::create()); |
296 v8::Local<v8::Value> value = converter->ToV8Value(result.get(), context); | 297 v8::Local<v8::Value> value = converter->ToV8Value(result.get(), context); |
297 v8::Local<v8::Value> argv[] = { value }; | 298 v8::Local<v8::Value> argv[] = { value }; |
298 | 299 |
299 frame->callFunctionEvenIfScriptDisabled( | 300 frame->callFunctionEvenIfScriptDisabled( |
300 callback_and_context->GetCallback(), | 301 callback_and_context->GetCallback(), |
301 v8::Object::New(isolate), | 302 v8::Object::New(isolate), |
302 1, | 303 1, |
303 argv); | 304 argv); |
304 } | 305 } |
305 } | 306 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 mouseMove.x = (contentRect.x + contentRect.width / 2) * page_scale_factor; | 344 mouseMove.x = (contentRect.x + contentRect.width / 2) * page_scale_factor; |
344 mouseMove.y = (contentRect.y + contentRect.height / 2) * page_scale_factor; | 345 mouseMove.y = (contentRect.y + contentRect.height / 2) * page_scale_factor; |
345 context.web_view()->handleInputEvent(mouseMove); | 346 context.web_view()->handleInputEvent(mouseMove); |
346 context.web_view()->setCursorVisibilityState(true); | 347 context.web_view()->setCursorVisibilityState(true); |
347 } | 348 } |
348 | 349 |
349 scoped_refptr<CallbackAndContext> callback_and_context = | 350 scoped_refptr<CallbackAndContext> callback_and_context = |
350 new CallbackAndContext( | 351 new CallbackAndContext( |
351 isolate, callback, context.web_frame()->mainWorldScriptContext()); | 352 isolate, callback, context.web_frame()->mainWorldScriptContext()); |
352 | 353 |
353 scoped_ptr<SyntheticSmoothScrollGestureParams> gesture_params( | 354 std::unique_ptr<SyntheticSmoothScrollGestureParams> gesture_params( |
354 new SyntheticSmoothScrollGestureParams); | 355 new SyntheticSmoothScrollGestureParams); |
355 | 356 |
356 if (gesture_source_type < 0 || | 357 if (gesture_source_type < 0 || |
357 gesture_source_type > SyntheticGestureParams::GESTURE_SOURCE_TYPE_MAX) { | 358 gesture_source_type > SyntheticGestureParams::GESTURE_SOURCE_TYPE_MAX) { |
358 return false; | 359 return false; |
359 } | 360 } |
360 gesture_params->gesture_source_type = | 361 gesture_params->gesture_source_type = |
361 static_cast<SyntheticGestureParams::GestureSourceType>( | 362 static_cast<SyntheticGestureParams::GestureSourceType>( |
362 gesture_source_type); | 363 gesture_source_type); |
363 | 364 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 v8::Local<v8::Function> callback, | 414 v8::Local<v8::Function> callback, |
414 int gesture_source_type, | 415 int gesture_source_type, |
415 float speed_in_pixels_s) { | 416 float speed_in_pixels_s) { |
416 GpuBenchmarkingContext context; | 417 GpuBenchmarkingContext context; |
417 if (!context.Init(false)) | 418 if (!context.Init(false)) |
418 return false; | 419 return false; |
419 scoped_refptr<CallbackAndContext> callback_and_context = | 420 scoped_refptr<CallbackAndContext> callback_and_context = |
420 new CallbackAndContext(isolate, callback, | 421 new CallbackAndContext(isolate, callback, |
421 context.web_frame()->mainWorldScriptContext()); | 422 context.web_frame()->mainWorldScriptContext()); |
422 | 423 |
423 scoped_ptr<SyntheticSmoothDragGestureParams> gesture_params( | 424 std::unique_ptr<SyntheticSmoothDragGestureParams> gesture_params( |
424 new SyntheticSmoothDragGestureParams); | 425 new SyntheticSmoothDragGestureParams); |
425 | 426 |
426 // Convert coordinates from CSS pixels to density independent pixels (DIPs). | 427 // Convert coordinates from CSS pixels to density independent pixels (DIPs). |
427 float page_scale_factor = context.web_view()->pageScaleFactor(); | 428 float page_scale_factor = context.web_view()->pageScaleFactor(); |
428 | 429 |
429 gesture_params->start_point.SetPoint(start_x * page_scale_factor, | 430 gesture_params->start_point.SetPoint(start_x * page_scale_factor, |
430 start_y * page_scale_factor); | 431 start_y * page_scale_factor); |
431 gfx::PointF end_point(end_x * page_scale_factor, | 432 gfx::PointF end_point(end_x * page_scale_factor, |
432 end_y * page_scale_factor); | 433 end_y * page_scale_factor); |
433 gfx::Vector2dF distance = end_point - gesture_params->start_point; | 434 gfx::Vector2dF distance = end_point - gesture_params->start_point; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 !GetOptionalArg(args, &start_y) || | 695 !GetOptionalArg(args, &start_y) || |
695 !GetOptionalArg(args, &speed_in_pixels_s)) { | 696 !GetOptionalArg(args, &speed_in_pixels_s)) { |
696 return false; | 697 return false; |
697 } | 698 } |
698 | 699 |
699 scoped_refptr<CallbackAndContext> callback_and_context = | 700 scoped_refptr<CallbackAndContext> callback_and_context = |
700 new CallbackAndContext(args->isolate(), | 701 new CallbackAndContext(args->isolate(), |
701 callback, | 702 callback, |
702 context.web_frame()->mainWorldScriptContext()); | 703 context.web_frame()->mainWorldScriptContext()); |
703 | 704 |
704 scoped_ptr<SyntheticSmoothScrollGestureParams> gesture_params( | 705 std::unique_ptr<SyntheticSmoothScrollGestureParams> gesture_params( |
705 new SyntheticSmoothScrollGestureParams); | 706 new SyntheticSmoothScrollGestureParams); |
706 | 707 |
707 gesture_params->speed_in_pixels_s = speed_in_pixels_s; | 708 gesture_params->speed_in_pixels_s = speed_in_pixels_s; |
708 | 709 |
709 gesture_params->anchor.SetPoint(start_x * page_scale_factor, | 710 gesture_params->anchor.SetPoint(start_x * page_scale_factor, |
710 start_y * page_scale_factor); | 711 start_y * page_scale_factor); |
711 | 712 |
712 distance_length *= page_scale_factor; | 713 distance_length *= page_scale_factor; |
713 overscroll_length *= page_scale_factor; | 714 overscroll_length *= page_scale_factor; |
714 gfx::Vector2dF distance; | 715 gfx::Vector2dF distance; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 | 759 |
759 | 760 |
760 if (!GetArg(args, &scale_factor) || | 761 if (!GetArg(args, &scale_factor) || |
761 !GetArg(args, &anchor_x) || | 762 !GetArg(args, &anchor_x) || |
762 !GetArg(args, &anchor_y) || | 763 !GetArg(args, &anchor_y) || |
763 !GetOptionalArg(args, &callback) || | 764 !GetOptionalArg(args, &callback) || |
764 !GetOptionalArg(args, &relative_pointer_speed_in_pixels_s)) { | 765 !GetOptionalArg(args, &relative_pointer_speed_in_pixels_s)) { |
765 return false; | 766 return false; |
766 } | 767 } |
767 | 768 |
768 scoped_ptr<SyntheticPinchGestureParams> gesture_params( | 769 std::unique_ptr<SyntheticPinchGestureParams> gesture_params( |
769 new SyntheticPinchGestureParams); | 770 new SyntheticPinchGestureParams); |
770 | 771 |
771 // TODO(bokan): Remove page scale here when change land in Catapult. | 772 // TODO(bokan): Remove page scale here when change land in Catapult. |
772 // Convert coordinates from CSS pixels to density independent pixels (DIPs). | 773 // Convert coordinates from CSS pixels to density independent pixels (DIPs). |
773 float page_scale_factor = context.web_view()->pageScaleFactor(); | 774 float page_scale_factor = context.web_view()->pageScaleFactor(); |
774 | 775 |
775 gesture_params->scale_factor = scale_factor; | 776 gesture_params->scale_factor = scale_factor; |
776 gesture_params->anchor.SetPoint(anchor_x * page_scale_factor, | 777 gesture_params->anchor.SetPoint(anchor_x * page_scale_factor, |
777 anchor_y * page_scale_factor); | 778 anchor_y * page_scale_factor); |
778 gesture_params->relative_pointer_speed_in_pixels_s = | 779 gesture_params->relative_pointer_speed_in_pixels_s = |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT; | 843 int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT; |
843 | 844 |
844 if (!GetArg(args, &position_x) || | 845 if (!GetArg(args, &position_x) || |
845 !GetArg(args, &position_y) || | 846 !GetArg(args, &position_y) || |
846 !GetOptionalArg(args, &callback) || | 847 !GetOptionalArg(args, &callback) || |
847 !GetOptionalArg(args, &duration_ms) || | 848 !GetOptionalArg(args, &duration_ms) || |
848 !GetOptionalArg(args, &gesture_source_type)) { | 849 !GetOptionalArg(args, &gesture_source_type)) { |
849 return false; | 850 return false; |
850 } | 851 } |
851 | 852 |
852 scoped_ptr<SyntheticTapGestureParams> gesture_params( | 853 std::unique_ptr<SyntheticTapGestureParams> gesture_params( |
853 new SyntheticTapGestureParams); | 854 new SyntheticTapGestureParams); |
854 | 855 |
855 // Convert coordinates from CSS pixels to density independent pixels (DIPs). | 856 // Convert coordinates from CSS pixels to density independent pixels (DIPs). |
856 float page_scale_factor = context.web_view()->pageScaleFactor(); | 857 float page_scale_factor = context.web_view()->pageScaleFactor(); |
857 | 858 |
858 gesture_params->position.SetPoint(position_x * page_scale_factor, | 859 gesture_params->position.SetPoint(position_x * page_scale_factor, |
859 position_y * page_scale_factor); | 860 position_y * page_scale_factor); |
860 gesture_params->duration_ms = duration_ms; | 861 gesture_params->duration_ms = duration_ms; |
861 | 862 |
862 if (gesture_source_type < 0 || | 863 if (gesture_source_type < 0 || |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 if (!GetArg(args, &name) || !GetArg(args, &callback) || | 900 if (!GetArg(args, &name) || !GetArg(args, &callback) || |
900 !GetOptionalArg(args, &arguments)) { | 901 !GetOptionalArg(args, &arguments)) { |
901 return 0; | 902 return 0; |
902 } | 903 } |
903 | 904 |
904 scoped_refptr<CallbackAndContext> callback_and_context = | 905 scoped_refptr<CallbackAndContext> callback_and_context = |
905 new CallbackAndContext(args->isolate(), | 906 new CallbackAndContext(args->isolate(), |
906 callback, | 907 callback, |
907 context.web_frame()->mainWorldScriptContext()); | 908 context.web_frame()->mainWorldScriptContext()); |
908 | 909 |
909 scoped_ptr<V8ValueConverter> converter = | 910 std::unique_ptr<V8ValueConverter> converter = |
910 make_scoped_ptr(V8ValueConverter::create()); | 911 base::WrapUnique(V8ValueConverter::create()); |
911 v8::Local<v8::Context> v8_context = callback_and_context->GetContext(); | 912 v8::Local<v8::Context> v8_context = callback_and_context->GetContext(); |
912 scoped_ptr<base::Value> value = | 913 std::unique_ptr<base::Value> value = |
913 make_scoped_ptr(converter->FromV8Value(arguments, v8_context)); | 914 base::WrapUnique(converter->FromV8Value(arguments, v8_context)); |
914 | 915 |
915 return context.compositor()->ScheduleMicroBenchmark( | 916 return context.compositor()->ScheduleMicroBenchmark( |
916 name, std::move(value), | 917 name, std::move(value), |
917 base::Bind(&OnMicroBenchmarkCompleted, | 918 base::Bind(&OnMicroBenchmarkCompleted, |
918 base::RetainedRef(callback_and_context))); | 919 base::RetainedRef(callback_and_context))); |
919 } | 920 } |
920 | 921 |
921 bool GpuBenchmarking::SendMessageToMicroBenchmark( | 922 bool GpuBenchmarking::SendMessageToMicroBenchmark( |
922 int id, | 923 int id, |
923 v8::Local<v8::Object> message) { | 924 v8::Local<v8::Object> message) { |
924 GpuBenchmarkingContext context; | 925 GpuBenchmarkingContext context; |
925 if (!context.Init(true)) | 926 if (!context.Init(true)) |
926 return false; | 927 return false; |
927 | 928 |
928 scoped_ptr<V8ValueConverter> converter = | 929 std::unique_ptr<V8ValueConverter> converter = |
929 make_scoped_ptr(V8ValueConverter::create()); | 930 base::WrapUnique(V8ValueConverter::create()); |
930 v8::Local<v8::Context> v8_context = | 931 v8::Local<v8::Context> v8_context = |
931 context.web_frame()->mainWorldScriptContext(); | 932 context.web_frame()->mainWorldScriptContext(); |
932 scoped_ptr<base::Value> value = | 933 std::unique_ptr<base::Value> value = |
933 make_scoped_ptr(converter->FromV8Value(message, v8_context)); | 934 base::WrapUnique(converter->FromV8Value(message, v8_context)); |
934 | 935 |
935 return context.compositor()->SendMessageToMicroBenchmark(id, | 936 return context.compositor()->SendMessageToMicroBenchmark(id, |
936 std::move(value)); | 937 std::move(value)); |
937 } | 938 } |
938 | 939 |
939 bool GpuBenchmarking::HasGpuChannel() { | 940 bool GpuBenchmarking::HasGpuChannel() { |
940 gpu::GpuChannelHost* gpu_channel = | 941 gpu::GpuChannelHost* gpu_channel = |
941 RenderThreadImpl::current()->GetGpuChannel(); | 942 RenderThreadImpl::current()->GetGpuChannel(); |
942 return !!gpu_channel; | 943 return !!gpu_channel; |
943 } | 944 } |
(...skipping 15 matching lines...) Expand all Loading... |
959 &gpu_driver_bug_workarounds))) { | 960 &gpu_driver_bug_workarounds))) { |
960 return; | 961 return; |
961 } | 962 } |
962 | 963 |
963 v8::Local<v8::Value> result; | 964 v8::Local<v8::Value> result; |
964 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) | 965 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) |
965 args->Return(result); | 966 args->Return(result); |
966 } | 967 } |
967 | 968 |
968 } // namespace content | 969 } // namespace content |
OLD | NEW |