| 1 | /* |
| 2 | Copyright (c) 2012, Broadcom Europe Ltd |
| 3 | All rights reserved. |
| 4 | |
| 5 | Redistribution and use in source and binary forms, with or without |
| 6 | modification, are permitted provided that the following conditions are met: |
| 7 | * Redistributions of source code must retain the above copyright |
| 8 | notice, this list of conditions and the following disclaimer. |
| 9 | * Redistributions in binary form must reproduce the above copyright |
| 10 | notice, this list of conditions and the following disclaimer in the |
| 11 | documentation and/or other materials provided with the distribution. |
| 12 | * Neither the name of the copyright holder nor the |
| 13 | names of its contributors may be used to endorse or promote products |
| 14 | derived from this software without specific prior written permission. |
| 15 | |
| 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
| 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #define EGL_EGLEXT_PROTOTYPES /* we want the prototypes so the compiler will check that the signatures match */ |
| 29 | |
| 30 | #include "interface/khronos/common/khrn_int_common.h" |
| 31 | |
| 32 | #include "interface/khronos/common/khrn_client.h" |
| 33 | #include "interface/khronos/common/khrn_client_rpc.h" |
| 34 | |
| 35 | #include "interface/khronos/egl/egl_client_config.h" |
| 36 | |
| 37 | #include "interface/khronos/ext/egl_brcm_perf_monitor_client.h" |
| 38 | |
| 39 | #include "interface/khronos/include/EGL/egl.h" |
| 40 | #include "interface/khronos/include/EGL/eglext.h" |
| 41 | |
| 42 | #if EGL_BRCM_perf_monitor |
| 43 | |
| 44 | EGLAPI EGLBoolean EGLAPIENTRY eglInitPerfMonitorBRCM(EGLDisplay dpy) |
| 45 | { |
| 46 | CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE(); |
| 47 | EGLBoolean result; |
| 48 | |
| 49 | CLIENT_LOCK(); |
| 50 | |
| 51 | { |
| 52 | CLIENT_PROCESS_STATE_T *process = client_egl_get_process_state(thread, dpy, EGL_TRUE); |
| 53 | |
| 54 | if (process) { |
| 55 | if (!process->perf_monitor_inited) |
| 56 | process->perf_monitor_inited = RPC_BOOLEAN_RES(RPC_CALL0_RES(eglInitPerfMonitorBRCM_impl, |
| 57 | EGLINITPERFMONITORBRCM_ID)); |
| 58 | |
| 59 | if (process->perf_monitor_inited) { |
| 60 | thread->error = EGL_SUCCESS; |
| 61 | result = EGL_TRUE; |
| 62 | } else { |
| 63 | thread->error = EGL_BAD_ALLOC; |
| 64 | result = EGL_FALSE; |
| 65 | } |
| 66 | } else |
| 67 | result = EGL_FALSE; |
| 68 | } |
| 69 | |
| 70 | CLIENT_UNLOCK(); |
| 71 | |
| 72 | return result; |
| 73 | } |
| 74 | |
| 75 | void egl_perf_monitor_term(CLIENT_PROCESS_STATE_T *process) |
| 76 | { |
| 77 | if (process->perf_monitor_inited) { |
| 78 | RPC_CALL0(eglTermPerfMonitorBRCM_impl, |
| 79 | EGLTERMPERFMONITORBRCM_ID); |
| 80 | |
| 81 | process->perf_monitor_inited = false; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | EGLAPI EGLBoolean EGLAPIENTRY eglTermPerfMonitorBRCM(EGLDisplay dpy) |
| 86 | { |
| 87 | CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE(); |
| 88 | EGLBoolean result; |
| 89 | |
| 90 | CLIENT_LOCK(); |
| 91 | |
| 92 | { |
| 93 | CLIENT_PROCESS_STATE_T *process = client_egl_get_process_state(thread, dpy, EGL_TRUE); |
| 94 | |
| 95 | if (process) { |
| 96 | egl_perf_monitor_term(process); |
| 97 | |
| 98 | thread->error = EGL_SUCCESS; |
| 99 | result = EGL_TRUE; |
| 100 | } else |
| 101 | result = EGL_FALSE; |
| 102 | } |
| 103 | |
| 104 | CLIENT_UNLOCK(); |
| 105 | |
| 106 | return result; |
| 107 | } |
| 108 | |
| 109 | #endif |
| 110 | |
| 111 | #if EGL_BRCM_perf_stats |
| 112 | |
| 113 | EGLAPI void eglPerfStatsResetBRCM(void) |
| 114 | { |
| 115 | CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE(); |
| 116 | RPC_CALL0(eglPerfStatsResetBRCM_impl, thread, EGLPERFSTATSRESETBRCM_ID); |
| 117 | } |
| 118 | |
| 119 | EGLAPI void eglPerfStatsGetBRCM(char *buffer, EGLint buffer_len, EGLBoolean reset) |
| 120 | { |
| 121 | CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE(); |
| 122 | // int len = _min(_max(buffer_len, 0), KHDISPATCH_WORKSPACE_SIZE); |
| 123 | |
| 124 | RPC_CALL3_OUT_BULK(eglPerfStatsGetBRCM_impl, |
| 125 | thread, |
| 126 | EGLPERFSTATSGETBRCM_ID, |
| 127 | RPC_INT(buffer_len), |
| 128 | RPC_BOOLEAN(reset), |
| 129 | buffer); |
| 130 | } |
| 131 | |
| 132 | #endif |
| 133 | |
| 134 | #if EGL_BRCM_mem_usage |
| 135 | |
| 136 | EGLAPI void eglProcessMemUsageGetBRCM(uint32_t id_0, uint32_t id_1, char *buffer, uint32_t buffer_len) |
| 137 | { |
| 138 | CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE(); |
| 139 | |
| 140 | RPC_CALL4_OUT_BULK(eglIntGetProcessMemUsage_impl, |
| 141 | thread, |
| 142 | EGLINTGETPROCESSMEMUSAGE_ID, |
| 143 | RPC_UINT(id_0), |
| 144 | RPC_UINT(id_1), |
| 145 | RPC_UINT(buffer_len), |
| 146 | buffer); |
| 147 | } |
| 148 | |
| 149 | #endif |
| 150 | |