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 "third_party/khronos/EGL/egl.h"
10 #include "ui/gfx/native_widget_types.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 (!GLSurfaceEGL::InitializeOneOff()) {
23 LOG(ERROR
) << "GLSurfaceEGL::InitializeOneOff failed.";
33 scoped_refptr
<GLSurface
> GLSurface::CreateViewGLSurface(
34 gfx::AcceleratedWidget window
) {
35 CHECK_NE(kGLImplementationNone
, GetGLImplementation());
36 if (GetGLImplementation() == kGLImplementationOSMesaGL
) {
37 scoped_refptr
<GLSurface
> surface(new GLSurfaceOSMesaHeadless());
38 if (!surface
->Initialize())
42 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2
);
43 if (window
!= kNullAcceleratedWidget
) {
44 scoped_refptr
<GLSurface
> surface
= new NativeViewGLSurfaceEGL(window
);
45 if (surface
->Initialize())
48 scoped_refptr
<GLSurface
> surface
= new GLSurfaceStub();
49 if (surface
->Initialize())
56 scoped_refptr
<GLSurface
> GLSurface::CreateOffscreenGLSurface(
57 const gfx::Size
& size
) {
58 CHECK_NE(kGLImplementationNone
, GetGLImplementation());
59 switch (GetGLImplementation()) {
60 case kGLImplementationOSMesaGL
: {
61 scoped_refptr
<GLSurface
> surface(
62 new GLSurfaceOSMesa(OSMesaSurfaceFormatBGRA
, size
));
63 if (!surface
->Initialize())
68 case kGLImplementationEGLGLES2
: {
69 scoped_refptr
<GLSurface
> surface
;
70 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() &&
71 (size
.width() == 0 && size
.height() == 0)) {
72 surface
= new SurfacelessEGL(size
);
74 surface
= new PbufferGLSurfaceEGL(size
);
77 if (!surface
->Initialize())
81 case kGLImplementationMockGL
:
82 return new GLSurfaceStub
;
89 EGLNativeDisplayType
GetPlatformDefaultEGLNativeDisplay() {
90 return EGL_DEFAULT_DISPLAY
;