Upstream version 7.36.149.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 #include "ui/gfx/overlay_transform.h"
16 #include "ui/gfx/rect.h"
17
18 class SkBitmap;
19 class SkCanvas;
20
21 namespace gfx {
22 class VSyncProvider;
23 class OverlayCandidatesOzone;
24 class SurfaceOzoneCanvas;
25 class SurfaceOzoneEGL;
26 typedef intptr_t NativeBufferOzone;
27
28 // The Ozone interface allows external implementations to hook into Chromium to
29 // provide a system specific implementation. The Ozone interface supports two
30 // drawing modes: 1) accelerated drawing through EGL and 2) software drawing
31 // through Skia.
32 //
33 // If you want to paint on a window with ozone, you need to create a
34 // SurfaceOzoneEGL or SurfaceOzoneCanvas for that window. The platform can
35 // support software, EGL, or both for painting on the window.
36 // The following functionality is specific to the drawing mode and may not have
37 // any meaningful implementation in the other mode. An implementation must
38 // provide functionality for at least one mode.
39 //
40 // 1) Accelerated Drawing (EGL path):
41 //
42 // The following functions are specific to EGL:
43 //  - GetNativeDisplay
44 //  - LoadEGLGLES2Bindings
45 //  - GetEGLSurfaceProperties (optional if the properties match the default
46 //  Chromium ones).
47 //  - CreateEGLSurfaceForWidget
48 //
49 // 2) Software Drawing (Skia):
50 //
51 // The following function is specific to the software path:
52 //  - CreateCanvasForWidget
53 //
54 // The accelerated path can optionally provide support for the software drawing
55 // path.
56 //
57 // The remaining functions are not covered since they are needed in both drawing
58 // modes (See comments bellow for descriptions).
59 class GFX_EXPORT SurfaceFactoryOzone {
60  public:
61   // Describes the state of the hardware after initialization.
62   enum HardwareState {
63     UNINITIALIZED,
64     INITIALIZED,
65     FAILED,
66   };
67
68   // Describes overlay buffer format.
69   // TODO: this is a placeholder for now and will be populated with more
70   // formats once we know what sorts of content, video, etc. we can support.
71   enum BufferFormat {
72     UNKNOWN,
73     RGBA_8888,
74     RGB_888,
75   };
76
77   typedef void*(*GLGetProcAddressProc)(const char* name);
78   typedef base::Callback<void(base::NativeLibrary)> AddGLLibraryCallback;
79   typedef base::Callback<void(GLGetProcAddressProc)>
80       SetGLGetProcAddressProcCallback;
81
82   SurfaceFactoryOzone();
83   virtual ~SurfaceFactoryOzone();
84
85   // Returns the instance
86   static SurfaceFactoryOzone* GetInstance();
87
88   // Sets the implementation delegate. Ownership is retained by the caller.
89   static void SetInstance(SurfaceFactoryOzone* impl);
90
91   // Configures the display hardware. Must be called from within the GPU
92   // process before the sandbox has been activated.
93   virtual HardwareState InitializeHardware() = 0;
94
95   // Cleans up display hardware state. Call this from within the GPU process.
96   // This method must be safe to run inside of the sandbox.
97   virtual void ShutdownHardware() = 0;
98
99   // Returns native platform display handle. This is used to obtain the EGL
100   // display connection for the native display.
101   virtual intptr_t GetNativeDisplay();
102
103   // Obtains an AcceleratedWidget backed by a native Linux framebuffer.
104   // The  returned AcceleratedWidget is an opaque token that must realized
105   // before it can be used to create a GL surface.
106   virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0;
107
108   // Create SurfaceOzoneEGL for the specified gfx::AcceleratedWidget.
109   //
110   // Note: When used from content, this is called in the GPU process. The
111   // platform must support creation of SurfaceOzoneEGL from the GPU process
112   // using only the handle contained in gfx::AcceleratedWidget.
113   virtual scoped_ptr<SurfaceOzoneEGL> CreateEGLSurfaceForWidget(
114         gfx::AcceleratedWidget widget);
115
116   // Create SurfaceOzoneCanvas for the specified gfx::AcceleratedWidget.
117   //
118   // Note: The platform must support creation of SurfaceOzoneCanvas from the
119   // Browser Process using only the handle contained in gfx::AcceleratedWidget.
120   virtual scoped_ptr<SurfaceOzoneCanvas> CreateCanvasForWidget(
121         gfx::AcceleratedWidget widget);
122
123   // Sets up GL bindings for the native surface. Takes two callback parameters
124   // that allow Ozone to register the GL bindings.
125   virtual bool LoadEGLGLES2Bindings(
126       AddGLLibraryCallback add_gl_library,
127       SetGLGetProcAddressProcCallback set_gl_get_proc_address) = 0;
128
129   // Returns an array of EGL properties, which can be used in any EGL function
130   // used to select a display configuration. Note that all properties should be
131   // immediately followed by the corresponding desired value and array should be
132   // terminated with EGL_NONE. Ownership of the array is not transferred to
133   // caller. desired_list contains list of desired EGL properties and values.
134   virtual const int32* GetEGLSurfaceProperties(const int32* desired_list);
135
136   // Get the hal struct to check for overlay support.
137   virtual gfx::OverlayCandidatesOzone* GetOverlayCandidates(
138       gfx::AcceleratedWidget w);
139
140   // Sets the overlay plane to switch to at the next page flip.
141   // |plane_z_order| specifies the stacking order of the plane relative to the
142   // main framebuffer located at index 0.
143   // |plane_transform| specifies how the buffer is to be transformed during.
144   // composition.
145   // |buffer| to be presented by the overlay.
146   // |display_bounds| specify where it is supposed to be on the screen.
147   // |crop_rect| specifies the region within the buffer to be placed inside
148   // |display_bounds|.
149   virtual void ScheduleOverlayPlane(gfx::AcceleratedWidget w,
150                                     int plane_z_order,
151                                     gfx::OverlayTransform plane_transform,
152                                     gfx::NativeBufferOzone buffer,
153                                     const gfx::Rect& display_bounds,
154                                     gfx::RectF crop_rect);
155
156   // Cleate a single native buffer to be used for overlay planes.
157   virtual gfx::NativeBufferOzone CreateNativeBuffer(gfx::Size size,
158                                                     BufferFormat format);
159
160  private:
161   static SurfaceFactoryOzone* impl_; // not owned
162 };
163
164 }  // namespace gfx
165
166 #endif  // UI_GFX_OZONE_SURFACE_LNUX_FACTORY_OZONE_H_