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/buffer_types.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/ozone/ozone_base_export.h"
20 class SurfaceOzoneCanvas
;
21 class SurfaceOzoneEGL
;
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
28 // If you want to paint on a window with ozone, you need to create a
29 // SurfaceOzoneEGL or SurfaceOzoneCanvas for that window. The platform can
30 // support software, EGL, or both for painting on the window.
31 // The following functionality is specific to the drawing mode and may not have
32 // any meaningful implementation in the other mode. An implementation must
33 // provide functionality for at least one mode.
35 // 1) Accelerated Drawing (EGL path):
37 // The following functions are specific to EGL:
39 // - LoadEGLGLES2Bindings
40 // - GetEGLSurfaceProperties (optional if the properties match the default
42 // - CreateEGLSurfaceForWidget
44 // 2) Software Drawing (Skia):
46 // The following function is specific to the software path:
47 // - CreateCanvasForWidget
49 // The accelerated path can optionally provide support for the software drawing
52 // The remaining functions are not covered since they are needed in both drawing
53 // modes (See comments bellow for descriptions).
54 class OZONE_BASE_EXPORT SurfaceFactoryOzone
{
56 typedef void* (*GLGetProcAddressProc
)(const char* name
);
57 typedef base::Callback
<void(base::NativeLibrary
)> AddGLLibraryCallback
;
58 typedef base::Callback
<void(GLGetProcAddressProc
)>
59 SetGLGetProcAddressProcCallback
;
61 // Returns native platform display handle. This is used to obtain the EGL
62 // display connection for the native display.
63 virtual intptr_t GetNativeDisplay();
65 // Create SurfaceOzoneEGL for the specified gfx::AcceleratedWidget.
67 // Note: When used from content, this is called in the GPU process. The
68 // platform must support creation of SurfaceOzoneEGL from the GPU process
69 // using only the handle contained in gfx::AcceleratedWidget.
70 virtual scoped_ptr
<SurfaceOzoneEGL
> CreateEGLSurfaceForWidget(
71 gfx::AcceleratedWidget widget
);
73 // Create an EGL surface that isn't backed by any buffers, and is used
74 // for overlay-only displays. This will return NULL if this mode is
76 virtual scoped_ptr
<SurfaceOzoneEGL
> CreateSurfacelessEGLSurfaceForWidget(
77 gfx::AcceleratedWidget widget
);
79 // Create SurfaceOzoneCanvas for the specified gfx::AcceleratedWidget.
81 // Note: The platform must support creation of SurfaceOzoneCanvas from the
82 // Browser Process using only the handle contained in gfx::AcceleratedWidget.
83 virtual scoped_ptr
<SurfaceOzoneCanvas
> CreateCanvasForWidget(
84 gfx::AcceleratedWidget widget
);
86 // Sets up GL bindings for the native surface. Takes two callback parameters
87 // that allow Ozone to register the GL bindings.
88 virtual bool LoadEGLGLES2Bindings(
89 AddGLLibraryCallback add_gl_library
,
90 SetGLGetProcAddressProcCallback set_gl_get_proc_address
) = 0;
92 // Returns an array of EGL properties, which can be used in any EGL function
93 // used to select a display configuration. Note that all properties should be
94 // immediately followed by the corresponding desired value and array should be
95 // terminated with EGL_NONE. Ownership of the array is not transferred to
96 // caller. desired_list contains list of desired EGL properties and values.
97 virtual const int32
* GetEGLSurfaceProperties(const int32
* desired_list
);
99 // Create a single native buffer to be used for overlay planes or zero copy
100 // for |widget| representing a particular display controller or default
101 // display controller for kNullAcceleratedWidget.
102 // It can be called on any thread.
103 virtual scoped_refptr
<NativePixmap
> CreateNativePixmap(
104 gfx::AcceleratedWidget widget
,
106 gfx::BufferFormat format
,
107 gfx::BufferUsage usage
);
110 SurfaceFactoryOzone();
111 virtual ~SurfaceFactoryOzone();
114 DISALLOW_COPY_AND_ASSIGN(SurfaceFactoryOzone
);
119 #endif // UI_OZONE_PUBLIC_SURFACE_FACTORY_OZONE_H_