Пример #1
0
void StartAnimation()
{
   DirectFBStage *stage = sgDirectFBFrame->GetStage();
   
   while (!sgDead) {
       int waitMs = (stage->GetNextWake() - GetTimeStamp()) * 1000;
       if (waitMs < 0) {
           waitMs = 0;
       }
       sgEventBuffer->WaitForEventWithTimeout(sgEventBuffer, 0, waitMs);
      
      while (sgEventBuffer->HasEvent(sgEventBuffer) != DFB_BUFFEREMPTY) {
          DFBEvent event;
          sgEventBuffer->GetEvent(sgEventBuffer, DFB_EVENT(&event));
          stage->ProcessEvent(event);
          if (sgDead) {
              break;
          }
      }

      Event poll(etPoll);
      stage->HandleEvent(poll);
   }
   
   Event deactivate(etDeactivate);
   stage->HandleEvent(deactivate);
   
   Event kill(etDestroyHandler);
   stage->HandleEvent(kill);
}
Пример #2
0
int
main( int argc, char *argv[] )
{
     /* Initialize application. */
     init_application( &argc, &argv );

     surface->Clear( surface, 0xff, 0xff, 0xff, 0x30 );

     window->SetOpacity( window, 0xff );

     /* Main loop. */
     while (1) {
          DFBWindowEvent event;

          update();

          events->WaitForEventWithTimeout( events, 0, 100 );

          /* Check for new events. */
          while (events->GetEvent( events, DFB_EVENT(&event) ) == DFB_OK) {
               switch (event.type) {
                    default:
                         break;
               }
          }
     }

     /* Shouldn't reach this. */
     return 0;
}
Пример #3
0
/**
 * Retrieves next event from queue. Must be called when 
 * <code>directfbapp_event_is_waiting</code> returned true.
 */
void directfbapp_get_event(void *event) {
    if (directfbapp_event_is_waiting()) {
        DFBCHECK(event_buffer->GetEvent(event_buffer, DFB_EVENT(event)));
        return;
    }
    REPORT_ERROR(LC_LOWUI, "Invalid sequence of calls: no events waiting");
dfb_err:;
}
Пример #4
0
/**
 * Checks for events from keyboard. Gotten event must be retrieved 
 * by <code>directfbapp_get_event</code>.
 * Processes events: DWET_GOTFOCUS and DWET_LOSTFOCUS.
 */
int directfbapp_event_is_waiting() {
    DFBWindowEvent event;
    
    for (;;) {
        if (event_buffer->HasEvent(event_buffer) == DFB_OK) {
            DFBCHECK(event_buffer->PeekEvent(event_buffer, DFB_EVENT(&event)));
            if (event.type == DWET_KEYUP || event.type == DWET_KEYDOWN) {
                return 1;
            } else {
                DFBCHECK(event_buffer->GetEvent(event_buffer, DFB_EVENT(&event)));
                switch (event.type) {
                case DWET_GOTFOCUS:
                    DFBCHECK2(window->RaiseToTop(window), dfb_err1);
                    DFBCHECK2(window->SetOpacity(window, 0xff), dfb_err1);
                    break;
                case DWET_LOSTFOCUS:
                    DFBCHECK2(window->SetOpacity(window, 0x7f), dfb_err1);
                    break;
                case DWET_DESTROYED:
                    directfbapp_finalize();
                    printf("Destroy my window...\n");
                    exit(0); /* IMPL_NOTE: exit from Java */
                    break;
                case DWET_CLOSE:
                    printf("Closing my window...\n");
                    DFBCHECK2(window->Destroy(window), dfb_err1);
                    break;
                default:
                    break;
                }
            }
        } else {
            return 0;
        }
    dfb_err1:;
    }
    
dfb_err:;
    return 0;
}
Пример #5
0
	InputEvent* InputEventBuffer::getNextEvent() {
		if (eventBuffer != NULL) {
#if HAVE_DIRECTFB
			DFBInputEvent* evt = new DFBInputEvent;
			IDirectFBEventBuffer* ieb;
			ieb = (IDirectFBEventBuffer*)eventBuffer;
			if (ieb->GetEvent(ieb, DFB_EVENT(evt)) == DFB_OK) {
				return new InputEvent((void*)evt);
			}
#endif
		}

		return NULL;
	}
