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

Side by Side Diff: services/native_viewport/native_viewport_impl.cc

Issue 1029753002: Plumbs through android supplying multipe touch points (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: no pointer Created 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "services/native_viewport/native_viewport_impl.h" 5 #include "services/native_viewport/native_viewport_impl.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "mojo/converters/geometry/geometry_type_converters.h" 12 #include "mojo/converters/geometry/geometry_type_converters.h"
13 #include "mojo/converters/input_events/input_events_type_converters.h"
14 #include "mojo/public/cpp/application/interface_factory.h" 13 #include "mojo/public/cpp/application/interface_factory.h"
15 #include "services/gles2/gpu_state.h" 14 #include "services/gles2/gpu_state.h"
16 #include "services/native_viewport/platform_viewport_headless.h" 15 #include "services/native_viewport/platform_viewport_headless.h"
17 #include "ui/events/event.h" 16 #include "ui/events/event.h"
18 17
19 namespace native_viewport { 18 namespace native_viewport {
20 namespace {
21
22 bool IsRateLimitedEventType(const mojo::EventPtr& event) {
23 return event->action == mojo::EVENT_TYPE_POINTER_MOVE;
24 }
25
26 } // namespace
27 19
28 NativeViewportImpl::NativeViewportImpl( 20 NativeViewportImpl::NativeViewportImpl(
29 bool is_headless, 21 bool is_headless,
30 const scoped_refptr<gles2::GpuState>& gpu_state, 22 const scoped_refptr<gles2::GpuState>& gpu_state,
31 mojo::InterfaceRequest<mojo::NativeViewport> request) 23 mojo::InterfaceRequest<mojo::NativeViewport> request)
32 : is_headless_(is_headless), 24 : is_headless_(is_headless),
33 context_provider_(gpu_state), 25 context_provider_(gpu_state),
34 sent_metrics_(false), 26 sent_metrics_(false),
35 metrics_(mojo::ViewportMetrics::New()), 27 metrics_(mojo::ViewportMetrics::New()),
36 waiting_for_event_ack_(false),
37 binding_(this, request.Pass()), 28 binding_(this, request.Pass()),
38 weak_factory_(this) { 29 weak_factory_(this) {
39 binding_.set_error_handler(this); 30 binding_.set_error_handler(this);
40 } 31 }
41 32
42 NativeViewportImpl::~NativeViewportImpl() { 33 NativeViewportImpl::~NativeViewportImpl() {
43 // Destroy the NativeViewport early on as it may call us back during 34 // Destroy the NativeViewport early on as it may call us back during
44 // destruction and we want to be in a known state. 35 // destruction and we want to be in a known state.
45 platform_viewport_.reset(); 36 platform_viewport_.reset();
46 } 37 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 create_callback_.Run(metrics_.Clone()); 106 create_callback_.Run(metrics_.Clone());
116 sent_metrics_ = true; 107 sent_metrics_ = true;
117 create_callback_.reset(); 108 create_callback_.reset();
118 } 109 }
119 110
120 void NativeViewportImpl::OnAcceleratedWidgetDestroyed() { 111 void NativeViewportImpl::OnAcceleratedWidgetDestroyed() {
121 context_provider_.SetAcceleratedWidget(gfx::kNullAcceleratedWidget); 112 context_provider_.SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
122 } 113 }
123 114
124 bool NativeViewportImpl::OnEvent(mojo::EventPtr event) { 115 bool NativeViewportImpl::OnEvent(mojo::EventPtr event) {
125 if (event.is_null() || !event_dispatcher_.get() || 116 if (event.is_null() || !event_dispatcher_.get())
126 (waiting_for_event_ack_ && IsRateLimitedEventType(event))) {
127 return false; 117 return false;
118
119 mojo::NativeViewportEventDispatcher::OnEventCallback callback;
120 switch (event->action) {
121 case mojo::EVENT_TYPE_POINTER_MOVE: {
122 // TODO(sky): add logic to remember last event location and not send if
123 // the same.
124 if (pointers_waiting_on_ack_.count(event->pointer_data->pointer_id))
125 return false;
126
127 pointers_waiting_on_ack_.insert(event->pointer_data->pointer_id);
128 callback =
129 base::Bind(&NativeViewportImpl::AckEvent, weak_factory_.GetWeakPtr(),
130 event->pointer_data->pointer_id);
131 break;
132 }
133
134 case mojo::EVENT_TYPE_POINTER_CANCEL:
135 pointers_waiting_on_ack_.clear();
136 break;
137
138 case mojo::EVENT_TYPE_POINTER_UP:
139 pointers_waiting_on_ack_.erase(event->pointer_data->pointer_id);
140 break;
141
142 default:
143 break;
128 } 144 }
129 145
130 event_dispatcher_->OnEvent( 146 event_dispatcher_->OnEvent(event.Pass(), callback);
131 event.Pass(),
132 base::Bind(&NativeViewportImpl::AckEvent, weak_factory_.GetWeakPtr()));
133 waiting_for_event_ack_ = true;
134 return false; 147 return false;
135 } 148 }
136 149
137 void NativeViewportImpl::OnDestroyed() { 150 void NativeViewportImpl::OnDestroyed() {
138 // This will signal a connection error and cause us to delete |this|. 151 // This will signal a connection error and cause us to delete |this|.
139 binding_.Close(); 152 binding_.Close();
140 } 153 }
141 154
142 void NativeViewportImpl::OnConnectionError() { 155 void NativeViewportImpl::OnConnectionError() {
143 binding_.set_error_handler(nullptr); 156 binding_.set_error_handler(nullptr);
144 delete this; 157 delete this;
145 } 158 }
146 159
147 void NativeViewportImpl::AckEvent() { 160 void NativeViewportImpl::AckEvent(int32 pointer_id) {
148 waiting_for_event_ack_ = false; 161 pointers_waiting_on_ack_.erase(pointer_id);
149 } 162 }
150 163
151 } // namespace native_viewport 164 } // namespace native_viewport
OLDNEW
« no previous file with comments | « services/native_viewport/native_viewport_impl.h ('k') | services/native_viewport/platform_viewport_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698