diff --git a/headers/os/game/WindowScreen.h b/headers/os/game/WindowScreen.h index 29c1d7c529..42c6d00225 100644 --- a/headers/os/game/WindowScreen.h +++ b/headers/os/game/WindowScreen.h @@ -56,35 +56,36 @@ enum { class BWindowScreen : public BWindow { public: - BWindowScreen(const char *title, - uint32 space, - status_t *error, - bool debug_enable = false); - BWindowScreen(const char *title, - uint32 space, - uint32 attributes, - status_t *error); -virtual ~BWindowScreen(); -virtual void Quit(void); -virtual void ScreenConnected(bool active); - void Disconnect(); -virtual void WindowActivated(bool active); -virtual void WorkspaceActivated(int32 ws, bool state); -virtual void ScreenChanged(BRect screen_size, color_space depth); -virtual void Hide(); -virtual void Show(); - void SetColorList(rgb_color *list,int32 first_index = 0,int32 last_index = 255); - status_t SetSpace(uint32 space); - bool CanControlFrameBuffer(); - status_t SetFrameBuffer(int32 width, int32 height); - status_t MoveDisplayArea(int32 x, int32 y); + BWindowScreen(const char *title, uint32 space, status_t *error, + bool debug_enable = false); + BWindowScreen(const char *title, uint32 space, uint32 attributes, + status_t *error); + virtual ~BWindowScreen(); - void *IOBase(); // Not supported anymore. It always returns NULL + virtual void Quit(); + virtual void ScreenConnected(bool active); + void Disconnect(); + + virtual void WindowActivated(bool active); + virtual void WorkspaceActivated(int32 ws, bool state); + virtual void ScreenChanged(BRect screen_size, color_space depth); + + virtual void Hide(); + virtual void Show(); + + void SetColorList(rgb_color *list,int32 first_index = 0,int32 last_index = 255); + status_t SetSpace(uint32 space); + + bool CanControlFrameBuffer(); + status_t SetFrameBuffer(int32 width, int32 height); + status_t MoveDisplayArea(int32 x, int32 y); + + void *IOBase(); // Not supported anymore. It always returns NULL - rgb_color *ColorList(); - frame_buffer_info *FrameBufferInfo(); - graphics_card_hook CardHookAt(int32 index); - graphics_card_info *CardInfo(); + rgb_color *ColorList(); + frame_buffer_info *FrameBufferInfo(); + graphics_card_hook CardHookAt(int32 index); + graphics_card_info *CardInfo(); /******************************* Debugger API Notice ******************************** Those three calls, and the debug_enable flag in the constructor, have been added to @@ -134,16 +135,16 @@ virtual void Show(); The Debug API will not be support after the Preview Release (replaced by the debug API in the new WindowScreen class). ***************************************************************************************/ - void RegisterThread(thread_id id); + void RegisterThread(thread_id id); virtual void SuspensionHook(bool active); - void Suspend(char *label); + void Suspend(char *label); virtual status_t Perform(perform_code d, void *arg); private: - typedef BWindow inherited; + typedef BWindow inherited; virtual void _ReservedWindowScreen1(); virtual void _ReservedWindowScreen2(); @@ -156,14 +157,13 @@ virtual void _ReservedWindowScreen4(); char _unused; char space_mode; - void *io_buffer; - bool direct_enable; + bool direct_enable; bool fWorkState; bool fWindowState; bool fActivateState; int32 fLockState; int32 fScreenIndex; - int32 memory_area, io_area; + display_mode *fOldDisplayMode; display_mode *fDisplayMode; uint32 space0; @@ -172,8 +172,9 @@ virtual void _ReservedWindowScreen4(); image_id fAddonImage; rgb_color fColorList[256]; - GetAccelerantHook m_gah; + GetAccelerantHook fGetAccelerantHook; graphics_card_info fCardInfo; + graphics_card_hook hooks[B_HOOK_COUNT]; _direct_screen_info_ info; frame_buffer_info fFrameBufferInfo; @@ -188,7 +189,8 @@ virtual void _ReservedWindowScreen4(); uint32 fAttributes; uint32 fModeCount; display_mode *fModeList; - engine_token *et; + + engine_token *fEngineToken; wait_engine_idle m_wei; acquire_engine m_ae; release_engine m_re; @@ -197,13 +199,12 @@ virtual void _ReservedWindowScreen4(); screen_to_screen_transparent_blit trans_blit_rect; screen_to_screen_scaled_filtered_blit scaled_filtered_blit_rect; - uint32 _reserved_[21]; + uint32 _reserved_[24]; -static BRect CalcFrame(int32 index, int32 space, display_mode *dmode); - status_t SetFullscreen(bool enable); + static BRect CalcFrame(int32 index, int32 space, display_mode *dmode); status_t InitData(uint32 space, uint32 attributes); status_t SetActiveState(int32 state); - status_t SetLockState(int32 state); + status_t SetupAccelerantHooks(bool enable); status_t GetCardInfo(); void Suspend(); void Resume(); diff --git a/src/kits/game/WindowScreen.cpp b/src/kits/game/WindowScreen.cpp index f5ecf8d3eb..479bcf4e1f 100644 --- a/src/kits/game/WindowScreen.cpp +++ b/src/kits/game/WindowScreen.cpp @@ -21,7 +21,6 @@ #include // For IS_SET_MOUSE_POSITION #include - #include #include @@ -36,22 +35,23 @@ using BPrivate::AppServerLink; #endif -static graphics_card_info card_info_global; -fill_rectangle fill_rect_global; -screen_to_screen_blit blit_rect_global; -screen_to_screen_transparent_blit trans_blit_rect_global; -screen_to_screen_scaled_filtered_blit scaled_filtered_blit_rect_global; -wait_engine_idle wait_idle_global; -engine_token *et_global; -acquire_engine acquire_engine_global; -release_engine release_engine_global; +// Acceleration hooks pointers +static fill_rectangle sFillRectHook; +static screen_to_screen_blit sBlitRectHook; +static screen_to_screen_transparent_blit sTransparentBlitHook; +static screen_to_screen_scaled_filtered_blit sScaledFilteredBlitHook; +static wait_engine_idle sWaitIdleHook; +static acquire_engine sAcquireEngineHook; +static release_engine sReleaseEngineHook; + +static engine_token *sEngineToken; // Helper methods which translates the pre r5 graphics methods to r5 ones static int32 card_sync() { - wait_idle_global(); + sWaitIdleHook(); return 0; } @@ -67,9 +67,9 @@ blit(int32 sx, int32 sy, int32 dx, int32 dy, int32 width, int32 height) param.width = width; param.height = height; - acquire_engine_global(B_2D_ACCELERATION, 0xff, NULL, &et_global); - blit_rect_global(et_global, ¶m, 1); - release_engine_global(et_global, NULL); + sAcquireEngineHook(B_2D_ACCELERATION, 0xff, NULL, &sEngineToken); + sBlitRectHook(sEngineToken, ¶m, 1); + sReleaseEngineHook(sEngineToken, NULL); return 0; } @@ -88,9 +88,9 @@ transparent_blit(int32 sx, int32 sy, int32 dx, int32 dy, param.width = width; param.height = height; - acquire_engine_global(B_2D_ACCELERATION, 0xff, 0, &et_global); - trans_blit_rect_global(et_global, transparent_color, ¶m, 1); - release_engine_global(et_global, 0); + sAcquireEngineHook(B_2D_ACCELERATION, 0xff, 0, &sEngineToken); + sTransparentBlitHook(sEngineToken, transparent_color, ¶m, 1); + sReleaseEngineHook(sEngineToken, 0); return 0; } */ @@ -108,9 +108,9 @@ scaled_filtered_blit(int32 sx, int32 sy, int32 sw, int32 sh, int32 dx, int32 dy, param.dest_width = dw; param.dest_height = dh; - acquire_engine_global(B_2D_ACCELERATION, 0xff, NULL, &et_global); - scaled_filtered_blit_rect_global(et_global, ¶m, 1); - release_engine_global(et_global, NULL); + sAcquireEngineHook(B_2D_ACCELERATION, 0xff, NULL, &sEngineToken); + sScaledFilteredBlitHook(sEngineToken, ¶m, 1); + sReleaseEngineHook(sEngineToken, NULL); return 0; } @@ -124,9 +124,9 @@ draw_rect_8(int32 sx, int32 sy, int32 sw, int32 sh, uint8 color_index) param.right = sw; param.bottom = sh; - acquire_engine_global(B_2D_ACCELERATION, 0xff, NULL, &et_global); - fill_rect_global(et_global, color_index, ¶m, 1); - release_engine_global(et_global, NULL); + sAcquireEngineHook(B_2D_ACCELERATION, 0xff, NULL, &sEngineToken); + sFillRectHook(sEngineToken, color_index, ¶m, 1); + sReleaseEngineHook(sEngineToken, NULL); return 0; } @@ -140,9 +140,9 @@ draw_rect_16(int32 sx, int32 sy, int32 sw, int32 sh, uint16 color) param.right = sw; param.bottom = sh; - acquire_engine_global(B_2D_ACCELERATION, 0xff, NULL, &et_global); - fill_rect_global(et_global, color, ¶m, 1); - release_engine_global(et_global, NULL); + sAcquireEngineHook(B_2D_ACCELERATION, 0xff, NULL, &sEngineToken); + sFillRectHook(sEngineToken, color, ¶m, 1); + sReleaseEngineHook(sEngineToken, NULL); return 0; } @@ -156,9 +156,9 @@ draw_rect_32(int32 sx, int32 sy, int32 sw, int32 sh, uint32 color) param.right = sw; param.bottom = sh; - acquire_engine_global(B_2D_ACCELERATION, 0xff, NULL, &et_global); - fill_rect_global(et_global, color, ¶m, 1); - release_engine_global(et_global, NULL); + sAcquireEngineHook(B_2D_ACCELERATION, 0xff, NULL, &sEngineToken); + sFillRectHook(sEngineToken, color, ¶m, 1); + sReleaseEngineHook(sEngineToken, NULL); return 0; } @@ -285,11 +285,10 @@ set_mouse_position(int32 x, int32 y) BWindowScreen::BWindowScreen(const char *title, uint32 space, - status_t *error, bool debug_enable) + status_t *error, bool debug_enable) : BWindow(BScreen().Frame(), title, B_TITLED_WINDOW, kWindowScreenFlag | B_NOT_MINIMIZABLE | B_NOT_CLOSABLE - | B_NOT_ZOOMABLE | B_NOT_MOVABLE | B_NOT_RESIZABLE, - B_CURRENT_WORKSPACE) + | B_NOT_ZOOMABLE | B_NOT_MOVABLE | B_NOT_RESIZABLE, B_CURRENT_WORKSPACE) { CALLED(); uint32 attributes = 0; @@ -303,11 +302,10 @@ BWindowScreen::BWindowScreen(const char *title, uint32 space, BWindowScreen::BWindowScreen(const char *title, uint32 space, - uint32 attributes, status_t *error) + uint32 attributes, status_t *error) : BWindow(BScreen().Frame(), title, B_TITLED_WINDOW, kWindowScreenFlag | B_NOT_MINIMIZABLE | B_NOT_CLOSABLE - | B_NOT_ZOOMABLE | B_NOT_MOVABLE | B_NOT_RESIZABLE, - B_CURRENT_WORKSPACE) + | B_NOT_ZOOMABLE | B_NOT_MOVABLE | B_NOT_RESIZABLE, B_CURRENT_WORKSPACE) { CALLED(); status_t status = InitData(space, attributes); @@ -323,8 +321,6 @@ BWindowScreen::~BWindowScreen() if (fAddonImage >= 0) unload_add_on(fAddonImage); - SetFullscreen(false); - delete_sem(fActivateSem); delete_sem(fDebugSem); @@ -404,12 +400,7 @@ void BWindowScreen::Hide() { CALLED(); - if (fLockState == 1) { - if (fDebugState) - fDebugFirst = true; - SetActiveState(0); - } - + Disconnect(); BWindow::Hide(); } @@ -439,7 +430,7 @@ BWindowScreen::SetColorList(rgb_color *list, int32 first_index, int32 last_index } else { uint32 colorCount = last_index - first_index + 1; if (fAddonImage >= 0) { - set_indexed_colors sic = (set_indexed_colors)m_gah(B_SET_INDEXED_COLORS, NULL); + set_indexed_colors sic = (set_indexed_colors)fGetAccelerantHook(B_SET_INDEXED_COLORS, NULL); if (sic != NULL) sic(colorCount, first_index, (uint8 *)fColorList, 0); } @@ -493,9 +484,6 @@ BWindowScreen::SetFrameBuffer(int32 width, int32 height) BScreen screen(this); status_t status = screen.ProposeMode(&mode, &lowMode, &highMode); - - // If the mode is supported, change the workspace - // to that mode. if (status == B_OK) status = AssertDisplayMode(&mode); @@ -553,36 +541,21 @@ BWindowScreen::CardHookAt(int32 index) switch (index) { case 5: // 8 bit fill rect - hook = (graphics_card_hook)m_gah(B_FILL_RECTANGLE, 0); - fill_rect = (fill_rectangle)hook; - fill_rect_global = fill_rect; hook = (graphics_card_hook)draw_rect_8; break; case 6: // 32 bit fill rect - hook = (graphics_card_hook)m_gah(B_FILL_RECTANGLE, 0); - fill_rect = (fill_rectangle)hook; - fill_rect_global = fill_rect; hook = (graphics_card_hook)draw_rect_32; break; case 7: // screen to screen blit - hook = (graphics_card_hook)m_gah(B_SCREEN_TO_SCREEN_BLIT, 0); - blit_rect = (screen_to_screen_blit)hook; - blit_rect_global = blit_rect; hook = (graphics_card_hook)blit; break; case 8: // screen to screen scaled filtered blit - hook = (graphics_card_hook)m_gah(B_SCREEN_TO_SCREEN_SCALED_FILTERED_BLIT, 0); - scaled_filtered_blit_rect = (screen_to_screen_scaled_filtered_blit)hook; - scaled_filtered_blit_rect_global = scaled_filtered_blit_rect; hook = (graphics_card_hook)scaled_filtered_blit; break; case 10: // sync aka wait for graphics card idle hook = (graphics_card_hook)card_sync; break; case 13: // 16 bit fill rect - hook = (graphics_card_hook)m_gah(B_FILL_RECTANGLE, 0); - fill_rect = (fill_rectangle)hook; - fill_rect_global = fill_rect; hook = (graphics_card_hook)draw_rect_16; break; default: @@ -677,17 +650,6 @@ BWindowScreen::CalcFrame(int32 index, int32 space, display_mode *dmode) } -status_t -BWindowScreen::SetFullscreen(bool enable) -{ - status_t status = B_ERROR; - - // TODO: Set fullscreen - - return status; -} - - status_t BWindowScreen::InitData(uint32 space, uint32 attributes) { @@ -699,32 +661,24 @@ BWindowScreen::InitData(uint32 space, uint32 attributes) fDebugFirst = true; fAttributes = attributes; - fScreenIndex = current_workspace(); + fScreenIndex = fDebugWorkspace = current_workspace(); fLockState = 0; fAddonImage = -1; fWindowState = 0; - fDebugWorkspace = 0; BScreen screen(this); status_t status = screen.GetModeList(&fModeList, &fModeCount); - if (status < B_OK) { - printf("BScreen::GetModeList() returned %s\n", strerror(status)); + if (status < B_OK) return status; - } display_mode newMode; status = GetModeFromSpace(space, &newMode); - if (status < B_OK) { - printf("GetModeFromSpace() returned %s\n", strerror(status)); + if (status < B_OK) return status; - } space_mode = 1; space0 = 0; - SetWorkspaces(B_CURRENT_WORKSPACE); - SetFullscreen(true); - memcpy(fColorList, screen.ColorMap()->color_list, 256); status = GetCardInfo(); @@ -753,37 +707,38 @@ BWindowScreen::SetActiveState(int32 state) status_t status = B_ERROR; if (state == 1) { be_app->HideCursor(); - if (be_app->IsCursorHidden() && (status = SetLockState(1)) == B_OK) { - status = AssertDisplayMode(fDisplayMode); - if (status == B_OK) { - if (!fActivateState) { - while (acquire_sem(fActivateSem) == B_INTERRUPTED) - ; - } - SetColorList(fColorList); - if (fDebugState && !fDebugFirst) { - SuspensionHook(true); - Resume(); - } else { - fDebugFirst = true; - ScreenConnected(true); - } - if (status == B_OK) - return status; + status = AssertDisplayMode(fDisplayMode); + if (status == B_OK && (status = SetupAccelerantHooks(true)) == B_OK) { + if (!fActivateState) { + while (acquire_sem(fActivateSem) == B_INTERRUPTED) + ; + } + + SetColorList(fColorList); + if (fDebugState && !fDebugFirst) { + SuspensionHook(true); + Resume(); + } else { + fDebugFirst = true; + ScreenConnected(true); + } + + if (status == B_OK) + return status; + + } else + SetupAccelerantHooks(false); - } else - SetLockState(0); - - be_app->ShowCursor(); - } + be_app->ShowCursor(); } else { + AssertDisplayMode(fOldDisplayMode); if (fDebugState && !fDebugFirst) { Suspend(); SuspensionHook(false); } else ScreenConnected(false); - status = SetLockState(0); + status = SetupAccelerantHooks(false); if (status == B_OK) { be_app->ShowCursor(); if (fActivateState) { @@ -792,55 +747,56 @@ BWindowScreen::SetActiveState(int32 state) } } - printf("SetActiveState() returning %s\n", strerror(status)); return status; } status_t -BWindowScreen::SetLockState(int32 state) +BWindowScreen::SetupAccelerantHooks(bool enable) { CALLED(); - if (fAddonImage >= 0 && state == 1) { + if (fAddonImage >= 0) { m_wei(); - fill_rect_global = NULL; - blit_rect_global = NULL; - trans_blit_rect_global = NULL; - scaled_filtered_blit_rect_global = NULL; - wait_idle_global = NULL; - et_global = NULL; - acquire_engine_global = NULL; - release_engine_global = NULL; + sFillRectHook = NULL; + sBlitRectHook = NULL; + sTransparentBlitHook = NULL; + sScaledFilteredBlitHook = NULL; + sWaitIdleHook = NULL; + sEngineToken = NULL; + sAcquireEngineHook = NULL; + sReleaseEngineHook = NULL; } - status_t status = B_OK; - - // TODO: Set lock state (whatever it means) + if (enable) + fLockState = 1; + else + fLockState = 0; - if (status == B_OK) { - fLockState = state; - if (state == 1) { - if (fAddonImage < 0) { - status = InitClone(); - if (status == B_OK) { - m_wei = (wait_engine_idle)m_gah(B_WAIT_ENGINE_IDLE, NULL); - m_re = (release_engine)m_gah(B_RELEASE_ENGINE, NULL); - m_ae = (acquire_engine)m_gah(B_ACQUIRE_ENGINE, NULL); - } - } - + status_t status = B_OK; + if (enable) { + if (fAddonImage < 0) { + status = InitClone(); if (status == B_OK) { - fill_rect_global = fill_rect; - blit_rect_global = blit_rect; - trans_blit_rect_global = trans_blit_rect; - scaled_filtered_blit_rect_global = scaled_filtered_blit_rect; - wait_idle_global = m_wei; - et_global = et; - acquire_engine_global = m_ae; - release_engine_global = m_re; - m_wei(); + m_wei = (wait_engine_idle)fGetAccelerantHook(B_WAIT_ENGINE_IDLE, fDisplayMode); + m_re = (release_engine)fGetAccelerantHook(B_RELEASE_ENGINE, fDisplayMode); + m_ae = (acquire_engine)fGetAccelerantHook(B_ACQUIRE_ENGINE, fDisplayMode); + fill_rect = (fill_rectangle)fGetAccelerantHook(B_FILL_RECTANGLE, fDisplayMode); + blit_rect = (screen_to_screen_blit)fGetAccelerantHook(B_SCREEN_TO_SCREEN_BLIT, fDisplayMode); + trans_blit_rect = (screen_to_screen_transparent_blit)fGetAccelerantHook(B_SCREEN_TO_SCREEN_TRANSPARENT_BLIT, fDisplayMode); + scaled_filtered_blit_rect = (screen_to_screen_scaled_filtered_blit)fGetAccelerantHook(B_SCREEN_TO_SCREEN_SCALED_FILTERED_BLIT, fDisplayMode); } } + + if (status == B_OK) { + sFillRectHook = fill_rect; + sBlitRectHook = blit_rect; + sTransparentBlitHook = trans_blit_rect; + sScaledFilteredBlitHook = scaled_filtered_blit_rect; + sWaitIdleHook = m_wei; + sAcquireEngineHook = m_ae; + sReleaseEngineHook = m_re; + m_wei(); + } } return status; @@ -854,7 +810,6 @@ BWindowScreen::GetCardInfo() BScreen screen(this); display_mode mode; - status_t status = screen.GetMode(&mode); if (status < B_OK) return status; @@ -876,7 +831,7 @@ BWindowScreen::GetCardInfo() } fCardInfo.version = 2; - fCardInfo.id = 0; + fCardInfo.id = screen.ID().id; fCardInfo.bits_per_pixel = bitsPerPixel; fCardInfo.width = mode.virtual_width; fCardInfo.height = mode.virtual_height; @@ -893,7 +848,6 @@ BWindowScreen::GetCardInfo() if (mode.flags & B_PARALLEL_ACCESS) fCardInfo.flags |= B_PARALLEL_BUFFER_ACCESS; - frame_buffer_config config; AppServerLink link; link.StartMessage(AS_GET_FRAME_BUFFER_CONFIG); link.Attach(screen.ID()); @@ -902,14 +856,12 @@ BWindowScreen::GetCardInfo() if (link.FlushWithReply(result) < B_OK || result < B_OK) return result; + frame_buffer_config config; link.Read(&config); - fCardInfo.id = screen.ID().id; fCardInfo.frame_buffer = config.frame_buffer; fCardInfo.bytes_per_row = config.bytes_per_row; - memcpy(&card_info_global, &fCardInfo, sizeof(graphics_card_info)); - return B_OK; } @@ -1005,7 +957,7 @@ BWindowScreen::InitClone() } status = get_image_symbol(fAddonImage, B_ACCELERANT_ENTRY_POINT, - B_SYMBOL_TYPE_ANY, (void **)&m_gah); + B_SYMBOL_TYPE_TEXT, (void **)&fGetAccelerantHook); if (status < B_OK) { printf("InitClone: cannot get accelerant entry point\n"); unload_add_on(fAddonImage); @@ -1013,7 +965,7 @@ BWindowScreen::InitClone() return status; } - clone_accelerant clone = (clone_accelerant)m_gah(B_CLONE_ACCELERANT, 0); + clone_accelerant clone = (clone_accelerant)fGetAccelerantHook(B_CLONE_ACCELERANT, 0); if (clone == NULL) { printf("InitClone: cannot get clone hook\n"); unload_add_on(fAddonImage); @@ -1043,18 +995,20 @@ BWindowScreen::InitClone() status_t BWindowScreen::AssertDisplayMode(display_mode *dmode) { + CALLED(); + status_t status = B_ERROR; - - display_mode mode = *dmode; - mode.flags |= B_SCROLL; - - // TODO: Assert display mode: negotiation with app server - status = BScreen(this).SetMode(&mode); - if (status == B_OK) { + if (dmode->virtual_width != fDisplayMode->virtual_width + || dmode->virtual_height != fDisplayMode->virtual_height + || dmode->space != fDisplayMode->space) { + status = BScreen(this).SetMode(dmode); + if (status < B_OK) + return status; + memcpy(fDisplayMode, dmode, sizeof(display_mode)); space_mode = 1; } - + status = GetCardInfo(); if (status < B_OK) return status;