From eb63642a43967db9c992c0bab8f754f6bcff602e Mon Sep 17 00:00:00 2001 From: "spang@chromium.org" Date: Thu, 17 Jul 2014 11:55:58 +0000 Subject: [PATCH] ozone: Port NativeViewportOzone on top of PlatformWindow This mirrors a similar change to WindowTreeHostOzone. BUG=392280 TEST=built with chromeos==1 use_ozone==1 & ran with egltest Review URL: https://codereview.chromium.org/390493003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283758 0039d316-1c4b-4281-b951-d872f2087c98 --- .../native_viewport/native_viewport_ozone.cc | 88 ++++++++++------------ .../platform/egltest/ozone_platform_egltest.cc | 8 +- 2 files changed, 45 insertions(+), 51 deletions(-) diff --git a/mojo/services/native_viewport/native_viewport_ozone.cc b/mojo/services/native_viewport/native_viewport_ozone.cc index 5e7455e615f1..31e02fe15969 100644 --- a/mojo/services/native_viewport/native_viewport_ozone.cc +++ b/mojo/services/native_viewport/native_viewport_ozone.cc @@ -9,90 +9,80 @@ #include "ui/events/platform/platform_event_source.h" #include "ui/ozone/public/cursor_factory_ozone.h" #include "ui/ozone/public/event_factory_ozone.h" +#include "ui/ozone/public/ozone_platform.h" #include "ui/ozone/public/surface_factory_ozone.h" +#include "ui/platform_window/platform_window.h" +#include "ui/platform_window/platform_window_delegate.h" namespace mojo { namespace services { -bool override_redirect = false; - +// TODO(spang): Deduplicate with NativeViewportX11.. but there's a hack +// in there that prevents this. class NativeViewportOzone : public NativeViewport, - public ui::PlatformEventDispatcher { + public ui::PlatformWindowDelegate { public: - NativeViewportOzone(NativeViewportDelegate* delegate) - : delegate_(delegate), - widget_(gfx::kNullAcceleratedWidget) { - ui::SurfaceFactoryOzone* surface_factory = - ui::SurfaceFactoryOzone::GetInstance(); - widget_ = surface_factory->GetAcceleratedWidget(); - // TODO(sky): need to enable this. - // ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); + explicit NativeViewportOzone(NativeViewportDelegate* delegate) + : delegate_(delegate) { + ui::OzonePlatform::InitializeForUI(); } virtual ~NativeViewportOzone() { - // TODO(sky): need to enable this. - // ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher( - // this); + // Destroy the platform-window while |this| is still alive. + platform_window_.reset(); } private: // Overridden from NativeViewport: virtual void Init(const gfx::Rect& bounds) OVERRIDE { - NOTIMPLEMENTED(); - bounds_ = bounds; - delegate_->OnAcceleratedWidgetAvailable(widget_); + platform_window_ = + ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); } - virtual void Show() OVERRIDE { - NOTIMPLEMENTED(); - } + virtual void Show() OVERRIDE { platform_window_->Show(); } - virtual void Hide() OVERRIDE { - NOTIMPLEMENTED(); - } + virtual void Hide() OVERRIDE { platform_window_->Hide(); } - virtual void Close() OVERRIDE { - delegate_->OnDestroyed(); - } + virtual void Close() OVERRIDE { platform_window_->Close(); } virtual gfx::Size GetSize() OVERRIDE { - return bounds_.size(); + return platform_window_->GetBounds().size(); } virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE { - bounds_ = bounds; - NOTIMPLEMENTED(); + platform_window_->SetBounds(bounds); } - virtual void SetCapture() OVERRIDE { - NOTIMPLEMENTED(); - } + virtual void SetCapture() OVERRIDE { platform_window_->SetCapture(); } + + virtual void ReleaseCapture() OVERRIDE { platform_window_->ReleaseCapture(); } - virtual void ReleaseCapture() OVERRIDE { - NOTIMPLEMENTED(); + // ui::PlatformWindowDelegate: + virtual void OnBoundsChanged(const gfx::Rect& new_bounds) OVERRIDE { + delegate_->OnBoundsChanged(new_bounds); } - // ui::PlatformEventDispatcher: - virtual bool CanDispatchEvent(const ui::PlatformEvent& ne) OVERRIDE { - CHECK(ne); - ui::Event* event = static_cast(ne); - if (event->IsMouseEvent() || event->IsScrollEvent()) { - return ui::CursorFactoryOzone::GetInstance()->GetCursorWindow() == - widget_; - } + virtual void OnDamageRect(const gfx::Rect& damaged_region) OVERRIDE {} - return true; + virtual void DispatchEvent(ui::Event* event) OVERRIDE { + delegate_->OnEvent(event); } - virtual uint32_t DispatchEvent(const ui::PlatformEvent& ne) OVERRIDE { - ui::Event* event = static_cast(ne); - delegate_->OnEvent(event); - return ui::POST_DISPATCH_STOP_PROPAGATION; + virtual void OnCloseRequest() OVERRIDE { platform_window_->Close(); } + + virtual void OnClosed() OVERRIDE { delegate_->OnDestroyed(); } + + virtual void OnWindowStateChanged(ui::PlatformWindowState state) OVERRIDE {} + + virtual void OnLostCapture() OVERRIDE {} + + virtual void OnAcceleratedWidgetAvailable( + gfx::AcceleratedWidget widget) OVERRIDE { + delegate_->OnAcceleratedWidgetAvailable(widget); } + scoped_ptr platform_window_; NativeViewportDelegate* delegate_; - gfx::AcceleratedWidget widget_; - gfx::Rect bounds_; DISALLOW_COPY_AND_ASSIGN(NativeViewportOzone); }; diff --git a/ui/ozone/platform/egltest/ozone_platform_egltest.cc b/ui/ozone/platform/egltest/ozone_platform_egltest.cc index dc34d737e57c..ee424592fc8a 100644 --- a/ui/ozone/platform/egltest/ozone_platform_egltest.cc +++ b/ui/ozone/platform/egltest/ozone_platform_egltest.cc @@ -282,7 +282,9 @@ class OzonePlatformEgltest : public OzonePlatform { virtual void InitializeUI() OVERRIDE { device_manager_ = CreateDeviceManager(); - surface_factory_ozone_.reset(new SurfaceFactoryEgltest(&eglplatform_shim_)); + if (!surface_factory_ozone_) + surface_factory_ozone_.reset( + new SurfaceFactoryEgltest(&eglplatform_shim_)); event_factory_ozone_.reset( new EventFactoryEvdev(NULL, device_manager_.get())); cursor_factory_ozone_.reset(new CursorFactoryOzone()); @@ -290,7 +292,9 @@ class OzonePlatformEgltest : public OzonePlatform { } virtual void InitializeGPU() OVERRIDE { - surface_factory_ozone_.reset(new SurfaceFactoryEgltest(&eglplatform_shim_)); + if (!surface_factory_ozone_) + surface_factory_ozone_.reset( + new SurfaceFactoryEgltest(&eglplatform_shim_)); gpu_platform_support_.reset(CreateStubGpuPlatformSupport()); } -- 2.11.4.GIT