Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
test_gl_context.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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.
4
6
7#include <EGL/egl.h>
8#include <EGL/eglext.h>
9#include <EGL/eglplatform.h>
10
11#include <cstring>
12
13#include "flutter/fml/logging.h"
16
17namespace flutter::testing {
18
21 FML_CHECK(display != EGL_NO_DISPLAY);
22
23 auto result = ::eglInitialize(display, nullptr, nullptr);
24 FML_CHECK(result == EGL_TRUE) << GetEGLError();
25
26 config = {0};
27
28 EGLint num_config = 0;
29 const EGLint attribute_list[] = {EGL_RED_SIZE,
30 8,
31 EGL_GREEN_SIZE,
32 8,
33 EGL_BLUE_SIZE,
34 8,
35 EGL_ALPHA_SIZE,
36 8,
37 EGL_SURFACE_TYPE,
38 EGL_PBUFFER_BIT,
39 EGL_CONFORMANT,
40 EGL_OPENGL_ES2_BIT,
41 EGL_RENDERABLE_TYPE,
42 EGL_OPENGL_ES2_BIT,
43 EGL_NONE};
44
45 result = ::eglChooseConfig(display, attribute_list, &config, 1, &num_config);
46 FML_CHECK(result == EGL_TRUE) << GetEGLError();
47 FML_CHECK(num_config == 1) << GetEGLError();
48
49 {
50 const EGLint context_attributes[] = {
51 EGL_CONTEXT_CLIENT_VERSION, //
52 2, //
53 EGL_NONE //
54 };
55
57 ::eglCreateContext(display, // display connection
58 config, // config
59 EGL_NO_CONTEXT, // sharegroup
60 context_attributes // context attributes
61 );
62 FML_CHECK(onscreen_context != EGL_NO_CONTEXT) << GetEGLError();
63
65 ::eglCreateContext(display, // display connection
66 config, // config
67 onscreen_context, // sharegroup
68 context_attributes // context attributes
69 );
70 FML_CHECK(offscreen_context != EGL_NO_CONTEXT) << GetEGLError();
71 }
72}
73
75 auto result = ::eglDestroyContext(display, onscreen_context);
76 FML_CHECK(result == EGL_TRUE) << GetEGLError();
77
78 result = ::eglDestroyContext(display, offscreen_context);
79 FML_CHECK(result == EGL_TRUE) << GetEGLError();
80
81 result = ::eglTerminate(display);
82 FML_CHECK(result == EGL_TRUE);
83}
84
85} // namespace flutter::testing
#define FML_CHECK(condition)
Definition logging.h:104
EGLDisplay CreateSwangleDisplay()
Creates an EGLDisplay using ANGLE with the Vulkan backend and SwiftShader as the device type.
std::string GetEGLError()