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

Side by Side Diff: content/renderer/pepper/pepper_plugin_instance_impl.cc

Issue 252663002: Track plugin input event latency (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix win & mac build Created 6 years, 6 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
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/pepper/pepper_plugin_instance_impl.h" 5 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_offset_string_conversions.h" 16 #include "base/strings/utf_offset_string_conversions.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "cc/base/latency_info_swap_promise.h"
19 #include "cc/layers/texture_layer.h" 20 #include "cc/layers/texture_layer.h"
21 #include "cc/trees/layer_tree_host.h"
20 #include "content/common/content_constants_internal.h" 22 #include "content/common/content_constants_internal.h"
23 #include "content/common/input/web_input_event_traits.h"
21 #include "content/public/common/content_switches.h" 24 #include "content/public/common/content_switches.h"
22 #include "content/public/common/page_zoom.h" 25 #include "content/public/common/page_zoom.h"
23 #include "content/public/renderer/content_renderer_client.h" 26 #include "content/public/renderer/content_renderer_client.h"
27 #include "content/renderer/gpu/render_widget_compositor.h"
24 #include "content/renderer/pepper/common.h" 28 #include "content/renderer/pepper/common.h"
25 #include "content/renderer/pepper/content_decryptor_delegate.h" 29 #include "content/renderer/pepper/content_decryptor_delegate.h"
26 #include "content/renderer/pepper/event_conversion.h" 30 #include "content/renderer/pepper/event_conversion.h"
27 #include "content/renderer/pepper/fullscreen_container.h" 31 #include "content/renderer/pepper/fullscreen_container.h"
28 #include "content/renderer/pepper/gfx_conversion.h" 32 #include "content/renderer/pepper/gfx_conversion.h"
29 #include "content/renderer/pepper/host_dispatcher_wrapper.h" 33 #include "content/renderer/pepper/host_dispatcher_wrapper.h"
30 #include "content/renderer/pepper/host_globals.h" 34 #include "content/renderer/pepper/host_globals.h"
31 #include "content/renderer/pepper/message_channel.h" 35 #include "content/renderer/pepper/message_channel.h"
32 #include "content/renderer/pepper/npapi_glue.h" 36 #include "content/renderer/pepper/npapi_glue.h"
33 #include "content/renderer/pepper/pepper_browser_connection.h" 37 #include "content/renderer/pepper/pepper_browser_connection.h"
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 virtual bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) 401 virtual bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event)
398 OVERRIDE { 402 OVERRIDE {
399 plugin_->HandleMouseLockedInputEvent(event); 403 plugin_->HandleMouseLockedInputEvent(event);
400 return true; 404 return true;
401 } 405 }
402 406
403 private: 407 private:
404 PepperPluginInstanceImpl* plugin_; 408 PepperPluginInstanceImpl* plugin_;
405 }; 409 };
406 410
411 void InitLatencyInfo(ui::LatencyInfo* new_latency,
412 const ui::LatencyInfo* old_latency,
413 blink::WebInputEvent::Type type,
414 int64 input_sequence) {
415 new_latency->AddLatencyNumber(
416 ui::INPUT_EVENT_LATENCY_BEGIN_PLUGIN_COMPONENT,
417 0,
418 input_sequence);
419 new_latency->TraceEventType(WebInputEventTraits::GetName(type));
420 if (old_latency) {
421 new_latency->CopyLatencyFrom(*old_latency,
422 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT);
423 new_latency->CopyLatencyFrom(*old_latency,
424 ui::INPUT_EVENT_LATENCY_UI_COMPONENT);
425 }
426 }
427
407 } // namespace 428 } // namespace
408 429
409 // static 430 // static
410 PepperPluginInstanceImpl* PepperPluginInstanceImpl::Create( 431 PepperPluginInstanceImpl* PepperPluginInstanceImpl::Create(
411 RenderFrameImpl* render_frame, 432 RenderFrameImpl* render_frame,
412 PluginModule* module, 433 PluginModule* module,
413 WebPluginContainer* container, 434 WebPluginContainer* container,
414 const GURL& plugin_url) { 435 const GURL& plugin_url) {
415 base::Callback<const void*(const char*)> get_plugin_interface_func = 436 base::Callback<const void*(const char*)> get_plugin_interface_func =
416 base::Bind(&PluginModule::GetPluginInterface, module); 437 base::Bind(&PluginModule::GetPluginInterface, module);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 text_input_caret_bounds_(0, 0, 0, 0), 552 text_input_caret_bounds_(0, 0, 0, 0),
532 text_input_caret_set_(false), 553 text_input_caret_set_(false),
533 selection_caret_(0), 554 selection_caret_(0),
534 selection_anchor_(0), 555 selection_anchor_(0),
535 pending_user_gesture_(0.0), 556 pending_user_gesture_(0.0),
536 document_loader_(NULL), 557 document_loader_(NULL),
537 external_document_load_(false), 558 external_document_load_(false),
538 npp_(new NPP_t), 559 npp_(new NPP_t),
539 isolate_(v8::Isolate::GetCurrent()), 560 isolate_(v8::Isolate::GetCurrent()),
540 is_deleted_(false), 561 is_deleted_(false),
562 last_input_number_(0),
563 is_tracking_latency_(false),
541 view_change_weak_ptr_factory_(this), 564 view_change_weak_ptr_factory_(this),
542 weak_factory_(this) { 565 weak_factory_(this) {
543 pp_instance_ = HostGlobals::Get()->AddInstance(this); 566 pp_instance_ = HostGlobals::Get()->AddInstance(this);
544 567
545 memset(&current_print_settings_, 0, sizeof(current_print_settings_)); 568 memset(&current_print_settings_, 0, sizeof(current_print_settings_));
546 module_->InstanceCreated(this); 569 module_->InstanceCreated(this);
547 570
548 if (render_frame) { // NULL in tests 571 if (render_frame) { // NULL in tests
549 render_frame->render_view()->PepperInstanceCreated(this); 572 render_frame->render_view()->PepperInstanceCreated(this);
550 // Bind a callback now so that we can inform the RenderViewImpl when we are 573 // Bind a callback now so that we can inform the RenderViewImpl when we are
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 // event. This allows out-of-process plugins to respond to the user 1115 // event. This allows out-of-process plugins to respond to the user
1093 // gesture after processing has finished here. 1116 // gesture after processing has finished here.
1094 if (WebUserGestureIndicator::isProcessingUserGesture()) { 1117 if (WebUserGestureIndicator::isProcessingUserGesture()) {
1095 pending_user_gesture_ = 1118 pending_user_gesture_ =
1096 ppapi::EventTimeToPPTimeTicks(event.timeStampSeconds); 1119 ppapi::EventTimeToPPTimeTicks(event.timeStampSeconds);
1097 pending_user_gesture_token_ = 1120 pending_user_gesture_token_ =
1098 WebUserGestureIndicator::currentUserGestureToken(); 1121 WebUserGestureIndicator::currentUserGestureToken();
1099 pending_user_gesture_token_.setOutOfProcess(); 1122 pending_user_gesture_token_.setOutOfProcess();
1100 } 1123 }
1101 1124
1125 const ui::LatencyInfo* current_event_latency_info = NULL;
1126 if (render_frame_->GetRenderWidget()) {
1127 current_event_latency_info =
1128 render_frame_->GetRenderWidget()->current_event_latency_info();
1129 }
1130
1102 // Each input event may generate more than one PP_InputEvent. 1131 // Each input event may generate more than one PP_InputEvent.
1103 for (size_t i = 0; i < events.size(); i++) { 1132 for (size_t i = 0; i < events.size(); i++) {
1133 if (is_tracking_latency_) {
1134 InitLatencyInfo(&events[i].latency_info,
1135 current_event_latency_info,
1136 event.type,
1137 last_input_number_++);
1138 }
1104 if (filtered_input_event_mask_ & event_class) 1139 if (filtered_input_event_mask_ & event_class)
1105 events[i].is_filtered = true; 1140 events[i].is_filtered = true;
1106 else 1141 else
1107 rv = true; // Unfiltered events are assumed to be handled. 1142 rv = true; // Unfiltered events are assumed to be handled.
1108 scoped_refptr<PPB_InputEvent_Shared> event_resource( 1143 scoped_refptr<PPB_InputEvent_Shared> event_resource(
1109 new PPB_InputEvent_Shared( 1144 new PPB_InputEvent_Shared(
1110 ppapi::OBJECT_IS_IMPL, pp_instance(), events[i])); 1145 ppapi::OBJECT_IS_IMPL, pp_instance(), events[i]));
1111 1146
1112 rv |= PP_ToBool(plugin_input_event_interface_->HandleInputEvent( 1147 rv |= PP_ToBool(plugin_input_event_interface_->HandleInputEvent(
1113 pp_instance(), event_resource->pp_resource())); 1148 pp_instance(), event_resource->pp_resource()));
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 scoped_ptr<cc::SingleReleaseCallback>* release_callback, 2024 scoped_ptr<cc::SingleReleaseCallback>* release_callback,
1990 bool use_shared_memory) { 2025 bool use_shared_memory) {
1991 if (!bound_graphics_2d_platform_) 2026 if (!bound_graphics_2d_platform_)
1992 return false; 2027 return false;
1993 return bound_graphics_2d_platform_->PrepareTextureMailbox(mailbox, 2028 return bound_graphics_2d_platform_->PrepareTextureMailbox(mailbox,
1994 release_callback); 2029 release_callback);
1995 } 2030 }
1996 2031
1997 void PepperPluginInstanceImpl::OnDestruct() { render_frame_ = NULL; } 2032 void PepperPluginInstanceImpl::OnDestruct() { render_frame_ = NULL; }
1998 2033
2034 void PepperPluginInstanceImpl::AddLatencyInfo(
2035 const std::vector<ui::LatencyInfo>& latency_info) {
2036 if (render_frame_ && render_frame_->GetRenderWidget()) {
2037 RenderWidgetCompositor* compositor =
2038 render_frame_->GetRenderWidget()->compositor();
2039 if (compositor) {
2040 for (size_t i = 0; i < latency_info.size(); i++) {
2041 scoped_ptr<cc::SwapPromise> swap_promise(
2042 new cc::LatencyInfoSwapPromise(latency_info[i]));
2043 compositor->QueueSwapPromise(swap_promise.Pass());
2044 }
2045 }
2046 }
2047 }
2048
1999 void PepperPluginInstanceImpl::AddPluginObject(PluginObject* plugin_object) { 2049 void PepperPluginInstanceImpl::AddPluginObject(PluginObject* plugin_object) {
2000 DCHECK(live_plugin_objects_.find(plugin_object) == 2050 DCHECK(live_plugin_objects_.find(plugin_object) ==
2001 live_plugin_objects_.end()); 2051 live_plugin_objects_.end());
2002 live_plugin_objects_.insert(plugin_object); 2052 live_plugin_objects_.insert(plugin_object);
2003 } 2053 }
2004 2054
2005 void PepperPluginInstanceImpl::RemovePluginObject(PluginObject* plugin_object) { 2055 void PepperPluginInstanceImpl::RemovePluginObject(PluginObject* plugin_object) {
2006 // Don't actually verify that the object is in the set since during module 2056 // Don't actually verify that the object is in the set since during module
2007 // deletion we'll be in the process of freeing them. 2057 // deletion we'll be in the process of freeing them.
2008 live_plugin_objects_.erase(plugin_object); 2058 live_plugin_objects_.erase(plugin_object);
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
2498 return ValidateRequestInputEvents(true, event_classes); 2548 return ValidateRequestInputEvents(true, event_classes);
2499 } 2549 }
2500 2550
2501 void PepperPluginInstanceImpl::ClearInputEventRequest(PP_Instance instance, 2551 void PepperPluginInstanceImpl::ClearInputEventRequest(PP_Instance instance,
2502 uint32_t event_classes) { 2552 uint32_t event_classes) {
2503 input_event_mask_ &= ~(event_classes); 2553 input_event_mask_ &= ~(event_classes);
2504 filtered_input_event_mask_ &= ~(event_classes); 2554 filtered_input_event_mask_ &= ~(event_classes);
2505 RequestInputEventsHelper(event_classes); 2555 RequestInputEventsHelper(event_classes);
2506 } 2556 }
2507 2557
2558 void PepperPluginInstanceImpl::StartTrackingLatency(PP_Instance instance) {
2559 if (module_->permissions().HasPermission(ppapi::PERMISSION_PRIVATE))
2560 is_tracking_latency_ = true;
2561 }
2562
2508 void PepperPluginInstanceImpl::ZoomChanged(PP_Instance instance, 2563 void PepperPluginInstanceImpl::ZoomChanged(PP_Instance instance,
2509 double factor) { 2564 double factor) {
2510 // We only want to tell the page to change its zoom if the whole page is the 2565 // We only want to tell the page to change its zoom if the whole page is the
2511 // plugin. If we're in an iframe, then don't do anything. 2566 // plugin. If we're in an iframe, then don't do anything.
2512 if (!IsFullPagePlugin()) 2567 if (!IsFullPagePlugin())
2513 return; 2568 return;
2514 container()->zoomLevelChanged(content::ZoomFactorToZoomLevel(factor)); 2569 container()->zoomLevelChanged(content::ZoomFactorToZoomLevel(factor));
2515 } 2570 }
2516 2571
2517 void PepperPluginInstanceImpl::ZoomLimitsChanged(PP_Instance instance, 2572 void PepperPluginInstanceImpl::ZoomLimitsChanged(PP_Instance instance,
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
3144 // Running out-of-process. Initiate an IPC call to notify the plugin 3199 // Running out-of-process. Initiate an IPC call to notify the plugin
3145 // process. 3200 // process.
3146 ppapi::proxy::HostDispatcher* dispatcher = 3201 ppapi::proxy::HostDispatcher* dispatcher =
3147 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); 3202 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance());
3148 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( 3203 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad(
3149 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); 3204 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data));
3150 } 3205 }
3151 } 3206 }
3152 3207
3153 } // namespace content 3208 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_plugin_instance_impl.h ('k') | content/renderer/pepper/plugin_module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698