From 7475dcdf3a736a8e17b0d3fabe970a48661f7d83 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Tue, 7 Jun 2005 21:32:24 +0000 Subject: [PATCH] Added an app server command to retrieve the color map. Made some adjustments to SystemPalette.cpp, implemented support for it in BPrivateScreen. Moved get_scs() a bit down to avoid a deadlock. Note that getting the colormap doesn't work due to port capacity limit (?) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12996 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/app/ServerProtocol.h | 1 + headers/private/servers/app/SystemPalette.h | 5 ++- src/kits/app/Application.cpp | 17 +++----- src/kits/interface/PrivateScreen.cpp | 21 ++++++--- src/servers/app/AppServer.cpp | 4 ++ src/servers/app/RGBColor.cpp | 4 +- src/servers/app/ServerApp.cpp | 24 ++++++++++- src/servers/app/SystemPalette.cpp | 47 +++++++++++++++++---- 8 files changed, 94 insertions(+), 29 deletions(-) diff --git a/headers/private/app/ServerProtocol.h b/headers/private/app/ServerProtocol.h index ecc4b2df9b..24077c7fd6 100644 --- a/headers/private/app/ServerProtocol.h +++ b/headers/private/app/ServerProtocol.h @@ -131,6 +131,7 @@ AS_SET_SYSFONT_FIXED, // Screen methods AS_SCREEN_GET_MODE, AS_SCREEN_SET_MODE, +AS_SCREEN_GET_COLORMAP, // Global function call defs AS_SET_UI_COLORS, diff --git a/headers/private/servers/app/SystemPalette.h b/headers/private/servers/app/SystemPalette.h index 25ee6c8354..967d8b1376 100644 --- a/headers/private/servers/app/SystemPalette.h +++ b/headers/private/servers/app/SystemPalette.h @@ -30,7 +30,8 @@ #include -void GenerateSystemPalette(rgb_color *palette); -extern const rgb_color system_palette[]; +extern void InitializeColorMap(); +extern const rgb_color *SystemPalette(); +extern const color_map *SystemColorMap(); #endif diff --git a/src/kits/app/Application.cpp b/src/kits/app/Application.cpp index 840651e6eb..9e1a337326 100644 --- a/src/kits/app/Application.cpp +++ b/src/kits/app/Application.cpp @@ -420,8 +420,6 @@ DBG(OUT("BApplication::InitData(`%s', %p)\n", signature, _error)); connect_to_app_server(); if (fInitError == B_OK) setup_server_heaps(); - if (fInitError == B_OK) - get_scs(); #endif // RUN_WITHOUT_APP_SERVER // init be_app and be_app_messenger @@ -429,14 +427,7 @@ DBG(OUT("BApplication::InitData(`%s', %p)\n", signature, _error)); be_app = this; be_app_messenger = BMessenger(NULL, this); } - -#ifndef RUN_WITHOUT_APP_SERVER - // Initialize the IK after we have set be_app because of a construction of a - // BAppServerLink (which depends on be_app) nested inside the call to get_menu_info. - if (fInitError == B_OK) - fInitError = _init_interface_kit_(); -#endif // RUN_WITHOUT_APP_SERVER - + // set the BHandler's name if (fInitError == B_OK) SetName(ref.name); @@ -448,6 +439,12 @@ DBG(OUT("BApplication::InitData(`%s', %p)\n", signature, _error)); } #ifndef RUN_WITHOUT_APP_SERVER + // Initialize the IK after we have set be_app because of a construction of a + // BAppServerLink (which depends on be_app) nested inside the call to get_menu_info. + if (fInitError == B_OK) + get_scs(); + if (fInitError == B_OK) + fInitError = _init_interface_kit_(); // create global system cursors // ToDo: these could have a predefined server token to safe the communication! B_CURSOR_SYSTEM_DEFAULT = new BCursor(B_HAND_CURSOR); diff --git a/src/kits/interface/PrivateScreen.cpp b/src/kits/interface/PrivateScreen.cpp index efe0942763..25a19daa69 100644 --- a/src/kits/interface/PrivateScreen.cpp +++ b/src/kits/interface/PrivateScreen.cpp @@ -26,6 +26,7 @@ //------------------------------------------------------------------------------ #include +#include #include #include "AppServerLink.h" @@ -433,11 +434,21 @@ BPrivateScreen::BPrivateScreen() fRetraceSem(-1), fOwnsColorMap(false) { - // TODO: Get a pointer or a copy of the colormap from the app server - // if we only have one screen (one card, one monitor), - // it's better to get only a pointer (with BApplication::ro_offset_to_ptr() ?) - // otherwise every BApplication will keep a copy of the same colormap, - // and we would waste memory for nothing + // TODO: BeOS R5 here gets the colormap pointer + // (with BApplication::ro_offset_to_ptr() ?) + // which is contained in a shared area created by the server. + BAppServerLink link; + link.StartMessage(AS_SCREEN_GET_COLORMAP); + link.Attach(ID()); + int32 reply; + link.FlushWithReply(&reply); + if (reply == SERVER_TRUE) { + fColorMap = (color_map *)malloc(sizeof(color_map)); + fOwnsColorMap = true; + // TODO: This doesn't work. We probably run into a port + // capacity issue ? + //link.Read(fColorMap); + } } diff --git a/src/servers/app/AppServer.cpp b/src/servers/app/AppServer.cpp index 5d11137482..7b75b43d09 100644 --- a/src/servers/app/AppServer.cpp +++ b/src/servers/app/AppServer.cpp @@ -48,6 +48,7 @@ #include "ServerCursor.h" #include "ServerProtocol.h" #include "ServerWindow.h" +#include "SystemPalette.h" #include "Utils.h" #include "AppServer.h" @@ -182,6 +183,9 @@ AppServer::AppServer(void) : gDesktop = new Desktop(); gDesktop->Init(); + // TODO: Maybe this is not the best place for this + InitializeColorMap(); + // Create the bitmap allocator. Object declared in BitmapManager.cpp bitmapmanager = new BitmapManager(); diff --git a/src/servers/app/RGBColor.cpp b/src/servers/app/RGBColor.cpp index 5a43a2590f..a315d61cb8 100644 --- a/src/servers/app/RGBColor.cpp +++ b/src/servers/app/RGBColor.cpp @@ -114,7 +114,7 @@ uint8 RGBColor::GetColor8() const { if(update8) { - color8=FindClosestColor(system_palette, color32); + color8=FindClosestColor(SystemPalette(), color32); update8=false; } @@ -214,7 +214,7 @@ void RGBColor::SetColor(uint16 col16) void RGBColor::SetColor(uint8 col8) { color8=col8; - color32=system_palette[col8]; + color32=SystemPalette()[col8]; update8=false; update16=true; diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index bc3631880d..8dff406aac 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -56,6 +56,7 @@ #include "ServerBitmap.h" #include "ServerPicture.h" #include "ServerConfig.h" +#include "SystemPalette.h" #include "WinBorder.h" #include "LayerData.h" #include "Utils.h" @@ -2028,7 +2029,28 @@ printf("ServerApp %s: AS_SCREEN_GET_MODE\n", fSignature.String()); replylink.Flush(); break; } - + + case AS_SCREEN_GET_COLORMAP: + { + STRACE(("ServerApp %s: AS_SCREEN_GET_COLORMAP\n", fSignature.String())); + + screen_id id; + msg.Read(&id); + + int32 replyport; + msg.Read(&replyport); + + replylink.SetSendPort(replyport); + replylink.StartMessage(SERVER_TRUE); + + // TODO: this doesn't seem to work. + //See also comment in BPrivateScreen::BPrivateScreen() + //replylink.Attach(*SystemColorMap()); + replylink.Flush(); + + break; + } + default: { printf("ServerApp %s received unhandled message code offset %s\n", fSignature.String(), diff --git a/src/servers/app/SystemPalette.cpp b/src/servers/app/SystemPalette.cpp index 785d50f9da..cca88711eb 100644 --- a/src/servers/app/SystemPalette.cpp +++ b/src/servers/app/SystemPalette.cpp @@ -29,13 +29,12 @@ // Local Includes -------------------------------------------------------------- #include "SystemPalette.h" -/*! - \var rgb_color system_palette[256] - \brief The global array of colors for the system palette. - - Whenever the system's color palette is referenced, this is the variable used. -*/ -const rgb_color system_palette[] = { + +// TODO: BWindowScreen has a method to set the palette. +// maybe we should have a lock to protect this variable. +static color_map sColorMap; + +const static rgb_color kSystemPalette[] = { { 0, 0, 0, 255 }, { 8, 8, 8, 255 }, { 16, 16, 16, 255 }, { 24, 24, 24, 255 }, { 32, 32, 32, 255 }, { 40, 40, 40, 255 }, { 48, 48, 48, 255 }, { 56, 56, 56, 255 }, { 64, 64, 64, 255 }, @@ -124,11 +123,13 @@ const rgb_color system_palette[] = { { 255, 255, 255, 255 } }; + /*! \brief Takes a palette array and places the BeOS System palette in it. \param palette 256-element rgb_color array -*/ -void GenerateSystemPalette(rgb_color *palette) +*//* +void +GenerateSystemPalette(rgb_color *palette) { int i,j,index=0; int indexvals1[]={ 255,229,204,179,154,129,105,80,55,30 }, @@ -446,3 +447,31 @@ void GenerateSystemPalette(rgb_color *palette) } } +*/ +static void +FillColorMap(const rgb_color *palette, color_map *map) +{ + memcpy(map->color_list, palette, sizeof(map->color_list)); + // TODO: Inversion map, etc. +} + + +void +InitializeColorMap() +{ + FillColorMap(kSystemPalette, &sColorMap); +} + + +const rgb_color * +SystemPalette() +{ + return sColorMap.color_list; +} + + +const color_map * +SystemColorMap() +{ + return &sColorMap; +}