From a5a64d5481aadad0161c2db2ce1e7e9e0ffac79f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 27 Aug 2009 09:19:40 +0000 Subject: [PATCH] * Renamed DirectWindowSupport/Data to DirectWindowInfo. * Cleanup of the fullscreen stuff. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32743 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- ...WindowSupport.cpp => DirectWindowInfo.cpp} | 78 ++++++----- ...rectWindowSupport.h => DirectWindowInfo.h} | 26 ++-- src/servers/app/Jamfile | 2 +- src/servers/app/ServerWindow.cpp | 121 +++++++++--------- src/servers/app/ServerWindow.h | 8 +- 5 files changed, 131 insertions(+), 104 deletions(-) rename src/servers/app/{DirectWindowSupport.cpp => DirectWindowInfo.cpp} (83%) rename src/servers/app/{DirectWindowSupport.h => DirectWindowInfo.h} (56%) diff --git a/src/servers/app/DirectWindowSupport.cpp b/src/servers/app/DirectWindowInfo.cpp similarity index 83% rename from src/servers/app/DirectWindowSupport.cpp rename to src/servers/app/DirectWindowInfo.cpp index 340cf24e66..d005a53641 100644 --- a/src/servers/app/DirectWindowSupport.cpp +++ b/src/servers/app/DirectWindowInfo.cpp @@ -8,7 +8,7 @@ */ -#include "DirectWindowSupport.h" +#include "DirectWindowInfo.h" #include #include @@ -20,13 +20,14 @@ #include "clipping.h" -DirectWindowData::DirectWindowData() +DirectWindowInfo::DirectWindowInfo() : - full_screen(false), fBufferInfo(NULL), fSem(-1), fAcknowledgeSem(-1), - fBufferArea(-1) + fBufferArea(-1), + fOriginalFeel(B_NORMAL_WINDOW_FEEL), + fFullScreen(false) { fBufferArea = create_area("direct area", (void**)&fBufferInfo, B_ANY_ADDRESS, DIRECT_BUFFER_INFO_AREA_SIZE, @@ -40,7 +41,7 @@ DirectWindowData::DirectWindowData() } -DirectWindowData::~DirectWindowData() +DirectWindowInfo::~DirectWindowInfo() { // this should make the client die in case it's still running fBufferInfo->bits = NULL; @@ -53,7 +54,7 @@ DirectWindowData::~DirectWindowData() status_t -DirectWindowData::InitCheck() const +DirectWindowInfo::InitCheck() const { if (fBufferArea < B_OK) return fBufferArea; @@ -67,7 +68,7 @@ DirectWindowData::InitCheck() const status_t -DirectWindowData::GetSyncData(direct_window_sync_data& data) const +DirectWindowInfo::GetSyncData(direct_window_sync_data& data) const { data.area = fBufferArea; data.disable_sem = fSem; @@ -78,30 +79,7 @@ DirectWindowData::GetSyncData(direct_window_sync_data& data) const status_t -DirectWindowData::_SyncronizeWithClient() -{ - // Releasing this semaphore causes the client to call - // BDirectWindow::DirectConnected() - status_t status = release_sem(fSem); - if (status != B_OK) - return status; - - // Wait with a timeout of half a second until the client exits - // from its DirectConnected() implementation - do { -#if 0 - status = acquire_sem(fAcknowledgeSem); -#else - status = acquire_sem_etc(fAcknowledgeSem, 1, B_TIMEOUT, 500000); -#endif - } while (status == B_INTERRUPTED); - - return status; -} - - -status_t -DirectWindowData::SetState(direct_buffer_state bufferState, +DirectWindowInfo::SetState(direct_buffer_state bufferState, direct_driver_state driverState, RenderingBuffer* buffer, const BRect& windowFrame, const BRegion& clipRegion) { @@ -142,7 +120,7 @@ DirectWindowData::SetState(direct_buffer_state bufferState, break; default: syslog(LOG_ERR, - "unknown colorspace in DirectWindowData::SetState()!\n"); + "unknown colorspace in DirectWindowInfo::SetState()!\n"); fBufferInfo->bits_per_pixel = 0; break; } @@ -153,7 +131,6 @@ DirectWindowData::SetState(direct_buffer_state bufferState, // TODO fBufferInfo->window_bounds = to_clipping_rect(windowFrame); - // TODO: Review this const int32 kMaxClipRectsCount = (DIRECT_BUFFER_INFO_AREA_SIZE - sizeof(direct_buffer_info)) / sizeof(clipping_rect); @@ -167,3 +144,38 @@ DirectWindowData::SetState(direct_buffer_state bufferState, return _SyncronizeWithClient(); } + + +void +DirectWindowInfo::EnableFullScreen(const BRect& frame, window_feel feel) +{ + fOriginalFrame = frame; + fOriginalFeel = feel; + fFullScreen = true; +} + + +void +DirectWindowInfo::DisableFullScreen() +{ + fFullScreen = false; +} + + +status_t +DirectWindowInfo::_SyncronizeWithClient() +{ + // Releasing this semaphore causes the client to call + // BDirectWindow::DirectConnected() + status_t status = release_sem(fSem); + if (status != B_OK) + return status; + + // Wait with a timeout of half a second until the client exits + // from its DirectConnected() implementation + do { + status = acquire_sem_etc(fAcknowledgeSem, 1, B_TIMEOUT, 500000); + } while (status == B_INTERRUPTED); + + return status; +} diff --git a/src/servers/app/DirectWindowSupport.h b/src/servers/app/DirectWindowInfo.h similarity index 56% rename from src/servers/app/DirectWindowSupport.h rename to src/servers/app/DirectWindowInfo.h index 1a562c7157..4a26ac98d0 100644 --- a/src/servers/app/DirectWindowSupport.h +++ b/src/servers/app/DirectWindowInfo.h @@ -3,8 +3,8 @@ * Distributed under the terms of the MIT License. * */ -#ifndef DIRECT_WINDOW_SUPPORT_H -#define DIRECT_WINDOW_SUPPORT_H +#ifndef DIRECT_WINDOW_INFO_H +#define DIRECT_WINDOW_INFO_H #include @@ -15,16 +15,15 @@ class RenderingBuffer; -class DirectWindowData { +class DirectWindowInfo { public: - DirectWindowData(); - ~DirectWindowData(); + DirectWindowInfo(); + ~DirectWindowInfo(); status_t InitCheck() const; status_t GetSyncData( direct_window_sync_data& data) const; - status_t SyncronizeWithClient(); status_t SetState(direct_buffer_state bufferState, direct_driver_state driverState, @@ -32,8 +31,13 @@ public: const BRect& windowFrame, const BRegion& clipRegion); - BRect old_window_frame; - bool full_screen; + void EnableFullScreen(const BRect& frame, + window_feel feel); + void DisableFullScreen(); + + bool IsFullScreen() const { return fFullScreen; } + const BRect& OriginalFrame() const { return fOriginalFrame; } + window_feel OriginalFeel() const { return fOriginalFeel; } private: status_t _SyncronizeWithClient(); @@ -42,7 +46,11 @@ private: sem_id fSem; sem_id fAcknowledgeSem; area_id fBufferArea; + + BRect fOriginalFrame; + window_feel fOriginalFeel; + bool fFullScreen; }; -#endif // DIRECT_WINDOW_SUPPORT_H +#endif // DIRECT_WINDOW_INFO_H diff --git a/src/servers/app/Jamfile b/src/servers/app/Jamfile index 3c78a0ed13..8393b0f402 100644 --- a/src/servers/app/Jamfile +++ b/src/servers/app/Jamfile @@ -23,7 +23,7 @@ Server app_server : DefaultDecorator.cpp Desktop.cpp DesktopSettings.cpp - DirectWindowSupport.cpp + DirectWindowInfo.cpp DrawState.cpp EventDispatcher.cpp EventStream.cpp diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index 83cfc2adf9..a249930fd3 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -51,7 +51,7 @@ #include "AppServer.h" #include "Desktop.h" -#include "DirectWindowSupport.h" +#include "DirectWindowInfo.h" #include "DrawingEngine.h" #include "HWInterface.h" #include "Overlay.h" @@ -166,9 +166,8 @@ ServerWindow::ServerWindow(const char* title, ServerApp* app, fCurrentDrawingRegion(), fCurrentDrawingRegionValid(false), - fDirectWindowData(NULL), - fIsDirectlyAccessing(false), - fDirectWindowFeel(B_NORMAL_WINDOW_FEEL) + fDirectWindowInfo(NULL), + fIsDirectlyAccessing(false) { STRACE(("ServerWindow(%s)::ServerWindow()\n", title)); @@ -208,7 +207,7 @@ ServerWindow::~ServerWindow() BPrivate::gDefaultTokens.RemoveToken(fServerToken); - delete fDirectWindowData; + delete fDirectWindowInfo; STRACE(("ServerWindow(%p) will exit NOW\n", this)); delete_sem(fDeathSemaphore); @@ -1073,7 +1072,7 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) fLink.StartMessage(status); if (status == B_OK) { struct direct_window_sync_data syncData; - fDirectWindowData->GetSyncData(syncData); + fDirectWindowInfo->GetSyncData(syncData); fLink.Attach(&syncData, sizeof(syncData)); } @@ -1088,7 +1087,7 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) link.Read(&enable); status_t status = B_OK; - if (fDirectWindowData != NULL) + if (fDirectWindowInfo != NULL) _DirectWindowSetFullScreen(enable); else status = B_BAD_TYPE; @@ -3404,12 +3403,8 @@ ServerWindow::ScreenChanged(const BMessage* message) { SendMessageToClient(message); - if (fDirectWindowData != NULL && fDirectWindowData->full_screen) { - BRect screenFrame = fWindow->Screen()->Frame(); - fDesktop->ResizeWindowBy(fWindow, - screenFrame.Width() - fWindow->Frame().Width(), - screenFrame.Height() - fWindow->Frame().Height()); - } + if (fDirectWindowInfo != NULL && fDirectWindowInfo->IsFullScreen()) + _ResizeToFullScreen(); } @@ -3437,42 +3432,18 @@ ServerWindow::MakeWindow(BRect frame, const char* name, } -status_t -ServerWindow::_EnableDirectWindowMode() -{ - if (fDirectWindowData != NULL) { - // already in direct window mode - return B_ERROR; - } - - fDirectWindowData = new (nothrow) DirectWindowData; - if (fDirectWindowData == NULL) - return B_NO_MEMORY; - - status_t status = fDirectWindowData->InitCheck(); - if (status != B_OK) { - delete fDirectWindowData; - fDirectWindowData = NULL; - - return status; - } - - return B_OK; -} - - void ServerWindow::HandleDirectConnection(int32 bufferState, int32 driverState) { ASSERT_MULTI_LOCKED(fDesktop->WindowLocker()); - if (fDirectWindowData == NULL) + if (fDirectWindowInfo == NULL) return; STRACE(("HandleDirectConnection(bufferState = %ld, driverState = %ld)\n", bufferState, driverState)); - status_t status = fDirectWindowData->SetState( + status_t status = fDirectWindowInfo->SetState( (direct_buffer_state)bufferState, (direct_driver_state)driverState, fDesktop->HWInterface()->FrontBuffer(), fWindow->Frame(), fWindow->VisibleContentRegion()); @@ -3487,8 +3458,8 @@ ServerWindow::HandleDirectConnection(int32 bufferState, int32 driverState) // The client application didn't release the semaphore // within the given timeout. Or something else went wrong. // Deleting this member should make it crash. - delete fDirectWindowData; - fDirectWindowData = NULL; + delete fDirectWindowInfo; + fDirectWindowInfo = NULL; } else if ((bufferState & B_DIRECT_MODE_MASK) == B_DIRECT_START) fIsDirectlyAccessing = true; else if ((bufferState & B_DIRECT_MODE_MASK) == B_DIRECT_STOP) @@ -3587,35 +3558,71 @@ ServerWindow::_MessageNeedsAllWindowsLocked(uint32 code) const } +void +ServerWindow::_ResizeToFullScreen() +{ + BRect screenFrame = fWindow->Screen()->Frame(); + + fDesktop->MoveWindowBy(fWindow, + screenFrame.left - fWindow->Frame().left, + screenFrame.top - fWindow->Frame().top); + fDesktop->ResizeWindowBy(fWindow, + screenFrame.Width() - fWindow->Frame().Width(), + screenFrame.Height() - fWindow->Frame().Height()); +} + + +status_t +ServerWindow::_EnableDirectWindowMode() +{ + if (fDirectWindowInfo != NULL) { + // already in direct window mode + return B_ERROR; + } + + fDirectWindowInfo = new(std::nothrow) DirectWindowInfo; + if (fDirectWindowInfo == NULL) + return B_NO_MEMORY; + + status_t status = fDirectWindowInfo->InitCheck(); + if (status != B_OK) { + delete fDirectWindowInfo; + fDirectWindowInfo = NULL; + + return status; + } + + return B_OK; +} + + void ServerWindow::_DirectWindowSetFullScreen(bool enable) { + window_feel feel = kWindowScreenFeel; + if (enable) { fDesktop->HWInterface()->SetCursorVisible(false); - fDirectWindowData->old_window_frame = fWindow->Frame(); - BRect screenFrame = fWindow->Screen()->Frame(); - fDirectWindowFeel = fWindow->Feel(); - fDesktop->MoveWindowBy(fWindow, -fWindow->Frame().left, - -fWindow->Frame().top); - fDesktop->ResizeWindowBy(fWindow, - screenFrame.Width() - fWindow->Frame().Width(), - screenFrame.Height() - fWindow->Frame().Height()); + fDirectWindowInfo->EnableFullScreen(fWindow->Frame(), fWindow->Feel()); + _ResizeToFullScreen(); } else { - const BRect &oldFrame = fDirectWindowData->old_window_frame; + const BRect& originalFrame = fDirectWindowInfo->OriginalFrame(); + + fDirectWindowInfo->DisableFullScreen(); + + // Resize window back to its original size fDesktop->MoveWindowBy(fWindow, - oldFrame.left - fWindow->Frame().left, - oldFrame.top - fWindow->Frame().top); + originalFrame.left - fWindow->Frame().left, + originalFrame.top - fWindow->Frame().top); fDesktop->ResizeWindowBy(fWindow, - oldFrame.Width() - fWindow->Frame().Width(), - oldFrame.Height() - fWindow->Frame().Height()); + originalFrame.Width() - fWindow->Frame().Width(), + originalFrame.Height() - fWindow->Frame().Height()); fDesktop->HWInterface()->SetCursorVisible(true); } - fDirectWindowData->full_screen = enable; - fDesktop->SetWindowFeel(fWindow, - enable ? kWindowScreenFeel : fDirectWindowFeel); + fDesktop->SetWindowFeel(fWindow, feel); } diff --git a/src/servers/app/ServerWindow.h b/src/servers/app/ServerWindow.h index 6c4a450705..2285aacb06 100644 --- a/src/servers/app/ServerWindow.h +++ b/src/servers/app/ServerWindow.h @@ -41,7 +41,7 @@ class Window; class Workspace; class View; class ServerPicture; -class DirectWindowData; +class DirectWindowInfo; struct window_info; #define AS_UPDATE_DECORATOR 'asud' @@ -103,7 +103,7 @@ public: void HandleDirectConnection(int32 bufferState, int32 driverState = 0); bool HasDirectFrameBufferAccess() const - { return fDirectWindowData != NULL; } + { return fDirectWindowInfo != NULL; } bool IsDirectlyAccessing() const { return fIsDirectlyAccessing; } @@ -133,6 +133,7 @@ private: virtual void _PrepareQuit(); virtual void _GetLooperName(char* name, size_t size); + void _ResizeToFullScreen(); status_t _EnableDirectWindowMode(); void _DirectWindowSetFullScreen(bool set); @@ -174,9 +175,8 @@ private: BRegion fCurrentDrawingRegion; bool fCurrentDrawingRegionValid; - DirectWindowData* fDirectWindowData; + DirectWindowInfo* fDirectWindowInfo; bool fIsDirectlyAccessing; - window_feel fDirectWindowFeel; }; #endif // SERVER_WINDOW_H