| 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 15 matching lines...) Expand all Loading... |
| 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 InterfaceImpl<mojo::NativeViewport>, |
| 34 public NativeViewportDelegate { | 34 public NativeViewportDelegate { |
| 35 public: | 35 public: |
| 36 NativeViewportImpl(ApplicationConnection* connection, | 36 explicit NativeViewportImpl(ApplicationConnection* connection) |
| 37 shell::Context* context) | 37 : widget_(gfx::kNullAcceleratedWidget), |
| 38 : context_(context), | |
| 39 widget_(gfx::kNullAcceleratedWidget), | |
| 40 waiting_for_event_ack_(false), | 38 waiting_for_event_ack_(false), |
| 41 weak_factory_(this) {} | 39 weak_factory_(this) {} |
| 42 virtual ~NativeViewportImpl() { | 40 virtual ~NativeViewportImpl() { |
| 43 // Destroy the NativeViewport early on as it may call us back during | 41 // Destroy the NativeViewport early on as it may call us back during |
| 44 // destruction and we want to be in a known state. | 42 // destruction and we want to be in a known state. |
| 45 native_viewport_.reset(); | 43 native_viewport_.reset(); |
| 46 } | 44 } |
| 47 | 45 |
| 48 virtual void Create(RectPtr bounds) OVERRIDE { | 46 virtual void Create(RectPtr bounds) OVERRIDE { |
| 49 native_viewport_ = | 47 native_viewport_ = services::NativeViewport::Create(this); |
| 50 services::NativeViewport::Create(context_, this); | |
| 51 native_viewport_->Init(bounds.To<gfx::Rect>()); | 48 native_viewport_->Init(bounds.To<gfx::Rect>()); |
| 52 client()->OnCreated(); | 49 client()->OnCreated(); |
| 53 OnBoundsChanged(bounds.To<gfx::Rect>()); | 50 OnBoundsChanged(bounds.To<gfx::Rect>()); |
| 54 } | 51 } |
| 55 | 52 |
| 56 virtual void Show() OVERRIDE { | 53 virtual void Show() OVERRIDE { |
| 57 native_viewport_->Show(); | 54 native_viewport_->Show(); |
| 58 } | 55 } |
| 59 | 56 |
| 60 virtual void Hide() OVERRIDE { | 57 virtual void Hide() OVERRIDE { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 virtual void OnDestroyed() OVERRIDE { | 136 virtual void OnDestroyed() OVERRIDE { |
| 140 client()->OnDestroyed(base::Bind(&NativeViewportImpl::AckDestroyed, | 137 client()->OnDestroyed(base::Bind(&NativeViewportImpl::AckDestroyed, |
| 141 base::Unretained(this))); | 138 base::Unretained(this))); |
| 142 } | 139 } |
| 143 | 140 |
| 144 private: | 141 private: |
| 145 void AckDestroyed() { | 142 void AckDestroyed() { |
| 146 command_buffer_.reset(); | 143 command_buffer_.reset(); |
| 147 } | 144 } |
| 148 | 145 |
| 149 shell::Context* context_; | |
| 150 gfx::AcceleratedWidget widget_; | 146 gfx::AcceleratedWidget widget_; |
| 151 scoped_ptr<services::NativeViewport> native_viewport_; | 147 scoped_ptr<services::NativeViewport> native_viewport_; |
| 152 InterfaceRequest<CommandBuffer> command_buffer_request_; | 148 InterfaceRequest<CommandBuffer> command_buffer_request_; |
| 153 scoped_ptr<CommandBufferImpl> command_buffer_; | 149 scoped_ptr<CommandBufferImpl> command_buffer_; |
| 154 bool waiting_for_event_ack_; | 150 bool waiting_for_event_ack_; |
| 155 base::WeakPtrFactory<NativeViewportImpl> weak_factory_; | 151 base::WeakPtrFactory<NativeViewportImpl> weak_factory_; |
| 156 }; | 152 }; |
| 157 | 153 |
| 158 class NVSDelegate : public ApplicationDelegate { | 154 class NVSDelegate : public ApplicationDelegate { |
| 159 public: | 155 public: |
| 160 NVSDelegate(shell::Context* context) : context_(context) {} | 156 NVSDelegate() {} |
| 161 virtual ~NVSDelegate() {} | 157 virtual ~NVSDelegate() {} |
| 162 | 158 |
| 163 virtual bool ConfigureIncomingConnection( | 159 virtual bool ConfigureIncomingConnection( |
| 164 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { | 160 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { |
| 165 connection->AddService<NativeViewportImpl>(context_); | 161 connection->AddService<NativeViewportImpl>(); |
| 166 return true; | 162 return true; |
| 167 } | 163 } |
| 164 }; |
| 168 | 165 |
| 169 private: | 166 MOJO_NATIVE_VIEWPORT_EXPORT mojo::ApplicationImpl* |
| 170 mojo::shell::Context* context_; | 167 CreateNativeViewportService( |
| 171 }; | 168 ScopedMessagePipeHandle service_provider_handle) { |
| 169 ApplicationImpl* app = new ApplicationImpl( |
| 170 new NVSDelegate(), service_provider_handle.Pass()); |
| 171 return app; |
| 172 } |
| 172 | 173 |
| 173 } // namespace services | 174 } // namespace services |
| 174 } // namespace mojo | 175 } // namespace mojo |
| 175 | 176 |
| 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 |