Path: blob/21.2-virgl/src/gallium/targets/graw-gdi/graw_gdi.c
4565 views
/**************************************************************************1*2* Copyright 2010 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL16* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,17* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR18* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE19* USE OR OTHER DEALINGS IN THE SOFTWARE.20*21* The above copyright notice and this permission notice (including the22* next paragraph) shall be included in all copies or substantial portions23* of the Software.24*25*26**************************************************************************/2728#include "gdi/gdi_sw_winsys.h"29#include "pipe/p_screen.h"30#include "frontend/graw.h"31#include "target-helpers/inline_debug_helper.h"32#include "target-helpers/inline_sw_helper.h"33#include <windows.h>343536static LRESULT CALLBACK37window_proc(HWND hWnd,38UINT uMsg,39WPARAM wParam,40LPARAM lParam)41{42switch (uMsg) {43case WM_DESTROY:44PostQuitMessage(0);45break;4647default:48return DefWindowProc(hWnd, uMsg, wParam, lParam);49}5051return 0;52}5354static struct {55void (* draw)(void);56} graw;5758struct pipe_screen *59graw_create_window_and_screen(int x,60int y,61unsigned width,62unsigned height,63enum pipe_format format,64void **handle)65{66struct sw_winsys *winsys = NULL;67struct pipe_screen *screen = NULL;68WNDCLASSEX wc;69UINT style = WS_VISIBLE | WS_TILEDWINDOW;70RECT rect;71HWND hWnd = NULL;72HDC hDC = NULL;7374if (format != PIPE_FORMAT_R8G8B8A8_UNORM)75goto fail;7677winsys = gdi_create_sw_winsys();78if (winsys == NULL)79goto fail;8081screen = sw_screen_create(winsys);82if (screen == NULL)83goto fail;8485memset(&wc, 0, sizeof wc);86wc.cbSize = sizeof wc;87wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;88wc.lpfnWndProc = window_proc;89wc.lpszClassName = TEXT("graw-gdi");90wc.hInstance = GetModuleHandle(NULL);91wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);92wc.hCursor = LoadCursor(NULL, IDC_ARROW);93wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);94RegisterClassEx(&wc);9596SetRect(&rect, 0, 0, width, height);97AdjustWindowRectEx(&rect, style, FALSE, 0);9899hWnd = CreateWindowEx(0,100wc.lpszClassName,101wc.lpszClassName,102style,103x,104y,105rect.right - rect.left,106rect.bottom - rect.top,107NULL,108NULL,109wc.hInstance,1100);111if (hWnd == NULL)112goto fail;113114hDC = GetDC(hWnd);115if (hDC == NULL)116goto fail;117118*handle = (void *)hDC;119120return debug_screen_wrap(screen);121122fail:123if (hWnd)124DestroyWindow(hWnd);125126if (screen)127screen->destroy(screen);128129return NULL;130}131132void133graw_set_display_func(void (* draw)(void))134{135graw.draw = draw;136}137138void139graw_main_loop(void)140{141for (;;) {142MSG msg;143144while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {145if (msg.message == WM_QUIT) {146return;147}148TranslateMessage(&msg);149DispatchMessage(&msg);150}151152if (graw.draw) {153graw.draw();154}155156Sleep(0);157}158}159160161