Home | History | Annotate | Download | only in dri
      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.
      4 
      5 #include "ui/ozone/platform/dri/ozone_platform_dri.h"
      6 
      7 #include "base/at_exit.h"
      8 #include "ui/events/ozone/device/device_manager.h"
      9 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
     10 #include "ui/events/ozone/evdev/event_factory_evdev.h"
     11 #include "ui/ozone/ozone_platform.h"
     12 #include "ui/ozone/platform/dri/cursor_factory_evdev_dri.h"
     13 #include "ui/ozone/platform/dri/dri_surface.h"
     14 #include "ui/ozone/platform/dri/dri_surface_factory.h"
     15 #include "ui/ozone/platform/dri/dri_wrapper.h"
     16 #include "ui/ozone/platform/dri/scanout_surface.h"
     17 #include "ui/ozone/platform/dri/screen_manager.h"
     18 #include "ui/ozone/platform/dri/virtual_terminal_manager.h"
     19 
     20 #if defined(OS_CHROMEOS)
     21 #include "ui/ozone/common/chromeos/touchscreen_device_manager_ozone.h"
     22 #include "ui/ozone/platform/dri/chromeos/native_display_delegate_dri.h"
     23 #endif
     24 
     25 namespace ui {
     26 
     27 namespace {
     28 
     29 const char kDefaultGraphicsCardPath[] = "/dev/dri/card0";
     30 
     31 class DriSurfaceGenerator : public ScanoutSurfaceGenerator {
     32  public:
     33   DriSurfaceGenerator(DriWrapper* dri) : dri_(dri) {}
     34   virtual ~DriSurfaceGenerator() {}
     35 
     36   virtual ScanoutSurface* Create(const gfx::Size& size) OVERRIDE {
     37     return new DriSurface(dri_, size);
     38   }
     39 
     40  private:
     41   DriWrapper* dri_;  // Not owned.
     42 
     43   DISALLOW_COPY_AND_ASSIGN(DriSurfaceGenerator);
     44 };
     45 
     46 // OzonePlatform for Linux DRI (Direct Rendering Infrastructure)
     47 //
     48 // This platform is Linux without any display server (no X, wayland, or
     49 // anything). This means chrome alone owns the display and input devices.
     50 class OzonePlatformDri : public OzonePlatform {
     51  public:
     52   OzonePlatformDri()
     53       : vt_manager_(new VirtualTerminalManager()),
     54         dri_(new DriWrapper(kDefaultGraphicsCardPath)),
     55         surface_generator_(new DriSurfaceGenerator(dri_.get())),
     56         screen_manager_(new ScreenManager(dri_.get(),
     57                                           surface_generator_.get())),
     58         device_manager_(CreateDeviceManager()) {
     59     base::AtExitManager::RegisterTask(
     60         base::Bind(&base::DeletePointer<OzonePlatformDri>, this));
     61   }
     62   virtual ~OzonePlatformDri() {}
     63 
     64   // OzonePlatform:
     65   virtual ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() OVERRIDE {
     66     return surface_factory_ozone_.get();
     67   }
     68   virtual EventFactoryOzone* GetEventFactoryOzone() OVERRIDE {
     69     return event_factory_ozone_.get();
     70   }
     71   virtual CursorFactoryOzone* GetCursorFactoryOzone() OVERRIDE {
     72     return cursor_factory_ozone_.get();
     73   }
     74   virtual GpuPlatformSupport* GetGpuPlatformSupport() OVERRIDE {
     75     return NULL;  // no GPU support
     76   }
     77   virtual GpuPlatformSupportHost* GetGpuPlatformSupportHost() OVERRIDE {
     78     return NULL;  // no GPU support
     79   }
     80 #if defined(OS_CHROMEOS)
     81   virtual scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate()
     82       OVERRIDE {
     83     return scoped_ptr<NativeDisplayDelegate>(new NativeDisplayDelegateDri(
     84         dri_.get(), screen_manager_.get(), device_manager_.get()));
     85   }
     86   virtual scoped_ptr<TouchscreenDeviceManager>
     87       CreateTouchscreenDeviceManager() OVERRIDE {
     88     return scoped_ptr<TouchscreenDeviceManager>(
     89         new TouchscreenDeviceManagerOzone());
     90   }
     91 #endif
     92   virtual void InitializeUI() OVERRIDE {
     93     surface_factory_ozone_.reset(
     94         new DriSurfaceFactory(dri_.get(), screen_manager_.get()));
     95     cursor_factory_ozone_.reset(
     96         new CursorFactoryEvdevDri(surface_factory_ozone_.get()));
     97     event_factory_ozone_.reset(new EventFactoryEvdev(
     98         cursor_factory_ozone_.get(), device_manager_.get()));
     99   }
    100 
    101   virtual void InitializeGPU() OVERRIDE {}
    102 
    103  private:
    104   scoped_ptr<VirtualTerminalManager> vt_manager_;
    105   scoped_ptr<DriWrapper> dri_;
    106   scoped_ptr<DriSurfaceGenerator> surface_generator_;
    107   scoped_ptr<ScreenManager> screen_manager_;
    108   scoped_ptr<DeviceManager> device_manager_;
    109 
    110   scoped_ptr<DriSurfaceFactory> surface_factory_ozone_;
    111   scoped_ptr<CursorFactoryEvdevDri> cursor_factory_ozone_;
    112   scoped_ptr<EventFactoryEvdev> event_factory_ozone_;
    113 
    114   DISALLOW_COPY_AND_ASSIGN(OzonePlatformDri);
    115 };
    116 
    117 }  // namespace
    118 
    119 OzonePlatform* CreateOzonePlatformDri() { return new OzonePlatformDri; }
    120 
    121 }  // namespace ui
    122