Chia-I Wu | f2001df | 2011-07-02 17:57:30 +0900 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
José Fonseca | 8771285 | 2014-01-17 16:27:50 +0000 | [diff] [blame] | 3 | * Copyright 2008 VMware, Inc. |
Chia-I Wu | f2001df | 2011-07-02 17:57:30 +0900 | [diff] [blame] | 4 | * 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 Paul | 6052af1 | 2008-05-27 16:48:23 -0600 | [diff] [blame] | 31 | /** |
| 32 | * Functions for choosing and opening/loading device drivers. |
| 33 | */ |
| 34 | |
| 35 | |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 36 | #include <assert.h> |
Brian Paul | 11a261e | 2008-05-28 15:50:58 -0600 | [diff] [blame] | 37 | #include <string.h> |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 38 | #include <stdio.h> |
Brian Paul | 0c8908c | 2008-05-28 12:56:36 -0600 | [diff] [blame] | 39 | #include <stdlib.h> |
Emil Velikov | efe87f1 | 2015-03-06 16:54:55 +0000 | [diff] [blame] | 40 | #include "c11/threads.h" |
Chia-I Wu | 1e6c10f | 2010-05-31 11:47:58 +0800 | [diff] [blame] | 41 | |
Brian Paul | e084fe5 | 2008-05-28 15:22:17 -0600 | [diff] [blame] | 42 | #include "egldefines.h" |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 43 | #include "egldisplay.h" |
| 44 | #include "egldriver.h" |
Brian Paul | b711eb7 | 2005-11-23 01:38:12 +0000 | [diff] [blame] | 45 | #include "egllog.h" |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 46 | |
Eric Engestrom | 47273d7 | 2017-10-18 17:04:27 +0100 | [diff] [blame] | 47 | #include "util/debug.h" |
| 48 | |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame] | 49 | extern const _EGLDriver _eglDriver; |
Chia-I Wu | f2aa361 | 2010-07-04 15:55:12 +0800 | [diff] [blame] | 50 | |
Chia-I Wu | 655e459 | 2011-01-13 00:27:45 +0800 | [diff] [blame] | 51 | /** |
Eric Engestrom | ed3f1e0 | 2020-07-22 01:19:03 +0200 | [diff] [blame] | 52 | * Initialize the display using the driver's function. |
| 53 | * If the initialisation fails, try again using only software rendering. |
Chia-I Wu | f2aa361 | 2010-07-04 15:55:12 +0800 | [diff] [blame] | 54 | */ |
Eric Engestrom | a77050c | 2020-07-22 00:51:51 +0200 | [diff] [blame] | 55 | bool |
Eric Engestrom | ed3f1e0 | 2020-07-22 01:19:03 +0200 | [diff] [blame] | 56 | _eglInitializeDisplay(_EGLDisplay *disp) |
Chia-I Wu | f2aa361 | 2010-07-04 15:55:12 +0800 | [diff] [blame] | 57 | { |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 58 | assert(!disp->Initialized); |
Chia-I Wu | f2aa361 | 2010-07-04 15:55:12 +0800 | [diff] [blame] | 59 | |
Chia-I Wu | 655e459 | 2011-01-13 00:27:45 +0800 | [diff] [blame] | 60 | /* set options */ |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 61 | disp->Options.ForceSoftware = |
Eric Engestrom | 47273d7 | 2017-10-18 17:04:27 +0100 | [diff] [blame] | 62 | env_var_as_boolean("LIBGL_ALWAYS_SOFTWARE", false); |
Chris Wilson | 863872e | 2019-10-31 07:29:55 +0000 | [diff] [blame] | 63 | if (disp->Options.ForceSoftware) |
| 64 | _eglLog(_EGL_DEBUG, "Found 'LIBGL_ALWAYS_SOFTWARE' set, will use a CPU renderer"); |
Chia-I Wu | f2aa361 | 2010-07-04 15:55:12 +0800 | [diff] [blame] | 65 | |
Eric Engestrom | ad61d4f | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 66 | if (_eglDriver.Initialize(disp)) { |
Eric Engestrom | 6d6b82a | 2020-07-22 01:13:13 +0200 | [diff] [blame] | 67 | disp->Driver = &_eglDriver; |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 68 | disp->Initialized = EGL_TRUE; |
Eric Engestrom | 6d6b82a | 2020-07-22 01:13:13 +0200 | [diff] [blame] | 69 | return true; |
Chia-I Wu | f2aa361 | 2010-07-04 15:55:12 +0800 | [diff] [blame] | 70 | } |
| 71 | |
Eric Engestrom | 6d6b82a | 2020-07-22 01:13:13 +0200 | [diff] [blame] | 72 | if (disp->Options.ForceSoftware) |
| 73 | return false; |
| 74 | |
| 75 | disp->Options.ForceSoftware = EGL_TRUE; |
Eric Engestrom | ad61d4f | 2018-04-22 16:48:15 +0200 | [diff] [blame] | 76 | if (!_eglDriver.Initialize(disp)) |
Eric Engestrom | 6d6b82a | 2020-07-22 01:13:13 +0200 | [diff] [blame] | 77 | return false; |
| 78 | |
| 79 | disp->Driver = &_eglDriver; |
| 80 | disp->Initialized = EGL_TRUE; |
| 81 | return true; |
Chia-I Wu | f2aa361 | 2010-07-04 15:55:12 +0800 | [diff] [blame] | 82 | } |
| 83 | |
Chia-I Wu | f2aa361 | 2010-07-04 15:55:12 +0800 | [diff] [blame] | 84 | __eglMustCastToProperFunctionPointerType |
| 85 | _eglGetDriverProc(const char *procname) |
| 86 | { |
Eric Engestrom | f91851e | 2020-07-22 01:09:56 +0200 | [diff] [blame] | 87 | if (_eglDriver.GetProcAddress) |
Eric Engestrom | a7d15d2 | 2018-04-22 16:48:15 +0200 | [diff] [blame^] | 88 | return _eglDriver.GetProcAddress(procname); |
Chia-I Wu | f2aa361 | 2010-07-04 15:55:12 +0800 | [diff] [blame] | 89 | |
Adam Jackson | b174a1a | 2017-08-28 11:23:58 -0400 | [diff] [blame] | 90 | return NULL; |
Chia-I Wu | f2aa361 | 2010-07-04 15:55:12 +0800 | [diff] [blame] | 91 | } |