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_driver_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_driver_monitor
43 
eglInitDriverMonitorBRCM(EGLDisplay dpy,EGLint hw_bank,EGLint l3c_bank)44 EGLAPI EGLBoolean EGLAPIENTRY eglInitDriverMonitorBRCM(EGLDisplay dpy, EGLint hw_bank, EGLint l3c_bank)
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       {
56          if (!process->driver_monitor_inited)
57             process->driver_monitor_inited = RPC_BOOLEAN_RES(RPC_CALL2_RES(eglInitDriverMonitorBRCM_impl,
58                                                          thread,
59                                                          EGLINITDRIVERMONITORBRCM_ID,
60                                                          hw_bank, l3c_bank));
61 
62          if (process->driver_monitor_inited)
63          {
64             thread->error = EGL_SUCCESS;
65             result = EGL_TRUE;
66          }
67          else
68          {
69             thread->error = EGL_BAD_ALLOC;
70             result = EGL_FALSE;
71          }
72       }
73       else
74          result = EGL_FALSE;
75    }
76 
77    CLIENT_UNLOCK();
78 
79    return result;
80 }
81 
egl_driver_monitor_term(CLIENT_PROCESS_STATE_T * process)82 void egl_driver_monitor_term(CLIENT_PROCESS_STATE_T *process)
83 {
84    CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE();
85 
86    if (process->driver_monitor_inited)
87    {
88       RPC_CALL0(eglTermDriverMonitorBRCM_impl,
89                 thread,
90                 EGLTERMDRIVERMONITORBRCM_ID);
91 
92       process->driver_monitor_inited = false;
93    }
94 }
95 
eglGetDriverMonitorXMLBRCM(EGLDisplay dpy,EGLint bufSize,EGLint * length,char * xmlStats)96 EGLAPI void EGLAPIENTRY eglGetDriverMonitorXMLBRCM(EGLDisplay dpy, EGLint bufSize, EGLint *length, char *xmlStats)
97 {
98    CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE();
99 
100    CLIENT_LOCK();
101 
102    {
103       CLIENT_PROCESS_STATE_T *process = client_egl_get_process_state(thread, dpy, EGL_TRUE);
104 
105       if (process)
106       {
107          if (process->driver_monitor_inited && xmlStats != NULL)
108          {
109             RPC_CALL2_OUT_BULK(eglGetDriverMonitorXMLBRCM_impl,
110                thread,
111                EGLGETDRIVERMONITORXMLBRCM_ID, bufSize, xmlStats);
112 
113             if (length != NULL)
114                *length = strlen(xmlStats);
115          }
116       }
117    }
118 
119    CLIENT_UNLOCK();
120 }
121 
eglTermDriverMonitorBRCM(EGLDisplay dpy)122 EGLAPI EGLBoolean EGLAPIENTRY eglTermDriverMonitorBRCM(EGLDisplay dpy)
123 {
124    CLIENT_THREAD_STATE_T *thread = CLIENT_GET_THREAD_STATE();
125    EGLBoolean result;
126 
127    CLIENT_LOCK();
128 
129    {
130       CLIENT_PROCESS_STATE_T *process = client_egl_get_process_state(thread, dpy, EGL_TRUE);
131 
132       if (process)
133       {
134          egl_driver_monitor_term(process);
135 
136          thread->error = EGL_SUCCESS;
137          result = EGL_TRUE;
138       }
139       else
140          result = EGL_FALSE;
141    }
142 
143    CLIENT_UNLOCK();
144 
145    return result;
146 }
147 
148 #endif
149