Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / ui / ozone / platform / dri / dri_surface_factory.h
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 "third_party/skia/include/core/SkBitmap.h"
12 #include "ui/ozone/platform/dri/hardware_cursor_delegate.h"
13 #include "ui/ozone/public/surface_factory_ozone.h"
14
15 namespace ui {
16
17 class DriBuffer;
18 class DriWrapper;
19 class ScreenManager;
20 class SurfaceOzoneCanvas;
21
22 // SurfaceFactoryOzone implementation on top of DRM/KMS using dumb buffers.
23 // This implementation is used in conjunction with the software rendering
24 // path.
25 class DriSurfaceFactory : public ui::SurfaceFactoryOzone,
26                           public HardwareCursorDelegate {
27  public:
28   static const gfx::AcceleratedWidget kDefaultWidgetHandle;
29
30   DriSurfaceFactory(DriWrapper* drm, ScreenManager* screen_manager);
31   virtual ~DriSurfaceFactory();
32
33   // Describes the state of the hardware after initialization.
34   enum HardwareState {
35     UNINITIALIZED,
36     INITIALIZED,
37     FAILED,
38   };
39
40   // Open the display device.
41   virtual HardwareState InitializeHardware();
42
43   // Close the display device.
44   virtual void ShutdownHardware();
45
46   virtual scoped_ptr<ui::SurfaceOzoneCanvas> CreateCanvasForWidget(
47       gfx::AcceleratedWidget w) OVERRIDE;
48   virtual bool LoadEGLGLES2Bindings(
49       AddGLLibraryCallback add_gl_library,
50       SetGLGetProcAddressProcCallback set_gl_get_proc_address) OVERRIDE;
51
52   // Create a new window/surface/widget identifier.
53   gfx::AcceleratedWidget GetAcceleratedWidget();
54
55   // Determine dimensions of a widget.
56   gfx::Size GetWidgetSize(gfx::AcceleratedWidget w);
57
58   // HardwareCursorDelegate:
59   virtual void SetHardwareCursor(gfx::AcceleratedWidget window,
60                                  const SkBitmap& image,
61                                  const gfx::Point& location) 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(gfx::AcceleratedWidget w);
68
69   DriWrapper* drm_;  // Not owned.
70   ScreenManager* screen_manager_;  // Not owned.
71   HardwareState state_;
72
73   // Active outputs.
74   int allocated_widgets_;
75
76   scoped_refptr<DriBuffer> cursor_buffers_[2];
77   int cursor_frontbuffer_;
78
79   SkBitmap cursor_bitmap_;
80   gfx::Point cursor_location_;
81
82   DISALLOW_COPY_AND_ASSIGN(DriSurfaceFactory);
83 };
84
85 }  // namespace ui
86
87 #endif  // UI_OZONE_PLATFORM_DRI_DRI_SURFACE_FACTORY_H_