Problem
Ozone platforms need to create custom GLSurfaces but //ui/gl/init needs to depend on //ui/ozone. Since //ui/ozone can't know about GLSurface, //ui/ozone defines a new class SurfaceOzoneEGL that duplicates the parts of GLSurface the Ozone platform needs to customize. This leads to an awkward hierarchy, where GLSurfaceOzoneEGL holds a SurfaceOzoneEGL. We want to add GLX support for Ozone X11 which makes this dependency problem even worse.
Solution
It would be much simpler if the Ozone platform could create an instance of GLSurface and override the parts it wants to customize. To allow for this, refactor //ui/gl/init into two parts, //ui/gl/init and //ui/gl. Functions to create new surfaces, contexts and one-off initialization will be moved to //ui/gl/init. Other existing code, including the definition of GLSurface and GLContext, will stay in //ui/gl.
//ui/gl/init will depend on //ui/ozone and then //ui/ozone will depend on //ui/gl. This will allow each Ozone platform to implement GLSurface (and GLContext for GLX) as appropriate.
One-off GL initialization and the creation of new contexts and surfaces is currently done using static functions on GLSurface and GLContext. The following functions will be moved to //ui/gl/init and out of the GLContext and GLSurface classes.
-gfx::GLContext::CreateGLContext will become gl::init::CreateGLContext
-gfx::GLSurface::InitializeOneOff will become gl::init::InitializeGLOneOff
-gfx::GLSurface::CreateViewGLSurface will become gl::init::CreateViewGLSurface
-gfx::GLSurface::CreateSurfacelessViewGLSurface will become -gl::init::CreateSurfacelessViewGLSurface
-gfx::GLSurface::CreateOffscreenGLSurface will become gl::init::CreateOffscreenGLSurface
The new functions will be defined in ui/gl/init/gl_factory.h in //ui/gl/init. Each platform will have a gl_factory_<platform>.cc implementation that will be conditionally compiled. All callers will be updated to call the functions defined in gl_factory.h. Build targets that need to initialize GL objects will updated to depend on //ui/gl/init (along with roughly equivalent changes for GYP targets).
Step 1
Create gl_factory.h and a single default gl_factory.cc in //ui/gl/init. The implementation for each function in gl_factory.cc will simply call the equivalent existing static function.
gl::init::CreateGLContext from //ui/gl/init will call gfx::GLContext::CreateGLContext from //ui/gl.
gl::init::InitializeGLOneOff from //ui/gl/init will call gfx::GLSurface::InitializeOneOff from //ui/gl.
gl::init::CreateViewGLSurface from //ui/gl/init will call gfx::GLSurface::CreateViewGLSurface from //ui/gl.
gl::init::CreateSurfacelessViewGLSurface from //ui/gl/init will call gfx::GLSurface::CreateSurfacelessViewGLSurface from //ui/gl.
gl::init::CreateOffscreenGLSurface from //ui/gl/init will call gfx::GLSurface::CreateOffscreenGLSurface from //ui/gl.
All call sites of the of existing functions in //ui/gl will be updated to call the new function in //ui/gl/init. The existing functions will be marked as deprecated. This step will update all call sites without making any logic changes.
Step 2
Create gl_factory_<platform>.cc for android, mac, win, x11 and ozone. Move the implementation for the static functions from gl_surface_<platform>.cc and gl_context_<platform>.cc in //ui/gl to gl_factory_<platform>.cc in //ui/gl/init. Some changes to organization will be required as many GLSurface and GLContext subclasses are hidden in anonymous namespaces. This can be done over multiple CLs on a per platform basis. Once this is finished the existing static functions can be removed and the default gl_factory.cc can be deleted.
There will be some other functions in gl_implementation.h / gl_implementation_<platform>.cc that will need to be moved into //ui/gl/init, including things like initializing GL bindings. These functions will end up in gl_factory.h as well.
Step 3
SurfaceFactoryOzone will be refactored to create a GLSurface/GLContext instead of creating a SurfaceOzoneEGL. SurfaceOzoneEGL will be deleted. The gl_factory_ozone.cc implementation will then simply call into SurfaceFactoryOzone.
gl::init::CreateGLContext from //ui/gl/init call ui::SurfaceFactoryOzone::CreateGLContext from //ui/ozone
gl::init::CreateViewGLSurface from //ui/gl/init call ui::init::SurfaceFactoryOzone::CreateViewGLSurface from //ui/ozone
gl::init::CreateSurfacelessViewGLSurface from //ui/gl/init call ui::init::SurfaceFactoryOzone::CreateSurfacelessViewGLSurface from //ui/ozone
Comment 1 by bugdroid1@chromium.org
, May 16 2016