|
1 // This is the main DLL file. |
|
2 |
|
3 #include "platformtypes.h" |
|
4 #include <KhronosAPIWrapper.h> |
|
5 #include <guestvideodriverinterfaceconstants.h> //Registers and enums |
|
6 #include <platformthreading.h> //mutex |
|
7 #include <graphicsvhwcallback.h> |
|
8 #include "simulator_graphicswrapper.h" |
|
9 |
|
10 SimulatorGraphicsWrapper::SimulatorGraphicsWrapper() |
|
11 { |
|
12 } |
|
13 |
|
14 SimulatorGraphicsWrapper::~SimulatorGraphicsWrapper() |
|
15 { |
|
16 delete m_wrapper; |
|
17 m_wrapper = 0; |
|
18 |
|
19 Psu::platform_release_semaphore(m_outputBufferSemaphore); |
|
20 } |
|
21 |
|
22 int SimulatorGraphicsWrapper::Reset( uint32_t *aGraphicsMemBase, uint32_t *aCommandMemBase ) |
|
23 { |
|
24 int ret = -1; |
|
25 if ( m_wrapper ) |
|
26 { |
|
27 delete m_wrapper; |
|
28 } |
|
29 m_wrapper = NULL; |
|
30 |
|
31 uint8_t *cmd_buffer = (uint8_t *)aCommandMemBase; |
|
32 uint8_t *frame_buffer = (uint8_t *)aGraphicsMemBase; |
|
33 if( (cmd_buffer != NULL) && (frame_buffer != NULL) ) |
|
34 { |
|
35 m_wrapper = new KhronosAPIWrapper( (MGraphicsVHWCallback*)this, |
|
36 frame_buffer, &cmd_buffer[VVHW_INPUT_BASE], &cmd_buffer[VVHW_OUTPUT_BASE] ); |
|
37 //Reset synchronisation mechanisms |
|
38 Psu::platform_release_semaphore(m_outputBufferSemaphore); |
|
39 Psu::platform_create_semaphore(m_outputBufferSemaphore, 1, 1); |
|
40 ret = 0; |
|
41 } |
|
42 else |
|
43 { |
|
44 ret = -1; |
|
45 } |
|
46 return ret; |
|
47 } |
|
48 |
|
49 void SimulatorGraphicsWrapper::LockOutputBuffer() |
|
50 { |
|
51 #ifdef KHRONOS_API_W_MULTITHREAD |
|
52 Psu::platform_wait_for_signal(m_outputBufferSemaphore); |
|
53 #endif |
|
54 } |
|
55 |
|
56 void SimulatorGraphicsWrapper::ReleaseOutputBuffer(){} |
|
57 |
|
58 void SimulatorGraphicsWrapper::ProcessingDone(int i) |
|
59 { |
|
60 m_pythonCallBack( i ); |
|
61 } |
|
62 |
|
63 extern "C" |
|
64 { |
|
65 SIMULATOR_GRAPHICSWRAPPER_API SimulatorGraphicsWrapper* create_SimulatorGraphicsWrapper() |
|
66 { |
|
67 return new SimulatorGraphicsWrapper(); |
|
68 } |
|
69 SIMULATOR_GRAPHICSWRAPPER_API int initialize_SimulatorGraphicsWrapper( SimulatorGraphicsWrapper* aSimulatorGraphicsWrapper ) |
|
70 { |
|
71 Psu::platform_create_semaphore(m_outputBufferSemaphore, 1, 1); |
|
72 // Change to proper error handling |
|
73 return 0; |
|
74 } |
|
75 |
|
76 SIMULATOR_GRAPHICSWRAPPER_API int set_GraphicsCallBack( SimulatorGraphicsWrapper* aSimulatorGraphicsWrapper, int (*aGraphicsCallBack) (int) ) |
|
77 { |
|
78 m_pythonCallBack = aGraphicsCallBack; |
|
79 // Change to proper error handling |
|
80 return 0; |
|
81 } |
|
82 |
|
83 SIMULATOR_GRAPHICSWRAPPER_API int reset_SimulatorGraphicsWrapper( SimulatorGraphicsWrapper* aSimulatorGraphicsWrapper, uint32_t *aGraphicsMemBase, uint32_t *aCommandMemBase ) |
|
84 { |
|
85 return aSimulatorGraphicsWrapper->Reset( aGraphicsMemBase, aCommandMemBase ); |
|
86 } |
|
87 |
|
88 SIMULATOR_GRAPHICSWRAPPER_API uint32_t get_InputBufferTail( SimulatorGraphicsWrapper* aSimulatorGraphicsWrapper ) |
|
89 { |
|
90 return m_wrapper->InputBufferTail(); |
|
91 } |
|
92 SIMULATOR_GRAPHICSWRAPPER_API uint32_t get_InputBufferHead( SimulatorGraphicsWrapper* aSimulatorGraphicsWrapper ) |
|
93 { |
|
94 return m_wrapper->InputBufferHead( ); |
|
95 } |
|
96 SIMULATOR_GRAPHICSWRAPPER_API uint32_t get_InputBufferReadCount( SimulatorGraphicsWrapper* aSimulatorGraphicsWrapper ) |
|
97 { |
|
98 return m_wrapper->InputBufferReadCount( ); |
|
99 } |
|
100 SIMULATOR_GRAPHICSWRAPPER_API uint32_t get_InputBufferWriteCount( SimulatorGraphicsWrapper* aSimulatorGraphicsWrapper ) |
|
101 { |
|
102 return m_wrapper->InputBufferWriteCount( ); |
|
103 } |
|
104 SIMULATOR_GRAPHICSWRAPPER_API uint32_t get_InputMaxTailIndex( SimulatorGraphicsWrapper* aSimulatorGraphicsWrapper ) |
|
105 { |
|
106 return m_wrapper->InputMaxTailIndex( ); |
|
107 } |
|
108 SIMULATOR_GRAPHICSWRAPPER_API uint32_t get_cmd_memsize( void ) |
|
109 { |
|
110 return (VVI_PARAMETERS_INPUT_MEMORY_SIZE + |
|
111 VVI_PARAMETERS_OUTPUT_MEMORY_SIZE); |
|
112 } |
|
113 SIMULATOR_GRAPHICSWRAPPER_API uint32_t get_framebuffer_memsize( void ) |
|
114 { |
|
115 return VVI_SURFACEBUFFER_BASE_ADDRESS; |
|
116 } |
|
117 |
|
118 |
|
119 SIMULATOR_GRAPHICSWRAPPER_API unsigned int execute_command( SimulatorGraphicsWrapper* aSimulatorGraphicsWrapper ) |
|
120 { |
|
121 return m_wrapper->Execute( ); |
|
122 } |
|
123 SIMULATOR_GRAPHICSWRAPPER_API void set_InputBufferTail( SimulatorGraphicsWrapper* aSimulatorGraphicsWrapper, uint32_t aVal ) |
|
124 { |
|
125 m_wrapper->SetInputBufferTail( aVal ); |
|
126 } |
|
127 SIMULATOR_GRAPHICSWRAPPER_API void set_InputBufferHead( SimulatorGraphicsWrapper* aSimulatorGraphicsWrapper, uint32_t aVal ) |
|
128 { |
|
129 m_wrapper->SetInputBufferHead( aVal ); |
|
130 } |
|
131 SIMULATOR_GRAPHICSWRAPPER_API void set_InputBufferReadCount( SimulatorGraphicsWrapper* aSimulatorGraphicsWrapper, uint32_t aVal ) |
|
132 { |
|
133 m_wrapper->SetInputBufferReadCount( aVal ); |
|
134 } |
|
135 SIMULATOR_GRAPHICSWRAPPER_API void set_InputBufferWriteCount( SimulatorGraphicsWrapper* aSimulatorGraphicsWrapper, uint32_t aVal ) |
|
136 { |
|
137 m_wrapper->SetInputBufferWriteCount( aVal ); |
|
138 } |
|
139 SIMULATOR_GRAPHICSWRAPPER_API void set_InputMaxTailIndex( SimulatorGraphicsWrapper* aSimulatorGraphicsWrapper, uint32_t aVal ) |
|
140 { |
|
141 m_wrapper->SetInputMaxTailIndex( aVal ); |
|
142 } |
|
143 SIMULATOR_GRAPHICSWRAPPER_API void signal_outputbuffer_semafore( SimulatorGraphicsWrapper* aSimulatorGraphicsWrapper ) |
|
144 { |
|
145 #ifdef KHRONOS_API_W_MULTITHREAD |
|
146 Psu::platform_signal_semaphore(m_outputBufferSemaphore); |
|
147 #endif |
|
148 } |
|
149 |
|
150 } |