Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ui / gl / gl_surface_android.cc
blob473425396dc44dd566cec1971045eb5626dcac0e
1 // Copyright (c) 2012 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 <EGL/egl.h>
9 #include "base/logging.h"
10 #include "base/memory/ref_counted.h"
11 #include "ui/gl/android_native_window.h"
12 #include "ui/gl/egl_util.h"
13 #include "ui/gl/gl_bindings.h"
14 #include "ui/gl/gl_context.h"
15 #include "ui/gl/gl_implementation.h"
16 #include "ui/gl/gl_surface_egl.h"
17 #include "ui/gl/gl_surface_stub.h"
19 using ui::GetLastEGLErrorString;
21 namespace gfx {
23 bool GLSurface::InitializeOneOffInternal() {
24 static bool initialized = false;
25 if (initialized)
26 return true;
28 switch (GetGLImplementation()) {
29 case kGLImplementationEGLGLES2:
30 if (!GLSurfaceEGL::InitializeOneOff()) {
31 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
32 return false;
34 break;
35 default:
36 NOTREACHED();
37 break;
40 initialized = true;
41 return true;
43 // static
44 scoped_refptr<GLSurface>
45 GLSurface::CreateViewGLSurface(bool software, gfx::AcceleratedWidget window) {
46 if (software)
47 return NULL;
49 switch (GetGLImplementation()) {
50 case kGLImplementationEGLGLES2: {
51 scoped_refptr<GLSurface> surface;
52 if (window)
53 surface = new NativeViewGLSurfaceEGL(false, window);
54 else
55 surface = new GLSurfaceStub();
56 if (!surface->Initialize())
57 return NULL;
58 return surface;
60 default:
61 NOTREACHED();
62 return NULL;
66 // static
67 scoped_refptr<GLSurface>
68 GLSurface::CreateOffscreenGLSurface(bool software, const gfx::Size& size) {
69 if (software)
70 return NULL;
72 switch (GetGLImplementation()) {
73 case kGLImplementationEGLGLES2: {
74 scoped_refptr<PbufferGLSurfaceEGL> surface(
75 new PbufferGLSurfaceEGL(false, size));
76 if (!surface->Initialize())
77 return NULL;
78 return surface;
80 default:
81 NOTREACHED();
82 return NULL;
86 } // namespace gfx