Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r598 - branches/itanium2/Engine/Display
- Date: Wed, 5 Oct 2005 20:36:28 -0600 (MDT)
Author: abe
Date: Wed Oct 5 20:36:24 2005
New Revision: 598
Added:
branches/itanium2/Engine/Display/SHMImageDisplay.cc
branches/itanium2/Engine/Display/SHMImageDisplay.h
Log:
Added empty implementation of image display for SysV SHM. Not yet included in
cmake build
A SHMImageDisplay.h
A SHMImageDisplay.cc
Added: branches/itanium2/Engine/Display/SHMImageDisplay.cc
==============================================================================
--- (empty file)
+++ branches/itanium2/Engine/Display/SHMImageDisplay.cc Wed Oct 5 20:36:24
2005
@@ -0,0 +1,471 @@
+
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2005
+ Silicon Graphics Inc. Mountain View California.
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+#include <Engine/Display/SHMImageDisplay.h>
+
+#include <Image/SimpleImage.h>
+#include <Image/Pixel.h>
+#include <Interface/Image.h>
+#include <Interface/Context.h>
+
+#include <iostream>
+
+using namespace Manta;
+
+// Includes for shm methods.
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <sys/sem.h>
+#include <unistd.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <errno.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// SHM Structure.
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+struct SHM_STREAM_DATA {
+ longheartbeat;
+ long counter;
+
+ int shmID;
+
+ int key;
+ int semID;
+
+ int refCount;
+ int exitFlag;
+
+ int pixelFlipHorz;
+ int pixelFlipVert;
+
+ int pID;
+
+ int lock;
+
+ int xres, yres, zres;
+
+ unsigned char *pixelPool[2];
+
+ int frontBuffer;
+ int backBuffer;
+
+ int numRects;
+ int rectDef[MAX_NUM_UPDATES][5];
+
+ intssCMD [MAX_NUM_SSCMD];
+ intssDATA[MAX_NUM_SSCMD];
+ intnumSSCMD;
+
+};
+
+// SHM Library functions.
+int shmCreate( int key, SHM_STREAM_DATA ** _strmSHM, int createFlag );
+int shmDestroy( SHM_STREAM_DATA ** _strmSHM );
+int semCreate( int key, int *semID, int initVal );
+int semDestroy( int semID );
+int semPost( int semID );
+int semWait( int semID );
+int semTryWait( int semID );
+int semGetValue( int semID );
+void strmSwapBuffers( SHM_STREAM_DATA * strmSHM );
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP
SETUP
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+SHMImageDisplay::SHMImageDisplay( const vector<string> &args ) {
+
+
+}
+
+GLXImageDisplay::~GLXImageDisplay() {
+}
+
+// Manta ImageDisplay interface.
+void SHMImageDisplay::setupDisplayChannel( SetupContext &context ) {
+
+ // Only the display processor.
+ if (context.proc != 0)
+ return;
+
+ // Determine the resolution.
+
+ // Allocate a SHM Stream structure.
+
+ // Initialize shared memory segment
+ if( !shmCreate( key, &strmSHM, true ) ) {
+ printf( "Cannot create shm for stream\n" );
+ exit( 1 );
+ }
+
+ // Initialize semaphore
+ if( !semCreate( key, &strmSHM->semID, LOCK_OPEN ) ) {
+ printf( "Cannot create semaphore for shm\n" );
+ exit( 1 );
+ }
+
+
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// DISPLAY IMAGE DISPLAY IMAGE DISPLAY IMAGE DISPLAY IMAGE DISPLAY IMAGE
D
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+void SHMImageDisplay::displayImage( const DisplayContext &context, const
Image* image ) {
+
+ // Check to see if this processor should display the image.
+ if (context.proc == 0) {
+
+ // Determine the image resolution.
+ int xres, yres;
+ bool stereo;
+
+ image->getResolution( stereo, xres, yres );
+
+
+ // ...
+ }
+
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// SHM FUNCTIONS SHM FUNCTIONS SHM FUNCTIONS SHM FUNCTIONS SHM FUNCTIONS
S
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+int shmCreate( int key, SHM_STREAM_DATA ** _strmSHM, int createFlag )
+{
+ int shm_id;
+
+ /*--- ICD SHARED MEMORY CREATION ---*/
+
+ printf("\n***********************************************************\n" );
+ printf("* \n" );
+ printf("* Initializing Shared Memory Area \n" );
+ printf("* \n" );
+ fflush( stdout );
+
+ printf( "* Shared Memory area size: %i\n", sizeof( SHM_STREAM_DATA ) );
+
+ /* get shared memory now */
+ shm_id = shmget( key, sizeof( SHM_STREAM_DATA ), PERM_FILE );
+
+ /* we have an error try to debug */
+ if( shm_id == -1 )
+ {
+ /* print error */
+ if( errno == ENOENT )
+ {
+ /* test is creation flag is set (only used by modules for opening
new segments */
+ if( createFlag == STRM_SHM_CREATE )
+ {
+ printf( "* INFO: SHM memory for stream has not been
initialized - initializing now \n" );
+
+ /* couldn't get the shared memory so create instead */
+ shm_id = shmget( key, sizeof( SHM_STREAM_DATA ),
IPC_CREAT|PERM_FILE );
+
+ if( shm_id == -1 )
+ {
+ /* print error */
+ printf( " Error code %i\n", errno );
+ printf( "*\n" );
+ printf( "* Possible Error Codes:\n" );
+ printf( "* Error code EINVAL = %i\n", EINVAL );
+ printf( "* Error code EEXIST = %i\n", EEXIST );
+ printf( "* Error code EIDRM = %i\n", EIDRM );
+ printf( "* Error code ENOSPC = %i\n", ENOSPC );
+ printf( "* Error code ENOENT = %i\n", ENOENT );
+ printf( "* Error code EACCES = %i\n", EACCES );
+ printf( "* Error code ENOMEM = %i\n", ENOMEM );
+
+ /* couldn't create shm so die badly */
+ printf("couldn't create shm so die badly\n");
+ return( FALSE );
+ }
+
+ } else {
+
+ printf( "* INFO: SHM memory for stream has not been
initialized - Stream key is invalid \n" );
+ printf("* \n" );
+
printf("***********************************************************\n\n" );
+ return( FALSE );
+
+ }
+
+ } else {
+
+ printf( "* Actual Error code %i\n", errno );
+ printf( "*\n" );
+ printf( "* Possible Error Codes:\n" );
+ printf( "* Error code EINVAL = %i\n", EINVAL );
+ printf( "* Error code EEXIST = %i\n", EEXIST );
+ printf( "* Error code EIDRM = %i\n", EIDRM );
+ printf( "* Error code ENOSPC = %i\n", ENOSPC );
+ printf( "* Error code ENOENT = %i\n", ENOENT );
+ printf( "* Error code EACCES = %i\n", EACCES );
+ printf( "* Error code ENOMEM = %i\n", ENOMEM );
+ }
+
+
+ }
+
+ /* attach pointer to shm memory */
+ *_strmSHM = shmat( shm_id, 0, 0 );
+
+ if( (int)*_strmSHM == -1 )
+ {
+ /* couldn't attach pointer to shm space */
+ printf("couldn't attach pointer to shm space \n");
+ exit( 1 );
+ }
+
+ printf("* Shared Memory ID = %i Address = %X Size of %i\n",
+ shm_id, (int) *_strmSHM, sizeof( SHM_STREAM_DATA ) );
+ printf("* \n" );
+ printf("***********************************************************\n\n" );
+
+ /* set shm_id internally in shm's structure */
+ (*_strmSHM)->shmID = shm_id;
+
+
+ /* if createFlag is FALSE this means this is a view trying to attach to
the stream module
+ therfore we should increment the reference count */
+ if( createFlag == STRM_SHM_ATTACH )
+ {
+ (*_strmSHM)->refCount++;
+ } else {
+ /* just viewing strmSHM (used by the stream_manager) don't increment
refCount */ ;
+ }
+
+
+ return( TRUE );
+
+}
+
+int shmDestroy( SHM_STREAM_DATA ** _strmSHM )
+{
+ int shmID;
+
+ shmID = (*_strmSHM)->shmID;
+
+
+ /* detach shm */
+ shmdt( *_strmSHM );
+ printf( "Detatched SHM\n" );
+
+ /* remove shm */
+ shmctl( shmID, IPC_RMID, NULL );
+ printf( "Deleted SHM\n" );
+
+ return( TRUE );
+
+}
+
+void strmSwapBuffers( SHM_STREAM_DATA * strmSHM )
+{
+ int semVAL;
+
+ /* WAIT FOR OTHER APPS THAT MAY BE READING SHM TO FINISHED AND UNLOCK IT */
+
+ /* wait for memory to be open for writing, then attempt to lock it */
+ semVAL = semGetValue( strmSHM->semID );
+ while( semVAL != LOCK_OPEN )
+ {
+ nano_sleep( 100000 );
+ semVAL = semGetValue( strmSHM->semID );
+ //printf("waiting to strmSwapBuffers #%i \n", semVAL-1 );
fflush(stdout);
+ }
+
+ /* decrement semaphore to 0 -> LOCK_WRITING */
+ semTryWait( strmSHM->semID );
+
+
+ /* do the swap..... */
+ if( strmSHM->backBuffer == 0 )
+ {
+ strmSHM->backBuffer = 1;
+ strmSHM->frontBuffer = 0;
+ } else {
+ strmSHM->backBuffer = 0;
+ strmSHM->frontBuffer = 1;
+ }
+
+ /* UNLOCK THE SHM FOR OTHER APPS TO READ FROM IT */
+
+ /* writing is finished open memory up for reading */
+ /* increment semaphore to 1 -> LOCK_OPEN */
+ semPost( strmSHM->semID );
+
+
+}
+
+int semCreate( int key, int *semID, int initVal )
+{
+ int val;
+ union semun {
+ int val;
+ struct semid_ds *buf;
+ unsigned short *array;
+ } arg;
+
+ *semID = semget( key, 1, PERM_FILE|IPC_CREAT );
+ if( *semID == -1 )
+ {
+ printf( "Couldn't get semaphore reason %i\n", errno );
+ return FALSE;
+ } else {
+ printf( "semaphore ID %d\n", (unsigned int)*semID );
+ }
+
+ arg.val = initVal;
+ val = semctl( *semID, 0, SETVAL, arg );
+
+ if( val == -1 )
+ {
+ printf( "Couldn't set semaphore val to 1 error#:%i\n", errno );
+ return FALSE;
+ } else {
+ printf( "semaphore val |%i|\n", arg.val );
+ }
+
+ return TRUE;
+
+}
+
+int semDestroy( int semID )
+{
+ if( semctl( semID, 0, IPC_RMID ) == -1 )
+ {
+ printf( "Couldn't remove semaphore reason %i\n", errno );
+ return FALSE;
+
+ } else {
+
+ printf( "semaphore ID %d removed \n", (unsigned int)semID );
+ return TRUE;
+ }
+}
+
+int semPost( int semID )
+{
+ int val;
+ struct sembuf sbuf;
+
+ sbuf.sem_num = 0;
+ sbuf.sem_op = 1;
+ sbuf.sem_flg = 0;
+
+ val = semop( semID, &sbuf, 1 );
+ if( val == -1 )
+ {
+ printf( "Couldn't perform Post operation on semaphore error#:%i\n",
errno );
+ return FALSE;
+ }
+
+ return TRUE;
+
+}
+
+int semWait( int semID )
+{
+ int val;
+ struct sembuf sbuf;
+
+ sbuf.sem_num = 0;
+ sbuf.sem_op = -1;
+ sbuf.sem_flg = 0;
+
+ val = semop( semID, &sbuf, 1 );
+ if( val == -1 )
+ {
+ printf( "Couldn't perform Wait operation on semaphore error#:%i\n",
errno );
+ return FALSE;
+ }
+
+ return TRUE;
+
+}
+
+int semTryWait( int semID )
+{
+ int val;
+ struct sembuf sbuf;
+
+ sbuf.sem_num = 0;
+ sbuf.sem_op = -1;
+ sbuf.sem_flg = IPC_NOWAIT;
+
+ val = semop( semID, &sbuf, 1 );
+ if( val == -1 )
+ {
+ if( errno != EAGAIN ) /* EAGAIN is a note to say that the semaphore is
already at zero... */
+ {
+ printf( "\nCouldn't perform TryWait operation on semaphore
error#:%i\n", errno );
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+
+}
+
+int semGetValue( int semID )
+{
+ int value = -1;
+ value = semctl( semID, 0, GETVAL, NULL );
+ return( value );
+}
+
+
+
+
+
Added: branches/itanium2/Engine/Display/SHMImageDisplay.h
==============================================================================
--- (empty file)
+++ branches/itanium2/Engine/Display/SHMImageDisplay.h Wed Oct 5 20:36:24
2005
@@ -0,0 +1,73 @@
+
+/*
+ For more information, please see:
http://software.sci.utah.edu
+
+ The MIT License
+
+ Copyright (c) 2005
+ Silicon Graphics Inc. Mountain View California.
+
+ License for the specific language governing rights and limitations under
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+
+
+#ifdef __ia64__
+
+#ifndef Manta_Engine_SHMImageDisplay_h
+#define Manta_Engine_SHMImageDisplay_h
+
+#include <Interface/ImageDisplay.h>
+
+namespace Manta {
+
+ class SetupContext;
+ class DisplayContext;
+ class Image;
+
+ // Abe Stephens -- abe@sgi.com
+ // Nigel Jenkins -- njenkins@sgi.com
+ // Tom Fuke -- tom@sgi.com
+
+ class SHMImageDisplay : public ImageDisplay {
+ private:
+
+ int manta_channel; // The last channel number to call
setupDisplayChannel.
+
+ public:
+ // Note that the GLXImage display must be passed a GLX context by the
+ // application it is embedded inside of.
+ SHMImageDisplay( const vector<string> &args );
+ ~SHMImageDisplay();
+
+ // RTRT_register creator function.
+ static ImageDisplay *create( const vector<string> &args ) { return new
SHMImageDisplay( args ); };
+
+ // Manta ImageDisplay interface.
+ void setupDisplayChannel( SetupContext &context );
+ void displayImage( const DisplayContext &context, const Image* image );
+
+ };
+};
+
+#endif
+
+
+#endif
- [MANTA] r598 - branches/itanium2/Engine/Display, abe, 10/05/2005
Archive powered by MHonArc 2.6.16.