Moved DirectWindow support classes into a separate DirectWindowSupport.h/cpp.
No functional change. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32613 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
2ff62714d0
commit
467c2e8cb5
143
src/servers/app/DirectWindowSupport.cpp
Normal file
143
src/servers/app/DirectWindowSupport.cpp
Normal file
@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright 2008-2009, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Stefano Ceccherini <stefano.ceccherini@gmail.com>
|
||||
* Axel Dörfler, axeld@pinc-software.de
|
||||
*/
|
||||
|
||||
#include "DirectWindowSupport.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
DirectWindowData::DirectWindowData()
|
||||
:
|
||||
buffer_info(NULL),
|
||||
full_screen(false),
|
||||
fSem(-1),
|
||||
fAcknowledgeSem(-1),
|
||||
fBufferArea(-1),
|
||||
fTransition(0)
|
||||
{
|
||||
fBufferArea = create_area("direct area", (void**)&buffer_info,
|
||||
B_ANY_ADDRESS, DIRECT_BUFFER_INFO_AREA_SIZE,
|
||||
B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
|
||||
|
||||
memset(buffer_info, 0, DIRECT_BUFFER_INFO_AREA_SIZE);
|
||||
buffer_info->buffer_state = B_DIRECT_STOP;
|
||||
fSem = create_sem(0, "direct sem");
|
||||
fAcknowledgeSem = create_sem(0, "direct sem ack");
|
||||
}
|
||||
|
||||
|
||||
DirectWindowData::~DirectWindowData()
|
||||
{
|
||||
// this should make the client die in case it's still running
|
||||
buffer_info->bits = NULL;
|
||||
buffer_info->bytes_per_row = 0;
|
||||
|
||||
delete_area(fBufferArea);
|
||||
delete_sem(fSem);
|
||||
delete_sem(fAcknowledgeSem);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
DirectWindowData::InitCheck() const
|
||||
{
|
||||
if (fBufferArea < B_OK)
|
||||
return fBufferArea;
|
||||
if (fSem < B_OK)
|
||||
return fSem;
|
||||
if (fAcknowledgeSem < B_OK)
|
||||
return fAcknowledgeSem;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
DirectWindowData::GetSyncData(direct_window_sync_data& data) const
|
||||
{
|
||||
data.area = fBufferArea;
|
||||
data.disable_sem = fSem;
|
||||
data.disable_sem_ack = fAcknowledgeSem;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
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 {
|
||||
status = acquire_sem_etc(fAcknowledgeSem, 1, B_TIMEOUT, 500000);
|
||||
} while (status == B_INTERRUPTED);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DirectWindowData::SetState(const direct_buffer_state& bufferState,
|
||||
const direct_driver_state& driverState)
|
||||
{
|
||||
BufferState inputState(bufferState);
|
||||
BufferState currentState(buffer_info->buffer_state);
|
||||
|
||||
bool handle = false;
|
||||
|
||||
if (inputState.Action() == B_DIRECT_STOP)
|
||||
handle = _HandleStop(bufferState);
|
||||
else if (inputState.Action() == B_DIRECT_START)
|
||||
handle = _HandleStart(bufferState);
|
||||
else if (inputState.Action() == B_DIRECT_MODIFY)
|
||||
handle = _HandleModify(bufferState);
|
||||
|
||||
if (driverState != -1)
|
||||
buffer_info->driver_state = driverState;
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DirectWindowData::_HandleStop(const direct_buffer_state& state)
|
||||
{
|
||||
buffer_info->buffer_state = B_DIRECT_STOP;
|
||||
if (fTransition-- >= 1)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DirectWindowData::_HandleStart(const direct_buffer_state& state)
|
||||
{
|
||||
buffer_info->buffer_state = (direct_buffer_state)
|
||||
(BufferState(buffer_info->buffer_state).Reason() | state);
|
||||
if (fTransition++ >= 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DirectWindowData::_HandleModify(const direct_buffer_state& state)
|
||||
{
|
||||
buffer_info->buffer_state = state;
|
||||
if (fTransition > 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
60
src/servers/app/DirectWindowSupport.h
Normal file
60
src/servers/app/DirectWindowSupport.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2008-2009, Haiku. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <DirectWindow.h>
|
||||
|
||||
#include <DirectWindowPrivate.h>
|
||||
|
||||
struct BufferState {
|
||||
BufferState(const direct_buffer_state& state)
|
||||
:
|
||||
fState(state)
|
||||
{
|
||||
}
|
||||
|
||||
inline direct_buffer_state Action() const
|
||||
{
|
||||
return (direct_buffer_state)(fState & B_DIRECT_MODE_MASK);
|
||||
}
|
||||
|
||||
inline direct_buffer_state Reason() const
|
||||
{
|
||||
return (direct_buffer_state)(fState & ~B_DIRECT_MODE_MASK);
|
||||
}
|
||||
|
||||
direct_buffer_state fState;
|
||||
};
|
||||
|
||||
|
||||
class DirectWindowData {
|
||||
public:
|
||||
DirectWindowData();
|
||||
~DirectWindowData();
|
||||
|
||||
status_t InitCheck() const;
|
||||
|
||||
status_t GetSyncData(
|
||||
direct_window_sync_data& data) const;
|
||||
status_t SyncronizeWithClient();
|
||||
|
||||
bool SetState(const direct_buffer_state& bufferState,
|
||||
const direct_driver_state& driverState);
|
||||
|
||||
BRect old_window_frame;
|
||||
direct_buffer_info* buffer_info;
|
||||
bool full_screen;
|
||||
|
||||
private:
|
||||
bool _HandleStop(const direct_buffer_state& state);
|
||||
bool _HandleStart(const direct_buffer_state& state);
|
||||
bool _HandleModify(const direct_buffer_state& state);
|
||||
|
||||
sem_id fSem;
|
||||
sem_id fAcknowledgeSem;
|
||||
area_id fBufferArea;
|
||||
int32 fTransition;
|
||||
};
|
||||
|
@ -23,6 +23,7 @@ Server app_server :
|
||||
DefaultDecorator.cpp
|
||||
Desktop.cpp
|
||||
DesktopSettings.cpp
|
||||
DirectWindowSupport.cpp
|
||||
DrawState.cpp
|
||||
EventDispatcher.cpp
|
||||
EventStream.cpp
|
||||
|
@ -40,7 +40,6 @@
|
||||
#include <GradientDiamond.h>
|
||||
#include <GradientConic.h>
|
||||
|
||||
#include <DirectWindowPrivate.h>
|
||||
#include <MessagePrivate.h>
|
||||
#include <PortLink.h>
|
||||
#include <ServerProtocolStructs.h>
|
||||
@ -52,6 +51,7 @@
|
||||
|
||||
#include "AppServer.h"
|
||||
#include "Desktop.h"
|
||||
#include "DirectWindowSupport.h"
|
||||
#include "DrawingEngine.h"
|
||||
#include "HWInterface.h"
|
||||
#include "Overlay.h"
|
||||
@ -120,189 +120,6 @@ static profile sRedrawProcessingTime;
|
||||
#endif
|
||||
|
||||
|
||||
// TODO: Move to another file
|
||||
struct BufferState {
|
||||
BufferState(const direct_buffer_state& state)
|
||||
:
|
||||
fState(state)
|
||||
{
|
||||
}
|
||||
|
||||
direct_buffer_state Action() const
|
||||
{
|
||||
return (direct_buffer_state)(fState & B_DIRECT_MODE_MASK);
|
||||
}
|
||||
|
||||
direct_buffer_state Reason() const
|
||||
{
|
||||
return (direct_buffer_state)(fState & ~B_DIRECT_MODE_MASK);
|
||||
}
|
||||
|
||||
direct_buffer_state fState;
|
||||
};
|
||||
|
||||
|
||||
class DirectWindowData {
|
||||
public:
|
||||
DirectWindowData();
|
||||
~DirectWindowData();
|
||||
|
||||
status_t InitCheck() const;
|
||||
|
||||
status_t GetSyncData(
|
||||
direct_window_sync_data& data) const;
|
||||
status_t SyncronizeWithClient();
|
||||
|
||||
bool SetState(const direct_buffer_state& bufferState,
|
||||
const direct_driver_state& driverState);
|
||||
|
||||
BRect old_window_frame;
|
||||
direct_buffer_info* buffer_info;
|
||||
bool full_screen;
|
||||
|
||||
private:
|
||||
bool _HandleStop(const direct_buffer_state& state);
|
||||
bool _HandleStart(const direct_buffer_state& state);
|
||||
bool _HandleModify(const direct_buffer_state& state);
|
||||
|
||||
sem_id fSem;
|
||||
sem_id fAcknowledgeSem;
|
||||
area_id fBufferArea;
|
||||
int32 fTransition;
|
||||
};
|
||||
|
||||
|
||||
DirectWindowData::DirectWindowData()
|
||||
:
|
||||
buffer_info(NULL),
|
||||
full_screen(false),
|
||||
fSem(-1),
|
||||
fAcknowledgeSem(-1),
|
||||
fBufferArea(-1),
|
||||
fTransition(0)
|
||||
{
|
||||
fBufferArea = create_area("direct area", (void**)&buffer_info,
|
||||
B_ANY_ADDRESS, DIRECT_BUFFER_INFO_AREA_SIZE,
|
||||
B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
|
||||
|
||||
memset(buffer_info, 0, DIRECT_BUFFER_INFO_AREA_SIZE);
|
||||
buffer_info->buffer_state = B_DIRECT_STOP;
|
||||
fSem = create_sem(0, "direct sem");
|
||||
fAcknowledgeSem = create_sem(0, "direct sem ack");
|
||||
}
|
||||
|
||||
|
||||
DirectWindowData::~DirectWindowData()
|
||||
{
|
||||
// this should make the client die in case it's still running
|
||||
buffer_info->bits = NULL;
|
||||
buffer_info->bytes_per_row = 0;
|
||||
|
||||
delete_area(fBufferArea);
|
||||
delete_sem(fSem);
|
||||
delete_sem(fAcknowledgeSem);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
DirectWindowData::InitCheck() const
|
||||
{
|
||||
if (fBufferArea < B_OK)
|
||||
return fBufferArea;
|
||||
if (fSem < B_OK)
|
||||
return fSem;
|
||||
if (fAcknowledgeSem < B_OK)
|
||||
return fAcknowledgeSem;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
DirectWindowData::GetSyncData(direct_window_sync_data& data) const
|
||||
{
|
||||
data.area = fBufferArea;
|
||||
data.disable_sem = fSem;
|
||||
data.disable_sem_ack = fAcknowledgeSem;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
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 {
|
||||
status = acquire_sem_etc(fAcknowledgeSem, 1, B_TIMEOUT, 500000);
|
||||
} while (status == B_INTERRUPTED);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DirectWindowData::SetState(const direct_buffer_state& bufferState,
|
||||
const direct_driver_state& driverState)
|
||||
{
|
||||
BufferState inputState(bufferState);
|
||||
BufferState currentState(buffer_info->buffer_state);
|
||||
|
||||
bool handle = false;
|
||||
|
||||
if (inputState.Action() == B_DIRECT_STOP)
|
||||
handle = _HandleStop(bufferState);
|
||||
else if (inputState.Action() == B_DIRECT_START)
|
||||
handle = _HandleStart(bufferState);
|
||||
else if (inputState.Action() == B_DIRECT_MODIFY)
|
||||
handle = _HandleModify(bufferState);
|
||||
|
||||
if (driverState != -1)
|
||||
buffer_info->driver_state = driverState;
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DirectWindowData::_HandleStop(const direct_buffer_state& state)
|
||||
{
|
||||
buffer_info->buffer_state = B_DIRECT_STOP;
|
||||
if (fTransition-- >= 1)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DirectWindowData::_HandleStart(const direct_buffer_state& state)
|
||||
{
|
||||
buffer_info->buffer_state = (direct_buffer_state)
|
||||
(BufferState(buffer_info->buffer_state).Reason() | state);
|
||||
if (fTransition++ >= 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DirectWindowData::_HandleModify(const direct_buffer_state& state)
|
||||
{
|
||||
buffer_info->buffer_state = state;
|
||||
if (fTransition > 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user