void DisplayChannel::create_canvas(int surface_id, const std::vector<int>& canvas_types, int width, int height, uint32_t format) { #ifdef USE_OGL bool recreate = true; #endif unsigned int i; #ifdef USE_OGL if (screen()->need_recreate_context_gl()) { recreate = false; } #endif screen()->set_update_interrupt_trigger(NULL); for (i = 0; i < canvas_types.size(); i++) { if (canvas_types[i] == CANVAS_OPTION_SW && create_sw_canvas(surface_id, width, height, format)) { break; } #ifdef USE_OGL if (canvas_types[i] == CANVAS_OPTION_OGL_FBO && create_ogl_canvas(surface_id, width, height, format, recreate, RENDER_TYPE_FBO)) { break; } if (canvas_types[i] == CANVAS_OPTION_OGL_PBUFF && create_ogl_canvas(surface_id, width, height, format, recreate, RENDER_TYPE_PBUFF)) { break; } #endif #ifdef WIN32 if (canvas_types[i] == CANVAS_OPTION_GDI && create_gdi_canvas(surface_id, width, height, format)) { break; } #endif } if (i == canvas_types.size()) { THROW("create canvas failed"); } }
/* ======================================= WinMain 程序入口 ======================================= */ int WINAPI WinMain ( __CR_IN__ HINSTANCE curt_app, __CR_IN__ HINSTANCE prev_app, __CR_IN__ LPSTR cmd_line, __CR_IN__ int cmd_show ) { CR_NOUSE(prev_app); CR_NOUSE(cmd_line); CR_NOUSE(cmd_show); /* 只允许一个例程 */ if (misc_is_running(EXE_XNAME)) return (QST_ERROR); /* 建立 CrHack 系统 */ if (!set_app_type(CR_APP_GUI)) return (QST_ERROR); mem_zero(&s_wrk_ctx, sizeof(s_wrk_ctx)); sint_t x1, y1; uint_t ww, hh; /* 生成一个可变大小的窗口 */ mtlock_init(&s_wrk_ctx.lock); qst_load_cfg(&s_wrk_ctx.cfgs); misc_desk_init(WIN_ICONF, &x1, &y1, &ww, &hh, QV2D_DEF_WIDTH, QV2D_DEF_HEIGHT); if (ww < QV2D_DEF_WIDTH) ww = QV2D_DEF_WIDTH; if (hh < QV2D_DEF_HEIGHT) hh = QV2D_DEF_HEIGHT; s_wrk_ctx.hwnd = (HWND)window_open(curt_app, (void_t*)WindowProc, x1, y1, ww, hh, WIN_TITLE, WIN_CLASS, (ansi_t*)101, CR_WSTYLE_NORMAL); if (s_wrk_ctx.hwnd == NULL) return (QST_ERROR); SetWindowLongPtr(s_wrk_ctx.hwnd, GWL_STYLE, GetWindowLongPtr(s_wrk_ctx.hwnd, GWL_STYLE) & (~WS_MAXIMIZEBOX)); iGFX2* draw; sIMAGE* imgs; /* 创建 GDI 绘制对象 (只支持32位色屏幕) */ draw = (iGFX2*)create_gdi_canvas(s_wrk_ctx.hwnd, 0, 0, FALSE); if (draw == NULL) { window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS); return (QST_ERROR); } imgs = CR_VCALL(draw)->lock(draw); if (imgs == NULL || imgs->fmt != CR_ARGB8888) { window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS); return (QST_ERROR); } CR_VCALL(draw)->unlock(draw); CR_VCALL(draw)->clear(draw, s_wrk_ctx.cfgs.bkcolor, 0); s_wrk_ctx.draw = draw; /* 初始化网络 */ if (!socket_init()) { window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS); return (QST_ERROR); } s_wrk_ctx.netw = netw_cli_open(EXE_XNAME); if (s_wrk_ctx.netw == NULL) { window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS); return (QST_ERROR); } /* 读取需要超时, 不然线程无法退出 */ socket_set_timeout(s_wrk_ctx.netw, -1, QST_TCP_TOUT); thrd_t thrd; /* 生成工作线程 */ s_wrk_ctx.send = TRUE; s_wrk_ctx.quit = FALSE; s_wrk_ctx.cur_busy = LoadCursor(NULL, IDC_WAIT); s_wrk_ctx.cur_free = LoadCursor(NULL, IDC_ARROW); s_wrk_ctx.res_loader = res_loader_get(); if (s_wrk_ctx.res_loader->init != NULL) s_wrk_ctx.res_loader->init(s_wrk_ctx.netw, NULL); qst_load_filter(&s_wrk_ctx); thrd = thread_new(0, qst_v2d_main, &s_wrk_ctx, FALSE); if (thrd == NULL) { window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS); return (QST_ERROR); } /* 消息循环 */ while (!s_wrk_ctx.quit) { MSG msg; if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { s_wrk_ctx.quit = TRUE; break; } TranslateMessage(&msg); DispatchMessage(&msg); } else { qst_do_keyboard(&s_wrk_ctx); } } thread_wait(thrd); thread_del(thrd); window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS); netw_cli_close(s_wrk_ctx.netw); return (QST_OKAY); }