|
1 /*------------------------------------------------------------------------ |
|
2 * |
|
3 * EGL 1.3 |
|
4 * ------- |
|
5 * |
|
6 * Copyright (c) 2007 The Khronos Group Inc. |
|
7 * |
|
8 * Permission is hereby granted, free of charge, to any person obtaining a |
|
9 * copy of this software and /or associated documentation files |
|
10 * (the "Materials "), to deal in the Materials without restriction, |
|
11 * including without limitation the rights to use, copy, modify, merge, |
|
12 * publish, distribute, sublicense, and/or sell copies of the Materials, |
|
13 * and to permit persons to whom the Materials are furnished to do so, |
|
14 * subject to the following conditions: |
|
15 * |
|
16 * The above copyright notice and this permission notice shall be included |
|
17 * in all copies or substantial portions of the Materials. |
|
18 * |
|
19 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
22 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
|
23 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
|
24 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR |
|
25 * THE USE OR OTHER DEALINGS IN THE MATERIALS. |
|
26 * |
|
27 *//** |
|
28 * \file |
|
29 * \brief Generic OS EGL functionality (not thread safe, no window rendering) |
|
30 * \note |
|
31 *//*-------------------------------------------------------------------*/ |
|
32 |
|
33 #include "egl.h" |
|
34 #include "riImage.h" |
|
35 |
|
36 namespace OpenVGRI |
|
37 { |
|
38 |
|
39 /*-------------------------------------------------------------------*//*! |
|
40 * \brief |
|
41 * \param |
|
42 * \return |
|
43 * \note |
|
44 *//*-------------------------------------------------------------------*/ |
|
45 |
|
46 void* OSGetCurrentThreadID(void) |
|
47 { |
|
48 return NULL; |
|
49 } |
|
50 |
|
51 /*-------------------------------------------------------------------*//*! |
|
52 * \brief |
|
53 * \param |
|
54 * \return |
|
55 * \note |
|
56 *//*-------------------------------------------------------------------*/ |
|
57 |
|
58 static int mutexRefCount = 0; |
|
59 static bool mutexInitialized = false; |
|
60 //acquired mutex cannot be deinited |
|
61 void OSDeinitMutex(void) |
|
62 { |
|
63 RI_ASSERT(mutexInitialized); |
|
64 RI_ASSERT(mutexRefCount == 0); |
|
65 } |
|
66 void OSAcquireMutex(void) |
|
67 { |
|
68 if(!mutexInitialized) |
|
69 { |
|
70 mutexInitialized = true; |
|
71 } |
|
72 mutexRefCount++; |
|
73 } |
|
74 void OSReleaseMutex(void) |
|
75 { |
|
76 RI_ASSERT(mutexInitialized); |
|
77 mutexRefCount--; |
|
78 RI_ASSERT(mutexRefCount >= 0); |
|
79 } |
|
80 |
|
81 /*-------------------------------------------------------------------*//*! |
|
82 * \brief |
|
83 * \param |
|
84 * \return |
|
85 * \note |
|
86 *//*-------------------------------------------------------------------*/ |
|
87 |
|
88 struct OSWindowContext |
|
89 { |
|
90 int tmpWidth; |
|
91 int tmpHeight; |
|
92 }; |
|
93 |
|
94 void* OSCreateWindowContext(EGLNativeWindowType window) |
|
95 { |
|
96 OSWindowContext* ctx = NULL; |
|
97 try |
|
98 { |
|
99 ctx = RI_NEW(OSWindowContext, ()); |
|
100 } |
|
101 catch(std::bad_alloc) |
|
102 { |
|
103 return NULL; |
|
104 } |
|
105 ctx->tmpWidth = 0; |
|
106 ctx->tmpHeight = 0; |
|
107 return ctx; |
|
108 } |
|
109 |
|
110 void OSDestroyWindowContext(void* context) |
|
111 { |
|
112 OSWindowContext* ctx = (OSWindowContext*)context; |
|
113 if(ctx) |
|
114 { |
|
115 RI_DELETE(ctx); |
|
116 } |
|
117 } |
|
118 |
|
119 bool OSIsWindow(const void* context) |
|
120 { |
|
121 OSWindowContext* ctx = (OSWindowContext*)context; |
|
122 if(ctx) |
|
123 { |
|
124 return true; |
|
125 } |
|
126 return false; |
|
127 } |
|
128 |
|
129 void OSGetWindowSize(const void* context, int& width, int& height) |
|
130 { |
|
131 OSWindowContext* ctx = (OSWindowContext*)context; |
|
132 if(ctx) |
|
133 { |
|
134 width = ctx->tmpWidth; |
|
135 height = ctx->tmpHeight; |
|
136 } |
|
137 else |
|
138 { |
|
139 width = 0; |
|
140 height = 0; |
|
141 } |
|
142 } |
|
143 |
|
144 void OSBlitToWindow(void* context, const Drawable* drawable) |
|
145 { |
|
146 OSWindowContext* ctx = (OSWindowContext*)context; |
|
147 if(ctx) |
|
148 { |
|
149 ctx->tmpWidth = drawable->getWidth(); |
|
150 ctx->tmpHeight = drawable->getHeight(); |
|
151 } |
|
152 } |
|
153 |
|
154 EGLDisplay OSGetDisplay(EGLNativeDisplayType display_id) |
|
155 { |
|
156 RI_UNREF(display_id); |
|
157 return (EGLDisplay)1; //support only a single display |
|
158 } |
|
159 |
|
160 } //namespace OpenVGRI |