OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/ozone/platform/dri/ozone_platform_gbm.h" | 5 #include "ui/ozone/platform/dri/ozone_platform_gbm.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <gbm.h> | 8 #include <gbm.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 | 10 |
11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
12 #include "ui/events/ozone/device/device_manager.h" | 12 #include "ui/events/ozone/device/device_manager.h" |
13 #include "ui/events/ozone/evdev/event_factory_evdev.h" | 13 #include "ui/events/ozone/evdev/event_factory_evdev.h" |
14 #include "ui/ozone/ozone_platform.h" | 14 #include "ui/ozone/ozone_platform.h" |
15 #include "ui/ozone/platform/dri/cursor_factory_evdev_dri.h" | 15 #include "ui/ozone/platform/dri/cursor_factory_evdev_dri.h" |
16 #include "ui/ozone/platform/dri/dri_wrapper.h" | 16 #include "ui/ozone/platform/dri/dri_wrapper.h" |
| 17 #include "ui/ozone/platform/dri/gbm_buffer.h" |
17 #include "ui/ozone/platform/dri/gbm_surface.h" | 18 #include "ui/ozone/platform/dri/gbm_surface.h" |
18 #include "ui/ozone/platform/dri/gbm_surface_factory.h" | 19 #include "ui/ozone/platform/dri/gbm_surface_factory.h" |
19 #include "ui/ozone/platform/dri/gpu_platform_support_gbm.h" | 20 #include "ui/ozone/platform/dri/gpu_platform_support_gbm.h" |
20 #include "ui/ozone/platform/dri/gpu_platform_support_host_gbm.h" | 21 #include "ui/ozone/platform/dri/gpu_platform_support_host_gbm.h" |
21 #include "ui/ozone/platform/dri/scanout_surface.h" | 22 #include "ui/ozone/platform/dri/scanout_surface.h" |
22 #include "ui/ozone/platform/dri/screen_manager.h" | 23 #include "ui/ozone/platform/dri/screen_manager.h" |
23 #include "ui/ozone/platform/dri/virtual_terminal_manager.h" | 24 #include "ui/ozone/platform/dri/virtual_terminal_manager.h" |
24 #include "ui/ozone/public/cursor_factory_ozone.h" | 25 #include "ui/ozone/public/cursor_factory_ozone.h" |
25 #include "ui/ozone/public/gpu_platform_support.h" | 26 #include "ui/ozone/public/gpu_platform_support.h" |
26 #include "ui/ozone/public/gpu_platform_support_host.h" | 27 #include "ui/ozone/public/gpu_platform_support_host.h" |
(...skipping 20 matching lines...) Expand all Loading... |
47 if (glapi_lib_) | 48 if (glapi_lib_) |
48 dlclose(glapi_lib_); | 49 dlclose(glapi_lib_); |
49 } | 50 } |
50 | 51 |
51 gbm_device* device() const { return device_; } | 52 gbm_device* device() const { return device_; } |
52 | 53 |
53 virtual ScanoutSurface* Create(const gfx::Size& size) OVERRIDE { | 54 virtual ScanoutSurface* Create(const gfx::Size& size) OVERRIDE { |
54 return new GbmSurface(device_, dri_, size); | 55 return new GbmSurface(device_, dri_, size); |
55 } | 56 } |
56 | 57 |
57 private: | 58 protected: |
58 DriWrapper* dri_; // Not owned. | 59 DriWrapper* dri_; // Not owned. |
59 | 60 |
60 // HACK: gbm drivers have broken linkage | 61 // HACK: gbm drivers have broken linkage |
61 void *glapi_lib_; | 62 void *glapi_lib_; |
62 | 63 |
63 gbm_device* device_; | 64 gbm_device* device_; |
64 | 65 |
65 DISALLOW_COPY_AND_ASSIGN(GbmSurfaceGenerator); | 66 DISALLOW_COPY_AND_ASSIGN(GbmSurfaceGenerator); |
66 }; | 67 }; |
67 | 68 |
| 69 class GbmEglImageSurfaceGenerator : public GbmSurfaceGenerator { |
| 70 public: |
| 71 GbmEglImageSurfaceGenerator(DriWrapper* dri) : GbmSurfaceGenerator(dri) {} |
| 72 virtual ~GbmEglImageSurfaceGenerator() {} |
| 73 |
| 74 virtual ScanoutSurface* Create(const gfx::Size& size) OVERRIDE { |
| 75 scoped_ptr<GbmBuffer> buffer = |
| 76 scoped_ptr<GbmBuffer>(new GbmBuffer(device_, dri_, size)); |
| 77 if (!buffer->InitializeBuffer(SurfaceFactoryOzone::RGBA_8888, true)) { |
| 78 return NULL; |
| 79 } |
| 80 return buffer.release(); |
| 81 } |
| 82 }; |
| 83 |
68 class OzonePlatformGbm : public OzonePlatform { | 84 class OzonePlatformGbm : public OzonePlatform { |
69 public: | 85 public: |
70 OzonePlatformGbm() { | 86 OzonePlatformGbm(bool use_surfaceless) : use_surfaceless_(use_surfaceless) { |
71 base::AtExitManager::RegisterTask( | 87 base::AtExitManager::RegisterTask( |
72 base::Bind(&base::DeletePointer<OzonePlatformGbm>, this)); | 88 base::Bind(&base::DeletePointer<OzonePlatformGbm>, this)); |
73 } | 89 } |
74 virtual ~OzonePlatformGbm() {} | 90 virtual ~OzonePlatformGbm() {} |
75 | 91 |
76 // OzonePlatform: | 92 // OzonePlatform: |
77 virtual ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() OVERRIDE { | 93 virtual ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() OVERRIDE { |
78 return surface_factory_ozone_.get(); | 94 return surface_factory_ozone_.get(); |
79 } | 95 } |
80 virtual EventFactoryOzone* GetEventFactoryOzone() OVERRIDE { | 96 virtual EventFactoryOzone* GetEventFactoryOzone() OVERRIDE { |
(...skipping 16 matching lines...) Expand all Loading... |
97 virtual scoped_ptr<TouchscreenDeviceManager> | 113 virtual scoped_ptr<TouchscreenDeviceManager> |
98 CreateTouchscreenDeviceManager() OVERRIDE { | 114 CreateTouchscreenDeviceManager() OVERRIDE { |
99 return scoped_ptr<TouchscreenDeviceManager>( | 115 return scoped_ptr<TouchscreenDeviceManager>( |
100 new TouchscreenDeviceManagerOzone()); | 116 new TouchscreenDeviceManagerOzone()); |
101 } | 117 } |
102 #endif | 118 #endif |
103 virtual void InitializeUI() OVERRIDE { | 119 virtual void InitializeUI() OVERRIDE { |
104 vt_manager_.reset(new VirtualTerminalManager()); | 120 vt_manager_.reset(new VirtualTerminalManager()); |
105 // Needed since the browser process creates the accelerated widgets and that | 121 // Needed since the browser process creates the accelerated widgets and that |
106 // happens through SFO. | 122 // happens through SFO. |
107 surface_factory_ozone_.reset(new GbmSurfaceFactory()); | 123 surface_factory_ozone_.reset(new GbmSurfaceFactory(use_surfaceless_)); |
108 | 124 |
109 device_manager_ = CreateDeviceManager(); | 125 device_manager_ = CreateDeviceManager(); |
110 gpu_platform_support_host_.reset(new GpuPlatformSupportHostGbm()); | 126 gpu_platform_support_host_.reset(new GpuPlatformSupportHostGbm()); |
111 cursor_factory_ozone_.reset( | 127 cursor_factory_ozone_.reset( |
112 new CursorFactoryEvdevDri(gpu_platform_support_host_.get())); | 128 new CursorFactoryEvdevDri(gpu_platform_support_host_.get())); |
113 event_factory_ozone_.reset(new EventFactoryEvdev( | 129 event_factory_ozone_.reset(new EventFactoryEvdev( |
114 cursor_factory_ozone_.get(), device_manager_.get())); | 130 cursor_factory_ozone_.get(), device_manager_.get())); |
115 } | 131 } |
116 | 132 |
117 virtual void InitializeGPU() OVERRIDE { | 133 virtual void InitializeGPU() OVERRIDE { |
118 dri_.reset(new DriWrapper(kDefaultGraphicsCardPath)); | 134 dri_.reset(new DriWrapper(kDefaultGraphicsCardPath)); |
119 surface_generator_.reset(new GbmSurfaceGenerator(dri_.get())); | 135 if (use_surfaceless_) |
| 136 surface_generator_.reset(new GbmEglImageSurfaceGenerator(dri_.get())); |
| 137 else |
| 138 surface_generator_.reset(new GbmSurfaceGenerator(dri_.get())); |
120 screen_manager_.reset(new ScreenManager(dri_.get(), | 139 screen_manager_.reset(new ScreenManager(dri_.get(), |
121 surface_generator_.get())); | 140 surface_generator_.get())); |
122 if (!surface_factory_ozone_) | 141 if (!surface_factory_ozone_) |
123 surface_factory_ozone_.reset(new GbmSurfaceFactory()); | 142 surface_factory_ozone_.reset(new GbmSurfaceFactory(use_surfaceless_)); |
124 | 143 |
125 surface_factory_ozone_->InitializeGpu(dri_.get(), | 144 surface_factory_ozone_->InitializeGpu(dri_.get(), |
126 surface_generator_->device(), | 145 surface_generator_->device(), |
127 screen_manager_.get()); | 146 screen_manager_.get()); |
128 | 147 |
129 gpu_platform_support_.reset( | 148 gpu_platform_support_.reset( |
130 new GpuPlatformSupportGbm(surface_factory_ozone_.get())); | 149 new GpuPlatformSupportGbm(surface_factory_ozone_.get())); |
131 } | 150 } |
132 | 151 |
133 private: | 152 private: |
| 153 bool use_surfaceless_; |
134 scoped_ptr<VirtualTerminalManager> vt_manager_; | 154 scoped_ptr<VirtualTerminalManager> vt_manager_; |
135 scoped_ptr<DriWrapper> dri_; | 155 scoped_ptr<DriWrapper> dri_; |
136 scoped_ptr<GbmSurfaceGenerator> surface_generator_; | 156 scoped_ptr<GbmSurfaceGenerator> surface_generator_; |
137 scoped_ptr<ScreenManager> screen_manager_; | 157 scoped_ptr<ScreenManager> screen_manager_; |
138 scoped_ptr<DeviceManager> device_manager_; | 158 scoped_ptr<DeviceManager> device_manager_; |
139 | 159 |
140 scoped_ptr<GbmSurfaceFactory> surface_factory_ozone_; | 160 scoped_ptr<GbmSurfaceFactory> surface_factory_ozone_; |
141 scoped_ptr<CursorFactoryEvdevDri> cursor_factory_ozone_; | 161 scoped_ptr<CursorFactoryEvdevDri> cursor_factory_ozone_; |
142 scoped_ptr<EventFactoryEvdev> event_factory_ozone_; | 162 scoped_ptr<EventFactoryEvdev> event_factory_ozone_; |
143 | 163 |
144 scoped_ptr<GpuPlatformSupportGbm> gpu_platform_support_; | 164 scoped_ptr<GpuPlatformSupportGbm> gpu_platform_support_; |
145 scoped_ptr<GpuPlatformSupportHostGbm> gpu_platform_support_host_; | 165 scoped_ptr<GpuPlatformSupportHostGbm> gpu_platform_support_host_; |
146 | 166 |
147 DISALLOW_COPY_AND_ASSIGN(OzonePlatformGbm); | 167 DISALLOW_COPY_AND_ASSIGN(OzonePlatformGbm); |
148 }; | 168 }; |
149 | 169 |
150 } // namespace | 170 } // namespace |
151 | 171 |
152 OzonePlatform* CreateOzonePlatformGbm() { return new OzonePlatformGbm; } | 172 OzonePlatform* CreateOzonePlatformGbm() { |
| 173 return new OzonePlatformGbm(false); |
| 174 } |
| 175 OzonePlatform* CreateOzonePlatformGbmEglImage() { |
| 176 return new OzonePlatformGbm(true); |
| 177 } |
153 | 178 |
154 } // namespace ui | 179 } // namespace ui |
OLD | NEW |