1 // Copyright 2014 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 #include "ui/gl/gl_surface.h"
7 #include "base/logging.h"
8 #include "base/memory/ref_counted.h"
9 #include "ui/gfx/native_widget_types.h"
10 #include "ui/gfx/ozone/surface_factory_ozone.h"
11 #include "ui/gl/gl_implementation.h"
12 #include "ui/gl/gl_surface_egl.h"
13 #include "ui/gl/gl_surface_osmesa.h"
14 #include "ui/gl/gl_surface_stub.h"
19 bool GLSurface::InitializeOneOffInternal() {
20 switch (GetGLImplementation()) {
21 case kGLImplementationEGLGLES2:
22 if (gfx::SurfaceFactoryOzone::GetInstance()->InitializeHardware() !=
23 gfx::SurfaceFactoryOzone::INITIALIZED) {
24 LOG(ERROR) << "Ozone failed to initialize hardware";
28 if (!GLSurfaceEGL::InitializeOneOff()) {
29 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
39 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
40 gfx::AcceleratedWidget window) {
41 if (GetGLImplementation() == kGLImplementationOSMesaGL) {
42 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless());
43 if (!surface->Initialize())
47 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2);
48 if (window != kNullAcceleratedWidget) {
49 EGLNativeWindowType egl_window =
50 gfx::SurfaceFactoryOzone::GetInstance()->RealizeAcceleratedWidget(
52 scoped_ptr<VSyncProvider> sync_provider =
53 gfx::SurfaceFactoryOzone::GetInstance()->CreateVSyncProvider(
55 scoped_refptr<NativeViewGLSurfaceEGL> surface =
56 new NativeViewGLSurfaceEGL(egl_window);
57 if (surface->Initialize(sync_provider.Pass()))
60 scoped_refptr<GLSurface> surface = new GLSurfaceStub();
61 if (surface->Initialize())
68 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
69 const gfx::Size& size) {
70 switch (GetGLImplementation()) {
71 case kGLImplementationOSMesaGL: {
72 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(1, size));
73 if (!surface->Initialize())
78 case kGLImplementationEGLGLES2: {
79 scoped_refptr<GLSurface> surface;
80 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() &&
81 (size.width() == 1 && size.height() == 1)) {
82 surface = new SurfacelessEGL(size);
84 surface = new PbufferGLSurfaceEGL(size);
86 if (!surface->Initialize())
96 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() {
97 return SurfaceFactoryOzone::GetInstance()->GetNativeDisplay();