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.
5 #ifndef UI_OZONE_PUBLIC_SURFACE_FACTORY_OZONE_H_
6 #define UI_OZONE_PUBLIC_SURFACE_FACTORY_OZONE_H_
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/native_widget_types.h"
14 #include "ui/gfx/overlay_transform.h"
15 #include "ui/gfx/rect.h"
16 #include "ui/ozone/ozone_base_export.h"
24 class OverlayCandidatesOzone
;
25 class SurfaceOzoneCanvas
;
26 class SurfaceOzoneEGL
;
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
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.
40 // 1) Accelerated Drawing (EGL path):
42 // The following functions are specific to EGL:
44 // - LoadEGLGLES2Bindings
45 // - GetEGLSurfaceProperties (optional if the properties match the default
47 // - CreateEGLSurfaceForWidget
49 // 2) Software Drawing (Skia):
51 // The following function is specific to the software path:
52 // - CreateCanvasForWidget
54 // The accelerated path can optionally provide support for the software drawing
57 // The remaining functions are not covered since they are needed in both drawing
58 // modes (See comments bellow for descriptions).
59 class OZONE_BASE_EXPORT SurfaceFactoryOzone
{
61 // Describes overlay buffer format.
62 // TODO: this is a placeholder for now and will be populated with more
63 // formats once we know what sorts of content, video, etc. we can support.
70 typedef void* (*GLGetProcAddressProc
)(const char* name
);
71 typedef base::Callback
<void(base::NativeLibrary
)> AddGLLibraryCallback
;
72 typedef base::Callback
<void(GLGetProcAddressProc
)>
73 SetGLGetProcAddressProcCallback
;
75 SurfaceFactoryOzone();
76 virtual ~SurfaceFactoryOzone();
78 // Returns the singleton instance.
79 static SurfaceFactoryOzone
* GetInstance();
81 // Returns native platform display handle. This is used to obtain the EGL
82 // display connection for the native display.
83 virtual intptr_t GetNativeDisplay();
85 // Create SurfaceOzoneEGL for the specified gfx::AcceleratedWidget.
87 // Note: When used from content, this is called in the GPU process. The
88 // platform must support creation of SurfaceOzoneEGL from the GPU process
89 // using only the handle contained in gfx::AcceleratedWidget.
90 virtual scoped_ptr
<SurfaceOzoneEGL
> CreateEGLSurfaceForWidget(
91 gfx::AcceleratedWidget widget
);
93 // Create SurfaceOzoneCanvas for the specified gfx::AcceleratedWidget.
95 // Note: The platform must support creation of SurfaceOzoneCanvas from the
96 // Browser Process using only the handle contained in gfx::AcceleratedWidget.
97 virtual scoped_ptr
<SurfaceOzoneCanvas
> CreateCanvasForWidget(
98 gfx::AcceleratedWidget widget
);
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;
106 // Returns an array of EGL properties, which can be used in any EGL function
107 // used to select a display configuration. Note that all properties should be
108 // immediately followed by the corresponding desired value and array should be
109 // terminated with EGL_NONE. Ownership of the array is not transferred to
110 // caller. desired_list contains list of desired EGL properties and values.
111 virtual const int32
* GetEGLSurfaceProperties(const int32
* desired_list
);
113 // Get the hal struct to check for overlay support.
114 virtual OverlayCandidatesOzone
* GetOverlayCandidates(
115 gfx::AcceleratedWidget w
);
117 // Cleate a single native buffer to be used for overlay planes.
118 virtual scoped_refptr
<NativePixmap
> CreateNativePixmap(
120 BufferFormat format
);
122 // Returns true if overlays can be shown at z-index 0, replacing the main
123 // surface. Combined with surfaceless extensions, it allows for an
124 // overlay-only mode.
125 virtual bool CanShowPrimaryPlaneAsOverlay();
128 static SurfaceFactoryOzone
* impl_
; // not owned
133 #endif // UI_OZONE_PUBLIC_SURFACE_FACTORY_OZONE_H_