Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / gfx / ozone / surface_factory_ozone.h
1 // Copyright (c) 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 #ifndef UI_GFX_OZONE_SURFACE_LNUX_FACTORY_OZONE_H_
6 #define UI_GFX_OZONE_SURFACE_LNUX_FACTORY_OZONE_H_
7
8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/native_library.h"
11 #include "ui/gfx/geometry/point.h"
12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/gfx/gfx_export.h"
14 #include "ui/gfx/native_widget_types.h"
15
16 class SkBitmap;
17 class SkCanvas;
18
19 namespace gfx {
20 class Screen;
21 class VSyncProvider;
22
23 // The Ozone interface allows external implementations to hook into Chromium to
24 // provide a system specific implementation. The Ozone interface supports two
25 // drawing modes: 1) accelerated drawing through EGL and 2) software drawing
26 // through Skia.
27 //
28 // The following functionality is specific to the drawing mode and may not have
29 // any meaningful implementation in the other mode. An implementation must
30 // provide functionality for at least one mode.
31 //
32 // 1) Accelerated Drawing (EGL path):
33 //
34 // The following functions are specific to EGL:
35 //  - GetNativeDisplay
36 //  - LoadEGLGLES2Bindings
37 //  - GetEGLSurfaceProperties (optional if the properties match the default
38 //  Chromium ones).
39 //
40 // 2) Software Drawing (Skia):
41 //
42 // The following function is specific to the software path:
43 //  - GetCanvasForWidget
44 //
45 // The accelerated path can optionally provide support for the software drawing
46 // path.
47 //
48 // The remaining functions are not covered since they are needed in both drawing
49 // modes (See comments bellow for descriptions).
50 class GFX_EXPORT SurfaceFactoryOzone {
51  public:
52   // Describes the state of the hardware after initialization.
53   enum HardwareState {
54     UNINITIALIZED,
55     INITIALIZED,
56     FAILED,
57   };
58
59   typedef void*(*GLGetProcAddressProc)(const char* name);
60   typedef base::Callback<void(base::NativeLibrary)> AddGLLibraryCallback;
61   typedef base::Callback<void(GLGetProcAddressProc)>
62       SetGLGetProcAddressProcCallback;
63
64   SurfaceFactoryOzone();
65   virtual ~SurfaceFactoryOzone();
66
67   // Returns the instance
68   static SurfaceFactoryOzone* GetInstance();
69
70   // Sets the implementation delegate. Ownership is retained by the caller.
71   static void SetInstance(SurfaceFactoryOzone* impl);
72
73   // TODO(rjkroege): decide how to separate screen/display stuff from SFOz
74   // This method implements gfx::Screen, particularly useful in Desktop Aura.
75   virtual gfx::Screen* CreateDesktopScreen();
76
77   // Configures the display hardware. Must be called from within the GPU
78   // process before the sandbox has been activated.
79   virtual HardwareState InitializeHardware() = 0;
80
81   // Cleans up display hardware state. Call this from within the GPU process.
82   // This method must be safe to run inside of the sandbox.
83   virtual void ShutdownHardware() = 0;
84
85   // Returns native platform display handle. This is used to obtain the EGL
86   // display connection for the native display.
87   virtual intptr_t GetNativeDisplay();
88
89   // Obtains an AcceleratedWidget backed by a native Linux framebuffer.
90   // The  returned AcceleratedWidget is an opaque token that must realized
91   // before it can be used to create a GL surface.
92   virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0;
93
94   // Realizes an AcceleratedWidget so that the returned AcceleratedWidget
95   // can be used to to create a GLSurface. This method may only be called in
96   // a process that has a valid GL context.
97   virtual gfx::AcceleratedWidget RealizeAcceleratedWidget(
98       gfx::AcceleratedWidget w) = 0;
99
100   // Sets up GL bindings for the native surface. Takes two callback parameters
101   // that allow Ozone to register the GL bindings.
102   virtual bool LoadEGLGLES2Bindings(
103       AddGLLibraryCallback add_gl_library,
104       SetGLGetProcAddressProcCallback set_gl_get_proc_address) = 0;
105
106   // If possible attempts to resize the given AcceleratedWidget instance and if
107   // a resize action was performed returns true, otherwise false (native
108   // hardware may only support a single fixed size).
109   virtual bool AttemptToResizeAcceleratedWidget(
110       gfx::AcceleratedWidget w,
111       const gfx::Rect& bounds) = 0;
112
113   // Called after the appropriate GL swap buffers command. Used if extra work
114   // is needed to perform the actual buffer swap.
115   virtual bool SchedulePageFlip(gfx::AcceleratedWidget w);
116
117   // Returns a SkCanvas for the backing buffers. Drawing to the canvas will draw
118   // to the native surface. The canvas is intended for use when no EGL
119   // acceleration is possible. Its implementation is optional when an EGL
120   // backend is provided for rendering.
121   virtual SkCanvas* GetCanvasForWidget(gfx::AcceleratedWidget w);
122
123   // Returns a gfx::VsyncProvider for the provided AcceleratedWidget. Note
124   // that this may be called after we have entered the sandbox so if there are
125   // operations (e.g. opening a file descriptor providing vsync events) that
126   // must be done outside of the sandbox, they must have been completed
127   // in InitializeHardware. Returns an empty scoped_ptr on error.
128   virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider(
129       gfx::AcceleratedWidget w) = 0;
130
131   // Returns an array of EGL properties, which can be used in any EGL function
132   // used to select a display configuration. Note that all properties should be
133   // immediately followed by the corresponding desired value and array should be
134   // terminated with EGL_NONE. Ownership of the array is not transferred to
135   // caller. desired_list contains list of desired EGL properties and values.
136   virtual const int32* GetEGLSurfaceProperties(const int32* desired_list);
137
138   // Sets the cursor image to |image|.
139   virtual void SetCursorImage(const SkBitmap& image);
140
141   // Sets the cursor position to |location|.
142   virtual void MoveCursorTo(const gfx::Point& location);
143
144  private:
145   static SurfaceFactoryOzone* impl_; // not owned
146 };
147
148 }  // namespace gfx
149
150 #endif  // UI_GFX_OZONE_SURFACE_LNUX_FACTORY_OZONE_H_