flutter_flutter/ui/gl/gl_surface_android.cc
James Robinson ff14e2c399 Remove users and delete //third_party/khronos headers
This stops using the GL/EGL/etc headers in //third_party/khronos on all
platforms and deletes them.  On Android, we use the EGL and OpenGL
headers from the Android NDK and define the enum values from the
following extensions if the platform does not provide them:

https://www.khronos.org/registry/egl/extensions/NV/EGL_NV_post_sub_buffer.txt
https://www.khronos.org/registry/egl/extensions/EXT/EGL_EXT_create_context_robustness.txt

On Linux we just need to know enough to talk to X in the theoretical
case that we want to swap OSMesa-produced pixels to an X window.

On Mac/iOS we're already using the headers from the relevant Frameworks.
2015-09-02 10:33:14 -07:00

103 lines
2.9 KiB
C++

// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gl/gl_surface.h"
#include <EGL/egl.h>
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface_egl.h"
#include "ui/gl/gl_surface_osmesa.h"
#include "ui/gl/gl_surface_stub.h"
namespace gfx {
// static
bool GLSurface::InitializeOneOffInternal() {
auto implementation = GetGLImplementation();
switch (implementation) {
case kGLImplementationEGLGLES2:
if (!GLSurfaceEGL::InitializeOneOff()) {
LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
return false;
}
break;
default:
LOG(ERROR)
<< "Unknown GL implementation returned from GetGLImplementation: "
<< implementation;
return false;
}
return true;
}
// static
scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
gfx::AcceleratedWidget window,
const gfx::SurfaceConfiguration& requested_configuration) {
CHECK_NE(kGLImplementationNone, GetGLImplementation());
if (GetGLImplementation() == kGLImplementationOSMesaGL) {
scoped_refptr<GLSurface> surface(
new GLSurfaceOSMesaHeadless(requested_configuration));
if (!surface->Initialize())
return NULL;
return surface;
}
DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2);
if (window != kNullAcceleratedWidget) {
scoped_refptr<GLSurface> surface =
new NativeViewGLSurfaceEGL(window, requested_configuration);
if (surface->Initialize())
return surface;
} else {
scoped_refptr<GLSurface> surface =
new GLSurfaceStub(requested_configuration);
if (surface->Initialize())
return surface;
}
return NULL;
}
// static
scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
const gfx::Size& size,
const gfx::SurfaceConfiguration& requested_configuration) {
CHECK_NE(kGLImplementationNone, GetGLImplementation());
switch (GetGLImplementation()) {
case kGLImplementationOSMesaGL: {
scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(
OSMesaSurfaceFormatBGRA, size, requested_configuration));
if (!surface->Initialize())
return NULL;
return surface;
}
case kGLImplementationEGLGLES2: {
scoped_refptr<GLSurface> surface;
if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() &&
(size.width() == 0 && size.height() == 0)) {
surface = new SurfacelessEGL(size, requested_configuration);
} else {
surface = new PbufferGLSurfaceEGL(size, requested_configuration);
}
if (!surface->Initialize())
return NULL;
return surface;
}
default:
NOTREACHED();
return NULL;
}
}
EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() {
return EGL_DEFAULT_DISPLAY;
}
} // namespace gfx