blob: 987b4b333ea3b2abfa60c38105a49991bb757e61 [file] [log] [blame]
Chia-I Wuf2001df2011-07-02 17:57:30 +09001/**************************************************************************
2 *
José Fonseca87712852014-01-17 16:27:50 +00003 * Copyright 2008 VMware, Inc.
Chia-I Wuf2001df2011-07-02 17:57:30 +09004 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5 * Copyright 2010-2011 LunarG, Inc.
6 * All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 *
28 **************************************************************************/
29
30
Brian Paul6052af12008-05-27 16:48:23 -060031/**
32 * Functions for choosing and opening/loading device drivers.
33 */
34
35
Brian Pauladbff7e2005-04-22 21:09:39 +000036#include <assert.h>
Brian Paul11a261e2008-05-28 15:50:58 -060037#include <string.h>
Brian Pauladbff7e2005-04-22 21:09:39 +000038#include <stdio.h>
Brian Paul0c8908c2008-05-28 12:56:36 -060039#include <stdlib.h>
Emil Velikovefe87f12015-03-06 16:54:55 +000040#include "c11/threads.h"
Chia-I Wu1e6c10f2010-05-31 11:47:58 +080041
Brian Paule084fe52008-05-28 15:22:17 -060042#include "egldefines.h"
Brian Pauladbff7e2005-04-22 21:09:39 +000043#include "egldisplay.h"
44#include "egldriver.h"
Brian Paulb711eb72005-11-23 01:38:12 +000045#include "egllog.h"
Brian Pauladbff7e2005-04-22 21:09:39 +000046
Eric Engestrom47273d72017-10-18 17:04:27 +010047#include "util/debug.h"
48
Eric Engestrom9c6fa942020-07-31 01:38:41 +020049extern const _EGLDriver _eglDriver;
Chia-I Wuf2aa3612010-07-04 15:55:12 +080050
Chia-I Wu655e4592011-01-13 00:27:45 +080051/**
Eric Engestromed3f1e02020-07-22 01:19:03 +020052 * Initialize the display using the driver's function.
53 * If the initialisation fails, try again using only software rendering.
Chia-I Wuf2aa3612010-07-04 15:55:12 +080054 */
Eric Engestroma77050c2020-07-22 00:51:51 +020055bool
Eric Engestromed3f1e02020-07-22 01:19:03 +020056_eglInitializeDisplay(_EGLDisplay *disp)
Chia-I Wuf2aa3612010-07-04 15:55:12 +080057{
Eric Engestrom54fa5ec2019-02-02 11:38:45 +000058 assert(!disp->Initialized);
Chia-I Wuf2aa3612010-07-04 15:55:12 +080059
Chia-I Wu655e4592011-01-13 00:27:45 +080060 /* set options */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +000061 disp->Options.ForceSoftware =
Eric Engestrom47273d72017-10-18 17:04:27 +010062 env_var_as_boolean("LIBGL_ALWAYS_SOFTWARE", false);
Chris Wilson863872e2019-10-31 07:29:55 +000063 if (disp->Options.ForceSoftware)
64 _eglLog(_EGL_DEBUG, "Found 'LIBGL_ALWAYS_SOFTWARE' set, will use a CPU renderer");
Chia-I Wuf2aa3612010-07-04 15:55:12 +080065
Eric Engestromad61d4f2018-04-22 16:48:15 +020066 if (_eglDriver.Initialize(disp)) {
Eric Engestrom6d6b82a2020-07-22 01:13:13 +020067 disp->Driver = &_eglDriver;
Eric Engestrom54fa5ec2019-02-02 11:38:45 +000068 disp->Initialized = EGL_TRUE;
Eric Engestrom6d6b82a2020-07-22 01:13:13 +020069 return true;
Chia-I Wuf2aa3612010-07-04 15:55:12 +080070 }
71
Eric Engestrom6d6b82a2020-07-22 01:13:13 +020072 if (disp->Options.ForceSoftware)
73 return false;
74
75 disp->Options.ForceSoftware = EGL_TRUE;
Eric Engestromad61d4f2018-04-22 16:48:15 +020076 if (!_eglDriver.Initialize(disp))
Eric Engestrom6d6b82a2020-07-22 01:13:13 +020077 return false;
78
79 disp->Driver = &_eglDriver;
80 disp->Initialized = EGL_TRUE;
81 return true;
Chia-I Wuf2aa3612010-07-04 15:55:12 +080082}
83
Chia-I Wuf2aa3612010-07-04 15:55:12 +080084__eglMustCastToProperFunctionPointerType
85_eglGetDriverProc(const char *procname)
86{
Eric Engestromf91851e2020-07-22 01:09:56 +020087 if (_eglDriver.GetProcAddress)
Eric Engestroma7d15d22018-04-22 16:48:15 +020088 return _eglDriver.GetProcAddress(procname);
Chia-I Wuf2aa3612010-07-04 15:55:12 +080089
Adam Jacksonb174a1a2017-08-28 11:23:58 -040090 return NULL;
Chia-I Wuf2aa3612010-07-04 15:55:12 +080091}