| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/services/native_viewport/native_viewport_service.h" | 5 #include "mojo/services/native_viewport/native_viewport_service.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "mojo/public/cpp/application/application_delegate.h" | 11 #include "mojo/public/cpp/application/application_delegate.h" |
| 12 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 12 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
| 13 #include "mojo/services/gles2/command_buffer_impl.h" | 13 #include "mojo/services/gles2/command_buffer_impl.h" |
| 14 #include "mojo/services/native_viewport/native_viewport.h" | 14 #include "mojo/services/native_viewport/native_viewport.h" |
| 15 #include "mojo/services/native_viewport/native_viewport_context.h" |
| 15 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 16 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
| 16 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | 17 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
| 17 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.
h" | 18 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.
h" |
| 18 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
| 19 | 20 |
| 20 namespace mojo { | 21 namespace mojo { |
| 21 namespace services { | 22 namespace services { |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 bool IsRateLimitedEventType(ui::Event* event) { | 25 bool IsRateLimitedEventType(ui::Event* event) { |
| 25 return event->type() == ui::ET_MOUSE_MOVED || | 26 return event->type() == ui::ET_MOUSE_MOVED || |
| 26 event->type() == ui::ET_MOUSE_DRAGGED || | 27 event->type() == ui::ET_MOUSE_DRAGGED || |
| 27 event->type() == ui::ET_TOUCH_MOVED; | 28 event->type() == ui::ET_TOUCH_MOVED; |
| 28 } | 29 } |
| 29 | 30 |
| 30 } // namespace | 31 } // namespace |
| 31 | 32 |
| 32 class NativeViewportImpl | 33 class NativeViewportImpl |
| 33 : public InterfaceImpl<mojo::NativeViewport>, | 34 : public InterfaceImpl<mojo::NativeViewport>, |
| 34 public NativeViewportDelegate { | 35 public NativeViewportDelegate { |
| 35 public: | 36 public: |
| 36 NativeViewportImpl(ApplicationConnection* connection, | 37 NativeViewportImpl(ApplicationConnection* connection, |
| 37 shell::Context* context) | 38 NativeViewportContext* context) |
| 38 : context_(context), | 39 : context_(context), |
| 39 widget_(gfx::kNullAcceleratedWidget), | 40 widget_(gfx::kNullAcceleratedWidget), |
| 40 waiting_for_event_ack_(false), | 41 waiting_for_event_ack_(false), |
| 41 weak_factory_(this) {} | 42 weak_factory_(this) {} |
| 42 virtual ~NativeViewportImpl() { | 43 virtual ~NativeViewportImpl() { |
| 43 // Destroy the NativeViewport early on as it may call us back during | 44 // Destroy the NativeViewport early on as it may call us back during |
| 44 // destruction and we want to be in a known state. | 45 // destruction and we want to be in a known state. |
| 45 native_viewport_.reset(); | 46 native_viewport_.reset(); |
| 46 } | 47 } |
| 47 | 48 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 virtual void OnDestroyed() OVERRIDE { | 140 virtual void OnDestroyed() OVERRIDE { |
| 140 client()->OnDestroyed(base::Bind(&NativeViewportImpl::AckDestroyed, | 141 client()->OnDestroyed(base::Bind(&NativeViewportImpl::AckDestroyed, |
| 141 base::Unretained(this))); | 142 base::Unretained(this))); |
| 142 } | 143 } |
| 143 | 144 |
| 144 private: | 145 private: |
| 145 void AckDestroyed() { | 146 void AckDestroyed() { |
| 146 command_buffer_.reset(); | 147 command_buffer_.reset(); |
| 147 } | 148 } |
| 148 | 149 |
| 149 shell::Context* context_; | 150 NativeViewportContext* context_; |
| 150 gfx::AcceleratedWidget widget_; | 151 gfx::AcceleratedWidget widget_; |
| 151 scoped_ptr<services::NativeViewport> native_viewport_; | 152 scoped_ptr<services::NativeViewport> native_viewport_; |
| 152 InterfaceRequest<CommandBuffer> command_buffer_request_; | 153 InterfaceRequest<CommandBuffer> command_buffer_request_; |
| 153 scoped_ptr<CommandBufferImpl> command_buffer_; | 154 scoped_ptr<CommandBufferImpl> command_buffer_; |
| 154 bool waiting_for_event_ack_; | 155 bool waiting_for_event_ack_; |
| 155 base::WeakPtrFactory<NativeViewportImpl> weak_factory_; | 156 base::WeakPtrFactory<NativeViewportImpl> weak_factory_; |
| 156 }; | 157 }; |
| 157 | 158 |
| 158 class NVSDelegate : public ApplicationDelegate { | 159 class NVSDelegate : public ApplicationDelegate { |
| 159 public: | 160 public: |
| 160 NVSDelegate(shell::Context* context) : context_(context) {} | 161 NVSDelegate(NativeViewportContext* context) : context_(context) {} |
| 161 virtual ~NVSDelegate() {} | 162 virtual ~NVSDelegate() {} |
| 162 | 163 |
| 163 virtual bool ConfigureIncomingConnection( | 164 virtual bool ConfigureIncomingConnection( |
| 164 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { | 165 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { |
| 165 connection->AddService<NativeViewportImpl>(context_); | 166 connection->AddService<NativeViewportImpl>(context_); |
| 166 return true; | 167 return true; |
| 167 } | 168 } |
| 168 | 169 |
| 169 private: | 170 private: |
| 170 mojo::shell::Context* context_; | 171 NativeViewportContext* context_; |
| 171 }; | 172 }; |
| 172 | 173 |
| 174 MOJO_NATIVE_VIEWPORT_EXPORT mojo::ApplicationImpl* |
| 175 CreateNativeViewportService( |
| 176 NativeViewportContext* context, |
| 177 ScopedMessagePipeHandle service_provider_handle) { |
| 178 ApplicationImpl* app = new ApplicationImpl( |
| 179 new NVSDelegate(context), service_provider_handle.Pass()); |
| 180 return app; |
| 181 } |
| 182 |
| 173 } // namespace services | 183 } // namespace services |
| 174 } // namespace mojo | 184 } // namespace mojo |
| 175 | 185 |
| 176 MOJO_NATIVE_VIEWPORT_EXPORT mojo::ApplicationImpl* | |
| 177 CreateNativeViewportService( | |
| 178 mojo::shell::Context* context, | |
| 179 mojo::ScopedMessagePipeHandle service_provider_handle) { | |
| 180 mojo::ApplicationImpl* app = new mojo::ApplicationImpl( | |
| 181 new mojo::services::NVSDelegate(context), service_provider_handle.Pass()); | |
| 182 return app; | |
| 183 } | |
| OLD | NEW |