Commit 108fc274 authored by Cyril Deguet's avatar Cyril Deguet

* os_graphics.hpp: added a parameter "blend" to drawBitmap(), to perform alpha

  blending only when it is useful (i.e. when drawing antialiased text)
* x11/*: optimized drawBitmap when alpha blending is not used: 5 times faster
parent 60b5f4b5
......@@ -471,7 +471,7 @@ void CtrlList::makeImage()
}
int lineHeight = __MIN( pText->getHeight() - ySrc, height - yPos );
m_pImage->drawBitmap( *pText, 0, ySrc, 0, yPos, pText->getWidth(),
lineHeight );
lineHeight, true );
yPos += (pText->getHeight() - ySrc );
delete pText;
......
......@@ -160,7 +160,7 @@ void CtrlText::draw( OSGraphics &rImage, int xDest, int yDest )
if( width > 0 && height > 0 )
{
rImage.drawBitmap( *m_pCurrImg, -m_xPos, 0, xDest, yDest,
width, height );
width, height, true );
}
}
}
......
......@@ -23,19 +23,18 @@
#ifdef MACOSX_SKINS
#include <Carbon/Carbon.h>
#include "macosx_loop.hpp"
MacOSXLoop::MacOSXLoop( intf_thread_t *pIntf ):
OSLoop( pIntf )
OSLoop( pIntf ), m_exit( false )
{
// TODO
}
MacOSXLoop::~MacOSXLoop()
{
// TODO
}
......@@ -62,13 +61,58 @@ void MacOSXLoop::destroy( intf_thread_t *pIntf )
void MacOSXLoop::run()
{
// TODO
// Main event loop
while( !m_exit )
{
EventRef pEvent;
OSStatus err = ReceiveNextEvent( 0, NULL, kEventDurationForever, true,
&pEvent );
if( err != noErr )
{
// Get the event type
UInt32 evClass = GetEventClass( pEvent );
switch( evClass )
{
case kEventClassMouse:
{
break;
}
case kEventClassKeyboard:
{
break;
}
case kEventClassWindow:
{
handleWindowEvent( pEvent );
break;
}
default:
{
EventTargetRef pTarget;
pTarget = GetEventDispatcherTarget();
SendEventToEventTarget( pEvent, pTarget );
ReleaseEvent( pEvent );
}
}
}
}
}
void MacOSXLoop::exit()
{
// TODO
m_exit = true;
}
void MacOSXLoop::handleWindowEvent( EventRef pEvent )
{
UInt32 evKind = GetEventKind( pEvent );
}
......
......@@ -49,6 +49,11 @@ class MacOSXLoop: public OSLoop
// Private because it's a singleton
MacOSXLoop( intf_thread_t *pIntf );
virtual ~MacOSXLoop();
// Flag set to exit the loop
bool m_exit;
// Handle a window event
void handleWindowEvent( EventRef pEvent );
};
#endif
......@@ -60,9 +60,9 @@ void FT2Bitmap::draw( const FT_Bitmap &rBitmap, int left, int top,
{
// The buffer in FT_Bitmap contains alpha values
uint8_t val = *(pBuf++);
*(pData++) = blue;
*(pData++) = green;
*(pData++) = red;
*(pData++) = (blue * val) >> 8;
*(pData++) = (green * val) >> 8;
*(pData++) = (red * val) >> 8;
*(pData++) = val;
}
}
......
......@@ -49,7 +49,8 @@ class OSGraphics: public SkinObject
/// Render a bitmap on this graphics
virtual void drawBitmap( const GenericBitmap &rBitmap, int xSrc = 0,
int ySrc = 0, int xDest = 0, int yDest = 0,
int width = -1, int height = -1 ) = 0;
int width = -1, int height = -1,
bool blend = false) = 0;
/// Draw a filled rectangle on the grahics (color is #RRGGBB)
virtual void fillRect( int left, int top, int width, int height,
......
......@@ -113,7 +113,7 @@ void Tooltip::makeImage( const UString &rText )
m_pImage = OSFactory::instance( getIntf() )->createOSGraphics( w, h );
m_pImage->fillRect( 0, 0, w, h, 0xffffd0 );
m_pImage->drawRect( 0, 0, w, h, 0x000000 );
m_pImage->drawBitmap( *pBmpTip, 0, 0, 5, 5 );
m_pImage->drawBitmap( *pBmpTip, 0, 0, 5, 5, -1, -1, true );
delete pBmpTip;
}
......
......@@ -68,7 +68,7 @@ void Win32Graphics::clear()
void Win32Graphics::drawBitmap( const GenericBitmap &rBitmap,
int xSrc, int ySrc, int xDest, int yDest,
int width, int height )
int width, int height, bool blend )
{
// Get the bitmap size if necessary
if( width == -1 )
......
......@@ -44,7 +44,8 @@ class Win32Graphics: public OSGraphics
/// Render a bitmap on this graphics
virtual void drawBitmap( const GenericBitmap &rBitmap, int xSrc = 0,
int ySrc = 0, int xDest = 0, int yDest = 0,
int width = -1, int height = -1 );
int width = -1, int height = -1,
bool blend = false );
/// Draw another graphics on this one
virtual void drawGraphics( const OSGraphics &rGraphics, int xSrc = 0,
......
This diff is collapsed.
......@@ -58,12 +58,15 @@ class X11Display: public SkinObject
/// Get the colormap
Colormap getColormap() const { return m_colormap; }
/// Type of function to convert RGB values into a pixel
/// Type of function to put RGBA values into a pixel
typedef void (X11Display::*MakePixelFunc_t)( uint8_t *pPixel,
uint8_t r, uint8_t g, uint8_t b, uint8_t a ) const;
/// Get a pointer on the right makePixel implementation
MakePixelFunc_t getMakePixel() const { return makePixelImpl; }
/// Get a pointer on the right blendPixel implementation
MakePixelFunc_t getBlendPixel() const { return blendPixelImpl; }
/// Get a pointer on the right putPixel implementation
MakePixelFunc_t getPutPixel() const { return putPixelImpl; }
/// Get the pixel value corresponding to the given colors
unsigned long getPixelValue( uint8_t r, uint8_t g, uint8_t b ) const;
......@@ -86,33 +89,54 @@ class X11Display: public SkinObject
int m_redLeftShift, m_redRightShift;
int m_greenLeftShift, m_greenRightShift;
int m_blueLeftShift, m_blueRightShift;
/// Pointer on the right implementation of getPixel
MakePixelFunc_t makePixelImpl;
/// Pointer on the right implementation of blendPixel
MakePixelFunc_t blendPixelImpl;
/// Pointer on the right implementation of putPixel
MakePixelFunc_t putPixelImpl;
/// Calculate shifts from a color mask
void getShifts( uint32_t mask, int &rLeftShift,
int &rRightShift ) const;
/// 8 bpp version of makePixel
void makePixel8( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t a ) const;
/// 8 bpp version of blendPixel
void blendPixel8( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t a ) const;
/// 16 bpp MSB first version of blendPixel
void blendPixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t a ) const;
/// 16 bpp LSB first version of blendPixel
void blendPixel16LSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t a ) const;
/// 24/32 bpp MSB first version of blendPixel
void blendPixel32MSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t a ) const;
/// 24/32 bpp LSB first version of blendPixel
void blendPixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t a ) const;
/// 8 bpp version of putPixel
void putPixel8( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t a ) const;
/// 16 bpp MSB first version of makePixel
void makePixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t a ) const;
/// 16 bpp MSB first version of putPixel
void putPixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t a ) const;
/// 16 bpp LSB first version of makePixel
void makePixel16LSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t a ) const;
/// 16 bpp LSB first version of putPixel
void putPixel16LSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t a ) const;
/// 24/32 bpp MSB first version of makePixel
void makePixel32MSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t a ) const;
/// 24/32 bpp MSB first version of putPixel
void putPixel32MSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t a ) const;
/// 24/32 bpp LSB first version of makePixel
void makePixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t a ) const;
/// 24/32 bpp LSB first version of putPixel
void putPixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
uint8_t a ) const;
};
#endif
......@@ -129,7 +129,7 @@ void X11Graphics::drawGraphics( const OSGraphics &rGraphics, int xSrc,
void X11Graphics::drawBitmap( const GenericBitmap &rBitmap, int xSrc,
int ySrc, int xDest, int yDest, int width,
int height )
int height, bool blend )
{
// Get the bitmap size if necessary
if( width == -1 )
......@@ -190,7 +190,8 @@ void X11Graphics::drawBitmap( const GenericBitmap &rBitmap, int xSrc,
Region mask = XCreateRegion();
// Get a pointer on the right X11Display::makePixel method
X11Display::MakePixelFunc_t makePixelFunc = m_rDisplay.getMakePixel();
X11Display::MakePixelFunc_t makePixelFunc = ( blend ?
m_rDisplay.getBlendPixel() : m_rDisplay.getPutPixel() );
// Skip the first lines of the image
pBmpData += 4 * ySrc * rBitmap.getWidth();
......
......@@ -54,7 +54,8 @@ class X11Graphics: public OSGraphics
/// Render a bitmap on this graphics
virtual void drawBitmap( const GenericBitmap &rBitmap, int xSrc = 0,
int ySrc = 0, int xDest = 0, int yDest = 0,
int width = -1, int height = -1 );
int width = -1, int height = -1,
bool blend = false );
/// Draw a filled rectangle on the grahics (color is #RRGGBB)
virtual void fillRect( int left, int top, int width, int height,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment