blob: 696a86f06b22523293eb43a25c2830bcda1b9b11 [file] [log] [blame]
Joe Gregorioa8fabd32017-05-31 09:45:19 -04001/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "fiddle_main.h"
9
10#include <EGL/egl.h>
Joe Gregorio97b10ac2017-06-01 13:24:11 -040011#include <GLES2/gl2.h>
Joe Gregorioa8fabd32017-05-31 09:45:19 -040012
13static const EGLint configAttribs[] = {
14 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
15 EGL_BLUE_SIZE, 8,
16 EGL_GREEN_SIZE, 8,
17 EGL_RED_SIZE, 8,
18 EGL_DEPTH_SIZE, 8,
19 EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
20 EGL_NONE
21};
22
23static const int pbufferWidth = 9;
24static const int pbufferHeight = 9;
25
26static const EGLint pbufferAttribs[] = {
27 EGL_WIDTH, pbufferWidth,
28 EGL_HEIGHT, pbufferHeight,
29 EGL_NONE,
30};
31
32// create_grcontext implementation for EGL.
Joe Gregorio97b10ac2017-06-01 13:24:11 -040033sk_sp<GrContext> create_grcontext(std::ostringstream &driverinfo) {
Joe Gregorioa8fabd32017-05-31 09:45:19 -040034 EGLDisplay eglDpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
35 if (EGL_NO_DISPLAY == eglDpy) {
36 return nullptr;
37 }
38
39 EGLint major, minor;
40 if (EGL_TRUE != eglInitialize(eglDpy, &major, &minor)) {
41 return nullptr;
42 }
43
44 EGLint numConfigs;
45 EGLConfig eglCfg;
46 if (EGL_TRUE != eglChooseConfig(eglDpy, configAttribs, &eglCfg, 1, &numConfigs)) {
47 return nullptr;
48 }
49
50 EGLSurface eglSurf = eglCreatePbufferSurface(eglDpy, eglCfg, pbufferAttribs);
51 if (EGL_NO_SURFACE == eglSurf) {
52 return nullptr;
53 }
54
55 if (EGL_TRUE != eglBindAPI(EGL_OPENGL_API)) {
56 return nullptr;
57 }
58
59 EGLContext eglCtx = eglCreateContext(eglDpy, eglCfg, EGL_NO_CONTEXT, NULL);
60 if (EGL_NO_CONTEXT == eglCtx) {
61 return nullptr;
62 }
63 if (EGL_FALSE == eglMakeCurrent(eglDpy, eglSurf, eglSurf, eglCtx)) {
64 return nullptr;
65 }
66
Joe Gregorio97b10ac2017-06-01 13:24:11 -040067 driverinfo << "EGL " << major << "." << minor << "\n";
68 GrGLGetStringProc getString = (GrGLGetStringProc )eglGetProcAddress("glGetString");
69 driverinfo << "GL Versionr: " << getString(GL_VERSION) << "\n";
70 driverinfo << "GL Vendor: " << getString(GL_VENDOR) << "\n";
71 driverinfo << "GL Renderer: " << getString(GL_RENDERER) << "\n";
72 driverinfo << "GL Extensions: " << getString(GL_EXTENSIONS) << "\n";
73
Joe Gregorioa8fabd32017-05-31 09:45:19 -040074 auto interface = GrGLCreateNativeInterface();
75 if (!interface) {
76 return nullptr;
77 }
78 eglTerminate(eglDpy);
79
Greg Daniel02611d92017-07-25 10:05:01 -040080 return sk_sp<GrContext>(GrContext::MakeGL(interface));
Joe Gregorioa8fabd32017-05-31 09:45:19 -040081}