Пример #6
0
void process_events()
{
	pthread_mutex_init(&keyevent_mutex, NULL);
	int quit = 0;

	if(DFBC_INTERFACE_->CreateInputEventBuffer(DFBC_INTERFACE_, DICAPS_ALL /*DICAPS_KEYS*/, DFB_TRUE, &DFBC_EVBUFF_ ))
	{
		printf("Create DFBInputEventBuffer failed\n");
		dfb_destroy();
		return;
	}

	while(quit == 0)
	{
		DFBInputEvent evt;
		DFBC_EVBUFF_->WaitForEvent(DFBC_EVBUFF_);
		while(DFBC_EVBUFF_->GetEvent(DFBC_EVBUFF_, DFB_EVENT(&evt)) == DFB_OK)
		{
			pthread_mutex_lock(&keyevent_mutex);
			if(evt.type == DIET_KEYRELEASE)
				KEY_PRESSED_ = 0;   // prevent getting events while key is pressed

			if( ((evt.type == DIET_KEYPRESS) && !KEY_PRESSED_) ||
			    ((evt.type == DIET_KEYPRESS) && WAKE_UP_))
			{
				KEY_PRESSED_ = 1;

				if(WAKE_UP_)
					WAKE_UP_ = 0;

				switch (evt.key_symbol)
				{
					case DIKS_ESCAPE:
					{
						quit = 1;
						DFBC_ESCAPECTRL_ = DIKS_DOWN;
						break;
					}
					default:
					{
						DFB_EVHANDLER_FCTR(&evt.key_symbol);
						break;
					}
				}
			}
			pthread_mutex_unlock(&keyevent_mutex);
		}
	}
	pthread_mutex_destroy(&keyevent_mutex);
}
Пример #7
0
IInputEvent* DFBEventBuffer::getNextEvent() {
    if (eventBuffer != NULL && (eventBuffer->HasEvent(eventBuffer) == DFB_OK)) {

        DFBInputEvent* evt = new DFBInputEvent;
        if (eventBuffer->GetEvent(eventBuffer, DFB_EVENT(evt)) == DFB_OK) {
            return new DFBGInputEvent((void*)evt);

        } /*else {
				delete evt;
				evt = NULL;
			}*/
    }

    return NULL;
}
void
DirectFB_PumpEventsWindow(_THIS)
{
    SDL_DFB_DEVICEDATA(_this);
    DFB_WindowData *p;
    DFBInputEvent ievt;

    for (p = devdata->firstwin; p != NULL; p = p->next) {
        DFBWindowEvent evt;
        SDL_Window *w = p->sdl_window;

        while (p->eventbuffer->GetEvent(p->eventbuffer,
                                        DFB_EVENT(&evt)) == DFB_OK) {
            if (!DirectFB_WM_ProcessEvent(_this, w, &evt))
                ProcessWindowEvent(_this, p, w->flags, &evt);
        }
    }

    /* Now get relative events in case we need them */
    while (devdata->events->GetEvent(devdata->events,
                                     DFB_EVENT(&ievt)) == DFB_OK) {
        ProcessInputEvent(_this, &ievt);
    }
}
void DirectFB_PumpEvents (_THIS)
{
  DFBInputEvent evt;

  while (HIDDEN->eventbuffer->GetEvent (HIDDEN->eventbuffer,
                                        DFB_EVENT (&evt)) == DFB_OK)
    {
      SDL_keysym keysym;

      switch (evt.type)
        {
        case DIET_BUTTONPRESS:
          posted += SDL_PrivateMouseButton(SDL_PRESSED,
                                           DirectFB_TranslateButton (&evt), 0, 0);
          break;
        case DIET_BUTTONRELEASE:
          posted += SDL_PrivateMouseButton(SDL_RELEASED,
                                           DirectFB_TranslateButton (&evt), 0, 0);
          break;
        case DIET_KEYPRESS:
          posted += SDL_PrivateKeyboard(SDL_PRESSED, DirectFB_TranslateKey(&evt, &keysym));
          break;
        case DIET_KEYRELEASE:
          posted += SDL_PrivateKeyboard(SDL_RELEASED, DirectFB_TranslateKey(&evt, &keysym));
          break;
        case DIET_AXISMOTION:
          if (evt.flags & DIEF_AXISREL)
            {
              if (evt.axis == DIAI_X)
                posted += SDL_PrivateMouseMotion(0, 1, evt.axisrel, 0);
              else if (evt.axis == DIAI_Y)
                posted += SDL_PrivateMouseMotion(0, 1, 0, evt.axisrel);
            }
          else if (evt.flags & DIEF_AXISABS)
            {
              static int last_x, last_y;
              if (evt.axis == DIAI_X)
                last_x = evt.axisabs;
              else if (evt.axis == DIAI_Y)
                last_y = evt.axisabs;
              posted += SDL_PrivateMouseMotion(0, 0, last_x, last_y);
            }
          break;
        default:
          ;
        }
    }
}
Пример #10
0
u32 DirectFBVid_ProcessMessageQueueWrapper(DirectFBVidCtx *ctx, u8 *type, u32 *flags, u32 *key_code, s32 *x, s32 *y, u32 *button)
{
	DFBInputEvent directfb_evt;

	if (ctx->events->GetEvent( ctx->events, DFB_EVENT(&directfb_evt) ) == DFB_OK)
	{
		switch (directfb_evt.type) {
			case DIET_KEYPRESS:
			case DIET_KEYRELEASE:
				directfb_translate_key(directfb_evt.key_id, flags, key_code);
				*type = (directfb_evt.type == DIET_KEYPRESS) ? GF_EVENT_KEYDOWN : GF_EVENT_KEYUP;
				break;
			case DIET_BUTTONPRESS:
			case DIET_BUTTONRELEASE:
				*type = (directfb_evt.type == DIET_BUTTONPRESS) ? GF_EVENT_MOUSEUP : GF_EVENT_MOUSEDOWN;
				switch(directfb_evt.button) {
					case DIBI_LEFT:
						*button = GF_MOUSE_LEFT;
						break;
					case DIBI_RIGHT:
						*button = GF_MOUSE_RIGHT;
						break;
					case DIBI_MIDDLE:
						*button = GF_MOUSE_MIDDLE;
						break;
					default:
						printf("in here for others\n");
						break;
				}
				break;
			case DIET_AXISMOTION:
				*type = GF_EVENT_MOUSEMOVE;
				ctx->mouse->GetXY(ctx->mouse, x, y);
			default:
				break;
		}
		
		return 0;
	}

	return 1;
}
Пример #11
0
void Renderer::loop(EventListener *listener)
{
  DFBInputEvent dfb_event;
  Event event;

  while (!m_exit) {
    m_eventBuffer->WaitForEventWithTimeout(m_eventBuffer, 0, 100);
    while (!m_exit && m_eventBuffer->GetEvent (m_eventBuffer, DFB_EVENT(&dfb_event)) == DFB_OK) {
      if (dfb_event.type == DIET_KEYPRESS) {
        event.type = EVENT_KEYPRESS;
        event.key = (Key)dfb_event.key_symbol;
        event.repeat = dfb_event.flags & DIEF_REPEAT;
#ifdef NMT
        if (event.key == (Key)DIKS_PAUSE) event.key = (Key)DIKS_PLAY;
#endif
        debug("got key: 0x%x 0x%x\n", (int)(event.key & 0xFF00), (int)(event.key & 0xFF));
        if (!listener->handleEvent(event)) m_exit = true;
      }
    }
    if (!listener->handleIdle()) m_exit = true;
  }    
}
Пример #12
0
int main( int argc, char *argv[] )
{
     IDirectFB              *dfb;
     IDirectFBDisplayLayer  *layer;

     IDirectFBSurface       *bgsurface;
     IDirectFBImageProvider *provider;

     IDirectFBWindow        *window1;
     IDirectFBWindow        *window2;
     IDirectFBSurface       *window_surface1;
     IDirectFBSurface       *window_surface2;

     IDirectFBEventBuffer   *buffer;

     DFBDisplayLayerConfig  layer_config;

#if ((DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23))
     DFBCardCapabilities    caps;
#else
     DFBGraphicsDeviceDescription caps;
#endif
     IDirectFBWindow*       upper;
     DFBWindowID            id1;

     IDirectFBFont          *font;
     int fontheight;
     int err;
     int quit = 0;


     DFBCHECK(DirectFBInit( &argc, &argv ));
     DFBCHECK(DirectFBCreate( &dfb ));

#if ((DIRECTFB_MAJOR_VERSION == 0) && (DIRECTFB_MINOR_VERSION == 9) && (DIRECTFB_MICRO_VERSION < 23))
     dfb->GetCardCapabilities( dfb, &caps );
#else
     dfb->GetDeviceDescription( dfb, &caps );
#endif

     dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer );

     if (!((caps.blitting_flags & DSBLIT_BLEND_ALPHACHANNEL) &&
           (caps.blitting_flags & DSBLIT_BLEND_COLORALPHA  )))
     {
          layer_config.flags = DLCONF_BUFFERMODE;
          layer_config.buffermode = DLBM_BACKSYSTEM;

          layer->SetConfiguration( layer, &layer_config );
     }

     layer->GetConfiguration( layer, &layer_config );
     layer->EnableCursor ( layer, 1 );

     {
          DFBFontDescription desc;

          desc.flags = DFDESC_HEIGHT;
          desc.height = layer_config.width/50;

          DFBCHECK(dfb->CreateFont( dfb, PACKAGE_DATA_DIR"/grunge.ttf", &desc, &font ));
          font->GetHeight( font, &fontheight );
     }

     {
          DFBSurfaceDescription desc;

          DFBCHECK(dfb->CreateImageProvider( dfb,
                                             PACKAGE_DATA_DIR"/bg.png",
                                             &provider ));

          desc.flags = DSDESC_WIDTH | DSDESC_HEIGHT;
          desc.width = layer_config.width;
          desc.height = layer_config.height;

          DFBCHECK(dfb->CreateSurface( dfb, &desc, &bgsurface ) );


          provider->RenderTo( provider, bgsurface, NULL );
          provider->Release( provider );

	  DFBCHECK(bgsurface->SetFont( bgsurface, font ));

          bgsurface->SetColor( bgsurface, 0xCF, 0xCF, 0xFF, 0xFF );
          bgsurface->DrawString( bgsurface,
                                 "Move the mouse over a window to activate it.",
                                 -1, 10, 0, DSTF_LEFT | DSTF_TOP );

          bgsurface->SetColor( bgsurface, 0xFF, 0xCF, 0xFF, 0xFF );
          bgsurface->DrawString( bgsurface,
                    "You can drag them around, too, if you want.",
                                 -1, 10 , 40, DSTF_LEFT | DSTF_TOP );

          bgsurface->SetColor( bgsurface, 0xCF, 0xCF, 0xFF, 0xFF );
	  bgsurface->DrawString( bgsurface,
                    "The one with funky stuff happening and things flying around is an evas.",
                                 -1, 10, 80, DSTF_LEFT | DSTF_TOP );




          layer->SetBackgroundImage( layer, bgsurface );
          layer->SetBackgroundMode( layer, DLBM_IMAGE );
     }
     {
	  DFBWindowDescription desc;
	  desc.flags = ( DWDESC_POSX | DWDESC_POSY |
                         DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS );

	  desc.posx = 20;
          desc.posy = 120;
          desc.width = 200;
          desc.height = 200;
	  desc.caps = DWCAPS_ALPHACHANNEL;

          DFBCHECK( layer->CreateWindow( layer, &desc, &window2 ) );
          window2->GetSurface( window2, &window_surface2 );

          window2->SetOpacity( window2, 0xFF );

          window2->CreateEventBuffer( window2, &buffer );

	  {
	     window_surface2->SetColor( window_surface2,
		   0x00, 0x30, 0x10, 0xc0 );
	     window_surface2->DrawRectangle( window_surface2, 0, 0,
		   desc.width, desc.height );
	     window_surface2->SetColor( window_surface2,
		   0x80, 0xa0, 0x00, 0x90 );
	     window_surface2->FillRectangle( window_surface2, 1, 1,
		   desc.width-2, desc.height-2 );


	     DFBCHECK(window_surface2->SetFont(window_surface2, font ));
	     window_surface2->SetColor( window_surface2, 0xCF, 0xFF, 0xCF, 0xFF );

	     window_surface2->DrawString( window_surface2,
		   "Pants!",
		   -1,10, fontheight + 5, DSTF_LEFT | DSTF_TOP );

	  }

          window_surface2->Flip( window_surface2, NULL, 0 );
     }

     {
          DFBWindowDescription desc;

          desc.flags = ( DWDESC_POSX | DWDESC_POSY |
                         DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS );
          desc.posx = 200;
          desc.posy = 200;
          desc.width = 240;
          desc.height = 320;
          desc.caps = DWCAPS_ALPHACHANNEL;

          DFBCHECK(layer->CreateWindow( layer, &desc, &window1 ) );
          window1->GetSurface( window1, &window_surface1 );

          window_surface1->SetColor( window_surface1, 0xFF, 0x20, 0x20, 0x90 );
          window_surface1->DrawRectangle( window_surface1, 0, 0,
                                          desc.width, desc.height );

          window_surface1->Flip( window_surface1, NULL, 0 );

          window1->SetOpacity( window1, 0xFF );

          window1->GetID( window1, &id1 );

          window1->AttachEventBuffer( window1, buffer );
     }

     window1->RequestFocus( window1 );
     window1->RaiseToTop( window1 );
     upper = window1;
     {
	evas_init();
	evas = evas_new();
	evas_output_method_set(evas, evas_render_method_lookup("directfb"));
	evas_output_size_set(evas, 240, 320);
	evas_output_viewport_set(evas, 0, 0, 240, 320);
	{
	   Evas_Engine_Info_DirectFB *einfo;

	   einfo = (Evas_Engine_Info_DirectFB *) evas_engine_info_get(evas);

	   einfo->info.dfb = dfb;
	   einfo->info.surface = window_surface1;
	   einfo->info.flags = DSDRAW_BLEND;
	   evas_engine_info_set(evas, (Evas_Engine_Info *) einfo);
	}
	setup();
	evas_render(evas);
	start_time = get_time();
     }

     while (!quit) {
          static IDirectFBWindow* active = NULL;
          static int grabbed = 0;
          static int startx = 0;
          static int starty = 0;
          static int endx = 0;
          static int endy = 0;
          DFBWindowEvent evt;

          buffer->WaitForEventWithTimeout( buffer, 0, 10 );

          while (buffer->GetEvent( buffer, DFB_EVENT(&evt) ) == DFB_OK) {
               IDirectFBWindow* window;

               if (evt.window_id == id1)
                    window = window1;
               else
                    window = window2;

               if (active) {
                    switch (evt.type) {

                    case DWET_BUTTONDOWN:
                         if (!grabbed && evt.button == DIBI_LEFT) {
                              grabbed = 1;
                              layer->GetCursorPosition( layer,
                                                        &startx, &starty );
                              window->GrabPointer( window );
                         }
                         break;

                    case DWET_BUTTONUP:
                         switch (evt.button) {
                              case DIBI_LEFT:
                                   if (grabbed) {
                                        window->UngrabPointer( window );
                                        grabbed = 0;
                                   }
                                   break;
                              case DIBI_MIDDLE:
                                   upper->LowerToBottom( upper );
                                   upper = (upper == window1) ? window2 : window1;
                                   break;
                              case DIBI_RIGHT:
                                   quit = DIKS_DOWN;
                                   break;
                              default:
                                   break;
                         }
                         break;

                    case DWET_KEYDOWN:
                         if (grabbed)
                              break;
                         switch (evt.key_id) {
                              case DIKI_RIGHT:
                                   active->Move (active, 1, 0);
                                   break;
                              case DIKI_LEFT:
                                   active->Move (active, -1, 0);
                                   break;
                              case DIKI_UP:
                                   active->Move (active, 0, -1);
                                   break;
                              case DIKI_DOWN:
                                   active->Move (active, 0, 1);
                                   break;
                              default:
                                   break;
                         }
                         break;

                    case DWET_LOSTFOCUS:
                         if (!grabbed)
                              active = NULL;
                         break;

                    default:
                         break;

                    }
               }
               else if (evt.type == DWET_GOTFOCUS)
                    active = window;

               switch (evt.type) {

               case DWET_MOTION:
                    endx = evt.cx;
                    endy = evt.cy;
                    break;

               case DWET_KEYDOWN:
                    switch (evt.key_symbol) {
                    case DIKS_ESCAPE:
                    case DIKS_SMALL_Q:
                    case DIKS_CAPITAL_Q:
                    case DIKS_BACK:
                    case DIKS_STOP:
                         quit = 1;
                         break;
                    default:
                         break;
                    }
                    break;

               default:
                    break;
               }
          }

          if (active) {
               if (grabbed) {
                    active->Move( active, endx - startx, endy - starty);
                    startx = endx;
                    starty = endy;
               }
               active->SetOpacity( active,
                                   (sin( myclock()/300.0 ) * 85) + 170 );
          }
	  loop();
	  {
	     Eina_List *updates;

	     updates = evas_render_updates(evas);
	     /* efficient update.. only flip the rectangle regions that changed! */
	     if (updates)
	       {
		  DFBRegion region;
		  Eina_List *l;

		  for (l = updates; l; l = l->next)
		    {
		       Evas_Rectangle *rect;

		       rect = l->data;
		       region.x1 = rect->x;
		       region.y1 = rect->y;
		       region.x2 = rect->x + rect->w - 1;
		       region.y2 = rect->y + rect->h - 1;
		       window_surface1->Flip(window_surface1, &region,
					     DSFLIP_BLIT);
		    }
		  evas_render_updates_free(updates);
	       }
	  }
     }

     buffer->Release( buffer );
     window_surface2->Release( window_surface2 );
     window_surface1->Release( window_surface1 );
     window2->Release( window2 );
     window1->Release( window1 );
     layer->Release( layer );
     bgsurface->Release( bgsurface );
     dfb->Release( dfb );

   evas_shutdown();
   return 0;
}
Пример #13
0
int
main( int argc, char *argv[] )
{
     DFBResult               ret;
     int                     i;
     DFBSurfaceDescription   desc;
     IDirectFB              *dfb;
     IDirectFBSurface       *dest          = NULL;
     DFBSurfacePixelFormat   dest_format   = DSPF_UNKNOWN;
     char                    pixel_buffer[100*100*4];
     IDirectFBSurface       *source        = NULL;
     IDirectFBEventBuffer   *keybuffer;
     DFBInputEvent           evt;
     bool                    quit          = false;

     /* Initialize DirectFB. */
     ret = DirectFBInit( &argc, &argv );
     if (ret) {
          D_DERROR( ret, "DFBTest/PreAlloc: DirectFBInit() failed!\n" );
          return ret;
     }

     /* Parse arguments. */
     for (i=1; i<argc; i++) {
          const char *arg = argv[i];

          if (strcmp( arg, "-h" ) == 0 || strcmp (arg, "--help") == 0)
               return print_usage( argv[0] );
          else if (strcmp (arg, "-v") == 0 || strcmp (arg, "--version") == 0) {
               fprintf (stderr, "dfbtest_blit version %s\n", DIRECTFB_VERSION);
               return false;
          }
          else if (strcmp (arg, "-d") == 0 || strcmp (arg, "--dest") == 0) {
               if (++i == argc) {
                    print_usage (argv[0]);
                    return false;
               }

               if (!parse_format( argv[i], &dest_format ))
                    return false;
          }
          else if (strcmp (arg, "-s") == 0 || strcmp (arg, "--static") == 0) {
               static_caps = DSCAPS_STATIC_ALLOC;
          }
          else
               return print_usage( argv[0] );
     }

     /* Create super interface. */
     ret = DirectFBCreate( &dfb );
     if (ret) {
          D_DERROR( ret, "DFBTest/PreAlloc: DirectFBCreate() failed!\n" );
          return ret;
     }

     /* Fill description for a primary surface. */
     desc.flags = DSDESC_CAPS;
     desc.caps  = DSCAPS_PRIMARY | DSCAPS_FLIPPING;

     if (dest_format != DSPF_UNKNOWN) {
          desc.flags       |= DSDESC_PIXELFORMAT;
          desc.pixelformat  = dest_format;
     }

     dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );

     /* Create an input buffer for key events */
     dfb->CreateInputEventBuffer( dfb, DICAPS_KEYS,
                                  DFB_TRUE, &keybuffer);

     /* Create a primary surface. */
     ret = dfb->CreateSurface( dfb, &desc, &dest );
     if (ret) {
          D_DERROR( ret, "DFBTest/PreAlloc: IDirectFB::CreateSurface() for the destination failed!\n" );
          goto out;
     }

     dest->GetSize( dest, &desc.width, &desc.height );
     dest->GetPixelFormat( dest, &desc.pixelformat );

     D_INFO( "DFBTest/PreAlloc: Destination is %dx%d using %s\n",
             desc.width, desc.height, dfb_pixelformat_name(desc.pixelformat) );

     /* Create a preallocated surface. */
     desc.flags                 = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS | DSDESC_PREALLOCATED;
     desc.width                 = 100;
     desc.height                = 100;
     desc.pixelformat           = DSPF_ARGB;
     desc.caps                  = static_caps;
     desc.preallocated[0].data  = pixel_buffer;
     desc.preallocated[0].pitch = 100 * 4;

     ret = dfb->CreateSurface( dfb, &desc, &source );
     if (ret) {
          D_DERROR( ret, "DFBTest/PreAlloc: IDirectFB::CreateSurface() for the preallocated source failed!\n" );
          goto out;
     }

     /* Before any other operation the pixel data can be written to without locking */
     gen_pixels( pixel_buffer, 100 * 4, 100 );

     while (!quit) {
          void *ptr;
          int   pitch;


          /* Lock source surface for writing before making updates to the pixel buffer */
          source->Lock( source, DSLF_WRITE, &ptr, &pitch );

          if (ptr == pixel_buffer)
               D_INFO( "DFBTest/PreAlloc: Locking preallocated source gave original preallocated pixel buffer :-)\n" );
          else {
               if (static_caps)
                    D_INFO( "DFBTest/PreAlloc: Locking preallocated source gave different pixel buffer, ERROR with static alloc!\n" );
               else
                    D_INFO( "DFBTest/PreAlloc: Locking preallocated source gave different pixel buffer, but OK (no static alloc)\n" );
          }

          update_pixels( ptr, pitch, 100 );

          /* Unlock source surface after writing, before making further Blits,
             to have the buffer be transfered to master again */
          source->Unlock( source );


          dest->Clear( dest, 0, 0, 0, 0xff );

          /* First Blit from preallocated source, data will be transfered to master */
          dest->Blit( dest, source, NULL, 50, 50 );

          /* Second Blit from preallocated source, data is already master */
          dest->Blit( dest, source, NULL, 150, 150 );

          dest->Flip( dest, NULL, DSFLIP_NONE );

          /* This will upload again the preallocated buffer to the master, where it is
             modified and outdates the preallocated buffer. Now it depends on the static
             alloc flag whether the next Lock will directly go into the shared memory
             allocation or the preallocated buffer again (with a transfer back from master
             to us). */
          source->FillRectangle( source, 0, 0, 10, 10 );

          /* Process keybuffer */
          while (keybuffer->GetEvent( keybuffer, DFB_EVENT(&evt)) == DFB_OK)
          {
              if (evt.type == DIET_KEYPRESS) {
                  switch (DFB_LOWER_CASE(evt.key_symbol)) {
                      case DIKS_ESCAPE:
                      case DIKS_SMALL_Q:
                      case DIKS_BACK:
                      case DIKS_STOP:
                      case DIKS_EXIT:
                          /* Quit main loop & test thread */
                          quit = true;
                          break;
                      default:
                          break;
                  }
              }
          }
          if (!quit)
          sleep( 5 );
     }

