Home | History | Annotate | Download | only in dri
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef UI_OZONE_PLATFORM_DRI_SCREEN_MANAGER_H_
      6 #define UI_OZONE_PLATFORM_DRI_SCREEN_MANAGER_H_
      7 
      8 #include <map>
      9 
     10 #include "base/macros.h"
     11 #include "base/memory/weak_ptr.h"
     12 #include "ui/gfx/native_widget_types.h"
     13 #include "ui/ozone/platform/dri/hardware_display_controller.h"
     14 
     15 typedef struct _drmModeModeInfo drmModeModeInfo;
     16 
     17 namespace gfx {
     18 class Point;
     19 class Rect;
     20 class Size;
     21 }  // namespace gfx
     22 
     23 namespace ui {
     24 
     25 class DriWrapper;
     26 class ScanoutSurfaceGenerator;
     27 
     28 // Responsible for keeping track of active displays and configuring them.
     29 class OZONE_EXPORT ScreenManager {
     30  public:
     31   ScreenManager(DriWrapper* dri, ScanoutSurfaceGenerator* surface_generator);
     32   virtual ~ScreenManager();
     33 
     34   // Remove a display controller from the list of active controllers. The
     35   // controller is removed since it was disconnected.
     36   void RemoveDisplayController(uint32_t crtc, uint32_t connector);
     37 
     38   // Configure (and add if not present) a display controller. The display
     39   // controller is identified by (|crtc|, |connector|) and the controller is
     40   // modeset using |mode|.
     41   bool ConfigureDisplayController(uint32_t crtc,
     42                                   uint32_t connector,
     43                                   const drmModeModeInfo& mode);
     44 
     45   // Disable the display controller identified by (|crtc|, |connector|). Note,
     46   // the controller may still be connected, so this does not remove the
     47   // controller.
     48   bool DisableDisplayController(uint32_t crtc, uint32_t connector);
     49 
     50   // Returns a reference to the display controller associated with |widget|.
     51   // This returns a weak reference since the display controller may be destroyed
     52   // at any point in time, but the changes are propagated to the compositor much
     53   // later (Compositor owns SurfaceOzone*, which is responsible for updating the
     54   // display surface).
     55   base::WeakPtr<HardwareDisplayController> GetDisplayController(
     56       gfx::AcceleratedWidget widget);
     57 
     58  private:
     59   typedef std::map<gfx::AcceleratedWidget, HardwareDisplayController*>
     60       HardwareDisplayControllerMap;
     61 
     62   // Returns an iterator into |controllers_| for the controller identified by
     63   // (|crtc|, |connector|).
     64   HardwareDisplayControllerMap::iterator FindDisplayController(
     65       uint32_t crtc, uint32_t connector);
     66 
     67   // On non CrOS builds there is no display configurator to look-up available
     68   // displays and initialize the HDCs. In such cases this is called internally
     69   // to initialize a display.
     70   virtual void ForceInitializationOfPrimaryDisplay();
     71 
     72   DriWrapper* dri_;  // Not owned.
     73   ScanoutSurfaceGenerator* surface_generator_;  // Not owned.
     74   // Mapping between an accelerated widget and an active display.
     75   HardwareDisplayControllerMap controllers_;
     76   gfx::AcceleratedWidget last_added_widget_;
     77 
     78   DISALLOW_COPY_AND_ASSIGN(ScreenManager);
     79 };
     80 
     81 }  // namespace ui
     82 
     83 #endif  // UI_OZONE_PLATFORM_DRI_SCREEN_MANAGER_H_
     84