From d9cebac2b77547b7064f22497514eecd2d047160 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Mon, 22 Oct 2007 10:29:44 +0000 Subject: [PATCH] Rewrote DirectWindow.h, updated DirectWindow.cpp accordingly. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22659 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/game/DirectWindow.h | 216 +++++++++++++++------------------ src/kits/game/DirectWindow.cpp | 93 ++++++-------- 2 files changed, 130 insertions(+), 179 deletions(-) diff --git a/headers/os/game/DirectWindow.h b/headers/os/game/DirectWindow.h index 48dcd43517..07579a81d4 100644 --- a/headers/os/game/DirectWindow.h +++ b/headers/os/game/DirectWindow.h @@ -1,23 +1,17 @@ -/******************************************************************************* -// -// File: DirectWindow.h -// -// Description: Client window class for direct screen access. -// -// Copyright 1998, Be Incorporated, All Rights Reserved. -// -*******************************************************************************/ - - +/* + * Copyright 2001-2007, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Stefano Ceccherini + */ #ifndef _DIRECT_WINDOW_H #define _DIRECT_WINDOW_H #include #include -class BDirectDriver; - -/* State of the direct access when called back through DirectConnected */ + enum direct_buffer_state { B_DIRECT_MODE_MASK = 15, @@ -25,151 +19,131 @@ enum direct_buffer_state { B_DIRECT_STOP = 1, B_DIRECT_MODIFY = 2, - B_CLIPPING_MODIFIED = 16, + B_CLIPPING_MODIFIED = 16, B_BUFFER_RESIZED = 32, B_BUFFER_MOVED = 64, B_BUFFER_RESET = 128 }; -/* State of the direct driver and its hooks functions */ + enum direct_driver_state { - B_DRIVER_CHANGED = 0x0001, - B_MODE_CHANGED = 0x0002 + B_DRIVER_CHANGED = 1, + 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 { direct_buffer_state buffer_state; direct_driver_state driver_state; - void *bits; - void *pci_bits; - int32 bytes_per_row; - uint32 bits_per_pixel; - color_space pixel_format; + void *bits; + void *pci_bits; + int32 bytes_per_row; + uint32 bits_per_pixel; + color_space pixel_format; buffer_layout layout; buffer_orientation orientation; - uint32 _reserved[9]; - uint32 _dd_type_; - uint32 _dd_token_; - uint32 clip_list_count; + uint32 _reserved[11]; + uint32 clip_list_count; clipping_rect window_bounds; clipping_rect clip_bounds; clipping_rect clip_list[1]; } direct_buffer_info; -/* BDirectWindow class */ + class BDirectWindow : public BWindow { -public: - BDirectWindow( BRect frame, - const char *title, - window_type type, - uint32 flags, - uint32 workspace = B_CURRENT_WORKSPACE); - BDirectWindow( BRect frame, - const char *title, - window_look look, - window_feel feel, - uint32 flags, - uint32 workspace = B_CURRENT_WORKSPACE); -virtual ~BDirectWindow(); -static BArchivable *Instantiate(BMessage *data); -virtual status_t Archive(BMessage *data, bool deep = true) const; + public: + BDirectWindow(BRect frame, const char *title, window_type type, + uint32 flags, uint32 workspace = B_CURRENT_WORKSPACE); + BDirectWindow(BRect frame, const char *title, window_look look, + window_feel feel, 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(void); -virtual void DispatchMessage(BMessage *message, BHandler *handler); -virtual void MessageReceived(BMessage *message); -virtual void FrameMoved(BPoint new_position); -virtual void WorkspacesChanged(uint32 old_ws, uint32 new_ws); -virtual void WorkspaceActivated(int32 ws, bool state); -virtual void FrameResized(float new_width, float new_height); -virtual void Minimize(bool minimize); -virtual void Zoom( BPoint rec_position, - float rec_width, - float rec_height); -virtual void ScreenChanged(BRect screen_size, color_space depth); -virtual void MenusBeginning(); -virtual void MenusEnded(); -virtual void WindowActivated(bool state); -virtual void Show(); -virtual void Hide(); -virtual BHandler *ResolveSpecifier(BMessage *msg, - int32 index, - BMessage *specifier, - int32 form, - const char *property); -virtual status_t GetSupportedSuites(BMessage *data); -virtual status_t Perform(perform_code d, void *arg); + virtual void Quit(); + virtual void DispatchMessage(BMessage *message, BHandler *handler); + virtual void MessageReceived(BMessage *message); + virtual void FrameMoved(BPoint newPosition); + virtual void WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces); + virtual void WorkspaceActivated(int32 workspaceIndex, bool state); + virtual void FrameResized(float newWidth, float newHeight); + virtual void Minimize(bool minimize); + virtual void Zoom(BPoint recPosition, float recWidth, float recHeight); + virtual void ScreenChanged(BRect screenFrame, color_space depth); + virtual void MenusBeginning(); + virtual void MenusEnded(); + virtual void WindowActivated(bool state); + virtual void Show(); + virtual void Hide(); + virtual BHandler* ResolveSpecifier(BMessage *message, int32 index, + BMessage *specifier, int32 form, + const char *property); + virtual status_t GetSupportedSuites(BMessage *data); + virtual status_t Perform(perform_code code, void *arg); -private: -virtual void task_looper(); -virtual BMessage *ConvertToMessage(void *raw, int32 code); + private: + virtual void task_looper(); + virtual BMessage* ConvertToMessage(void *raw, int32 code); -/* new APIs */ -public: -virtual void DirectConnected(direct_buffer_info *info); + public: + virtual void DirectConnected(direct_buffer_info *info); status_t GetClippingRegion(BRegion *region, BPoint *origin = NULL) const; status_t SetFullScreen(bool enable); 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; -virtual void _ReservedDirectWindow1(); -virtual void _ReservedDirectWindow2(); -virtual void _ReservedDirectWindow3(); -virtual void _ReservedDirectWindow4(); + virtual void _ReservedDirectWindow1(); + virtual void _ReservedDirectWindow2(); + virtual void _ReservedDirectWindow3(); + virtual void _ReservedDirectWindow4(); - BDirectWindow(); BDirectWindow(BDirectWindow &); BDirectWindow &operator=(BDirectWindow &); - bool fDaemonKiller; - bool fConnectionEnable; - bool fIsFullScreen; - bool fDirectDriverReady; - 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 _daemon_thread(void *arg); + int32 _DirectDaemon(); + bool _LockDirect() const; + void _UnlockDirect() const; - static int32 _DaemonStarter(void *arg); - int32 DirectDaemonFunc(); - bool LockDirect() const; - void UnlockDirect() const; - void InitData(); - void DisposeData(); - status_t DriverSetup() const; + void _InitData(); + void _DisposeData(); + + bool fDaemonKiller; + bool fConnectionEnable; + bool fIsFullScreen; + 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 diff --git a/src/kits/game/DirectWindow.cpp b/src/kits/game/DirectWindow.cpp index 461d3c14ca..4a91e56fd5 100644 --- a/src/kits/game/DirectWindow.cpp +++ b/src/kits/game/DirectWindow.cpp @@ -1,13 +1,12 @@ /* - * Copyright 2003-2006, Haiku Inc. + * Copyright 2003-2007, Haiku Inc. * Authors: - * Stefano Ceccherini (burton666@libero.it). - * Carwyn Jones (turok2@currantbun.com) + * Stefano Ceccherini + * Carwyn Jones * * Distributed under the terms of the MIT License. */ - #include #include @@ -89,7 +88,7 @@ BDirectWindow::BDirectWindow(BRect frame, const char *title, window_type type, uint32 flags, uint32 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) : BWindow(frame, title, look, feel, flags, workspace) { - InitData(); + _InitData(); } BDirectWindow::~BDirectWindow() { - DisposeData(); + _DisposeData(); } @@ -144,30 +143,30 @@ BDirectWindow::MessageReceived(BMessage *message) void -BDirectWindow::FrameMoved(BPoint new_position) +BDirectWindow::FrameMoved(BPoint newPosition) { - inherited::FrameMoved(new_position); + inherited::FrameMoved(newPosition); } 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 -BDirectWindow::WorkspaceActivated(int32 ws, bool state) +BDirectWindow::WorkspaceActivated(int32 index, bool state) { - inherited::WorkspaceActivated(ws, state); + inherited::WorkspaceActivated(index, state); } 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 -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 -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) return B_BAD_VALUE; - if (IsLocked() || !LockDirect()) + if (IsLocked() || !_LockDirect()) return B_ERROR; if (fInDirectConnect) { - UnlockDirect(); + _UnlockDirect(); 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 // more overkill than this (tested ). if (!region->_SetSize(fBufferDesc->clip_list_count)) { - UnlockDirect(); + _UnlockDirect(); return B_NO_MEMORY; } region->fCount = fBufferDesc->clip_list_count; @@ -318,7 +317,7 @@ BDirectWindow::GetClippingRegion(BRegion *region, BPoint *origin) const region->OffsetBy(-originX, -originY); #endif - UnlockDirect(); + _UnlockDirect(); return B_OK; @@ -376,14 +375,14 @@ BDirectWindow::SupportsWindowMode(screen_id id) /* static */ int32 -BDirectWindow::_DaemonStarter(void *arg) +BDirectWindow::_daemon_thread(void *arg) { - return static_cast(arg)->DirectDaemonFunc(); + return static_cast(arg)->_DirectDaemon(); } int32 -BDirectWindow::DirectDaemonFunc() +BDirectWindow::_DirectDaemon() { while (!fDaemonKiller) { // This sem is released by the app_server when our @@ -401,7 +400,7 @@ BDirectWindow::DirectDaemonFunc() print_direct_buffer_info(*fBufferDesc); #endif - if (LockDirect()) { + if (_LockDirect()) { if ((fBufferDesc->buffer_state & B_DIRECT_MODE_MASK) == B_DIRECT_START) fConnectionEnable = true; @@ -412,7 +411,7 @@ BDirectWindow::DirectDaemonFunc() if ((fBufferDesc->buffer_state & B_DIRECT_MODE_MASK) == B_DIRECT_STOP) fConnectionEnable = false; - UnlockDirect(); + _UnlockDirect(); } // 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() // 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 -// any shared data. They are probably here for future enhancements (see also the -// comment in DriverSetup() +// any shared data. They are probably here for future enhancements bool -BDirectWindow::LockDirect() const +BDirectWindow::_LockDirect() const { status_t status = B_OK; @@ -444,7 +439,7 @@ BDirectWindow::LockDirect() const if (atomic_add(&casted->fDirectLock, 1) > 0) { do { - status = acquire_sem(fDirectSem); + status = acquire_sem(casted->fDirectSem); } while (status == B_INTERRUPTED); } @@ -459,7 +454,7 @@ BDirectWindow::LockDirect() const void -BDirectWindow::UnlockDirect() const +BDirectWindow::_UnlockDirect() const { #if DW_NEEDS_LOCKING BDirectWindow *casted = const_cast(this); @@ -473,7 +468,7 @@ BDirectWindow::UnlockDirect() const void -BDirectWindow::InitData() +BDirectWindow::_InitData() { fConnectionEnable = false; fIsFullScreen = false; @@ -481,11 +476,6 @@ BDirectWindow::InitData() fInitStatus = 0; - fDirectDriverReady = false; - fDirectDriverType = 0; - fDirectDriverToken = 0; - direct_driver = NULL; - status_t status = B_ERROR; struct direct_window_sync_data syncData; if (Lock()) { @@ -519,7 +509,7 @@ BDirectWindow::InitData() if (fClonedClippingArea > 0) { fInitStatus |= DW_STATUS_AREA_CLONED; - fDirectDaemonId = spawn_thread(_DaemonStarter, "direct daemon", + fDirectDaemonId = spawn_thread(_daemon_thread, "direct daemon", B_DISPLAY_PRIORITY, this); if (fDirectDaemonId > 0) { @@ -534,7 +524,7 @@ BDirectWindow::InitData() void -BDirectWindow::DisposeData() +BDirectWindow::_DisposeData() { // wait until the connection terminates: we can't destroy // the object until the client receives the B_DIRECT_STOP @@ -542,7 +532,7 @@ BDirectWindow::DisposeData() while (fConnectionEnable) snooze(50000); - LockDirect(); + _LockDirect(); if (fInitStatus & DW_STATUS_THREAD_STARTED) { 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::_ReservedDirectWindow2() {} void BDirectWindow::_ReservedDirectWindow3() {}