out:
     if (source)
          source->Release( source );

     if (dest)
          dest->Release( dest );

     keybuffer->Release( keybuffer );

     /* Shutdown DirectFB. */
     dfb->Release( dfb );

     return ret;
}
Пример #14
0
int
main( int argc, char *argv[] )
{
     DFBResult              err;
     DFBSurfaceDescription  sdsc;
     DFBFontDescription     fdsc;
     const char            *fontfile = FONTDIR"/decker.ttf";
     int                    n;
     DeviceInfo            *devices = NULL;

     DFBCHECK(DirectFBInit( &argc, &argv ));

     DirectFBSetOption ("bg-none", NULL);

     /* create the super interface */
     DFBCHECK(DirectFBCreate( &dfb ));

     /* create a list of input devices */
     dfb->EnumInputDevices( dfb, enum_input_device, &devices );

     /* create an event buffer for all devices */
     DFBCHECK(dfb->CreateInputEventBuffer( dfb, DICAPS_ALL,
                                           DFB_FALSE, &events ));

     /* set our cooperative level to DFSCL_FULLSCREEN
        for exclusive access to the primary layer */
     dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );

     /* get the primary surface, i.e. the surface of the
        primary layer we have exclusive access to */
     sdsc.flags = DSDESC_CAPS;
     sdsc.caps  = DSCAPS_PRIMARY | DSCAPS_DOUBLE;

     DFBCHECK(dfb->CreateSurface( dfb, &sdsc, &primary ));

     primary->GetSize( primary, &screen_width, &screen_height );

     mouse_x = screen_width  / 2;
     mouse_y = screen_height / 2;

     fdsc.flags = DFDESC_HEIGHT;

     fdsc.height = screen_width / 30;
     DFBCHECK(dfb->CreateFont( dfb, fontfile, &fdsc, &font_small ));

     fdsc.height = screen_width / 20;
     DFBCHECK(dfb->CreateFont( dfb, fontfile, &fdsc, &font_normal ));

     fdsc.height = screen_width / 10;
     DFBCHECK(dfb->CreateFont( dfb, fontfile, &fdsc, &font_large ));

     primary->Clear( primary, 0, 0, 0, 0 );
     primary->SetFont( primary, font_normal );
     primary->SetColor( primary, 0x60, 0x60, 0x60, 0xFF );
     primary->DrawString( primary, "Press any key to continue.", -1,
                          screen_width/2, screen_height/2, DSTF_CENTER );
     primary->Flip( primary, NULL, 0 );

     keys_image  = load_image( IMGDIR "/gnu-keys.png" );
     mouse_image = load_image( IMGDIR "/gnome-mouse.png" );

     if (events->WaitForEventWithTimeout( events, 10, 0 ) == DFB_TIMEOUT) {
          primary->Clear( primary, 0, 0, 0, 0 );
          primary->DrawString( primary, "Timed out.", -1,
                               screen_width/2, screen_height/2, DSTF_CENTER );
          primary->Flip( primary, NULL, 0 );
          primary->Clear( primary, 0, 0, 0, 0 );
          sleep( 1 );
     }
     else {
          DFBInputDeviceKeySymbol  last_symbol = DIKS_NULL;

          while (1) {
               DFBInputEvent evt;

               while (events->GetEvent( events, DFB_EVENT(&evt) ) == DFB_OK) {
                    const char *device_name;
                    DFBInputDeviceTypeFlags device_type;

                    primary->Clear( primary, 0, 0, 0, 0 );

                    device_name  = get_device_name( devices, evt.device_id );
                    device_type  = get_device_type( devices, evt.device_id );

                    show_event( device_name, device_type, &evt );

                    primary->Flip( primary, NULL, 0 );
               }

               if (evt.type == DIET_KEYRELEASE) {
                    if ((last_symbol == DIKS_ESCAPE || last_symbol == DIKS_EXIT) &&
                        (evt.key_symbol == DIKS_ESCAPE || evt.key_symbol == DIKS_EXIT))
                         break;
                    last_symbol = evt.key_symbol;
               }

               events->WaitForEvent( events );
          }
     }

     while (devices) {
          DeviceInfo *next = devices->next;

          free( devices );
          devices = next;
     }

     /* release our interfaces to shutdown DirectFB */
     if (keys_image)
          keys_image->Release( keys_image );
     if (mouse_image)
          mouse_image->Release( mouse_image );

     font_small->Release( font_small );
     font_normal->Release( font_normal );
     font_large->Release( font_large );

     primary->Release( primary );
     events->Release( events );
     dfb->Release( dfb );

     return 0;
}
Пример #15
0
int main( int argc, char *argv[] )
{
     int                   quit = 0;
     pthread_t             render_loop_thread = -1;

     IDirectFBSurface     *primary;
     IDirectFBEventBuffer *buffer;

     DFBSurfaceDescription dsc;


     srand((long)time(0));

     DFBCHECK(DirectFBInit( &argc, &argv ));

     /* create the super interface */
     DFBCHECK(DirectFBCreate( &dfb ));

     /* get an interface to the primary keyboard and create an
        input buffer for it */
     DFBCHECK(dfb->CreateInputEventBuffer( dfb, DICAPS_ALL, DFB_FALSE, &buffer ));

     /* set our cooperative level to DFSCL_FULLSCREEN for exclusive access to
        the primary layer */
     dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );

     /* get the primary surface, i.e. the surface of the primary layer we have
        exclusive access to */
     dsc.flags = DSDESC_CAPS;
     dsc.caps = DSCAPS_PRIMARY | DSCAPS_DOUBLE;

     DFBCHECK(dfb->CreateSurface( dfb, &dsc, &primary ));

     DFBCHECK(primary->GetSize( primary, &xres, &yres ));

     /* load font */
     {
          DFBFontDescription desc;

          desc.flags = DFDESC_HEIGHT;
          desc.height = yres/10;

          DFBCHECK(dfb->CreateFont( dfb, FONT, &desc, &font ));
          DFBCHECK(primary->SetFont( primary, font ));
     }

     projection = matrix_new_perspective( 400 );
     camera = matrix_new_identity();

     load_stars();

     generate_starfield();

     pthread_mutex_lock( &render_start );
     pthread_mutex_lock( &render_finish );
     pthread_create( &render_loop_thread, NULL, render_loop, (void*)primary );

     /* main loop */
     while (!quit) {
          static float  translation[3] = { 0, 0, 0 };
          DFBInputEvent evt;

          /* transform world to screen coordinates */
          transform_starfield();

          /* start rendering before waiting for events */
          start_rendering();


          buffer->WaitForEvent( buffer );

          /* process event buffer */
          while (buffer->GetEvent( buffer, DFB_EVENT(&evt)) == DFB_OK) {
               if (evt.type == DIET_KEYPRESS) {
                    switch (evt.key_id) {
                         case DIKI_ESCAPE:
                              /* quit main loop */
                              quit = 1;
                              break;

                         case DIKI_LEFT:
                              translation[0] =  10;
                              break;

                         case DIKI_RIGHT:
                              translation[0] = -10;
                              break;

                         case DIKI_UP:
                              translation[2] = -10;
                              break;

                         case DIKI_DOWN:
                              translation[2] =  10;
                              break;

                         default:
                              break;
                    }
               } else
               if (evt.type == DIET_KEYRELEASE) {
                    switch (evt.key_id) {
                         case DIKI_LEFT:
                         case DIKI_RIGHT:
                              translation[0] = 0;
                              break;

                         case DIKI_UP:
                         case DIKI_DOWN:
                              translation[2] = 0;
                              break;

                         default:
                              break;
                    }
               } else
               if (evt.type == DIET_AXISMOTION  && (evt.flags & DIEF_AXISREL)) {
                    switch (evt.axis) {
                         case DIAI_X:
                              matrix_rotate( camera, Y, -evt.axisrel/80.0f );
                              break;

                         case DIAI_Y:
                              matrix_rotate( camera, X,  evt.axisrel/80.0f );
                              break;

                         default:
                              break;
                    }
               }
          }

          matrix_translate( camera,
                            translation[0], translation[1], translation[2] );

          /* finish rendering before retransforming the world */
          finish_rendering();
     }

     pthread_cancel( render_loop_thread );
     pthread_mutex_unlock( &render_start );
     pthread_join( render_loop_thread, NULL );
     render_loop_thread = -1;


     unload_stars();

     free( camera );
     free( projection );

     buffer->Release( buffer );
     primary->Release( primary );
     dfb->Release( dfb );

     return 0;
}
/* FIXME: Remove once determined this is not needed in fullscreen mode */
void
DirectFB_PumpEvents(_THIS)
{
    SDL_DFB_DEVICEDATA(_this);
    DFBInputEvent evt;
    static last_x = 0, last_y = 0;

    while (devdata->eventbuffer->GetEvent(devdata->eventbuffer,
                                          DFB_EVENT(&evt)) == DFB_OK) {
        SDL_keysym keysym;
        DFBInputDeviceModifierMask mod;

        if (evt.clazz = DFEC_INPUT) {
            if (evt.flags & DIEF_MODIFIERS)
                mod = evt.modifiers;
            else
                mod = 0;

            switch (evt.type) {
            case DIET_BUTTONPRESS:
                posted +=
                    SDL_PrivateMouseButton(SDL_PRESSED,
                                           DirectFB_TranslateButton
                                           (evt.button), 0, 0);
                break;
            case DIET_BUTTONRELEASE:
                posted +=
                    SDL_PrivateMouseButton(SDL_RELEASED,
                                           DirectFB_TranslateButton
                                           (evt.button), 0, 0);
                break;
            case DIET_KEYPRESS:
                posted +=
                    SDL_PrivateKeyboard(SDL_PRESSED,
                                        DirectFB_TranslateKey
                                        (evt.key_id, evt.key_symbol,
                                         mod, &keysym));
                break;
            case DIET_KEYRELEASE:
                posted +=
                    SDL_PrivateKeyboard(SDL_RELEASED,
                                        DirectFB_TranslateKey
                                        (evt.key_id, evt.key_symbol,
                                         mod, &keysym));
                break;
            case DIET_AXISMOTION:
                if (evt.flags & DIEF_AXISREL) {
                    if (evt.axis == DIAI_X)
                        posted +=
                            SDL_PrivateMouseMotion(0, 1, evt.axisrel, 0);
                    else if (evt.axis == DIAI_Y)
                        posted +=
                            SDL_PrivateMouseMotion(0, 1, 0, evt.axisrel);
                } else if (evt.flags & DIEF_AXISABS) {
                    if (evt.axis == DIAI_X)
                        last_x = evt.axisabs;
                    else if (evt.axis == DIAI_Y)
                        last_y = evt.axisabs;
                    posted += SDL_PrivateMouseMotion(0, 0, last_x, last_y);
                }
                break;
            default:
                ;
            }
        }
    }
}
Пример #17
0
int
main( int argc, char *argv[] )
{
     DFBResult ret;
     int       i;
     int       quit = 0;
     const int num = 2;
     Context   contexts[num];

     DFBCHECK(DirectFBInit( &argc, &argv ));

     /* create the super interface */
     DFBCHECK(DirectFBCreate( &dfb ));

     DFBCHECK(dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer ));

     /* create the default font */
     DFBCHECK(dfb->CreateFont( dfb, NULL, NULL, &font ));

     for (i=0; i<num; i++) {
          IDirectFBWindow      *window;
          IDirectFBSurface     *surface;
          IDirectFBGL          *gl;
          DFBWindowDescription  desc;

          desc.flags  = DWDESC_POSX | DWDESC_POSY |
                        DWDESC_WIDTH | DWDESC_HEIGHT;
          desc.posx   = (i%3) * 200 + 10;
          desc.posy   = (i/3) * 200 + 10;
          desc.width  = 180;
          desc.height = 180;

          DFBCHECK(layer->CreateWindow( layer, &desc, &window ));
          DFBCHECK(window->GetSurface( window, &surface ));
          DFBCHECK(surface->GetGL( surface, &gl ));

          contexts[i].window    = window;
          contexts[i].surface   = surface;
          contexts[i].gl        = gl;

          contexts[i].last_time = get_millis();
          contexts[i].frames    = 0;
          contexts[i].fps       = 0;

          setup( &contexts[i] );

          if (events)
               DFBCHECK(window->AttachEventBuffer( window, events ));
          else
               DFBCHECK(window->CreateEventBuffer( window, &events ));
          
          DFBCHECK(surface->SetFont( surface, font ));

          window->SetOpacity( window, 0xff );
     }
     
     while (!quit) {
          DFBWindowEvent evt;

          for (i=0; i<num; i++)
               update( &contexts[i] );
          
          while (events->GetEvent( events, DFB_EVENT(&evt) ) == DFB_OK) {
               switch (evt.type) {
                    case DWET_KEYDOWN:
                         switch (evt.key_symbol) {
                              case DIKS_ESCAPE:
                                   quit = 1;
                                   break;

                              default:
                                   break;
                         }
                         break;

                    default:
                         break;
               }
          }
     }

     events->Release( events );

     for (i=0; i<num; i++) {
          contexts[i].gl->Release( contexts[i].gl );
          contexts[i].surface->Release( contexts[i].surface );
          contexts[i].window->Release( contexts[i].window );
     }

     font->Release( font );
     layer->Release( layer );
     dfb->Release( dfb );

     return 0;
}
Пример #18
0
static DFBResult
Test_Sensitivity( IDirectFB        *dfb,
                  DFBInputDeviceID  device_id )
{
     DFBResult             ret;
     IDirectFBInputDevice *device;
     IDirectFBEventBuffer *buffer;
     int                   i, n;
     int                   sensitivities[] = { 0x100, 0x200, 0x80 };

     D_INFO( "DFBTest/Input: Testing sensitivity with input device %u...\n", device_id );

     ret = dfb->GetInputDevice( dfb, device_id, &device );
     if (ret) {
          D_DERROR( ret, "DFBTest/Input: GetInputDevice( %u ) failed!\n", device_id );
          return ret;
     }

     ret = device->CreateEventBuffer( device, &buffer );
     if (ret) {
          D_DERROR( ret, "DFBTest/Input: CreateEventBuffer() failed!\n" );
          device->Release( device );
          return ret;
     }

     for (i=0; i<D_ARRAY_SIZE(sensitivities); i++) {
          DFBInputDeviceConfig config;
          unsigned int         move = 0;

          D_INFO( "DFBTest/Input: Setting sensitivity to 0x%x, please move mouse!\n", sensitivities[i] );

          config.flags       = DIDCONF_SENSITIVITY;
          config.sensitivity = sensitivities[i];

          ret = device->SetConfiguration( device, &config );
          if (ret) {
               D_DERROR( ret, "DFBTest/Input: SetConfiguration() failed!\n" );
               buffer->Release( buffer );
               device->Release( device );
               return ret;
          }

          buffer->Reset( buffer );

          for (n=0; n<500; n++) {
               DFBInputEvent event;

               buffer->WaitForEvent( buffer );

               buffer->GetEvent( buffer, DFB_EVENT(&event) );

               switch (event.type) {
                    case DIET_AXISMOTION:
                         if (event.flags & DIEF_AXISREL) {
                              //D_INFO( "DFBTest/Input: Motion (axis %d) by %d\n", event.axis, event.axisrel );

                              if (event.axisrel > 0)
                                   move += event.axisrel;
                              else
                                   move -= event.axisrel;
                         }

                         break;

                    default:
                         break;
               }
          }

          D_INFO( "DFBTest/Input: Average movement %d.\n", move / n );

          direct_thread_sleep( 1000000 );
     }

     buffer->Release( buffer );
     device->Release( device );

     return DFB_OK;
}
Пример #19
0
int
main (int    argc,
      char **argv)
{
  DFBSurfaceDescription   dsc;
  DFBSurfaceDescription   back_dsc;
  DFBRectangle            rect;
  IDirectFBImageProvider *provider;
  IDirectFBEventBuffer   *keybuffer;
  DFBInputEvent           evt;
  int                     width;
  int                     height;
  int                     quit;
  unsigned int            cycle_len;
  struct timeval          tv;
  long                    start_time;
  long                    current_time;
  long                    frame_delay;
  long                    delay;

  frame_delay = delay = FRAME_DELAY;
  cycle_len   = CYCLE_LEN;
  quit        = FALSE;

  DFBCHECK (DirectFBInit (&argc, &argv));

  if (argc > 1 && argv[1] && strcmp (argv[1], "--on-crack") == 0)
    on_crack = TRUE;

  /* create the super interface */
  DFBCHECK (DirectFBCreate (&dfb));

  dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN);
  DFBCHECK (dfb->CreateInputEventBuffer (dfb, DICAPS_KEYS,
                                         DFB_FALSE, &keybuffer));

  /*  create the primary surface  */
  dsc.flags = DSDESC_CAPS;
  dsc.caps  = DSCAPS_PRIMARY;

  if (!on_crack) {
       dsc.caps |= DSCAPS_TRIPLE;

       if (dfb->CreateSurface (dfb, &dsc, &primary) != DFB_OK) {
            dsc.caps = (dsc.caps & ~DSCAPS_TRIPLE) | DSCAPS_DOUBLE;
            DFBCHECK (dfb->CreateSurface (dfb, &dsc, &primary));
       }
  }
  else
       DFBCHECK (dfb->CreateSurface (dfb, &dsc, &primary));

  /* load size of background image */
  DFBCHECK (dfb->CreateImageProvider (dfb, BACKGROUND_NAME, &provider));
  DFBCHECK (provider->GetSurfaceDescription (provider, &back_dsc));
  back_width  = back_dsc.width;
  back_height = back_dsc.height;

  if (!back_width || !back_height)
    return -1;

  /*  create the background surface  */
  DFBCHECK (dfb->CreateSurface (dfb, &back_dsc, &background));
  provider->RenderTo (provider, background, NULL);
  provider->Release (provider);

  /*  create subsurface in the middle of the screen */
  primary->GetSize (primary, &width, &height);
  rect.x = (width  - back_width)  / 2;
  rect.y = (height - back_height) / 2;
  rect.w = back_width;
  rect.h = back_height;
  primary->GetSubSurface (primary, &rect, &sub);

  if (on_crack)
    {
      /* clear screen */
      primary->Clear (primary, 0, 0, 0, 0xff);
    }
  else
    {
      /*  fill screen and backbuffers with tiled background  */
      primary->TileBlit (primary, background, NULL, rect.x, rect.y);
      primary->Flip (primary, NULL, 0) ;
      primary->TileBlit (primary, background, NULL, rect.x, rect.y);
      primary->Flip (primary, NULL, 0) ;
      primary->TileBlit (primary, background, NULL, rect.x, rect.y);

      primary->SetClip (primary, NULL);
    }

  /*  load the remaining images  */
  load_images ();

  frame_num = 0;

  while (!quit)
    {
      gettimeofday (&tv, NULL);
      start_time = tv.tv_sec * 1000 + tv.tv_usec / 1000;

      timeout (cycle_len);

      while (keybuffer->GetEvent (keybuffer, DFB_EVENT(&evt)) == DFB_OK)
        {
          if (evt.type == DIET_KEYPRESS)
            {
              switch (evt.key_id)
                {
                case DIKI_LEFT:
                  frame_delay = MIN (500, frame_delay + 5);
                  break;
                case DIKI_RIGHT:
                  frame_delay = MAX (0, frame_delay - 5);
                  break;
                case DIKI_UP:
                  cycle_len = MIN (600, cycle_len + 6);
                  break;
                case DIKI_DOWN:
                  cycle_len = cycle_len > 6 ? cycle_len - 6 : 6;
                  break;
                case DIKI_SPACE:
                case DIKI_ENTER:
                  colorize = !colorize;
                  break;
                case DIKI_A:
                  alpha = !alpha;
                  break;
                case DIKI_HOME:
                  cycle_len   = CYCLE_LEN;
                  frame_delay = FRAME_DELAY;
                  colorize    = TRUE;
                  alpha       = TRUE;
                  break;
                case DIKI_ESCAPE:
                case DIKI_Q:
                  quit = TRUE;
                  break;
                default:
                  break;
                }

              switch (evt.key_symbol)
                {
                case DIKS_OK:
                  colorize = !colorize;
                  break;
                case DIKS_BACK:
                case DIKS_STOP:
                  quit = TRUE;
                  break;
                default:
                  break;
                }
            }
        }

      if (frame_delay)
        {
          gettimeofday (&tv, NULL);
          current_time = tv.tv_sec * 1000 + tv.tv_usec / 1000;

          delay = frame_delay - (current_time - start_time);
          if (delay > 0)
            usleep (1000 * delay);
        }
    }

  keybuffer->Release (keybuffer);
  release_images ();
  background->Release (background);
  sub->Release (sub);
  primary->Release (primary);
  dfb->Release (dfb);

  return 0;
}
Пример #20
0
int
main( int argc, char *argv[] )
{
     DFBResult              ret;
     bool                   quit = false;
     int                    i;
     IDirectFB              dfb;
     IDirectFBDisplayLayer  layer;
     IDirectFBSurface       surface;
     DFBDisplayLayerConfig  config;
     DFBDimension           sizes[2]  = { {400, 400}, {600, 600} };
     size_t                 num_sizes = D_ARRAY_SIZE(sizes);
     DFBInputEvent          evt;
     IDirectFBEventBuffer   keybuffer;

     /* Initialize DirectFB. */
     DirectFB::Init( &argc, &argv );

     /* Create super interface. */
     dfb = DirectFB::Create();

     layer = dfb.GetDisplayLayer( DLID_PRIMARY );

     /* Create an input buffer for key events */
     keybuffer = dfb.CreateInputEventBuffer( DICAPS_KEYS, DFB_TRUE );

     layer.SetCooperativeLevel( DLSCL_EXCLUSIVE );

     layer.GetConfiguration( &config );

     config.width  = sizes[0].w;
     config.height = sizes[0].h;

     layer.SetConfiguration( config );

     surface = layer.GetSurface();

     while (true) {
          surface.Clear( 0, 0, 0, 0xff );

          surface.SetColor( 0x00, 0xff, 0x00, 0xff );
          surface.DrawRectangle( 0, 0, config.width, config.height );

          surface.Flip( NULL, DSFLIP_NONE );


          keybuffer.WaitForEventWithTimeout( 3, 0 );

          /* Process keybuffer */
          while (keybuffer.GetEvent( DFB_EVENT(&evt) )) {
              if (evt.type == DIET_KEYPRESS) {
                  switch (DFB_LOWER_CASE(evt.key_symbol)) {
                      case DIKS_ESCAPE:
                      case DIKS_SMALL_Q:
                      case DIKS_BACK:
                      case DIKS_STOP:
                      case DIKS_EXIT:
                          /* Quit main loop & test thread */
                          quit = 1;
                          break;

                      case DIKS_SPACE:
                      case DIKS_OK:
                          i++;

                          config.width  = sizes[i % num_sizes].w;
                          config.height = sizes[i % num_sizes].h;

                          layer.SetConfiguration( config );
                          break;

                      default:
                          break;
                  }
              }
          }
     }

     return 0;
}
Пример #21
0
static void
TestResize( IDirectFB *dfb )
{
     DFBResult              ret;
     DirectThread          *thread;
     DFBWindowDescription   desc;
     IDirectFBDisplayLayer *layer;
     IDirectFBWindow       *window;
     IDirectFBSurface      *surface;
     DFBInputEvent          evt;
     IDirectFBEventBuffer  *keybuffer;

     quit = 0;

     /* Create an input buffer for key events */
     ret = dfb->CreateInputEventBuffer( dfb, DICAPS_KEYS,
                                        DFB_FALSE, &keybuffer);
     if (ret) {
          D_DERROR( ret, "DFBTest/Resize: CreateInputBuffer() failed!\n" );
          return;
     }

     ret = dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer );
     if (ret) {
          D_DERROR( ret, "DFBTest/Resize: Failed to get display layer!\n" );
          keybuffer->Release( keybuffer );
          return;
     }

     desc.flags       = DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_PIXELFORMAT;
     desc.width       = 500;
     desc.height      = 500;
     desc.pixelformat = DSPF_ARGB;

     ret = layer->CreateWindow( layer, &desc, &window );
     if (ret) {
          D_DERROR( ret, "DFBTest/Resize: CreateWindow() failed!\n" );
          keybuffer->Release( keybuffer );
          layer->Release( layer );
          return;
     }

     ret = window->GetSurface( window, &surface );
     if (ret) {
          D_DERROR( ret, "DFBTest/Resize: GetSurface() failed!\n" );
          keybuffer->Release( keybuffer );
          window->Release( window );
          layer->Release( layer );
          return;
     }

     thread = direct_thread_create( DTT_DEFAULT, TestThread, surface, "Test" );

     while (!quit) {

          ret = window->Resize( window, 500, 400 );
          if (ret)
               D_DERROR( ret, "DFBTest/Resize: Resize() failed!\n" );

          ret = window->Resize( window, 500, 500 );
          if (ret)
               D_DERROR( ret, "DFBTest/Resize: Resize() failed!\n" );

          /* Process keybuffer */
          while (keybuffer->GetEvent( keybuffer, DFB_EVENT(&evt)) == DFB_OK)
          {
              if (evt.type == DIET_KEYPRESS) {
                  switch (DFB_LOWER_CASE(evt.key_symbol)) {
                      case DIKS_ESCAPE:
                      case DIKS_SMALL_Q:
                      case DIKS_BACK:
                      case DIKS_STOP:
                      case DIKS_EXIT:
                          /* Quit main loop & test thread */
                          quit = 1;
                          direct_thread_join(thread);
                          break;
                      default:
                          break;
                  }
              }
          }
     }

     keybuffer->Release( keybuffer );
     surface->Release( surface );
     window->Release( window );
     layer->Release( layer );
}
Пример #22
0
int
main( int argc, char *argv[] )
{
     int                    quit = 0;
     DFBResult              err;
     DFBSurfaceDescription  sdsc;

     DFBCHECK(DirectFBInit( &argc, &argv ));

     /* create the super interface */
     DFBCHECK(DirectFBCreate( &dfb ));

     /* create an event buffer for all devices */
     DFBCHECK(dfb->CreateInputEventBuffer( dfb, DICAPS_ALL,
                                           DFB_FALSE, &events ));

     /* set our cooperative level to DFSCL_FULLSCREEN
        for exclusive access to the primary layer */
     dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );

     /* get the primary surface, i.e. the surface of the
        primary layer we have exclusive access to */
     sdsc.flags       = DSDESC_CAPS | DSDESC_PIXELFORMAT;
     sdsc.caps        = DSCAPS_PRIMARY;
     sdsc.pixelformat = DSPF_LUT8;

     DFBCHECK(dfb->CreateSurface( dfb, &sdsc, &primary ));

     primary->Clear( primary, 0, 0, 0, 0 );

     primary->GetSize( primary, &screen_width, &screen_height );

     /* get access to the palette */
     DFBCHECK(primary->GetPalette( primary, &palette ));

     generate_palette();

     fill_surface( primary );
     
     while (!quit) {
          DFBInputEvent evt;

          while (events->GetEvent( events, DFB_EVENT(&evt) ) == DFB_OK) {
               switch (evt.type) {
                    case DIET_KEYPRESS:
                         switch (evt.key_symbol) {
                              case DIKS_ESCAPE:
                                   quit = 1;
                                   break;
                              default:
                                   ;
                         }
                    default:
                         ;
               }
          }

          rotate_palette();
     }

     /* release our interfaces to shutdown DirectFB */
     palette->Release( palette );
     primary->Release( primary );
     events->Release( events );
     dfb->Release( dfb );

     return 0;
}
Пример #23
0
int main( int argc, char *argv[] )
{
     int                     i;
     int                     step;
     DFBResult               err;
     DFBSurfaceDescription   sdsc;
     DFBFontDescription      fdsc;
     IDirectFBImageProvider *provider;

     DFBCHECK(DirectFBInit( &argc, &argv ));

     /* create the super interface */
     DFBCHECK(DirectFBCreate( &dfb ));

     /* create an event buffer with all devices attached that have keys */
     DFBCHECK(dfb->CreateInputEventBuffer( dfb, DIDCAPS_KEYS, DFB_FALSE, &events ));

     /* set our cooperative level to DFSCL_FULLSCREEN
        for exclusive access to the primary layer */
     dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );


     /* get the primary surface, i.e. the surface of the
        primary layer we have exclusive access to */
     sdsc.flags = DSDESC_CAPS;
     sdsc.caps  = DSCAPS_PRIMARY | DSCAPS_FLIPPING | DSCAPS_PREMULTIPLIED;

     DFBCHECK(dfb->CreateSurface( dfb, &sdsc, &primary ));

     primary->Clear( primary, 0, 0, 0, 0 );
     primary->Flip( primary, NULL, DSFLIP_NONE );

     primary->GetSize( primary, &screen_width, &screen_height );

     step = screen_width / 5;


     /* create the temporary surface */
     sdsc.flags       = DSDESC_CAPS | DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_HEIGHT;
     sdsc.caps        = DSCAPS_PREMULTIPLIED;
     sdsc.pixelformat = DSPF_ARGB;
     sdsc.width       = screen_width;
     sdsc.height      = screen_height;

     DFBCHECK(dfb->CreateSurface( dfb, &sdsc, &tempsurf ));



     /* Load background image. */
     DFBCHECK(dfb->CreateImageProvider( dfb, DATADIR"/wood_andi.jpg", &provider ));

     /* Render to temporary surface. */
     provider->RenderTo( provider, tempsurf, NULL );
     provider->Release( provider );

     /* Blit background onto primary surface (dimmed). */
     primary->SetBlittingFlags( primary, DSBLIT_COLORIZE );
     primary->SetColor( primary, 190, 200, 180, 0 );
     primary->Blit( primary, tempsurf, NULL, 0, 0 );


     tempsurf->Clear( tempsurf, 0, 0, 0, 0 );


     tempsurf->SetDrawingFlags( tempsurf, DSDRAW_SRC_PREMULTIPLY | DSDRAW_BLEND );
     tempsurf->SetPorterDuff( tempsurf, DSPD_SRC );

     fdsc.flags = DFDESC_HEIGHT;
     fdsc.height = screen_width/24;

     DFBCHECK(dfb->CreateFont( dfb, FONT, &fdsc, &font ));
     DFBCHECK(tempsurf->SetFont( tempsurf, font ));

     tempsurf->SetColor( tempsurf, 0xFF, 0xFF, 0xFF, 0xFF );
     tempsurf->DrawString( tempsurf, "Porter/Duff Demo", -1, screen_width/2, 20, DSTF_TOPCENTER );

     font->Release( font );


     fdsc.height = screen_width/32;

     DFBCHECK(dfb->CreateFont( dfb, FONT, &fdsc, &font ));
     DFBCHECK(tempsurf->SetFont( tempsurf, font ));


     for (i=0; i<num_rules; i++) {
          int x = (1 + i % 4) * step;
          int y = (0 + i / 4) * 180;
          DFBAccelerationMask mask;
          char *str;

          str = strdup( rules[i] );

          tempsurf->SetPorterDuff( tempsurf, DSPD_SRC );
          tempsurf->SetColor( tempsurf, 255, 0, 0, 140 );
          tempsurf->FillRectangle( tempsurf, x - 50, y + 100, 80, 70 );

          tempsurf->SetPorterDuff( tempsurf, i+1 );
          tempsurf->SetColor( tempsurf, 0, 0, 255, 200 );
          tempsurf->FillRectangle( tempsurf, x - 30, y + 130, 80, 70 );

          tempsurf->GetAccelerationMask( tempsurf, NULL, &mask );
          if (mask & DFXL_FILLRECTANGLE)
               str[0] = '*';

          tempsurf->SetPorterDuff( tempsurf, DSPD_SRC_OVER );
          tempsurf->SetColor( tempsurf, 6*0x1F, 6*0x10+0x7f, 0xFF, 0xFF );
          tempsurf->DrawString( tempsurf, str, -1, x, y + 210, DSTF_CENTER | DSTF_TOP );

          free( str );
     }

     font->Release( font );


     primary->SetBlittingFlags( primary, DSBLIT_BLEND_ALPHACHANNEL );
     primary->SetPorterDuff( primary, DSPD_SRC_OVER );
     primary->Blit( primary, tempsurf, NULL, 0, 0 );

     primary->Flip( primary, NULL, DSFLIP_NONE );


     while (1) {
          DFBInputEvent ev;

          events->WaitForEvent( events );

          events->GetEvent( events, DFB_EVENT(&ev) );

          if (ev.type == DIET_KEYRELEASE && ev.key_symbol == DIKS_ESCAPE)
               break;
     }

     /* release our interfaces to shutdown DirectFB */
     tempsurf->Release( tempsurf );
     primary->Release( primary );
     events->Release( events );
     dfb->Release( dfb );

     return 0;
}
Пример #24
0
int
main( int argc, char *argv[] )
{
     DFBResult ret;
     bool      quit = false;
     Test      test;

     memset( &test, 0, sizeof(test) );


     ret = Initialize( &test, &argc, &argv );
     if (ret)
          goto error;

     ret = InitGL( &test );
     if (ret)
          goto error;

     shader_init();

     /*
      * Main Loop
      */
     while (!quit) {
          DFBInputEvent evt;

          const static GLfloat v[6] = { -1.0, -1.0,  1.0, 0.0,  -1.0, 1.0 };

          glClearColor(1.0, 1.0, 1.0, 1.0);
          glClear(GL_COLOR_BUFFER_BIT);

          glDisable( GL_CULL_FACE );
          glDisable( GL_DEPTH_TEST );

          glEnableVertexAttribArray( 0 );
          glVertexAttribPointer( 0, 2, GL_FLOAT, GL_TRUE, 0, v );

          glDrawArrays( GL_TRIANGLE_FAN, 0, 3 );

          eglSwapBuffers( display, surface );

          sleep(30);

          /*
           * Process events
           */
          while (test.events->GetEvent( test.events, DFB_EVENT(&evt) ) == DFB_OK) {
               switch (evt.type) {
                    case DIET_KEYPRESS:
                         switch (evt.key_symbol) {
                              case DIKS_CURSOR_LEFT:
                                   //view_rot[1] += 5.0;
                                   break;
                              case DIKS_CURSOR_RIGHT:
                                   //view_rot[1] -= 5.0;
                                   break;
                              case DIKS_CURSOR_UP:
                                   //view_rot[0] += 5.0;
                                   break;
                              case DIKS_CURSOR_DOWN:
                                   //view_rot[0] -= 5.0;
                                   break;
                              case DIKS_ESCAPE:
                                   quit = true;
                                   break;
                              default:
                                   ;
                         }
                         break;
                    case DIET_KEYRELEASE:
                         switch (evt.key_symbol) {
                              default:
                                   ;
                         }
                         break;
                    case DIET_AXISMOTION:
                         if (evt.flags & DIEF_AXISREL) {
                              switch (evt.axis) {
                                   default:
                                        ;
                              }
                         }
                         break;
                    default:
                         ;
               }
          }
     }


error:
     Shutdown( &test );

     return ret;
}
Пример #25
0
int
main( int argc, char *argv[] )
{
     DFBResult ret;
     bool      quit = false;
     Test      test;
     int       n = 1;

     memset( &test, 0, sizeof(test) );

#if 1

     DFBSurfaceDescription  dsc;

     IDirectFB             *dfb;
//     IDirectFBDisplayLayer *layer;

     /*
      * Initialize DirectFB options
      */
     ret = DirectFBInit( &argc, &argv );
     if (ret) {
          D_DERROR( ret, "DirectFBInit() failed!\n" );
          return ret;
     }

     /*
      * Create the super interface
      */
     ret = DirectFBCreate( &dfb );
     if (ret) {
          D_DERROR( ret, "DirectFBCreate() failed!\n" );
          return ret;
     }



     EGLDisplay gEGLDisplay = 0;
     EGLConfig  gEGLConfig;
     EGLContext gEGLContext;


    const char *s;
    //Display* display = sharedDisplay();
    //gEGLDisplay = eglGetDisplay(display);
    gEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    if (gEGLDisplay == EGL_NO_DISPLAY)
        return 0;
    if (!eglInitialize(gEGLDisplay, 0, 0))
        return 0;
    s = eglQueryString(gEGLDisplay, EGL_VERSION);
    printf("EGL_VERSION = %s\n", s);
    s = eglQueryString(gEGLDisplay, EGL_VENDOR);
    printf("EGL_VENDOR = %s\n", s);
    s = eglQueryString(gEGLDisplay, EGL_EXTENSIONS);
    printf("EGL_EXTENSIONS = %s\n", s);
    s = eglQueryString(gEGLDisplay, EGL_CLIENT_APIS);
    printf("EGL_CLIENT_APIS = %s\n", s);


     const int fbConfigAttrbs[] = {
//             EGL_BUFFER_SIZE, EGL_DONT_CARE,
         EGL_RED_SIZE, 1,
         EGL_GREEN_SIZE, 1,
         EGL_BLUE_SIZE, 1,
         EGL_ALPHA_SIZE, 1,
         EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
         EGL_SURFACE_TYPE, /*EGL_PIXMAP_BIT |*/ EGL_WINDOW_BIT,
         EGL_NONE
     };
     EGLint numOfConfig;
     if (!eglChooseConfig(gEGLDisplay, fbConfigAttrbs, &gEGLConfig, 1, &numOfConfig)) {
         printf("egl choose config failed\n");
         return 0;
     }
     if (!numOfConfig) {
         printf("no egl configs found\n");
         return 0;
     }


     const EGLint eglContextAttrbs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
     gEGLContext = eglCreateContext(gEGLDisplay, gEGLConfig, EGL_NO_CONTEXT, eglContextAttrbs);
     if (gEGLContext)
         eglBindAPI(EGL_OPENGL_ES_API);


     IDirectFBSurface *m_dfbsurface;
     EGLSurface        m_surface;

     {
         IDirectFB *dfb;
         if (DirectFBCreate(&dfb)) {
             printf("failed to DirectFBCreate\n");
             return -1;
         }

         DFBSurfaceDescription dsc;
         dsc.flags = (DFBSurfaceDescriptionFlags)(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS);
         dsc.width = 1024;
         dsc.height = 1024;
         dsc.pixelformat = DSPF_ARGB;
         dsc.caps = DSCAPS_DOUBLE;

//         surf->GetSize( surf, &dsc.width, &dsc.height );
//         surf->GetPixelFormat( surf, &dsc.pixelformat );

         if (dfb->CreateSurface(dfb, &dsc, &m_dfbsurface)) {
             printf("failed to DFB::CreateSurface\n");
             return -1;
         }

         EGLint windowsAttr[] = { EGL_RENDER_BUFFER, EGL_BACK_BUFFER, EGL_NONE };

         m_surface = eglCreateWindowSurface(gEGLDisplay, gEGLConfig, (EGLNativeWindowType)m_dfbsurface, windowsAttr);
         if (m_surface == EGL_NO_SURFACE) {
             printf("failed to eglCreateWindowSurface()\n");
             return -1;
         }
     }


     eglMakeCurrent(gEGLDisplay, m_surface, m_surface, gEGLContext);
//        WKViewPaintToCurrentGLContext(_view->wkView());

     glClearColor( 0, 0, 1, 1 );
     glClear( GL_COLOR_BUFFER_BIT );

     eglSwapBuffers(gEGLDisplay, m_surface);

//     m_dfbsurface->Dump( m_dfbsurface, ".", "dfbsurface" );
//sleep(1);
//     m_dfbsurface->Dump( m_dfbsurface, ".", "dfbsurface" );
//sleep(999);
//exit(1);




#endif




     ret = Initialize( &test, &argc, &argv );
     if (ret)
          goto error;

     ret = InitGL( &test );
     if (ret)
          goto error;

     shader_init();

     /*
      * Main Loop
      */
     while (!quit) {
          DFBInputEvent evt;
#if 0
          GLfloat       color[4] = { n * 100 / 100.0f, n * 100 / 100.0f, n * 100 / 100.0f, 1.0f };

          const static GLfloat v[6] = { -1.0, -1.0,  1.0, 0.0,  -1.0, 1.0 };

          glClearColor(n/10.0, n/10.0, n/10.0, 1.0);
          glClear(GL_COLOR_BUFFER_BIT);

          glDisable( GL_CULL_FACE );
          glDisable( GL_DEPTH_TEST );

          glEnableVertexAttribArray( 0 );
          glVertexAttribPointer( 0, 2, GL_FLOAT, GL_TRUE, 0, v );

          glUniform4fv( color_location, 4, color );

          glDrawArrays( GL_TRIANGLE_FAN, 0, 3 );

          eglSwapBuffers( display, surface );
          test.offscreen->Dump( test.offscreen, ".", "offscreen" );
//exit(0);
#endif
          // behaves like eglCopyBuffers( display, surface, test.primary );
          //test.primary->Blit( test.primary, test.offscreen, NULL, 0, 0 );
          test.primary->Blit( test.primary, m_dfbsurface, NULL, 0, 0 );

          test.primary->Flip( test.primary, NULL, DSFLIP_NONE );

          /*
           * Process events
           */
          sleep( 3 );

          while (test.events->GetEvent( test.events, DFB_EVENT(&evt) ) == DFB_OK) {
               switch (evt.type) {
                    case DIET_KEYPRESS:
                         switch (evt.key_symbol) {
                              case DIKS_ESCAPE:
                                   quit = true;
                                   break;
                              default:
                                   ;
                         }
                         break;
                    default:
                         ;
               }
          }

          n++;
     }


error:
     Shutdown( &test );

     return ret;
}
Пример #26
0
int main(int argc, char *argv[])
{
	int quit = 0;
	DFBResult err;
	DFBSurfaceDescription dsc;

	DFBCHECK(DirectFBInit(&argc, &argv));

	// create the super interface
	DFBCHECK(DirectFBCreate(&dfb));

	// create an event buffer for all devices with these caps
	DFBCHECK(dfb->CreateInputEventBuffer(dfb, DICAPS_KEYS | DICAPS_AXES, DFB_FALSE, &events));

	// set our cooperative level to DFSCL_FULLSCREEN for exclusive access to the primary layer
	dfb->SetCooperativeLevel(dfb, DFSCL_FULLSCREEN);

	// get the primary surface, i.e. the surface of the primary layer we have exclusive access to
	dsc.flags = DSDESC_CAPS;
	dsc.caps  = DSCAPS_PRIMARY | DSCAPS_DOUBLE | DSCAPS_OPENGL_HINT;

	DFBCHECK(dfb->CreateSurface(dfb, &dsc, &primary));

	// get the size of the surface and fill it
	DFBCHECK(primary->GetSize(primary, &screen_width, &screen_height));
	DFBCHECK(primary->FillRectangle(primary, 0, 0, screen_width, screen_height));
	primary->Flip(primary, NULL, 0);

	// create the default font and set it
	DFBCHECK(dfb->CreateFont(dfb, NULL, NULL, &font));
	DFBCHECK(primary->SetFont(primary, font));

	// get the GL context
	DFBCHECK(primary->GetGL(primary, &primary_gl));

	DFBCHECK(primary_gl->Lock(primary_gl));

	init(argc, argv);
	reshape(screen_width, screen_height);

	DFBCHECK(primary_gl->Unlock(primary_gl));

	T0 = get_millis();

	while (!quit)
	{
		DFBInputEvent evt;
		unsigned long t;

		DFBCHECK(primary_gl->Lock(primary_gl));

		draw();

		DFBCHECK(primary_gl->Unlock(primary_gl));

		if (fps)
		{
			char buf[64];

			snprintf(buf, 64, "%4.1f FPS\n", fps);

			primary->SetColor(primary, 0xff, 0, 0, 0xff);
			primary->DrawString(primary, buf, -1, screen_width - 5, 5, DSTF_TOPRIGHT);
		}

		primary->Flip(primary, NULL, 0);
		Frames++;


		t = get_millis();
		if (t - T0 >= 2000)
		{
			GLfloat seconds = (t - T0) / 1000.0;

			fps = Frames / seconds;

			T0 = t;
			Frames = 0;
		}


		while (events->GetEvent(events, DFB_EVENT(&evt)) == DFB_OK)
		{
			switch (evt.type)
			{
				case DIET_KEYPRESS:
					switch (evt.key_symbol)
					{
						case DIKS_ESCAPE:
							quit = 1;
							break;
						case DIKS_CURSOR_UP:
 							inc_y = 0.1;
							break;
						case DIKS_CURSOR_DOWN:
							inc_y = -0.1;
							break;
						case DIKS_CURSOR_LEFT:
							inc_x = -0.1;
							break;
						case DIKS_CURSOR_RIGHT:
							inc_x = 0.1;
							break;
						case DIKS_PAGE_UP:
							inc_z = 0.01;
							break;
						case DIKS_PAGE_DOWN:
							inc_z = -0.01;
							break;
						default:
							;
					}
					break;
				case DIET_KEYRELEASE:
					switch (evt.key_symbol)
					{
						case DIKS_CURSOR_UP:
							inc_y = 0;
							break;
						case DIKS_CURSOR_DOWN:
							inc_y = 0;
							break;
						case DIKS_CURSOR_LEFT:
							inc_x = 0;
							break;
						case DIKS_CURSOR_RIGHT:
							inc_x = 0;
							break;
						case DIKS_PAGE_UP:
							inc_z = 0;
							break;
						case DIKS_PAGE_DOWN:
							inc_z = 0;
							break;
						default:
							;
					}
					break;
				case DIET_AXISMOTION:
					if (evt.flags & DIEF_AXISREL)
					{
						switch (evt.axis)
						{
							case DIAI_X:
								view_x += evt.axisrel / 2.0;
								break;
							case DIAI_Y:
								view_y -= evt.axisrel / 2.0;
								break;
							case DIAI_Z:
								view_z += evt.axisrel / 2.0;
								break;
							default:
								;
						}
					}
					break;
				default:
					;
			}
		}

		view_x += inc_x;
		view_y += inc_y;
		view_z += inc_z;
	}

	// release our interfaces to shutdown DirectFB
	primary_gl->Release(primary_gl);
	primary->Release(primary);
	font->Release(font);
	events->Release(events);
	dfb->Release(dfb);

	return 0;
}
Пример #27
0
int main( int argc, char *argv[] )
{
     char *filename = NULL;
     pthread_t demo_loop_thread = (pthread_t) -1;
     DFBResult err;
     int quit = 0;

     if (argc > 1) {
        filename = argv[1];
     } else {
        filename = "./smokey_light.jpg";
     }

     DFBSurfaceDescription dsc;

     srand((long)time(0));

     DFBCHECK(DirectFBInit( &argc, &argv ));

     /* create the super interface */
     DFBCHECK(DirectFBCreate( &dfb ));


     /* get an interface to the primary keyboard and create an
        input buffer for it */
//     DFBCHECK(dfb->GetInputDevice( dfb, DIDID_KEYBOARD, &keyboard ));
  //   DFBCHECK(keyboard->CreateEventBuffer( keyboard, &keybuffer ));

     /* set our cooperative level to DFSCL_FULLSCREEN for exclusive access to
        the primary layer */
     err = dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );
     if (err)
          DirectFBError( "Failed to get exclusive access", err );

     /* get the primary surface, i.e. the surface of the primary layer we have
        exclusive access to */
     dsc.flags = DSDESC_CAPS;
     dsc.caps = DSCAPS_PRIMARY | DSCAPS_DOUBLE | DSCAPS_VIDEOONLY;

     DFBCHECK(dfb->CreateSurface( dfb, &dsc, &primary ));

     /* set our desired video mode */
     DFBCHECK(primary->GetSize( primary, &xres, &yres ));

     /* load font */
     {
          DFBFontDescription desc;

          desc.flags = DFDESC_HEIGHT;
          desc.height = yres/10;

          DFBCHECK(dfb->CreateFont( dfb, "./decker.ttf", &desc, &font ));
          DFBCHECK(primary->SetFont( primary, font ));
     }

     /* load smokey_light */
     DFBCHECK(dfb->CreateImageProvider( dfb, filename,
                                        &provider ));

     DFBCHECK(provider->GetSurfaceDescription (provider, &dsc));
     DFBCHECK(dfb->CreateSurface( dfb, &dsc, &smokey_light ));

     DFBCHECK(provider->RenderTo( provider, smokey_light, NULL ));
     provider->Release( provider );


     /* main loop */
     while (1) {
          DFBInputEvent evt;

          if ((int)demo_loop_thread == -1)
               pthread_create( &demo_loop_thread, NULL, demo_loop, NULL );

	sleep(5);
#if (0)
          keybuffer->WaitForEvent( keybuffer );

          /* process keybuffer */
          while (keybuffer->GetEvent( keybuffer, DFB_EVENT(&evt)) == DFB_OK) {
               if (evt.type == DIET_KEYPRESS) {
                    switch (evt.key_id) {
                         case DIKI_ESCAPE:
                              /* quit main loop */
                              quit = 1;
                              pthread_cancel( demo_loop_thread );
                              pthread_join( demo_loop_thread, NULL );
                              break;

                         default:
                              break;
                    }
               }
          }
#endif
     }

     smokey_light->Release( smokey_light );
     keybuffer->Release( keybuffer );
     keyboard->Release( keyboard );
     primary->Release( primary );
     dfb->Release( dfb );

     return 0;
}
Пример #28
0
static void *input_thread(void *data)
{
	int uinput;
	int i;
	struct input_event u;
	struct uinput_user_dev ud;
	FILE *f;

	DFBResult err;
	IDirectFB *dfb = (IDirectFB *)data;
	fprintf(stderr, "DFB input converter thread starting...\n");

	/* modprobe does not complain if the module is already loaded... */
	system("/sbin/modprobe uinput");
	system("/sbin/modprobe evdev");
	uinput = open("/dev/misc/uinput", O_WRONLY|O_NDELAY);
	if (uinput < 0)
	{
		fprintf(stderr, "DFB input thread: unable to open /dev/misc/uinput (%m)\n");
		return NULL;
	}

	memset(&u, 0, sizeof(u));
	fcntl(uinput, F_SETFD, FD_CLOEXEC);

	/* configure the device */
	memset(&ud, 0, sizeof(ud));
	strncpy(ud.name, "Neutrino TD to Input Device converter", UINPUT_MAX_NAME_SIZE);
	ud.id.version = 0x42;
	ud.id.vendor  = 0x1234;
	ud.id.product = 0x5678;
	ud.id.bustype = BUS_I2C; /* ?? */
	write(uinput, &ud, sizeof(ud));
	ioctl(uinput, UI_SET_EVBIT, EV_KEY);
	ioctl(uinput, UI_SET_EVBIT, EV_REP);
	/* register keys */
	for (i = 0; key_list[i] != -1; i++)
		ioctl(uinput, UI_SET_KEYBIT, key_list[i]);

	if (ioctl(uinput, UI_DEV_CREATE))
	{
		perror("DFB input thread UI_DEV_CREATE");
		close(uinput);
		return NULL;
	}

	/* this is ugly: parse the new input device from /proc/...devices
	 * and symlink it to /dev/input/nevis_ir... */
#define DEVLINE "I: Bus=0018 Vendor=1234 Product=5678 Version=0042"
	f = fopen("/proc/bus/input/devices", "r");
	if (f)
	{
		int found = 0;
		int evdev = -1;
		size_t n = 0;
		char *line = NULL;
		char *p;
		char newdev[20];
		while (getline(&line, &n, f) != -1)
		{
			switch(line[0])
			{
				case 'I':
					if (strncmp(line, DEVLINE, strlen(DEVLINE)) == 0)
						found = 1;
					break;
				case 'H':
					if (! found)
						break;
					p = strstr(line, " event");
					if (! p)
					{
						evdev = -1;
						break;
					}
					evdev = atoi(p + 6);
					sprintf(newdev, "event%d", evdev);
					fprintf(stderr, "DFB input thread: symlink /dev/input/nevis_ir to %s\n", newdev);
					unlink("/dev/input/nevis_ir");
					symlink(newdev, "/dev/input/nevis_ir");
					break;
				default:
					break;
			}
			if (evdev != -1)
				break;
		}
		fclose(f);
		free(line);
	}

	u.type = EV_KEY;
	u.value = 0; /* initialize: first event wil be a key press */

	dfb->EnumInputDevices(dfb, enum_input_device, &inputs);
	DFBCHECK(dfb->CreateInputEventBuffer(dfb, DICAPS_ALL, DFB_FALSE, &events));

	thread_running = 1;
	while (thread_running)
	{
		/* check every 250ms (if a key is pressed on remote, we might
		 * even check earlier, but it does not really hurt... */
		if (_vdec)
			_vdec->VideoParamWatchdog();

		if (events->WaitForEventWithTimeout(events, 0, 250) == DFB_TIMEOUT)
			continue;
		DFBInputEvent e;
		while (events->GetEvent(events, DFB_EVENT(&e)) == DFB_OK)
		{
#if 0
			fprintf(stderr, "type: %x devid: %x flags: %03x "
					"key_id: %4x key_sym: %4x keycode: %d\n",
					e.type, e.device_id, e.flags,
					e.key_id, e.key_symbol, e.key_code);
#endif
			switch (e.key_symbol)
			{
				/* will a lookup table be more efficient? */
				case 0x0030: u.code = KEY_0;		break;
				case 0x0031: u.code = KEY_1;		break;
				case 0x0032: u.code = KEY_2;		break;
				case 0x0033: u.code = KEY_3;		break;
				case 0x0034: u.code = KEY_4;		break;
				case 0x0035: u.code = KEY_5;		break;
				case 0x0036: u.code = KEY_6;		break;
				case 0x0037: u.code = KEY_7;		break;
				case 0x0038: u.code = KEY_8;		break;
				case 0x0039: u.code = KEY_9;		break;
				case 0x000d: u.code = KEY_OK;		break;
				case 0xf504: u.code = KEY_TIME;		break;
				case 0xf01a: u.code = KEY_FAVORITES;	break; /* blue heart */
				case 0xf021: u.code = KEY_ZOOMOUT;	break;
				case 0xf022: u.code = KEY_ZOOMIN;	break;
				case 0xf505: u.code = KEY_NEXT;		break; /* red hand */
				case 0xf00f: u.code = KEY_POWER;	break;
				case 0xf04e: u.code = KEY_MUTE;		break;
				case 0xf012: u.code = KEY_MENU;		break;
				case 0xf01b: u.code = KEY_EPG;		break;
				case 0xf014: u.code = KEY_INFO;		break;
				case 0x001b: u.code = KEY_EXIT;		break;
				case 0xf046: u.code = KEY_PAGEUP;	break;
				case 0xf047: u.code = KEY_PAGEDOWN;	break;
				case 0xf000: u.code = KEY_LEFT;		break;
				case 0xf001: u.code = KEY_RIGHT;	break;
				case 0xf002: u.code = KEY_UP;		break;
				case 0xf003: u.code = KEY_DOWN;		break;
				case 0xf04c: u.code = KEY_VOLUMEUP;	break;
				case 0xf04d: u.code = KEY_VOLUMEDOWN;	break;
				case 0xf042: u.code = KEY_RED;		break;
				case 0xf043: u.code = KEY_GREEN;	break;
				case 0xf044: u.code = KEY_YELLOW;	break;
				case 0xf045: u.code = KEY_BLUE;		break;
				case 0xf027: u.code = KEY_TV;		break;
				case 0xf035: u.code = KEY_VIDEO;	break;
				case 0xf033: u.code = KEY_AUDIO;	break;
				case 0xf034: u.code = KEY_AUX;		break;
				case 0xf032: u.code = KEY_TEXT;		break;
				case 0xf501: u.code = KEY_TTTV;		break;
				case 0xf502: u.code = KEY_TTZOOM;	break;
				case 0xf503: u.code = KEY_REVEAL;	break;
				case 0xf059: u.code = KEY_REWIND;	break;
				case 0xf052: u.code = KEY_STOP;		break;
				case 0xf051: u.code = KEY_PAUSE;	break;
				case 0xf05a: u.code = KEY_FORWARD;	break;
			/*	case 0xf05b: u.code = KEY_PREV;		break; */
				case 0xf057: u.code = KEY_EJECTCD;	break;
				case 0xf056: u.code = KEY_RECORD;	break;
			/*	case 0xf05c: u.code = KEY_NEXT;		break; */
				/* front panel left / right */
				case 0xf506: u.code = KEY_LEFT;		break;
				case 0xf507: u.code = KEY_RIGHT;	break;
				default:
					continue;
			}
			switch (e.type)
			{
				case 1: u.value = 1; break;	/* 1 = key press */
				case 2: u.value = 0; break;	/* 0 = key release */
								/* 2 = key repeat (not used) */
				default:
					continue;
			}
			// fprintf(stderr, "uinput write: value: %d code: %d\n", u.value, u.code);
			write(uinput, &u, sizeof(u));
		}
	}
	/* clean up */
	ioctl(uinput, UI_DEV_DESTROY);
	while (inputs) {
		DeviceInfo *next = inputs->next;
		free(inputs);
		inputs = next;
	}
	events->Release(events);
	return NULL;
}
Пример #29
0
/** entry point */
int main(int argc, char *argv[])
{
    const char *uuid = NULL;
    int c;
    int listHostModes = 0;
    int quit = 0;
    const struct option options[] =
    {
        { "help",          no_argument,       NULL, 'h' },
        { "startvm",       required_argument, NULL, 's' },
        { "fixedres",      required_argument, NULL, 'f' },
        { "listhostmodes", no_argument,       NULL, 'l' },
        { "scale",         no_argument,       NULL, 'c' }
    };

    printf("VirtualBox DirectFB GUI built %s %s\n"
           "(C) 2004-" VBOX_C_YEAR " " VBOX_VENDOR "\n"
           "(C) 2004-2005 secunet Security Networks AG\n", __DATE__, __TIME__);

    for (;;)
    {
        c = getopt_long(argc, argv, "s:", options, NULL);
        if (c == -1)
            break;
        switch (c)
        {
            case 'h':
            {
                showusage();
                exit(0);
                break;
            }
            case 's':
            {
                // UUID as string, parse it
                RTUUID buuid;
                if (!RT_SUCCESS(RTUuidFromStr((PRTUUID)&buuid, optarg)))
                {
                    printf("Error, invalid UUID format given!\n");
                    showusage();
                    exit(-1);
                }
                uuid = optarg;
                break;
            }
            case 'f':
            {
                if (sscanf(optarg, "%ux%ux%u", &fixedVideoMode.width, &fixedVideoMode.height,
                           &fixedVideoMode.bpp) != 3)
                {
                    printf("Error, invalid resolution argument!\n");
                    showusage();
                    exit(-1);
                }
                useFixedVideoMode = 1;
                break;
            }
            case 'l':
            {
                listHostModes = 1;
                break;
            }
            case 'c':
            {
                scaleGuest = 1;
                break;
            }
            default:
                break;
        }
    }

    // check if we got a UUID
    if (!uuid)
    {
        printf("Error, no UUID given!\n");
        showusage();
        exit(-1);
    }


    /**
     * XPCOM setup
     */

    nsresult rc;
    /*
     * Note that we scope all nsCOMPtr variables in order to have all XPCOM
     * objects automatically released before we call NS_ShutdownXPCOM at the
     * end. This is an XPCOM requirement.
     */
    {
        nsCOMPtr<nsIServiceManager> serviceManager;
        rc = NS_InitXPCOM2(getter_AddRefs(serviceManager), nsnull, nsnull);
        if (NS_FAILED(rc))
        {
            printf("Error: XPCOM could not be initialized! rc=0x%x\n", rc);
            exit(-1);
        }

        // register our component
        nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(serviceManager);
        if (!registrar)
        {
            printf("Error: could not query nsIComponentRegistrar interface!\n");
            exit(-1);
        }
        registrar->AutoRegister(nsnull);

        /*
         * Make sure the main event queue is created. This event queue is
         * responsible for dispatching incoming XPCOM IPC messages. The main
         * thread should run this event queue's loop during lengthy non-XPCOM
         * operations to ensure messages from the VirtualBox server and other
         * XPCOM IPC clients are processed. This use case doesn't perform such
         * operations so it doesn't run the event loop.
         */
        nsCOMPtr<nsIEventQueue> eventQ;
        rc = NS_GetMainEventQ(getter_AddRefs (eventQ));
        if (NS_FAILED(rc))
        {
            printf("Error: could not get main event queue! rc=%08X\n", rc);
            return -1;
        }

        /*
         * Now XPCOM is ready and we can start to do real work.
         * IVirtualBox is the root interface of VirtualBox and will be
         * retrieved from the XPCOM component manager. We use the
         * XPCOM provided smart pointer nsCOMPtr for all objects because
         * that's very convenient and removes the need deal with reference
         * counting and freeing.
         */
        nsCOMPtr<nsIComponentManager> manager;
        rc = NS_GetComponentManager (getter_AddRefs (manager));
        if (NS_FAILED(rc))
        {
            printf("Error: could not get component manager! rc=%08X\n", rc);
            exit(-1);
        }

        nsCOMPtr<IVirtualBox> virtualBox;
        rc = manager->CreateInstanceByContractID(NS_VIRTUALBOX_CONTRACTID,
                                                 nsnull,
                                                 NS_GET_IID(IVirtualBox),
                                                 getter_AddRefs(virtualBox));
        if (NS_FAILED(rc))
        {
            printf("Error, could not instantiate object! rc=0x%x\n", rc);
            exit(-1);
        }

        nsCOMPtr<ISession> session;
        rc = manager->CreateInstance(CLSID_Session,
                                     nsnull,
                                     NS_GET_IID(ISession),
                                     getter_AddRefs(session));
        if (NS_FAILED(rc))
        {
            printf("Error: could not instantiate Session object! rc = %08X\n", rc);
            exit(-1);
        }

        // open session for this VM
        rc = virtualBox->OpenSession(session, NS_ConvertUTF8toUTF16(uuid).get());
        if (NS_FAILED(rc))
        {
            printf("Error: given machine not found!\n");
            exit(-1);
        }
        nsCOMPtr<IMachine> machine;
        session->GetMachine(getter_AddRefs(machine));
        if (!machine)
        {
            printf("Error: given machine not found!\n");
            exit(-1);
        }
        nsCOMPtr<IConsole> console;
        session->GetConsole(getter_AddRefs(console));
        if (!console)
        {
            printf("Error: cannot get console!\n");
            exit(-1);
        }

        nsCOMPtr<IDisplay> display;
        console->GetDisplay(getter_AddRefs(display));
        if (!display)
        {
            printf("Error: could not get display object!\n");
            exit(-1);
        }

        nsCOMPtr<IKeyboard> keyboard;
        nsCOMPtr<IMouse> mouse;
        VBoxDirectFB *frameBuffer = NULL;

        /**
         * Init DirectFB
         */
        IDirectFB *dfb = NULL;
        IDirectFBSurface *surface = NULL;
        IDirectFBInputDevice *dfbKeyboard = NULL;
        IDirectFBInputDevice *dfbMouse = NULL;
        IDirectFBEventBuffer *dfbEventBuffer = NULL;
        DFBSurfaceDescription dsc;
        int screen_width, screen_height;

        DFBCHECK(DirectFBInit(&argc, &argv));
        DFBCHECK(DirectFBCreate(&dfb));
        DFBCHECK(dfb->SetCooperativeLevel(dfb, DFSCL_FULLSCREEN));
        // populate our structure of supported video modes
        DFBCHECK(dfb->EnumVideoModes(dfb, enumVideoModesHandler, NULL));

        if (listHostModes)
        {
            printf("*****************************************************\n");
            printf("Number of available host video modes: %u\n", numVideoModes);
            for (uint32_t i = 0; i < numVideoModes; i++)
            {
                printf("Mode %u: xres = %u, yres = %u, bpp = %u\n", i,
                       videoModes[i].width, videoModes[i].height, videoModes[i].bpp);
            }
            printf("Note: display modes with bpp < have been filtered out\n");
            printf("*****************************************************\n");
            goto Leave;
        }

        if (useFixedVideoMode)
        {
            int32_t bestVideoMode = getBestVideoMode(fixedVideoMode.width,
                                                     fixedVideoMode.height,
                                                     fixedVideoMode.bpp);
            // validate the fixed mode
            if ((bestVideoMode == -1) ||
                ((fixedVideoMode.width  != videoModes[bestVideoMode].width) ||
                (fixedVideoMode.height != videoModes[bestVideoMode].height) ||
                (fixedVideoMode.bpp    != videoModes[bestVideoMode].bpp)))
            {
                printf("Error: the specified fixed video mode is not available!\n");
                exit(-1);
            }
        } else
        {
            initialVideoMode = getBestVideoMode(640, 480, 16);
            if (initialVideoMode == -1)
            {
                printf("Error: initial video mode 640x480x16 is not available!\n");
                exit(-1);
            }
        }

        dsc.flags = DSDESC_CAPS;
        dsc.caps = DSCAPS_PRIMARY;
        DFBCHECK(dfb->CreateSurface(dfb, &dsc, &surface));
        DFBCHECK(surface->Clear(surface, 0, 0, 0, 0));
        DFBCHECK(surface->GetSize(surface, &screen_width, &screen_height));
        DFBCHECK(dfb->GetInputDevice(dfb, DIDID_KEYBOARD, &dfbKeyboard));
        DFBCHECK(dfbKeyboard->CreateEventBuffer(dfbKeyboard, &dfbEventBuffer));
        DFBCHECK(dfb->GetInputDevice(dfb, DIDID_MOUSE, &dfbMouse));
        DFBCHECK(dfbMouse->AttachEventBuffer(dfbMouse, dfbEventBuffer));


        if (useFixedVideoMode)
        {
            printf("Information: setting video mode to %ux%ux%u\n", fixedVideoMode.width,
                   fixedVideoMode.height, fixedVideoMode.bpp);
            DFBCHECK(dfb->SetVideoMode(dfb, fixedVideoMode.width,
                                       fixedVideoMode.height, fixedVideoMode.bpp));
        } else
        {
            printf("Information: starting with default video mode %ux%ux%u\n",
                   videoModes[initialVideoMode].width, videoModes[initialVideoMode].height,
                   videoModes[initialVideoMode].bpp);
            DFBCHECK(dfb->SetVideoMode(dfb, videoModes[initialVideoMode].width,
                                            videoModes[initialVideoMode].height,
                                            videoModes[initialVideoMode].bpp));
        }

        // register our framebuffer
        frameBuffer = new VBoxDirectFB(dfb, surface);
        display->SetFramebuffer(0, frameBuffer);

        /**
         * Start the VM execution thread
         */
        console->PowerUp(NULL);

        console->GetKeyboard(getter_AddRefs(keyboard));
        console->GetMouse(getter_AddRefs(mouse));

        /**
         * Main event loop
         */
        #define MAX_KEYEVENTS 10
        PRInt32 keyEvents[MAX_KEYEVENTS];
        int numKeyEvents;

        while (!quit)
        {
            DFBInputEvent event;

            numKeyEvents = 0;
            DFBCHECK(dfbEventBuffer->WaitForEvent(dfbEventBuffer));
            while (dfbEventBuffer->GetEvent(dfbEventBuffer, DFB_EVENT(&event)) == DFB_OK)
            {
                int mouseXDelta = 0;
                int mouseYDelta = 0;
                int mouseZDelta = 0;
                switch (event.type)
                {
                    #define QUEUEEXT() keyEvents[numKeyEvents++] = 0xe0
                    #define QUEUEKEY(scan) keyEvents[numKeyEvents++] = scan | (event.type == DIET_KEYRELEASE ? 0x80 : 0x00)
                    #define QUEUEKEYRAW(scan) keyEvents[numKeyEvents++] = scan
                    case DIET_KEYPRESS:
                    case DIET_KEYRELEASE:
                    {
                        // @@@AH development hack to get out of it!
                        if ((event.key_id == DIKI_ESCAPE) && (event.modifiers & (DIMM_CONTROL | DIMM_ALT)))
                            quit = 1;

                        if (numKeyEvents < MAX_KEYEVENTS)
                        {
                            //printf("%s: key_code: 0x%x\n", event.type == DIET_KEYPRESS ? "DIET_KEYPRESS" : "DIET_KEYRELEASE", event.key_code);
                            switch ((uint32_t)event.key_id)
                            {
                                case DIKI_CONTROL_R:
                                    QUEUEEXT();
                                    QUEUEKEY(0x1d);
                                    break;
                                case DIKI_INSERT:
                                    QUEUEEXT();
                                    QUEUEKEY(0x52);
                                    break;
                                case DIKI_DELETE:
                                    QUEUEEXT();
                                    QUEUEKEY(0x53);
                                    break;
                                case DIKI_HOME:
                                    QUEUEEXT();
                                    QUEUEKEY(0x47);
                                    break;
                                case DIKI_END:
                                    QUEUEEXT();
                                    QUEUEKEY(0x4f);
                                    break;
                                case DIKI_PAGE_UP:
                                    QUEUEEXT();
                                    QUEUEKEY(0x49);
                                    break;
                                case DIKI_PAGE_DOWN:
                                    QUEUEEXT();
                                    QUEUEKEY(0x51);
                                    break;
                                case DIKI_LEFT:
                                    QUEUEEXT();
                                    QUEUEKEY(0x4b);
                                    break;
                                case DIKI_RIGHT:
                                    QUEUEEXT();
                                    QUEUEKEY(0x4d);
                                    break;
                                case DIKI_UP:
                                    QUEUEEXT();
                                    QUEUEKEY(0x48);
                                    break;
                                case DIKI_DOWN:
                                    QUEUEEXT();
                                    QUEUEKEY(0x50);
                                    break;
                                case DIKI_KP_DIV:
                                    QUEUEEXT();
                                    QUEUEKEY(0x35);
                                    break;
                                case DIKI_KP_ENTER:
                                    QUEUEEXT();
                                    QUEUEKEY(0x1c);
                                    break;
                                case DIKI_PRINT:
                                    // the break code is inverted!
                                    if (event.type == DIET_KEYPRESS)
                                    {
                                        QUEUEEXT();
                                        QUEUEKEY(0x2a);
                                        QUEUEEXT();
                                        QUEUEKEY(0x37);
                                    } else
                                    {
                                        QUEUEEXT();
                                        QUEUEKEY(0x37);
                                        QUEUEEXT();
                                        QUEUEKEY(0x2a);
                                    }
                                    break;
                                case DIKI_PAUSE:
                                    // This is a super weird key. No break code and a 6 byte
                                    // combination.
                                    if (event.type == DIET_KEYPRESS)
                                    {
                                        QUEUEKEY(0xe1);
                                        QUEUEKEY(0x1d);
                                        QUEUEKEY(0x45);
                                        QUEUEKEY(0xe1);
                                        QUEUEKEY(0x9d);
                                        QUEUEKEY(0xc5);
                                    }
                                    break;
                                case DIKI_META_L:
                                    // the left Windows logo is a bit different
                                    if (event.type == DIET_KEYPRESS)
                                    {
                                        QUEUEEXT();
                                        QUEUEKEYRAW(0x1f);
                                    } else
                                    {
                                        QUEUEEXT();
                                        QUEUEKEYRAW(0xf0);
                                        QUEUEKEYRAW(0x1f);
                                    }
                                    break;
                                case DIKI_META_R:
                                    // the right Windows logo is a bit different
                                    if (event.type == DIET_KEYPRESS)
                                    {
                                        QUEUEEXT();
                                        QUEUEKEYRAW(0x27);
                                    } else
                                    {
                                        QUEUEEXT();
                                        QUEUEKEYRAW(0xf0);
                                        QUEUEKEYRAW(0x27);
                                    }
                                    break;
                                case DIKI_SUPER_R:
                                    // the popup menu is a bit different
                                    if (event.type == DIET_KEYPRESS)
                                    {
                                        QUEUEEXT();
                                        QUEUEKEYRAW(0x2f);
                                    } else
                                    {
                                        QUEUEEXT();
                                        QUEUEKEYRAW(0xf0);
                                        QUEUEKEYRAW(0x2f);
                                    }
                                    break;

                                default:
                                    // check if we got a hardware scancode
                                    if (event.key_code != -1)
                                    {
                                        // take the scancode from DirectFB as is
                                        QUEUEKEY(event.key_code);
                                    } else
                                    {
                                        // XXX need extra handling!
                                    }
                            }
                        }
                        break;
                    }
                    #undef QUEUEEXT
                    #undef QUEUEKEY
                    #undef QUEUEKEYRAW

                    case DIET_AXISMOTION:
                    {
                        switch (event.axis)
                        {
                            case DIAI_X:
                                mouseXDelta += event.axisrel;
                                break;
                            case DIAI_Y:
                                mouseYDelta += event.axisrel;
                                break;
                            case DIAI_Z:
                                mouseZDelta += event.axisrel;
                                break;
                            default:
                                break;
                        }
                        // fall through
                    }
                    case DIET_BUTTONPRESS:
                        // fall through;
                    case DIET_BUTTONRELEASE:
                    {
                        int buttonState = 0;
                        if (event.buttons & DIBM_LEFT)
                            buttonState |= MouseButtonState::LeftButton;
                        if (event.buttons & DIBM_RIGHT)
                            buttonState |= MouseButtonState::RightButton;
                        if (event.buttons & DIBM_MIDDLE)
                            buttonState |= MouseButtonState::MiddleButton;
                        mouse->PutMouseEvent(mouseXDelta, mouseYDelta, mouseZDelta,
                                             buttonState);
                        break;
                    }
                    default:
                        break;
                }
            }
            // did we get any keyboard events?
            if (numKeyEvents > 0)
            {
                uint32_t codesStored;
                if (numKeyEvents > 1)
                {
                    keyboard->PutScancodes(numKeyEvents, keyEvents,
                                           &codesStored);
                } else
                {
                    keyboard->PutScancode(keyEvents[0]);
                }
            }
        }
        {
            nsCOMPtr<IProgress> progress;
            console->PowerDown(getter_AddRefs(progress));
            progress->WaitForCompletion(-1);
        }
    }

Leave:
    /*
     * Perform the standard XPCOM shutdown procedure.
     */
    NS_ShutdownXPCOM(nsnull);

    return 0;
}
Пример #30
0
int
main( int argc, char *argv[] )
{
     int quit = 0;
     DFBResult err;
     DFBGraphicsDeviceDescription gdesc;
     
     char init_str[64];
     const char* dev = "/dev/ttyS0";
     char buf[4096]={0};
     
     char *home = getenv( "HOME" );
     int   file;

     int leftx, topy, rightx, bottomy, ofs;
     int mouse_x, mouse_y, tx1, ty1;
     int touch, count, color; 
	struct timespec rqtp,rmtp;
     
     if(home)
         sprintf(init_str,"%s/.directfbrc",home);
	 else
	     strcpy(init_str,"root/.directfbrc");
	 		   
	 file = open ( init_str, O_RDONLY );
	 if ( file != -1 ){
	 	 char *pos, *pos2;
           read(file, buf, sizeof(buf));
		 close(file);
	 
		 pos = strstr( buf, "penmount-device" );
		 if(pos){
	 		 pos = strchr(pos,'=');
		 	 if(pos){
		 	 	*pos++ = '\0';
	 		 	if( (pos2=strchr(pos,':'))||(pos2=strchr(pos,'\n')) )
	 	 			*pos2 = '\0';
		 	 	dev = pos;	
		 	 }
		 } 
	 }
	 printf( "penmount device '%s'\n", dev );
	 
	 sprintf( init_str,"--dfb:penmount-device=%s:raw", dev);
	 argv[argc++] = init_str;
	 	
     if (DirectFBInit( &argc, &argv ) != DFB_OK)
          return 1;

     if (DirectFBCreate( &dfb ) != DFB_OK)
          return 1;

     dfb->GetDeviceDescription( dfb, &gdesc );

	 err = dfb->SetCooperativeLevel( dfb, DFSCL_FULLSCREEN );
     if (err != DFB_OK)
          DirectFBError( "Failed requesting exclusive access", err );

     err = dfb->CreateInputEventBuffer( dfb, DICAPS_ALL, DFB_FALSE, &buffer );
     if (err != DFB_OK) {
          DirectFBError( "CreateInputEventBuffer failed", err );
          dfb->Release( dfb );
          return 1;
     }

     {
          DFBSurfaceDescription dsc;

          dsc.flags = DSDESC_CAPS;
          dsc.caps = (gdesc.drawing_flags & DSDRAW_BLEND) ?
                         DSCAPS_PRIMARY | DSCAPS_FLIPPING :
                         DSCAPS_PRIMARY | DSCAPS_FLIPPING | DSCAPS_SYSTEMONLY;

          err = dfb->CreateSurface( dfb, &dsc, &primary );
          if (err != DFB_OK) {
               DirectFBError( "Failed creating primary surface", err );
               buffer->Release( buffer );
               dfb->Release( dfb );
               return 1;
          }

          primary->GetSize( primary, &sx, &sy );
     }

     primary->Clear( primary, 0x0, 0x0, 0x0, 0xFF );
     
     leftx = sx/10;
     topy = sy/10;
     rightx = sx*9/10;
     bottomy = sy*9/10;
     ofs = 10;

     primary->SetColor( primary,0xFF,0,0,0xFF );
   	 primary->DrawLine( primary,rightx-ofs,bottomy,rightx+ofs,bottomy );
     primary->DrawLine( primary,rightx,bottomy-ofs,rightx,bottomy+ofs );
	      
     err = primary->Flip( primary, NULL, 0 );
     if (err != DFB_OK) {
          DirectFBError( "Failed flipping the primary surface", err );
          primary->Release( primary );
          buffer->Release( buffer );
          dfb->Release( dfb );
          return 1;
     }

	mouse_x=0,mouse_y=0,tx1=0,ty1=0;
	touch=0,count=0,color=0;
      
     while (!quit) {
          DFBInputEvent evt;
          rqtp.tv_nsec = 10000;
          rqtp.tv_sec = 0;
          nanosleep( &rqtp,&rmtp );
          if (count++ >= 30){
          	count = 0;
          	color = !color;
          	if (color)
          		primary->SetColor( primary,0x00,0xFF,0,0xFF );
          	else
          		primary->SetColor( primary,0xFF,0x00,0,0xFF );
          	
          	switch(touch){
          		case 0:
          			primary->DrawLine( primary,leftx-ofs,topy,leftx+ofs,topy );
     				primary->DrawLine( primary,leftx,topy-ofs,leftx,topy+ofs );
     				break;
     			case 1:
				    primary->DrawLine( primary,rightx-ofs,bottomy,rightx+ofs,bottomy );
				    primary->DrawLine( primary,rightx,bottomy-ofs,rightx,bottomy+ofs );  			
     				break;
          	}
          	primary->Flip( primary, NULL, 0 );
          }		 

          while (buffer->GetEvent( buffer, DFB_EVENT(&evt) ) == DFB_OK) {
          	if ( evt.type == DIET_AXISMOTION){
          		if (evt.flags & DIEF_AXISABS) {
	               	switch (evt.axis) {
	               	case DIAI_X:
	                    mouse_x = evt.axisabs;
	               		break;
	               	case DIAI_Y:
	                    mouse_y = evt.axisabs;
	                    break;
	               default:
	                    break;
	               }
          		}
          	}
          	if ( evt.type == DIET_BUTTONPRESS ){
          		switch(++touch){
          			case 1: //save first touchscreen position
          				tx1=mouse_x;
          				ty1=mouse_y;
          				break;
          			case 2://build new calibration values and quit
          			{	
          				float dx = ((float)mouse_x-tx1)/(rightx-leftx);
          				float dy = ((float)mouse_y-ty1)/(bottomy-topy);
          				printf( "Insert followed values into source code of penmount's driver\n'inputdrivers/penmount/penmount.c:96,99' and rebuild:\n" );
          				printf( "min_x=%d min_y=%d\n",(int)(tx1-leftx*dx+.5),(int)(ty1-topy*dy+.5));
           				printf( "max_x=%d max_y=%d\n",(int)(mouse_x+leftx*dx+.5),(int)(mouse_y+topy*dy+.5));
 	                 	quit = 1;
 	                 	break;
          			}
           		}
           	}
            if (evt.type == DIET_KEYPRESS  &&  evt.key_id == DIKI_ESCAPE)
                 quit = 1;
          }
     }
     primary->Release( primary );
     buffer->Release( buffer );
     dfb->Release( dfb );

     return 0;
}