Rewrote DirectWindow.h, updated DirectWindow.cpp accordingly.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22659 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2007-10-22 10:29:44 +00:00
parent 7bd24def80
commit d9cebac2b7
2 changed files with 130 additions and 179 deletions
+95 -121
View File
@@ -1,23 +1,17 @@
/******************************************************************************* /*
// * Copyright 2001-2007, Haiku.
// File: DirectWindow.h * Distributed under the terms of the MIT License.
// *
// Description: Client window class for direct screen access. * Authors:
// * Stefano Ceccherini <[email protected]>
// Copyright 1998, Be Incorporated, All Rights Reserved. */
//
*******************************************************************************/
#ifndef _DIRECT_WINDOW_H #ifndef _DIRECT_WINDOW_H
#define _DIRECT_WINDOW_H #define _DIRECT_WINDOW_H
#include <Region.h> #include <Region.h>
#include <Window.h> #include <Window.h>
class BDirectDriver;
/* State of the direct access when called back through DirectConnected */
enum direct_buffer_state { enum direct_buffer_state {
B_DIRECT_MODE_MASK = 15, B_DIRECT_MODE_MASK = 15,
@@ -25,151 +19,131 @@ enum direct_buffer_state {
B_DIRECT_STOP = 1, B_DIRECT_STOP = 1,
B_DIRECT_MODIFY = 2, B_DIRECT_MODIFY = 2,
B_CLIPPING_MODIFIED = 16, B_CLIPPING_MODIFIED = 16,
B_BUFFER_RESIZED = 32, B_BUFFER_RESIZED = 32,
B_BUFFER_MOVED = 64, B_BUFFER_MOVED = 64,
B_BUFFER_RESET = 128 B_BUFFER_RESET = 128
}; };
/* State of the direct driver and its hooks functions */
enum direct_driver_state { enum direct_driver_state {
B_DRIVER_CHANGED = 0x0001, B_DRIVER_CHANGED = 1,
B_MODE_CHANGED = 0x0002 B_MODE_CHANGED = 2
}; };
/* Integer rect used to define a cliping rectangle. All bounds are included */
/* Moved to Region.h */
/* Frame buffer access descriptor */
typedef struct { typedef struct {
direct_buffer_state buffer_state; direct_buffer_state buffer_state;
direct_driver_state driver_state; direct_driver_state driver_state;
void *bits; void *bits;
void *pci_bits; void *pci_bits;
int32 bytes_per_row; int32 bytes_per_row;
uint32 bits_per_pixel; uint32 bits_per_pixel;
color_space pixel_format; color_space pixel_format;
buffer_layout layout; buffer_layout layout;
buffer_orientation orientation; buffer_orientation orientation;
uint32 _reserved[9]; uint32 _reserved[11];
uint32 _dd_type_; uint32 clip_list_count;
uint32 _dd_token_;
uint32 clip_list_count;
clipping_rect window_bounds; clipping_rect window_bounds;
clipping_rect clip_bounds; clipping_rect clip_bounds;
clipping_rect clip_list[1]; clipping_rect clip_list[1];
} direct_buffer_info; } direct_buffer_info;
/* BDirectWindow class */
class BDirectWindow : public BWindow { class BDirectWindow : public BWindow {
public: public:
BDirectWindow( BRect frame, BDirectWindow(BRect frame, const char *title, window_type type,
const char *title, uint32 flags, uint32 workspace = B_CURRENT_WORKSPACE);
window_type type, BDirectWindow(BRect frame, const char *title, window_look look,
uint32 flags, window_feel feel, uint32 flags,
uint32 workspace = B_CURRENT_WORKSPACE); uint32 workspace = B_CURRENT_WORKSPACE);
BDirectWindow( BRect frame, virtual ~BDirectWindow();
const char *title,
window_look look, static BArchivable* Instantiate(BMessage *data);
window_feel feel, virtual status_t Archive(BMessage *data, bool deep = true) const;
uint32 flags,
uint32 workspace = B_CURRENT_WORKSPACE);
virtual ~BDirectWindow();
static BArchivable *Instantiate(BMessage *data);
virtual status_t Archive(BMessage *data, bool deep = true) const;
/* defined for future extension (fragile base class). Identical to BWindow */ virtual void Quit();
virtual void Quit(void); virtual void DispatchMessage(BMessage *message, BHandler *handler);
virtual void DispatchMessage(BMessage *message, BHandler *handler); virtual void MessageReceived(BMessage *message);
virtual void MessageReceived(BMessage *message); virtual void FrameMoved(BPoint newPosition);
virtual void FrameMoved(BPoint new_position); virtual void WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces);
virtual void WorkspacesChanged(uint32 old_ws, uint32 new_ws); virtual void WorkspaceActivated(int32 workspaceIndex, bool state);
virtual void WorkspaceActivated(int32 ws, bool state); virtual void FrameResized(float newWidth, float newHeight);
virtual void FrameResized(float new_width, float new_height); virtual void Minimize(bool minimize);
virtual void Minimize(bool minimize); virtual void Zoom(BPoint recPosition, float recWidth, float recHeight);
virtual void Zoom( BPoint rec_position, virtual void ScreenChanged(BRect screenFrame, color_space depth);
float rec_width, virtual void MenusBeginning();
float rec_height); virtual void MenusEnded();
virtual void ScreenChanged(BRect screen_size, color_space depth); virtual void WindowActivated(bool state);
virtual void MenusBeginning(); virtual void Show();
virtual void MenusEnded(); virtual void Hide();
virtual void WindowActivated(bool state); virtual BHandler* ResolveSpecifier(BMessage *message, int32 index,
virtual void Show(); BMessage *specifier, int32 form,
virtual void Hide(); const char *property);
virtual BHandler *ResolveSpecifier(BMessage *msg, virtual status_t GetSupportedSuites(BMessage *data);
int32 index, virtual status_t Perform(perform_code code, void *arg);
BMessage *specifier,
int32 form,
const char *property);
virtual status_t GetSupportedSuites(BMessage *data);
virtual status_t Perform(perform_code d, void *arg);
private: private:
virtual void task_looper(); virtual void task_looper();
virtual BMessage *ConvertToMessage(void *raw, int32 code); virtual BMessage* ConvertToMessage(void *raw, int32 code);
/* new APIs */
public: public:
virtual void DirectConnected(direct_buffer_info *info); virtual void DirectConnected(direct_buffer_info *info);
status_t GetClippingRegion(BRegion *region, BPoint *origin = NULL) const; status_t GetClippingRegion(BRegion *region, BPoint *origin = NULL) const;
status_t SetFullScreen(bool enable); status_t SetFullScreen(bool enable);
bool IsFullScreen() const; bool IsFullScreen() const;
static bool SupportsWindowMode(screen_id = B_MAIN_SCREEN_ID); static bool SupportsWindowMode(screen_id id = B_MAIN_SCREEN_ID);
/* private */
private: private:
typedef BWindow inherited; typedef BWindow inherited;
virtual void _ReservedDirectWindow1(); virtual void _ReservedDirectWindow1();
virtual void _ReservedDirectWindow2(); virtual void _ReservedDirectWindow2();
virtual void _ReservedDirectWindow3(); virtual void _ReservedDirectWindow3();
virtual void _ReservedDirectWindow4(); virtual void _ReservedDirectWindow4();
BDirectWindow(); BDirectWindow();
BDirectWindow(BDirectWindow &); BDirectWindow(BDirectWindow &);
BDirectWindow &operator=(BDirectWindow &); BDirectWindow &operator=(BDirectWindow &);
bool fDaemonKiller; static int32 _daemon_thread(void *arg);
bool fConnectionEnable; int32 _DirectDaemon();
bool fIsFullScreen; bool _LockDirect() const;
bool fDirectDriverReady; void _UnlockDirect() const;
bool fInDirectConnect;
int32 fDirectLock;
sem_id fDirectSem;
uint32 fDirectLockCount;
thread_id fDirectLockOwner;
char *fDirectLockStack;
sem_id fDisableSem;
sem_id fDisableSemAck;
uint32 fInitStatus;
uint32 fInfoAreaSize;
uint32 fDirectDriverType;
uint32 fDirectDriverToken;
area_id fClonedClippingArea;
area_id fSourceClippingArea;
thread_id fDirectDaemonId;
direct_buffer_info *fBufferDesc;
BDirectDriver *direct_driver;
struct priv_ext *extension;
uint32 _reserved_[15];
static int32 _DaemonStarter(void *arg); void _InitData();
int32 DirectDaemonFunc(); void _DisposeData();
bool LockDirect() const;
void UnlockDirect() const; bool fDaemonKiller;
void InitData(); bool fConnectionEnable;
void DisposeData(); bool fIsFullScreen;
status_t DriverSetup() const; bool _unused;
bool fInDirectConnect;
int32 fDirectLock;
sem_id fDirectSem;
uint32 fDirectLockCount;
thread_id fDirectLockOwner;
char *fDirectLockStack;
sem_id fDisableSem;
sem_id fDisableSemAck;
uint32 fInitStatus;
uint32 fInfoAreaSize;
uint32 _reserved[2];
area_id fClonedClippingArea;
area_id fSourceClippingArea;
thread_id fDirectDaemonId;
direct_buffer_info *fBufferDesc;
uint32 _more_reserved_[17];
}; };
#endif #endif
+35 -58
View File
@@ -1,13 +1,12 @@
/* /*
* Copyright 2003-2006, Haiku Inc. * Copyright 2003-2007, Haiku Inc.
* Authors: * Authors:
* Stefano Ceccherini ([email protected]). * Stefano Ceccherini <[email protected]>
* Carwyn Jones ([email protected]) * Carwyn Jones <[email protected]>
* *
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include <DirectWindow.h> #include <DirectWindow.h>
#include <Screen.h> #include <Screen.h>
@@ -89,7 +88,7 @@ BDirectWindow::BDirectWindow(BRect frame, const char *title, window_type type,
uint32 flags, uint32 workspace) uint32 flags, uint32 workspace)
: BWindow(frame, title, type, flags, workspace) : BWindow(frame, title, type, flags, workspace)
{ {
InitData(); _InitData();
} }
@@ -97,13 +96,13 @@ BDirectWindow::BDirectWindow(BRect frame, const char *title, window_look look,
window_feel feel, uint32 flags, uint32 workspace) window_feel feel, uint32 flags, uint32 workspace)
: BWindow(frame, title, look, feel, flags, workspace) : BWindow(frame, title, look, feel, flags, workspace)
{ {
InitData(); _InitData();
} }
BDirectWindow::~BDirectWindow() BDirectWindow::~BDirectWindow()
{ {
DisposeData(); _DisposeData();
} }
@@ -144,30 +143,30 @@ BDirectWindow::MessageReceived(BMessage *message)
void void
BDirectWindow::FrameMoved(BPoint new_position) BDirectWindow::FrameMoved(BPoint newPosition)
{ {
inherited::FrameMoved(new_position); inherited::FrameMoved(newPosition);
} }
void void
BDirectWindow::WorkspacesChanged(uint32 old_ws, uint32 new_ws) BDirectWindow::WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces)
{ {
inherited::WorkspacesChanged(old_ws, new_ws); inherited::WorkspacesChanged(oldWorkspaces, newWorkspaces);
} }
void void
BDirectWindow::WorkspaceActivated(int32 ws, bool state) BDirectWindow::WorkspaceActivated(int32 index, bool state)
{ {
inherited::WorkspaceActivated(ws, state); inherited::WorkspaceActivated(index, state);
} }
void void
BDirectWindow::FrameResized(float new_width, float new_height) BDirectWindow::FrameResized(float newWidth, float newHeight)
{ {
inherited::FrameResized(new_width, new_height); inherited::FrameResized(newWidth, newHeight);
} }
@@ -179,16 +178,16 @@ BDirectWindow::Minimize(bool minimize)
void void
BDirectWindow::Zoom(BPoint rec_position, float rec_width, float rec_height) BDirectWindow::Zoom(BPoint recPosition, float recWidth, float recHeight)
{ {
inherited::Zoom(rec_position, rec_width, rec_height); inherited::Zoom(recPosition, recWidth, recHeight);
} }
void void
BDirectWindow::ScreenChanged(BRect screen_size, color_space depth) BDirectWindow::ScreenChanged(BRect screenFrame, color_space depth)
{ {
inherited::ScreenChanged(screen_size, depth); inherited::ScreenChanged(screenFrame, depth);
} }
@@ -279,11 +278,11 @@ BDirectWindow::GetClippingRegion(BRegion *region, BPoint *origin) const
if (region == NULL) if (region == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
if (IsLocked() || !LockDirect()) if (IsLocked() || !_LockDirect())
return B_ERROR; return B_ERROR;
if (fInDirectConnect) { if (fInDirectConnect) {
UnlockDirect(); _UnlockDirect();
return B_ERROR; return B_ERROR;
} }
@@ -304,7 +303,7 @@ BDirectWindow::GetClippingRegion(BRegion *region, BPoint *origin) const
// for every clipping_rect in our clip_list, and that would be much // for every clipping_rect in our clip_list, and that would be much
// more overkill than this (tested ). // more overkill than this (tested ).
if (!region->_SetSize(fBufferDesc->clip_list_count)) { if (!region->_SetSize(fBufferDesc->clip_list_count)) {
UnlockDirect(); _UnlockDirect();
return B_NO_MEMORY; return B_NO_MEMORY;
} }
region->fCount = fBufferDesc->clip_list_count; region->fCount = fBufferDesc->clip_list_count;
@@ -318,7 +317,7 @@ BDirectWindow::GetClippingRegion(BRegion *region, BPoint *origin) const
region->OffsetBy(-originX, -originY); region->OffsetBy(-originX, -originY);
#endif #endif
UnlockDirect(); _UnlockDirect();
return B_OK; return B_OK;
@@ -376,14 +375,14 @@ BDirectWindow::SupportsWindowMode(screen_id id)
/* static */ /* static */
int32 int32
BDirectWindow::_DaemonStarter(void *arg) BDirectWindow::_daemon_thread(void *arg)
{ {
return static_cast<BDirectWindow *>(arg)->DirectDaemonFunc(); return static_cast<BDirectWindow *>(arg)->_DirectDaemon();
} }
int32 int32
BDirectWindow::DirectDaemonFunc() BDirectWindow::_DirectDaemon()
{ {
while (!fDaemonKiller) { while (!fDaemonKiller) {
// This sem is released by the app_server when our // This sem is released by the app_server when our
@@ -401,7 +400,7 @@ BDirectWindow::DirectDaemonFunc()
print_direct_buffer_info(*fBufferDesc); print_direct_buffer_info(*fBufferDesc);
#endif #endif
if (LockDirect()) { if (_LockDirect()) {
if ((fBufferDesc->buffer_state & B_DIRECT_MODE_MASK) == B_DIRECT_START) if ((fBufferDesc->buffer_state & B_DIRECT_MODE_MASK) == B_DIRECT_START)
fConnectionEnable = true; fConnectionEnable = true;
@@ -412,7 +411,7 @@ BDirectWindow::DirectDaemonFunc()
if ((fBufferDesc->buffer_state & B_DIRECT_MODE_MASK) == B_DIRECT_STOP) if ((fBufferDesc->buffer_state & B_DIRECT_MODE_MASK) == B_DIRECT_STOP)
fConnectionEnable = false; fConnectionEnable = false;
UnlockDirect(); _UnlockDirect();
} }
// The app_server then waits (with a timeout) on this sem. // The app_server then waits (with a timeout) on this sem.
@@ -428,14 +427,10 @@ BDirectWindow::DirectDaemonFunc()
// LockDirect() and UnlockDirect() are no-op on R5. I tried to call (R5's) LockDirect() // LockDirect() and UnlockDirect() are no-op on R5. I tried to call (R5's) LockDirect()
// repeatedly, from the same thread and from different threads, nothing happened. // repeatedly, from the same thread and from different threads, nothing happened.
// I implemented them anyway, as they were the first methods I wrote
// in this class (As you can see, I even needed to cast away their constness
// to make them do something useful).
// They're not needed though, as the direct_daemon_thread doesn't change // They're not needed though, as the direct_daemon_thread doesn't change
// any shared data. They are probably here for future enhancements (see also the // any shared data. They are probably here for future enhancements
// comment in DriverSetup()
bool bool
BDirectWindow::LockDirect() const BDirectWindow::_LockDirect() const
{ {
status_t status = B_OK; status_t status = B_OK;
@@ -444,7 +439,7 @@ BDirectWindow::LockDirect() const
if (atomic_add(&casted->fDirectLock, 1) > 0) { if (atomic_add(&casted->fDirectLock, 1) > 0) {
do { do {
status = acquire_sem(fDirectSem); status = acquire_sem(casted->fDirectSem);
} while (status == B_INTERRUPTED); } while (status == B_INTERRUPTED);
} }
@@ -459,7 +454,7 @@ BDirectWindow::LockDirect() const
void void
BDirectWindow::UnlockDirect() const BDirectWindow::_UnlockDirect() const
{ {
#if DW_NEEDS_LOCKING #if DW_NEEDS_LOCKING
BDirectWindow *casted = const_cast<BDirectWindow *>(this); BDirectWindow *casted = const_cast<BDirectWindow *>(this);
@@ -473,7 +468,7 @@ BDirectWindow::UnlockDirect() const
void void
BDirectWindow::InitData() BDirectWindow::_InitData()
{ {
fConnectionEnable = false; fConnectionEnable = false;
fIsFullScreen = false; fIsFullScreen = false;
@@ -481,11 +476,6 @@ BDirectWindow::InitData()
fInitStatus = 0; fInitStatus = 0;
fDirectDriverReady = false;
fDirectDriverType = 0;
fDirectDriverToken = 0;
direct_driver = NULL;
status_t status = B_ERROR; status_t status = B_ERROR;
struct direct_window_sync_data syncData; struct direct_window_sync_data syncData;
if (Lock()) { if (Lock()) {
@@ -519,7 +509,7 @@ BDirectWindow::InitData()
if (fClonedClippingArea > 0) { if (fClonedClippingArea > 0) {
fInitStatus |= DW_STATUS_AREA_CLONED; fInitStatus |= DW_STATUS_AREA_CLONED;
fDirectDaemonId = spawn_thread(_DaemonStarter, "direct daemon", fDirectDaemonId = spawn_thread(_daemon_thread, "direct daemon",
B_DISPLAY_PRIORITY, this); B_DISPLAY_PRIORITY, this);
if (fDirectDaemonId > 0) { if (fDirectDaemonId > 0) {
@@ -534,7 +524,7 @@ BDirectWindow::InitData()
void void
BDirectWindow::DisposeData() BDirectWindow::_DisposeData()
{ {
// wait until the connection terminates: we can't destroy // wait until the connection terminates: we can't destroy
// the object until the client receives the B_DIRECT_STOP // the object until the client receives the B_DIRECT_STOP
@@ -542,7 +532,7 @@ BDirectWindow::DisposeData()
while (fConnectionEnable) while (fConnectionEnable)
snooze(50000); snooze(50000);
LockDirect(); _LockDirect();
if (fInitStatus & DW_STATUS_THREAD_STARTED) { if (fInitStatus & DW_STATUS_THREAD_STARTED) {
fDaemonKiller = true; fDaemonKiller = true;
@@ -563,19 +553,6 @@ BDirectWindow::DisposeData()
} }
status_t
BDirectWindow::DriverSetup() const
{
// Unimplemented in R5.
// This function is probably here because they wanted, in a future time,
// to implement graphic acceleration within BDirectWindow
// (in fact, there is also a BDirectDriver member in BDirectWindow,
// though it's not used).
return B_OK;
}
void BDirectWindow::_ReservedDirectWindow1() {} void BDirectWindow::_ReservedDirectWindow1() {}
void BDirectWindow::_ReservedDirectWindow2() {} void BDirectWindow::_ReservedDirectWindow2() {}
void BDirectWindow::_ReservedDirectWindow3() {} void BDirectWindow::_ReservedDirectWindow3() {}