Subversion Repositories Kolibri OS

Rev

Rev 3773 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2010 VMware, Inc.
  4.  * All Rights Reserved.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the
  8.  * "Software"), to deal in the Software without restriction, including
  9.  * without limitation the rights to use, copy, modify, merge, publish,
  10.  * distribute, sub license, and/or sell copies of the Software, and to
  11.  * permit persons to whom the Software is furnished to do so, subject to
  12.  * the following conditions:
  13.  *
  14.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16.  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  17.  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  18.  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  19.  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  20.  * USE OR OTHER DEALINGS IN THE SOFTWARE.
  21.  *
  22.  * The above copyright notice and this permission notice (including the
  23.  * next paragraph) shall be included in all copies or substantial portions
  24.  * of the Software.
  25.  *
  26.  *
  27.  **************************************************************************/
  28.  
  29. #include "sw/kos_sw_winsys.h"
  30. #include "pipe/p_screen.h"
  31. #include "state_tracker/graw.h"
  32. #include "target-helpers/inline_debug_helper.h"
  33. #include "target-helpers/inline_sw_helper.h"
  34. #include <kos32sys.h>
  35. //#include <windows.h>
  36.  
  37. /*
  38. static LRESULT CALLBACK
  39. window_proc(HWND hWnd,
  40.             UINT uMsg,
  41.             WPARAM wParam,
  42.             LPARAM lParam)
  43. {
  44.    switch (uMsg) {
  45.    case WM_DESTROY:
  46.       PostQuitMessage(0);
  47.       break;
  48.  
  49.    default:
  50.       return DefWindowProc(hWnd, uMsg, wParam, lParam);
  51.    }
  52.  
  53.    return 0;
  54. }
  55. */
  56.  
  57. static struct {
  58.    void (* draw)(void);
  59. } graw;
  60.  
  61. struct pipe_screen *
  62. graw_create_window_and_screen(int x,
  63.                               int y,
  64.                               unsigned width,
  65.                               unsigned height,
  66.                               enum pipe_format format,
  67.                               void **handle)
  68. {
  69.    struct sw_winsys *winsys = NULL;
  70.    struct pipe_screen *screen = NULL;
  71.  
  72.    if (format != PIPE_FORMAT_B8G8R8X8_UNORM)
  73.       goto fail;
  74.  
  75.    winsys = kos_create_sw_winsys();
  76.    if (winsys == NULL)
  77.       goto fail;
  78.  
  79.    screen = sw_screen_create(winsys);
  80.    
  81.    if (screen == NULL)
  82.       goto fail;
  83.  
  84.     BeginDraw();
  85.     DrawWindow(x, y,width-1,height-1,
  86.                NULL,0,0x41);
  87.     EndDraw();
  88.    
  89.     *handle = (void *)winsys;
  90.     return (screen);
  91.  
  92. fail:
  93.  
  94.    if (screen)
  95.       screen->destroy(screen);
  96.  
  97.    return NULL;
  98. }
  99.  
  100. void
  101. graw_set_display_func(void (* draw)(void))
  102. {
  103.    graw.draw = draw;
  104. }
  105.  
  106. void
  107. graw_main_loop(void)
  108. {
  109.     int ev;
  110.     oskey_t   key;
  111.  
  112.     BeginDraw();
  113.     DrawWindow(0,0,0,0, NULL, 0x000000,0x41);
  114.     EndDraw();
  115.            
  116.     if (graw.draw)
  117.     {
  118.        graw.draw();
  119.     }
  120.  
  121.     while(1)
  122.     {
  123.         ev = wait_for_event(2);
  124.  
  125.         switch(ev)
  126.         {
  127.             case 1:
  128.                 BeginDraw();
  129.                 DrawWindow(0,0,0,0, NULL, 0x000000,0x41);
  130.                 EndDraw();
  131.            
  132.                 if (graw.draw)
  133.                 {
  134.                     graw.draw();
  135.                 }
  136.                 continue;
  137.  
  138.             case 2:
  139.                 key = get_key();
  140. //                printf("key %x\n", key.code);
  141.                 if( key.code == 0x1b)
  142.                     return;
  143.                 continue;
  144.         };
  145.         if (graw.draw)
  146.         {
  147.             graw.draw();
  148.         }
  149.        
  150.     };
  151. }
  152.