190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// found in the LICENSE file.
490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
56d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#ifndef UI_OZONE_PUBLIC_SURFACE_FACTORY_OZONE_H_
66d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#define UI_OZONE_PUBLIC_SURFACE_FACTORY_OZONE_H_
790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/callback.h"
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/native_library.h"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/gfx/geometry/point.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/gfx/geometry/rect.h"
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/gfx/native_widget_types.h"
14c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "ui/gfx/overlay_transform.h"
15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/gfx/rect.h"
166d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "ui/ozone/ozone_base_export.h"
1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class SkBitmap;
191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class SkCanvas;
201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
216d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)namespace ui {
226d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
23116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass NativePixmap;
24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class OverlayCandidatesOzone;
25c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochclass SurfaceOzoneCanvas;
26c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochclass SurfaceOzoneEGL;
2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// The Ozone interface allows external implementations to hook into Chromium to
291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// provide a system specific implementation. The Ozone interface supports two
301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// drawing modes: 1) accelerated drawing through EGL and 2) software drawing
311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// through Skia.
321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//
33c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch// If you want to paint on a window with ozone, you need to create a
34c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch// SurfaceOzoneEGL or SurfaceOzoneCanvas for that window. The platform can
35c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch// support software, EGL, or both for painting on the window.
361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// The following functionality is specific to the drawing mode and may not have
371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// any meaningful implementation in the other mode. An implementation must
381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// provide functionality for at least one mode.
391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//
401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// 1) Accelerated Drawing (EGL path):
411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//
421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// The following functions are specific to EGL:
431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//  - GetNativeDisplay
441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//  - LoadEGLGLES2Bindings
451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//  - GetEGLSurfaceProperties (optional if the properties match the default
461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//  Chromium ones).
47c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch//  - CreateEGLSurfaceForWidget
481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//
491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// 2) Software Drawing (Skia):
501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//
511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// The following function is specific to the software path:
52c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch//  - CreateCanvasForWidget
531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//
541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// The accelerated path can optionally provide support for the software drawing
551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// path.
561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//
571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// The remaining functions are not covered since they are needed in both drawing
581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// modes (See comments bellow for descriptions).
596d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)class OZONE_BASE_EXPORT SurfaceFactoryOzone {
6090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public:
61a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Describes overlay buffer format.
62a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // TODO: this is a placeholder for now and will be populated with more
63a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // formats once we know what sorts of content, video, etc. we can support.
64a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  enum BufferFormat {
65a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    UNKNOWN,
66a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    RGBA_8888,
6703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    RGBX_8888,
68a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    RGB_888,
69a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  };
70a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
716d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  typedef void* (*GLGetProcAddressProc)(const char* name);
721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  typedef base::Callback<void(base::NativeLibrary)> AddGLLibraryCallback;
731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  typedef base::Callback<void(GLGetProcAddressProc)>
741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      SetGLGetProcAddressProcCallback;
751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
7690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  SurfaceFactoryOzone();
7790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual ~SurfaceFactoryOzone();
7890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
79cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Returns the singleton instance.
803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  static SurfaceFactoryOzone* GetInstance();
8190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Returns native platform display handle. This is used to obtain the EGL
831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // display connection for the native display.
8458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual intptr_t GetNativeDisplay();
8558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
86c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // Create SurfaceOzoneEGL for the specified gfx::AcceleratedWidget.
87e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  //
88e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  // Note: When used from content, this is called in the GPU process. The
89c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // platform must support creation of SurfaceOzoneEGL from the GPU process
90e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  // using only the handle contained in gfx::AcceleratedWidget.
91c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  virtual scoped_ptr<SurfaceOzoneEGL> CreateEGLSurfaceForWidget(
926d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      gfx::AcceleratedWidget widget);
93c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
9403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Create an EGL surface that isn't backed by any buffers, and is used
9503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // for overlay-only displays. This will return NULL if this mode is
9603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // not supported.
9703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  virtual scoped_ptr<SurfaceOzoneEGL> CreateSurfacelessEGLSurfaceForWidget(
9803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      gfx::AcceleratedWidget widget);
9903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
100c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // Create SurfaceOzoneCanvas for the specified gfx::AcceleratedWidget.
101c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  //
102c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // Note: The platform must support creation of SurfaceOzoneCanvas from the
103c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // Browser Process using only the handle contained in gfx::AcceleratedWidget.
104c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  virtual scoped_ptr<SurfaceOzoneCanvas> CreateCanvasForWidget(
1056d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      gfx::AcceleratedWidget widget);
10690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Sets up GL bindings for the native surface. Takes two callback parameters
1081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // that allow Ozone to register the GL bindings.
1091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual bool LoadEGLGLES2Bindings(
1101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      AddGLLibraryCallback add_gl_library,
1111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      SetGLGetProcAddressProcCallback set_gl_get_proc_address) = 0;
11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Returns an array of EGL properties, which can be used in any EGL function
1144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // used to select a display configuration. Note that all properties should be
1154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // immediately followed by the corresponding desired value and array should be
1164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // terminated with EGL_NONE. Ownership of the array is not transferred to
1174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // caller. desired_list contains list of desired EGL properties and values.
1184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual const int32* GetEGLSurfaceProperties(const int32* desired_list);
1194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
120a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Get the hal struct to check for overlay support.
1216d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  virtual OverlayCandidatesOzone* GetOverlayCandidates(
122a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      gfx::AcceleratedWidget w);
123a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
124a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Cleate a single native buffer to be used for overlay planes.
125116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual scoped_refptr<NativePixmap> CreateNativePixmap(
126116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      gfx::Size size,
127116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      BufferFormat format);
128116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
1296e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Sets the overlay plane to switch to at the next page flip.
1306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // |w| specifies the screen to display this overlay plane on.
1316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // |plane_z_order| specifies the stacking order of the plane relative to the
1326e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // main framebuffer located at index 0.
1336e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // |plane_transform| specifies how the buffer is to be transformed during.
1346e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // composition.
1356e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // |buffer| to be presented by the overlay.
1366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // |display_bounds| specify where it is supposed to be on the screen.
1376e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // |crop_rect| specifies the region within the buffer to be placed
1386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // inside |display_bounds|. This is specified in texture coordinates, in the
1396e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // range of [0,1].
1406e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
1416e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                    int plane_z_order,
1426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                    gfx::OverlayTransform plane_transform,
1436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                    scoped_refptr<NativePixmap> buffer,
1446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                    const gfx::Rect& display_bounds,
1456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                    const gfx::RectF& crop_rect);
1466e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
147116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Returns true if overlays can be shown at z-index 0, replacing the main
148116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // surface. Combined with surfaceless extensions, it allows for an
149116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // overlay-only mode.
150116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual bool CanShowPrimaryPlaneAsOverlay();
151a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
152eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch private:
1536d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  static SurfaceFactoryOzone* impl_;  // not owned
15490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)};
15590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1566d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)}  // namespace ui
15790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1586d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#endif  // UI_OZONE_PUBLIC_SURFACE_FACTORY_OZONE_H_
159