From 8c86105b9aaf164afd9eb5410d68a3f674cbadf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 20 Mar 2006 23:35:25 +0000 Subject: [PATCH] If you still think this is informative, just have a look in the SVN history :-) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16849 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../old_but_informative/AccelerantDriver.cpp | 1716 ---------- .../old_but_informative/AccelerantDriver.h | 124 - .../old_but_informative/BitmapDriver.cpp | 998 ------ .../old_but_informative/BitmapDriver.h | 110 - .../drawing/old_but_informative/Clipper.cpp | 376 --- .../app/drawing/old_but_informative/Clipper.h | 86 - .../old_but_informative/CursorHandler.cpp | 249 -- .../old_but_informative/CursorHandler.h | 81 - .../old_but_informative/DirectDriver.cpp | 1363 -------- .../old_but_informative/DirectDriver.h | 174 - .../old_but_informative/DisplayDriverImpl.cpp | 2940 ----------------- .../old_but_informative/DisplayDriverImpl.h | 433 --- .../old_but_informative/DisplaySupport.cpp | 473 --- .../old_but_informative/FontManager.cpp | 334 -- .../drawing/old_but_informative/FontManager.h | 73 - .../old_but_informative/GraphicsBuffer.cpp | 97 - .../old_but_informative/GraphicsBuffer.h | 62 - .../old_but_informative/PixelRenderer.cpp | 278 -- .../old_but_informative/PixelRenderer.h | 125 - .../drawing/old_but_informative/RectUtils.cpp | 131 - .../drawing/old_but_informative/RectUtils.h | 38 - .../old_but_informative/ScreenDriver.cpp | 1488 --------- .../old_but_informative/ScreenDriver.h | 201 -- .../old_but_informative/ViewDriver.cpp | 986 ------ .../drawing/old_but_informative/ViewDriver.h | 170 - 25 files changed, 13106 deletions(-) delete mode 100644 src/servers/app/drawing/old_but_informative/AccelerantDriver.cpp delete mode 100644 src/servers/app/drawing/old_but_informative/AccelerantDriver.h delete mode 100644 src/servers/app/drawing/old_but_informative/BitmapDriver.cpp delete mode 100644 src/servers/app/drawing/old_but_informative/BitmapDriver.h delete mode 100644 src/servers/app/drawing/old_but_informative/Clipper.cpp delete mode 100644 src/servers/app/drawing/old_but_informative/Clipper.h delete mode 100644 src/servers/app/drawing/old_but_informative/CursorHandler.cpp delete mode 100644 src/servers/app/drawing/old_but_informative/CursorHandler.h delete mode 100644 src/servers/app/drawing/old_but_informative/DirectDriver.cpp delete mode 100644 src/servers/app/drawing/old_but_informative/DirectDriver.h delete mode 100644 src/servers/app/drawing/old_but_informative/DisplayDriverImpl.cpp delete mode 100644 src/servers/app/drawing/old_but_informative/DisplayDriverImpl.h delete mode 100644 src/servers/app/drawing/old_but_informative/DisplaySupport.cpp delete mode 100644 src/servers/app/drawing/old_but_informative/FontManager.cpp delete mode 100644 src/servers/app/drawing/old_but_informative/FontManager.h delete mode 100644 src/servers/app/drawing/old_but_informative/GraphicsBuffer.cpp delete mode 100644 src/servers/app/drawing/old_but_informative/GraphicsBuffer.h delete mode 100644 src/servers/app/drawing/old_but_informative/PixelRenderer.cpp delete mode 100644 src/servers/app/drawing/old_but_informative/PixelRenderer.h delete mode 100644 src/servers/app/drawing/old_but_informative/RectUtils.cpp delete mode 100644 src/servers/app/drawing/old_but_informative/RectUtils.h delete mode 100644 src/servers/app/drawing/old_but_informative/ScreenDriver.cpp delete mode 100644 src/servers/app/drawing/old_but_informative/ScreenDriver.h delete mode 100644 src/servers/app/drawing/old_but_informative/ViewDriver.cpp delete mode 100644 src/servers/app/drawing/old_but_informative/ViewDriver.h diff --git a/src/servers/app/drawing/old_but_informative/AccelerantDriver.cpp b/src/servers/app/drawing/old_but_informative/AccelerantDriver.cpp deleted file mode 100644 index f24d5186fb..0000000000 --- a/src/servers/app/drawing/old_but_informative/AccelerantDriver.cpp +++ /dev/null @@ -1,1716 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2003, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: AccelerantDriver.cpp -// Author: Gabe Yoder -// Michael Lotz -// Description: A display driver which works directly with the -// accelerant for the graphics card. -// -//------------------------------------------------------------------------------ -#include "AccelerantDriver.h" -#include "Angle.h" -#include "FontFamily.h" -#include "ServerCursor.h" -#include "ServerBitmap.h" -#include "LayerData.h" -#include "PNGDump.h" -#include -#include -#include -#include -#include -#include -#include -#include - -//#define TRACE_ACCELERANT -#ifdef TRACE_ACCELERANT -# include -# define ATRACE(x) printf x -#else -# define ATRACE(x) -#endif - -//#define RUN_UNDER_R5 -//#define DRAW_TEST - -/* TODO: Add handling of draw modes */ - -/*! - \brief Sets up internal variables needed by AccelerantDriver - -*/ -AccelerantDriver::AccelerantDriver() - : DisplayDriverImpl() -{ - cursor=NULL; - under_cursor=NULL; - cursorframe.Set(0,0,0,0); - - card_fd = -1; - accelerant_image = -1; - mode_list = NULL; -} - - -/*! - \brief Deletes the heap memory used by the AccelerantDriver -*/ -AccelerantDriver::~AccelerantDriver() -{ - delete cursor; - delete under_cursor; - free(mode_list); -} - -/*! - \brief Initializes the driver object. - \return true if successful, false if not - - Initialize sets up the driver for display, including the initial clearing - of the screen. If things do not go as they should, false should be returned. -*/ -bool -AccelerantDriver::Initialize() -{ - int i; - char signature[1024]; - char path[PATH_MAX]; - struct stat accelerant_stat; - const static directory_which dirs[] = { - B_USER_ADDONS_DIRECTORY, - B_COMMON_ADDONS_DIRECTORY, - B_BEOS_ADDONS_DIRECTORY - }; - - card_fd = OpenGraphicsDevice(1); - if ( card_fd < 0 ) - { - ATRACE(("Failed to open graphics device\n")); - return false; - } - - if (ioctl(card_fd, B_GET_ACCELERANT_SIGNATURE, &signature, sizeof(signature)) != B_OK) - { - close(card_fd); - return false; - } - ATRACE(("accelerant signature: %s\n", signature)); - - accelerant_image = -1; - for (i=0; i<3; i++) - { - if ( find_directory(dirs[i], -1, false, path, PATH_MAX) != B_OK ) - continue; - - strcat(path,"/accelerants/"); - strcat(path,signature); - if (stat(path, &accelerant_stat) != 0) - continue; - accelerant_image = load_add_on(path); - if (accelerant_image >= 0) - { - if ( get_image_symbol(accelerant_image,B_ACCELERANT_ENTRY_POINT, - B_SYMBOL_TYPE_ANY,(void**)(&accelerant_hook)) != B_OK ) - return false; - - init_accelerant InitAccelerant; - InitAccelerant = (init_accelerant)accelerant_hook(B_INIT_ACCELERANT,NULL); - if (!InitAccelerant || (InitAccelerant(card_fd) != B_OK)) - return false; - break; - } - } - if (accelerant_image < 0) - return false; - - // TODO: Shouldn't these be (re-)moved. They are implemented elsewhere. - accelerant_mode_count GetModeCount = (accelerant_mode_count)accelerant_hook(B_ACCELERANT_MODE_COUNT, NULL); - if ( !GetModeCount ) - return false; - mode_count = GetModeCount(); - if ( !mode_count ) - return false; - get_mode_list GetModeList = (get_mode_list)accelerant_hook(B_GET_MODE_LIST, NULL); - if ( !GetModeList ) - return false; - mode_list = (display_mode *)calloc(sizeof(display_mode), mode_count); - if ( !mode_list ) - return false; - if ( GetModeList(mode_list) != B_OK ) - return false; - -#ifdef RUN_UNDER_R5 - get_display_mode GetDisplayMode = (get_display_mode)accelerant_hook(B_GET_DISPLAY_MODE,NULL); - if ( !GetDisplayMode ) - return false; - if ( GetDisplayMode(&fDisplayMode) != B_OK ) - return false; - SetMode(fDisplayMode); - memcpy(&R5DisplayMode,&fDisplayMode,sizeof(display_mode)); -#else - SetMode(B_8_BIT_640x480); -#endif - - get_frame_buffer_config GetFrameBufferConfig = (get_frame_buffer_config)accelerant_hook(B_GET_FRAME_BUFFER_CONFIG, NULL); - if ( !GetFrameBufferConfig ) - return false; - if ( GetFrameBufferConfig(&mFrameBufferConfig) != B_OK ) - return false; - - AcquireEngine = (acquire_engine)accelerant_hook(B_ACQUIRE_ENGINE,NULL); - ReleaseEngine = (release_engine)accelerant_hook(B_RELEASE_ENGINE,NULL); - accFillRect = (fill_rectangle)accelerant_hook(B_FILL_RECTANGLE,NULL); - accInvertRect = (invert_rectangle)accelerant_hook(B_INVERT_RECTANGLE,NULL); - accSetCursorShape = (set_cursor_shape)accelerant_hook(B_SET_CURSOR_SHAPE,NULL); - accMoveCursor = (move_cursor)accelerant_hook(B_MOVE_CURSOR,NULL); - accShowCursor = (show_cursor)accelerant_hook(B_SHOW_CURSOR,NULL); - accScreenBlit = (screen_to_screen_blit)accelerant_hook(B_SCREEN_TO_SCREEN_BLIT, NULL); - -#ifdef DRAW_TEST - // Commented out to remove a couple warnings -// RGBColor red(255,0,0,0); -// RGBColor green(0,255,0,0); - RGBColor blue(0,0,255,0); - FillRect(BRect(0,0,639,479),blue); -#endif - - return true; -} - -/*! - \brief Shuts down the driver's video subsystem - - Any work done by Initialize() should be undone here. Note that Shutdown() is - called even if Initialize() was unsuccessful. -*/ -void -AccelerantDriver::Shutdown() -{ - if (card_fd < 0) - return; - -#ifdef RUN_UNDER_R5 - set_display_mode SetDisplayMode = (set_display_mode)accelerant_hook(B_SET_DISPLAY_MODE, NULL); - if ( SetDisplayMode ) - SetDisplayMode(&R5DisplayMode); -#endif - uninit_accelerant UninitAccelerant = (uninit_accelerant)accelerant_hook(B_UNINIT_ACCELERANT,NULL); - if ( UninitAccelerant ) - UninitAccelerant(); - if (accelerant_image >= 0) - unload_add_on(accelerant_image); - if (card_fd >= 0) - close(card_fd); -} - -/*! - \brief Draws a series of lines - optimized for speed - \param pts Array of BPoints pairs - \param numlines Number of lines to be drawn - \param d the other 10 billion drawing options -*/ -void AccelerantDriver::StrokeLineArray(const int32 &numlines, const LineArrayData *linedata,const DrawData *d) -{ - if(!d || !linedata) - return; - - int i; - int x1, y1, x2, y2; - const LineArrayData *data; - - Lock(); - for (i=0; ipt1.x); - y1 = ROUND(data->pt1.y); - x2 = ROUND(data->pt2.x); - y2 = ROUND(data->pt2.y); - StrokePatternLine(x1,y1,x2,y2,d); - } - Unlock(); -} - - -/*! - \brief Inverts the colors in the rectangle. - \param r Rectangle of the area to be inverted. Guaranteed to be within bounds. -*/ -void -AccelerantDriver::InvertRect(const BRect &r) -{ - Lock(); - if ( accInvertRect && AcquireEngine && (AcquireEngine(0,0,NULL,&mEngineToken) == B_OK) ) - { - fill_rect_params fillParams; - fillParams.right = (uint16)r.right; - fillParams.left = (uint16)r.left; - fillParams.top = (uint16)r.top; - fillParams.bottom = (uint16)r.bottom; - accInvertRect(mEngineToken, &fillParams, 1); - if ( ReleaseEngine ) - ReleaseEngine(mEngineToken,NULL); - Unlock(); - return; - } - switch (fDisplayMode.space) - { - case B_RGB32_BIG: - case B_RGBA32_BIG: - case B_RGB32_LITTLE: - case B_RGBA32_LITTLE: - { - uint16 width=r.IntegerWidth(); - uint16 height=r.IntegerHeight(); - uint32 *start=(uint32*)mFrameBufferConfig.frame_buffer; - uint32 *index; - start = (uint32 *)((uint8 *)start+(int32)r.top*mFrameBufferConfig.bytes_per_row); - start+=(int32)r.left; - - index = start; - for(int32 i=0;i= 0) - result = acquire_sem_etc(sem, 1, B_RELATIVE_TIMEOUT, timeout); - - Unlock(); - return result; -} - -/*! - \brief Dumps the contents of the frame buffer to a file. - \param path Path and leaf of the file to be created without an extension - \return False if unimplemented or unsuccessful. True if otherwise. - - Subclasses should add an extension based on what kind of file is saved -*/ -bool -AccelerantDriver::DumpToFile(const char *path) -{ -#if 0 - // TODO: find out why this does not work - SaveToPNG( path, - BRect(0, 0, fDisplayMode.virtual_width - 1, fDisplayMode.virtual_height - 1), - (color_space)fDisplayMode.space, - mFrameBufferConfig.frame_buffer, - fDisplayMode.virtual_height * mFrameBufferConfig.bytes_per_row, - mFrameBufferConfig.bytes_per_row);*/ -#else - // TODO: remove this when SaveToPNG works properly - - // this does dump each line at a time to ensure that everything - // gets written even if we crash somewhere. - // it's a bit overkill, but works for now. - FILE *output = fopen(path, "w"); - uint32 row = mFrameBufferConfig.bytes_per_row / 4; - for (int i = 0; i < fDisplayMode.virtual_height; i++) { - fwrite((uint32 *)mFrameBufferConfig.frame_buffer + i * row, 4, row, output); - sync(); - } - fclose(output); - sync(); -#endif - - return true; -} - -bool -AccelerantDriver::AcquireBuffer(FBBitmap *bmp) -{ - if (!bmp) - return false; - - Lock(); - - bmp->SetBytesPerRow(mFrameBufferConfig.bytes_per_row); - bmp->SetSpace((color_space)fDisplayMode.space); - bmp->SetSize(fDisplayMode.virtual_width - 1, fDisplayMode.virtual_height - 1); - bmp->SetBuffer(mFrameBufferConfig.frame_buffer); - bmp->SetBitsPerPixel((color_space)fDisplayMode.space, mFrameBufferConfig.bytes_per_row); - - Unlock(); - return true; -} - -void -AccelerantDriver::ReleaseBuffer(void) -{ - /* TODO: maybe we need to unlock something here? */ -} - -/*! - \brief Copies a bitmap to the screen - \param sourcebmp The bitmap containing the data to blit to the screen - \param sourcerect The rectangle defining the section of the bitmap to blit - \param destrect The rectangle defining the section of the screen to be blitted - \param mode The drawing mode to use when blitting the bitmap - The bitmap and the screen must have the same color depth, or this will do nothing. -*/ -void -AccelerantDriver::BlitBitmap(ServerBitmap *sourcebmp, BRect sourcerect, BRect destrect, drawing_mode mode) -{ - /* TODO: Need to check for hardware support for this. */ - if(!sourcebmp) - return; - - if(sourcebmp->BitsPerPixel() != GetDepthFromColorspace(fDisplayMode.space)) - return; - - uint8 colorspace_size=sourcebmp->BitsPerPixel()/8; - // First, clip source rect to destination - if(sourcerect.Width() > destrect.Width()) - sourcerect.right=sourcerect.left+destrect.Width(); - - - if(sourcerect.Height() > destrect.Height()) - sourcerect.bottom=sourcerect.top+destrect.Height(); - - - // Second, check rectangle bounds against their own bitmaps - BRect work_rect; - - work_rect.Set( sourcebmp->Bounds().left, - sourcebmp->Bounds().top, - sourcebmp->Bounds().right, - sourcebmp->Bounds().bottom ); - if( !(work_rect.Contains(sourcerect)) ) - { // something in selection must be clipped - if(sourcerect.left < 0) - sourcerect.left = 0; - if(sourcerect.right > work_rect.right) - sourcerect.right = work_rect.right; - if(sourcerect.top < 0) - sourcerect.top = 0; - if(sourcerect.bottom > work_rect.bottom) - sourcerect.bottom = work_rect.bottom; - } - - work_rect.Set(0,0,fDisplayMode.virtual_width-1,fDisplayMode.virtual_height-1); - - if( !(work_rect.Contains(destrect)) ) - { // something in selection must be clipped - if(destrect.left < 0) - destrect.left = 0; - if(destrect.right > work_rect.right) - destrect.right = work_rect.right; - if(destrect.top < 0) - destrect.top = 0; - if(destrect.bottom > work_rect.bottom) - destrect.bottom = work_rect.bottom; - } - - // Set pointers to the actual data - uint8 *src_bits = (uint8*) sourcebmp->Bits(); - uint8 *dest_bits = (uint8*) mFrameBufferConfig.frame_buffer; - - // Get row widths for offset looping - uint32 src_width = uint32 (sourcebmp->BytesPerRow()); - uint32 dest_width = uint32 (mFrameBufferConfig.bytes_per_row); - - // Offset bitmap pointers to proper spot in each bitmap - src_bits += uint32 ( (sourcerect.top * src_width) + (sourcerect.left * colorspace_size) ); - dest_bits += uint32 ( (destrect.top * dest_width) + (destrect.left * colorspace_size) ); - - uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size); - uint32 lines = uint32 (destrect.bottom-destrect.top+1); - - switch(mode) - { - case B_OP_OVER: - { - uint32 srow_pixels=src_width>>2; - uint8 *srow_index, *drow_index; - - - // This could later be optimized to use uint32's for faster copying - for (uint32 pos_y=0; pos_y!=lines; pos_y++) - { - - srow_index=src_bits; - drow_index=dest_bits; - - for(uint32 pos_x=0; pos_x!=srow_pixels;pos_x++) - { - // 32-bit RGBA32 mode byte order is BGRA - if(srow_index[3]>127) - { - *drow_index=*srow_index; drow_index++; srow_index++; - *drow_index=*srow_index; drow_index++; srow_index++; - *drow_index=*srow_index; drow_index++; srow_index++; - // we don't copy the alpha channel - drow_index++; srow_index++; - } - else - { - srow_index+=4; - drow_index+=4; - } - } - - // Increment offsets - src_bits += src_width; - dest_bits += dest_width; - } - break; - } - default: // B_OP_COPY - { - for (uint32 pos_y = 0; pos_y != lines; pos_y++) - { - memcpy(dest_bits,src_bits,line_length); - - // Increment offsets - src_bits += src_width; - dest_bits += dest_width; - } - break; - } - } - -} - -/*! - \brief Copies a bitmap to the screen - \param destbmp The bitmap receing the data from the screen - \param destrect The rectangle defining the section of the bitmap to receive data - \param sourcerect The rectangle defining the section of the screen to be copied - The bitmap and the screen must have the same color depth or this will do nothing. -*/ -void -AccelerantDriver::ExtractToBitmap(ServerBitmap *destbmp, BRect destrect, BRect sourcerect) -{ - /* TODO: Need to check for hardware support for this. */ - if(!destbmp) - return; - - if(destbmp->BitsPerPixel() != GetDepthFromColorspace(fDisplayMode.space)) - return; - - uint8 colorspace_size=destbmp->BitsPerPixel()/8; - // First, clip source rect to destination - if(sourcerect.Width() > destrect.Width()) - sourcerect.right=sourcerect.left+destrect.Width(); - - - if(sourcerect.Height() > destrect.Height()) - sourcerect.bottom=sourcerect.top+destrect.Height(); - - - // Second, check rectangle bounds against their own bitmaps - BRect work_rect; - - work_rect.Set( destbmp->Bounds().left, - destbmp->Bounds().top, - destbmp->Bounds().right, - destbmp->Bounds().bottom ); - if( !(work_rect.Contains(destrect)) ) - { // something in selection must be clipped - if(destrect.left < 0) - destrect.left = 0; - if(destrect.right > work_rect.right) - destrect.right = work_rect.right; - if(destrect.top < 0) - destrect.top = 0; - if(destrect.bottom > work_rect.bottom) - destrect.bottom = work_rect.bottom; - } - - work_rect.Set(0,0,fDisplayMode.virtual_width-1,fDisplayMode.virtual_height-1); - - if( !(work_rect.Contains(sourcerect)) ) - { // something in selection must be clipped - if(sourcerect.left < 0) - sourcerect.left = 0; - if(sourcerect.right > work_rect.right) - sourcerect.right = work_rect.right; - if(sourcerect.top < 0) - sourcerect.top = 0; - if(sourcerect.bottom > work_rect.bottom) - sourcerect.bottom = work_rect.bottom; - } - - // Set pointers to the actual data - uint8 *dest_bits = (uint8*) destbmp->Bits(); - uint8 *src_bits = (uint8*) mFrameBufferConfig.frame_buffer; - - // Get row widths for offset looping - uint32 dest_width = uint32 (destbmp->BytesPerRow()); - uint32 src_width = uint32 (mFrameBufferConfig.bytes_per_row); - - // Offset bitmap pointers to proper spot in each bitmap - src_bits += uint32 ( (sourcerect.top * src_width) + (sourcerect.left * colorspace_size) ); - dest_bits += uint32 ( (destrect.top * dest_width) + (destrect.left * colorspace_size) ); - - uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size); - uint32 lines = uint32 (destrect.bottom-destrect.top+1); - - for (uint32 pos_y = 0; pos_y != lines; pos_y++) - { - memcpy(dest_bits,src_bits,line_length); - - // Increment offsets - src_bits += src_width; - dest_bits += dest_width; - } -} - -/*! - \brief Opens a graphics device for read-write access - \param deviceNumber Number identifying which graphics card to open (1 for first card) - \return The file descriptor for the opened graphics device - - The deviceNumber is relative to the number of graphics devices that can be successfully - opened. One represents the first card that can be successfully opened (not necessarily - the first one listed in the directory). -*/ -int -AccelerantDriver::OpenGraphicsDevice(int deviceNumber) -{ - int current_card_fd = -1; - int count = 0; - char path[PATH_MAX]; - DIR *directory; - struct dirent *entry; - - directory = opendir("/dev/graphics"); - if ( !directory ) - return -1; - while ( (count < deviceNumber) && ((entry = readdir(directory)) != NULL) ) - { - if ( !strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..") || - !strcmp(entry->d_name, "stub") ) - continue; - if (current_card_fd >= 0) - { - close(current_card_fd); - current_card_fd = -1; - } - sprintf(path,"/dev/graphics/%s",entry->d_name); - current_card_fd = open(path,B_READ_WRITE); - if ( current_card_fd >= 0 ) - count++; - } - if ( count < deviceNumber ) - { - if ( deviceNumber == 1 ) - { - sprintf(path,"/dev/graphics/stub"); - current_card_fd = open(path,B_READ_WRITE); - } - else - { - close(current_card_fd); - current_card_fd = -1; - } - } - - return current_card_fd; -} - -status_t -AccelerantDriver::GetModeList(display_mode **modes, uint32 *count) -{ - if (!count || !modes) - return B_BAD_VALUE; - - Lock(); - - *modes = new display_mode[mode_count]; - *count = mode_count; - - memcpy(*modes, mode_list, sizeof(display_mode) * mode_count); - - Unlock(); - - return B_OK; -} - -/*! - \brief Determines a display mode constant from display size and depth - \param width The display width - \param height The display height - \param depth The color depth - \return The display mode constant -*/ -int -AccelerantDriver::GetModeFromResolution(int width, int height, int depth) -{ - int mode = 0; - switch (depth) - { - case 8: - switch (width) - { - case 640: - if ( height == 400 ) - mode = B_8_BIT_640x400; - else - mode = B_8_BIT_640x480; - break; - case 800: - mode = B_8_BIT_800x600; - break; - case 1024: - mode = B_8_BIT_1024x768; - break; - case 1152: - mode = B_8_BIT_1152x900; - break; - case 1280: - mode = B_8_BIT_1280x1024; - break; - case 1600: - mode = B_8_BIT_1600x1200; - break; - } - break; - case 15: - switch (width) - { - case 640: - mode = B_15_BIT_640x480; - break; - case 800: - mode = B_15_BIT_800x600; - break; - case 1024: - mode = B_15_BIT_1024x768; - break; - case 1152: - mode = B_15_BIT_1152x900; - break; - case 1280: - mode = B_15_BIT_1280x1024; - break; - case 1600: - mode = B_15_BIT_1600x1200; - break; - } - break; - case 16: - switch (width) - { - case 640: - mode = B_16_BIT_640x480; - break; - case 800: - mode = B_16_BIT_800x600; - break; - case 1024: - mode = B_16_BIT_1024x768; - break; - case 1152: - mode = B_16_BIT_1152x900; - break; - case 1280: - mode = B_16_BIT_1280x1024; - break; - case 1600: - mode = B_16_BIT_1600x1200; - break; - } - break; - case 32: - switch (width) - { - case 640: - mode = B_32_BIT_640x480; - break; - case 800: - mode = B_32_BIT_800x600; - break; - case 1024: - mode = B_32_BIT_1024x768; - break; - case 1152: - mode = B_32_BIT_1152x900; - break; - case 1280: - mode = B_32_BIT_1280x1024; - break; - case 1600: - mode = B_32_BIT_1600x1200; - break; - } - break; - } - return mode; -} - -/*! - \brief Determines the display width from a display mode constant - \param mode The display mode - \return The display height (640, 800, 1024, 1152, 1280, or 1600) -*/ -int -AccelerantDriver::GetWidthFromMode(int mode) -{ - int width=0; - - switch (mode) - { - case B_8_BIT_640x400: - case B_8_BIT_640x480: - case B_15_BIT_640x480: - case B_16_BIT_640x480: - case B_32_BIT_640x480: - width = 640; - break; - case B_8_BIT_800x600: - case B_15_BIT_800x600: - case B_16_BIT_800x600: - case B_32_BIT_800x600: - width = 800; - break; - case B_8_BIT_1024x768: - case B_15_BIT_1024x768: - case B_16_BIT_1024x768: - case B_32_BIT_1024x768: - width = 1024; - break; - case B_8_BIT_1152x900: - case B_15_BIT_1152x900: - case B_16_BIT_1152x900: - case B_32_BIT_1152x900: - width = 1152; - break; - case B_8_BIT_1280x1024: - case B_15_BIT_1280x1024: - case B_16_BIT_1280x1024: - case B_32_BIT_1280x1024: - width = 1280; - break; - case B_8_BIT_1600x1200: - case B_15_BIT_1600x1200: - case B_16_BIT_1600x1200: - case B_32_BIT_1600x1200: - width = 1600; - break; - } - return width; -} - -/*! - \brief Determines the display height from a display mode constant - \param mode The display mode - \return The display height (400, 480, 600, 768, 900, 1024, or 1200) -*/ -int -AccelerantDriver::GetHeightFromMode(int mode) -{ - int height=0; - - switch (mode) - { - case B_8_BIT_640x400: - height = 400; - break; - case B_8_BIT_640x480: - case B_15_BIT_640x480: - case B_16_BIT_640x480: - case B_32_BIT_640x480: - height = 480; - break; - case B_8_BIT_800x600: - case B_15_BIT_800x600: - case B_16_BIT_800x600: - case B_32_BIT_800x600: - height = 600; - break; - case B_8_BIT_1024x768: - case B_15_BIT_1024x768: - case B_16_BIT_1024x768: - case B_32_BIT_1024x768: - height = 768; - break; - case B_8_BIT_1152x900: - case B_15_BIT_1152x900: - case B_16_BIT_1152x900: - case B_32_BIT_1152x900: - height = 900; - break; - case B_8_BIT_1280x1024: - case B_15_BIT_1280x1024: - case B_16_BIT_1280x1024: - case B_32_BIT_1280x1024: - height = 1024; - break; - case B_8_BIT_1600x1200: - case B_15_BIT_1600x1200: - case B_16_BIT_1600x1200: - case B_32_BIT_1600x1200: - height = 1200; - break; - } - return height; -} - -/*! - \brief Determines the color depth from a display mode constant - \param mode The display mode - \return The color depth (8,15,16 or 32) -*/ -int -AccelerantDriver::GetDepthFromMode(int mode) -{ - int depth=0; - - switch (mode) - { - case B_8_BIT_640x400: - case B_8_BIT_640x480: - case B_8_BIT_800x600: - case B_8_BIT_1024x768: - case B_8_BIT_1152x900: - case B_8_BIT_1280x1024: - case B_8_BIT_1600x1200: - depth = 8; - break; - case B_15_BIT_640x480: - case B_15_BIT_800x600: - case B_15_BIT_1024x768: - case B_15_BIT_1152x900: - case B_15_BIT_1280x1024: - case B_15_BIT_1600x1200: - depth = 15; - break; - case B_16_BIT_640x480: - case B_16_BIT_800x600: - case B_16_BIT_1024x768: - case B_16_BIT_1152x900: - case B_16_BIT_1280x1024: - case B_16_BIT_1600x1200: - depth = 16; - break; - case B_32_BIT_640x480: - case B_32_BIT_800x600: - case B_32_BIT_1024x768: - case B_32_BIT_1152x900: - case B_32_BIT_1280x1024: - case B_32_BIT_1600x1200: - depth = 32; - break; - } - return depth; -} - -/*! - \brief Determines the color depth from a color space constant - \param mode The color space constant - \return The color depth (1,8,16 or 32) -*/ -int -AccelerantDriver::GetDepthFromColorspace(int space) -{ - int depth=0; - - switch (space) - { - case B_GRAY1: - depth = 1; - break; - case B_CMAP8: - case B_GRAY8: - depth = 8; - break; - case B_RGB15: - case B_RGBA15: - case B_RGB15_BIG: - case B_RGBA15_BIG: - depth = 15; - break; - case B_RGB16: - case B_RGB16_BIG: - depth = 16; - break; - case B_RGB32: - case B_RGBA32: - case B_RGB24: - case B_RGB32_BIG: - case B_RGBA32_BIG: - case B_RGB24_BIG: - depth = 32; - break; - } - return depth; -} - -void -AccelerantDriver::Blit(const BRect &src, const BRect &dest, const DrawData *d) -{ -#ifndef DISABLE_HARDWARE_ACCELERATION - if (accScreenBlit && AcquireEngine) { - if (AcquireEngine(0, 0, NULL, &mEngineToken) == B_OK) { - blit_params blitParams; - blitParams.src_left = (uint16)src.left; - blitParams.src_top = (uint16)src.top; - blitParams.dest_left = (uint16)dest.left; - blitParams.dest_top = (uint16)dest.top; - blitParams.width = (int16)src.Width() - 1; - blitParams.height = (int16)src.Height() - 1; - - accScreenBlit(mEngineToken, &blitParams, 1); - - if (ReleaseEngine) - ReleaseEngine(mEngineToken, NULL); - - Unlock(); - return; - } - } -#endif -} - -void -AccelerantDriver::FillSolidRect(const BRect &rect, const RGBColor &_color) -{ - RGBColor color = _color; - int32 left = (int32)rect.left; - int32 right = (int32)rect.right; - int32 top = (int32)rect.top; - int32 bottom = (int32)rect.bottom; -#ifndef DISABLE_HARDWARE_ACCELERATION - if (accFillRect && AcquireEngine) - { - if (AcquireEngine(0, 0, NULL, &mEngineToken) == B_OK) - { - fill_rect_params fillParams; - uint32 fill_color = 0; - fillParams.right = (uint16)right; - fillParams.left = (uint16)left; - fillParams.top = (uint16)top; - fillParams.bottom = (uint16)bottom; - switch (fDisplayMode.space) - { - case B_CMAP8: - case B_GRAY8: - fill_color = color.GetColor8(); - break; - case B_RGB15_BIG: - case B_RGBA15_BIG: - case B_RGB15_LITTLE: - case B_RGBA15_LITTLE: - fill_color = color.GetColor15(); - break; - case B_RGB16_BIG: - case B_RGB16_LITTLE: - fill_color = color.GetColor16(); - break; - case B_RGB32_BIG: - case B_RGBA32_BIG: - case B_RGB32_LITTLE: - case B_RGBA32_LITTLE: - { - rgb_color rgbcolor = color.GetColor32(); - fill_color = (rgbcolor.alpha << 24) | (rgbcolor.red << 16) | (rgbcolor.green << 8) | (rgbcolor.blue); - } - break; - } - accFillRect(mEngineToken, fill_color, &fillParams, 1); - if (ReleaseEngine) - ReleaseEngine(mEngineToken, NULL); - Unlock(); - return; - } - } -#endif - - switch (fDisplayMode.space) - { - case B_CMAP8: - case B_GRAY8: - { - uint8 *fb = (uint8 *)mFrameBufferConfig.frame_buffer + top*mFrameBufferConfig.bytes_per_row; - uint8 color8 = color.GetColor8(); - int x,y; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - fb[x] = color8; - fb += mFrameBufferConfig.bytes_per_row; - } - } break; - case B_RGB15_BIG: - case B_RGBA15_BIG: - case B_RGB15_LITTLE: - case B_RGBA15_LITTLE: - { - uint16 *fb = (uint16 *)((uint8 *)mFrameBufferConfig.frame_buffer + top*mFrameBufferConfig.bytes_per_row); - uint16 color15 = color.GetColor15(); - int x,y; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - fb[x] = color15; - fb = (uint16 *)((uint8 *)fb + mFrameBufferConfig.bytes_per_row); - } - } break; - case B_RGB16_BIG: - case B_RGB16_LITTLE: - { - uint16 *fb = (uint16 *)((uint8 *)mFrameBufferConfig.frame_buffer + top*mFrameBufferConfig.bytes_per_row); - uint16 color16 = color.GetColor16(); - int x,y; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - fb[x] = color16; - fb = (uint16 *)((uint8 *)fb + mFrameBufferConfig.bytes_per_row); - } - } break; - case B_RGB32_BIG: - case B_RGBA32_BIG: - case B_RGB32_LITTLE: - case B_RGBA32_LITTLE: - { - uint32 *fb = (uint32 *)((uint8 *)mFrameBufferConfig.frame_buffer + top*mFrameBufferConfig.bytes_per_row); - rgb_color fill_color = color.GetColor32(); - uint32 color32 = (fill_color.alpha << 24) | (fill_color.red << 16) | (fill_color.green << 8) | (fill_color.blue); - int x,y; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - fb[x] = color32; - fb = (uint32 *)((uint8 *)fb + mFrameBufferConfig.bytes_per_row); - } - } break; - default: - printf("Error: Unknown color space\n"); - } -} - -void -AccelerantDriver::FillPatternRect(const BRect &rect, const DrawData *d) -{ - int32 left = (int32)rect.left; - int32 right = (int32)rect.right; - int32 top = (int32)rect.top; - int32 bottom = (int32)rect.bottom; - PatternHandler drawPattern(d->patt); - switch (fDisplayMode.space) - { - case B_CMAP8: - case B_GRAY8: - { - uint8 *fb = (uint8 *)mFrameBufferConfig.frame_buffer + top*mFrameBufferConfig.bytes_per_row; - int x,y; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - fb[x] = drawPattern.ColorAt(x,y).GetColor8(); - fb += mFrameBufferConfig.bytes_per_row; - } - } break; - case B_RGB15_BIG: - case B_RGBA15_BIG: - case B_RGB15_LITTLE: - case B_RGBA15_LITTLE: - { - uint16 *fb = (uint16 *)((uint8 *)mFrameBufferConfig.frame_buffer + top*mFrameBufferConfig.bytes_per_row); - int x,y; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - fb[x] = drawPattern.ColorAt(x,y).GetColor15(); - fb = (uint16 *)((uint8 *)fb + mFrameBufferConfig.bytes_per_row); - } - } break; - case B_RGB16_BIG: - case B_RGB16_LITTLE: - { - uint16 *fb = (uint16 *)((uint8 *)mFrameBufferConfig.frame_buffer + top*mFrameBufferConfig.bytes_per_row); - int x,y; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - fb[x] = drawPattern.ColorAt(x,y).GetColor16(); - fb = (uint16 *)((uint8 *)fb + mFrameBufferConfig.bytes_per_row); - } - } break; - case B_RGB32_BIG: - case B_RGBA32_BIG: - case B_RGB32_LITTLE: - case B_RGBA32_LITTLE: - { - uint32 *fb = (uint32 *)((uint8 *)mFrameBufferConfig.frame_buffer + top*mFrameBufferConfig.bytes_per_row); - int x,y; - rgb_color color; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - { - color = drawPattern.ColorAt(x,y).GetColor32(); - fb[x] = (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue); - } - fb = (uint32 *)((uint8 *)fb + mFrameBufferConfig.bytes_per_row); - } - } break; - default: - printf("Error: Unknown color space\n"); - } -} - -#define BRESENHAM_LOOP(color) { \ - if (steep) \ - fb[x * width + y] = color; \ - else \ - fb[y * width + x] = color; \ - \ - while (x != x2) { \ - x += xstep; \ - error += derror; \ - \ - if (error << 1 >= dx) { \ - y += ystep; \ - error -= dx; \ - } \ - \ - if (steep) \ - fb[x * width + y] = color; \ - else \ - fb[y * width + x] = color; \ - } \ -} - -inline uint32 -rgb_to_32(rgb_color color) -{ - return (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue); -} - -void -AccelerantDriver::StrokeSolidLine(int32 x1, int32 y1, int32 x2, int32 y2, const RGBColor &_color) -{ - RGBColor color = _color; - int32 width = mFrameBufferConfig.bytes_per_row; - - // setup variables for bresenham algorithm - bool steep = abs(y2 - y1) > abs(x2 - x1); - if (steep) { - // swap x1 and y1 - int32 temp = x1; - x1 = y1; - y1 = temp; - - // swap x2 and y2 - temp = x2; - x2 = y2; - y2 = temp; - } - - int32 dx = abs(x2 - x1); - int32 dy = abs(y2 - y1); - int32 error = 0; - int32 derror = dy; - int32 x = x1; - int32 y = y1; - int32 xstep = 1; - int32 ystep = 1; - - if (x1 >= x2) - xstep = -1; - if (y1 >= y2) - ystep = -1; - - switch (fDisplayMode.space) - { - case B_CMAP8: - case B_GRAY8: - { - uint8 *fb = (uint8 *)mFrameBufferConfig.frame_buffer; - uint8 draw_color = color.GetColor8(); - BRESENHAM_LOOP(draw_color); - } break; - case B_RGB15_BIG: - case B_RGBA15_BIG: - case B_RGB15_LITTLE: - case B_RGBA15_LITTLE: - { - uint16 *fb = (uint16 *)mFrameBufferConfig.frame_buffer; - uint16 draw_color = color.GetColor15(); - width >>= 1; - BRESENHAM_LOOP(draw_color); - } break; - case B_RGB16_BIG: - case B_RGB16_LITTLE: - { - uint16 *fb = (uint16 *)mFrameBufferConfig.frame_buffer; - uint16 draw_color = color.GetColor16(); - width >>= 1; - BRESENHAM_LOOP(draw_color); - } break; - case B_RGB32_BIG: - case B_RGBA32_BIG: - case B_RGB32_LITTLE: - case B_RGBA32_LITTLE: - { - uint32 *fb = (uint32 *)mFrameBufferConfig.frame_buffer; - uint32 draw_color = rgb_to_32(color.GetColor32()); - width >>= 2; - BRESENHAM_LOOP(draw_color); - } break; - default: - printf("Error: Unknown color space\n"); - } -} - -void -AccelerantDriver::StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2, const DrawData *d) -{ - PatternHandler drawPattern(d->patt); - int32 width = mFrameBufferConfig.bytes_per_row; - - // setup variables for bresenham algorithm - bool steep = abs(y2 - y1) > abs(x2 - x1); - if (steep) { - // swap x1 and y1 - int32 temp = x1; - x1 = y1; - y1 = temp; - - // swap x2 and y2 - temp = x2; - x2 = y2; - y2 = temp; - } - - int32 dx = abs(x2 - x1); - int32 dy = abs(y2 - y1); - int32 error = 0; - int32 derror = dy; - int32 x = x1; - int32 y = y1; - int32 xstep = 1; - int32 ystep = 1; - - if (x1 >= x2) - xstep = -1; - if (y1 >= y2) - ystep = -1; - - switch (fDisplayMode.space) - { - case B_CMAP8: - case B_GRAY8: - { - uint8 *fb = (uint8 *)mFrameBufferConfig.frame_buffer; - BRESENHAM_LOOP(drawPattern.ColorAt((float)x,(float)y).GetColor8()); - } break; - case B_RGB15_BIG: - case B_RGBA15_BIG: - case B_RGB15_LITTLE: - case B_RGBA15_LITTLE: - { - uint16 *fb = (uint16 *)mFrameBufferConfig.frame_buffer; - width >>= 1; - BRESENHAM_LOOP(drawPattern.ColorAt((float)x,(float)y).GetColor15()); - } break; - case B_RGB16_BIG: - case B_RGB16_LITTLE: - { - uint16 *fb = (uint16 *)mFrameBufferConfig.frame_buffer; - width >>= 1; - BRESENHAM_LOOP(drawPattern.ColorAt((float)x,(float)y).GetColor16()); - } break; - case B_RGB32_BIG: - case B_RGBA32_BIG: - case B_RGB32_LITTLE: - case B_RGBA32_LITTLE: - { - uint32 *fb = (uint32 *)mFrameBufferConfig.frame_buffer; - width >>= 2; - BRESENHAM_LOOP(rgb_to_32(drawPattern.ColorAt((float)x,(float)y).GetColor32())); - } break; - default: - printf("Error: Unknown color space\n"); - } -} - -void -AccelerantDriver::StrokeSolidRect(const BRect &rect, const RGBColor &color) -{ - StrokeSolidLine(rect.left, rect.top, rect.right, rect.top, color); - StrokeSolidLine(rect.left, rect.top, rect.left, rect.bottom, color); - StrokeSolidLine(rect.right, rect.top, rect.right, rect.bottom, color); - StrokeSolidLine(rect.left, rect.bottom, rect.right, rect.bottom, color); -} - -void -AccelerantDriver::CopyBitmap(ServerBitmap *bitmap, const BRect &source, const BRect &dest, const DrawData *d) -{ -} - -void -AccelerantDriver::CopyToBitmap(ServerBitmap *destbmp, const BRect &sourcerect) -{ - /* - if(!destbmp) - { - fprintf(stdout, "CopyToBitmap returned - not init or NULL bitmap\n"); - return; - } - - if(((uint32)destbmp->ColorSpace() & 0x000F) != (_displaymode.space & 0x000F)) - { - fprintf(stdout, "CopyToBitmap returned - unequal buffer pixel depth\n"); - return; - } - - BRect destrect(destbmp->Bounds()), source(sourcerect); - - uint8 colorspace_size=destbmp->BitsPerPixel()/8; - - // First, clip source rect to destination - if(source.Width() > destrect.Width()) - source.right=source.left+destrect.Width(); - - if(source.Height() > destrect.Height()) - source.bottom=source.top+destrect.Height(); - - - // Second, check rectangle bounds against their own bitmaps - BRect work_rect(destbmp->Bounds()); - - if( !(work_rect.Contains(destrect)) ) - { - // something in selection must be clipped - if(destrect.left < 0) - destrect.left = 0; - if(destrect.right > work_rect.right) - destrect.right = work_rect.right; - if(destrect.top < 0) - destrect.top = 0; - if(destrect.bottom > work_rect.bottom) - destrect.bottom = work_rect.bottom; - } - - work_rect.Set(0,0,_displaymode.virtual_width-1,_displaymode.virtual_height-1); - - if(!work_rect.Contains(sourcerect)) - return; - - if( !(work_rect.Contains(source)) ) - { - // something in selection must be clipped - if(source.left < 0) - source.left = 0; - if(source.right > work_rect.right) - source.right = work_rect.right; - if(source.top < 0) - source.top = 0; - if(source.bottom > work_rect.bottom) - source.bottom = work_rect.bottom; - } - - // Set pointers to the actual data - uint8 *dest_bits = (uint8*) destbmp->Bits(); - uint8 *src_bits = (uint8*) _target->Bits(); - - // Get row widths for offset looping - uint32 dest_width = uint32 (destbmp->BytesPerRow()); - uint32 src_width = uint32 (_target->BytesPerRow()); - - // Offset bitmap pointers to proper spot in each bitmap - src_bits += uint32 ( (source.top * src_width) + (source.left * colorspace_size) ); - dest_bits += uint32 ( (destrect.top * dest_width) + (destrect.left * colorspace_size) ); - - - uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size); - uint32 lines = uint32 (source.bottom-source.top+1); - - for (uint32 pos_y=0; pos_y -// Michael Lotz -// Description: A display driver which works directly with the -// accelerant of the graphics card. -// -//------------------------------------------------------------------------------ -#ifndef _ACCELERANTDRIVER_H_ -#define _ACCELERANTDRIVER_H_ - -#include - -#include "PatternHandler.h" -#include "FontServer.h" -#include "LayerData.h" -#include "DisplayDriverImpl.h" - -class ServerBitmap; -class ServerCursor; - -class AccelerantDriver : public DisplayDriverImpl { -public: - AccelerantDriver(); - ~AccelerantDriver(); - -virtual bool Initialize(); -virtual void Shutdown(); - -/* -virtual bool Lock(bigtime_t timeout = B_INFINITE_TIMEOUT); -virtual void Unlock(void); -*/ - -virtual void SetMode(const int32 &mode); -virtual void SetMode(const display_mode &mode); - -virtual bool DumpToFile(const char *path); -virtual void InvertRect(const BRect &r); -virtual void StrokeLineArray(const int32 &numlines, const LineArrayData *linedata,const DrawData *d); - -/* -virtual status_t SetDPMSMode(const uint32 &state); -virtual uint32 DPMSMode() const; -virtual uint32 DPMSCapabilities() const; -*/ - -virtual status_t GetDeviceInfo(accelerant_device_info *info); -virtual status_t GetModeList(display_mode **mode_list, uint32 *count); -virtual status_t GetPixelClockLimits(display_mode *mode, uint32 *low, uint32 *high); -virtual status_t GetTimingConstraints(display_timing_constraints *dtc); -virtual status_t ProposeMode(display_mode *candidate, const display_mode *low, const display_mode *high); -virtual status_t WaitForRetrace(bigtime_t timeout=B_INFINITE_TIMEOUT); - -protected: -virtual bool AcquireBuffer(FBBitmap *bmp); -virtual void ReleaseBuffer(void); - - void BlitBitmap(ServerBitmap *sourcebmp, BRect sourcerect, BRect destrect, drawing_mode mode=B_OP_COPY); - void ExtractToBitmap(ServerBitmap *destbmp, BRect destrect, BRect sourcerect); - rgb_color GetBlitColor(rgb_color src, rgb_color dest, LayerData *d, bool use_high=true); - int OpenGraphicsDevice(int deviceNumber); - int GetModeFromResolution(int width, int height, int space); - int GetWidthFromMode(int mode); - int GetHeightFromMode(int mode); - int GetDepthFromMode(int mode); - int GetDepthFromColorspace(int space); - - // Support functions for the rest of the driver -virtual void Blit(const BRect &src, const BRect &dest, const DrawData *d); -virtual void FillSolidRect(const BRect &rect, const RGBColor &color); -virtual void FillPatternRect(const BRect &rect, const DrawData *d); -virtual void StrokeSolidLine(int32 x1, int32 y1, int32 x2, int32 y2, const RGBColor &color); -virtual void StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2, const DrawData *d); -virtual void StrokeSolidRect(const BRect &rect, const RGBColor &color); -virtual void CopyBitmap(ServerBitmap *bitmap, const BRect &source, const BRect &dest, const DrawData *d); -virtual void CopyToBitmap(ServerBitmap *target, const BRect &source); - - ServerCursor *cursor; - ServerCursor *under_cursor; - BRect cursorframe; - - int card_fd; - image_id accelerant_image; - GetAccelerantHook accelerant_hook; - engine_token *mEngineToken; - acquire_engine AcquireEngine; - release_engine ReleaseEngine; - - // accelerant hooks - fill_rectangle accFillRect; - invert_rectangle accInvertRect; - set_cursor_shape accSetCursorShape; - move_cursor accMoveCursor; - show_cursor accShowCursor; - screen_to_screen_blit accScreenBlit; - - frame_buffer_config mFrameBufferConfig; - int mode_count; - display_mode *mode_list; - display_mode R5DisplayMode; // This should go away once we stop running under r5 -}; - -#endif diff --git a/src/servers/app/drawing/old_but_informative/BitmapDriver.cpp b/src/servers/app/drawing/old_but_informative/BitmapDriver.cpp deleted file mode 100644 index a499dcb3b3..0000000000 --- a/src/servers/app/drawing/old_but_informative/BitmapDriver.cpp +++ /dev/null @@ -1,998 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: BitmapDriver.cpp -// Author: DarkWyrm -// Gabe Yoder -// Description: Driver to draw on ServerBitmaps -// -//------------------------------------------------------------------------------ -#include "Angle.h" -#include "PatternHandler.h" -#include "BitmapDriver.h" -#include "ServerProtocol.h" -#include "ServerBitmap.h" -#include "ServerCursor.h" -#include "ServerConfig.h" -#include "SystemPalette.h" -#include "ColorUtils.h" -#include "PortLink.h" -#include "FontFamily.h" -#include "RGBColor.h" -#include "LayerData.h" -#include -#include -#include -#include -#include - -extern RGBColor workspace_default_color; // defined in AppServer.cpp - -/*! - \brief Sets up internal variables needed by all DisplayDriver subclasses - - Subclasses should follow DisplayDriver's lead and use this function mostly - for initializing data members. -*/ -BitmapDriver::BitmapDriver() - : DisplayDriverImpl(), - // NOTE: fLineThickness appeared to be never - // initialized in DisplayDriver - fLineThickness(1) -{ - fTarget=NULL; - fGraphicsBuffer=NULL; - fPixelRenderer=NULL; -} - -/*! - \brief Deletes the locking semaphore - - Subclasses should use the destructor mostly for freeing allocated heap space. -*/ -BitmapDriver::~BitmapDriver() -{ -} - -void BitmapDriver::SetTarget(ServerBitmap *target) -{ - Lock(); - - if(fGraphicsBuffer) - { - delete fGraphicsBuffer; - fGraphicsBuffer=NULL; - } - - if(fPixelRenderer) - { - delete fPixelRenderer; - fPixelRenderer=NULL; - } - - fTarget=target; - - if(target) - { - fDisplayMode.virtual_width=target->Width(); - fDisplayMode.virtual_height=target->Height(); - fDisplayMode.space=target->ColorSpace(); - - fGraphicsBuffer=new GraphicsBuffer((uint8*)fTarget->Bits(),fTarget->Bounds().Width(), - fTarget->Bounds().Height(),fTarget->BytesPerRow()); - - switch(fTarget->ColorSpace()) - { - case B_RGB32: - case B_RGBA32: - { - fPixelRenderer=new PixelRendererRGBA32(*fGraphicsBuffer); - break; - } - case B_RGB16: - { - fPixelRenderer=new PixelRendererRGB16(*fGraphicsBuffer); - break; - } - case B_RGB15: - case B_RGBA15: - { - fPixelRenderer=new PixelRendererRGBA15(*fGraphicsBuffer); - break; - } - case B_CMAP8: - case B_GRAY8: - { - fPixelRenderer=new PixelRendererCMAP8(*fGraphicsBuffer); - break; - } - default: - break; - } - // Setting mode not necessary. Can get color space stuff via ServerBitmap->ColorSpace - } - - Unlock(); -} - -//! Empty -void BitmapDriver::SetMode(const int32 &space) -{ - // No need to reset a bitmap's color space -} - -//! Empty -void BitmapDriver::SetMode(const display_mode &mode) -{ - // No need to reset a bitmap's color space -} - -void BitmapDriver::InvertRect(const BRect &r) -{ - Lock(); - if(fTarget) - { - if(r.top<0 || r.left<0 || - r.right>fTarget->Width()-1 || r.bottom>fTarget->Height()-1) - { - Unlock(); - return; - } - - switch(fTarget->BitsPerPixel()) - { - case 32: - case 24: - { - uint16 width=r.IntegerWidth(), height=r.IntegerHeight(); - uint32 *start=(uint32*)fTarget->Bits(), *index; - start+=int32(r.top)*fTarget->Width(); - start+=int32(r.left); - - for(int32 i=0;iWidth()); - for(int32 j=0; jdraw_mode) - { - case B_OP_COPY: - { - return src; - } - case B_OP_ADD: - { - value=src.red+dest.red; - returncolor.red=(value>255)?255:value; - - value=src.green+dest.green; - returncolor.green=(value>255)?255:value; - - value=src.blue+dest.blue; - returncolor.blue=(value>255)?255:value; - return returncolor; - } - case B_OP_SUBTRACT: - { - value=src.red-dest.red; - returncolor.red=(value<0)?0:value; - - value=src.green-dest.green; - returncolor.green=(value<0)?0:value; - - value=src.blue-dest.blue; - returncolor.blue=(value<0)?0:value; - return returncolor; - } - case B_OP_BLEND: - { - value=int16(src.red+dest.red)>>1; - returncolor.red=value; - - value=int16(src.green+dest.green)>>1; - returncolor.green=value; - - value=int16(src.blue+dest.blue)>>1; - returncolor.blue=value; - return returncolor; - } - case B_OP_MIN: - { - - return ( uint16(src.red+src.blue+src.green) > - uint16(dest.red+dest.blue+dest.green) )?dest:src; - } - case B_OP_MAX: - { - return ( uint16(src.red+src.blue+src.green) < - uint16(dest.red+dest.blue+dest.green) )?dest:src; - } - case B_OP_OVER: - { - return (use_high && src.alpha>127)?src:dest; - } - case B_OP_INVERT: - { - returncolor.red=dest.red ^ 255; - returncolor.green=dest.green ^ 255; - returncolor.blue=dest.blue ^ 255; - return (use_high && src.alpha>127)?returncolor:dest; - } - // This is a pain in the arse to implement, so I'm saving it for the real - // server - case B_OP_ALPHA: - { - return src; - } - case B_OP_ERASE: - { - // This one's tricky. - return (use_high && src.alpha>127)?d->lowcolor.GetColor32():dest; - } - case B_OP_SELECT: - { - // This one's tricky, too. We are passed a color in src. If it's the layer's - // high color or low color, we check for a swap. - if(d->highcolor==src) - return (use_high && d->highcolor==dest)?d->lowcolor.GetColor32():dest; - - if(d->lowcolor==src) - return (use_high && d->lowcolor==dest)?d->highcolor.GetColor32():dest; - - return dest; - } - default: - { - break; - } - } - Unlock(); - return returncolor; -} - -/*! - \brief Draws a point using the display driver's specified thickness and pattern - \param x The x coordinate (not guaranteed to be in bounds) - \param y The y coordinate (not guaranteed to be in bounds) -*/ -void BitmapDriver::SetThickPatternPixel(int x, int y) -{ - int left, right, top, bottom; - int bytes_per_row = fTarget->BytesPerRow(); - left = x - fLineThickness/2; - right = x + fLineThickness/2; - top = y - fLineThickness/2; - bottom = y + fLineThickness/2; - switch(fTarget->BitsPerPixel()) - { - case 8: - { - int x,y; - uint8 *fb = (uint8 *)fTarget->Bits() + top*bytes_per_row; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - fb[x] = fDrawPattern.ColorAt(x,y).GetColor8(); - fb += bytes_per_row; - } - } break; - case 15: - { - int x,y; - uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + top*bytes_per_row); - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - fb[x] = fDrawPattern.ColorAt(x,y).GetColor15(); - fb = (uint16 *)((uint8 *)fb + bytes_per_row); - } - } break; - case 16: - { - int x,y; - uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + top*bytes_per_row); - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - fb[x] = fDrawPattern.ColorAt(x,y).GetColor16(); - fb = (uint16 *)((uint8 *)fb + bytes_per_row); - } - } break; - case 24: - case 32: - { - int x,y; - uint32 *fb = (uint32 *)((uint8 *)fTarget->Bits() + top*bytes_per_row); - rgb_color color; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - { - color = fDrawPattern.ColorAt(x,y).GetColor32(); - fb[x] = (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue); - } - fb = (uint32 *)((uint8 *)fb + bytes_per_row); - } - } break; - default: - printf("Error: Unknown color space\n"); - } -} - -/*! - \brief Draws a horizontal line using the display driver's line thickness and pattern - \param x1 The first x coordinate (not guaranteed to be in bounds) - \param x2 The second x coordinate (not guaranteed to be in bounds) - \param y The y coordinate (not guaranteed to be in bounds) -*/ -void BitmapDriver::HLinePatternThick(int32 x1, int32 x2, int32 y) -{ - int x, y1, y2; - int bytes_per_row = fTarget->BytesPerRow(); - - if ( x1 > x2 ) - { - x = x2; - x2 = x1; - x1 = x; - } - y1 = y - fLineThickness/2; - y2 = y + fLineThickness/2; - switch(fTarget->BitsPerPixel()) - { - case 8: - { - uint8 *fb = (uint8 *)fTarget->Bits() + y1*bytes_per_row; - for (y=y1; y<=y2; y++) - { - for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.ColorAt(x,y).GetColor8(); - fb += bytes_per_row; - } - } break; - case 15: - { - uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + y1*bytes_per_row); - for (y=y1; y<=y2; y++) - { - for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.ColorAt(x,y).GetColor15(); - fb = (uint16 *)((uint8 *)fb + bytes_per_row); - } - } break; - case 16: - { - uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + y1*bytes_per_row); - for (y=y1; y<=y2; y++) - { - for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.ColorAt(x,y).GetColor16(); - fb = (uint16 *)((uint8 *)fb + bytes_per_row); - } - } break; - case 24: - case 32: - { - uint32 *fb = (uint32 *)((uint8 *)fTarget->Bits() + y1*bytes_per_row); - rgb_color color; - for (y=y1; y<=y2; y++) - { - for (x=x1; x<=x2; x++) - { - color = fDrawPattern.ColorAt(x,y).GetColor32(); - fb[x] = (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue); - } - fb = (uint32 *)((uint8 *)fb + bytes_per_row); - } - } break; - default: - printf("Error: Unknown color space\n"); - } -} - -/*! - \brief Draws a vertical line using the display driver's line thickness and pattern - \param x The x coordinate - \param y1 The first y coordinate - \param y2 The second y coordinate -*/ -void BitmapDriver::VLinePatternThick(int32 x, int32 y1, int32 y2) -{ - int y, x1, x2; - int bytes_per_row = fTarget->BytesPerRow(); - - if ( y1 > y2 ) - { - y = y2; - y2 = y1; - y1 = y; - } - x1 = x - fLineThickness/2; - x2 = x + fLineThickness/2; - switch(fTarget->BitsPerPixel()) - { - case 8: - { - uint8 *fb = (uint8 *)fTarget->Bits() + y1*bytes_per_row; - for (y=y1; y<=y2; y++) - { - for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.ColorAt(x,y).GetColor8(); - fb += bytes_per_row; - } - } break; - case 15: - { - uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + y1*bytes_per_row); - for (y=y1; y<=y2; y++) - { - for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.ColorAt(x,y).GetColor15(); - fb = (uint16 *)((uint8 *)fb + bytes_per_row); - } - } break; - case 16: - { - uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + y1*bytes_per_row); - for (y=y1; y<=y2; y++) - { - for (x=x1; x<=x2; x++) - fb[x] = fDrawPattern.ColorAt(x,y).GetColor16(); - fb = (uint16 *)((uint8 *)fb + bytes_per_row); - } - } break; - case 24: - case 32: - { - uint32 *fb = (uint32 *)((uint8 *)fTarget->Bits() + y1*bytes_per_row); - rgb_color color; - for (y=y1; y<=y2; y++) - { - for (x=x1; x<=x2; x++) - { - color = fDrawPattern.ColorAt(x,y).GetColor32(); - fb[x] = (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue); - } - fb = (uint32 *)((uint8 *)fb + bytes_per_row); - } - } break; - default: - printf("Error: Unknown color space\n"); - } -} - -/* -void BitmapDriver::DrawBitmap(ServerBitmap *sourcebmp, const BRect &source, - const BRect &dest, const DrawData *d) -{ - // Another internal function called from other functions. - - if(!sourcebmp | !d) - return; - - if(sourcebmp->BitsPerPixel() != fTarget->BitsPerPixel()) - return; - - uint8 colorspace_size=sourcebmp->BitsPerPixel()/8; - - BRect sourcerect(source),destrect(dest); - - // First, clip source rect to destination - if(sourcerect.Width() > destrect.Width()) - sourcerect.right=sourcerect.left+destrect.Width(); - - - if(sourcerect.Height() > destrect.Height()) - sourcerect.bottom=sourcerect.top+destrect.Height(); - - - // Second, check rectangle bounds against their own bitmaps - BRect work_rect; - - work_rect=sourcebmp->Bounds(); - - if( !(work_rect.Contains(sourcerect)) ) - { // something in selection must be clipped - if(sourcerect.left < 0) - sourcerect.left = 0; - if(sourcerect.right > work_rect.right) - sourcerect.right = work_rect.right; - if(sourcerect.top < 0) - sourcerect.top = 0; - if(sourcerect.bottom > work_rect.bottom) - sourcerect.bottom = work_rect.bottom; - } - - work_rect.Set(0,0,fTarget->Width()-1,fTarget->Height()-1); - - // Check to see if we actually need to copy anything - if( (destrect.rightwork_rect.right) || - (destrect.bottomwork_rect.bottom) ) - return; - - // something in selection must be clipped - if(destrect.left < 0) - destrect.left = 0; - if(destrect.right > work_rect.right) - destrect.right = work_rect.right; - if(destrect.top < 0) - destrect.top = 0; - if(destrect.bottom > work_rect.bottom) - destrect.bottom = work_rect.bottom; - - // Set pointers to the actual data - uint8 *src_bits = (uint8*) sourcebmp->Bits(); - uint8 *dest_bits = (uint8*) fTarget->Bits(); - - // Get row widths for offset looping - uint32 src_width = uint32 (sourcebmp->BytesPerRow()); - uint32 dest_width = uint32 (fTarget->BytesPerRow()); - - // Offset bitmap pointers to proper spot in each bitmap - src_bits += uint32 ( (sourcerect.top * src_width) + (sourcerect.left * colorspace_size) ); - dest_bits += uint32 ( (destrect.top * dest_width) + (destrect.left * colorspace_size) ); - - uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size); - uint32 lines = uint32 (destrect.bottom-destrect.top+1); - - switch(d->draw_mode) - { - case B_OP_OVER: - { -// uint32 srow_pixels=src_width>>2; - uint32 srow_pixels=((destrect.IntegerWidth()>=sourcerect.IntegerWidth())?src_width:destrect.IntegerWidth()+1)>>2; - uint8 *srow_index, *drow_index; - - - // This could later be optimized to use uint32's for faster copying - for (uint32 pos_y=0; pos_y!=lines; pos_y++) - { - - srow_index=src_bits; - drow_index=dest_bits; - - for(uint32 pos_x=0; pos_x!=srow_pixels;pos_x++) - { - // 32-bit RGBA32 mode byte order is BGRA - if(srow_index[3]>127) - { - *drow_index=*srow_index; drow_index++; srow_index++; - *drow_index=*srow_index; drow_index++; srow_index++; - *drow_index=*srow_index; drow_index++; srow_index++; - // we don't copy the alpha channel - drow_index++; srow_index++; - } - else - { - srow_index+=4; - drow_index+=4; - } - } - - // Increment offsets - src_bits += src_width; - dest_bits += dest_width; - } - break; - } - default: // B_OP_COPY - { - for (uint32 pos_y = 0; pos_y != lines; pos_y++) - { - memcpy(dest_bits,src_bits,line_length); - - // Increment offsets - src_bits += src_width; - dest_bits += dest_width; - } - break; - } - } -}*/ - - -bool BitmapDriver::AcquireBuffer(FBBitmap *fbmp) -{ - if(!fbmp) - return false; - - fbmp->ServerBitmap::ShallowCopy(fTarget); - - return true; -} - -void BitmapDriver::ReleaseBuffer() -{ -} - -void BitmapDriver::Blit(const BRect &src, const BRect &dest, const DrawData *d) -{ -} - -void BitmapDriver::FillSolidRect(const BRect &rect, const RGBColor &color) -{ - int bytes_per_row = fTarget->BytesPerRow(); - int top = (int)rect.top; - int left = (int)rect.left; - int right = (int)rect.right; - int bottom = (int)rect.bottom; - RGBColor col(color); // to avoid GetColor8/15/16() const issues - - switch(fTarget->BitsPerPixel()) - { - case 8: - { - uint8 *fb = (uint8 *)fTarget->Bits() + top*bytes_per_row; - uint8 color8 = col.GetColor8(); - int x,y; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - fb[x] = color8; - fb += bytes_per_row; - } - } break; - case 15: - { - uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + top*bytes_per_row); - uint16 color15 = col.GetColor15(); - int x,y; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - fb[x] = color15; - fb = (uint16 *)((uint8 *)fb + bytes_per_row); - } - } break; - case 16: - { - uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + top*bytes_per_row); - uint16 color16 = col.GetColor16(); - int x,y; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - fb[x] = color16; - fb = (uint16 *)((uint8 *)fb + bytes_per_row); - } - } break; - case 24: - case 32: - { - uint32 *fb = (uint32 *)((uint8 *)fTarget->Bits() + top*bytes_per_row); - rgb_color fill_color = color.GetColor32(); - uint32 color32 = (fill_color.alpha << 24) | (fill_color.red << 16) | (fill_color.green << 8) | (fill_color.blue); - int x,y; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - fb[x] = color32; - fb = (uint32 *)((uint8 *)fb + bytes_per_row); - } - } break; - default: - printf("Error: Unknown color space\n"); - } -} - -void BitmapDriver::FillPatternRect(const BRect &rect, const DrawData *d) -{ - int bytes_per_row = fTarget->BytesPerRow(); - int top = (int)rect.top; - int left = (int)rect.left; - int right = (int)rect.right; - int bottom = (int)rect.bottom; - - switch(fTarget->BitsPerPixel()) - { - case 8: - { - uint8 *fb = (uint8 *)fTarget->Bits() + top*bytes_per_row; - int x,y; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - fb[x] = fDrawPattern.ColorAt(x,y).GetColor8(); - fb += bytes_per_row; - } - } break; - case 15: - { - uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + top*bytes_per_row); - int x,y; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - fb[x] = fDrawPattern.ColorAt(x,y).GetColor15(); - fb = (uint16 *)((uint8 *)fb + bytes_per_row); - } - } break; - case 16: - { - uint16 *fb = (uint16 *)((uint8 *)fTarget->Bits() + top*bytes_per_row); - int x,y; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - fb[x] = fDrawPattern.ColorAt(x,y).GetColor16(); - fb = (uint16 *)((uint8 *)fb + bytes_per_row); - } - } break; - case 24: - case 32: - { - uint32 *fb = (uint32 *)((uint8 *)fTarget->Bits() + top*bytes_per_row); - int x,y; - rgb_color color; - for (y=top; y<=bottom; y++) - { - for (x=left; x<=right; x++) - { - color = fDrawPattern.ColorAt(x,y).GetColor32(); - fb[x] = (color.alpha << 24) | (color.red << 16) | (color.green << 8) | (color.blue); - } - fb = (uint32 *)((uint8 *)fb + bytes_per_row); - } - } break; - default: - printf("Error: Unknown color space\n"); - } -} - -void BitmapDriver::StrokeSolidLine(int32 x1, int32 y1, int32 x2, int32 y2, const RGBColor &color) -{ -} - -void BitmapDriver::StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2, const DrawData *d) -{ -} - -void BitmapDriver::StrokeSolidRect(const BRect &rect, const RGBColor &color) -{ -} - - -/*! - \brief Copy a ServerBitmap to the BitmapDriver's internal ServerBitmap - \param bitmap The ServerBitmap source of the copy - \param sourcerect The source rectangle of the copy - \param dest The destination position of the copy (no scaling occurs) - \param d The DrawData (currently unused) -*/ - -// TODO: dest should really become a BPoint to avoid confusion -// TODO: can we unify CopyBitmap and CopyToBitmap somehow, to avoid the -// near-total code duplication? - -void BitmapDriver::CopyBitmap(ServerBitmap *bitmap, const BRect &sourcerect, const BRect &dest, const DrawData *d) -{ - if(!bitmap) - { - printf("CopyBitmap returned - not init or NULL bitmap\n"); - return; - } - - if(((uint32)bitmap->ColorSpace() & 0x000F) != (fDisplayMode.space & 0x000F)) - { - printf("CopyBitmap returned - unequal buffer pixel depth\n"); - return; - } - - // dest shows position only, not size (i.e. no scaling), so we - // emphasize that point by using the source rect and offsetting it - BRect destrect(sourcerect), source(sourcerect); - destrect.OffsetTo(dest.left, dest.top); - - uint8 colorspace_size=bitmap->BitsPerPixel()/8; - - // First, clip source rect to destination - if(source.Width() > destrect.Width()) - source.right=source.left+destrect.Width(); - - if(source.Height() > destrect.Height()) - source.bottom=source.top+destrect.Height(); - - - // Second, check rectangle bounds against their own bitmaps - BRect work_rect(bitmap->Bounds()); - - // Is there anything at all to copy? - if(!work_rect.Contains(sourcerect)) - return; - - if( !(work_rect.Contains(source)) ) - { - // something in selection must be clipped - if(source.left < 0) - source.left = 0; - if(source.right > work_rect.right) - source.right = work_rect.right; - if(source.top < 0) - source.top = 0; - if(source.bottom > work_rect.bottom) - source.bottom = work_rect.bottom; - } - - work_rect.Set(0,0,fDisplayMode.virtual_width-1,fDisplayMode.virtual_height-1); - - if( !(work_rect.Contains(destrect)) ) - { - // something in selection must be clipped - if(destrect.left < 0) - destrect.left = 0; - if(destrect.right > work_rect.right) - destrect.right = work_rect.right; - if(destrect.top < 0) - destrect.top = 0; - if(destrect.bottom > work_rect.bottom) - destrect.bottom = work_rect.bottom; - } - - // Set pointers to the actual data - uint8 *dest_bits = (uint8*) fTarget->Bits(); - uint8 *src_bits = (uint8*) bitmap->Bits(); - - // Get row widths for offset looping - uint32 dest_width = uint32 (fTarget->BytesPerRow()); - uint32 src_width = uint32 (bitmap->BytesPerRow()); - - // Offset bitmap pointers to proper spot in each bitmap - src_bits += uint32 ( (source.top * src_width) + (source.left * colorspace_size) ); - dest_bits += uint32 ( (destrect.top * dest_width) + (destrect.left * colorspace_size) ); - - - uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size); - uint32 lines = uint32 (destrect.bottom-destrect.top+1); - - for (uint32 pos_y=0; pos_yColorSpace() & 0x000F) != (fDisplayMode.space & 0x000F)) - { - printf("CopyToBitmap returned - unequal buffer pixel depth\n"); - return; - } - - BRect destrect(destbmp->Bounds()), source(sourcerect); - - uint8 colorspace_size=destbmp->BitsPerPixel()/8; - - // First, clip source rect to destination - if(source.Width() > destrect.Width()) - source.right=source.left+destrect.Width(); - - if(source.Height() > destrect.Height()) - source.bottom=source.top+destrect.Height(); - - - // Second, check rectangle bounds against their own bitmaps - BRect work_rect(destbmp->Bounds()); - - if( !(work_rect.Contains(destrect)) ) - { - // something in selection must be clipped - if(destrect.left < 0) - destrect.left = 0; - if(destrect.right > work_rect.right) - destrect.right = work_rect.right; - if(destrect.top < 0) - destrect.top = 0; - if(destrect.bottom > work_rect.bottom) - destrect.bottom = work_rect.bottom; - } - - work_rect.Set(0,0,fDisplayMode.virtual_width-1,fDisplayMode.virtual_height-1); - - // Is there anything at all to copy? - if(!work_rect.Contains(sourcerect)) - return; - - if( !(work_rect.Contains(source)) ) - { - // something in selection must be clipped - if(source.left < 0) - source.left = 0; - if(source.right > work_rect.right) - source.right = work_rect.right; - if(source.top < 0) - source.top = 0; - if(source.bottom > work_rect.bottom) - source.bottom = work_rect.bottom; - } - - // Set pointers to the actual data - uint8 *dest_bits = (uint8*) destbmp->Bits(); - uint8 *src_bits = (uint8*) fTarget->Bits(); - - // Get row widths for offset looping - uint32 dest_width = uint32 (destbmp->BytesPerRow()); - uint32 src_width = uint32 (fTarget->BytesPerRow()); - - // Offset bitmap pointers to proper spot in each bitmap - src_bits += uint32 ( (source.top * src_width) + (source.left * colorspace_size) ); - dest_bits += uint32 ( (destrect.top * dest_width) + (destrect.left * colorspace_size) ); - - - uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size); - uint32 lines = uint32 (source.bottom-source.top+1); - - for (uint32 pos_y=0; pos_y -// -// Description: Driver to draw on ServerBitmaps -// -//------------------------------------------------------------------------------ -#ifndef _BITMAPDRIVER_H_ -#define _BITMAPNDRIVER_H_ - -#include -#include -#include -#include -#include -#include -#include // for clipping_rect definition -#include -#include - -#include "FontServer.h" -#include "GraphicsBuffer.h" -#include "PixelRenderer.h" - -#include "DisplayDriverImpl.h" - -class ServerCursor; -class ServerBitmap; -class RGBColor; -class PatternHandler; - -/*! - \class BitmapDriver BitmapDriver.h - \brief Driver to draw on ServerBitmaps - - This driver is not technically a regular DisplayDriver subclass. BitmapDriver - objects are intended for use when a BBitmap is created with the ability to - accept child views. It also adds one significant function over regular DisplayDriver - child classes - SetTarget. There is also no option for input server emulation, for - obvious reasons. Cursor functions are redefined to do absolutely nothing - - Usage: Allocate and call SetTarget on the desired ServerBitmap and start calling - graphics methods. All ServerBitmap memory belongs to the BitmapManager. -*/ -class BitmapDriver : public DisplayDriverImpl -{ -public: - BitmapDriver(); - ~BitmapDriver(); - - void SetTarget(ServerBitmap *target); - ServerBitmap *GetTarget() const { return fTarget; } - - // Settings functions -// virtual void DrawBitmap(ServerBitmap *bmp, const BRect &src, const BRect &dest, const DrawData *d); - - virtual void SetMode(const int32 &mode); - virtual void SetMode(const display_mode &mode); - virtual void InvertRect(const BRect &rect); -protected: - virtual bool AcquireBuffer(FBBitmap *bmp); - virtual void ReleaseBuffer(); - - virtual void Blit(const BRect &src, const BRect &dest, const DrawData *d); - virtual void FillSolidRect(const BRect &rect, const RGBColor &color); - virtual void FillPatternRect(const BRect &rect, const DrawData *d); - virtual void StrokeSolidLine(int32 x1, int32 y1, int32 x2, int32 y2, const RGBColor &color); - virtual void StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2, const DrawData *d); - virtual void StrokeSolidRect(const BRect &rect, const RGBColor &color); - virtual void CopyBitmap(ServerBitmap *bitmap, const BRect &source, const BRect &dest, const DrawData *d); - virtual void CopyToBitmap(ServerBitmap *target, const BRect &source); - - void ExtractToBitmap(ServerBitmap *destbmp, BRect destrect, BRect sourcerect); - rgb_color GetBlitColor(rgb_color src, rgb_color dest, DrawData *d, bool use_high=true); - void HLinePatternThick(int32 x1, int32 x2, int32 y); - void VLinePatternThick(int32 x, int32 y1, int32 y2); -// void FillSolidRect(int32 left, int32 top, int32 right, int32 bottom); -// void FillPatternRect(int32 left, int32 top, int32 right, int32 bottom); - void SetThickPatternPixel(int x, int y); - - ServerBitmap *fTarget; - GraphicsBuffer *fGraphicsBuffer; - PixelRenderer *fPixelRenderer; - - // NOTE: completely outdated? - int fLineThickness; - PatternHandler fDrawPattern; -}; - -#endif diff --git a/src/servers/app/drawing/old_but_informative/Clipper.cpp b/src/servers/app/drawing/old_but_informative/Clipper.cpp deleted file mode 100644 index 842eb2f5c5..0000000000 --- a/src/servers/app/drawing/old_but_informative/Clipper.cpp +++ /dev/null @@ -1,376 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2003, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: Clipper.cpp -// Author: Gabe Yoder -// Description: A wrapper which translates drawing commands -// into appropriately clipped drawing commands. -// -//------------------------------------------------------------------------------ -#include "Clipper.h" -#include "LayerData.h" - -Clipper::Clipper(DisplayDriver* driver) -{ - fDriver = driver; -} - -Clipper::~Clipper() -{ -} - -void Clipper::DrawBitmap(BRegion* clip_reg, ServerBitmap *bmp, BRect src, BRect dest, LayerData *d) -{ - fDriver->DrawBitmap(bmp,src,dest,d); -} - -void Clipper::DrawString(BRegion* clip_reg, const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *edelta) -{ - fDriver->DrawString(string,length,pt,d,edelta); -} - - - - - - - - -void Clipper::FillArc(const BRect r, float angle, float span, RGBColor& color, BRegion* clip_reg) -{ - fDriver->FillArc(r,angle,span,color); -} - -void Clipper::FillArc(const BRect r, float angle, float span, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg) -{ - fDriver->FillArc(r,angle,span,pattern,high_color,low_color); -} - -void Clipper::FillBezier(BPoint *pts, RGBColor& color, BRegion* clip_reg) -{ - fDriver->FillBezier(pts,color); -} - -void Clipper::FillBezier(BPoint *pts, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg) -{ - fDriver->FillBezier(pts,pattern,high_color,low_color); -} - -void Clipper::FillEllipse(BRect r, RGBColor& color, BRegion* clip_reg) -{ - fDriver->FillEllipse(r,color); -} - -void Clipper::FillEllipse(BRect r, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg) -{ - fDriver->FillEllipse(r,pattern,high_color,low_color); -} - -void Clipper::FillPolygon(BPoint *ptlist, int32 numpts, RGBColor& color, BRegion* clip_reg) -{ - fDriver->FillPolygon(ptlist,numpts,color); -} - -void Clipper::FillPolygon(BPoint *ptlist, int32 numpts, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg) -{ - fDriver->FillPolygon(ptlist,numpts,pattern,high_color,low_color); -} - -void Clipper::FillRect(const BRect r, RGBColor& color, BRegion* clip_reg) -{ - if ( clip_reg ) - { - BRegion reg; - reg.Set(r); - reg.IntersectWith(clip_reg); - fDriver->FillRegion(reg,color); - } - else - fDriver->FillRect(r,color); -} - -void Clipper::FillRect(const BRect r, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg) -{ - if ( clip_reg ) - { - BRegion reg; - reg.Set(r); - reg.IntersectWith(clip_reg); - fDriver->FillRegion(reg,pattern,high_color,low_color); - } - else - fDriver->FillRect(r,pattern,high_color,low_color); -} - -void Clipper::FillRegion(BRegion& r, RGBColor& color, BRegion* clip_reg) -{ - if ( clip_reg ) - { - BRegion reg; - reg = r; - reg.IntersectWith(clip_reg); - fDriver->FillRegion(reg,color); - } - else - fDriver->FillRegion(r,color); -} - -void Clipper::FillRegion(BRegion& r, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg) -{ - if ( clip_reg ) - { - BRegion reg; - reg = r; - reg.IntersectWith(clip_reg); - fDriver->FillRegion(reg,pattern,high_color,low_color); - } - else - fDriver->FillRegion(r,pattern,high_color,low_color); -} - -void Clipper::FillRoundRect(BRect r, float xrad, float yrad, RGBColor& color, BRegion* clip_reg) -{ - if ( !clip_reg ) - fDriver->FillRoundRect(r,xrad,yrad,color); - else - { - BRegion reg(r); - BRect corner_rect(0,0,xrad,yrad); - BRect arc_rect(0,0,2*xrad,2*yrad); - corner_rect.OffsetTo(r.left,r.top); - reg.Exclude(corner_rect); - corner_rect.OffsetTo(r.right-xrad,r.top); - reg.Exclude(corner_rect); - corner_rect.OffsetTo(r.left,r.bottom-yrad); - reg.Exclude(corner_rect); - corner_rect.OffsetTo(r.right-xrad,r.bottom-yrad); - reg.Exclude(corner_rect); - FillRegion(reg,color,clip_reg); - arc_rect.OffsetTo(r.left,r.top); - FillArc(arc_rect,90,90,color,clip_reg); - arc_rect.OffsetTo(r.left,r.bottom-2*yrad); - FillArc(arc_rect,180,90,color,clip_reg); - arc_rect.OffsetTo(r.right-2*xrad,r.bottom-2*yrad); - FillArc(arc_rect,270,90,color,clip_reg); - arc_rect.OffsetTo(r.right-2*xrad,r.top); - FillArc(arc_rect,0,90,color,clip_reg); - } -} - -void Clipper::FillRoundRect(BRect r, float xrad, float yrad, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg) -{ - if ( !clip_reg ) - fDriver->FillRoundRect(r,xrad,yrad,pattern,high_color,low_color); - else - { - BRegion reg(r); - BRect corner_rect(0,0,xrad,yrad); - BRect arc_rect(0,0,2*xrad,2*yrad); - corner_rect.OffsetTo(r.left,r.top); - reg.Exclude(corner_rect); - corner_rect.OffsetTo(r.right-xrad,r.top); - reg.Exclude(corner_rect); - corner_rect.OffsetTo(r.left,r.bottom-yrad); - reg.Exclude(corner_rect); - corner_rect.OffsetTo(r.right-xrad,r.bottom-yrad); - reg.Exclude(corner_rect); - FillRegion(reg,pattern,high_color,low_color,clip_reg); - arc_rect.OffsetTo(r.left,r.top); - FillArc(arc_rect,90,90,pattern,high_color,low_color,clip_reg); - arc_rect.OffsetTo(r.left,r.bottom-2*yrad); - FillArc(arc_rect,180,90,pattern,high_color,low_color,clip_reg); - arc_rect.OffsetTo(r.right-2*xrad,r.bottom-2*yrad); - FillArc(arc_rect,270,90,pattern,high_color,low_color,clip_reg); - arc_rect.OffsetTo(r.right-2*xrad,r.top); - FillArc(arc_rect,0,90,pattern,high_color,low_color,clip_reg); - } -} - -void Clipper::FillTriangle(BPoint *pts, RGBColor& color, BRegion* clip_reg) -{ - fDriver->FillTriangle(pts,color); -} - -void Clipper::FillTriangle(BPoint *pts, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg) -{ - fDriver->FillTriangle(pts,pattern,high_color,low_color); -} - -void Clipper::StrokeArc(BRect r, float angle, float span, float pensize, RGBColor& color, BRegion* clip_reg) -{ - fDriver->StrokeArc(r,angle,span,pensize,color); -} - -void Clipper::StrokeArc(BRect r, float angle, float span, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg) -{ - fDriver->StrokeArc(r,angle,span,pensize,pattern,high_color,low_color); -} - -void Clipper::StrokeBezier(BPoint *pts, float pensize, RGBColor& color, BRegion* clip_reg) -{ - fDriver->StrokeBezier(pts,pensize,color); -} - -void Clipper::StrokeBezier(BPoint *pts, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg) -{ - fDriver->StrokeBezier(pts,pensize,pattern,high_color,low_color); -} - -void Clipper::StrokeEllipse(BRect r, float pensize, RGBColor& color, BRegion* clip_reg) -{ - fDriver->StrokeEllipse(r,pensize,color); -} - -void Clipper::StrokeEllipse(BRect r, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg) -{ - fDriver->StrokeEllipse(r,pensize,pattern,high_color,low_color); -} - -void Clipper::StrokeLine(BPoint start, BPoint end, float pensize, RGBColor& color, BRegion* clip_reg) -{ - if ( clip_reg ) - { - int i; - BRect currentRect; - LineCalc line(start,end); - BRect lineBounds(line.MinX(),line.MinY(),line.MaxX(),line.MaxY()); - for (i=0; iCountRects(); i++) - { - currentRect = clip_reg->RectAt(i); - if ( currentRect.Intersects(lineBounds) ) - { - if ( currentRect.Contains(start) && currentRect.Contains(end) ) - { - fDriver->StrokeLine(start,end,pensize,color); - return; - } - if ( line.ClipToRect(currentRect) ) - { - fDriver->StrokeLine(line.GetStart(),line.GetEnd(),pensize,color); - line.SetPoints(start,end); - } - } - } - } - else - fDriver->StrokeLine(start,end,pensize,color); -} - -void Clipper::StrokeLine(BPoint start, BPoint end, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg) -{ - if ( clip_reg ) - { - int i; - BRect currentRect; - LineCalc line(start,end); - BRect lineBounds(line.MinX(),line.MinY(),line.MaxX(),line.MaxY()); - for (i=0; iCountRects(); i++) - { - currentRect = clip_reg->RectAt(i); - if ( currentRect.Intersects(lineBounds) ) - { - if ( currentRect.Contains(start) && currentRect.Contains(end) ) - { - fDriver->StrokeLine(start,end,pensize,pattern,high_color,low_color); - return; - } - if ( line.ClipToRect(currentRect) ) - { - fDriver->StrokeLine(line.GetStart(),line.GetEnd(),pensize,pattern,high_color,low_color); - line.SetPoints(start,end); - } - } - } - } - else - fDriver->StrokeLine(start,end,pensize,pattern,high_color,low_color); -} - -void Clipper::StrokePolygon(BPoint *ptlist, int32 numpts, float pensize, RGBColor& color, bool is_closed, BRegion* clip_reg) -{ - fDriver->StrokePolygon(ptlist,numpts,pensize,color,is_closed); -} - -void Clipper::StrokePolygon(BPoint *ptlist, int32 numpts, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, bool is_closed, BRegion* clip_reg) -{ - fDriver->StrokePolygon(ptlist,numpts,pensize,pattern,high_color,low_color,is_closed); -} - -void Clipper::StrokeRect(BRect r, float pensize, RGBColor& color, BRegion* clip_reg) -{ - if ( clip_reg ) - { - StrokeLine(r.LeftTop(), r.RightTop(), pensize, color, clip_reg); - StrokeLine(r.LeftTop(), r.LeftBottom(), pensize, color, clip_reg); - StrokeLine(r.RightTop(), r.RightBottom(), pensize, color, clip_reg); - StrokeLine(r.LeftBottom(), r.RightBottom(), pensize, color, clip_reg); - } - else - fDriver->StrokeRect(r,pensize,color); -} - -void Clipper::StrokeRect(BRect r, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg) -{ - if ( clip_reg ) - { - StrokeLine(r.LeftTop(), r.RightTop(), pensize, pattern, high_color, low_color, clip_reg); - StrokeLine(r.LeftTop(), r.LeftBottom(), pensize, pattern, high_color, low_color, clip_reg); - StrokeLine(r.RightTop(), r.RightBottom(), pensize, pattern, high_color, low_color, clip_reg); - StrokeLine(r.LeftBottom(), r.RightBottom(), pensize, pattern, high_color, low_color, clip_reg); - } - else - fDriver->StrokeRect(r,pensize,pattern,high_color,low_color); -} - -void Clipper::StrokeRegion(BRegion& r, float pensize, RGBColor& color, BRegion* clip_reg) -{ - fDriver->StrokeRegion(r,pensize,color); -} - -void Clipper::StrokeRegion(BRegion& r, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg) -{ - fDriver->StrokeRegion(r,pensize,pattern,high_color,low_color); -} - -void Clipper::StrokeRoundRect(BRect r, float xrad, float yrad, float pensize, RGBColor& color, BRegion* clip_reg) -{ - fDriver->StrokeRoundRect(r,xrad,yrad,pensize,color); -} - -void Clipper::StrokeRoundRect(BRect r, float xrad, float yrad, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg) -{ - fDriver->StrokeRoundRect(r,xrad,yrad,pensize,pattern,high_color,low_color); -} - -void Clipper::StrokeTriangle(BPoint *pts, float pensize, RGBColor& color, BRegion* clip_reg) -{ - fDriver->StrokeTriangle(pts,pensize,color); -} - -void Clipper::StrokeTriangle(BPoint *pts, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg) -{ - fDriver->StrokeTriangle(pts,pensize,pattern,high_color,low_color); -} - -void Clipper::StrokeLineArray(BPoint *pts, int32 numlines, float pensize, RGBColor *colors, BRegion* clip_reg) -{ - fDriver->StrokeLineArray(pts,numlines,pensize,colors); -} diff --git a/src/servers/app/drawing/old_but_informative/Clipper.h b/src/servers/app/drawing/old_but_informative/Clipper.h deleted file mode 100644 index 1ccbb04e18..0000000000 --- a/src/servers/app/drawing/old_but_informative/Clipper.h +++ /dev/null @@ -1,86 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2003, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: Clipper.h -// Author: Gabe Yoder -// Description: A wrapper which translates drawing commands -// into appropriately clipped drawing commands. -// -//------------------------------------------------------------------------------ -#ifndef _CLIPPER_H_ -#define _CLIPPER_H_ - -#include "DisplayDriver.h" -#include "Region.h" -#include "Picture.h" - -class Clipper -{ -public: - Clipper(DisplayDriver* driver); - ~Clipper(); - - void DrawBitmap(BRegion* clip_reg, ServerBitmap *bmp, BRect src, BRect dest, LayerData *d); - void DrawString(BRegion* clip_reg, const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *edelta=NULL); - - - void FillArc(const BRect r, float angle, float span, RGBColor& color, BRegion* clip_reg=NULL); - void FillArc(const BRect r, float angle, float span, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL); - void FillBezier(BPoint *pts, RGBColor& color, BRegion* clip_reg=NULL); - void FillBezier(BPoint *pts, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL); - void FillEllipse(BRect r, RGBColor& color, BRegion* clip_reg=NULL); - void FillEllipse(BRect r, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL); - void FillPolygon(BPoint *ptlist, int32 numpts, RGBColor& color, BRegion* clip_reg=NULL); - void FillPolygon(BPoint *ptlist, int32 numpts, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL); - void FillRect(const BRect r, RGBColor& color, BRegion* clip_reg=NULL); - void FillRect(const BRect r, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL); - void FillRegion(BRegion& r, RGBColor& color, BRegion* clip_reg=NULL); - void FillRegion(BRegion& r, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL); - void FillRoundRect(BRect r, float xrad, float yrad, RGBColor& color, BRegion* clip_reg=NULL); - void FillRoundRect(BRect r, float xrad, float yrad, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL); - void FillTriangle(BPoint *pts, RGBColor& color, BRegion* clip_reg=NULL); - void FillTriangle(BPoint *pts, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL); - - void StrokeArc(BRect r, float angle, float span, float pensize, RGBColor& color, BRegion* clip_reg=NULL); - void StrokeArc(BRect r, float angle, float span, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL); - void StrokeBezier(BPoint *pts, float pensize, RGBColor& color, BRegion* clip_reg=NULL); - void StrokeBezier(BPoint *pts, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL); - void StrokeEllipse(BRect r, float pensize, RGBColor& color, BRegion* clip_reg=NULL); - void StrokeEllipse(BRect r, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL); - void StrokeLine(BPoint start, BPoint end, float pensize, RGBColor& color, BRegion* clip_reg=NULL); - void StrokeLine(BPoint start, BPoint end, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL); - void StrokePolygon(BPoint *ptlist, int32 numpts, float pensize, RGBColor& color, bool is_closed=true, BRegion* clip_reg=NULL); - void StrokePolygon(BPoint *ptlist, int32 numpts, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, bool is_closed=true, BRegion* clip_reg=NULL); - void StrokeRect(BRect r, float pensize, RGBColor& color, BRegion* clip_reg=NULL); - void StrokeRect(BRect r, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL); - void StrokeRegion(BRegion& r, float pensize, RGBColor& color, BRegion* clip_reg=NULL); - void StrokeRegion(BRegion& r, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL); - void StrokeRoundRect(BRect r, float xrad, float yrad, float pensize, RGBColor& color, BRegion* clip_reg=NULL); - void StrokeRoundRect(BRect r, float xrad, float yrad, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL); - void StrokeTriangle(BPoint *pts, float pensize, RGBColor& color, BRegion* clip_reg=NULL); - void StrokeTriangle(BPoint *pts, float pensize, const Pattern& pattern, RGBColor& high_color, RGBColor& low_color, BRegion* clip_reg=NULL); - - void StrokeLineArray(BPoint *pts, int32 numlines, float pensize, RGBColor *colors, BRegion* clip_reg=NULL); -private: - DisplayDriver* fDriver; -}; - -#endif diff --git a/src/servers/app/drawing/old_but_informative/CursorHandler.cpp b/src/servers/app/drawing/old_but_informative/CursorHandler.cpp deleted file mode 100644 index 4ced7f740c..0000000000 --- a/src/servers/app/drawing/old_but_informative/CursorHandler.cpp +++ /dev/null @@ -1,249 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: CursorHandler.cpp -// Author: DarkWyrm -// Description: class for handling cursor display for DisplayDriver -// -//------------------------------------------------------------------------------ -#include "CursorHandler.h" -#include "DisplayDriver.h" -#include "RectUtils.h" - -CursorHandler::CursorHandler(DisplayDriver *driver) - : fDriver(driver), - fOldPosition(0,0,0,0), - fPosition(0,0,0,0), - fCursorPos(0,0), - fSavedData(NULL), - fCursor(NULL), - fHideLevel(0), - fDrawData(), - fDriverHidden(false), - fIsObscured(false), - fValidSaveData(false) -{ -} - -//! Frees any memory used for saving screen data -CursorHandler::~CursorHandler(void) -{ - delete fSavedData; -} - -/*! - \brief Tests to see if the passed rectangle intersects the cursor's current position - \param r The rectangle to test against - \return true if r intersects the cursor's current screen footprint -*/ -bool CursorHandler::IntersectsCursor(const BRect &r) -{ - return TestRectIntersection(r, fPosition); -} - -void CursorHandler::SetCursor(ServerCursor *cursor) -{ - // we may start empty, but we will never need to stay that way - if(!cursor) - return; - - Hide(); - - if(fSavedData && cursor->Bounds()!=fSavedData->Bounds()) - { - delete fSavedData; - fSavedData=NULL; - } - - if(!fSavedData) - fSavedData=new UtilityBitmap(cursor); - - fCursor=cursor; - - // We change the position rectangles to reflect the new cursor, compensating for the - // new cursor's hotspot. - fPosition=cursor->Bounds().OffsetToCopy(fCursorPos.x-fCursor->GetHotSpot().x, - fCursorPos.y-fCursor->GetHotSpot().y); - fOldPosition=fPosition; - - Show(); -} - -/*! - \brief Moves the cursor to the specified place on screen - \param pt The new cursor location - - This function fails if asked to move the cursor outside the screen boundaries -*/ -void CursorHandler::MoveTo(BPoint pt) -{ - pt.x = max_c(pt.x, 0.0); - pt.y = max_c(pt.y, 0.0); - pt.x = min_c(pt.x, fDriver->DisplayMode()->virtual_width - 1); - pt.y = min_c(pt.y, fDriver->DisplayMode()->virtual_height - 1); - - if (fCursorPos != pt) { - - fCursorPos=pt; - - if (!fSavedData) - debugger("NULL savedata\n"); - - fDriver->CopyBitmap(fSavedData,fSavedData->Bounds(),fOldPosition,&fDrawData); - fPosition.OffsetTo(fCursorPos.x-fCursor->GetHotSpot().x, - fCursorPos.y-fCursor->GetHotSpot().y); - fDriver->CopyToBitmap(fSavedData,fPosition); - - fDrawData.draw_mode=B_OP_ALPHA; - fDriver->CopyBitmap(fCursor,fCursor->Bounds(),fPosition,&fDrawData); - fDrawData.draw_mode=B_OP_COPY; - - fDriver->Invalidate(fOldPosition); - fOldPosition=fPosition; - - fDriver->Invalidate(fPosition); - } -} - -//! Shows the cursor. Unlike BView, calls are not cumulative -void CursorHandler::Show(void) -{ - // This call is pretty simple -- save the area underneath the cursor and draw the thing - - if (fHideLevel == 0) - return; - - fIsObscured = false; - fHideLevel--; - - if (fHideLevel > 0) - return; - - fOldPosition = fPosition; - - if (!fCursor) - return; - - fValidSaveData = true; - - if (!fSavedData) - fSavedData = new UtilityBitmap(fCursor->Bounds(), - (color_space)fDriver->DisplayMode()->space, 0); - - fDriver->CopyToBitmap(fSavedData, fPosition); - - // Draw the data to the buffer - fDrawData.draw_mode = B_OP_ALPHA; - fDriver->CopyBitmap(fCursor, fCursor->Bounds(), fPosition, &fDrawData); - fDrawData.draw_mode = B_OP_COPY; - fDriver->Invalidate(fPosition); -} - -//! Hides the cursor. Unlike BView, calls are not cumulative -void CursorHandler::Hide(void) -{ - fHideLevel++; - - // TODO: find out what the behavior is if a Hide is called on an obscured cursor - - // For now, we will change the state from obscured to hidden and leave it at that - if(fIsObscured) - { - fIsObscured=false; - return; - } - - if(fHideLevel>1) - return; - - if(!fCursor) - return; - - if(!fSavedData) - fSavedData=new UtilityBitmap(fCursor); - - fDriver->CopyBitmap(fSavedData,fSavedData->Bounds(),fOldPosition,&fDrawData); - fDriver->Invalidate(fPosition); -} - -//! Hides the cursor until the next MoveTo call. Unlike BView, calls are not cumulative -void CursorHandler::Obscure(void) -{ - if(IsObscured()) - return; - - fIsObscured=true; - - // TODO: find out what the behavior is if an Obscure is called on a hidden cursor - - // For now, we will change the state from obscured to hidden and leave it at that - if(fHideLevel>0) - { - fHideLevel=0; - return; - } - - fDriver->CopyBitmap(fSavedData,fSavedData->Bounds(),fOldPosition,&fDrawData); - fDriver->Invalidate(fPosition); -} - -void CursorHandler::DriverHide(void) -{ - if(fDriverHidden) - return; - - fDriverHidden=true; - - if(!fCursor) - return; - - if(!fSavedData) - fSavedData=new UtilityBitmap(fCursor); - - fDriver->CopyBitmap(fSavedData,fSavedData->Bounds(),fOldPosition,&fDrawData); - fDriver->Invalidate(fPosition); -} - -void CursorHandler::DriverShow(void) -{ - if(!fDriverHidden) - return; - - fDriverHidden=false; - - fOldPosition=fPosition; - - if(!fCursor) - return; - - fValidSaveData=true; - - if(!fSavedData) - fSavedData=new UtilityBitmap(fCursor->Bounds(),(color_space)fDriver->DisplayMode()->space,0); - - fDriver->CopyToBitmap(fSavedData,fPosition); - - // Draw the data to the buffer - fDrawData.draw_mode=B_OP_ALPHA; - fDriver->CopyBitmap(fCursor,fCursor->Bounds(),fPosition,&fDrawData); - fDrawData.draw_mode=B_OP_COPY; - fDriver->Invalidate(fPosition); -} diff --git a/src/servers/app/drawing/old_but_informative/CursorHandler.h b/src/servers/app/drawing/old_but_informative/CursorHandler.h deleted file mode 100644 index 7df8faab16..0000000000 --- a/src/servers/app/drawing/old_but_informative/CursorHandler.h +++ /dev/null @@ -1,81 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: CursorHandler.h -// Author: DarkWyrm -// Description: class for handling cursor display for DisplayDriver -// -//------------------------------------------------------------------------------ -#ifndef CURSORHANDLER_H -#define CURSORHANDLER_H - -#include "GraphicsBuffer.h" -#include "LayerData.h" -#include "ServerCursor.h" -#include "ServerBitmap.h" - -class DisplayDriver; - -/*! - \class CursorHandler CursorHandler.h - \brief Object used by DisplayDriver to handle all the messiness of displaying the cursor -*/ -class CursorHandler -{ -public: - CursorHandler(DisplayDriver *driver); - ~CursorHandler(void); - - bool IntersectsCursor(const BRect &r); - - void SetCursor(ServerCursor *cursor); - ServerCursor *GetCursor(void) const { return fCursor; } - - void MoveTo(BPoint pt); - BPoint GetPosition(void) const { return fPosition.LeftTop(); } - - void Hide(void); - void Show(void); - void Obscure(void); - bool IsHidden(void) const { return (fHideLevel>0); } - bool IsObscured(void) const { return fIsObscured; } - - void DriverHide(void); - void DriverShow(void); -private: - - DisplayDriver *fDriver; - - BRect fOldPosition; - BRect fPosition; - BPoint fCursorPos; - - UtilityBitmap *fSavedData; - ServerCursor *fCursor; - int8 fHideLevel; - DrawData fDrawData; - - bool fDriverHidden; - bool fIsObscured; - bool fValidSaveData; -}; - -#endif diff --git a/src/servers/app/drawing/old_but_informative/DirectDriver.cpp b/src/servers/app/drawing/old_but_informative/DirectDriver.cpp deleted file mode 100644 index fad507fd6a..0000000000 --- a/src/servers/app/drawing/old_but_informative/DirectDriver.cpp +++ /dev/null @@ -1,1363 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: DirectDriver.h -// Author: DarkWyrm -// -// Description: BDirectWindow graphics module -// -//------------------------------------------------------------------------------ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Angle.h" -#include "PortLink.h" -#include "RectUtils.h" -#include "ServerProtocol.h" -#include "ServerBitmap.h" -#include "DirectDriver.h" -#include "ServerConfig.h" -#include "ServerCursor.h" -#include "ServerFont.h" -#include "FontFamily.h" -#include "LayerData.h" -#include "PNGDump.h" - -//#define DEBUG_DRIVER_ALL - -#ifdef DEBUG_DRIVER_ALL -# include -# define ATRACE(x) printf x -# define STRACE(x) printf x -# define DTRACE(x) printf x -#else -# define ATRACE(x) ; -#endif - - -//#define DEBUG_DRIVER_MODULE - -#ifdef DEBUG_DRIVER_MODULE -# include -# define STRACE(x) printf x -#else -# ifndef STRACE -# define STRACE(x) ; -# endif -#endif - -//#define DEBUG_DRIVER_THREAD - -#ifdef DEBUG_DRIVER_THREAD -# include -# define DTRACE(x) printf x -#else -# ifndef DTRACE -# define DTRACE(x) ; -# endif -#endif - -extern RGBColor workspace_default_color; - - -/* --------------------------------------------------------------------------------------- - DW's NOTES: - - The current state of the driver still operates somewhat like ViewDriver in that it - still uses the app_server to draw on the BBitmap. The advantage to this temporary - state is that the driver can be quickly taken from not-at-all-working to works-but- - still-needs-work. Code which uses the R5 server can be replaced with code which - directly manipulates the buffer one function at a time for an even greater speed boost. - Simply not using DrawBitmap() to display the framebuffer will allow for a speed gain - by a couple orders of magnitude ---------------------------------------------------------------------------------------- */ - -DirectDriver::DirectDriver() - : DisplayDriverImpl() -{ - ATRACE(("DirectDriver::DirectDriver\n")); - - screenwin=NULL; - - ATRACE(("\tCreating framebuffer bitmap\n")); - framebuffer=new BBitmap(BRect(0,0,639,479),B_RGB32,true); - - ATRACE(("\tCreating child view for framebuffer\n")); - drawview=new BView(framebuffer->Bounds(),"drawview",0,0); - framebuffer->AddChild(drawview); - - BScreen screen; - screen.GetMode(&fCurrentScreenMode); - ATRACE(("\tCurrent Mode:%u x %u\n",fCurrentScreenMode.virtual_width,fCurrentScreenMode.virtual_height)); - - // We'll save this so that if we change the bit depth of the screen, we - // can change it back when the driver is shut down. - fSavedScreenMode=fCurrentScreenMode; -} - -DirectDriver::~DirectDriver() -{ - ATRACE(("DirectDriver::~DirectDriver\n")); - Lock(); - ATRACE(("\tDeleting the framebuffer\n")); - delete framebuffer; - screenwin->framebuffer=NULL; - Unlock(); -} - -bool DirectDriver::Initialize() -{ - if (DisplayDriver::Initialize()) { - ATRACE(("DirectDriver::Initialize\n")); - screenwin=new DDWindow(640,480,B_RGB32,this); - while(find_thread("drawing_thread")==B_NAME_NOT_FOUND) - { - ATRACE(("\tWaiting for the drawing thread to spawn\n")); - snooze(100); - } - return true; - } - return false; -} - -void DirectDriver::Shutdown() -{ - DisplayDriver::Shutdown(); - - ATRACE(("DirectDriver::Shutdown\n")); - screenwin->PostMessage(B_QUIT_REQUESTED); - - if(fSavedScreenMode.space!=fCurrentScreenMode.space) - BScreen().SetMode(&fSavedScreenMode); -} -/* -void DirectDriver::DrawBitmap(ServerBitmap *bmp, const BRect &src, const BRect &dest, const DrawData *d) -{ - STRACE(("DirectDriver::DrawBitmap\n")); - if(!bmp || !d) - { - printf("CopyBitmap returned - not init or NULL bitmap\n"); - return; - } - - SetDrawData(d); - - // Oh, wow, is this going to be slow. Gotta write the real DrawBitmap code sometime... - - BBitmap *mediator=new BBitmap(bmp->Bounds(),bmp->ColorSpace()); - memcpy(mediator->Bits(),bmp->Bits(),bmp->BitsLength()); - - Lock(); - framebuffer->Lock(); - - drawview->DrawBitmap(mediator,src,dest); - drawview->Sync(); - - framebuffer->Unlock(); - screenwin->rectpipe.PutRect(dest); - Unlock(); - delete mediator; -}*/ - -void DirectDriver::InvertRect(const BRect &r) -{ - STRACE(("DirectDriver::InvertRect\n")); - // Shamelessly stolen from AccelerantDriver.cpp - - Lock(); - switch (framebuffer->ColorSpace()) - { - case B_RGB32_BIG: - case B_RGBA32_BIG: - case B_RGB32_LITTLE: - case B_RGBA32_LITTLE: - { - uint16 width=r.IntegerWidth(); - uint16 height=r.IntegerHeight(); - uint32 *start=(uint32*)framebuffer->Bits(); - uint32 *index; - start = (uint32 *)((uint8 *)start+(int32)r.top*framebuffer->BytesPerRow()); - start+=(int32)r.left; - - index = start; - for(int32 i=0;iBytesPerRow()); - } - } - break; - case B_RGB16_BIG: - case B_RGB16_LITTLE: - { - uint16 width=r.IntegerWidth(); - uint16 height=r.IntegerHeight(); - uint16 *start=(uint16*)framebuffer->Bits(); - uint16 *index; - start = (uint16 *)((uint8 *)start+(int32)r.top*framebuffer->BytesPerRow()); - start+=(int32)r.left; - - index = start; - for(int32 i=0;iBytesPerRow()); - } - } - break; - case B_RGB15_BIG: - case B_RGBA15_BIG: - case B_RGB15_LITTLE: - case B_RGBA15_LITTLE: - { - uint16 width=r.IntegerWidth(); - uint16 height=r.IntegerHeight(); - uint16 *start=(uint16*)framebuffer->Bits(); - uint16 *index; - start = (uint16 *)((uint8 *)start+(int32)r.top*framebuffer->BytesPerRow()); - start+=(int32)r.left; - - index = start; - for(int32 i=0;iBytesPerRow()); - } - } - break; - case B_CMAP8: - case B_GRAY8: - { - uint16 width=r.IntegerWidth(); - uint16 height=r.IntegerHeight(); - uint8 *start=(uint8*)framebuffer->Bits(); - uint8 *index; - start = (uint8 *)start+(int32)r.top*framebuffer->BytesPerRow(); - start+=(int32)r.left; - - index = start; - for(int32 i=0;iBytesPerRow(); - } - } - break; - default: - break; - } - Unlock(); -} - -void DirectDriver::StrokeLineArray(const int32 &numlines, const LineArrayData *linedata, const DrawData *d) -{ - STRACE(("DirectDriver::StrokeLineArray\n")); - if( !numlines || !linedata || !d) - return; - - const LineArrayData *data; - - Lock(); - framebuffer->Lock(); - drawview->SetPenSize(d->pensize); - drawview->SetDrawingMode(d->draw_mode); - - drawview->BeginLineArray(numlines); - for(int32 i=0; iAddLine(data->pt1,data->pt2,data->color); - } - drawview->EndLineArray(); - - drawview->Sync(); - screenwin->rectpipe.PutRect(framebuffer->Bounds()); - framebuffer->Unlock(); - Unlock(); -} - -void DirectDriver::SetMode(const display_mode &mode) -{ - STRACE(("DirectDriver::SetMode(%u x %u)\n",mode.virtual_width,mode.virtual_height)); - Lock(); - - // Supports all modes all modes >= 640x480 and < supported resolutions in - // all supported color depths - - - // Because we don't support modes with the same height and different widths, we can - // use the height to determine what we're going to do. - - if(mode.virtual_height>fCurrentScreenMode.virtual_height) - { - STRACE(("DirectDriver::SetMode: height requested greater than current screen height\n")); - Unlock(); - return; - } - - switch(mode.virtual_height) - { - // These mode heights are kosher, so filter out any others - case 400: - case 480: - case 600: - case 768: - case 864: - case 1024: - case 1200: - break; - - default: - STRACE(("DirectDriver::SetMode:invalid mode height\n")); - Unlock(); - return; - } - - // If we're running in a really crappy resolution, allow the user to set the mode - // to full-screen non-exclusive mode. - if(fCurrentScreenMode.virtual_height>480 && - mode.virtual_height==fCurrentScreenMode.virtual_height) - { - STRACE(("DirectDriver::SetMode: height requested equal to current screen height " - "and greater than 640x480\n")); - Unlock(); - return; - } - - // We got this far, so apparently the mode requested is smaller than the current screen's - // mode OR is one of our two exceptions, so now we check for supported bit depth. - // Because we're directly accessing the framebuffer, changing bit depths for the driver - // also means changing the user's actual screen bit depth. Realistically, we *could* - // fake output and change to the user's current bit depth, but considering that (1) it - // would be a *lot* more work, (2) this driver isn't the real thing, (3) there would - // be a performance hit, and (4) I'm too lazy to mess with it, we'll change the screen's - // depth, not make it default, and save the old ont so that we can change it back when - // the driver is shut down. - -/* BScreen screen; - display_mode candidate=mode; - if(screen.ProposeMode(&candidate,&mode,&mode)!=B_OK) - { - STRACE(("DirectDriver::SetMode:ProposeMode failed\n")); - return; - } -*/ - // It would seem that everything passed the error check, so actually set the mode - DTRACE(("Locking screen window\n")); - screenwin->Lock(); - - DTRACE(("Hiding screen window\n")); - screenwin->Hide(); - screenwin->Unlock(); - - DTRACE(("Locking screen window\n")); - screenwin->Lock(); - - DTRACE(("Quitting old screen window\n")); - screenwin->Quit(); - - DTRACE(("deleting framebuffer\n")); - delete framebuffer; - - DTRACE(("creating new framebuffer\n")); - framebuffer=new BBitmap(BRect(0,0,mode.virtual_width-1, mode.virtual_height-1),(color_space)mode.space,true); - drawview=new BView(framebuffer->Bounds(),"drawview",0,0); - framebuffer->AddChild(drawview); - - DTRACE(("creating new window\n")); - screenwin=new DDWindow(mode.virtual_width, mode.virtual_height,(color_space)mode.space,this); - while(find_thread("drawing_thread")==B_NAME_NOT_FOUND) - { - STRACE(("\tSetMode::Waiting for the drawing thread to spawn\n")); - snooze(100); - } - - Unlock(); -} - -bool DirectDriver::DumpToFile(const char *path) -{ - STRACE(("DirectDriver::DumpToFile\n")); - Lock(); - SaveToPNG(path,framebuffer->Bounds(),framebuffer->ColorSpace(), - framebuffer->Bits(),framebuffer->BitsLength(),framebuffer->BytesPerRow()); - - Unlock(); - return true; -} - -status_t DirectDriver::SetDPMSMode(const uint32 &state) -{ - STRACE(("DirectDriver::SetDPMSMode\n")); - - // This is a hack, but should do enough to be ok for our purposes - return BScreen().SetDPMS(state); -} - -uint32 DirectDriver::DPMSMode() -{ - STRACE(("DirectDriver::DPMSMode\n")); - // This is a hack, but should do enough to be ok for our purposes - return BScreen().DPMSState(); -} - -uint32 DirectDriver::DPMSCapabilities() -{ - STRACE(("DirectDriver::DPMSCapabilities\n")); - - // This is a hack, but should do enough to be ok for our purposes - return BScreen().DPMSCapabilites(); -} - -status_t DirectDriver::GetDeviceInfo(accelerant_device_info *info) -{ - STRACE(("DirectDriver::GetDeviceInfo\n")); - if(!info) - return B_ERROR; - - Lock(); - status_t error=BScreen().GetDeviceInfo(info); - Unlock(); - - return error; -} - -status_t DirectDriver::GetModeList(display_mode **mode_list, uint32 *count) -{ - STRACE(("DirectDriver::GetModeList\n")); - if(!mode_list || !count) - return B_ERROR; - - Lock(); - status_t error=BScreen().GetModeList(mode_list,count); - Unlock(); - - return error; -} - -status_t DirectDriver::GetPixelClockLimits(display_mode *mode, uint32 *low, uint32 *high) -{ - STRACE(("DirectDriver::GetPixelClockLimits\n")); - if(!mode || !low || !high) - return B_ERROR; - - Lock(); - status_t error=BScreen().GetPixelClockLimits(mode,low,high); - Unlock(); - - return error; -} - -status_t DirectDriver::GetTimingConstraints(display_timing_constraints *dtc) -{ - STRACE(("DirectDriver::GetTimingConstraints\n")); - if(!dtc) - return B_ERROR; - - Lock(); - status_t error=BScreen().GetTimingConstraints(dtc); - Unlock(); - - return error; -} - -status_t DirectDriver::ProposeMode(display_mode *candidate, const display_mode *low, const display_mode *high) -{ - STRACE(("DirectDriver::ProposeMode UNIMPLEMENTED\n")); - // This could get sticky here. Theoretically, we should support the subset of modes - // which the hardware can display and is not fullscreen unless the mode is 640x480 and - // the current screen mode is also 640x480. - - - //TODO: Implement this properly or get a "gotcha" sometime down the road. - return B_OK; -} - -status_t DirectDriver::WaitForRetrace(bigtime_t timeout=B_INFINITE_TIMEOUT) -{ - STRACE(("DirectDriver::WaitForRetrace\n")); - // There shouldn't be a need for a Lock call on this one... - return BScreen().WaitForRetrace(timeout); -} - -void DirectDriver::FillSolidRect(const BRect &rect, const RGBColor &color) -{ - STRACE(("DirectDriver::FillSolidRect\n")); - Lock(); - framebuffer->Lock(); - drawview->SetHighColor(color.GetColor32()); - drawview->FillRect(rect); - drawview->Sync(); - screenwin->rectpipe.PutRect(rect); - framebuffer->Unlock(); - Unlock(); -} - -void DirectDriver::FillPatternRect(const BRect &rect, const DrawData *d) -{ - STRACE(("DirectDriver::FillPatternRect\n")); - if(!d) - return; - - Lock(); - framebuffer->Lock(); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->FillRect(rect,*((pattern*)d->patt.GetInt8())); - drawview->Sync(); - screenwin->rectpipe.PutRect(rect); - framebuffer->Unlock(); - Unlock(); -} - -void DirectDriver::StrokeSolidRect(const BRect &rect, const RGBColor &color) -{ - STRACE(("DirectDriver::StrokeSolidRect\n")); - Lock(); - framebuffer->Lock(); - drawview->SetHighColor(color.GetColor32()); - drawview->StrokeRect(rect); - drawview->Sync(); - screenwin->rectpipe.PutRect(rect); - framebuffer->Unlock(); - Unlock(); -} - -void DirectDriver::StrokeSolidLine(int32 x1, int32 y1, int32 x2, int32 y2, const RGBColor &color) -{ - STRACE(("DirectDriver::StrokeSolidLine\n")); - Lock(); - framebuffer->Lock(); - drawview->SetHighColor(color.GetColor32()); - drawview->StrokeLine(BPoint(x1,y1),BPoint(x2,y2)); - drawview->Sync(); - screenwin->rectpipe.PutRect(BRect(x1,y1,x2,y2)); - framebuffer->Unlock(); - Unlock(); -} - -void DirectDriver::StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2, const DrawData *d) -{ - STRACE(("DirectDriver::StrokePatternLine\n")); - if(!d) - return; - - Lock(); - framebuffer->Lock(); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->StrokeLine(BPoint(x1,y1),BPoint(x2,y2),*((pattern*)d->patt.GetInt8())); - drawview->Sync(); - screenwin->rectpipe.PutRect(BRect(x1,y1,x2,y2)); - framebuffer->Unlock(); - Unlock(); -} - -void DirectDriver::CopyBitmap(ServerBitmap *bitmap, const BRect &source,const BRect &dest, const DrawData *d) -{ - if(!bitmap) - { - STRACE(("DirectDriver::CopyBitmap returned - NULL bitmap\n")); -} - if(!d) - { - STRACE(("DirectDriver::CopyBitmap returned - NULL DrawData\n")); - return; - } - - SetDrawData(d); - - // Oh, wow, is this going to be slow. Then again, ViewDriver was never meant to be very fast. It could - // be made significantly faster by directly copying from the source to the destination, but that would - // require implementing a lot of code. Eventually, this should be replaced, but for now, using - // DrawBitmap will at least work with a minimum of effort. - - BBitmap *mediator=new BBitmap(bitmap->Bounds(),bitmap->ColorSpace()); - memcpy(mediator->Bits(),bitmap->Bits(),bitmap->BitsLength()); - - Lock(); - framebuffer->Lock(); - - drawview->DrawBitmap(mediator,source,dest); - drawview->Sync(); - - framebuffer->Unlock(); - screenwin->rectpipe.PutRect(dest); - Unlock(); - delete mediator; -} - -void DirectDriver::SetDrawData(const DrawData *d, bool set_font_data) -{ - STRACE(("DirectDriver::SetDrawData\n")); - if(!d) - return; - - bool unlock=false; - if(!framebuffer->IsLocked()) - { - framebuffer->Lock(); - unlock=true; - } - - drawview->SetPenSize(d->pensize); - drawview->SetDrawingMode(d->draw_mode); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->SetScale(d->scale); - drawview->MovePenTo(d->penlocation); - if(set_font_data) - { - BFont font; - const ServerFont *sf=&(d->font); - - if(!sf) - return; - - font.SetFamilyAndStyle(sf->GetFamily(),sf->GetStyle()); - font.SetFlags(sf->Flags()); - font.SetEncoding(sf->Encoding()); - font.SetSize(sf->Size()); - font.SetRotation(sf->Rotation()); - font.SetShear(sf->Shear()); - font.SetSpacing(sf->Spacing()); - drawview->SetFont(&font); - } - if(unlock) - framebuffer->Unlock(); -} - -void DirectDriver::CopyToBitmap(ServerBitmap *destbmp, const BRect &sourcerect) -{ - STRACE(("DirectDriver::CopyToBitmap\n")); - if(!destbmp) - { - printf("CopyToBitmap returned - not init or NULL bitmap\n"); - return; - } - - if((destbmp->ColorSpace() & 0x000F) != (framebuffer->ColorSpace() & 0x000F)) - { - printf("CopyToBitmap returned - unequal buffer pixel depth\n"); - return; - } - - BRect destrect(destbmp->Bounds()), source(sourcerect); - - uint8 colorspace_size=destbmp->BitsPerPixel()/8; - - // First, clip source rect to destination - if(source.Width() > destrect.Width()) - source.right=source.left+destrect.Width(); - - if(source.Height() > destrect.Height()) - source.bottom=source.top+destrect.Height(); - - - // Second, check rectangle bounds against their own bitmaps - BRect work_rect(destbmp->Bounds()); - - if( !(work_rect.Contains(destrect)) ) - { - // something in selection must be clipped - if(destrect.left < 0) - destrect.left = 0; - if(destrect.right > work_rect.right) - destrect.right = work_rect.right; - if(destrect.top < 0) - destrect.top = 0; - if(destrect.bottom > work_rect.bottom) - destrect.bottom = work_rect.bottom; - } - - work_rect.Set(0,0,fDisplayMode.virtual_width-1,fDisplayMode.virtual_height-1); - - if(!work_rect.Contains(sourcerect)) - return; - - if( !(work_rect.Contains(source)) ) - { - // something in selection must be clipped - if(source.left < 0) - source.left = 0; - if(source.right > work_rect.right) - source.right = work_rect.right; - if(source.top < 0) - source.top = 0; - if(source.bottom > work_rect.bottom) - source.bottom = work_rect.bottom; - } - - // Set pointers to the actual data - uint8 *dest_bits = (uint8*) destbmp->Bits(); - uint8 *src_bits = (uint8*) framebuffer->Bits(); - - // Get row widths for offset looping - uint32 dest_width = uint32 (destbmp->BytesPerRow()); - uint32 src_width = uint32 (framebuffer->BytesPerRow()); - - // Offset bitmap pointers to proper spot in each bitmap - src_bits += uint32 ( (source.top * src_width) + (source.left * colorspace_size) ); - dest_bits += uint32 ( (destrect.top * dest_width) + (destrect.left * colorspace_size) ); - - - uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size); - uint32 lines = uint32 (source.bottom-source.top+1); - - for (uint32 pos_y=0; pos_yLock(); - -// screenwin->view->ConstrainClippingRegion(reg); - drawview->ConstrainClippingRegion(reg); - - framebuffer->Unlock(); - Unlock(); -} - -rgb_color DirectDriver::GetBlitColor(rgb_color src, rgb_color dest,DrawData *d, bool use_high) -{ - rgb_color returncolor={0,0,0,0}; - - int16 value; - if(!d) - return returncolor; - - switch(d->draw_mode) - { - case B_OP_COPY: - { - return src; - } - case B_OP_ADD: - { - value=src.red+dest.red; - returncolor.red=(value>255)?255:value; - - value=src.green+dest.green; - returncolor.green=(value>255)?255:value; - - value=src.blue+dest.blue; - returncolor.blue=(value>255)?255:value; - return returncolor; - } - case B_OP_SUBTRACT: - { - value=src.red-dest.red; - returncolor.red=(value<0)?0:value; - - value=src.green-dest.green; - returncolor.green=(value<0)?0:value; - - value=src.blue-dest.blue; - returncolor.blue=(value<0)?0:value; - return returncolor; - } - case B_OP_BLEND: - { - value=int16(src.red+dest.red)>>1; - returncolor.red=value; - - value=int16(src.green+dest.green)>>1; - returncolor.green=value; - - value=int16(src.blue+dest.blue)>>1; - returncolor.blue=value; - return returncolor; - } - case B_OP_MIN: - { - - return ( uint16(src.red+src.blue+src.green) > - uint16(dest.red+dest.blue+dest.green) )?dest:src; - } - case B_OP_MAX: - { - return ( uint16(src.red+src.blue+src.green) < - uint16(dest.red+dest.blue+dest.green) )?dest:src; - } - case B_OP_OVER: - { - return (use_high && src.alpha>127)?src:dest; - } - case B_OP_INVERT: - { - returncolor.red=dest.red ^ 255; - returncolor.green=dest.green ^ 255; - returncolor.blue=dest.blue ^ 255; - return (use_high && src.alpha>127)?returncolor:dest; - } - case B_OP_ALPHA: - { - //TODO: Implement - return src; - } - case B_OP_ERASE: - { - // This one's tricky. - return (use_high && src.alpha>127)?d->lowcolor.GetColor32():dest; - } - case B_OP_SELECT: - { - // This one's tricky, too. We are passed a color in src. If it's the layer's - // high color or low color, we check for a swap. - if(d->highcolor==src) - return (use_high && d->highcolor==dest)?d->lowcolor.GetColor32():dest; - - if(d->lowcolor==src) - return (use_high && d->lowcolor==dest)?d->highcolor.GetColor32():dest; - - return dest; - } - default: - { - break; - } - } - return returncolor; -} - -//-------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------- -//-------------------------------------------------------------------------------------- - - -DDView::DDView(BRect bounds) - : BView(bounds,"viewdriver_view",B_FOLLOW_ALL, B_WILL_DRAW), - serverlink(0L) -{ - SetViewColor(B_TRANSPARENT_32_BIT); - -#ifdef ENABLE_INPUT_SERVER_EMULATION - port_id serverInputPort = find_port(SERVER_INPUT_PORT); - if (serverInputPort<0) - { - debugger("DirectDriver:DDView couldn't find input port\n"); - return; - } - serverlink.SetSendPort(serverInputPort); -#endif - -} - -// These functions emulate the Input Server by sending the *exact* same kind of messages -// to the server's port. Being we're using a regular window, it would make little sense -// to do anything else. - -void DDView::MouseDown(BPoint pt) -{ -#ifdef ENABLE_INPUT_SERVER_EMULATION - // Attach data: - // 1) int64 - time of mouse click - // 2) float - x coordinate of mouse click - // 3) float - y coordinate of mouse click - // 4) int32 - modifier keys down - // 5) int32 - buttons down - // 6) int32 - clicks - - uint32 buttons, mod, clicks=1; - int64 time=(int64)real_time_clock(); - - BMessage *msg=Window()->CurrentMessage(); - msg->FindPoint("where",&pt); - msg->FindInt32("modifiers",(int32*)&mod); - msg->FindInt32("buttons",(int32*)&buttons); - msg->FindInt32("clicks",(int32*)&clicks); - - serverlink.StartMessage(B_MOUSE_DOWN); - serverlink.Attach(&time, sizeof(int64)); - serverlink.Attach(&pt.x,sizeof(float)); - serverlink.Attach(&pt.y,sizeof(float)); - serverlink.Attach(&mod, sizeof(uint32)); - serverlink.Attach(&buttons, sizeof(uint32)); - serverlink.Attach(&clicks, sizeof(uint32)); - serverlink.Flush(); -#endif -} - -void DDView::MouseMoved(BPoint pt, uint32 transit, const BMessage *msg) -{ -#ifdef ENABLE_INPUT_SERVER_EMULATION - // Attach data: - // 1) int64 - time of mouse click - // 2) float - x coordinate of mouse click - // 3) float - y coordinate of mouse click - // 4) int32 - buttons down - BPoint p; - uint32 buttons; - int64 time=(int64)real_time_clock(); - - serverlink.StartMessage(B_MOUSE_MOVED); - serverlink.Attach(&time,sizeof(int64)); - serverlink.Attach(&pt.x,sizeof(float)); - serverlink.Attach(&pt.y,sizeof(float)); - GetMouse(&p,&buttons); - serverlink.Attach(&buttons,sizeof(int32)); - serverlink.Flush(); -#endif -} - -void DDView::MouseUp(BPoint pt) -{ -#ifdef ENABLE_INPUT_SERVER_EMULATION - // Attach data: - // 1) int64 - time of mouse click - // 2) float - x coordinate of mouse click - // 3) float - y coordinate of mouse click - // 4) int32 - modifier keys down - BPoint p; - - uint32 buttons, - mod=modifiers(); - - int64 time=(int64)real_time_clock(); - - GetMouse(&p,&buttons); - - serverlink.StartMessage(B_MOUSE_UP); - serverlink.Attach(&time, sizeof(int64)); - serverlink.Attach(&pt.x,sizeof(float)); - serverlink.Attach(&pt.y,sizeof(float)); - serverlink.Attach(&mod, sizeof(uint32)); - serverlink.Flush(); -#endif -} - -void DDView::MessageReceived(BMessage *msg) -{ - switch(msg->what) - { -#ifdef ENABLE_INPUT_SERVER_EMULATION - case B_MOUSE_WHEEL_CHANGED: - { - float x,y; - msg->FindFloat("be:wheel_delta_x",&x); - msg->FindFloat("be:wheel_delta_y",&y); - int64 time=real_time_clock(); - serverlink.StartMessage(B_MOUSE_WHEEL_CHANGED); - serverlink.Attach(&time,sizeof(int64)); - serverlink.Attach(x); - serverlink.Attach(y); - serverlink.Flush(); - break; - } -#endif - default: - BView::MessageReceived(msg); - break; - } -} - -DDWindow::DDWindow(uint16 width, uint16 height, color_space space, DirectDriver *owner) -: BDirectWindow(BRect(0,0,width-1,height-1), "Haiku App Server",B_TITLED_WINDOW, - B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NOT_MOVABLE) -{ - AddChild(new DDView(Bounds())); - - fOwner=owner; - fConnected=false; - fConnectionDisabled=false; - fClipList=NULL; - fNumClipRects=0; - fDirty=true; - fDrawThreadID=-1; - - if(!owner) - debugger("DDWindow requires a non-NULL owner."); - - framebuffer=owner->framebuffer; - - if(SupportsWindowMode()) - { - BRect sframe(BScreen().Frame()); - screensize.left=(int32)sframe.left; - screensize.right=(int32)sframe.right; - screensize.top=(int32)sframe.top; - screensize.bottom=(int32)sframe.bottom; - - MoveTo( (int32)(sframe.Width()-width)/2, (int32)(sframe.Height()-height)/2 ); - } - else - { - SetFullScreen(true); - } - - Show(); -} - -DDWindow::~DDWindow() -{ - int32 result; - - fConnectionDisabled=true; -// Sync(); - if(fDrawThreadID!=-1) - wait_for_thread(fDrawThreadID,&result); - free(fClipList); -} - -void DDWindow::DirectConnected(direct_buffer_info *info) -{ - if(!fConnected && fConnectionDisabled) - return; - - locker.Lock(); - - switch(info->buffer_state & B_DIRECT_MODE_MASK) - { - case B_DIRECT_START: - { - fConnected=true; - fDrawThreadID=spawn_thread(DrawingThread,"drawing_thread", B_NORMAL_PRIORITY,(void*)this); - resume_thread(fDrawThreadID); - // fall through to B_DIRECT_MODIFY case - } - case B_DIRECT_MODIFY: - { - fBits=(uint8*)info->bits; - fRowBytes=info->bytes_per_row; - fFormat=info->pixel_format; - fBounds=info->window_bounds; - - if(fClipList) - { - free(fClipList); - fClipList=NULL; - } - fNumClipRects=info->clip_list_count; - fClipList=(clipping_rect*)malloc(fNumClipRects*sizeof(clipping_rect)); - - if(fClipList) - { - memcpy(fClipList, info->clip_list, fNumClipRects*sizeof(clipping_rect)); - fDirty=true; - } - break; - } - case B_DIRECT_STOP: - { - fConnected=false; - break; - } - } - locker.Unlock(); -} - -bool DDWindow::QuitRequested() -{ - port_id serverport=find_port(SERVER_PORT_NAME); - - if(serverport>=0) - { - BPortLink link(serverport); - link.StartMessage(B_QUIT_REQUESTED); - link.Flush(); - } - else - printf("ERROR: couldn't find the app_server's main port!"); - - return true; -} - -void DDWindow::WindowActivated(bool active) -{ - // This is just to hide the regular system cursor so we can see our own - - if(active) - be_app->HideCursor(); - else - be_app->ShowCursor(); -} - -int32 DDWindow::DrawingThread(void *data) -{ - ATRACE(("DrawingThread started\n")); - - DDWindow *w; - w=(DDWindow *)data; - - bool wait_for_good_mode=true; - while(wait_for_good_mode) - { - switch(w->fFormat) - { - case B_RGB32: - case B_RGBA32: - case B_RGB32_BIG: - case B_RGBA32_BIG: - case B_GRAY8: - case B_CMAP8: - { - DTRACE(("\tFound a good mode. Exiting wait loop\n")); - wait_for_good_mode=false; - break; - } - default: - DTRACE(("\tWaiting for a good mode\n")); - break; - } - } - - switch(w->fFormat) - { - case B_RGB32: - case B_RGBA32: - case B_RGB32_BIG: - case B_RGBA32_BIG: - { - DTRACE(("\tEntering while loop\n")); - while(!w->fConnectionDisabled) - { - DTRACE(("\tacquiring window lock\n")); - w->locker.Lock(); - if(w->fConnected) - { - int32 winleft=(int32)w->Frame().left,wintop=(int32)w->Frame().top; - - DTRACE(("\tcheck to see if window is dirty\n")); - if(w->fDirty) - { - DTRACE(("\twindow is dirty\n")); - int32 y,bytes_to_copy,height; - uint8 *srcbits, *destbits; - clipping_rect *clip; - uint32 i; - - DTRACE(("\tClipping rectangles to copy: %lu\n",w->fNumClipRects)); - for(i=0; ifNumClipRects; i++) - { - DTRACE(("\tcopying clipping rectangle %lu\n",i)); - clip=&(w->fClipList[i]); - bytes_to_copy=((clip->right-clip->left)+1)<<2; - height=(clip->bottom-clip->top)+1; - - destbits=w->fBits+ (clip->top*w->fRowBytes)+ - (clip->left<<2); - - srcbits=(uint8*)w->framebuffer->Bits()+ - ((clip->top-wintop)*w->framebuffer->BytesPerRow())+ - ( (clip->left-winleft)<<2); - y=0; - - while(yfRowBytes; - srcbits+=w->framebuffer->BytesPerRow(); - } - } - w->fDirty=false; - } - else - DTRACE(("\tWindow is not dirty\n")); - - if(!w->fConnected) - { - DTRACE(("\twindow is no longer connected. Exiting draw case\n")); - break; - } - - // This will be true if the driver has changed the contents of - // the framebuffer bitmap - DTRACE(("\tFramebuffer bitmap has %ld invalid regions\n",w->rectpipe.CountRects())); - while(w->rectpipe.HasRects()) - { - clipping_rect rect; - int32 y,bytes_to_copy,height; - uint8 *srcbits, *destbits; - - w->rectpipe.GetRect(&rect); - - bytes_to_copy=((rect.right-rect.left)+1)<<2; - height=(rect.bottom-rect.top)+1; - - destbits=w->fBits+ ( (rect.top+wintop)*w->fRowBytes)+ - ( (rect.left+winleft)<<2); - - srcbits=(uint8*)w->framebuffer->Bits()+ - (rect.top*w->framebuffer->BytesPerRow())+ - (rect.left<<2); - y=0; - - DTRACE(("Copying data from bitmap to screen\n")); - while(yfRowBytes; - srcbits+=w->framebuffer->BytesPerRow(); - } - } - } - DTRACE(("\tReleasing window lock\n")); - w->locker.Unlock(); - snooze(16000); - } - break; - } - case B_GRAY8: - case B_CMAP8: - { - while(!w->fConnectionDisabled) - { - w->locker.Lock(); - if(w->fConnected) - { - if(w->fDirty) - { - int32 y,width,height,adder; - uint8 *p; - clipping_rect *clip; - uint32 i; - - adder=w->fRowBytes; - for(i=0; ifNumClipRects; i++) - { - clip=&(w->fClipList[i]); - width=(clip->right-clip->left)+1; - height=(clip->bottom-clip->top)+1; - p=w->fBits+(clip->top*w->fRowBytes)+clip->left; - y=0; - while(yfDirty=false; - } - } - w->locker.Unlock(); - snooze(16000); - } - break; - } - default: - debugger("DirectDriver was given an unsupported color mode."); - break; - } - w->fDrawThreadID=-1; - return 0; -} - -RectPipe::RectPipe() -{ - list.MakeEmpty(); -} - -RectPipe::~RectPipe() -{ - lock.Lock(); - clipping_rect *rect; - for(int32 i=0; ileft=(int32)rect.left; - clip->right=(int32)rect.right; - clip->top=(int32)rect.top; - clip->bottom=(int32)rect.bottom; - list.AddItem(clip); - lock.Unlock(); -} - -void RectPipe::PutRect(const clipping_rect &rect) -{ - lock.Lock(); - has_rects=true; - clipping_rect *clip=new clipping_rect; - *clip=rect; - list.AddItem(clip); - lock.Unlock(); -} - -bool RectPipe::GetRect(clipping_rect *rect) -{ - lock.Lock(); - clipping_rect *clip=(clipping_rect*)list.RemoveItem(0L); - if(clip) - { - *rect=*clip; - delete clip; - - if(list.IsEmpty()) - has_rects=false; - - lock.Unlock(); - return true; - } - - // If we returned NULL, it means that the list is empty - has_rects=false; - lock.Unlock(); - return false; -} - -bool RectPipe::HasRects() -{ - lock.Lock(); - bool value=has_rects; - lock.Unlock(); - return value; -} diff --git a/src/servers/app/drawing/old_but_informative/DirectDriver.h b/src/servers/app/drawing/old_but_informative/DirectDriver.h deleted file mode 100644 index 30b945d222..0000000000 --- a/src/servers/app/drawing/old_but_informative/DirectDriver.h +++ /dev/null @@ -1,174 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: DirectDriver.h -// Author: DarkWyrm -// -// Description: BDirectWindow graphics module -// -//------------------------------------------------------------------------------ -#ifndef DIRECTDRIVER_H_ -#define DIRECTDRIVER_H_ - -#include -#include -#include -#include // for clipping_rect definition -#include -#include -#include "PortLink.h" -#include -#include "PatternHandler.h" - -#include "DisplayDriverImpl.h" - -class UtilityBitmap; -class SDWindow; -class LayerData; -class DirectDriver; - -// This is very much not the fastest thing in the world - just quickly hacked out to get it going -// and make it relatively easy to optimize later. Ideally, rectangles stored in this should be -// stored in a singly-linked list and allocated items should be saved (and freed upon the object's -// destruction) to minimize calls to the OS' memory manager. -class RectPipe -{ -public: - RectPipe(); - ~RectPipe(); - - void PutRect(const BRect &rect); - void PutRect(const clipping_rect &rect); - bool GetRect(clipping_rect *rect); - bool HasRects(); - int32 CountRects() const { return list.CountItems(); } -protected: - BList list; - BLocker lock; - bool has_rects; -}; - -class DDView : public BView -{ -public: - DDView(BRect bounds); - void MouseDown(BPoint pt); - void MouseMoved(BPoint pt, uint32 transit, const BMessage *msg); - void MouseUp(BPoint pt); - void MessageReceived(BMessage *msg); - - BPortLink serverlink; -}; - -class DDWindow : public BDirectWindow -{ -public: - DDWindow(uint16 width, uint16 height, color_space space, DirectDriver *owner); - ~DDWindow(); - - virtual bool QuitRequested(); - virtual void DirectConnected(direct_buffer_info *info); - virtual void WindowActivated(bool active); - static int32 DrawingThread(void *data); - - uint8 *fBits; - int32 fRowBytes; - color_space fFormat; - clipping_rect fBounds; - uint32 fNumClipRects; - clipping_rect *fClipList; - - bool fDirty, fConnected, fConnectionDisabled; - BLocker locker; - thread_id fDrawThreadID; - DisplayDriver *fOwner; - BBitmap *framebuffer; - clipping_rect screensize; - RectPipe rectpipe; -}; - -/*! - \brief BDirectWindow graphics module - - Last (and best) driver class in the app_server which is designed - to provide fast graphics access for testing. - - The concept is to have a bitmap get written to which is used for double-buffering - the video display. An updater thread simply locks access to this bitmap, copies data to - the framebuffer, and releases access. Derived DisplayDriver functions operate on this bitmap. -*/ -class DirectDriver : public DisplayDriverImpl -{ -public: - DirectDriver(); - ~DirectDriver(); - - virtual bool Initialize(); - virtual void Shutdown(); - -// void DrawBitmap(ServerBitmap *bmp, const BRect &src, const BRect &dest, const DrawData *d); - - virtual void InvertRect(const BRect &r); - - virtual void StrokeLineArray(const int32 &numlines, const LineArrayData *linedata, const DrawData *d); - - virtual void SetMode(const display_mode &mode); - - virtual bool DumpToFile(const char *path); - - virtual status_t SetDPMSMode(const uint32 &state); - virtual uint32 DPMSMode(); - virtual uint32 DPMSCapabilities(); - virtual status_t GetDeviceInfo(accelerant_device_info *info); - virtual status_t GetModeList(display_mode **mode_list, uint32 *count); - virtual status_t GetPixelClockLimits(display_mode *mode, uint32 *low, uint32 *high); - virtual status_t GetTimingConstraints(display_timing_constraints *dtc); - virtual status_t ProposeMode(display_mode *candidate, const display_mode *low, const display_mode *high); - virtual status_t WaitForRetrace(bigtime_t timeout=B_INFINITE_TIMEOUT); - - BBitmap *framebuffer; - display_mode fCurrentScreenMode, fSavedScreenMode; - -protected: - virtual void FillSolidRect(const BRect &rect, const RGBColor &color); - virtual void FillPatternRect(const BRect &rect, const DrawData *d); - virtual void StrokeSolidRect(const BRect &rect, const RGBColor &color); - virtual void StrokeSolidLine(int32 x1, int32 y1, int32 x2, int32 y2, const RGBColor &color); - virtual void StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2, const DrawData *d); - virtual void CopyBitmap(ServerBitmap *bitmap, const BRect &source, - const BRect &dest, const DrawData *d); - virtual void CopyToBitmap(ServerBitmap *target, const BRect &source); - - // Temporary function which will exist while we use BViews in the regular code - void SetDrawData(const DrawData *d, bool set_font_data=false); - - // temporarily virtual - until clipping code is added in DisplayDriver - virtual void ConstrainClippingRegion(BRegion *reg); - - rgb_color GetBlitColor(rgb_color src, rgb_color dest,DrawData *d, bool use_high=true); - - BPortLink *serverlink; - DDWindow *screenwin; - BView *drawview; -}; - - -#endif diff --git a/src/servers/app/drawing/old_but_informative/DisplayDriverImpl.cpp b/src/servers/app/drawing/old_but_informative/DisplayDriverImpl.cpp deleted file mode 100644 index dc86edd410..0000000000 --- a/src/servers/app/drawing/old_but_informative/DisplayDriverImpl.cpp +++ /dev/null @@ -1,2940 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2005, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: DisplayDriverImpl.cpp -// Authors: DarkWyrm -// Gabe Yoder -// Stephan Aßmus -// Description: Mostly abstract class which handles all graphics output -// for the server -// -//------------------------------------------------------------------------------ -#include - -#include - -#include "Angle.h" -#include "CursorData.h" -#include "FontFamily.h" -#include "RectUtils.h" -#include "ServerCursor.h" -#include "Utils.h" - -#include "DisplayDriverImpl.h" - -// TODO: Implement all functions. Bounds checking needs to be -// handled by the public drawing functions. -// Add clipping and make sure public functions have Lock & Unlock. - -static Blitter blitter; - -/*! - \brief Sets up internal variables needed by all DisplayDriverImpl subclasses -*/ -DisplayDriverImpl::DisplayDriverImpl() - : DisplayDriver(), - fLocker("DisplayDriver lock"), - fCursorHandler(this), - fDPMSState(B_DPMS_ON), - fDPMSCaps(B_DPMS_ON) -{ -} - - -/*! - \brief Does nothing -*/ -DisplayDriverImpl::~DisplayDriverImpl() -{ -} - -/*! - \brief Called for all BView::CopyBits calls - \param src Source rectangle. - \param dest Destination rectangle. - - If the destination is not the same size as the source, the source should be scaled to fit. -*/ -void DisplayDriverImpl::CopyBits(const BRect &src, const BRect &dest, const DrawData *d) -{ - if(!d) - return; - - Lock(); - - if(fCursorHandler.IntersectsCursor(dest)) - fCursorHandler.DriverHide(); - Blit(src,dest,d); - fCursorHandler.DriverShow(); - Unlock(); -} - -/*! - \brief A screen-to-screen blit (of sorts) which copies a BRegion - \param src Source region - \param lefttop Offset to which the region will be copied -*/ -void -DisplayDriverImpl::CopyRegion(BRegion *src, const BPoint &lefttop) -{ - // TODO: Implement DisplayDriverImpl::CopyRegion -} - -/*! - \brief Inverts the colors in the rectangle. - \param r Rectangle of the area to be inverted. Guaranteed to be within bounds. -*/ -void DisplayDriverImpl::InvertRect(const BRect &r) -{ -} - -/*! - \brief Called for all BView::DrawBitmap calls - \param region Destination rects in screen coordinates - \param bmp Bitmap to be drawn. It will always be non-NULL and valid. The color - space is not guaranteed to match. - \param src Source rectangle - \param dest Destination rectangle. Source will be scaled to fit if not the same size. - \param d Data structure containing any other data necessary for the call. Always non-NULL. -*/ -void -DisplayDriverImpl::DrawBitmap(BRegion *region, ServerBitmap *bitmap, - const BRect &source, const BRect &dest, - const DrawData *d) -{ - // TODO: make sure we all mean the same region -> see PicturePlayer line 257 - if (!region) - return; - - Lock(); - - FBBitmap frameBuffer; - FBBitmap *bmp = &frameBuffer; - - blitter.Select(32, 32); - - if(!AcquireBuffer(&frameBuffer)) - { - debugger("ERROR: Couldn't acquire framebuffer in DrawBitmap()\n"); - Unlock(); - return; - } - - if(fCursorHandler.IntersectsCursor(dest)) - fCursorHandler.DriverHide(); - - uint8 colorspace_size = (bitmap->BitsPerPixel() + 7) / 8; - - int32 count = region->CountRects(); - - BRect bitmaprect(bitmap->Bounds()); - BRect sourcerect(source); - - BRect destrect(dest); - destrect.right *= d->scale; - destrect.bottom *= d->scale; - - if(sourcerect.left < 0) sourcerect.left = 0; - if(sourcerect.top < 0) sourcerect.top = 0; - - if(sourcerect.Width() > bitmaprect.Width()) - sourcerect.right = bitmaprect.left + bitmaprect.Width(); - - if(sourcerect.Height() > bitmaprect.Height()) - sourcerect.bottom = bitmaprect.top + bitmaprect.Height(); - - int32 sourcewidth = (int32)sourcerect.Width() + 1; - int32 sourceheight = (int32)sourcerect.Height() + 1; - - int32 destwidth = (int32)destrect.Width() + 1; - int32 destheight = (int32)destrect.Height() + 1; - - int32 xscale_factor = (sourcewidth << 16) / destwidth; - int32 yscale_factor = (sourceheight << 16) / destheight; - - uint8 *src_bits = (uint8 *)bitmap->Bits(); - uint8 *dest_bits = (uint8*)bmp->Bits(); - - int32 src_row = bitmap->BytesPerRow(); - int32 dest_row = bmp->BytesPerRow(); - - src_bits += uint32((sourcerect.top * src_row) + (sourcerect.left * colorspace_size)); - - integer_rect src_integer_rectangle = BRect_to_integer_rect(sourcerect); - integer_rect dst_integer_rectangle = BRect_to_integer_rect(destrect); - - int32 xscale_position = 0, yscale_position = 0, clipped_xscale_position = 0; - - for(int32 c = 0; c < count; c++) - { - integer_rect screen_integer_rect = BRect_to_integer_rect(region->RectAt(c)); - integer_rect src_integer_rect = src_integer_rectangle; - integer_rect dst_integer_rect = dst_integer_rectangle; - - xscale_position = 0, yscale_position = 0, clipped_xscale_position = 0; - - if(dst_integer_rect.x < screen_integer_rect.x) - { - dst_integer_rect.x -= screen_integer_rect.x; - dst_integer_rect.w += dst_integer_rect.x; - src_integer_rect.x -= dst_integer_rect.x; - dst_integer_rect.x = screen_integer_rect.x; - } - - if(dst_integer_rect.y < screen_integer_rect.y) - { - dst_integer_rect.y -= screen_integer_rect.y; - dst_integer_rect.h += dst_integer_rect.y; - src_integer_rect.y -= dst_integer_rect.y; - dst_integer_rect.y = screen_integer_rect.y; - } - - if(dst_integer_rect.w > screen_integer_rect.w) - dst_integer_rect.w = screen_integer_rect.w; - - if(dst_integer_rect.h > screen_integer_rect.h) - dst_integer_rect.h = screen_integer_rect.h; - - if(src_integer_rect.x > src_integer_rectangle.x) - { - int32 x_scale_pixel_multiply = src_integer_rect.x - src_integer_rectangle.x; - clipped_xscale_position = xscale_factor * x_scale_pixel_multiply; - } - - if(src_integer_rect.y > src_integer_rectangle.y) - { - int32 y_scale_pixel_multiply = src_integer_rect.y - src_integer_rectangle.y; - yscale_position = yscale_factor * y_scale_pixel_multiply; - } - - if(dst_integer_rect.w > 0 && dst_integer_rect.h > 0) - { - uint8 *src_data = src_bits; - uint8 *dst_data = (uint8 *)dest_bits + dst_integer_rect.y * dest_row + dst_integer_rect.x * colorspace_size; - - while(dst_integer_rect.h--) - { - xscale_position = clipped_xscale_position; - uint8 *s = (uint8 *)((uint8 *)src_data + (yscale_position >> 16) * src_row); - uint8 *d = (uint8 *)((uint8 *)dst_data); - - blitter.Draw(s, d, dst_integer_rect.w, xscale_position, xscale_factor); - #if 0 - for(int32 x = 0; x < dst_integer_rect.w; x++) - { - *d++ = s[xscale_position >> 16]; - xscale_position += xscale_factor; - } - #endif - dst_data += dest_row; - yscale_position += yscale_factor; - } - } - } - - fCursorHandler.DriverShow(); - ReleaseBuffer(); - Unlock(); - Invalidate(destrect); -} - -void DisplayDriverImpl::CopyRegionList(BList* list, BList* pList, int32 rCount, BRegion* clipReg) -{ - Lock(); - - FBBitmap frameBuffer; - FBBitmap *bmp = &frameBuffer; - - if(!AcquireBuffer(&frameBuffer)) - { - debugger("ERROR: Couldn't acquire framebuffer in CopyRegionList()\n"); - Unlock(); - return; - } - - fCursorHandler.DriverHide(); - - - uint32 bytesPerPixel = bmp->BytesPerRow() / bmp->Bounds().IntegerWidth(); - BList rectList; - int32 i, k; - uint8 *bitmapBits = (uint8*)bmp->Bits(); - int32 Bwidth = bmp->Bounds().IntegerWidth() + 1; - int32 Bheight = bmp->Bounds().IntegerHeight() + 1; - - for(k=0; k < rCount; k++) - { - BRegion *reg = (BRegion*)list->ItemAt(k); - - int32 rectCount = reg->CountRects(); - for(i=0; i < rectCount; i++) - { - BRect r = reg->RectAt(i); - uint8 *rectCopy; - uint8 *srcAddress; - uint8 *destAddress; - int32 firstRow, lastRow; - int32 firstCol, lastCol; - int32 copyLength; - int32 copyRows; - - firstRow = (int32)(r.top < 0? 0: r.top); - lastRow = (int32)(r.bottom > (Bheight-1)? (Bheight-1): r.bottom); - firstCol = (int32)(r.left < 0? 0: r.left); - lastCol = (int32)(r.right > (Bwidth-1)? (Bwidth-1): r.right); - copyLength = (lastCol - firstCol + 1) < 0? 0: (lastCol - firstCol + 1); - copyRows = (lastRow - firstRow + 1) < 0? 0: (lastRow - firstRow + 1); - - rectCopy = (uint8*)malloc(copyLength * copyRows * bytesPerPixel); - - srcAddress = bitmapBits + (((firstRow) * Bwidth + firstCol) * bytesPerPixel); - destAddress = rectCopy; - - for (int32 j = 0; j < copyRows; j++) - { - uint8 *destRowAddress = destAddress + (j * copyLength * bytesPerPixel); - uint8 *srcRowAddress = srcAddress + (j * Bwidth * bytesPerPixel); - memcpy(destRowAddress, srcRowAddress, copyLength * bytesPerPixel ); - } - - rectList.AddItem(rectCopy); - } - } - - int32 item = 0; - for(k=0; k < rCount; k++) - { - BRegion *reg = (BRegion*)list->ItemAt(k); - - int32 rectCount = reg->CountRects(); - for(i=0; i < rectCount; i++) - { - BRect r = reg->RectAt(i); - uint8 *rectCopy; - uint8 *srcAddress; - uint8 *destAddress; - int32 firstRow, lastRow; - int32 firstCol, lastCol; - int32 copyLength, copyLength2; - int32 copyRows, copyRows2; - - firstRow = (int32)(r.top < 0? 0: r.top); - lastRow = (int32)(r.bottom > (Bheight-1)? (Bheight-1): r.bottom); - firstCol = (int32)(r.left < 0? 0: r.left); - lastCol = (int32)(r.right > (Bwidth-1)? (Bwidth-1): r.right); - copyLength = (lastCol - firstCol + 1) < 0? 0: (lastCol - firstCol + 1); - copyRows = (lastRow - firstRow + 1) < 0? 0: (lastRow - firstRow + 1); - - rectCopy = (uint8*)rectList.ItemAt(item++); - - srcAddress = rectCopy; - - r.Set(firstCol, firstRow, lastCol, lastRow); - r.OffsetBy( *((BPoint*)pList->ItemAt(k%rCount)) ); - firstRow = (int32)(r.top < 0? 0: r.top); - lastRow = (int32)(r.bottom > (Bheight-1)? (Bheight-1): r.bottom); - firstCol = (int32)(r.left < 0? 0: r.left); - lastCol = (int32)(r.right > (Bwidth-1)? (Bwidth-1): r.right); - copyLength2 = (lastCol - firstCol + 1) < 0? 0: (lastCol - firstCol + 1); - copyRows2 = (lastRow - firstRow + 1) < 0? 0: (lastRow - firstRow + 1); - - destAddress = bitmapBits + (((firstRow) * Bwidth + firstCol) * bytesPerPixel); - - int32 minLength = copyLength < copyLength2? copyLength: copyLength2; - int32 minRows = copyRows < copyRows2? copyRows: copyRows2; - - for (int32 j = 0; j < minRows; j++) - { - uint8 *destRowAddress = destAddress + (j * Bwidth * bytesPerPixel); - uint8 *srcRowAddress = srcAddress + (j * copyLength * bytesPerPixel); - memcpy(destRowAddress, srcRowAddress, minLength * bytesPerPixel ); - } - } - } - - for(i=0; i < rectList.CountItems(); i++) - { - void *rectCopy; - rectCopy = rectList.ItemAt(i); - if (rectCopy) - free(rectCopy); - } - rectList.MakeEmpty(); - - fCursorHandler.DriverShow(); - - BRect inval(bmp->Bounds()); - ReleaseBuffer(); - Unlock(); - -// ConstrainClippingRegion(clipReg); - Invalidate(inval); -// ConstrainClippingRegion(NULL); -} - -/*! - \brief Called for all BView::FillArc calls - \param r Rectangle enclosing the entire arc - \param angle Starting angle for the arc in degrees - \param span Span of the arc in degrees. Ending angle = angle+span. - \param d Object holding the bazillion other options -*/ -void DisplayDriverImpl::FillArc(const BRect &r, const float &angle, const float &span, const DrawData *d) -{ - if(fCursorHandler.IntersectsCursor(r)) - fCursorHandler.DriverHide(); - - float xc = (r.left+r.right)/2; - float yc = (r.top+r.bottom)/2; - float rx = r.Width()/2; - float ry = r.Height()/2; - int Rx2 = ROUND(rx*rx); - int Ry2 = ROUND(ry*ry); - int twoRx2 = 2*Rx2; - int twoRy2 = 2*Ry2; - int p; - int x=0; - int y = (int)ry; - int px = 0; - int py = twoRx2 * y; - int startx, endx; - int starty, endy; - int xclip, startclip, endclip; - int startQuad, endQuad; - bool useQuad1, useQuad2, useQuad3, useQuad4; - bool shortspan = false; - DrawData data; - - // Watch out for bozos giving us whacko spans - if ( (span >= 360) || (span <= -360) ) - { - FillEllipse(r,d); - fCursorHandler.DriverShow(); - return; - } - - Lock(); - - data = *d; - data.pensize = 1; - - if ( span > 0 ) - { - startQuad = (int)(angle/90)%4+1; - endQuad = (int)((angle+span)/90)%4+1; - startx = ROUND(.5*r.Width()*fabs(cos(angle*M_PI/180))); - endx = ROUND(.5*r.Width()*fabs(cos((angle+span)*M_PI/180))); - } - else - { - endQuad = (int)(angle/90)%4+1; - startQuad = (int)((angle+span)/90)%4+1; - endx = ROUND(.5*r.Width()*fabs(cos(angle*M_PI/180))); - startx = ROUND(.5*r.Width()*fabs(cos((angle+span)*M_PI/180))); - } - - starty = ROUND(ry*sqrt(1-(double)startx*startx/(rx*rx))); - endy = ROUND(ry*sqrt(1-(double)endx*endx/(rx*rx))); - - if ( startQuad != endQuad ) - { - useQuad1 = (endQuad > 1) && (startQuad > endQuad); - useQuad2 = ((startQuad == 1) && (endQuad > 2)) || ((startQuad > endQuad) && (endQuad > 2)); - useQuad3 = ((startQuad < 3) && (endQuad == 4)) || ((startQuad < 3) && (endQuad < startQuad)); - useQuad4 = (startQuad < 4) && (startQuad > endQuad); - } - else - { - if ( (span < 90) && (span > -90) ) - { - useQuad1 = false; - useQuad2 = false; - useQuad3 = false; - useQuad4 = false; - shortspan = true; - } - else - { - useQuad1 = (startQuad != 1); - useQuad2 = (startQuad != 2); - useQuad3 = (startQuad != 3); - useQuad4 = (startQuad != 4); - } - } - - if ( useQuad1 ) - StrokeLine(BPoint(xc,yc-y),BPoint(xc+x,yc-y),&data); - if ( useQuad2 ) - StrokeLine(BPoint(xc,yc-y),BPoint(xc-x,yc-y),&data); - if ( useQuad3 ) - StrokeLine(BPoint(xc,yc+y),BPoint(xc-x,yc+y),&data); - if ( useQuad4 ) - StrokeLine(BPoint(xc,yc+y),BPoint(xc+x,yc+y),&data); - - p = ROUND (Ry2 - (Rx2 * ry) + (.25 * Rx2)); - while (px < py) - { - x++; - px += twoRy2; - if ( p < 0 ) - p += Ry2 + px; - else - { - y--; - py -= twoRx2; - p += Ry2 + px - py; - } - - if ( useQuad1 ) - StrokeLine(BPoint(xc,yc-y),BPoint(xc+x,yc-y),&data); - if ( useQuad2 ) - StrokeLine(BPoint(xc,yc-y),BPoint(xc-x,yc-y),&data); - if ( useQuad3 ) - StrokeLine(BPoint(xc,yc+y),BPoint(xc-x,yc+y),&data); - if ( useQuad4 ) - StrokeLine(BPoint(xc,yc+y),BPoint(xc+x,yc+y),&data); - if ( !shortspan ) - { - if ( startQuad == 1 ) - { - if ( x <= startx ) - StrokeLine(BPoint(xc,yc-y),BPoint(xc+x,yc-y),&data); - else - { - xclip = ROUND(y*startx/(double)starty); - StrokeLine(BPoint(xc,yc-y),BPoint(xc+xclip,yc-y),&data); - } - } - else if ( startQuad == 2 ) - { - if ( x >= startx ) - { - xclip = ROUND(y*startx/(double)starty); - StrokeLine(BPoint(xc-x,yc-y),BPoint(xc-xclip,yc-y),&data); - } - } - else if ( startQuad == 3 ) - { - if ( x <= startx ) - StrokeLine(BPoint(xc-x,yc+y),BPoint(xc,yc+y),&data); - else - { - xclip = ROUND(y*startx/(double)starty); - StrokeLine(BPoint(xc-xclip,yc+y),BPoint(xc,yc+y),&data); - } - } - else if ( startQuad == 4 ) - { - if ( x >= startx ) - { - xclip = ROUND(y*startx/(double)starty); - StrokeLine(BPoint(xc+xclip,yc+y),BPoint(xc+x,yc+y),&data); - } - } - - if ( endQuad == 1 ) - { - if ( x >= endx ) - { - xclip = ROUND(y*endx/(double)endy); - StrokeLine(BPoint(xc+xclip,yc-y),BPoint(xc+x,yc-y),&data); - } - } - else if ( endQuad == 2 ) - { - if ( x <= endx ) - StrokeLine(BPoint(xc-x,yc-y),BPoint(xc,yc-y),&data); - else - { - xclip = ROUND(y*endx/(double)endy); - StrokeLine(BPoint(xc-xclip,yc-y),BPoint(xc,yc-y),&data); - } - } - else if ( endQuad == 3 ) - { - if ( x >= endx ) - { - xclip = ROUND(y*endx/(double)endy); - StrokeLine(BPoint(xc-x,yc+y),BPoint(xc-xclip,yc+y),&data); - } - } - else if ( endQuad == 4 ) - { - if ( x <= endx ) - StrokeLine(BPoint(xc,yc+y),BPoint(xc+x,yc+y),&data); - else - { - xclip = ROUND(y*endx/(double)endy); - StrokeLine(BPoint(xc,yc+y),BPoint(xc+xclip,yc+y),&data); - } - } - } - else - { - startclip = ROUND(y*startx/(double)starty); - endclip = ROUND(y*endx/(double)endy); - if ( startQuad == 1 ) - { - if ( (x <= startx) && (x >= endx) ) - StrokeLine(BPoint(xc+endclip,yc-y),BPoint(xc+x,yc-y),&data); - else - StrokeLine(BPoint(xc+endclip,yc-y),BPoint(xc+startclip,yc-y),&data); - } - else if ( startQuad == 2 ) - { - if ( (x <= startx) && (x >= endx) ) - StrokeLine(BPoint(xc-x,yc-y),BPoint(xc-startclip,yc-y),&data); - else - StrokeLine(BPoint(xc-endclip,yc-y),BPoint(xc-startclip,yc-y),&data); - } - else if ( startQuad == 3 ) - { - if ( (x <= startx) && (x >= endx) ) - StrokeLine(BPoint(xc-x,yc+y),BPoint(xc-endclip,yc+y),&data); - else - StrokeLine(BPoint(xc-startclip,yc+y),BPoint(xc-endclip,yc+y),&data); - } - else if ( startQuad == 4 ) - { - if ( (x <= startx) && (x >= endx) ) - StrokeLine(BPoint(xc+startclip,yc+y),BPoint(xc+x,yc+y),&data); - else - StrokeLine(BPoint(xc+startclip,yc+y),BPoint(xc+endclip,yc+y),&data); - } - } - } - - p = ROUND(Ry2*(x+.5)*(x+.5) + Rx2*(y-1)*(y-1) - Rx2*Ry2); - while (y>0) - { - y--; - py -= twoRx2; - if (p>0) - p += Rx2 - py; - else - { - x++; - px += twoRy2; - p += Rx2 - py +px; - } - - if ( useQuad1 ) - StrokeLine(BPoint(xc,yc-y),BPoint(xc+x,yc-y),&data); - if ( useQuad2 ) - StrokeLine(BPoint(xc,yc-y),BPoint(xc-x,yc-y),&data); - if ( useQuad3 ) - StrokeLine(BPoint(xc,yc+y),BPoint(xc-x,yc+y),&data); - if ( useQuad4 ) - StrokeLine(BPoint(xc,yc+y),BPoint(xc+x,yc+y),&data); - if ( !shortspan ) - { - if ( startQuad == 1 ) - { - if ( x <= startx ) - StrokeLine(BPoint(xc,yc-y),BPoint(xc+x,yc-y),&data); - else - { - xclip = ROUND(y*startx/(double)starty); - StrokeLine(BPoint(xc,yc-y),BPoint(xc+xclip,yc-y),&data); - } - } - else if ( startQuad == 2 ) - { - if ( x >= startx ) - { - xclip = ROUND(y*startx/(double)starty); - StrokeLine(BPoint(xc-x,yc-y),BPoint(xc-xclip,yc-y),&data); - } - } - else if ( startQuad == 3 ) - { - if ( x <= startx ) - StrokeLine(BPoint(xc-x,yc+y),BPoint(xc,yc+y),&data); - else - { - xclip = ROUND(y*startx/(double)starty); - StrokeLine(BPoint(xc-xclip,yc+y),BPoint(xc,yc+y),&data); - } - } - else if ( startQuad == 4 ) - { - if ( x >= startx ) - { - xclip = ROUND(y*startx/(double)starty); - StrokeLine(BPoint(xc+xclip,yc+y),BPoint(xc+x,yc+y),&data); - } - } - - if ( endQuad == 1 ) - { - if ( x >= endx ) - { - xclip = ROUND(y*endx/(double)endy); - StrokeLine(BPoint(xc+xclip,yc-y),BPoint(xc+x,yc-y),&data); - } - } - else if ( endQuad == 2 ) - { - if ( x <= endx ) - StrokeLine(BPoint(xc-x,yc-y),BPoint(xc,yc-y),&data); - else - { - xclip = ROUND(y*endx/(double)endy); - StrokeLine(BPoint(xc-xclip,yc-y),BPoint(xc,yc-y),&data); - } - } - else if ( endQuad == 3 ) - { - if ( x >= endx ) - { - xclip = ROUND(y*endx/(double)endy); - StrokeLine(BPoint(xc-x,yc+y),BPoint(xc-xclip,yc+y),&data); - } - } - else if ( endQuad == 4 ) - { - if ( x <= endx ) - StrokeLine(BPoint(xc,yc+y),BPoint(xc+x,yc+y),&data); - else - { - xclip = ROUND(y*endx/(double)endy); - StrokeLine(BPoint(xc,yc+y),BPoint(xc+xclip,yc+y),&data); - } - } - } - else - { - startclip = ROUND(y*startx/(double)starty); - endclip = ROUND(y*endx/(double)endy); - if ( startQuad == 1 ) - { - if ( (x <= startx) && (x >= endx) ) - StrokeLine(BPoint(xc+endclip,yc-y),BPoint(xc+x,yc-y),&data); - else - StrokeLine(BPoint(xc+endclip,yc-y),BPoint(xc+startclip,yc-y),&data); - } - else if ( startQuad == 2 ) - { - if ( (x <= startx) && (x >= endx) ) - StrokeLine(BPoint(xc-x,yc-y),BPoint(xc-startclip,yc-y),&data); - else - StrokeLine(BPoint(xc-endclip,yc-y),BPoint(xc-startclip,yc-y),&data); - } - else if ( startQuad == 3 ) - { - if ( (x <= startx) && (x >= endx) ) - StrokeLine(BPoint(xc-x,yc+y),BPoint(xc-endclip,yc+y),&data); - else - StrokeLine(BPoint(xc-startclip,yc+y),BPoint(xc-endclip,yc+y),&data); - } - else if ( startQuad == 4 ) - { - if ( (x <= startx) && (x >= endx) ) - StrokeLine(BPoint(xc+startclip,yc+y),BPoint(xc+x,yc+y),&data); - else - StrokeLine(BPoint(xc+startclip,yc+y),BPoint(xc+endclip,yc+y),&data); - } - } - } - fCursorHandler.DriverShow(); - Invalidate(r); - Unlock(); -} - -/*! - \brief Called for all BView::FillBezier calls. - \param pts 4-element array of BPoints in the order of start, end, and then the two control - points. - \param d draw data -*/ -void DisplayDriverImpl::FillBezier(BPoint *pts, const DrawData *d) -{ - Lock(); - - BezierCurve curve(pts); - - if(fCursorHandler.IntersectsCursor(curve.Frame())) - fCursorHandler.DriverHide(); - - FillPolygon(curve.GetPointArray(), curve.points.CountItems(), curve.Frame(), d); - - fCursorHandler.DriverShow(); - Unlock(); -} - -/*! - \brief Called for all BView::FillEllipse calls - \param r BRect enclosing the ellipse to be drawn. - \param d DrawData containing the endless options -*/ -void DisplayDriverImpl::FillEllipse(const BRect &r, const DrawData *d) -{ - float xc = (r.left+r.right)/2; - float yc = (r.top+r.bottom)/2; - float rx = r.Width()/2; - float ry = r.Height()/2; - int Rx2 = ROUND(rx*rx); - int Ry2 = ROUND(ry*ry); - int twoRx2 = 2*Rx2; - int twoRy2 = 2*Ry2; - int p; - int x=0; - int y = (int)ry; - int px = 0; - int py = twoRx2 * y; - DrawData data; - - Lock(); - - if(fCursorHandler.IntersectsCursor(r)) - fCursorHandler.DriverHide(); - - data = *d; - data.pensize = 1; - - StrokeLine(BPoint(xc,yc-y),BPoint(xc,yc-y),&data); - StrokeLine(BPoint(xc,yc+y),BPoint(xc,yc+y),&data); - - p = ROUND (Ry2 - (Rx2 * ry) + (.25 * Rx2)); - while (px < py) - { - x++; - px += twoRy2; - if ( p < 0 ) - p += Ry2 + px; - else - { - y--; - py -= twoRx2; - p += Ry2 + px - py; - } - - StrokeLine(BPoint(xc-x,yc-y),BPoint(xc+x,yc-y),&data); - StrokeLine(BPoint(xc-x,yc+y),BPoint(xc+x,yc+y),&data); - } - - p = ROUND(Ry2*(x+.5)*(x+.5) + Rx2*(y-1)*(y-1) - Rx2*Ry2); - while (y>0) - { - y--; - py -= twoRx2; - if (p>0) - p += Rx2 - py; - else - { - x++; - px += twoRy2; - p += Rx2 - py +px; - } - - StrokeLine(BPoint(xc-x,yc-y),BPoint(xc+x,yc-y),&data); - StrokeLine(BPoint(xc-x,yc+y),BPoint(xc+x,yc+y),&data); - } - fCursorHandler.DriverShow(); - Invalidate(r); - Unlock(); -} - -/*! - \brief Called for all BView::FillPolygon calls - \param ptlist Array of BPoints defining the polygon. - \param numpts Number of points in the BPoint array. - \param d The 50 bazillion drawing options (inluding clip region) -*/ -void DisplayDriverImpl::FillPolygon(BPoint *ptlist, int32 numpts, const BRect &bounds, const DrawData *d) -{ - // Here's the plan. Record all line segments in polygon. If a line segments crosses - // the y-value of a point not in the segment, split the segment into 2 segments. - // Once we have gone through all of the segments, sort them primarily on y-value - // and secondarily on x-value. Step through each y-value in the bounding rectangle - // and look for intersections with line segments. First intersection is start of - // horizontal line, second intersection is end of horizontal line. Continue for - // all pairs of intersections. Watch out for horizontal line segments. - if ( !ptlist || (numpts < 3) ) - return; - - Lock(); - - if(fCursorHandler.IntersectsCursor(bounds)) - fCursorHandler.DriverHide(); - - BPoint *currentPoint, *nextPoint; - BPoint tempNextPoint; - BPoint tempCurrentPoint; - int currentIndex, bestIndex, i, j, y; - LineCalc *segmentArray = new LineCalc[2*numpts]; - int numSegments = 0; - int minX, minY, maxX, maxY; - - minX = ROUND(ptlist[0].x); - maxX = ROUND(ptlist[0].x); - minY = ROUND(ptlist[0].y); - maxY = ROUND(ptlist[0].y); - - // Generate the segment list - currentPoint = ptlist; - currentIndex = 0; - nextPoint = &ptlist[1]; - while (currentPoint) - { - if ( numSegments >= 2*numpts ) - { - printf("ERROR: Insufficient memory allocated to segment array\n"); - delete[] segmentArray; - fCursorHandler.DriverShow(); - Unlock(); - return; - } - - if ( ROUND(currentPoint->x) < minX ) - minX = ROUND(currentPoint->x); - if ( ROUND(currentPoint->x) > maxX ) - maxX = ROUND(currentPoint->x); - if ( ROUND(currentPoint->y) < minY ) - minY = ROUND(currentPoint->y); - if ( ROUND(currentPoint->y) > maxY ) - maxY = ROUND(currentPoint->y); - - for (i=0; i currentPoint->y) && (ptlist[i].y < nextPoint->y)) || - ((ptlist[i].y < currentPoint->y) && (ptlist[i].y > nextPoint->y)) ) - { - segmentArray[numSegments].SetPoints(*currentPoint,*nextPoint); - tempNextPoint.x = segmentArray[numSegments].GetX(ptlist[i].y); - tempNextPoint.y = ptlist[i].y; - nextPoint = &tempNextPoint; - } - } - - segmentArray[numSegments].SetPoints(*currentPoint,*nextPoint); - numSegments++; - if ( nextPoint == &tempNextPoint ) - { - tempCurrentPoint = tempNextPoint; - currentPoint = &tempCurrentPoint; - nextPoint = &ptlist[(currentIndex+1)%numpts]; - } - else if ( nextPoint == ptlist ) - { - currentPoint = NULL; - } - else - { - currentPoint = nextPoint; - currentIndex++; - nextPoint = &ptlist[(currentIndex+1)%numpts]; - } - } - - // Selection sort the segments. Probably should replace this later. - for (i=0; iclipReg ) - { - // Draw the lines - for (y=minY; y<=maxY; y++) - { - i = 0; - while (i y) - break; - if (segmentArray[i].MaxY() < y) - { - i++; - continue; - } - if (segmentArray[i].MinY() == segmentArray[i].MaxY()) - { - if ( (segmentArray[i].MinX() < fDisplayMode.virtual_width) && - (segmentArray[i].MaxX() >= 0) ) - StrokePatternLine(ROUND(segmentArray[i].MinX()), y, - ROUND(segmentArray[i].MaxX()), y, d); - i++; - } - else - { - if ( (segmentArray[i+1].GetX(y) < fDisplayMode.virtual_width) && - (segmentArray[i].GetX(y) >= 0) ) - StrokePatternLine(ROUND(segmentArray[i].GetX(y)), y, - ROUND(segmentArray[i+1].GetX(y)), y, d); - i+=2; - } - } - } - } - else - { - int numRects, rectIndex; - int yStart, yEnd; - BRect clipRect; - numRects = d->clipReg->CountRects(); - for (rectIndex = 0; rectIndex < numRects; rectIndex++) - { - clipRect = d->clipReg->RectAt(rectIndex); - if ( clipRect.bottom < minY ) - continue; - if ( clipRect.top > maxY ) - continue; - if ( clipRect.left < minX ) - continue; - if ( clipRect.right > maxX ) - continue; - yStart = MAX(minY,ROUND(clipRect.top)); - yEnd = MIN(maxY,ROUND(clipRect.bottom)); - - // Draw the lines - for (y=yStart; y<=yEnd; y++) - { - i = 0; - while (i y) - break; - if (segmentArray[i].MaxY() < y) - { - i++; - continue; - } - if (segmentArray[i].MinY() == segmentArray[i].MaxY()) - { - if (segmentArray[i].MinX() > clipRect.right) - { - i++; - continue; - } - if (segmentArray[i].MaxX() < clipRect.left) - { - i++; - continue; - } - StrokePatternLine(ROUND(MAX(segmentArray[i].MinX(),clipRect.left)), y, - ROUND(MIN(segmentArray[i].MaxX(),clipRect.right)), y, d); - i++; - } - else - { - if (segmentArray[i].GetX(y) > clipRect.right) - { - i+=2; - continue; - } - if (segmentArray[i+1].GetX(y) < clipRect.left) - { - i+=2; - continue; - } - StrokePatternLine(ROUND(MAX(segmentArray[i].GetX(y),clipRect.left)), y, - ROUND(MIN(segmentArray[i+1].GetX(y),clipRect.right)), y, d); - i+=2; - } - } - } - } - } - delete[] segmentArray; - fCursorHandler.DriverShow(); - Invalidate(bounds); - Unlock(); -} - -/*! - \brief Called for all BView::FillRect calls - \param r BRect to be filled. Guaranteed to be in the frame buffer's coordinate space - \param color The color used to fill the rectangle -*/ -void DisplayDriverImpl::FillRect(const BRect &r, const RGBColor &color) -{ - Lock(); - if(fCursorHandler.IntersectsCursor(r)) - fCursorHandler.DriverHide(); - - FillSolidRect(r,color); - fCursorHandler.DriverShow(); - Unlock(); -} - -/*! - \brief Called for all BView::FillRect calls - \param r BRect to be filled. Guaranteed to be in the frame buffer's coordinate space - \param pattern The pattern used to fill the rectangle - \param high_color The high color of the pattern - \param low_color The low color of the pattern -*/ -void DisplayDriverImpl::FillRect(const BRect &r, const DrawData *d) -{ - if(!d) - return; - - Lock(); - if(fCursorHandler.IntersectsCursor(r)) - fCursorHandler.DriverHide(); - if ( d->clipReg ) - { - if ( d->clipReg->Intersects(r) ) - { - BRegion reg(r); - reg.IntersectWith(d->clipReg); - int numRects = reg.CountRects(); - - for(int32 i=0; iclipReg ) - { - BRegion drawReg = r; - - drawReg.IntersectWith(d->clipReg); - numRects = drawReg.CountRects(); - - for(int32 i=0; iclipReg ) - { - int numRects, rectIndex; - BRect clipRect; - int left, right, y1, y2; - int rectTop, rectBottom, rectLeft, rectRight; - - numRects = d->clipReg->CountRects(); - for (rectIndex=0; rectIndexclipReg->RectAt(rectIndex); - rectTop = ROUND(clipRect.top); - rectBottom = ROUND(clipRect.bottom); - rectLeft = ROUND(clipRect.left); - rectRight = ROUND(clipRect.right); - for (i=0; i<=(int)yrad; i++) - { - arc_x = xrad*sqrt(1-i*i/yrad2); - left = ROUND(r.left + xrad - arc_x); - right = ROUND(r.right - xrad + arc_x); - if ( (left > rectRight) || (right < rectLeft) ) - continue; - y1 = ROUND(r.top + yrad - i); - y2 = ROUND(r.bottom - yrad + i); - if ( (y1 >= rectTop) && (y1 <= rectBottom) ) - StrokePatternLine(MAX(left,rectLeft), y1, MIN(right,rectRight), y1,d); - if ( (y2 >= rectTop) && (y2 <= rectBottom) ) - StrokePatternLine(MAX(left,rectLeft), y2, MIN(right,rectRight), y2,d); - } - } - } - else - { - for (i=0; i<=(int)yrad; i++) - { - arc_x = xrad*sqrt(1-i*i/yrad2); - StrokePatternLine(ROUND(r.left+xrad-arc_x), ROUND(r.top+yrad-i), ROUND(r.right-xrad+arc_x), ROUND(r.top+yrad-i),d); - StrokePatternLine(ROUND(r.left+xrad-arc_x), ROUND(r.bottom-yrad+i), ROUND(r.right-xrad+arc_x), ROUND(r.bottom-yrad+i),d); - } - } - FillPatternRect(BRect(r.left,r.top+yrad,r.right,r.bottom-yrad),d); - fCursorHandler.DriverShow(); - Invalidate(r); - Unlock(); -} - -void DisplayDriverImpl::FillShape(const BRect &bounds, const int32 &opcount, const int32 *oplist, - const int32 &ptcount, const BPoint *ptlist, const DrawData *d) -{ - // TODO: Implement DisplayDriverImpl::FillShape. How, though? AGG backend? - printf("DisplayDriverImpl::FillShape unimplemented\n"); -} - -/*! - \brief Called for all BView::FillTriangle calls - \param pts Array of 3 BPoints. Always non-NULL. - \param setLine Horizontal line drawing routine which handles things like color and pattern. -*/ -void DisplayDriverImpl::FillTriangle(BPoint *pts, const BRect &bounds, const DrawData *d) -{ - if ( !pts ) - return; - - Lock(); - - if(fCursorHandler.IntersectsCursor(bounds)) - fCursorHandler.DriverHide(); - - if ( d->clipReg ) - { - // For now, cop out and use FillPolygon - // Need to investigate if Triangle specific code would save processing time - FillPolygon(pts,3,bounds,d); - fCursorHandler.DriverShow(); - } - else - { - BPoint first, second, third; - - // Sort points according to their y values and x values (y is primary) - if ( (pts[0].y < pts[1].y) || - ((pts[0].y == pts[1].y) && (pts[0].x <= pts[1].x)) ) - { - first=pts[0]; - second=pts[1]; - } - else - { - first=pts[1]; - second=pts[0]; - } - - if ( (second.y= 360) || (span <= -360) ) - { - StrokeEllipse(r,d); - fCursorHandler.DriverShow(); - Unlock(); - return; - } - - if ( span > 0 ) - { - startQuad = (int)(angle/90)%4+1; - endQuad = (int)((angle+span)/90)%4+1; - startx = ROUND(.5*r.Width()*fabs(cos(angle*M_PI/180))); - endx = ROUND(.5*r.Width()*fabs(cos((angle+span)*M_PI/180))); - } - else - { - endQuad = (int)(angle/90)%4+1; - startQuad = (int)((angle+span)/90)%4+1; - endx = ROUND(.5*r.Width()*fabs(cos(angle*M_PI/180))); - startx = ROUND(.5*r.Width()*fabs(cos((angle+span)*M_PI/180))); - } - - if ( startQuad != endQuad ) - { - useQuad1 = (endQuad > 1) && (startQuad > endQuad); - useQuad2 = ((startQuad == 1) && (endQuad > 2)) || ((startQuad > endQuad) && (endQuad > 2)); - useQuad3 = ((startQuad < 3) && (endQuad == 4)) || ((startQuad < 3) && (endQuad < startQuad)); - useQuad4 = (startQuad < 4) && (startQuad > endQuad); - } - else - { - if ( (span < 90) && (span > -90) ) - { - useQuad1 = false; - useQuad2 = false; - useQuad3 = false; - useQuad4 = false; - shortspan = true; - } - else - { - useQuad1 = (startQuad != 1); - useQuad2 = (startQuad != 2); - useQuad3 = (startQuad != 3); - useQuad4 = (startQuad != 4); - } - } - - if ( useQuad1 || - (!shortspan && (((startQuad == 1) && (x <= startx)) || ((endQuad == 1) && (x >= endx)))) || - (shortspan && (startQuad == 1) && (x <= startx) && (x >= endx)) ) - StrokePoint(BPoint(xc+x,yc-y),d); - if ( useQuad2 || - (!shortspan && (((startQuad == 2) && (x >= startx)) || ((endQuad == 2) && (x <= endx)))) || - (shortspan && (startQuad == 2) && (x >= startx) && (x <= endx)) ) - StrokePoint(BPoint(xc-x,yc-y),d); - if ( useQuad3 || - (!shortspan && (((startQuad == 3) && (x <= startx)) || ((endQuad == 3) && (x >= endx)))) || - (shortspan && (startQuad == 3) && (x <= startx) && (x >= endx)) ) - StrokePoint(BPoint(xc-x,yc+y),d); - if ( useQuad4 || - (!shortspan && (((startQuad == 4) && (x >= startx)) || ((endQuad == 4) && (x <= endx)))) || - (shortspan && (startQuad == 4) && (x >= startx) && (x <= endx)) ) - StrokePoint(BPoint(xc+x,yc+y),d); - - p = ROUND (Ry2 - (Rx2 * ry) + (.25 * Rx2)); - while (px < py) - { - x++; - px += twoRy2; - if ( p < 0 ) - p += Ry2 + px; - else - { - y--; - py -= twoRx2; - p += Ry2 + px - py; - } - - if ( useQuad1 || - (!shortspan && (((startQuad == 1) && (x <= startx)) || ((endQuad == 1) && (x >= endx)))) || - (shortspan && (startQuad == 1) && (x <= startx) && (x >= endx)) ) - StrokePoint(BPoint(xc+x,yc-y),d); - if ( useQuad2 || - (!shortspan && (((startQuad == 2) && (x >= startx)) || ((endQuad == 2) && (x <= endx)))) || - (shortspan && (startQuad == 2) && (x >= startx) && (x <= endx)) ) - StrokePoint(BPoint(xc-x,yc-y),d); - if ( useQuad3 || - (!shortspan && (((startQuad == 3) && (x <= startx)) || ((endQuad == 3) && (x >= endx)))) || - (shortspan && (startQuad == 3) && (x <= startx) && (x >= endx)) ) - StrokePoint(BPoint(xc-x,yc+y),d); - if ( useQuad4 || - (!shortspan && (((startQuad == 4) && (x >= startx)) || ((endQuad == 4) && (x <= endx)))) || - (shortspan && (startQuad == 4) && (x >= startx) && (x <= endx)) ) - StrokePoint(BPoint(xc+x,yc+y),d); - } - - p = ROUND(Ry2*(x+.5)*(x+.5) + Rx2*(y-1)*(y-1) - Rx2*Ry2); - while (y>0) - { - y--; - py -= twoRx2; - if (p>0) - p += Rx2 - py; - else - { - x++; - px += twoRy2; - p += Rx2 - py +px; - } - - if ( useQuad1 || - (!shortspan && (((startQuad == 1) && (x <= startx)) || ((endQuad == 1) && (x >= endx)))) || - (shortspan && (startQuad == 1) && (x <= startx) && (x >= endx)) ) - StrokePoint(BPoint(xc+x,yc-y),d); - if ( useQuad2 || - (!shortspan && (((startQuad == 2) && (x >= startx)) || ((endQuad == 2) && (x <= endx)))) || - (shortspan && (startQuad == 2) && (x >= startx) && (x <= endx)) ) - StrokePoint(BPoint(xc-x,yc-y),d); - if ( useQuad3 || - (!shortspan && (((startQuad == 3) && (x <= startx)) || ((endQuad == 3) && (x >= endx)))) || - (shortspan && (startQuad == 3) && (x <= startx) && (x >= endx)) ) - StrokePoint(BPoint(xc-x,yc+y),d); - if ( useQuad4 || - (!shortspan && (((startQuad == 4) && (x >= startx)) || ((endQuad == 4) && (x <= endx)))) || - (shortspan && (startQuad == 4) && (x >= startx) && (x <= endx)) ) - StrokePoint(BPoint(xc+x,yc+y),d); - } - fCursorHandler.DriverShow(); - Invalidate(r); - Unlock(); -} - -/*! - \brief Called for all BView::StrokeBezier calls. - \param pts 4-element array of BPoints in the order of start, end, and then the two control points. - \param d draw data -*/ -void DisplayDriverImpl::StrokeBezier(BPoint *pts, const DrawData *d) -{ - int i, numLines; - - Lock(); - BezierCurve curve(pts); - - if(fCursorHandler.IntersectsCursor(curve.Frame())) - fCursorHandler.DriverHide(); - - numLines = curve.points.CountItems()-1; - for (i=0; i0) - { - lastx = x; - lasty = y; - y--; - py -= twoRx2; - if (p>0) - p += Rx2 - py; - else - { - x++; - px += twoRy2; - p += Rx2 - py +px; - } - - StrokeLine(BPoint(xc+lastx,yc-lasty),BPoint(xc+x,yc-y),d); - StrokeLine(BPoint(xc-lastx,yc-lasty),BPoint(xc-x,yc-y),d); - StrokeLine(BPoint(xc-lastx,yc+lasty),BPoint(xc-x,yc+y),d); - StrokeLine(BPoint(xc+lastx,yc+lasty),BPoint(xc+x,yc+y),d); - } - fCursorHandler.DriverShow(); - Invalidate(r); - Unlock(); -} - -/*! - \brief Draws a line. Really. - \param start Starting point - \param end Ending point - \param c The color of the line -*/ -void DisplayDriverImpl::StrokeLine(const BPoint &start, const BPoint &end, const RGBColor &color) -{ - Lock(); - if(fCursorHandler.IntersectsCursor(BRect(start,end))) - fCursorHandler.DriverHide(); - StrokeSolidLine(ROUND(start.x),ROUND(start.y),ROUND(end.x),ROUND(end.y),color); - - fCursorHandler.DriverShow(); - Invalidate(BRect(start,end)); - Unlock(); -} - -/*! - \brief Draws a line. Really. - \param start Starting point - \param end Ending point - \param d The relevant drawing data for this line -*/ -void DisplayDriverImpl::StrokeLine(const BPoint &start, const BPoint &end, DrawData *d) -{ - Lock(); - - if(fCursorHandler.IntersectsCursor(BRect(start,end))) - fCursorHandler.DriverHide(); - - if ( d->pensize == 1 ) - { - if ( d->clipReg ) - { - int i, numRects; - double left, right, y1, y2; - BRect clipRect; - LineCalc line(start,end); - numRects = d->clipReg->CountRects(); - for (i=0; iclipReg->RectAt(i); - left = MAX(line.MinX(), clipRect.left); - right = MIN(line.MaxX(), clipRect.right); - if ( right < left ) - continue; - y1 = line.GetY(left); - y2 = line.GetY(right); - if ( MAX(y1,y2) < clipRect.top ) - continue; - if ( MIN(y1,y2) > clipRect.bottom ) - continue; - if ( y1 < clipRect.top ) - { - y1 = clipRect.top; - left = line.GetX(y1); - } - if ( y1 > clipRect.bottom ) - { - y1 = clipRect.bottom; - left = line.GetX(y1); - } - if ( y2 < clipRect.top ) - { - y2 = clipRect.top; - right = line.GetX(y2); - } - if ( y2 > clipRect.bottom ) - { - y2 = clipRect.bottom; - right = line.GetX(y2); - } - StrokePatternLine(ROUND(left),ROUND(y1),ROUND(right),ROUND(y2),d); - } - } - else - StrokePatternLine(ROUND(start.x),ROUND(start.y),ROUND(end.x),ROUND(end.y),d); - } - else - { - BPoint corners[4]; - double halfWidth = .5*d->pensize; - corners[0] = start; - corners[1] = start; - corners[2] = end; - corners[3] = end; - if ( (start.x == end.x) && (start.y == end.y) ) - { - FillRect(BRect(start.x-halfWidth,start.y-halfWidth,start.x+halfWidth,start.y+halfWidth),d); - } - else - { - if ( start.x == end.x ) - { - corners[0].x += halfWidth; - corners[1].x -= halfWidth; - corners[2].x -= halfWidth; - corners[3].x += halfWidth; - } - else if ( start.y == end.y ) - { - corners[0].y -= halfWidth; - corners[1].y += halfWidth; - corners[2].y += halfWidth; - corners[3].y -= halfWidth; - } - else - { - double angle, xoffset, yoffset; - // TODO try to find a way to avoid atan2, sin, and cos - angle = atan2(end.y-start.y, end.x-start.x) + M_PI/4; - xoffset = halfWidth*cos(angle); - yoffset = halfWidth*sin(angle); - corners[0].x += xoffset; - corners[0].y += yoffset; - corners[1].x -= xoffset; - corners[1].y -= yoffset; - corners[2].x -= xoffset; - corners[2].y -= yoffset; - corners[3].x += xoffset; - corners[3].y += yoffset; - } - FillPolygon(corners,4,BRect(start,end),d); - } - } - fCursorHandler.DriverShow(); - Invalidate(BRect(start,end)); - Unlock(); -} - -void DisplayDriverImpl::StrokePoint(const BPoint& pt, const RGBColor &color) -{ - StrokeLine(pt, pt, color); - Invalidate(BRect(pt,pt)); -} - -void DisplayDriverImpl::StrokePoint(const BPoint& pt, DrawData *d) -{ - StrokeLine(pt, pt, d); - Invalidate(BRect(pt,pt)); -} - -/*! - \brief Called for all BView::StrokePolygon calls - \param ptlist Array of BPoints defining the polygon. - \param numpts Number of points in the BPoint array. - \param d DrawData containing all of the other options -*/ -void DisplayDriverImpl::StrokePolygon(BPoint *ptlist, int32 numpts, const BRect &bounds, const DrawData *d, bool is_closed) -{ - if(!ptlist) - return; - - Lock(); - if(fCursorHandler.IntersectsCursor(bounds)) - fCursorHandler.DriverHide(); - - for(int32 i=0; i<(numpts-1); i++) - StrokeLine(ptlist[i],ptlist[i+1],d); - if(is_closed) - StrokeLine(ptlist[numpts-1],ptlist[0],d); - - fCursorHandler.DriverShow(); - Invalidate(bounds); - Unlock(); -} - -/*! - \brief Called by Decorator - \param r BRect to be drawn - \param color Color in which to draw -*/ -void DisplayDriverImpl::StrokeRect(const BRect &r, const RGBColor &color) -{ - Lock(); - - if(fCursorHandler.IntersectsCursor(r)) - fCursorHandler.DriverHide(); - StrokeSolidRect(r,color); - - fCursorHandler.DriverShow(); - Invalidate(r); - Unlock(); -} - -/*! - \brief Called for all BView::StrokeRect calls - \param r BRect to be drawn - \param d DrawData containing all of the other options -*/ -void DisplayDriverImpl::StrokeRect(const BRect &r, const DrawData *d) -{ - Lock(); - if(fCursorHandler.IntersectsCursor(r)) - fCursorHandler.DriverHide(); - StrokeLine(r.LeftTop(),r.RightTop(),d); - StrokeLine(r.LeftTop(),r.LeftBottom(),d); - StrokeLine(r.RightTop(),r.RightBottom(),d); - StrokeLine(r.LeftBottom(),r.RightBottom(),d); - - fCursorHandler.DriverShow(); - Invalidate(r); - Unlock(); -} - -/*! - \brief Convenience function for server use - \param r BRegion to be stroked - \param d Data structure containing any other data necessary for the call. Always non-NULL. - -*/ -void DisplayDriverImpl::StrokeRegion(BRegion& r, const DrawData *d) -{ - Lock(); - - if(fCursorHandler.IntersectsCursor(r.Frame())) - fCursorHandler.DriverHide(); - - for(int32 i=0; ifont.Size() * 1.5; - intersection.right += d->font.Size() * 1.5 * length; - - if (fCursorHandler.IntersectsCursor(intersection)) - fCursorHandler.DriverHide(); - - BPoint point(pt); - const ServerFont *font = &(d->font); - - bool antialias = true; - if (font->Size() < 18 && font->Flags() & B_DISABLE_ANTIALIASING) - antialias = false; - - // Originally, I thought to do this shear checking here, but it really should be - // done in BFont::SetShear() - Angle shear(font->Shear()); - if (font->Shear() != 90) { - float shearangle = shear.Value(); - if (shearangle > 135) - shearangle = 135; - if (shearangle < 45) - shearangle = 45; - - if(shearangle > 90) - shear = 90 + ((180 - shearangle) * 2); - else - shear = 90 - (90 - shearangle) * 2; - } - - FT_Face face = font->GetFTFace(); - if (!face) { - Unlock(); - return; - } - - uint16 error = FT_Set_Char_Size(face, 0, int32(font->Size()) * 64, 72, 72); - if (error) { - Unlock(); - return; - } - - bool use_kerning = font->HasKerning() && font->Spacing() == B_STRING_SPACING; - - FT_Vector space, nonspace; - Angle rotation(font->Rotation()); - - // First, rotate - FT_Matrix rmatrix; - rmatrix.xx = (FT_Fixed)( rotation.Cosine()*0x10000); - rmatrix.xy = (FT_Fixed)(-rotation.Sine()*0x10000); - rmatrix.yx = (FT_Fixed)( rotation.Sine()*0x10000); - rmatrix.yy = (FT_Fixed)( rotation.Cosine()*0x10000); - - // Next, shear - FT_Matrix smatrix; - smatrix.xx = (FT_Fixed)(0x10000); - smatrix.xy = (FT_Fixed)(-shear.Cosine()*0x10000); - smatrix.yx = (FT_Fixed)(0); - smatrix.yy = (FT_Fixed)(0x10000); - - // Multiply togheter - FT_Matrix_Multiply(&rmatrix, &smatrix); - - // Set up the increment value for escapement padding - space.x = int32(d->edelta.space * rotation.Cosine() * 64); - space.y = int32(d->edelta.space * rotation.Sine() * 64); - nonspace.x = int32(d->edelta.nonspace * rotation.Cosine() * 64); - nonspace.y = int32(d->edelta.nonspace * rotation.Sine() * 64); - - // set the pen position in 26.6 cartesian space coordinates - FT_Vector pen; - pen.x = (int32)point.x * 64; - pen.y = (int32)point.y * 64; - - int32 strlength = strlen(string); - if(length < strlength) - strlength = length; - - FT_Vector delta; - FT_GlyphSlot slot = face->glyph; - FT_UInt glyph_index = 0, previous = 0; - for (int32 i = 0; i < strlength; i++) { - FT_Set_Transform(face, &smatrix, &pen); - - // Handle escapement padding option - if((uint8)string[i] <= 0x20) { - pen.x += space.x; - pen.y += space.y; - } else { - pen.x += nonspace.x; - pen.y += nonspace.y; - } - - // get kerning and move pen - if(use_kerning && previous && glyph_index) { - FT_Get_Kerning(face, previous, glyph_index, ft_kerning_default, &delta); - pen.x += delta.x; - pen.y += delta.y; - } - - error = FT_Load_Char(face, string[i], (antialias ? FT_LOAD_RENDER : FT_LOAD_RENDER | FT_LOAD_MONOCHROME)); - if (error) - continue; - - if (antialias) - BlitGray2RGB32(&slot->bitmap, BPoint(slot->bitmap_left, point.y - (slot->bitmap_top - point.y)), d); - else - BlitMono2RGB32(&slot->bitmap, BPoint(slot->bitmap_left, point.y - (slot->bitmap_top - point.y)), d); - - // increment pen position - pen.x += slot->advance.x; - pen.y += slot->advance.y; - previous = glyph_index; - } - - // TODO: implement calculation of invalid rectangle in DisplayDriverImpl::DrawString properly - BRect r; - r.left = MIN(point.x, pen.x >> 6); - r.right = MAX(point.x, pen.x >> 6); - r.top = point.y - face->height; - r.bottom = point.y + face->height; - - fCursorHandler.DriverShow(); - Invalidate(r); - - // Update the caller's pen position - d->penlocation.x = pen.x / 64; - d->penlocation.y = pen.y / 64; - - Unlock(); -} - -/*! - \brief Gets the width of a string in pixels - \param string Source null-terminated string - \param length Number of characters in the string - \param d Data structure containing any other data necessary for the call. Always non-NULL. - \return Width of the string in pixels - - This corresponds to BView::StringWidth. -*/ -float DisplayDriverImpl::StringWidth(const char *string, int32 length, const DrawData *d) -{ - if(!string || !d) - return 0.0; - - Lock(); - - const ServerFont *font = &(d->font); - - FT_Face face = font->GetFTFace(); - if(!face) { - Unlock(); - return 0.0; - } - - uint16 error = FT_Set_Char_Size(face, 0, int32(font->Size()) * 64, 72, 72); - if (error) { - Unlock(); - return 0.0; - } - - bool use_kerning = font->HasKerning() && font->Spacing() == B_STRING_SPACING; - - // set the pen position in 26.6 cartesian space coordinates - FT_Vector pen, delta; - pen.x = 0; - - int32 strlength = strlen(string); - if (length < strlength) - strlength = length; - - FT_GlyphSlot slot = face->glyph; - FT_UInt glyph_index = 0, previous = 0; - for (int32 i = 0; i < strlength; i++) { - // get kerning and move pen - if (use_kerning && previous && glyph_index) { - FT_Get_Kerning(face, previous, glyph_index, ft_kerning_default, &delta); - pen.x += delta.x; - } - - error = FT_Load_Char(face, string[i], FT_LOAD_MONOCHROME); - if (error) - continue; - - // increment pen position - pen.x += slot->advance.x; - previous = glyph_index; - } - - Unlock(); - return pen.x >> 6; -} - -/*! - \brief Gets the height of a string in pixels - \param string Source null-terminated string - \param length Number of characters in the string - \param d Data structure containing any other data necessary for the call. Always non-NULL. - \return Height of the string in pixels - - The height calculated in this function does not include any padding - just the - precise maximum height of the characters within and does not necessarily equate - with a font's height, i.e. the strings 'case' and 'alps' will have different values - even when called with all other values equal. -*/ -float DisplayDriverImpl::StringHeight(const char *string, int32 length, const DrawData *d) -{ - if (!string || !d) - return 0.0; - - Lock(); - - const ServerFont *font = &(d->font); - - FT_Face face = font->GetFTFace(); - if (!face) { - Unlock(); - return 0.0; - } - - uint16 error = FT_Set_Char_Size(face, 0, int32(font->Size()) * 64, 72, 72); - - int32 strlength = strlen(string); - if (length < strlength) - strlength = length; - - FT_GlyphSlot slot = face->glyph; - float ascent = 0.0, descent = 0.0; - for (int32 i = 0; i < strlength; i++) { - error = FT_Load_Char(face, string[i], FT_LOAD_MONOCHROME); - if (error) - continue; - - if (slot->metrics.horiBearingY < slot->metrics.height) - descent = MAX((slot->metrics.height - slot->metrics.horiBearingY) >> 6, descent); - else - ascent = MAX(slot->bitmap.rows, ascent); - } - - Unlock(); - return ascent + descent; -} - -/*! - \brief Retrieves the bounding box each character in the string - \param string Source null-terminated string - \param count Number of characters in the string - \param mode Metrics mode for either screen or printing - \param delta Optional glyph padding. This value may be NULL. - \param rectarray Array of BRect objects which will have at least count elements - \param d Data structure containing any other data necessary for the call. Always non-NULL. - - See BFont::GetBoundingBoxes for more details on this function. -*/ -void DisplayDriverImpl::GetBoundingBoxes(const char *string, int32 count, - font_metric_mode mode, escapement_delta *delta, BRect *rectarray, const DrawData *d) -{ - // TODO: Implement DisplayDriverImpl::GetBoundingBoxes -} - -/*! - \brief Retrieves the escapements for each character in the string - \param string Source null-terminated string - \param charcount Number of characters in the string - \param delta Optional glyph padding. This value may be NULL. - \param escapements Array of escapement_delta objects which will have at least charcount elements - \param offsets Actual offset values when iterating over the string. This array will also - have at least charcount elements and the values placed therein will reflect - the current kerning/spacing mode. - \param d Data structure containing any other data necessary for the call. Always non-NULL. - - See BFont::GetEscapements for more details on this function. -*/ -void DisplayDriverImpl::GetEscapements(const char *string, int32 charcount, - escapement_delta *delta, escapement_delta *escapements, escapement_delta *offsets, const DrawData *d) -{ - // TODO: Implement DisplayDriverImpl::GetEscapements -} - -/*! - \brief Retrieves the inset values of each glyph from its escapement values - \param string Source null-terminated string - \param charcount Number of characters in the string - \param edgearray Array of edge_info objects which will have at least charcount elements - \param d Data structure containing any other data necessary for the call. Always non-NULL. - - See BFont::GetEdges for more details on this function. -*/ -void DisplayDriverImpl::GetEdges(const char *string, int32 charcount, edge_info *edgearray, const DrawData *d) -{ - // TODO: Implement DisplayDriverImpl::GetEdges -} - -/*! - \brief Determines whether a font contains a certain string of characters - \param string Source null-terminated string - \param charcount Number of characters in the string - \param hasarray Array of booleans which will have at least charcount elements - - See BFont::GetHasGlyphs for more details on this function. -*/ -void DisplayDriverImpl::GetHasGlyphs(const char *string, int32 charcount, bool *hasarray) -{ - // TODO: Implement DisplayDriverImpl::GetHasGlyphs -} - -/*! - \brief Truncates an array of strings to a certain width - \param instrings Array of null-terminated strings - \param stringcount Number of strings passed to the function - \param mode Truncation mode - \param maxwidth Maximum width for all strings - \param outstrings String array provided by the caller into which the truncated strings are - to be placed. - - See BFont::GetTruncatedStrings for more details on this function. -*/ -void DisplayDriverImpl::GetTruncatedStrings(const char **instrings,const int32 &stringcount, - const uint32 &mode, const float &maxwidth, char **outstrings) -{ - // TODO: Implement DisplayDriverImpl::GetTruncatedStrings -} - -/*! - \brief Hides the cursor. - - Hide calls are not nestable, unlike that of the BApplication class. Subclasses should - call _SetCursorHidden(true) somewhere within this function to ensure that data is - maintained accurately. Subclasses must include a call to DisplayDriver::HideCursor - for proper state tracking. -*/ -void -DisplayDriverImpl::HideCursor() -{ - Lock(); - fCursorHandler.Hide(); - Unlock(); -} - -/*! - \brief Returns whether the cursor is visible or not. - \return true if hidden or obscured, false if not. - -*/ -bool -DisplayDriverImpl::IsCursorHidden() -{ - Lock(); - bool value = fCursorHandler.IsHidden(); - Unlock(); - - return value; -} - -/*! - \brief Moves the cursor to the given point. - - The coordinates passed to MoveCursorTo are guaranteed to be within the frame buffer's - range, but the cursor data itself will need to be clipped. A check to see if the - cursor is obscured should be made and if so, a call to _SetCursorObscured(false) - should be made the cursor in addition to displaying at the passed coordinates. -*/ -void -DisplayDriverImpl::MoveCursorTo(const float &x, const float &y) -{ - Lock(); - fCursorHandler.MoveTo(BPoint(x, y)); - Unlock(); -} - -/*! - \brief Shows the cursor. - - Show calls are not nestable, unlike that of the BApplication class. Subclasses should - call _SetCursorHidden(false) somewhere within this function to ensure that data is - maintained accurately. Subclasses must call DisplayDriver::ShowCursor at some point - to ensure proper state tracking. -*/ -void -DisplayDriverImpl::ShowCursor() -{ - Lock(); - fCursorHandler.Show(); - Unlock(); -} - -/*! - \brief Obscures the cursor. - - Obscure calls are not nestable. Subclasses should call DisplayDriver::ObscureCursor - somewhere within this function to ensure that data is maintained accurately. A check - will be made by the system before the next MoveCursorTo call to show the cursor if - it is obscured. -*/ -void -DisplayDriverImpl::ObscureCursor() -{ - Lock(); - fCursorHandler.Obscure(); - Unlock(); - -} - -/*! - \brief Changes the cursor. - \param cursor The new cursor. Guaranteed to be non-NULL. - - The driver does not take ownership of the given cursor. Subclasses should make - a copy of the cursor passed to it. The default version of this function hides the - cursory, replaces it, and shows the cursor if previously visible. -*/ -void -DisplayDriverImpl::SetCursor(ServerCursor *cursor) -{ - Lock(); - fCursorHandler.SetCursor(cursor); - Unlock(); -} - -//! Returns the cursor's current position -BPoint -DisplayDriverImpl::GetCursorPosition() -{ - Lock(); - BPoint pos = fCursorHandler.GetPosition(); - Unlock(); - - return pos; -} - -/*! - \brief Returns whether or not the cursor is currently obscured - \return True if obscured, false if not. -*/ -bool -DisplayDriverImpl::IsCursorObscured(bool state) -{ - Lock(); - bool obscured = fCursorHandler.IsObscured(); - Unlock(); - - return obscured; -} - -/*! - \brief Locks the driver - \param timeout Optional timeout specifier - \return True if the lock was successful, false if not. - - The return value need only be checked if a timeout was specified. Each public - member function should lock the driver before doing anything else. Functions - internal to the driver (protected/private) need not do this. -*/ -bool -DisplayDriverImpl::Lock(bigtime_t timeout) -{ - if (timeout == B_INFINITE_TIMEOUT) - return fLocker.Lock(); - - return (fLocker.LockWithTimeout(timeout) == B_OK) ? true : false; -} - -/*! - \brief Unlocks the driver -*/ -void -DisplayDriverImpl::Unlock() -{ - fLocker.Unlock(); -} - -// Protected Internal Functions - -/*! - \brief Sets the driver's Display Power Management System state - \param state The state which the driver should enter - \return B_OK if successful, B_ERROR for failure - - This function will fail if the driver's rendering context does not support a - particular DPMS state. Use DPMSCapabilities to find out the supported states. - The default implementation supports only B_DPMS_ON. -*/ -status_t -DisplayDriverImpl::SetDPMSMode(const uint32 &state) -{ - if (state != B_DPMS_ON) - return B_ERROR; - - fDPMSState = state; - - return B_OK; -} - -/*! - \brief Returns the driver's current DPMS state - \return The driver's current DPMS state -*/ -uint32 -DisplayDriverImpl::DPMSMode() -{ - return fDPMSState; -} - -/*! - \brief Returns the driver's DPMS capabilities - \return The driver's DPMS capabilities - - The capabilities are the modes supported by the driver. The default implementation - allows only B_DPMS_ON. Other possible states are B_DPMS_STANDBY, SUSPEND, and OFF. -*/ -uint32 -DisplayDriverImpl::DPMSCapabilities() -{ - return fDPMSCaps; -} - -/*! - \brief Dumps the contents of the frame buffer to a file. - \param path Path and leaf of the file to be created without an extension - \return False if unimplemented or unsuccessful. True if otherwise. - - Subclasses should add an extension based on what kind of file is saved -*/ -bool DisplayDriverImpl::DumpToFile(const char *path) -{ - return false; -} - -/*! - \brief Returns a new ServerBitmap containing the contents of the frame buffer - \return A new ServerBitmap containing the contents of the frame buffer or NULL if unsuccessful -*/ -ServerBitmap *DisplayDriverImpl::DumpToBitmap() -{ - return NULL; -} - -/*! - \brief Draws a series of lines - optimized for speed - \param numlines Number of lines to be drawn - \param linedata Array of LineArrayData objects - \param d current DrawData settings -*/ -void DisplayDriverImpl::StrokeLineArray(const int32 &numlines, const LineArrayData *linedata,const DrawData *d) -{ - if(!d || !linedata) - return; - - const LineArrayData *dataindex=linedata; - BRect r(0,0,0,0); - DrawData drawdata; - - Lock(); - - fCursorHandler.DriverHide(); - - drawdata = *d; - - r.Set(linedata->pt1.x,linedata->pt1.y,linedata->pt1.x,linedata->pt1.y); - - for (int32 i=0; icolor; - - // Keep track of the invalid region - if (dataindex->pt1.x < r.left) - r.left = dataindex->pt1.x; - if (dataindex->pt1.y < r.top) - r.top = dataindex->pt1.y; - if (dataindex->pt1.x > r.right) - r.right = dataindex->pt1.x; - if (dataindex->pt1.y > r.bottom) - r.bottom = dataindex->pt1.y; - - if (dataindex->pt2.x < r.left) - r.left = dataindex->pt2.x; - if (dataindex->pt2.y < r.top) - r.top = dataindex->pt2.y; - if (dataindex->pt2.x > r.right) - r.right = dataindex->pt2.x; - if (dataindex->pt2.y > r.bottom) - r.bottom = dataindex->pt2.y; - - StrokeLine(dataindex->pt1,dataindex->pt2,&drawdata); - } - - Invalidate(r); - - fCursorHandler.DriverShow(); - - Unlock(); -} - - -/*! - \brief Returns data about the rendering device - \param info Pointer to an object to receive the device info - \return B_OK if this function is supported, B_UNSUPPORTED if not - - The default implementation of this returns B_UNSUPPORTED and does nothing. - - From Accelerant.h: - - uint32 version; // structure version number - char name[32]; // a name the user will recognize the device by - char chipset[32]; // the chipset used by the device - char serial_no[32]; // serial number for the device - uint32 memory; // amount of memory on the device, in bytes - uint32 dac_speed; // nominal DAC speed, in MHz - -*/ -status_t DisplayDriverImpl::GetDeviceInfo(accelerant_device_info *info) -{ - return B_ERROR; -} - -/*! - \brief Returns data about the rendering device - \param mode_list Pointer to receive a list of modes. - \param count The number of modes in mode_list - \return B_OK if this function is supported, B_UNSUPPORTED if not - - The default implementation of this returns B_UNSUPPORTED and does nothing. -*/ -status_t DisplayDriverImpl::GetModeList(display_mode **mode_list, uint32 *count) -{ - return B_UNSUPPORTED; -} - -/*! - \brief Obtains the minimum and maximum pixel throughput - \param mode Structure to receive the data for the given mode - \param low Recipient of the minimum clock rate - \param high Recipient of the maximum clock rate - \return - - \c B_OK: Everything is kosher - - \c B_UNSUPPORTED: The function is unsupported - - \c B_ERROR: No known pixel clock limits - - - This function returns the minimum and maximum "pixel clock" rates, in - thousands-of-pixels per second, that are possible for the given mode. See - BScreen::GetPixelClockLimits() for more information. - - The default implementation of this returns B_UNSUPPORTED and does nothing. -*/ -status_t DisplayDriverImpl::GetPixelClockLimits(display_mode *mode, uint32 *low, uint32 *high) -{ - return B_UNSUPPORTED; -} - -/*! - \brief Obtains the timing constraints of the current display mode. - \param dtc Object to receive the constraints - \return - - \c B_OK: Everything is kosher - - \c B_UNSUPPORTED: The function is unsupported - - \c B_ERROR: No known timing constraints - - The default implementation of this returns B_UNSUPPORTED and does nothing. -*/ -status_t DisplayDriverImpl::GetTimingConstraints(display_timing_constraints *dtc) -{ - return B_UNSUPPORTED; -} - -/*! - \brief Obtains the timing constraints of the current display mode. - \param dtc Object to receive the constraints - \return - - \c B_OK: Everything is kosher - - \c B_UNSUPPORTED: The function is unsupported - - The default implementation of this returns B_UNSUPPORTED and does nothing. - This is mostly the responsible of the hardware driver if the DisplayDriverImpl - interfaces with actual hardware. -*/ -status_t DisplayDriverImpl::ProposeMode(display_mode *candidate, const display_mode *low, const display_mode *high) -{ - return B_UNSUPPORTED; -} - -/*! - \brief Waits for the device's vertical retrace - \param timeout Amount of time to wait until retrace. Default is B_INFINITE_TIMEOUT - \return - - \c B_OK: Everything is kosher - - \c B_ERROR: The function timed out before retrace - - \c B_UNSUPPORTED: The function is unsupported - - The default implementation of this returns B_UNSUPPORTED and does nothing. -*/ -status_t DisplayDriverImpl::WaitForRetrace(bigtime_t timeout) -{ - return B_UNSUPPORTED; -} - - -/*! - \brief Obtains the current cursor for the driver. - \return Pointer to the current cursor object. - - Do NOT delete this pointer - change pointers via SetCursor. This call will be - necessary for blitting the cursor to the screen and other such tasks. -*/ -ServerCursor *DisplayDriverImpl::_GetCursor() -{ - Lock(); - ServerCursor *c=fCursorHandler.GetCursor(); - Unlock(); - - return c; -} - -void DisplayDriverImpl::HLinePatternThick(int32 x1, int32 x2, int32 y) -{ -} - -void DisplayDriverImpl::VLinePatternThick(int32 x1, int32 x2, int32 y) -{ -} - -/*! - \brief Draws a point of a specified thickness - \param x The x coordinate (not guaranteed to be in bounds) - \param y The y coordinate (not guaranteed to be in bounds) - \param thick The thickness of the point - \param pat The PatternHandler which detemines pixel colors - Must be implemented in subclasses -*/ -void DisplayDriverImpl::SetThickPatternPixel(int x, int y) -{ -} - -/*! - \brief Draws a horizontal line - \param x1 The first x coordinate (guaranteed to be in bounds) - \param x2 The second x coordinate (guaranteed to be in bounds) - \param y The y coordinate (guaranteed to be in bounds) - \param pat The PatternHandler which detemines pixel colors - Must be implemented in subclasses -*/ - -void DisplayDriverImpl::BlitMono2RGB32(FT_Bitmap *src, const BPoint &pt, const DrawData *d) -{ - rgb_color color=d->highcolor.GetColor32(); - - // pointers to the top left corner of the area to be copied in each bitmap - uint8 *srcbuffer, *destbuffer; - FBBitmap framebuffer; - - if(!AcquireBuffer(&framebuffer)) - { - printf("ERROR: Couldn't acquire framebuffer in BlitMono2RGB32\n"); - return; - } - - // index pointers which are incremented during the course of the blit - uint8 *srcindex, *destindex, *rowptr, value; - - // increment values for the index pointers - int32 srcinc=src->pitch, destinc=framebuffer.BytesPerRow(); - - int16 i,j,k, srcwidth=src->pitch, srcheight=src->rows; - int32 x=(int32)pt.x,y=(int32)pt.y; - - // starting point in source bitmap - srcbuffer=(uint8*)src->buffer; - - if(y<0) - { - if(yframebuffer.Bounds().IntegerHeight()) - { - if(y>pt.y) - y--; - srcheight-=(y+srcheight-1)-framebuffer.Bounds().IntegerHeight(); - } - - if(x+srcwidth>framebuffer.Bounds().IntegerWidth()) - { - if(x>pt.x) - x--; - srcwidth-=(x+srcwidth-1)-framebuffer.Bounds().IntegerWidth(); - } - - if(x<0) - { - if(x>3; - srcwidth-=0-x; - destbuffer+=(0-x)*4; - } - - // starting point in destination bitmap - destbuffer=(uint8*)framebuffer.Bits()+int32( (pt.y*framebuffer.BytesPerRow())+(pt.x*4) ); - - srcindex=srcbuffer; - destindex=destbuffer; - - for(i=0; ihighcolor.GetColor32(); - rgb_color lowcolor = d->lowcolor.GetColor32(); - - float rstep, gstep, bstep, astep; - rstep = float(highcolor.red - lowcolor.red) / 255.0; - gstep = float(highcolor.green - lowcolor.green) / 255.0; - bstep = float(highcolor.blue - lowcolor.blue) / 255.0; - astep = float(highcolor.alpha - lowcolor.alpha) / 255.0; - - // increment values for the index pointers - int32 x = (int32)pt.x; - int32 y = (int32)pt.y; - int32 srcinc = src->pitch; - int32 destinc = framebuffer.BytesPerRow(); - int32 srcwidth = src->width; - int32 srcheight = src->rows; - int32 incval = 0; - - // pointers to the top left corner of the area to be copied in each bitmap - uint8 *srcbuffer = (uint8 *)src->buffer; - uint8 *destbuffer= (uint8 *)framebuffer.Bits() + (y * framebuffer.BytesPerRow() + (x * 4)); - - if (y < 0) { - if (y < pt.y) - y++; - - incval = 0 - y; - - srcbuffer += incval * srcinc; - srcheight -= incval; - destbuffer += incval * destinc; - } - - if (y + srcheight > framebuffer.Bounds().IntegerHeight()) { - if(y > pt.y) - y--; - srcheight -= (y + srcheight - 1) - framebuffer.Bounds().IntegerHeight(); - } - - if (x + srcwidth > framebuffer.Bounds().IntegerWidth()) { - if(x > pt.x) - x--; - srcwidth -= (x + srcwidth - 1) - framebuffer.Bounds().IntegerWidth(); - } - - if (x < 0) { - if(x < pt.x) - x++; - incval = 0 - x; - srcbuffer += incval; - srcwidth -= incval; - destbuffer += incval * 4; - } - - // index pointers which are incremented during the course of the blit - uint8 *srcindex = srcbuffer; - uint8 *destindex = destbuffer; - uint8 *rowptr = NULL; - int32 value; - - for (int32 i = 0; i < srcheight; i++) { - rowptr = destindex; - - for(int32 j = 0; j < srcwidth; j++) { - value = *(srcindex + j) ^ 255; - - if (value != 255) { - if(d->draw_mode == B_OP_COPY) { - rowptr[0] = uint8(highcolor.blue - (value * bstep)); - rowptr[1] = uint8(highcolor.green - (value * gstep)); - rowptr[2] = uint8(highcolor.red - (value * rstep)); - rowptr[3] = 255; - } else if (d->draw_mode == B_OP_OVER) { - if(highcolor.alpha>127) { - rowptr[0] = uint8(highcolor.blue - (value * (float(highcolor.blue - rowptr[0]) / 255.0))); - rowptr[1] = uint8(highcolor.green - (value * (float(highcolor.green - rowptr[1]) / 255.0))); - rowptr[2] = uint8(highcolor.red - (value * (float(highcolor.red - rowptr[2]) / 255.0))); - rowptr[3] = 255; - } - } - } - rowptr += 4; - } - - srcindex += srcinc; - destindex += destinc; - } - - ReleaseBuffer(); -} - -bool DisplayDriverImpl::AcquireBuffer(FBBitmap *bmp) -{ - return false; -} - -void DisplayDriverImpl::ReleaseBuffer() -{ -} - -void DisplayDriverImpl::Blit(const BRect &src, const BRect &dest, const DrawData *d) -{ -} - -void DisplayDriverImpl::FillSolidRect(const BRect &rect, const RGBColor &color) -{ -} - -void DisplayDriverImpl::FillPatternRect(const BRect &rect, const DrawData *d) -{ -} - -/* Draws a line with pensize 1. Coordinates are guarenteed to be in bounds */ -void DisplayDriverImpl::StrokeSolidLine(int32 x1, int32 y1, int32 x2, int32 y2, const RGBColor &color) -{ -} - -// Draws a line with pensize 1. Coordinates are guarenteed to be in bounds -void DisplayDriverImpl::StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2, const DrawData *d) -{ -} - -void DisplayDriverImpl::StrokeSolidRect(const BRect &rect, const RGBColor &color) -{ -} - -void DisplayDriverImpl::CopyBitmap(ServerBitmap *bitmap, const BRect &source, const BRect &dest, const DrawData *d) -{ -} - -void DisplayDriverImpl::CopyToBitmap(ServerBitmap *target, const BRect &source) -{ -} - -void DisplayDriverImpl::Invalidate(const BRect &r) -{ -} - -void DisplayDriverImpl::ConstrainClippingRegion(BRegion *reg) -{ -} diff --git a/src/servers/app/drawing/old_but_informative/DisplayDriverImpl.h b/src/servers/app/drawing/old_but_informative/DisplayDriverImpl.h deleted file mode 100644 index bed57cc128..0000000000 --- a/src/servers/app/drawing/old_but_informative/DisplayDriverImpl.h +++ /dev/null @@ -1,433 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2005, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: DisplayDriver.h -// Authors: DarkWyrm -// Gabe Yoder -// Stephan Aßmus -// -// Description: Abstract class which handles all graphics output -// for the server -// -//------------------------------------------------------------------------------ -#ifndef _DISPLAY_DRIVER_IMPL_H_ -#define _DISPLAY_DRIVER_IMPL_H_ - -#include - -#include -#include -#include -#include - -#include -#include FT_FREETYPE_H - -//#include "CursorHandler.h" -#include "DisplaySupport.h" -#include "LayerData.h" -#include "PatternHandler.h" -#include "RGBColor.h" -#include "ServerBitmap.h" - -#include "DisplayDriver.h" - -#ifndef ROUND - #define ROUND(a) ( (long)(a+.5) ) -#endif - - -class ServerCursor; - -/*! - \brief Data structure for passing cursor information to hardware drivers. -*/ -typedef struct -{ - uchar *xormask, *andmask; - int32 width, height; - int32 hotx, hoty; - -} cursor_data; - -#ifndef HOOK_DEFINE_CURSOR - -#define HOOK_DEFINE_CURSOR 0 -#define HOOK_MOVE_CURSOR 1 -#define HOOK_SHOW_CURSOR 2 -#define HOOK_DRAW_LINE_8BIT 3 -#define HOOK_DRAW_LINE_16BIT 12 -#define HOOK_DRAW_LINE_32BIT 4 -#define HOOK_DRAW_RECT_8BIT 5 -#define HOOK_DRAW_RECT_16BIT 13 -#define HOOK_DRAW_RECT_32BIT 6 -#define HOOK_BLIT 7 -#define HOOK_DRAW_ARRAY_8BIT 8 -#define HOOK_DRAW_ARRAY_16BIT 14 // Not implemented in current R5 drivers -#define HOOK_DRAW_ARRAY_32BIT 9 -#define HOOK_SYNC 10 -#define HOOK_INVERT_RECT 11 - -#endif - -class DisplayDriverImpl; - -typedef void (DisplayDriverImpl::* SetPixelFuncType)(int x, int y); -typedef void (DisplayDriverImpl::* SetHorizontalLineFuncType)(int xstart, int xend, int y); -typedef void (DisplayDriverImpl::* SetVerticalLineFuncType)(int x, int ystart, int yend); -typedef void (DisplayDriverImpl::* SetRectangleFuncType)(int left, int top, int right, int bottom); - -/*! - \class DisplayDriverImpl DisplayDriverImpl.h - \brief original DisplayDriver implementation. - - While all virtual functions are technically optional, the default versions - do very little, so implementing them all more or less required. -*/ - -class DisplayDriverImpl : public DisplayDriver { - public: - DisplayDriverImpl(); - virtual ~DisplayDriverImpl(); - - // Graphics calls implemented in DisplayDriver - virtual void CopyBits( const BRect &src, - const BRect &dest, - const DrawData *d); - - virtual void CopyRegion( BRegion *src, - const BPoint &lefttop); - - virtual void InvertRect( const BRect &r); - - virtual void DrawBitmap( BRegion *region, - ServerBitmap *bitmap, - const BRect &source, - const BRect &dest, - const DrawData *d); - - virtual void CopyRegionList( BList* list, - BList* pList, - int32 rCount, - BRegion* clipReg); - - virtual void FillArc( const BRect &r, - const float &angle, - const float &span, - const DrawData *d); - - virtual void FillBezier( BPoint *pts, - const DrawData *d); - - virtual void FillEllipse( const BRect &r, - const DrawData *d); - - virtual void FillPolygon( BPoint *ptlist, - int32 numpts, - const BRect &bounds, - const DrawData *d); - - virtual void FillRect( const BRect &r, - const RGBColor &color); - - virtual void FillRect( const BRect &r, - const DrawData *d); - - virtual void FillRegion( BRegion &r, - const DrawData *d); - - virtual void FillRoundRect( const BRect &r, - const float &xrad, - const float &yrad, - const DrawData *d); - - virtual void FillShape( const BRect &bounds, - const int32 &opcount, - const int32 *oplist, - const int32 &ptcount, - const BPoint *ptlist, - const DrawData *d); - - virtual void FillTriangle( BPoint *pts, - const BRect &bounds, - const DrawData *d); - - virtual void StrokeArc( const BRect &r, - const float &angle, - const float &span, - const DrawData *d); - - virtual void StrokeBezier( BPoint *pts, - const DrawData *d); - - virtual void StrokeEllipse( const BRect &r, - const DrawData *d); - - // this version used by Decorator - virtual void StrokeLine( const BPoint &start, - const BPoint &end, - const RGBColor &color); - - virtual void StrokeLine( const BPoint &start, - const BPoint &end, - DrawData *d); - - // this version used by Decorator - virtual void StrokePoint( const BPoint &pt, - const RGBColor &color); - - virtual void StrokePoint( const BPoint &pt, - DrawData *d); - - virtual void StrokePolygon( BPoint *ptlist, - int32 numpts, - const BRect &bounds, - const DrawData *d, - bool is_closed=true); - - // this version used by Decorator - virtual void StrokeRect( const BRect &r, - const RGBColor &color); - - virtual void StrokeRect( const BRect &r, - const DrawData *d); - - virtual void StrokeRegion( BRegion &r, - const DrawData *d); - - virtual void StrokeRoundRect(const BRect &r, - const float &xrad, - const float &yrad, - const DrawData *d); - - virtual void StrokeShape( const BRect &bounds, - const int32 &opcount, - const int32 *oplist, - const int32 &ptcount, - const BPoint *ptlist, - const DrawData *d); - - virtual void StrokeTriangle( BPoint *pts, - const BRect &bounds, - const DrawData *d); - - // Font-related calls - - // DrawData is NOT const because this call updates the pen position in the passed DrawData - virtual void DrawString(const char *string, - const int32 &length, - const BPoint &pt, - DrawData *d); - - virtual void DrawString(const char *string, - const int32 &length, - const BPoint &pt, - const RGBColor &color, - escapement_delta *delta=NULL); - - virtual float StringWidth(const char *string, - int32 length, - const DrawData *d); - - virtual float StringHeight(const char *string, - int32 length, - const DrawData *d); - - virtual void GetBoundingBoxes(const char *string, - int32 count, - font_metric_mode mode, - escapement_delta *delta, - BRect *rectarray, - const DrawData *d); - - virtual void GetEscapements(const char *string, - int32 charcount, - escapement_delta *delta, - escapement_delta *escapements, - escapement_delta *offsets, - const DrawData *d); - - virtual void GetEdges(const char *string, - int32 charcount, - edge_info *edgearray, - const DrawData *d); - - virtual void GetHasGlyphs(const char *string, - int32 charcount, - bool *hasarray); - - virtual void GetTruncatedStrings(const char **instrings, - const int32 &stringcount, - const uint32 &mode, - const float &maxwidth, - char **outstrings); - - // cursor handling - virtual void HideCursor(); - virtual bool IsCursorHidden(); - virtual void MoveCursorTo( const float &x, - const float &y); - virtual void ShowCursor(); - virtual void ObscureCursor(); - virtual void SetCursor(ServerCursor *cursor); - BPoint GetCursorPosition(); - virtual bool IsCursorObscured(bool state); - - - // These two will rarely be implemented by subclasses, - // but it still needs to be possible - virtual bool Lock(bigtime_t timeout = B_INFINITE_TIMEOUT); - virtual void Unlock(); - - virtual bool DumpToFile(const char *path); - virtual ServerBitmap* DumpToBitmap(); - - virtual void StrokeLineArray(const int32 &numlines, - const LineArrayData *data, - const DrawData *d); - - virtual status_t SetDPMSMode(const uint32 &state); - virtual uint32 DPMSMode(); - virtual uint32 DPMSCapabilities(); - - virtual status_t GetDeviceInfo(accelerant_device_info *info); - - virtual status_t GetModeList(display_mode **mode_list, - uint32 *count); - - virtual status_t GetPixelClockLimits(display_mode *mode, - uint32 *low, - uint32 *high); - - virtual status_t GetTimingConstraints(display_timing_constraints *dtc); - virtual status_t ProposeMode(display_mode *candidate, - const display_mode *low, - const display_mode *high); - - virtual status_t WaitForRetrace(bigtime_t timeout = B_INFINITE_TIMEOUT); - - - // needed by CursorHandler - virtual void CopyBitmap(ServerBitmap *bitmap, - const BRect &source, - const BRect &dest, - const DrawData *d); - - virtual void CopyToBitmap(ServerBitmap *target, - const BRect &source); - - // This is for drivers which are internally double buffered - // and calling this will cause the real framebuffer to be updated - virtual void Invalidate(const BRect &r); - - // temporarily virtual - until clipping code is added in DisplayDriver - // needed by Layer - virtual void ConstrainClippingRegion(BRegion *reg); - -protected: -//friend class Layer; -friend class WinBorder; -//friend CursorHandler; - - ServerCursor* _GetCursor(); - - virtual void HLinePatternThick(int32 x1, int32 x2, int32 y); - - virtual void VLinePatternThick(int32 x, int32 y1, int32 y2); - - virtual void SetThickPatternPixel(int x, int y); - - // Blit functions specific to FreeType2 glyph copying. - // These probably could be replaced with more generic functions, - // but these are written and can be replaced later. - void BlitMono2RGB32(FT_Bitmap *src, - const BPoint &pt, - const DrawData *d); - - void BlitGray2RGB32(FT_Bitmap *src, - const BPoint &pt, - const DrawData *d); - - // Two functions for gaining direct access to the framebuffer - // of a child class. This removes the need for a set of - // glyph-blitting virtual functions for each driver. - virtual bool AcquireBuffer(FBBitmap *bmp); - virtual void ReleaseBuffer(); - - -/* void FillBezier(BPoint *pts, - DisplayDriver* driver, - SetHorizontalLineFuncType setLine); - - void FillRegion(BRegion &r, - DisplayDriver* driver, - SetRectangleFuncType setRect); - - void StrokeArc(const BRect &r, - const float &angle, - const float &span, - DisplayDriver* driver, - SetPixelFuncType setPixel); - - void StrokeBezier(BPoint *pts, - DisplayDriver* driver, - SetPixelFuncType setPixel); - - void StrokeEllipse(const BRect &r, - DisplayDriver* driver, - SetPixelFuncType setPixel); - - void StrokeLine(const BPoint &start, - const BPoint &end, - DisplayDriver* driver, - SetPixelFuncType setPixel);*/ - - // Support functions for the rest of the driver - virtual void Blit(const BRect &src, - const BRect &dest, - const DrawData *d); - - virtual void FillSolidRect(const BRect &rect, - const RGBColor &color); - - virtual void FillPatternRect(const BRect &rect, - const DrawData *d); - - virtual void StrokeSolidLine(int32 x1, int32 y1, - int32 x2, int32 y2, - const RGBColor &color); - - virtual void StrokePatternLine(int32 x1, int32 y1, - int32 x2, int32 y2, - const DrawData *d); - - virtual void StrokeSolidRect(const BRect &rect, - const RGBColor &color); - - protected: - BLocker fLocker; - CursorHandler fCursorHandler; - - uint32 fDPMSState; - uint32 fDPMSCaps; -}; - -#endif diff --git a/src/servers/app/drawing/old_but_informative/DisplaySupport.cpp b/src/servers/app/drawing/old_but_informative/DisplaySupport.cpp deleted file mode 100644 index e947ae0d80..0000000000 --- a/src/servers/app/drawing/old_but_informative/DisplaySupport.cpp +++ /dev/null @@ -1,473 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: DisplaySupport.cpp -// Author: DarkWyrm -// Gabe Yoder -// Description: Support classes for the DisplayDriver class -// -//------------------------------------------------------------------------------ -#include "DisplaySupport.h" - -BezierCurve::BezierCurve(BPoint* pts) -{ - int i; - - pointArray = NULL; - for (i=0; i<4; i++) - points.AddItem(new BPoint(pts[i])); - GenerateFrame(pts); - GeneratePoints(0); -} - -BezierCurve::~BezierCurve() -{ - int i, numPoints; - - numPoints = points.CountItems(); - for (i=0; i fFrame.right) - fFrame.right = pts[i].x; - if (pts[i].y > fFrame.bottom) - fFrame.bottom = pts[i].y; - } -} - -int BezierCurve::GeneratePoints(int startPos) -{ - double slopeAB, slopeBC, slopeCD; - BPoint** pointList = (BPoint **)points.Items(); - - // TODO Check for more conditions where we can fudge the curve to a line - - if ( (fabs(pointList[startPos]->x-pointList[startPos+3]->x) <= 1) && - (fabs(pointList[startPos]->y-pointList[startPos+3]->y) <= 1) ) - return 0; - - if ( (pointList[startPos]->x == pointList[startPos+1]->x) && - (pointList[startPos+1]->x == pointList[startPos+2]->x) && - (pointList[startPos+2]->x == pointList[startPos+3]->x) ) - return 0; - - slopeAB = (pointList[startPos]->y-pointList[startPos+1]->y)/(pointList[startPos]->x-pointList[startPos+1]->x); - slopeBC = (pointList[startPos+1]->y-pointList[startPos+2]->y)/(pointList[startPos+1]->x-pointList[startPos+2]->x); - slopeCD = (pointList[startPos+2]->y-pointList[startPos+3]->y)/(pointList[startPos+2]->x-pointList[startPos+3]->x); - - if ( (slopeAB == slopeBC) && (slopeBC == slopeCD) ) - return 0; - - BPoint *pointAB = new BPoint(); - BPoint pointBC; - BPoint *pointCD = new BPoint(); - BPoint *pointABC = new BPoint(); - BPoint *pointBCD = new BPoint(); - BPoint *curvePoint = new BPoint(); - int lengthIncrement = 3; - - pointAB->x = (pointList[startPos]->x + pointList[startPos+1]->x)/2; - pointAB->y = (pointList[startPos]->y + pointList[startPos+1]->y)/2; - pointBC.x = (pointList[startPos+1]->x + pointList[startPos+2]->x)/2; - pointBC.y = (pointList[startPos+1]->y + pointList[startPos+2]->y)/2; - pointCD->x = (pointList[startPos+2]->x + pointList[startPos+3]->x)/2; - pointCD->y = (pointList[startPos+2]->y + pointList[startPos+3]->y)/2; - pointABC->x = (pointAB->x + pointBC.x)/2; - pointABC->y = (pointAB->y + pointBC.y)/2; - pointBCD->x = (pointCD->x + pointBC.x)/2; - pointBCD->y = (pointCD->y + pointBC.y)/2; - curvePoint->x = (pointABC->x + pointBCD->x)/2; - curvePoint->y = (pointABC->y + pointBCD->y)/2; - delete pointList[startPos+1]; - delete pointList[startPos+2]; - pointList[startPos+1] = pointAB; - pointList[startPos+2] = pointCD; - points.AddItem(pointABC,startPos+2); - points.AddItem(curvePoint,startPos+3); - points.AddItem(pointBCD,startPos+4); - lengthIncrement += GeneratePoints(startPos); - lengthIncrement += GeneratePoints(startPos + lengthIncrement); - return lengthIncrement; -} - -Blitter::Blitter() -{ - DrawFunc = &Blitter::draw_none; -} - -void Blitter::draw_8_to_8(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor) -{ - uint8 *s = (uint8 *)src; - uint8 *d = (uint8 *)dst; - - while(width--) - { - *d++ = s[xscale_position >> 16]; - xscale_position += xscale_factor; - } -} - -void Blitter::draw_8_to_16(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor) -{ - uint8 *s = (uint8 *)src; - uint16 *d = (uint16 *)dst; - - while(width--) - { - *d++ = s[xscale_position >> 16]; - xscale_position += xscale_factor; - } -} - -void Blitter::draw_8_to_32(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor) -{ - uint8 *s = (uint8 *)src; - uint32 *d = (uint32 *)dst; - - while(width--) - { - *d++ = s[xscale_position >> 16]; - xscale_position += xscale_factor; - } -} - -void Blitter::draw_16_to_8(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor) -{ - uint16 *s = (uint16 *)src; - uint8 *d = (uint8 *)dst; - - while(width--) - { - *d++ = s[xscale_position >> 16]; - xscale_position += xscale_factor; - } -} - -void Blitter::draw_16_to_16(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor) -{ - uint16 *s = (uint16 *)src; - uint16 *d = (uint16 *)dst; - - while(width--) - { - *d++ = s[xscale_position >> 16]; - xscale_position += xscale_factor; - } -} - -void Blitter::draw_16_to_32(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor) -{ - uint16 *s = (uint16 *)src; - uint32 *d = (uint32 *)dst; - - while(width--) - { - *d++ = s[xscale_position >> 16]; - xscale_position += xscale_factor; - } -} - -void Blitter::draw_32_to_8(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor) -{ - uint32 *s = (uint32 *)src; - uint8 *d = (uint8 *)dst; - - while(width--) - { - *d++ = s[xscale_position >> 16]; - xscale_position += xscale_factor; - } -} - -void Blitter::draw_32_to_16(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor) -{ - uint32 *s = (uint32 *)src; - uint16 *d = (uint16 *)dst; - - while(width--) - { - *d++ = s[xscale_position >> 16]; - xscale_position += xscale_factor; - } -} - -void Blitter::draw_32_to_32(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor) -{ - uint32 *s = (uint32 *)src; - uint32 *d = (uint32 *)dst; - - while(width--) - { - *d++ = s[xscale_position >> 16]; - xscale_position += xscale_factor; - } -} - -void Blitter::Draw(uint8 *src, uint8 *dst, int32 width, int32 xscale_position, int32 xscale_factor) -{ - (this->*DrawFunc)(src, dst, width, xscale_position, xscale_factor); -} - -void Blitter::Select(int32 source_bits_per_pixel, int32 dest_bits_per_pixel) -{ - if(source_bits_per_pixel == 8 && dest_bits_per_pixel == 8) - DrawFunc = &Blitter::draw_8_to_8; - else if(source_bits_per_pixel == 8 && dest_bits_per_pixel == 16) - DrawFunc = &Blitter::draw_8_to_16; - else if(source_bits_per_pixel == 8 && dest_bits_per_pixel == 32) - DrawFunc = &Blitter::draw_8_to_32; - else if(source_bits_per_pixel == 16 && dest_bits_per_pixel == 16) - DrawFunc = &Blitter::draw_16_to_16; - else if(source_bits_per_pixel == 16 && dest_bits_per_pixel == 8) - DrawFunc = &Blitter::draw_16_to_8; - else if(source_bits_per_pixel == 16 && dest_bits_per_pixel == 32) - DrawFunc = &Blitter::draw_16_to_32; - else if(source_bits_per_pixel == 32 && dest_bits_per_pixel == 32) - DrawFunc = &Blitter::draw_32_to_32; - else if(source_bits_per_pixel == 32 && dest_bits_per_pixel == 16) - DrawFunc = &Blitter::draw_32_to_16; - else if(source_bits_per_pixel == 32 && dest_bits_per_pixel == 8) - DrawFunc = &Blitter::draw_32_to_8; - else - DrawFunc = &Blitter::draw_none; -} - -LineCalc::LineCalc() -{ -} - -LineCalc::LineCalc(const BPoint &pta, const BPoint &ptb) -{ - start=pta; - end=ptb; - slope=(start.y-end.y)/(start.x-end.x); - offset=start.y-(slope * start.x); - minx = MIN(start.x,end.x); - maxx = MAX(start.x,end.x); - miny = MIN(start.y,end.y); - maxy = MAX(start.y,end.y); -} - -void LineCalc::SetPoints(const BPoint &pta, const BPoint &ptb) -{ - start=pta; - end=ptb; - slope=(start.y-end.y)/(start.x-end.x); - offset=start.y-(slope * start.x); - minx = MIN(start.x,end.x); - maxx = MAX(start.x,end.x); - miny = MIN(start.y,end.y); - maxy = MAX(start.y,end.y); -} - -bool LineCalc::ClipToRect(const BRect& rect) -{ - if ( (maxx < rect.left) || (minx > rect.right) || (miny < rect.top) || (maxy > rect.bottom) ) - return false; - BPoint newStart(-1,-1); - BPoint newEnd(-1,-1); - if ( maxx == minx ) - { - newStart.x = newEnd.x = minx; - if ( miny < rect.top ) - newStart.y = rect.top; - else - newStart.y = miny; - if ( maxy > rect.bottom ) - newEnd.y = rect.bottom; - else - newEnd.y = maxy; - } - else if ( maxy == miny ) - { - newStart.y = newEnd.y = miny; - if ( minx < rect.left ) - newStart.x = rect.left; - else - newStart.x = minx; - if ( maxx > rect.right ) - newEnd.x = rect.right; - else - newEnd.x = maxx; - } - else - { - float leftInt, rightInt, topInt, bottomInt; - BPoint tempPoint; - leftInt = GetY(rect.left); - rightInt = GetY(rect.right); - topInt = GetX(rect.top); - bottomInt = GetX(rect.bottom); - if ( end.x < start.x ) - { - tempPoint = start; - start = end; - end = tempPoint; - } - if ( start.x < rect.left ) - { - if ( (leftInt >= rect.top) && (leftInt <= rect.bottom) ) - { - newStart.x = rect.left; - newStart.y = leftInt; - } - if ( start.y < end.y ) - { - if ( (topInt >= rect.left) && (topInt <= rect.right) ) - { - newStart.x = topInt; - newStart.y = rect.top; - } - } - else - { - if ( (bottomInt >= rect.left) && (bottomInt <= rect.right) ) - { - newStart.x = bottomInt; - newStart.y = rect.bottom; - } - } - } - else - { - if ( start.y < rect.top ) - { - if ( (topInt >= rect.left) && (topInt <= rect.right) ) - { - newStart.x = topInt; - newStart.y = rect.top; - } - } - else if ( start.y > rect.bottom ) - { - if ( (bottomInt >= rect.left) && (bottomInt <= rect.right) ) - { - newStart.x = bottomInt; - newStart.y = rect.bottom; - } - } - else - newStart = start; - } - if ( end.x > rect.right ) - { - if ( (rightInt >= rect.top) && (rightInt <= rect.bottom) ) - { - newEnd.x = rect.right; - newEnd.y = rightInt; - } - if ( start.y < end.y ) - { - if ( (bottomInt >= rect.left) && (bottomInt <= rect.right) ) - { - newEnd.x = bottomInt; - newEnd.y = rect.bottom; - } - } - else - { - if ( (topInt >= rect.left) && (topInt <= rect.right) ) - { - newEnd.x = topInt; - newEnd.y = rect.top; - } - } - } - else - { - if ( end.y < rect.top ) - { - if ( (topInt >= rect.left) && (topInt <= rect.right) ) - { - newEnd.x = topInt; - newEnd.y = rect.top; - } - } - else if ( end.y > rect.bottom ) - { - if ( (bottomInt >= rect.left) && (bottomInt <= rect.right) ) - { - newEnd.x = bottomInt; - newEnd.y = rect.bottom; - } - } - else - newEnd = end; - } - } - if ( (newStart.x == -1) || (newStart.y == -1) || (newEnd.x == -1) || (newEnd.y == -1) ) - return false; - SetPoints(newStart,newEnd); - - return true; -} - -void LineCalc::Swap(LineCalc &from) -{ - BPoint pta, ptb; - pta = start; - ptb = end; - SetPoints(from.start,from.end); - from.SetPoints(pta,ptb); -} - -float LineCalc::GetX(float y) -{ - if (start.x == end.x) - return start.x; - return ( (y-offset)/slope ); -} - -float LineCalc::GetY(float x) -{ - if ( start.x == end.x ) - return start.y; - return ( (slope * x) + offset ); -} diff --git a/src/servers/app/drawing/old_but_informative/FontManager.cpp b/src/servers/app/drawing/old_but_informative/FontManager.cpp deleted file mode 100644 index 87515b8a89..0000000000 --- a/src/servers/app/drawing/old_but_informative/FontManager.cpp +++ /dev/null @@ -1,334 +0,0 @@ -// FontManager.cpp - -#include -#include -#include - -#include -#include FT_SFNT_NAMES_H -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "FontManager.h" - -// static default instance -FontManager* -FontManager::fDefaultManager = NULL; - -static const char* threadName = "font scanner"; - -// constructor -FontManager::FontManager(bool scanFontsInline) - : BLooper(threadName, B_LOW_PRIORITY), - fLibrary(NULL), - fFontFiles(1024) -{ - // initialize engine - FT_Error error = FT_Init_FreeType(&fLibrary); - if (error) - fprintf(stderr, "Could not initialise FreeType library\n"); - -/* - if (scanFontsInline) { - _update((void*)this); - } else { - // start thread to read keyfile - thread_id fontScanner = spawn_thread(_update, threadName, - B_LOW_PRIORITY, this); - if (fontScanner >= B_OK) - resume_thread(fontScanner); - }*/ - - Run(); -} - -// destructor -FontManager::~FontManager() -{ - _MakeEmpty(); -} - -// MessageReceived -void -FontManager::MessageReceived(BMessage* message) -{ - switch (message->what) { - case MSG_UPDATE: { - // notify potential observes - BMessage message(MSG_FONTS_CHANGED); - SendNotices(FONTS_CHANGED, &message); - break; - } - default: - break; - } -} - -// CreateDefault -void -FontManager::CreateDefault(bool scanFontsInline) -{ - if (!fDefaultManager) - fDefaultManager = new FontManager(scanFontsInline); -} - -// DeleteDefault -void -FontManager::DeleteDefault() -{ - fDefaultManager->Lock(); - fDefaultManager->Quit(); -} - -// Default -FontManager* -FontManager::Default() -{ - if (!fDefaultManager) - CreateDefault(); - return fDefaultManager; -} - -// FontFileAt -const entry_ref* -FontManager::FontFileAt(int32 index) const -{ - if (font_file* ff = (font_file*)fFontFiles.ItemAt(index)) { - return &ff->ref; - } - return NULL; -} - -// FontFileFor -const entry_ref* -FontManager::FontFileFor(const char* family, const char* style) const -{ - if (family && style) { - for (int32 i = 0; font_file* ff = (font_file*)fFontFiles.ItemAt(i); i++) { - if (ff->family_name && strcmp(ff->family_name, family) == 0 - && ff->style_name && strcmp(ff->style_name, style) == 0) - return &ff->ref; - } - } - return NULL; -} - -// FamilyFor -const char* -FontManager::FamilyFor(const entry_ref* fontFile) const -{ - if (font_file* ff = _FontFileFor(fontFile)) - return ff->family_name; - return NULL; -} - -// StyleFor -const char* -FontManager::StyleFor(const entry_ref* fontFile) const -{ - if (font_file* ff = _FontFileFor(fontFile)) - return ff->style_name; - return NULL; -} - -// FullFamilyFor -const char* -FontManager::FullFamilyFor(const entry_ref* fontFile) const -{ - if (font_file* ff = _FontFileFor(fontFile)) - return ff->full_family_name; - return NULL; -} - -// PostScriptNameFor -const char* -FontManager::PostScriptNameFor(const entry_ref* fontFile) const -{ - if (font_file* ff = _FontFileFor(fontFile)) - return ff->ps_name; - return NULL; -} - -// CountFontFiles -int32 -FontManager::CountFontFiles() const -{ - return fFontFiles.CountItems(); -} - -// _MakeEmpty -void -FontManager::_MakeEmpty() -{ - int32 i = fFontFiles.CountItems() - 1; - while (i >= 0) { - if (font_file* ff = (font_file*)fFontFiles.ItemAt(i)) { - if (ff->family_name) - free(ff->family_name); - if (ff->style_name) - free(ff->style_name); - if (ff->full_family_name) - free(ff->full_family_name); - if (ff->ps_name) - free(ff->ps_name); - delete ff; - } - i--; - } - fFontFiles.MakeEmpty(); -} - -int32 -FontManager::_update(void* cookie) -{ - FontManager* fm = (FontManager*)cookie; - if (fm && fm->Lock()) { -//bigtime_t now = system_time(); - // update from system, common and user fonts folders - BPath path; - if (find_directory(B_BEOS_FONTS_DIRECTORY, &path) >= B_OK) { - BDirectory fontFolder(path.Path()); - fm->_Update(&fontFolder); - } - if (find_directory(B_COMMON_FONTS_DIRECTORY, &path) >= B_OK) { - BDirectory fontFolder(path.Path()); - fm->_Update(&fontFolder); - } -/* if (find_directory(B_USER_FONTS_DIRECTORY, &path) >= B_OK) { - BDirectory fontFolder(path.Path()); - _Update(&fontFolder); - }*/ -/*printf("scanning fonts: %lld µsecs\n", system_time() - now); -for (int32 i = 0; font_file* ff = (font_file*)fFontFiles.ItemAt(i); i++) { - printf("fond %ld: \"%s, %s\"\n", i, ff->family_name, ff->style_name); -}*/ - fm->Unlock(); - } - return 0; -} - -//_Update -void -FontManager::_Update(BDirectory* fontFolder) -{ - fontFolder->Rewind(); - // scan the entire folder for font files - BEntry entry; - while (fontFolder->GetNextEntry(&entry) >= B_OK) { - if (entry.IsDirectory()) { - // recursive scan of sub folders - BDirectory subFolder(&entry); - _Update(&subFolder); - } else { - // see if this is a usable font file - BPath path; - if (entry.GetPath(&path) >= B_OK) { - FT_Face face; - FT_Error error = FT_New_Face(fLibrary, path.Path(), 0, &face); - if (!error && face->family_name && face->style_name) { - // create font_file object and init it - font_file* fontFile = new font_file; - entry.GetRef(&fontFile->ref); - fontFile->family_name = strdup(face->family_name); - fontFile->style_name = strdup(face->style_name); - fontFile->full_family_name = NULL; - fontFile->ps_name = NULL; - // iterate over the names we find for this font face - int32 nameCount = FT_Get_Sfnt_Name_Count(face); - FT_SfntName fontName; -//printf("\n\nfont: '%s'/'%s':\n", fontFile->family_name, fontFile->style_name); - for (int32 i = 0; (fontFile->full_family_name == NULL || fontFile->ps_name == NULL) - && i < nameCount; i++) { - if (FT_Get_Sfnt_Name(face, i, &fontName ) == 0) { - switch (fontName.platform_id) { - case TT_PLATFORM_APPLE_UNICODE: -//printf(" platform: TT_PLATFORM_APPLE_UNICODE\n"); - // TODO: implement - break; - case TT_PLATFORM_MACINTOSH: -//printf(" platform: TT_PLATFORM_MACINTOSH\n"); - if (fontName.encoding_id == TT_MAC_ID_ROMAN) { - if (fontName.name_id == TT_NAME_ID_FULL_NAME) { - fontFile->full_family_name = (char*)malloc(fontName.string_len + 1); - memcpy(fontFile->full_family_name, fontName.string, fontName.string_len); - fontFile->full_family_name[fontName.string_len] = 0; - } else if (fontName.name_id == TT_NAME_ID_PS_NAME) { - fontFile->ps_name = (char*)malloc(fontName.string_len + 1); - memcpy(fontFile->ps_name, fontName.string, fontName.string_len); - fontFile->ps_name[fontName.string_len] = 0; - } - } - break; - case TT_PLATFORM_MICROSOFT: -//printf(" platform: TT_PLATFORM_MICROSOFT\n"); - // TODO: implement - if (fontName.encoding_id == TT_MS_ID_UNICODE_CS) { - if (fontName.name_id == TT_NAME_ID_FULL_NAME - || fontName.name_id == TT_NAME_ID_PS_NAME) { - int32 length = fontName.string_len + 1; - char* buffer = (char*)malloc(length); - memcpy(buffer, fontName.string, length - 1); - buffer[length - 1] = 0; - int32 state = 0; - convert_to_utf8(B_UNICODE_CONVERSION, - buffer, - &length, - buffer, - &length, - &state, - B_SUBSTITUTE); - if (fontName.name_id == TT_NAME_ID_FULL_NAME) - fontFile->full_family_name = buffer; - else if (fontName.name_id == TT_NAME_ID_PS_NAME) - fontFile->ps_name = buffer; -//printf("uni-code name: '%s' (orig-length: %d, length: %ld)\n", buffer, fontName.string_len, length); - } - } - break; - } - } -/* -char* name = (char*)malloc(fontName.string_len + 1); -memcpy(name, fontName.string, fontName.string_len); -name[fontName.string_len] = 0; -printf(" %d, %d, ", fontName.encoding_id, fontName.name_id); -printf("name: '%s'\n", name); -free(name); -*/ - } - // find slot in sorted list and add it - int32 i = 0; - for (; font_file* ff = (font_file*)fFontFiles.ItemAt(i); i++) { - if (strcmp(fontFile->family_name, ff->family_name) < 0 - && strcmp(fontFile->style_name, ff->style_name) <= 0) { - break; - } - } - fFontFiles.AddItem((void*)fontFile, i); - FT_Done_Face(face); - } - } - } - } -} - -// _FontFileFor -FontManager::font_file* -FontManager::_FontFileFor(const entry_ref* ref) const -{ - if (ref) { - for (int32 i = 0; font_file* ff = (font_file*)fFontFiles.ItemAt(i); i++) { - if (ff->ref == *ref) { - return ff; - } - } - } - return NULL; -} diff --git a/src/servers/app/drawing/old_but_informative/FontManager.h b/src/servers/app/drawing/old_but_informative/FontManager.h deleted file mode 100644 index b1a6d34060..0000000000 --- a/src/servers/app/drawing/old_but_informative/FontManager.h +++ /dev/null @@ -1,73 +0,0 @@ -// FontManager.h - -#ifndef FT_FONT_MANAGER_H -#define FT_FONT_MANAGER_H - -#include -#include FT_FREETYPE_H -#include FT_GLYPH_H - -#include -#include - -class BMenu; - -enum { - MSG_FONTS_CHANGED = 'fnch', - MSG_SET_FONT = 'stfn', - MSG_UPDATE = 'updt', -}; - -enum { - FONTS_CHANGED = 0x01, -}; - -class FontManager : public BLooper { - public: - FontManager(bool scanFontsInline); - virtual ~FontManager(); - - // BLooper - virtual void MessageReceived(BMessage* message); - - // FontManager - static void CreateDefault(bool scanFontsInline = false); - static void DeleteDefault(); - static FontManager* Default(); - - // lock the object! - virtual const entry_ref* FontFileAt(int32 index) const; - virtual const entry_ref* FontFileFor(const char* family, - const char* style) const; - - virtual const char* FamilyFor(const entry_ref* fontFile) const; - virtual const char* StyleFor(const entry_ref* fontFile) const; - - virtual const char* FullFamilyFor(const entry_ref* fontFile) const; - virtual const char* PostScriptNameFor(const entry_ref* fontFile) const; - - virtual int32 CountFontFiles() const; - - private: - void _MakeEmpty(); - static int32 _update(void* cookie); - void _Update(BDirectory* fontFolder); - - struct font_file { - char* family_name; - char* style_name; - char* full_family_name; - char* ps_name; - entry_ref ref; - }; - - font_file* _FontFileFor(const entry_ref* ref) const; - - FT_Library fLibrary; // the FreeType fLibrary - - BList fFontFiles; - - static FontManager* fDefaultManager; -}; - -#endif // FT_FONT_MANAGER_H diff --git a/src/servers/app/drawing/old_but_informative/GraphicsBuffer.cpp b/src/servers/app/drawing/old_but_informative/GraphicsBuffer.cpp deleted file mode 100644 index 4c5ed71a04..0000000000 --- a/src/servers/app/drawing/old_but_informative/GraphicsBuffer.cpp +++ /dev/null @@ -1,97 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: GraphicsBuffer.cpp -// Author: DarkWyrm -// -// Description: Convenience class for working with graphics buffers -// Based on concepts from the Anti-Grain Geometry vector gfx library -//------------------------------------------------------------------------------ -#include "GraphicsBuffer.h" - -GraphicsBuffer::GraphicsBuffer(uint8 *buffer, uint32 width, uint32 height, uint32 rowbytes) -{ - fBuffer=NULL; - fRowList=NULL; - fWidth=0; - fHeight=0; - fBytesPerRow=0; - fMaxHeight=0; - - SetTo(buffer, width, height, rowbytes); -} - -GraphicsBuffer::GraphicsBuffer(const GraphicsBuffer &buffer) -{ - SetTo(buffer.fBuffer, buffer.fWidth, buffer.fHeight, buffer.fBytesPerRow); -} - -GraphicsBuffer::~GraphicsBuffer() -{ - delete [] fRowList; -} - -void GraphicsBuffer::SetTo(uint8 *buffer, uint32 width, uint32 height, uint32 rowbytes) -{ - fBuffer = buffer; - fWidth = width; - fHeight = height; - fBytesPerRow = rowbytes; - - if(height > fMaxHeight) - { - delete [] fRowList; - fRowList = new uint8* [fMaxHeight = height]; - } - - uint8 *row_ptr = fBuffer; - - if(rowbytes < 0) - { - row_ptr = fBuffer - int(height - 1) * rowbytes; - } - - uint8 **rows = fRowList; - - while(height--) - { - *rows++ = row_ptr; - row_ptr += rowbytes; - } -} - -void GraphicsBuffer::Unset(void) -{ - delete [] fRowList; - fBuffer=NULL; - fRowList=NULL; - fWidth=0; - fHeight=0; - fBytesPerRow=0; - fMaxHeight=0; -} - - -GraphicsBuffer &GraphicsBuffer::operator=(const GraphicsBuffer &buffer) -{ - SetTo(buffer.fBuffer, buffer.fWidth, buffer.fHeight, buffer.fBytesPerRow); - return *this; -} diff --git a/src/servers/app/drawing/old_but_informative/GraphicsBuffer.h b/src/servers/app/drawing/old_but_informative/GraphicsBuffer.h deleted file mode 100644 index 8b5fc321c7..0000000000 --- a/src/servers/app/drawing/old_but_informative/GraphicsBuffer.h +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: GraphicsBuffer.h -// Author: DarkWyrm -// -// Description: Convenience class for working with graphics buffers -// Based on concepts from the Anti-Grain Geometry vector gfx library -//------------------------------------------------------------------------------ -#ifndef GFX_BUFFER_H -#define GFX_BUFFER_H - -#include - -class GraphicsBuffer -{ -public: - GraphicsBuffer(uint8 *buffer, uint32 width, uint32 height, uint32 rowbytes); - GraphicsBuffer(const GraphicsBuffer &buffer); - ~GraphicsBuffer(); - - void SetTo(uint8 *buffer, uint32 width, uint32 height, uint32 rowbytes); - void Unset(void); - - uint8 *Bits(void) const { return fBuffer; } - uint8 *RowAt(uint32 row) { return fRowList[row]; } - - uint32 Width(void) const { return fWidth; } - uint32 Height(void) const { return fHeight; } - - uint32 BytesPerRow(void) const { return fBytesPerRow; } - GraphicsBuffer &operator=(const GraphicsBuffer &buf); - -private: - - uint32 fWidth; - uint32 fHeight; - uint8 *fBuffer; - uint8 **fRowList; - uint32 fBytesPerRow; - uint32 fMaxHeight; -}; - -#endif diff --git a/src/servers/app/drawing/old_but_informative/PixelRenderer.cpp b/src/servers/app/drawing/old_but_informative/PixelRenderer.cpp deleted file mode 100644 index 0bda6afa55..0000000000 --- a/src/servers/app/drawing/old_but_informative/PixelRenderer.cpp +++ /dev/null @@ -1,278 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: PixelRenderer.h -// Author: DarkWyrm -// -// Description: Base class for pixel plotting renderers -// Based on concepts from the Anti-Grain Geometry vector gfx library -//------------------------------------------------------------------------------ -#include "PixelRenderer.h" -#include -#include "IPoint.h" - -PixelRenderer::PixelRenderer(GraphicsBuffer &buffer) -{ - fBuffer=&buffer; -} - -PixelRenderer::~PixelRenderer(void) -{ -} - -RGBColor PixelRenderer::GetPixel(const IPoint &pt) -{ - RGBColor c(0,0,0,0); - return c; -} - -void PixelRenderer::PixelRenderer::PutPixel(const IPoint &pt, RGBColor &c) -{ -} - -void PixelRenderer::PutHLine(const IPoint &pt, const uint32 length, RGBColor &c) -{ -} - -void PixelRenderer::PutVLine(const IPoint &pt, const uint32 length, RGBColor &c) -{ -} - -//---------------------------------------------------------------------------------------- -// -// PixelRendererRGBA32: 32-Bit color handler -// -//---------------------------------------------------------------------------------------- - -PixelRendererRGBA32::PixelRendererRGBA32(GraphicsBuffer &buffer) - : PixelRenderer(buffer) -{ -} - -PixelRendererRGBA32::~PixelRendererRGBA32(void) -{ -} - -RGBColor PixelRendererRGBA32::GetPixel(const IPoint &pt) -{ - uint8 *pixel=GetBuffer()->RowAt(pt.y) + (pt.x << 2); - return RGBColor(pixel[2],pixel[1],pixel[0],pixel[3]); -} - -void PixelRendererRGBA32::PutPixel(const IPoint &pt, RGBColor &color) -{ - rgb_color c=color.GetColor32(); - - uint8 *pixel=GetBuffer()->RowAt(pt.y) + (pt.x << 2); - - pixel[0]=c.blue; - pixel[1]=c.green; - pixel[2]=c.red; - pixel[3]=c.alpha; -} - -void PixelRendererRGBA32::PutHLine(const IPoint &pt, const uint32 length, RGBColor &color) -{ - rgb_color c=color.GetColor32(); - - uint32 *pixel32=(uint32*)GetBuffer()->RowAt(pt.y); - uint8 *pixel=(uint8*)&(pixel32[pt.x]); - - pixel[0]=c.blue; - pixel[1]=c.green; - pixel[2]=c.red; - pixel[3]=c.alpha; - int32 color32=*pixel32; - - uint32 end=pt.x+length; - - for(uint32 i=pt.x+1; iRowAt(pt.y); - uint8 *pixel=(uint8*)&(pixel32[pt.x]); - - pixel[0]=c.blue; - pixel[1]=c.green; - pixel[2]=c.red; - pixel[3]=c.alpha; - int32 color32=*pixel32; - - uint32 end=pt.y+length; - - for(uint32 i=pt.y+1; iRowAt(i); - pixel32[pt.x]=color32; - } -} - -//---------------------------------------------------------------------------------------- -// -// PixelRendererRGB16: 16-Bit color handler -- 565 space -// -//---------------------------------------------------------------------------------------- - -PixelRendererRGB16::PixelRendererRGB16(GraphicsBuffer &buffer) - : PixelRenderer(buffer) -{ -} - -PixelRendererRGB16::~PixelRendererRGB16(void) -{ -} - -// TODO: Double check the values in RGB16 renderer to make sure they are correct for little endian - -RGBColor PixelRendererRGB16::GetPixel(const IPoint &pt) -{ - uint16 pixel=((uint16*)GetBuffer()->RowAt(pt.y))[pt.x]; - return RGBColor( (pixel<<3) & 248, (pixel>>3) & 252, (pixel>>8) & 248); -} - -void PixelRendererRGB16::PutPixel(const IPoint &pt, RGBColor &c) -{ - ((uint16*)GetBuffer()->RowAt(pt.y))[pt.x]=c.GetColor16(); -} - -void PixelRendererRGB16::PutHLine(const IPoint &pt, const uint32 length, RGBColor &color) -{ - uint16 *pixel16=(uint16*)GetBuffer()->RowAt(pt.y); - uint32 end=pt.x+length; - - for(uint32 i=pt.x; iRowAt(i); - index[pt.x]=color.GetColor16(); - } -} - -//---------------------------------------------------------------------------------------- -// -// PixelRendererRGBA15: 15-Bit color handler -- 5551 space -// -//---------------------------------------------------------------------------------------- - -PixelRendererRGBA15::PixelRendererRGBA15(GraphicsBuffer &buffer) - : PixelRenderer(buffer) -{ -} - -PixelRendererRGBA15::~PixelRendererRGBA15(void) -{ -} - -// TODO: Double check the values in RGBA15 renderer to make sure they are correct for little endian - -RGBColor PixelRendererRGBA15::GetPixel(const IPoint &pt) -{ - uint16 pixel=((uint16*)GetBuffer()->RowAt(pt.y))[pt.x]; - return RGBColor( (pixel<<3) & 248, - (pixel>>3) & 252, - (pixel>>7) & 248, - ((pixel>>8) & 128)?255:0 ); -} - -void PixelRendererRGBA15::PutPixel(const IPoint &pt, RGBColor &color) -{ - ((uint16*)GetBuffer()->RowAt(pt.y))[pt.x]=color.GetColor15(); -} - -void PixelRendererRGBA15::PutHLine(const IPoint &pt, const uint32 length, RGBColor &color) -{ - uint16 *pixel16=(uint16*)GetBuffer()->RowAt(pt.y); - uint32 end=pt.x+length; - - for(uint32 i=pt.x; iRowAt(i); - index[pt.x]=color.GetColor15(); - } -} - -//---------------------------------------------------------------------------------------- -// -// PixelRendererCMAP8: 8-Bit color handler -// -//---------------------------------------------------------------------------------------- - -PixelRendererCMAP8::PixelRendererCMAP8(GraphicsBuffer &buffer) - : PixelRenderer(buffer) -{ -} - -PixelRendererCMAP8::~PixelRendererCMAP8(void) -{ -} - -// TODO: Double check the values in CMAP8 renderer to make sure they are correct for little endian - -RGBColor PixelRendererCMAP8::GetPixel(const IPoint &pt) -{ - uint8 pixel=((uint8*)GetBuffer()->RowAt(pt.y))[pt.x]; - return RGBColor(pixel); -} - -void PixelRendererCMAP8::PutPixel(const IPoint &pt, RGBColor &color) -{ - (GetBuffer()->RowAt(pt.y))[pt.x]=color.GetColor8(); -} - -void PixelRendererCMAP8::PutHLine(const IPoint &pt, const uint32 length, RGBColor &color) -{ - uint8 *index=GetBuffer()->RowAt(pt.y)+pt.x; - memset(index,color.GetColor8(),length); -} - -void PixelRendererCMAP8::PutVLine(const IPoint &pt, const uint32 length, RGBColor &color) -{ - uint8 *index=GetBuffer()->RowAt(pt.y)+pt.x; - uint32 end=pt.y+length; - - for(uint32 i=pt.y; iBytesPerRow(); - } -} diff --git a/src/servers/app/drawing/old_but_informative/PixelRenderer.h b/src/servers/app/drawing/old_but_informative/PixelRenderer.h deleted file mode 100644 index 91b3ce3146..0000000000 --- a/src/servers/app/drawing/old_but_informative/PixelRenderer.h +++ /dev/null @@ -1,125 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: PixelRenderer.cpp -// Author: DarkWyrm -// -// Description: Base class for pixel plotting renderers -// Based on concepts from the Anti-Grain Geometry vector gfx library -//------------------------------------------------------------------------------ -#ifndef PIXEL_RENDERER -#define PIXEL_RENDERER - -#include "GraphicsBuffer.h" -#include "GraphicsDefs.h" -#include "RGBColor.h" - -class IPoint; - -class PixelRenderer -{ -public: - PixelRenderer(GraphicsBuffer &buffer); - virtual ~PixelRenderer(void); - - virtual color_space ColorSpace(void) { return B_NO_COLOR_SPACE; } - - virtual RGBColor GetPixel(const IPoint &pt); - virtual void PutPixel(const IPoint &pt, RGBColor &c); - virtual void PutHLine(const IPoint &pt, const uint32 length, RGBColor &c); - virtual void PutVLine(const IPoint &pt, const uint32 length, RGBColor &c); - - virtual void SetBuffer(GraphicsBuffer &buffer) { fBuffer=&buffer; } - GraphicsBuffer *GetBuffer(void) const { return fBuffer; } - -private: - GraphicsBuffer *fBuffer; -}; - -class PixelRendererRGBA32 : public PixelRenderer -{ -public: - PixelRendererRGBA32(GraphicsBuffer &buffer); - virtual ~PixelRendererRGBA32(void); - - virtual color_space ColorSpace(void) { return B_RGBA32; } - - virtual RGBColor GetPixel(const IPoint &pt); - virtual void PutPixel(const IPoint &pt, RGBColor &c); - virtual void PutHLine(const IPoint &pt, const uint32 length, RGBColor &c); - virtual void PutVLine(const IPoint &pt, const uint32 length, RGBColor &c); -}; - -class PixelRendererRGB16 : public PixelRenderer -{ -public: - PixelRendererRGB16(GraphicsBuffer &buffer); - virtual ~PixelRendererRGB16(void); - - virtual color_space ColorSpace(void) { return B_RGB16; } - - virtual RGBColor GetPixel(const IPoint &pt); - virtual void PutPixel(const IPoint &pt, RGBColor &c); - virtual void PutHLine(const IPoint &pt, const uint32 length, RGBColor &c); - virtual void PutVLine(const IPoint &pt, const uint32 length, RGBColor &c); -}; - -class PixelRendererRGBA15 : public PixelRenderer -{ -public: - PixelRendererRGBA15(GraphicsBuffer &buffer); - virtual ~PixelRendererRGBA15(void); - - virtual color_space ColorSpace(void) { return B_RGBA15; } - - virtual RGBColor GetPixel(const IPoint &pt); - virtual void PutPixel(const IPoint &pt, RGBColor &c); - virtual void PutHLine(const IPoint &pt, const uint32 length, RGBColor &c); - virtual void PutVLine(const IPoint &pt, const uint32 length, RGBColor &c); -}; - -class PixelRendererCMAP8 : public PixelRenderer -{ -public: - PixelRendererCMAP8(GraphicsBuffer &buffer); - virtual ~PixelRendererCMAP8(void); - - virtual color_space ColorSpace(void) { return B_CMAP8; } - - virtual RGBColor GetPixel(const IPoint &pt); - virtual void PutPixel(const IPoint &pt, RGBColor &c); - virtual void PutHLine(const IPoint &pt, const uint32 length, RGBColor &c); - virtual void PutVLine(const IPoint &pt, const uint32 length, RGBColor &c); -}; - -// TODO: These inlines probably should go in ColorUtils -inline uint16 MakeRGB16Color(uint8 r, uint8 g, uint8 b) -{ - return (uint16)(((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3)); -} - -// TODO: Doublecheck to make sure the shifting is correct in MakeRGBA15Color -inline uint16 MakeRGBA15Color(uint8 r, uint8 g, uint8 b, bool visible=true) -{ - return (uint16)(((r & 0xF8) << 7) | ((g & 0xF8) << 2) | (b >> 3)); -} - -#endif diff --git a/src/servers/app/drawing/old_but_informative/RectUtils.cpp b/src/servers/app/drawing/old_but_informative/RectUtils.cpp deleted file mode 100644 index 9d14ce866e..0000000000 --- a/src/servers/app/drawing/old_but_informative/RectUtils.cpp +++ /dev/null @@ -1,131 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: RectUtils.cpp -// Author: DarkWyrm -// Description: Utilities for work around R5 Interface Kit bugs -// -//------------------------------------------------------------------------------ -#include "RectUtils.h" - -/*! - \brief Checks for the intersection of two rectangles. Works properly, - unlike BRect::Intersects - - \param r First rectangle - \param r2 Second rectangle - \return True if they intersect, false if they don't. - - The two rectangles intersect if they are equal, one contains the other, - or if any edge intersects any edge of the other rectangle. -*/ -bool TestRectIntersection(const BRect &r,const BRect &r2) -{ - return TestLineIntersection(r, r2.left, r2.top, r2.left, r2.bottom) || - TestLineIntersection(r, r2.left, r2.top, r2.right, r2.top, false) || - TestLineIntersection(r, r2.right, r2.top, r2.right, r2.bottom) || - TestLineIntersection(r, r2.left, r2.bottom, r2.right, r2.bottom, false) || - r.Contains(r2) || - r2.Contains(r); -} - -/*! - \brief Checks to see if a region intersects with a particular rectangle - - \param r Region - \param r2 Rectangle to check intersection with - \return True if they intersect, false if they don't. - - The two intersect if they the rectangle intersects any one rectangle in the - region. -*/ -bool TestRegionIntersection(BRegion *r,const BRect &r2) -{ - for(int32 i=0; iCountRects(); i++) - if(TestRectIntersection(r->RectAt(i),r2)); - return true; - return false; -} - -/*! - \brief Modifies the region to intersect with the rectangle given - - \param r Region - \param r2 Rectangle to intersect with -*/ -void IntersectRegionWith(BRegion *r,const BRect &r2) -{ - // We have three conditions: - // 1) Region frame contains rect. Action: call Include() - // 2) Rect intersects region frame. Action: call IntersectWith - // 3) Region frame does not intersect rectangle. Make the region empty - if(r->Frame().Contains(r2)) - r->Include(r2); - if(r->Frame().Intersects(r2)) - { - BRegion reg(r2); - r->IntersectWith(®); - } - else - r->MakeEmpty(); -} - -/*! - \brief Checks for the intersection of a line with a rectangle - - \param r Rectangle - \param x1 starting x of line - \param y1 starting y of line - \param x2 ending x of line - \param y2 ending y of line - \param vertical Test for vertical intersection - \return true if they intersect, false if not -*/ -bool TestLineIntersection(const BRect& r, float x1, float y1, float x2, float y2, - bool vertical) -{ - if (vertical) - { - return (x1 >= r.left && x1 <= r.right) && - ((y1 >= r.top && y1 <= r.bottom) || - (y2 >= r.top && y2 <= r.bottom)); - } - else - { - return (y1 >= r.top && y1 <= r.bottom) && - ((x1 >= r.left && x1 <= r.right) || - (x2 >= r.left && x2 <= r.right)); - } -} - -/*! - \brief Ensures that a BRect's IsValid() member returns true - \param rect BRect to validate -*/ -void ValidateRect(BRect *rect) -{ - float l,r,t,b; - l=(rect->leftright)?rect->left:rect->right; - r=(rect->left>rect->right)?rect->left:rect->right; - t=(rect->topbottom)?rect->top:rect->bottom; - b=(rect->top>rect->bottom)?rect->top:rect->bottom; - rect->Set(l,t,r,b); -} diff --git a/src/servers/app/drawing/old_but_informative/RectUtils.h b/src/servers/app/drawing/old_but_informative/RectUtils.h deleted file mode 100644 index 85c0caf717..0000000000 --- a/src/servers/app/drawing/old_but_informative/RectUtils.h +++ /dev/null @@ -1,38 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: RectUtils.h -// Author: DarkWyrm -// Description: Utilities for work around R5 Interface Kit bugs -// -//------------------------------------------------------------------------------ -#ifndef RECTUTILS_H_ -#define RECTUTILS_H_ - -#include -#include - -bool TestLineIntersection(const BRect&r, float x1, float y1, float x2, float y2,bool vertical=true); -bool TestRectIntersection(const BRect &r,const BRect &r2); -bool TestRegionIntersection(BRegion *r,const BRect &r2); -void IntersectRegionWith(BRegion *r,const BRect &r2); -void ValidateRect(BRect *r); -#endif diff --git a/src/servers/app/drawing/old_but_informative/ScreenDriver.cpp b/src/servers/app/drawing/old_but_informative/ScreenDriver.cpp deleted file mode 100644 index edae805885..0000000000 --- a/src/servers/app/drawing/old_but_informative/ScreenDriver.cpp +++ /dev/null @@ -1,1488 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: ScreenDriver.cpp -// Author: DarkWyrm -// Description: BView/BWindow combination graphics module -// -//------------------------------------------------------------------------------ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Angle.h" -#include "PortLink.h" -#include "ServerProtocol.h" -#include "ServerBitmap.h" -#include "ScreenDriver.h" -#include "ServerConfig.h" -#include "ServerCursor.h" -#include "ServerFont.h" -#include "FontFamily.h" -#include "LayerData.h" -#include "PNGDump.h" -#include "PatternHandler.h" - -#ifdef DEBUG_DRIVER_MODULE -# include -# define STRACE(x) printf x -#else -# define STRACE(x) ; -#endif - -enum -{ -SDWIN_CLEAR=100, - -SDWIN_SHOWCURSOR, -SDWIN_HIDECURSOR, -SDWIN_OBSCURECURSOR, -SDWIN_MOVECURSOR, -SDWIN_SETCURSOR, -}; - -extern RGBColor workspace_default_color; - -FrameBuffer::FrameBuffer(const char *title, uint32 space, status_t *st,bool debug) - : BWindowScreen(title,space,st,debug) -{ - is_connected=false; - port_id serverport=find_port(SERVER_INPUT_PORT); - serverlink=new PortLink(serverport); - mousepos.Set(0,0); - buttons=0; - viewbmp=new BBitmap(BRect(0,0,639,479),B_CMAP8,true); - - // View exists to poll for the mouse - view=new BView(Bounds(),"view",0,0); - AddChild(view); - view->GetMouse(&mousepos,&buttons); - - invalid=new BRegion(Bounds()); - invalidflag=0; - -#ifdef ENABLE_INPUT_SERVER_EMULATION - monitor_thread=spawn_thread(MouseMonitor,"mousemonitor",B_NORMAL_PRIORITY,this); - resume_thread(monitor_thread); -#endif - - copy_thread=spawn_thread(CopyThread,"copymonitor",B_NORMAL_PRIORITY,this); - resume_thread(copy_thread); -} - -FrameBuffer::~FrameBuffer(void) -{ - kill_thread(copy_thread); - kill_thread(monitor_thread); - delete viewbmp; - delete invalid; - delete serverlink; -} - -void FrameBuffer::ScreenConnected(bool connected) -{ - is_connected=connected; - if(connected) - { - // Cache the state just in case - graphics_card_info *info=CardInfo(); - gcinfo=*info; - } -} - -void FrameBuffer::MessageReceived(BMessage *msg) -{ - switch(msg->what) - { - case B_KEY_DOWN: - { - int32 key,modifiers; - msg->FindInt32("key",&key); - msg->FindInt32("modifiers",&modifiers); - - int32 servermods=0; - servermods|=modifiers & B_RIGHT_COMMAND_KEY; - servermods|=modifiers & B_RIGHT_OPTION_KEY; - servermods|=modifiers & B_RIGHT_CONTROL_KEY; - servermods|=modifiers & B_SHIFT_KEY; - - switch(key) - { - case 0x47: // Enter key - { - port_id serverport=find_port(SERVER_PORT_NAME); - write_port(serverport,B_QUIT_REQUESTED,NULL,0); - break; - } - default: - break; - } - } - -#ifdef ENABLE_INPUT_SERVER_EMULATION - case B_MOUSE_WHEEL_CHANGED: - { - float x,y; - msg->FindFloat("be:wheel_delta_x",&x); - msg->FindFloat("be:wheel_delta_y",&y); - int64 time=real_time_clock(); - serverlink->SetOpCode(B_MOUSE_WHEEL_CHANGED); - serverlink->Attach(&time,sizeof(int64)); - serverlink->Attach(x); - serverlink->Attach(y); - serverlink->Flush(); - break; - } -#endif - default: - BWindowScreen::MessageReceived(msg); - } -} - -bool FrameBuffer::QuitRequested(void) -{ - port_id serverport=find_port(SERVER_PORT_NAME); - - if(serverport!=B_NAME_NOT_FOUND) - write_port(serverport,B_QUIT_REQUESTED,NULL,0); - - return true; -} - -int32 FrameBuffer::CopyThread(void *data) -{ - FrameBuffer *fb=(FrameBuffer*)data; - - while(1) - { - if(fb->IsConnected()) - { - if(fb->invalidflag) - { - fb->Lock(); - fb->viewbmp->Lock(); - - if(fb->invalid) - { - int8 *start_ptr; - clipping_rect r; - for(int32 i=0; iinvalid->CountRects(); i++) - { - // Copy from viewbmp to framebuffer - start_ptr=(int8*)fb->viewbmp->Bits(); - r=fb->invalid->RectAtInt(i); - memcpy(fb->gcinfo.frame_buffer,start_ptr,fb->viewbmp->BitsLength()); - } - } - - fb->viewbmp->Unlock(); - fb->Unlock(); - } - } - } - - return 0; -} - -int32 FrameBuffer::MouseMonitor(void *data) -{ - FrameBuffer *fb=(FrameBuffer*)data; - BPoint mousepos(0,0),oldpos(0,0); - uint32 buttons=0, oldbuttons=0; - uint32 clicks=1; // TODO: add multiclick support - uint32 mods; - int64 time; - - fb->Lock(); - PortLink *link=new PortLink(fb->serverlink->GetPort()); - fb->view->GetMouse(&mousepos,&buttons); - oldpos=mousepos; - oldbuttons=buttons; - fb->Unlock(); - - while(1) - { - if(fb->IsConnected()) - { - // Get the mouse position - fb->Lock(); - fb->view->GetMouse(&mousepos,&buttons); - fb->Unlock(); - - // Check for changes and post messages as necessary - - // Mouse button change? - if(buttons!=oldbuttons) - { - time=(int64)real_time_clock(); - mods=modifiers(); - if(oldbuttons==0) - { - // MouseDown - link->SetOpCode(B_MOUSE_DOWN); - link->Attach(&time, sizeof(int64)); - link->Attach(&mousepos.x,sizeof(float)); - link->Attach(&mousepos.y,sizeof(float)); - link->Attach(&mods, sizeof(uint32)); - link->Attach(&buttons, sizeof(uint32)); - link->Attach(&clicks, sizeof(uint32)); - link->Flush(); - } - else - { - // MouseUp - link->SetOpCode(B_MOUSE_UP); - link->Attach(&time, sizeof(int64)); - link->Attach(&mousepos.x,sizeof(float)); - link->Attach(&mousepos.y,sizeof(float)); - link->Attach(&mods, sizeof(uint32)); - link->Flush(); - } - oldbuttons=buttons; - } - - // Mouse Position change? - if( (mousepos.x!=oldpos.x) || (mousepos.y!=oldpos.y)) - { - time=(int64)real_time_clock(); - mods=modifiers(); - - // B_MOUSE_MOVED - link->SetOpCode(B_MOUSE_MOVED); - link->Attach(&time, sizeof(int64)); - link->Attach(&mousepos.x,sizeof(float)); - link->Attach(&mousepos.y,sizeof(float)); - link->Attach(&mods, sizeof(int32)); - link->Attach(&buttons, sizeof(uint32)); - link->Attach(&clicks, sizeof(uint32)); - link->Flush(); - oldpos=mousepos; - } - - // Mouse wheel support messages are actually sent to BWindowScreens, - // so we handle that in MessageReceived - } - snooze(150); - } - - delete link; -} - -void FrameBuffer::Invalidate(const BRect &r) -{ - if(invalid) - invalid->Include(r); - else - invalid=new BRegion(r); -} - -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- - -ScreenDriver::ScreenDriver(void) -{ - status_t st; - screenwin=new FrameBuffer("OBAppServer",B_8_BIT_640x480,&st,false); - - framebuffer=screenwin->viewbmp; - serverlink=screenwin->serverlink; - hide_cursor=0; - _SetWidth(640); - _SetHeight(480); - _SetDepth(8); - _SetMode(B_8_BIT_640x480); - _SetBytesPerRow(framebuffer->BytesPerRow()); -} - -ScreenDriver::~ScreenDriver(void) -{ - if(is_initialized) - { - screenwin->Lock(); - screenwin->Quit(); - screenwin=NULL; - } -} - -bool ScreenDriver::Initialize(void) -{ - Lock(); - drawview=new BView(framebuffer->Bounds(),"drawview",B_FOLLOW_ALL, B_WILL_DRAW); - framebuffer->AddChild(drawview); - - hide_cursor=0; - obscure_cursor=false; - - is_initialized=true; - - // We can afford to call the above functions without locking - // because the window is locked until Show() is first called - screenwin->Show(); - Unlock(); - return true; -} - -void ScreenDriver::Shutdown(void) -{ - Lock(); - screenwin->Disconnect(); - is_initialized=false; - Unlock(); -} - -void ScreenDriver::SetMode(const display_mode &mode) -{ - screenwin->Lock(); - int16 w=mode.virtual_width,h=mode.virtual_height; - color_space s=(color_space)mode.space; - - screenwin->ResizeTo(w-1,h-1); - - // Clear the invalid flag so that there is no danger of a crash - while(screenwin->invalidflag>0) - atomic_add(&screenwin->invalidflag,-1); - - delete framebuffer; - - // don't forget to update the internal vars! - _SetWidth(w); - _SetHeight(h); - _SetMode(s); - - screenwin->SetSpace((uint32)s); - - screenwin->viewbmp=new BBitmap(screenwin->Bounds(),s,true); - framebuffer=screenwin->viewbmp; - drawview=new BView(framebuffer->Bounds(),"drawview",B_FOLLOW_ALL, B_WILL_DRAW); - framebuffer->AddChild(drawview); - - framebuffer->Lock(); - drawview->SetHighColor(workspace_default_color.GetColor32()); - drawview->FillRect(drawview->Bounds()); - drawview->Sync(); - framebuffer->Unlock(); - - screenwin->Invalidate(framebuffer->Bounds()); - - _SetBytesPerRow(framebuffer->BytesPerRow()); - atomic_add(&screenwin->invalidflag,1); - screenwin->Unlock(); -} - -void ScreenDriver::SetMode(int32 space) -{ - screenwin->Lock(); - int16 w=640,h=480; - color_space s=B_CMAP8; - - switch(space) - { - case B_32_BIT_800x600: - case B_16_BIT_800x600: - case B_8_BIT_800x600: - { - w=800; h=600; - break; - } - case B_32_BIT_1024x768: - case B_16_BIT_1024x768: - case B_8_BIT_1024x768: - { - w=1024; h=768; - break; - } - default: - break; - } - screenwin->ResizeTo(w-1,h-1); - - switch(space) - { - case B_32_BIT_640x480: - case B_32_BIT_800x600: - case B_32_BIT_1024x768: - s=B_RGBA32; - _SetDepth(32); - break; - case B_16_BIT_640x480: - case B_16_BIT_800x600: - case B_16_BIT_1024x768: - s=B_RGBA15; - _SetDepth(15); - break; - case B_8_BIT_640x480: - case B_8_BIT_800x600: - case B_8_BIT_1024x768: - s=B_CMAP8; - _SetDepth(8); - break; - default: - _SetDepth(8); - break; - } - - // Clear the invalid flag so that there is no danger of a crash - while(screenwin->invalidflag>0) - atomic_add(&screenwin->invalidflag,-1); - - delete framebuffer; - - // don't forget to update the internal vars! - _SetWidth(w); - _SetHeight(h); - _SetMode(space); - - screenwin->SetSpace((uint32)space); - - screenwin->viewbmp=new BBitmap(screenwin->Bounds(),s,true); - framebuffer=screenwin->viewbmp; - drawview=new BView(framebuffer->Bounds(),"drawview",B_FOLLOW_ALL, B_WILL_DRAW); - framebuffer->AddChild(drawview); - - framebuffer->Lock(); - drawview->SetHighColor(workspace_default_color.GetColor32()); - drawview->FillRect(drawview->Bounds()); - drawview->Sync(); - framebuffer->Unlock(); - - screenwin->Invalidate(framebuffer->Bounds()); - - _SetBytesPerRow(framebuffer->BytesPerRow()); - atomic_add(&screenwin->invalidflag,1); - screenwin->Unlock(); -} - -void ScreenDriver::CopyBits(BRect src, BRect dest) -{ - screenwin->Lock(); - framebuffer->Lock(); - drawview->CopyBits(src,dest); - drawview->Sync(); - screenwin->view->Invalidate(src); - screenwin->view->Invalidate(dest); - framebuffer->Unlock(); - screenwin->Unlock(); -} - -void ScreenDriver::DrawBitmap(ServerBitmap *bitmap, BRect src, BRect dest) -{ -STRACE(("ScreenDriver:: DrawBitmap unimplemented()\n")); -} - -void ScreenDriver::DrawChar(char c, BPoint pt, LayerData *d) -{ - char str[2]; - str[0]=c; - str[1]='\0'; - DrawString(str, 1, pt, d); -} -/* -void ScreenDriver::DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *delta=NULL) -{ -STRACE(("ScreenDriver:: DrawString(\"%s\",%ld,BPoint(%f,%f))\n",string,length,pt.x,pt.y)); - if(!d) - return; - BRect r; - - screenwin->Lock(); - framebuffer->Lock(); - - SetLayerData(d,true); // set all layer data and additionally set the font-related data - - drawview->DrawString(string,length,pt,delta); - drawview->Sync(); - - // calculate the invalid rectangle - font_height fh; - BFont font; - drawview->GetFont(&font); - drawview->GetFontHeight(&fh); - r.left=pt.x; - r.right=pt.x+font.StringWidth(string); - r.top=pt.y-fh.ascent; - r.bottom=pt.y+fh.descent; - screenwin->view->Invalidate(r); - - framebuffer->Unlock(); - screenwin->Unlock(); - -} -*/ - -bool ScreenDriver::DumpToFile(const char *path) -{ - // Dump to PNG - Lock(); - SaveToPNG(path,framebuffer->Bounds(),framebuffer->ColorSpace(), - framebuffer->Bits(),framebuffer->BitsLength(),framebuffer->BytesPerRow()); - - Unlock(); - return true; -} - -void ScreenDriver::FillArc(BRect r, float angle, float span, LayerData *d, const Pattern &pat) -{ - if(!d) - return; - screenwin->Lock(); - framebuffer->Lock(); - SetLayerData(d); - drawview->FillArc(r,angle,span,*((pattern*)pat.GetInt8())); - drawview->Sync(); - screenwin->view->Invalidate(r); - framebuffer->Unlock(); - screenwin->Unlock(); -} - -void ScreenDriver::FillBezier(BPoint *pts, LayerData *d, const Pattern &pat) -{ - if(!pts) - return; - screenwin->Lock(); - framebuffer->Lock(); - SetLayerData(d); - drawview->FillBezier(pts,*((pattern*)pat.GetInt8())); - drawview->Sync(); - - // Invalidate the whole view until I get around to adding in the invalid rect calc code - screenwin->view->Invalidate(); - framebuffer->Unlock(); - screenwin->Unlock(); -} - -void ScreenDriver::FillEllipse(BRect r, LayerData *d, const Pattern &pat) -{ - if(!d) - return; - screenwin->Lock(); - framebuffer->Lock(); - SetLayerData(d); - drawview->FillEllipse(r,*((pattern*)pat.GetInt8())); - drawview->Sync(); - screenwin->view->Invalidate(r); - framebuffer->Unlock(); - screenwin->Unlock(); -} - -void ScreenDriver::FillPolygon(BPoint *ptlist, int32 numpts, BRect rect, LayerData *d, const Pattern &pat) -{ - if(!d) - return; - screenwin->Lock(); - framebuffer->Lock(); - SetLayerData(d); - drawview->FillPolygon(ptlist,numpts,rect,*((pattern*)pat.GetInt8())); - drawview->Sync(); - screenwin->view->Invalidate(rect); - framebuffer->Unlock(); - screenwin->Unlock(); -} - -void ScreenDriver::FillRect(BRect r, LayerData *d, const Pattern &pat) -{ - if(!d) - return; - screenwin->Lock(); - framebuffer->Lock(); - SetLayerData(d); - drawview->FillRect(r,*((pattern*)pat.GetInt8())); - drawview->Sync(); - screenwin->view->Invalidate(r); - framebuffer->Unlock(); - screenwin->Unlock(); -} - -void ScreenDriver::FillRoundRect(BRect r, float xrad, float yrad, LayerData *d, const Pattern &pat) -{ - if(!d) - return; - screenwin->Lock(); - framebuffer->Lock(); - SetLayerData(d); - drawview->FillRoundRect(r,xrad,yrad,*((pattern*)pat.GetInt8())); - drawview->Sync(); - screenwin->view->Invalidate(r); - framebuffer->Unlock(); - screenwin->Unlock(); - -} - -void ScreenDriver::FillTriangle(BPoint *pts, BRect r, LayerData *d, const Pattern &pat) -{ - if(!pts) - return; - screenwin->Lock(); - framebuffer->Lock(); - BPoint first=pts[0],second=pts[1],third=pts[2]; - SetLayerData(d); - drawview->FillTriangle(first,second,third,r,*((pattern*)pat.GetInt8())); - drawview->Sync(); - screenwin->view->Invalidate(r); - framebuffer->Unlock(); - screenwin->Unlock(); - -} - -void ScreenDriver::HideCursor(void) -{ - screenwin->Lock(); - Lock(); - - hide_cursor++; - screenwin->PostMessage(SDWIN_HIDECURSOR); - - Unlock(); - screenwin->Unlock(); -} - -void ScreenDriver::InvertRect(BRect r) -{ - screenwin->Lock(); - framebuffer->Lock(); - drawview->InvertRect(r); - drawview->Sync(); - screenwin->view->Invalidate(r); - framebuffer->Unlock(); - screenwin->Unlock(); -} - -bool ScreenDriver::IsCursorHidden(void) -{ - screenwin->Lock(); - bool value=(hide_cursor>0)?true:false; - screenwin->Unlock(); - return value; -} - -void ScreenDriver::ObscureCursor(void) -{ - screenwin->Lock(); - screenwin->PostMessage(SDWIN_OBSCURECURSOR); - screenwin->Unlock(); -} - -void ScreenDriver::MoveCursorTo(float x, float y) -{ - screenwin->Lock(); - BMessage *msg=new BMessage(SDWIN_MOVECURSOR); - msg->AddFloat("x",x); - msg->AddFloat("y",y); - screenwin->PostMessage(msg); - screenwin->Unlock(); -} - -void ScreenDriver::SetCursor(ServerCursor *cursor) -{ -printf("SetCursor unimplemented\n"); -/* - if(cursor!=NULL) - { - screenwin->Lock(); - BBitmap *bmp=new BBitmap(cursor->Bounds(),B_RGBA32); - - // Copy the server bitmap in the cursor to a BBitmap - uint8 *sbmppos=(uint8*)cursor->Bits(), - *bbmppos=(uint8*)bmp->Bits(); - - int32 bytes=cursor->BytesPerRow(), - bbytes=bmp->BytesPerRow(); - - for(int i=0;i<=cursor->Bounds().IntegerHeight();i++) - memcpy(bbmppos+(i*bbytes), sbmppos+(i*bytes), bytes); - - // Replace the bitmap - delete screenwin->cursor; - screenwin->cursor=bmp; - screenwin->Invalidate(screenwin->view->cursorframe); - screenwin->Unlock(); - } -*/ -} - -void ScreenDriver::ShowCursor(void) -{ - screenwin->Lock(); - if(hide_cursor>0) - { - hide_cursor--; - screenwin->PostMessage(SDWIN_SHOWCURSOR); - } - screenwin->Unlock(); - -} - -void ScreenDriver::StrokeArc(BRect r, float angle, float span, LayerData *d, const Pattern &pat) -{ - if(!d) - return; - screenwin->Lock(); - framebuffer->Lock(); - SetLayerData(d); - drawview->StrokeArc(r,angle,span,*((pattern*)pat.GetInt8())); - drawview->Sync(); - screenwin->view->Invalidate(r); - framebuffer->Unlock(); - screenwin->Unlock(); - -} - -void ScreenDriver::StrokeBezier(BPoint *pts, LayerData *d, const Pattern &pat) -{ - if(!pts) - return; - screenwin->Lock(); - framebuffer->Lock(); - SetLayerData(d); - drawview->StrokeBezier(pts,*((pattern*)pat.GetInt8())); - drawview->Sync(); - - // Invalidate the whole view until I get around to adding in the invalid rect calc code - screenwin->view->Invalidate(); - framebuffer->Unlock(); - screenwin->Unlock(); - -} - -void ScreenDriver::StrokeEllipse(BRect r, LayerData *d, const Pattern &pat) -{ - if(!d) - return; - screenwin->Lock(); - framebuffer->Lock(); - SetLayerData(d); - drawview->StrokeEllipse(r,*((pattern*)pat.GetInt8())); - drawview->Sync(); - screenwin->view->Invalidate(r); - framebuffer->Unlock(); - screenwin->Unlock(); - -} - -void ScreenDriver::StrokeLine(BPoint start, BPoint end, LayerData *d, const Pattern &pat) -{ - if(!d) - return; - screenwin->Lock(); - framebuffer->Lock(); - SetLayerData(d); - drawview->StrokeLine(start,end,*((pattern*)pat.GetInt8())); - drawview->Sync(); - screenwin->view->Invalidate(BRect(start,end)); - framebuffer->Unlock(); - screenwin->Unlock(); -} - -void ScreenDriver::StrokeLineArray(BPoint *pts, int32 numlines, RGBColor *colors, LayerData *d) -{ -STRACE(("ScreenDriver:: StrokeLineArray unimplemented\n")); - -} - -void ScreenDriver::StrokePolygon(BPoint *ptlist, int32 numpts, BRect rect, LayerData *d, const Pattern &pat, bool is_closed) -{ - if(!ptlist) - return; - screenwin->Lock(); - framebuffer->Lock(); - - BRegion invalid; - - SetLayerData(d); - drawview->BeginLineArray(numpts+2); - for(int i=1;iAddLine(ptlist[i-1],ptlist[i],d->highcolor.GetColor32()); - invalid.Include(BRect(ptlist[i-1],ptlist[i])); - } - - if(is_closed) - { - drawview->AddLine(ptlist[numpts-1],ptlist[0],d->highcolor.GetColor32()); - invalid.Include(BRect(ptlist[numpts-1],ptlist[0])); - } - drawview->EndLineArray(); - - drawview->Sync(); - screenwin->view->Invalidate(invalid.Frame()); - framebuffer->Unlock(); - screenwin->Unlock(); - -} - -void ScreenDriver::StrokeRect(BRect r, LayerData *d, const Pattern &pat) -{ - if(!d) - return; - screenwin->Lock(); - framebuffer->Lock(); - SetLayerData(d); - drawview->StrokeRect(r,*((pattern*)pat.GetInt8())); - drawview->Sync(); - screenwin->view->Invalidate(r); - framebuffer->Unlock(); - screenwin->Unlock(); -} - -void ScreenDriver::StrokeRoundRect(BRect r, float xrad, float yrad, LayerData *d, const Pattern &pat) -{ - if(!d) - return; - screenwin->Lock(); - framebuffer->Lock(); - SetLayerData(d); - drawview->StrokeRoundRect(r,xrad,yrad,*((pattern*)pat.GetInt8())); - drawview->Sync(); - screenwin->view->Invalidate(r); - framebuffer->Unlock(); - screenwin->Unlock(); - -} - -void ScreenDriver::StrokeTriangle(BPoint *pts, BRect r, LayerData *d, const Pattern &pat) -{ - if(!pts || !d) - return; - screenwin->Lock(); - framebuffer->Lock(); - BPoint first=pts[0],second=pts[1],third=pts[2]; - SetLayerData(d); - drawview->StrokeTriangle(first,second,third,r,*((pattern*)pat.GetInt8())); - drawview->Sync(); - screenwin->view->Invalidate(r); - framebuffer->Unlock(); - screenwin->Unlock(); - -} - -void ScreenDriver::SetLayerData(LayerData *d, bool set_font_data) -{ - if(!d) - return; - - drawview->SetPenSize(d->pensize); - drawview->SetDrawingMode(d->draw_mode); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->SetScale(d->scale); - drawview->MovePenTo(d->penlocation); - if(set_font_data) - { - BFont font; - ServerFont *sf=&(d->font); - - if(!sf) - return; - - FontStyle *style=d->font.Style(); - - if(!style) - return; - - FontFamily *family=(FontFamily *)style->Family(); - if(!family) - return; - - font_family fontfamily; - strcpy(fontfamily,family->Name()); - font.SetFamilyAndStyle(fontfamily,style->Name()); - font.SetFlags(sf->Flags()); - font.SetEncoding(sf->Encoding()); - font.SetSize(sf->Size()); - font.SetRotation(sf->Rotation()); - font.SetShear(sf->Shear()); - font.SetSpacing(sf->Spacing()); - drawview->SetFont(&font); - } -} - -float ScreenDriver::StringWidth(const char *string, int32 length, LayerData *d) -{ - if(!string || !d) - return 0.0; - screenwin->Lock(); - - ServerFont *font=&(d->font); - FontStyle *style=font->Style(); - - if(!style) - return 0.0; - - FT_Face face; - FT_GlyphSlot slot; - FT_UInt glyph_index=0, previous=0; - FT_Vector pen,delta; - int16 error=0; - int32 strlength,i; - float returnval; - - error=FT_New_Face(ftlib, style->GetPath(), 0, &face); - if(error) - return 0.0; - - slot=face->glyph; - - bool use_kerning=FT_HAS_KERNING(face) && font->Spacing()==B_STRING_SPACING; - - error=FT_Set_Char_Size(face, 0,int32(font->Size())*64,72,72); - if(error) - return 0.0; - - // set the pen position in 26.6 cartesian space coordinates - pen.x=0; - - slot=face->glyph; - - strlength=strlen(string); - if(lengthadvance.x; - previous=glyph_index; - } - screenwin->Unlock(); - - FT_Done_Face(face); - - returnval=pen.x>>6; - return returnval; -} - -float ScreenDriver::StringHeight(const char *string, int32 length, LayerData *d) -{ - if(!string || !d) - return 0.0; - screenwin->Lock(); - - ServerFont *font=&(d->font); - FontStyle *style=font->Style(); - - if(!style) - return 0.0; - - FT_Face face; - FT_GlyphSlot slot; - int16 error=0; - int32 strlength,i; - float returnval=0.0,ascent=0.0,descent=0.0; - - error=FT_New_Face(ftlib, style->GetPath(), 0, &face); - if(error) - return 0.0; - - slot=face->glyph; - - error=FT_Set_Char_Size(face, 0,int32(font->Size())*64,72,72); - if(error) - return 0.0; - - slot=face->glyph; - - strlength=strlen(string); - if(lengthmetrics.horiBearingYmetrics.height) - descent=MAX((slot->metrics.height-slot->metrics.horiBearingY)>>6,descent); - else - ascent=MAX(slot->bitmap.rows,ascent); - } - screenwin->Unlock(); - - FT_Done_Face(face); - - returnval=ascent+descent; - return returnval; -} - -void ScreenDriver::DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *edelta) -{ - if(!string || !d) - return; - screenwin->Lock(); - - pt.y--; // because of Be's backward compatibility hack - - ServerFont *font=&(d->font); - FontStyle *style=font->Style(); - - if(!style) - return; - - FT_Face face; - FT_GlyphSlot slot; - FT_Matrix rmatrix,smatrix; - FT_UInt glyph_index=0, previous=0; - FT_Vector pen,delta,space,nonspace; - int16 error=0; - int32 strlength,i; - Angle rotation(font->Rotation()), shear(font->Shear()); - - bool antialias=( (font->Size()<18 && font->Flags()& B_DISABLE_ANTIALIASING==0) - || font->Flags()& B_FORCE_ANTIALIASING)?true:false; - - // Originally, I thought to do this shear checking here, but it really should be - // done in BFont::SetShear() - float shearangle=shear.Value(); - if(shearangle>135) - shearangle=135; - if(shearangle<45) - shearangle=45; - - if(shearangle>90) - shear=90+((180-shearangle)*2); - else - shear=90-(90-shearangle)*2; - - error=FT_New_Face(ftlib, style->GetPath(), 0, &face); - if(error) - return; - - slot=face->glyph; - - bool use_kerning=FT_HAS_KERNING(face) && font->Spacing()==B_STRING_SPACING; - - error=FT_Set_Char_Size(face, 0,int32(font->Size())*64,72,72); - if(error) - return; - - // if we do any transformation, we do a call to FT_Set_Transform() here - - // First, rotate - rmatrix.xx = (FT_Fixed)( rotation.Cosine()*0x10000); - rmatrix.xy = (FT_Fixed)(-rotation.Sine()*0x10000); - rmatrix.yx = (FT_Fixed)( rotation.Sine()*0x10000); - rmatrix.yy = (FT_Fixed)( rotation.Cosine()*0x10000); - - // Next, shear - smatrix.xx = (FT_Fixed)(0x10000); - smatrix.xy = (FT_Fixed)(-shear.Cosine()*0x10000); - smatrix.yx = (FT_Fixed)(0); - smatrix.yy = (FT_Fixed)(0x10000); - - FT_Matrix_Multiply(&rmatrix,&smatrix); - - // Set up the increment value for escapement padding - space.x=int32(d->edelta.space * rotation.Cosine()*64); - space.y=int32(d->edelta.space * rotation.Sine()*64); - nonspace.x=int32(d->edelta.nonspace * rotation.Cosine()*64); - nonspace.y=int32(d->edelta.nonspace * rotation.Sine()*64); - - // set the pen position in 26.6 cartesian space coordinates - pen.x=(int32)pt.x * 64; - pen.y=(int32)pt.y * 64; - - slot=face->glyph; - - - strlength=strlen(string); - if(lengthbitmap, - BPoint(slot->bitmap_left,pt.y-(slot->bitmap_top-pt.y)), d); - else - BlitMono2RGB32(&slot->bitmap, - BPoint(slot->bitmap_left,pt.y-(slot->bitmap_top-pt.y)), d); - } - - // increment pen position - pen.x+=slot->advance.x; - pen.y+=slot->advance.y; - previous=glyph_index; - } - - // TODO: implement properly - // calculate the invalid rectangle - BRect r; - r.left=MIN(pt.x,pen.x>>6); - r.right=MAX(pt.x,pen.x>>6); - r.top=pt.y-face->height; - r.bottom=pt.y+face->height; - - screenwin->view->Invalidate(r); - screenwin->Unlock(); - - FT_Done_Face(face); -} - -void ScreenDriver::BlitMono2RGB32(FT_Bitmap *src, BPoint pt, LayerData *d) -{ - rgb_color color=d->highcolor.GetColor32(); - - // pointers to the top left corner of the area to be copied in each bitmap - uint8 *srcbuffer, *destbuffer; - - // index pointers which are incremented during the course of the blit - uint8 *srcindex, *destindex, *rowptr, value; - - // increment values for the index pointers - int32 srcinc=src->pitch, destinc=framebuffer->BytesPerRow(); - - int16 i,j,k, srcwidth=src->pitch, srcheight=src->rows; - int32 x=(int32)pt.x,y=(int32)pt.y; - - // starting point in source bitmap - srcbuffer=(uint8*)src->buffer; - - if(y<0) - { - if(yframebuffer->Bounds().IntegerHeight()) - { - if(y>pt.y) - y--; - srcheight-=(y+srcheight-1)-framebuffer->Bounds().IntegerHeight(); - } - - if(x+srcwidth>framebuffer->Bounds().IntegerWidth()) - { - if(x>pt.x) - x--; - srcwidth-=(x+srcwidth-1)-framebuffer->Bounds().IntegerWidth(); - } - - if(x<0) - { - if(x>3; - srcwidth-=0-x; - destbuffer+=(0-x)*4; - } - - // starting point in destination bitmap - destbuffer=(uint8*)framebuffer->Bits()+int32( (pt.y*framebuffer->BytesPerRow())+(pt.x*4) ); - - srcindex=srcbuffer; - destindex=destbuffer; - - for(i=0; ihighcolor.GetColor32(), lowcolor=d->lowcolor.GetColor32(); float rstep,gstep,bstep,astep; - - rstep=float(highcolor.red-lowcolor.red)/255.0; - gstep=float(highcolor.green-lowcolor.green)/255.0; - bstep=float(highcolor.blue-lowcolor.blue)/255.0; - astep=float(highcolor.alpha-lowcolor.alpha)/255.0; - - // increment values for the index pointers - int32 x=(int32)pt.x, - y=(int32)pt.y, - srcinc=src->pitch, -// destinc=dest->BytesPerRow(), - destinc=framebuffer->BytesPerRow(), - srcwidth=src->width, - srcheight=src->rows, - incval=0; - - int16 i,j; - - // starting point in source bitmap - srcbuffer=(uint8*)src->buffer; - - // starting point in destination bitmap -// destbuffer=(uint8*)dest->Bits()+(y*dest->BytesPerRow()+(x*4)); - destbuffer=(uint8*)framebuffer->Bits()+(y*framebuffer->BytesPerRow()+(x*4)); - - - if(y<0) - { - if(yframebuffer->Bounds().IntegerHeight()) - { - if(y>pt.y) - y--; - srcheight-=(y+srcheight-1)-framebuffer->Bounds().IntegerHeight(); - } - - if(x+srcwidth>framebuffer->Bounds().IntegerWidth()) - { - if(x>pt.x) - x--; - srcwidth-=(x+srcwidth-1)-framebuffer->Bounds().IntegerWidth(); - } - - if(x<0) - { - if(xdraw_mode==B_OP_COPY) - { - rowptr[0]=uint8(highcolor.blue-(value*bstep)); - rowptr[1]=uint8(highcolor.green-(value*gstep)); - rowptr[2]=uint8(highcolor.red-(value*rstep)); - rowptr[3]=255; - } - else - if(d->draw_mode==B_OP_OVER) - { - if(highcolor.alpha>127) - { - rowptr[0]=uint8(highcolor.blue-(value*(float(highcolor.blue-rowptr[0])/255.0))); - rowptr[1]=uint8(highcolor.green-(value*(float(highcolor.green-rowptr[1])/255.0))); - rowptr[2]=uint8(highcolor.red-(value*(float(highcolor.red-rowptr[2])/255.0))); - rowptr[3]=255; - } - } - } - rowptr+=4; - - } - - srcindex+=srcinc; - destindex+=destinc; - } -} - -rgb_color ScreenDriver::GetBlitColor(rgb_color src, rgb_color dest, LayerData *d, bool use_high) -{ - rgb_color returncolor={0,0,0,0}; - int16 value; - if(!d) - return returncolor; - - switch(d->draw_mode) - { - case B_OP_COPY: - { - return src; - } - case B_OP_ADD: - { - value=src.red+dest.red; - returncolor.red=(value>255)?255:value; - - value=src.green+dest.green; - returncolor.green=(value>255)?255:value; - - value=src.blue+dest.blue; - returncolor.blue=(value>255)?255:value; - return returncolor; - } - case B_OP_SUBTRACT: - { - value=src.red-dest.red; - returncolor.red=(value<0)?0:value; - - value=src.green-dest.green; - returncolor.green=(value<0)?0:value; - - value=src.blue-dest.blue; - returncolor.blue=(value<0)?0:value; - return returncolor; - } - case B_OP_BLEND: - { - value=int16(src.red+dest.red)>>1; - returncolor.red=value; - - value=int16(src.green+dest.green)>>1; - returncolor.green=value; - - value=int16(src.blue+dest.blue)>>1; - returncolor.blue=value; - return returncolor; - } - case B_OP_MIN: - { - - return ( uint16(src.red+src.blue+src.green) > - uint16(dest.red+dest.blue+dest.green) )?dest:src; - } - case B_OP_MAX: - { - return ( uint16(src.red+src.blue+src.green) < - uint16(dest.red+dest.blue+dest.green) )?dest:src; - } - case B_OP_OVER: - { - return (use_high && src.alpha>127)?src:dest; - } - case B_OP_INVERT: - { - returncolor.red=dest.red ^ 255; - returncolor.green=dest.green ^ 255; - returncolor.blue=dest.blue ^ 255; - return (use_high && src.alpha>127)?returncolor:dest; - } - // This is a pain in the arse to implement, so I'm saving it for the real - // server - case B_OP_ALPHA: - { - return src; - } - case B_OP_ERASE: - { - // This one's tricky. - return (use_high && src.alpha>127)?d->lowcolor.GetColor32():dest; - } - case B_OP_SELECT: - { - // This one's tricky, too. We are passed a color in src. If it's the layer's - // high color or low color, we check for a swap. - if(d->highcolor==src) - return (use_high && d->highcolor==dest)?d->lowcolor.GetColor32():dest; - - if(d->lowcolor==src) - return (use_high && d->lowcolor==dest)?d->highcolor.GetColor32():dest; - - return dest; - } - default: - { - break; - } - } - return returncolor; -} diff --git a/src/servers/app/drawing/old_but_informative/ScreenDriver.h b/src/servers/app/drawing/old_but_informative/ScreenDriver.h deleted file mode 100644 index 040d37d6c9..0000000000 --- a/src/servers/app/drawing/old_but_informative/ScreenDriver.h +++ /dev/null @@ -1,201 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: ScreenDriver.h -// Author: DarkWyrm -// Gabe Yoder -// Description: BWindowScreen graphics module -// -//------------------------------------------------------------------------------ -#ifndef _SCREENDRIVER_H_ -#define _SCREENDRIVER_H_ - -#include -#include -#include -#include -#include // for pattern struct -#include -#include -#include -#include -#include "DisplayDriver.h" -#include -#include "FontServer.h" -#include "PatternHandler.h" - -class BBitmap; -class BPortLink; -class SDWindow; -class LayerData; -class ScreenDriver; - -class FrameBuffer : public BWindowScreen -{ -public: - FrameBuffer(const char *title, uint32 space, status_t *st,bool debug); - ~FrameBuffer(void); - void ScreenConnected(bool connected); - void MessageReceived(BMessage *msg); - bool IsConnected(void) const { return is_connected; } - bool QuitRequested(void); - static int32 MouseMonitor(void *data); - static int32 CopyThread(void *data); - void Invalidate(const BRect &r); - graphics_card_info gcinfo; -protected: - friend class ScreenDriver; - - bool is_connected; - BPortLink *serverlink; - BPoint mousepos; - uint32 buttons; - thread_id monitor_thread,copy_thread; - BView *view; - BBitmap *viewbmp; - ServerBitmap *cursor; - BRegion *invalid; - int32 invalidflag; -}; -/* -class SDView : public BView -{ -public: - SDView(BRect bounds); - ~SDView(void); - void AttachedToWindow(void); - void Draw(BRect rect); - void MouseDown(BPoint pt); - void MouseMoved(BPoint pt, uint32 transit, const BMessage *msg); - void MouseUp(BPoint pt); - void MessageReceived(BMessage *msg); - - BBitmap *viewbmp; - BPortLink *serverlink; - - int hide_cursor; - BBitmap *cursor; - - BRect cursorframe, oldcursorframe; - bool obscure_cursor; -}; -*/ -class SDWindow : public BWindowScreen -{ -public: - SDWindow(void); - ~SDWindow(void); - void MessageReceived(BMessage *msg); - bool QuitRequested(void); - void WindowActivated(bool active); - -// SDView *view; -}; - -/*! - \brief BView/BWindow combination graphics module - - First, slowest, and easiest driver class in the app_server which is designed - to utilize the BeOS graphics functions to cut out a lot of junk in getting the - drawing infrastructure in this server. - - The concept is to have SDView::Draw() draw a bitmap, which is a "frame buffer" - of sorts, utilize a second view to write to it. This cuts out - the most problems with having a crapload of code to get just right without - having to write a bunch of unit tests - - Components: 3 classes, SDView, SDWindow, and ScreenDriver - - ScreenDriver - a wrapper class which mostly posts messages to the SDWindow - SDWindow - does most of the work. - SDView - doesn't do all that much except display the rendered bitmap -*/ -class ScreenDriver : public DisplayDriver -{ -public: - ScreenDriver(void); - ~ScreenDriver(void); - - bool Initialize(void); // Sets the driver - void Shutdown(void); // You never know when you'll need this - - // Drawing functions - void CopyBits(BRect src, BRect dest); - void DrawBitmap(ServerBitmap *bmp, BRect src, BRect dest); - void DrawChar(char c, BPoint pt, LayerData *d); -// virtual void DrawPicture(SPicture *pic, BPoint pt); - void DrawString(const char *string, int32 length, BPoint pt, LayerData *d, escapement_delta *delta=NULL); - - void FillArc(BRect r, float angle, float span, LayerData *d, const Pattern &pat); - void FillBezier(BPoint *pts, LayerData *d, const Pattern &pat); - void FillEllipse(BRect r, LayerData *d, const Pattern &pat); - void FillPolygon(BPoint *ptlist, int32 numpts, BRect rect, LayerData *d, const Pattern &pat); - void FillRect(BRect r, LayerData *d, const Pattern &pat); - void FillRoundRect(BRect r, float xrad, float yrad, LayerData *d, const Pattern &pat); -// void FillShape(SShape *sh, LayerData *d, const Pattern &pat); - void FillTriangle(BPoint *pts, BRect r, LayerData *d, const Pattern &pat); - - void HideCursor(void); - void InvertRect(BRect r); - bool IsCursorHidden(void); - void MoveCursorTo(float x, float y); -// void MovePenTo(BPoint pt); - void ObscureCursor(void); -// BPoint PenPosition(void); -// float PenSize(void); - void SetCursor(ServerCursor *cursor); -// drawing_mode GetDrawingMode(void); -// void SetDrawingMode(drawing_mode mode); - void ShowCursor(void); - - void StrokeArc(BRect r, float angle, float span, LayerData *d, const Pattern &pat); - void StrokeBezier(BPoint *pts, LayerData *d, const Pattern &pat); - void StrokeEllipse(BRect r, LayerData *d, const Pattern &pat); - void StrokeLine(BPoint start, BPoint end, LayerData *d, const Pattern &pat); - void StrokeLineArray(BPoint *pts, int32 numlines, RGBColor *colors, LayerData *d); - void StrokePolygon(BPoint *ptlist, int32 numpts, BRect rect, LayerData *d, const Pattern &pat, bool is_closed=true); - void StrokeRect(BRect r, LayerData *d, const Pattern &pat); - void StrokeRoundRect(BRect r, float xrad, float yrad, LayerData *d, const Pattern &pat); -// void StrokeShape(SShape *sh, LayerData *d, const Pattern &pat); - void StrokeTriangle(BPoint *pts, BRect r, LayerData *d, const Pattern &pat); - void SetMode(int32 mode); - void SetMode(const display_mode &mode); - float StringWidth(const char *string, int32 length, LayerData *d); - float StringHeight(const char *string, int32 length, LayerData *d); - bool DumpToFile(const char *path); - FrameBuffer *screenwin; -protected: - void SetLayerData(LayerData *d, bool set_font_data=false); - void BlitMono2RGB32(FT_Bitmap *src, BPoint pt, LayerData *d); - void BlitGray2RGB32(FT_Bitmap *src, BPoint pt, LayerData *d); - rgb_color GetBlitColor(rgb_color src, rgb_color dest, LayerData *d, bool use_high=true); - int hide_cursor; - bool obscure_cursor; - BBitmap *framebuffer; - BView *drawview; - BRegion laregion; - BPortLink *serverlink; - - rgb_color highcolor,lowcolor; - bool is_initialized; -}; - -#endif diff --git a/src/servers/app/drawing/old_but_informative/ViewDriver.cpp b/src/servers/app/drawing/old_but_informative/ViewDriver.cpp deleted file mode 100644 index fedb652a27..0000000000 --- a/src/servers/app/drawing/old_but_informative/ViewDriver.cpp +++ /dev/null @@ -1,986 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2005, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: ViewDriver.cpp -// Author: DarkWyrm -// Description: BView/BWindow combination graphics module -// -//------------------------------------------------------------------------------ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "fake_input_server.h" - -#include "PortLink.h" -#include "RectUtils.h" -#include "ServerProtocol.h" -#include "ServerBitmap.h" -#include "ViewDriver.h" -#include "ServerConfig.h" -#include "ServerCursor.h" -#include "ServerFont.h" -#include "FontFamily.h" -#include "LayerData.h" -#include "PNGDump.h" - -#ifdef DEBUG_DRIVER_MODULE -# include -# define STRACE(x) printf x -#else -# define STRACE(x) ; -#endif - -enum -{ -VDWIN_CLEAR=100, - -VDWIN_SHOWCURSOR, -VDWIN_HIDECURSOR, -VDWIN_OBSCURECURSOR, -VDWIN_MOVECURSOR, -VDWIN_SETCURSOR, -}; - -extern RGBColor workspace_default_color; - -bool is_initialized = false; -BPoint offset(50,50); - -VDView::VDView(BRect bounds) - : BView(bounds,"viewdriver_view",B_FOLLOW_ALL, B_WILL_DRAW) -{ - SetViewColor(B_TRANSPARENT_32_BIT); - viewbmp=new BBitmap(bounds,B_RGBA32,true); - - // This link for sending mouse messages to the Haiku app_server. - // This is only to take the place of the Input Server. - port_id input_port = find_port(SERVER_INPUT_PORT); - serverlink = new BPortLink(input_port); - - // Create a cursor which isn't just a box - cursor=new BBitmap(BRect(0,0,20,20),B_RGBA32,true); - BView *v=new BView(cursor->Bounds(),"v", B_FOLLOW_NONE, B_WILL_DRAW); - hide_cursor=0; - - cursor->Lock(); - cursor->AddChild(v); - - v->SetHighColor(255,255,255,0); - v->FillRect(cursor->Bounds()); - v->SetHighColor(255,0,0,255); - v->FillTriangle(cursor->Bounds().LeftTop(),cursor->Bounds().RightTop(),cursor->Bounds().LeftBottom()); - - cursor->RemoveChild(v); - cursor->Unlock(); - - cursorframe=cursor->Bounds(); - oldcursorframe=cursor->Bounds(); -} - -VDView::~VDView() -{ - delete serverlink; - delete cursor; - - viewbmp->Lock(); - delete viewbmp; -} - -void VDView::AttachedToWindow() -{ -} - -void VDView::Draw(BRect rect) -{ - if(viewbmp) - { - DrawBitmapAsync(viewbmp,oldcursorframe,oldcursorframe); - DrawBitmapAsync(viewbmp,rect,rect); - - if(hide_cursor==0 && obscure_cursor==false) - { - SetDrawingMode(B_OP_ALPHA); - DrawBitmapAsync(cursor,cursor->Bounds(),cursorframe); - SetDrawingMode(B_OP_COPY); - } - Sync(); - } -} - -// These functions emulate the Input Server by sending the *exact* same kind of messages -// to the server's port. Being we're using a regular window, it would make little sense -// to do anything else. - -void VDView::MouseDown(BPoint pt) -{ -#ifdef ENABLE_INPUT_SERVER_EMULATION - send_mouse_down(serverlink, pt, Window()->CurrentMessage()); -#endif -} - -void VDView::MouseMoved(BPoint pt, uint32 transit, const BMessage *msg) -{ - if (!(transit == B_ENTERED_VIEW || transit == B_INSIDE_VIEW)) - return; -#ifdef ENABLE_INPUT_SERVER_EMULATION - send_mouse_moved(serverlink, pt, Window()->CurrentMessage()); -#endif -} - -void VDView::MouseUp(BPoint pt) -{ -#ifdef ENABLE_INPUT_SERVER_EMULATION - send_mouse_up(serverlink, pt, Window()->CurrentMessage()); -#endif -} - -void VDView::MessageReceived(BMessage *msg) -{ - switch(msg->what) - { - default: - BView::MessageReceived(msg); - break; - } -} - -VDWindow::VDWindow(BRect frame) - : BWindow(frame, "Haiku App Server", B_TITLED_WINDOW, - B_NOT_ZOOMABLE | B_NOT_RESIZABLE) -{ - view=new VDView(Bounds()); - AddChild(view); -} - -VDWindow::~VDWindow() -{ -} - -void VDWindow::MessageReceived(BMessage *msg) -{ -#ifdef ENABLE_INPUT_SERVER_EMULATION - if (!handle_message(view->serverlink, msg)) -#endif - BWindow::MessageReceived(msg); -} - -bool VDWindow::QuitRequested() -{ - port_id serverport=find_port(SERVER_PORT_NAME); - - if(serverport>=0) - { - BPortLink link(serverport); - link.StartMessage(B_QUIT_REQUESTED); - link.Flush(); - } - else - printf("ERROR: couldn't find the app_server's main port!"); - - // We actually have to perform the internal equivalent of calling Shutdown - // to eliminate a race condition. If a ServerWindow attempts to call a driver - // function after the window has closed but before the AppServer instance - // has called Shutdown, we end up with a crash inside one of the graphics - // methods - is_initialized=false; - return true; -} - -void VDWindow::WindowActivated(bool active) -{ - // This is just to hide the regular system cursor so we can see our own - - if(active) - be_app->HideCursor(); - else - be_app->ShowCursor(); -} - -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- -//----------------------------------------------------------------------- - -ViewDriver::ViewDriver() - : DisplayDriverImpl() -{ - fDisplayMode.virtual_width=640; - fDisplayMode.virtual_height=480; - fDisplayMode.space=B_RGBA32; - - screenwin=new VDWindow(BRect(0,0,fDisplayMode.virtual_width-1,fDisplayMode.virtual_height-1).OffsetToCopy(offset)); - framebuffer=screenwin->view->viewbmp; - serverlink=screenwin->view->serverlink; - hide_cursor=0; - - framebuffer->Lock(); - drawview=new BView(framebuffer->Bounds(),"drawview",B_FOLLOW_ALL, B_WILL_DRAW); - framebuffer->AddChild(drawview); - framebuffer->Unlock(); -} - -ViewDriver::~ViewDriver() -{ - if(is_initialized) - { - screenwin->Lock(); - screenwin->Quit(); - screenwin=NULL; - } -} - -bool -ViewDriver::Initialize() -{ - Lock(); - - // the screen should start black - framebuffer->Lock(); - rgb_color c; c.red = 0; c.blue = 0; c.green = 0; c.alpha = 255; - drawview->SetHighColor(c); - drawview->FillRect(drawview->Bounds()); - drawview->Sync(); - framebuffer->Unlock(); - - hide_cursor=0; - obscure_cursor=false; - - is_initialized=true; - - // We can afford to call the above functions without locking - // because the window is locked until Show() is first called - screenwin->Show(); - Unlock(); - - return DisplayDriver::Initialize(); -} - -void ViewDriver::Shutdown() -{ - DisplayDriver::Shutdown(); - - Lock(); - is_initialized=false; - Unlock(); -} - -void ViewDriver::SetMode(const display_mode &mode) -{ - if(!is_initialized) - return; - - if (fDisplayMode.virtual_width==mode.virtual_width && - fDisplayMode.virtual_height==mode.virtual_height && - fDisplayMode.space==mode.space) - { - return; - } - - fDisplayMode.virtual_width = mode.virtual_width; - fDisplayMode.virtual_height = mode.virtual_height; - fDisplayMode.space = mode.space; - - screenwin->Lock(); - - BBitmap *tempbmp=new BBitmap(BRect(0,0,mode.virtual_width-1, mode.virtual_height-1), - (color_space)mode.space,true); - - if(!tempbmp) - { - screenwin->Unlock(); - delete tempbmp; - return; - } - - if(!tempbmp->IsValid()) - { - screenwin->Unlock(); - delete tempbmp; - return; - } - - delete framebuffer; - - screenwin->ResizeTo(mode.virtual_width-1, mode.virtual_height-1); - - screenwin->view->viewbmp=tempbmp; - framebuffer=screenwin->view->viewbmp; - - drawview=new BView(framebuffer->Bounds(),"drawview",B_FOLLOW_ALL, B_WILL_DRAW); - framebuffer->AddChild(drawview); - - // the screen should start black - framebuffer->Lock(); - rgb_color c; c.red = 0; c.blue = 0; c.green = 0; c.alpha = 255; - drawview->SetHighColor(c);//workspace_default_color.GetColor32()); - drawview->FillRect(drawview->Bounds()); - drawview->Sync(); - framebuffer->Unlock(); - - screenwin->view->Invalidate(); - screenwin->Unlock(); -} - -/* -void ViewDriver::DrawBitmap(ServerBitmap *bitmap, const BRect &src, const BRect &dest, const DrawData *d) -{ - if(!is_initialized) - return; - -STRACE(("ViewDriver:: DrawBitmap unimplemented()\n")); -}*/ - -bool ViewDriver::DumpToFile(const char *path) -{ - if(!is_initialized) - return false; - - // Dump to PNG - Lock(); - SaveToPNG(path,framebuffer->Bounds(),framebuffer->ColorSpace(), - framebuffer->Bits(),framebuffer->BitsLength(),framebuffer->BytesPerRow()); - - Unlock(); - return true; -} - - -/*! - \brief Draws a series of lines - optimized for speed - \param pts Array of BPoints pairs - \param numlines Number of lines to be drawn - \param pensize The thickness of the lines - \param colors Array of colors for each respective line -*/ -void ViewDriver::StrokeLineArray(const int32 &numlines, const LineArrayData *linedata, - const DrawData *d) -{ - if(!is_initialized) - return; - - if( !numlines || !linedata || !d) - return; - - const LineArrayData *data; - - Lock(); - screenwin->Lock(); - framebuffer->Lock(); - - drawview->SetPenSize(d->pensize); - drawview->SetDrawingMode(d->draw_mode); - - drawview->BeginLineArray(numlines); - for(int32 i=0; iAddLine(data->pt1,data->pt2,data->color); - } - drawview->EndLineArray(); - - drawview->Sync(); - screenwin->view->Invalidate(); - - framebuffer->Unlock(); - screenwin->Unlock(); - Unlock(); -} - - -void ViewDriver::InvertRect(const BRect &r) -{ - if(!is_initialized) - return; - - screenwin->Lock(); - framebuffer->Lock(); - drawview->InvertRect(r); - drawview->Sync(); - screenwin->view->Invalidate(r); - framebuffer->Unlock(); - screenwin->Unlock(); -} - -void ViewDriver::FillSolidRect(const BRect &rect, const RGBColor &color) -{ - if(!is_initialized) - return; - - screenwin->Lock(); - framebuffer->Lock(); - drawview->SetHighColor(color.GetColor32()); - drawview->FillRect(rect); - drawview->Sync(); - screenwin->view->Invalidate(rect); - framebuffer->Unlock(); - screenwin->Unlock(); -} - -void ViewDriver::FillPatternRect(const BRect &rect, const DrawData *d) -{ - if(!d) - return; - - if(!is_initialized) - return; - - screenwin->Lock(); - framebuffer->Lock(); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->FillRect(rect,*((pattern*)d->patt.GetInt8())); - drawview->Sync(); - screenwin->view->Invalidate(rect); - framebuffer->Unlock(); - screenwin->Unlock(); -} - -void ViewDriver::StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2, const DrawData *d) -{ - if(!d) - return; - - if(!is_initialized) - return; - - screenwin->Lock(); - framebuffer->Lock(); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->StrokeLine(BPoint(x1,y1),BPoint(x2,y2),*((pattern*)d->patt.GetInt8())); - drawview->Sync(); - screenwin->view->Invalidate(BRect(x1, y1, x2, y2)); - framebuffer->Unlock(); - screenwin->Unlock(); -} - -void ViewDriver::StrokeSolidLine(int32 x1, int32 y1, int32 x2, int32 y2, const RGBColor &color) -{ - if(!is_initialized) - return; - - screenwin->Lock(); - framebuffer->Lock(); - drawview->SetHighColor(color.GetColor32()); - drawview->StrokeLine(BPoint(x1,y1),BPoint(x2,y2)); - drawview->Sync(); - screenwin->view->Invalidate(BRect(x1,y1,x2,y2)); - framebuffer->Unlock(); - screenwin->Unlock(); -} - -void ViewDriver::StrokeSolidRect(const BRect &rect, const RGBColor &color) -{ - if(!is_initialized) - return; - - screenwin->Lock(); - framebuffer->Lock(); - drawview->SetHighColor(color.GetColor32()); - drawview->StrokeRect(rect); - drawview->Sync(); - screenwin->view->Invalidate(rect); - framebuffer->Unlock(); - screenwin->Unlock(); -} - -void ViewDriver::SetDrawData(const DrawData *d, bool set_font_data) -{ - if(!is_initialized) - return; - - if(!d) - return; - - bool unlock=false; - if(!framebuffer->IsLocked()) - { - framebuffer->Lock(); - unlock=true; - } - - drawview->ConstrainClippingRegion(d->clipReg); - drawview->SetPenSize(d->pensize); - drawview->SetDrawingMode(d->draw_mode); - drawview->SetHighColor(d->highcolor.GetColor32()); - drawview->SetLowColor(d->lowcolor.GetColor32()); - drawview->SetScale(d->scale); - drawview->MovePenTo(d->penlocation); - if(set_font_data) - { - BFont font; - const ServerFont *sf=&(d->font); - - if(!sf) - return; - - font.SetFamilyAndStyle(sf->GetFamily(),sf->GetStyle()); - font.SetFlags(sf->Flags()); - font.SetEncoding(sf->Encoding()); - font.SetSize(sf->Size()); - font.SetRotation(sf->Rotation()); - font.SetShear(sf->Shear()); - font.SetSpacing(sf->Spacing()); - drawview->SetFont(&font); - } - if(unlock) - framebuffer->Unlock(); -} - -rgb_color ViewDriver::GetBlitColor(rgb_color src, rgb_color dest, DrawData *d, bool use_high) -{ - rgb_color returncolor={0,0,0,0}; - - int16 value; - if(!d || !is_initialized) - return returncolor; - - switch(d->draw_mode) - { - case B_OP_COPY: - { - return src; - } - case B_OP_ADD: - { - value=src.red+dest.red; - returncolor.red=(value>255)?255:value; - - value=src.green+dest.green; - returncolor.green=(value>255)?255:value; - - value=src.blue+dest.blue; - returncolor.blue=(value>255)?255:value; - return returncolor; - } - case B_OP_SUBTRACT: - { - value=src.red-dest.red; - returncolor.red=(value<0)?0:value; - - value=src.green-dest.green; - returncolor.green=(value<0)?0:value; - - value=src.blue-dest.blue; - returncolor.blue=(value<0)?0:value; - return returncolor; - } - case B_OP_BLEND: - { - value=int16(src.red+dest.red)>>1; - returncolor.red=value; - - value=int16(src.green+dest.green)>>1; - returncolor.green=value; - - value=int16(src.blue+dest.blue)>>1; - returncolor.blue=value; - return returncolor; - } - case B_OP_MIN: - { - - return ( uint16(src.red+src.blue+src.green) > - uint16(dest.red+dest.blue+dest.green) )?dest:src; - } - case B_OP_MAX: - { - return ( uint16(src.red+src.blue+src.green) < - uint16(dest.red+dest.blue+dest.green) )?dest:src; - } - case B_OP_OVER: - { - return (use_high && src.alpha>127)?src:dest; - } - case B_OP_INVERT: - { - returncolor.red=dest.red ^ 255; - returncolor.green=dest.green ^ 255; - returncolor.blue=dest.blue ^ 255; - return (use_high && src.alpha>127)?returncolor:dest; - } - // This is a pain in the arse to implement, so I'm saving it for the real - // server - case B_OP_ALPHA: - { - return src; - } - case B_OP_ERASE: - { - // This one's tricky. - return (use_high && src.alpha>127)?d->lowcolor.GetColor32():dest; - } - case B_OP_SELECT: - { - // This one's tricky, too. We are passed a color in src. If it's the layer's - // high color or low color, we check for a swap. - if(d->highcolor==src) - return (use_high && d->highcolor==dest)?d->lowcolor.GetColor32():dest; - - if(d->lowcolor==src) - return (use_high && d->lowcolor==dest)?d->highcolor.GetColor32():dest; - - return dest; - } - default: - { - break; - } - } - return returncolor; -} - -status_t ViewDriver::SetDPMSMode(const uint32 &state) -{ - if(!is_initialized) - return B_ERROR; - - // NOTE: Originally, this was a to-do item to implement software DPMS, - // but this driver will not be the official testing driver, so implementing - // this stuff the way it was intended -- blanking the server's screen but not - // the physical monitor -- is moot, but we will support blanking the - // actual monitor if it is supported. - return BScreen().SetDPMS(state); -} - -uint32 ViewDriver::DPMSMode() -{ - // See note for SetDPMSMode if there are questions - return BScreen().DPMSState(); -} - -uint32 ViewDriver::DPMSCapabilities() -{ - // See note for SetDPMSMode if there are questions - return BScreen().DPMSCapabilites(); -} - -status_t ViewDriver::GetDeviceInfo(accelerant_device_info *info) -{ - if(!info || !is_initialized) - return B_ERROR; - - // We really don't have to provide anything here because this is strictly - // a software-only driver, but we'll have some fun, anyway. - - info->version=100; - sprintf(info->name,"Haiku, Inc. ViewDriver"); - sprintf(info->chipset,"Haiku, Inc. Chipset"); - sprintf(info->serial_no,"3.14159265358979323846"); - info->memory=134217728; // 128 MB, not that we really have that much. :) - info->dac_speed=0xFFFFFFFF; // *heh* - - return B_OK; -} - -status_t ViewDriver::GetModeList(display_mode **modes, uint32 *count) -{ - if(!count || !is_initialized) - return B_ERROR; - - screenwin->Lock(); - - // DEPRECATED: - // NOTE: Originally, I was going to figure out good timing values to be - // returned in each of the modes supported, but I won't bother, being this - // won't be used much longer anyway. - - *modes=new display_mode[13]; - *count=13; - - modes[0]->virtual_width=640; - modes[0]->virtual_width=480; - modes[0]->space=B_CMAP8; - modes[1]->virtual_width=640; - modes[1]->virtual_width=480; - modes[1]->space=B_RGB16; - modes[2]->virtual_width=640; - modes[2]->virtual_width=480; - modes[2]->space=B_RGB32; - modes[3]->virtual_width=640; - modes[3]->virtual_width=480; - modes[3]->space=B_RGBA32; - - modes[4]->virtual_width=800; - modes[4]->virtual_width=600; - modes[4]->space=B_CMAP8; - modes[5]->virtual_width=800; - modes[5]->virtual_width=600; - modes[5]->space=B_RGB16; - modes[6]->virtual_width=800; - modes[6]->virtual_width=600; - modes[6]->space=B_RGB32; - - modes[7]->virtual_width=1024; - modes[7]->virtual_width=768; - modes[7]->space=B_CMAP8;; - modes[8]->virtual_width=1024; - modes[8]->virtual_width=768; - modes[8]->space=B_RGB16; - modes[9]->virtual_width=1024; - modes[9]->virtual_width=768; - modes[9]->space=B_RGB32; - - modes[10]->virtual_width=1152; - modes[10]->virtual_width=864; - modes[10]->space=B_CMAP8; - modes[11]->virtual_width=1152; - modes[11]->virtual_width=864; - modes[11]->space=B_RGB16; - modes[12]->virtual_width=1152; - modes[12]->virtual_width=864; - modes[12]->space=B_RGB32; - - for(int32 i=0; i<13; i++) - { - modes[i]->h_display_start=0; - modes[i]->v_display_start=0; - modes[i]->flags=B_PARALLEL_ACCESS; - } - screenwin->Unlock(); - - return B_OK; -} - -status_t ViewDriver::GetPixelClockLimits(display_mode *mode, uint32 *low, uint32 *high) -{ - if(!is_initialized) - return B_ERROR; - - return B_ERROR; -} - -status_t ViewDriver::GetTimingConstraints(display_timing_constraints *dtc) -{ - if(!is_initialized) - return B_ERROR; - - return B_ERROR; -} - -status_t ViewDriver::ProposeMode(display_mode *candidate, const display_mode *low, const display_mode *high) -{ - if(!is_initialized) - return B_ERROR; - - // We should be able to get away with this because we're not dealing with any - // specific hardware. This is a Good Thing(TM) because we can support any hardware - // we wish within reasonable expectaions and programmer laziness. :P - return B_OK; -} - -status_t ViewDriver::WaitForRetrace(bigtime_t timeout=B_INFINITE_TIMEOUT) -{ - if(!is_initialized) - return B_ERROR; - - // Locking shouldn't be necessary here - R5 should handle this for us. :) - BScreen screen; - return screen.WaitForRetrace(timeout); -} - -void ViewDriver::CopyBitmap(ServerBitmap *bitmap, const BRect &source, const BRect &dest, const DrawData *d) -{ - if(!is_initialized || !bitmap || !d) - { - printf("CopyBitmap returned - not init or NULL bitmap\n"); - return; - } - - // DON't set draw data here! your existing clipping region will be deleted -// SetDrawData(d); - - // Oh, wow, is this going to be slow. Then again, ViewDriver was never meant to be very fast. It could - // be made significantly faster by directly copying from the source to the destination, but that would - // require implementing a lot of code. Eventually, this should be replaced, but for now, using - // DrawBitmap will at least work with a minimum of effort. - - BBitmap *mediator=new BBitmap(bitmap->Bounds(),bitmap->ColorSpace()); - memcpy(mediator->Bits(),bitmap->Bits(),bitmap->BitsLength()); - - screenwin->Lock(); - framebuffer->Lock(); - - drawview->DrawBitmap(mediator,source,dest); - drawview->Sync(); - screenwin->view->Invalidate(dest); - - framebuffer->Unlock(); - screenwin->Unlock(); - delete mediator; -} - -void ViewDriver::CopyToBitmap(ServerBitmap *destbmp, const BRect &sourcerect) -{ - if(!is_initialized || !destbmp) - { - printf("CopyToBitmap returned - not init or NULL bitmap\n"); - return; - } - - if(((uint32)destbmp->ColorSpace() & 0x000F) != (fDisplayMode.space & 0x000F)) - { - printf("CopyToBitmap returned - unequal buffer pixel depth\n"); - return; - } - - BRect destrect(destbmp->Bounds()), source(sourcerect); - - uint8 colorspace_size=destbmp->BitsPerPixel()/8; - - // First, clip source rect to destination - if(source.Width() > destrect.Width()) - source.right=source.left+destrect.Width(); - - if(source.Height() > destrect.Height()) - source.bottom=source.top+destrect.Height(); - - - // Second, check rectangle bounds against their own bitmaps - BRect work_rect(destbmp->Bounds()); - - if( !(work_rect.Contains(destrect)) ) - { - // something in selection must be clipped - if(destrect.left < 0) - destrect.left = 0; - if(destrect.right > work_rect.right) - destrect.right = work_rect.right; - if(destrect.top < 0) - destrect.top = 0; - if(destrect.bottom > work_rect.bottom) - destrect.bottom = work_rect.bottom; - } - - work_rect.Set(0,0,fDisplayMode.virtual_width-1,fDisplayMode.virtual_height-1); - - if(!work_rect.Contains(sourcerect)) - return; - - if( !(work_rect.Contains(source)) ) - { - // something in selection must be clipped - if(source.left < 0) - source.left = 0; - if(source.right > work_rect.right) - source.right = work_rect.right; - if(source.top < 0) - source.top = 0; - if(source.bottom > work_rect.bottom) - source.bottom = work_rect.bottom; - } - - // Set pointers to the actual data - uint8 *dest_bits = (uint8*) destbmp->Bits(); - uint8 *src_bits = (uint8*) framebuffer->Bits(); - - // Get row widths for offset looping - uint32 dest_width = uint32 (destbmp->BytesPerRow()); - uint32 src_width = uint32 (framebuffer->BytesPerRow()); - - // Offset bitmap pointers to proper spot in each bitmap - src_bits += uint32 ( (source.top * src_width) + (source.left * colorspace_size) ); - dest_bits += uint32 ( (destrect.top * dest_width) + (destrect.left * colorspace_size) ); - - - uint32 line_length = uint32 ((destrect.right - destrect.left+1)*colorspace_size); - uint32 lines = uint32 (source.bottom-source.top+1); - - for (uint32 pos_y=0; pos_yLock(); - framebuffer->Lock(); - -// screenwin->view->ConstrainClippingRegion(reg); - drawview->ConstrainClippingRegion(reg); - - framebuffer->Unlock(); - screenwin->Unlock(); -} - -bool ViewDriver::AcquireBuffer(FBBitmap *bmp) -{ - if(!bmp || !is_initialized) - return false; - - screenwin->Lock(); - framebuffer->Lock(); - - bmp->SetBytesPerRow(framebuffer->BytesPerRow()); - bmp->SetSpace(framebuffer->ColorSpace()); - bmp->SetSize(framebuffer->Bounds().IntegerWidth(), framebuffer->Bounds().IntegerHeight()); - bmp->SetBuffer(framebuffer->Bits()); - bmp->SetBitsPerPixel(framebuffer->ColorSpace(),framebuffer->BytesPerRow()); - - return true; -} - -void ViewDriver::ReleaseBuffer() -{ - if(!is_initialized) - return; - framebuffer->Unlock(); - screenwin->Unlock(); -} - -void ViewDriver::Invalidate(const BRect &r) -{ - if(!is_initialized) - return; - - screenwin->Lock(); - screenwin->view->Draw(r); - screenwin->Unlock(); -} diff --git a/src/servers/app/drawing/old_but_informative/ViewDriver.h b/src/servers/app/drawing/old_but_informative/ViewDriver.h deleted file mode 100644 index afd161df86..0000000000 --- a/src/servers/app/drawing/old_but_informative/ViewDriver.h +++ /dev/null @@ -1,170 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: ViewDriver.h -// Author: DarkWyrm -// Description: BView/BWindow combination graphics module -// -//------------------------------------------------------------------------------ -#ifndef _VIEWDRIVER_H_ -#define _VIEWDRIVER_H_ - -#include -#include -#include -#include -#include // for pattern struct -#include -#include -#include -#include -#include "FontServer.h" - -#include "DisplayDriverImpl.h" - -class BBitmap; -class BPortLink; -class VDWindow; -class DrawData; - -class VDView : public BView -{ -public: - VDView(BRect bounds); - ~VDView(); - void AttachedToWindow(); - void Draw(BRect rect); - void MouseDown(BPoint pt); - void MouseMoved(BPoint pt, uint32 transit, const BMessage *msg); - void MouseUp(BPoint pt); - void MessageReceived(BMessage *msg); - - BBitmap *viewbmp; - BPortLink *serverlink; - - int hide_cursor; - BBitmap *cursor; - - BRect cursorframe, oldcursorframe; - bool obscure_cursor; -}; - -class VDWindow : public BWindow -{ -public: - VDWindow(BRect frame); - ~VDWindow(); - void MessageReceived(BMessage *msg); - bool QuitRequested(); - void WindowActivated(bool active); - - VDView *view; -}; - -/*! - \brief BView/BWindow combination graphics module - - First, slowest, and easiest driver class in the app_server which is designed - to utilize the BeOS graphics functions to cut out a lot of junk in getting the - drawing infrastructure in this server. - - The concept is to have VDView::Draw() draw a bitmap, which is a "frame buffer" - of sorts, utilize a second view to write to it. This cuts out - the most problems with having a crapload of code to get just right without - having to write a bunch of unit tests - - Components: 3 classes, VDView, VDWindow, and ViewDriver - - ViewDriver - a wrapper class which mostly posts messages to the VDWindow - VDWindow - does most of the work. - VDView - doesn't do all that much except display the rendered bitmap -*/ -class ViewDriver : public DisplayDriverImpl -{ -public: - ViewDriver(); - ~ViewDriver(); - - virtual bool Initialize(); // Sets the driver - virtual void Shutdown(); // You never know when you'll need this - - // Drawing functions -// void DrawBitmap(ServerBitmap *bmp, const BRect &src, const BRect &dest, const DrawData *d); - - virtual void InvertRect(const BRect &r); - - virtual void StrokeLineArray(const int32 &numlines, const LineArrayData *data, - const DrawData *d); - - virtual void SetMode(const display_mode &mode); - - virtual bool DumpToFile(const char *path); - - VDWindow *screenwin; - - virtual status_t SetDPMSMode(const uint32 &state); - virtual uint32 DPMSMode(); - virtual uint32 DPMSCapabilities(); - virtual status_t GetDeviceInfo(accelerant_device_info *info); - virtual status_t GetModeList(display_mode **mode_list, uint32 *count); - virtual status_t GetPixelClockLimits(display_mode *mode, uint32 *low, uint32 *high); - virtual status_t GetTimingConstraints(display_timing_constraints *dtc); - virtual status_t ProposeMode(display_mode *candidate, const display_mode *low, const display_mode *high); - virtual status_t WaitForRetrace(bigtime_t timeout=B_INFINITE_TIMEOUT); - -protected: - virtual void FillSolidRect(const BRect &rect, const RGBColor &color); - virtual void FillPatternRect(const BRect &rect, const DrawData *d); - virtual void StrokeSolidRect(const BRect &rect, const RGBColor &color); - virtual void StrokeSolidLine(int32 x1, int32 y1, int32 x2, int32 y2, - const RGBColor &color); - virtual void SetDrawData(const DrawData *d, bool set_font_data=false); - virtual void StrokePatternLine(int32 x1, int32 y1, int32 x2, int32 y2, - const DrawData *d); - virtual void CopyBitmap(ServerBitmap *bitmap, const BRect &source, - const BRect &dest, const DrawData *d); - virtual void CopyToBitmap(ServerBitmap *target, const BRect &source); - // temporarily virtual - until clipping code is added in DisplayDriver - virtual void ConstrainClippingRegion(BRegion *reg); - - - virtual bool AcquireBuffer(FBBitmap *bmp); - virtual void ReleaseBuffer(); - virtual void Invalidate(const BRect &r); - -// void BlitMono2RGB32(FT_Bitmap *src, BPoint pt, DrawData *d); -// void BlitGray2RGB32(FT_Bitmap *src, BPoint pt, DrawData *d); - rgb_color GetBlitColor(rgb_color src, rgb_color dest, - DrawData *d, bool use_high=true); - - int hide_cursor; - bool obscure_cursor; - BBitmap *framebuffer; - BView *drawview; - BRegion laregion; - - BPortLink *serverlink; -// drawing_mode drawmode; - - rgb_color highcolor,lowcolor; -}; - -#endif