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_DRI_SURFACE_FACTORY_H_
6#define UI_OZONE_PLATFORM_DRI_DRI_SURFACE_FACTORY_H_
7
8#include <map>
9
10#include "base/memory/scoped_ptr.h"
11#include "base/timer/timer.h"
12#include "third_party/skia/include/core/SkBitmap.h"
13#include "ui/ozone/platform/dri/hardware_cursor_delegate.h"
14#include "ui/ozone/public/surface_factory_ozone.h"
15
16namespace ui {
17
18class DriBuffer;
19class DriWindowDelegateManager;
20class DriWrapper;
21class ScreenManager;
22class SurfaceOzoneCanvas;
23
24// SurfaceFactoryOzone implementation on top of DRM/KMS using dumb buffers.
25// This implementation is used in conjunction with the software rendering
26// path.
27class DriSurfaceFactory : public SurfaceFactoryOzone,
28                          public HardwareCursorDelegate {
29 public:
30  static const gfx::AcceleratedWidget kDefaultWidgetHandle;
31
32  DriSurfaceFactory(DriWrapper* drm,
33                    ScreenManager* screen_manager,
34                    DriWindowDelegateManager* window_manager);
35  virtual ~DriSurfaceFactory();
36
37  // Describes the state of the hardware after initialization.
38  enum HardwareState {
39    UNINITIALIZED,
40    INITIALIZED,
41    FAILED,
42  };
43
44  // Open the display device.
45  HardwareState InitializeHardware();
46
47  // Close the display device.
48  void ShutdownHardware();
49
50  // SurfaceFactoryOzone:
51  virtual scoped_ptr<SurfaceOzoneCanvas> CreateCanvasForWidget(
52      gfx::AcceleratedWidget widget) OVERRIDE;
53  virtual bool LoadEGLGLES2Bindings(
54      AddGLLibraryCallback add_gl_library,
55      SetGLGetProcAddressProcCallback set_gl_get_proc_address) OVERRIDE;
56
57  // HardwareCursorDelegate:
58  virtual void SetHardwareCursor(gfx::AcceleratedWidget widget,
59                                 const std::vector<SkBitmap>& bitmaps,
60                                 const gfx::Point& location,
61                                 int frame_delay_ms) OVERRIDE;
62  virtual void MoveHardwareCursor(gfx::AcceleratedWidget window,
63                                  const gfx::Point& location) OVERRIDE;
64
65 protected:
66  // Draw the last set cursor & update the cursor plane.
67  void ResetCursor();
68
69  // Draw next frame in an animated cursor.
70  void OnCursorAnimationTimeout();
71
72  DriWrapper* drm_;  // Not owned.
73  ScreenManager* screen_manager_;  // Not owned.
74  DriWindowDelegateManager* window_manager_;  // Not owned.
75  HardwareState state_;
76
77  scoped_refptr<DriBuffer> cursor_buffers_[2];
78  int cursor_frontbuffer_;
79
80  gfx::AcceleratedWidget cursor_widget_;
81  std::vector<SkBitmap> cursor_bitmaps_;
82  gfx::Point cursor_location_;
83  int cursor_frame_;
84  int cursor_frame_delay_ms_;
85  base::RepeatingTimer<DriSurfaceFactory> cursor_timer_;
86
87  DISALLOW_COPY_AND_ASSIGN(DriSurfaceFactory);
88};
89
90}  // namespace ui
91
92#endif  // UI_OZONE_PLATFORM_DRI_DRI_SURFACE_FACTORY_H_
93