| 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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 bool IsRateLimitedEventType(ui::Event* event) { | 24 bool IsRateLimitedEventType(ui::Event* event) { |
| 25 return event->type() == ui::ET_MOUSE_MOVED || | 25 return event->type() == ui::ET_MOUSE_MOVED || |
| 26 event->type() == ui::ET_MOUSE_DRAGGED || | 26 event->type() == ui::ET_MOUSE_DRAGGED || |
| 27 event->type() == ui::ET_TOUCH_MOVED; | 27 event->type() == ui::ET_TOUCH_MOVED; |
| 28 } | 28 } |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 class NativeViewportImpl | 32 class NativeViewportImpl |
| 33 : public InterfaceImpl<mojo::NativeViewport>, | 33 : public InterfaceImplDeleteOnError<mojo::NativeViewport>, |
| 34 public NativeViewportDelegate { | 34 public NativeViewportDelegate { |
| 35 public: | 35 public: |
| 36 NativeViewportImpl(ApplicationConnection* connection, | 36 explicit NativeViewportImpl(shell::Context* context) |
| 37 shell::Context* context) | |
| 38 : context_(context), | 37 : context_(context), |
| 39 widget_(gfx::kNullAcceleratedWidget), | 38 widget_(gfx::kNullAcceleratedWidget), |
| 40 waiting_for_event_ack_(false), | 39 waiting_for_event_ack_(false), |
| 41 weak_factory_(this) {} | 40 weak_factory_(this) {} |
| 42 virtual ~NativeViewportImpl() { | 41 virtual ~NativeViewportImpl() { |
| 43 // Destroy the NativeViewport early on as it may call us back during | 42 // Destroy the NativeViewport early on as it may call us back during |
| 44 // destruction and we want to be in a known state. | 43 // destruction and we want to be in a known state. |
| 45 native_viewport_.reset(); | 44 native_viewport_.reset(); |
| 46 } | 45 } |
| 47 | 46 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 private: | 144 private: |
| 146 shell::Context* context_; | 145 shell::Context* context_; |
| 147 gfx::AcceleratedWidget widget_; | 146 gfx::AcceleratedWidget widget_; |
| 148 scoped_ptr<services::NativeViewport> native_viewport_; | 147 scoped_ptr<services::NativeViewport> native_viewport_; |
| 149 InterfaceRequest<CommandBuffer> command_buffer_request_; | 148 InterfaceRequest<CommandBuffer> command_buffer_request_; |
| 150 scoped_ptr<CommandBufferImpl> command_buffer_; | 149 scoped_ptr<CommandBufferImpl> command_buffer_; |
| 151 bool waiting_for_event_ack_; | 150 bool waiting_for_event_ack_; |
| 152 base::WeakPtrFactory<NativeViewportImpl> weak_factory_; | 151 base::WeakPtrFactory<NativeViewportImpl> weak_factory_; |
| 153 }; | 152 }; |
| 154 | 153 |
| 155 class NVSDelegate : public ApplicationDelegate { | 154 class NVSDelegate : public ApplicationDelegate, |
| 155 public InterfaceProvider<mojo::NativeViewport> { |
| 156 public: | 156 public: |
| 157 NVSDelegate(shell::Context* context) : context_(context) {} | 157 NVSDelegate(shell::Context* context) : context_(context) {} |
| 158 virtual ~NVSDelegate() {} | 158 virtual ~NVSDelegate() {} |
| 159 | 159 |
| 160 // ApplicationDelegate implementation. |
| 160 virtual bool ConfigureIncomingConnection( | 161 virtual bool ConfigureIncomingConnection( |
| 161 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { | 162 ApplicationConnection* connection) OVERRIDE { |
| 162 connection->AddService<NativeViewportImpl>(context_); | 163 connection->AddServiceProvider(this); |
| 163 return true; | 164 return true; |
| 164 } | 165 } |
| 165 | 166 |
| 167 // InterfaceProvider<mojo::NativeViewport> implementation. |
| 168 virtual void BindToRequest( |
| 169 ApplicationConnection* connection, |
| 170 InterfaceRequest<mojo::NativeViewport> request) OVERRIDE { |
| 171 mojo::BindToRequest(new NativeViewportImpl(context_), &request); |
| 172 } |
| 173 |
| 166 private: | 174 private: |
| 167 mojo::shell::Context* context_; | 175 mojo::shell::Context* context_; |
| 168 }; | 176 }; |
| 169 | 177 |
| 170 } // namespace services | 178 } // namespace services |
| 171 } // namespace mojo | 179 } // namespace mojo |
| 172 | 180 |
| 173 MOJO_NATIVE_VIEWPORT_EXPORT mojo::ApplicationImpl* | 181 MOJO_NATIVE_VIEWPORT_EXPORT mojo::ApplicationImpl* |
| 174 CreateNativeViewportService( | 182 CreateNativeViewportService( |
| 175 mojo::shell::Context* context, | 183 mojo::shell::Context* context, |
| 176 mojo::ScopedMessagePipeHandle service_provider_handle) { | 184 mojo::ScopedMessagePipeHandle service_provider_handle) { |
| 177 mojo::ApplicationImpl* app = new mojo::ApplicationImpl( | 185 mojo::ApplicationImpl* app = new mojo::ApplicationImpl( |
| 178 new mojo::services::NVSDelegate(context), service_provider_handle.Pass()); | 186 new mojo::services::NVSDelegate(context), service_provider_handle.Pass()); |
| 179 return app; | 187 return app; |
| 180 } | 188 } |
| OLD | NEW |