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
3 // found in the LICENSE file.
5 #include "ui/ozone/platform/dri/ozone_platform_dri.h"
7 #include "base/at_exit.h"
8 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h"
9 #include "ui/events/ozone/device/device_manager.h"
10 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
11 #include "ui/events/ozone/evdev/event_factory_evdev.h"
12 #include "ui/ozone/platform/dri/dri_buffer.h"
13 #include "ui/ozone/platform/dri/dri_cursor.h"
14 #include "ui/ozone/platform/dri/dri_surface_factory.h"
15 #include "ui/ozone/platform/dri/dri_window.h"
16 #include "ui/ozone/platform/dri/dri_window_delegate_impl.h"
17 #include "ui/ozone/platform/dri/dri_window_delegate_manager.h"
18 #include "ui/ozone/platform/dri/dri_window_manager.h"
19 #include "ui/ozone/platform/dri/dri_wrapper.h"
20 #include "ui/ozone/platform/dri/screen_manager.h"
21 #include "ui/ozone/platform/dri/virtual_terminal_manager.h"
22 #include "ui/ozone/public/ozone_platform.h"
24 #if defined(OS_CHROMEOS)
25 #include "ui/ozone/platform/dri/chromeos/native_display_delegate_dri.h"
32 const char kDefaultGraphicsCardPath[] = "/dev/dri/card0";
34 // OzonePlatform for Linux DRI (Direct Rendering Infrastructure)
36 // This platform is Linux without any display server (no X, wayland, or
37 // anything). This means chrome alone owns the display and input devices.
38 class OzonePlatformDri : public OzonePlatform {
41 : vt_manager_(new VirtualTerminalManager()),
42 dri_(new DriWrapper(kDefaultGraphicsCardPath)),
43 buffer_generator_(new DriBufferGenerator(dri_.get())),
44 screen_manager_(new ScreenManager(dri_.get(),
45 buffer_generator_.get())),
46 device_manager_(CreateDeviceManager()) {
47 base::AtExitManager::RegisterTask(
48 base::Bind(&base::DeletePointer<OzonePlatformDri>, this));
50 virtual ~OzonePlatformDri() {}
53 virtual ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() OVERRIDE {
54 return surface_factory_ozone_.get();
56 virtual CursorFactoryOzone* GetCursorFactoryOzone() OVERRIDE {
57 return cursor_factory_ozone_.get();
59 virtual GpuPlatformSupport* GetGpuPlatformSupport() OVERRIDE {
60 return NULL; // no GPU support
62 virtual GpuPlatformSupportHost* GetGpuPlatformSupportHost() OVERRIDE {
63 return NULL; // no GPU support
65 virtual scoped_ptr<PlatformWindow> CreatePlatformWindow(
66 PlatformWindowDelegate* delegate,
67 const gfx::Rect& bounds) OVERRIDE {
68 scoped_ptr<DriWindow> platform_window(new DriWindow(
71 scoped_ptr<DriWindowDelegate>(new DriWindowDelegateImpl(
72 window_manager_->NextAcceleratedWidget(), screen_manager_.get())),
73 event_factory_ozone_.get(),
74 &window_delegate_manager_,
75 window_manager_.get()));
76 platform_window->Initialize();
77 return platform_window.PassAs<PlatformWindow>();
79 #if defined(OS_CHROMEOS)
80 virtual scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate()
82 return scoped_ptr<NativeDisplayDelegate>(new NativeDisplayDelegateDri(
83 dri_.get(), screen_manager_.get(), device_manager_.get()));
86 virtual void InitializeUI() OVERRIDE {
88 surface_factory_ozone_.reset(new DriSurfaceFactory(
89 dri_.get(), screen_manager_.get(), &window_delegate_manager_));
90 cursor_factory_ozone_.reset(new BitmapCursorFactoryOzone);
91 window_manager_.reset(new DriWindowManager(surface_factory_ozone_.get()));
92 event_factory_ozone_.reset(new EventFactoryEvdev(window_manager_->cursor(),
93 device_manager_.get()));
94 if (surface_factory_ozone_->InitializeHardware() !=
95 DriSurfaceFactory::INITIALIZED)
96 LOG(FATAL) << "failed to initialize display hardware";
100 virtual void InitializeGPU() OVERRIDE {}
103 scoped_ptr<VirtualTerminalManager> vt_manager_;
104 scoped_ptr<DriWrapper> dri_;
105 scoped_ptr<DriBufferGenerator> buffer_generator_;
106 scoped_ptr<ScreenManager> screen_manager_;
107 scoped_ptr<DeviceManager> device_manager_;
109 scoped_ptr<DriSurfaceFactory> surface_factory_ozone_;
110 scoped_ptr<BitmapCursorFactoryOzone> cursor_factory_ozone_;
111 scoped_ptr<EventFactoryEvdev> event_factory_ozone_;
113 scoped_ptr<DriWindowManager> window_manager_;
114 DriWindowDelegateManager window_delegate_manager_;
116 DISALLOW_COPY_AND_ASSIGN(OzonePlatformDri);
121 OzonePlatform* CreateOzonePlatformDri() { return new OzonePlatformDri; }