ISAAC
Overview :: Library Doc :: Server Doc :: JSON Commands

In Situ Animation of Accelerated Computations

SDLImageConnector.cpp
Go to the documentation of this file.
1 /* This file is part of ISAAC.
2  *
3  * ISAAC is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * ISAAC is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with ISAAC. If not, see <www.gnu.org/licenses/>. */
15 
16 #include "SDLImageConnector.hpp"
17 
19 {
20  SDL_Init(SDL_INIT_VIDEO);
21  group = NULL;
22  showClient = false;
23 }
24 
26 {
27  return "SDLImageConnector";
28 }
29 
30 errorCode SDLImageConnector::init(int minport,int maxport)
31 {
32  return 0;
33 }
34 
36 {
37  window = SDL_SetVideoMode( 512, 512, 32, SDL_HWSURFACE );
38  int finish = 0;
39  while (finish == 0)
40  {
41  SDL_Event event;
42  while ( SDL_PollEvent( &event ) == 1 )
43  {
44  if (event.type == SDL_QUIT)
45  finish = 2;
46  }
47  ImageBufferContainer* message;
48  while (message = clientGetMessage())
49  {
50  if (message->type == IMG_FORCE_EXIT)
51  finish = 1;
52  if (message->type == GROUP_FINISHED)
53  {
54  if (group == message->group)
55  {
56  group = NULL;
57  SDL_FreeSurface(window);
58  window = SDL_SetVideoMode( 512, 512, 32, SDL_HWSURFACE );
59  }
60  }
61  if (message->type == UPDATE_BUFFER)
62  {
63  if (group == NULL)
64  {
65  group = message->group;
66  SDL_FreeSurface(window);
67  window = SDL_SetVideoMode( group->getFramebufferWidth(), group->getFramebufferHeight(), 32, SDL_HWSURFACE );
68  }
69  if (group == message->group) //We show always the very first group
70  {
71  SDL_LockSurface( window );
72  uint8_t* pixels = (uint8_t*)(window->pixels);
73  for (int i = 0; i < message->group->getVideoBufferSize() / 4; i++)
74  {
75  for (int j = 0; j < 3; j++)
76  pixels[i*4+j] = message->image->buffer[i*4+2-j];
77  pixels[i*4+3] = message->image->buffer[i*4+3];
78  }
79  SDL_UnlockSurface( window );
80  SDL_Flip(window);
81  }
82  }
83  clientSendMessage( message );
84  }
85  usleep(1000);
86  }
87  SDL_FreeSurface(window);
88  SDL_Quit();
89  //Even if the window is close we still need to free the video buffers!
90  while (finish == 2)
91  {
92  ImageBufferContainer* message;
93  while (message = clientGetMessage())
94  {
95  if (message->type == IMG_FORCE_EXIT)
96  finish = 1;
97  clientSendMessage( message );
98  }
99  usleep(1000);
100  }
101 }
ImageBufferContainer * clientGetMessage()
Definition: MessageAble.hpp:38
errorCode clientSendMessage(ImageBufferContainer *message)
Definition: MessageAble.hpp:34
InsituConnectorGroup * group
Definition: Common.hpp:196
int getVideoBufferSize()
Definition: Broker.hpp:66
errorCode init(int minport, int maxport)
int errorCode
Definition: Common.hpp:24
int getFramebufferHeight()
Definition: Broker.hpp:74
ImageBufferType type
Definition: Common.hpp:195
int getFramebufferWidth()
Definition: Broker.hpp:70
uint8_t * buffer
Definition: Common.hpp:162
ImageBuffer * image
Definition: Common.hpp:199