Changes for the qnx photon platform - they should not affect building/runtime on other platforms.

The offscreen context gets allocated its own gc instead of using the photon's default one.
This fixes the problems seen on our platform lately with sites like: http://www.math.uni-augsburg.de/opt/goblin.html
or http://www.reasoning.com
Also changes to speed up the rendering.
This commit is contained in:
amardare%qnx.com 2003-07-14 17:22:24 +00:00
Родитель d91118e262
Коммит 2803899d88
15 изменённых файлов: 753 добавлений и 896 удалений

Просмотреть файл

@ -251,29 +251,128 @@ NS_IMETHODIMP nsDeviceContextPh :: CreateRenderingContext( nsIRenderingContext *
return rv;
}
NS_IMETHODIMP nsDeviceContextPh :: SupportsNativeWidgets( PRBool &aSupportsWidgets ) {
/* REVISIT: These needs to return FALSE if we are printing! */
if( nsnull == mDC ) aSupportsWidgets = PR_TRUE;
else aSupportsWidgets = PR_FALSE; /* while printing! */
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextPh :: GetScrollBarDimensions( float &aWidth, float &aHeight ) const {
/* Revisit: the scroll bar sizes is a gross guess based on Phab */
float scale;
GetCanonicalPixelScale(scale);
aWidth = mScrollbarWidth * mPixelsToTwips * scale;
aHeight = mScrollbarHeight * mPixelsToTwips * scale;
return NS_OK;
}
static char *FaceMessageFont, *FaceMenuFont, *FaceBalloonFont, *FaceGeneralFont;
static int SizeMessageFont, SizeMenuFont, SizeBalloonFont, SizeGeneralFont;
static short StyleMessageFont, StyleMenuFont, StyleBalloonFont, StyleGeneralFont;
static short WeightMessageFont, WeightMenuFont, WeightBalloonFont, WeightGeneralFont;
static int InitSystemFonts;
/* load the file /usr/share/mozilla/system_fonts */
int nsDeviceContextPh :: ReadSystemFonts( ) const
{
FILE *fp;
char buffer[512];
fp = fopen( "/usr/share/mozilla/system_fonts", "r" );
if( !fp ) return -1;
while ( fgets( buffer, 512, fp ) != NULL ) {
int len, code;
char *p, **face;
int *size;
short *style, *weight;
/* skip comments and blank lines */
if( buffer[0] == '#' || buffer[0] == ' ' || buffer[0] == '\n' ) continue;
len = strlen( buffer );
if( len<3 ) continue;
if( buffer[len-1] == '\n' ) buffer[ len-1 ] = 0;
code = buffer[0] << 8 | buffer[1];
p = &buffer[2];
switch( code ) {
case 'h=':
if( !strcmp( p, "General" ) ) {
style = &StyleGeneralFont;
face = &FaceGeneralFont;
weight = &WeightGeneralFont;
size = &SizeGeneralFont;
}
else if( !strcmp( p, "Message" ) ) {
style = &StyleMessageFont;
face = &FaceMessageFont;
weight = &WeightMessageFont;
size = &SizeMessageFont;
}
else if( !strcmp( p, "Menu" ) ) {
style = &StyleMenuFont;
face = &FaceMenuFont;
weight = &WeightMenuFont;
size = &SizeMenuFont;
}
else if( !strcmp( p, "Balloon" ) ) {
style = &StyleBalloonFont;
face = &FaceBalloonFont;
weight = &WeightBalloonFont;
size = &SizeBalloonFont;
}
break;
case 'f=':
*face = strdup( p );
break;
case 's=':
*size = atoi( p );
break;
case 'w=':
*weight = 0;
if( strstr( p, "bold" ) )
*weight = NS_FONT_WEIGHT_BOLD;
else
*weight = NS_FONT_WEIGHT_NORMAL;
break;
case 'S=':
*style = 0;
if( strstr( p, "italic" ) )
*style = NS_FONT_STYLE_ITALIC;
else
*style = NS_FONT_STYLE_NORMAL;
if( strstr( p, "antialias" ) )
*style |= NS_FONT_STYLE_ANTIALIAS;
break;
}
}
fclose( fp );
return 0;
}
void nsDeviceContextPh :: DefaultSystemFonts( ) const
{
FaceMessageFont = "MessageFont";
SizeMessageFont = 9;
StyleMessageFont = NS_FONT_STYLE_NORMAL | NS_FONT_STYLE_ANTIALIAS;
WeightMessageFont = NS_FONT_WEIGHT_NORMAL;
FaceMenuFont = "MenuFont";
SizeMenuFont = 9;
StyleMenuFont = NS_FONT_STYLE_NORMAL | NS_FONT_STYLE_ANTIALIAS;
WeightMenuFont = NS_FONT_WEIGHT_NORMAL;
FaceBalloonFont = "BalloonFont";
SizeBalloonFont = 9;
StyleBalloonFont = NS_FONT_STYLE_NORMAL | NS_FONT_STYLE_ANTIALIAS;
WeightBalloonFont = NS_FONT_WEIGHT_NORMAL;
FaceGeneralFont = "TextFont";
SizeGeneralFont = 9;
StyleGeneralFont = NS_FONT_STYLE_NORMAL | NS_FONT_STYLE_ANTIALIAS;
WeightGeneralFont = NS_FONT_WEIGHT_NORMAL;
}
NS_IMETHODIMP nsDeviceContextPh :: GetSystemFont( nsSystemFontID aID, nsFont *aFont) const
{
aFont->style = NS_FONT_STYLE_NORMAL | NS_FONT_STYLE_ANTIALIAS;
aFont->weight = NS_FONT_WEIGHT_NORMAL;
if( !InitSystemFonts ) {
InitSystemFonts = 1;
DefaultSystemFonts( );
ReadSystemFonts( );
}
aFont->decorations = NS_FONT_DECORATION_NONE;
aFont->size = NSIntPointsToTwips(9/*8*/);
switch (aID) {
case eSystemFont_Caption: // css2
@ -291,28 +390,34 @@ NS_IMETHODIMP nsDeviceContextPh :: GetSystemFont( nsSystemFontID aID, nsFont *aF
case eSystemFont_List:
case eSystemFont_Field:
case eSystemFont_Widget:
aFont->name.Assign(NS_LITERAL_STRING("TextFont"));
aFont->name.AssignWithConversion( FaceGeneralFont );
aFont->style = StyleGeneralFont;
aFont->weight = WeightGeneralFont;
aFont->size = NSIntPointsToTwips( SizeGeneralFont );
break;
case eSystemFont_MessageBox:
aFont->name.Assign(NS_LITERAL_STRING("MessageFont"));
aFont->name.AssignWithConversion( FaceMessageFont );
aFont->style = StyleMessageFont;
aFont->weight = WeightMessageFont;
aFont->size = NSIntPointsToTwips( SizeMessageFont );
break;
case eSystemFont_Tooltips: // moz
aFont->name.Assign(NS_LITERAL_STRING("BalloonFont"));
aFont->name.AssignWithConversion( FaceBalloonFont );
aFont->style = StyleBalloonFont;
aFont->weight = WeightBalloonFont;
aFont->size = NSIntPointsToTwips( SizeBalloonFont );
break;
case eSystemFont_Menu:
aFont->name.Assign(NS_LITERAL_STRING("MenuFont"));
aFont->name.AssignWithConversion( FaceMenuFont );
aFont->style = StyleMenuFont;
aFont->weight = WeightMenuFont;
aFont->size = NSIntPointsToTwips( SizeMenuFont );
break;
}
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextPh :: GetDrawingSurface( nsIRenderingContext &aContext, nsDrawingSurface &aSurface ) {
nsRect aRect;
GetClientRect( aRect );
aContext.CreateDrawingSurface(aRect, 0, aSurface);
return nsnull == aSurface ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
}
NS_IMETHODIMP nsDeviceContextPh :: GetClientRect( nsRect &aRect ) {
nsresult rv = NS_OK;
@ -378,16 +483,6 @@ printf( "\t\t Not Found in cache\n" );
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsDeviceContextPh::GetDepth( PRUint32& aDepth ) {
aDepth = mDepth; // 24;
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextPh :: ConvertPixel( nscolor aColor, PRUint32 & aPixel ) {
aPixel = NS_TO_PH_RGB(aColor);
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextPh :: GetDeviceSurfaceDimensions( PRInt32 &aWidth, PRInt32 &aHeight ) {
if( mIsPrinting ) { //(mSpec)

Просмотреть файл

@ -62,9 +62,26 @@ public:
NS_IMETHOD CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aView,aContext));}
NS_IMETHOD CreateRenderingContext(nsIWidget *aWidget, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aWidget,aContext));}
NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets);
inline
NS_IMETHODIMP SupportsNativeWidgets(PRBool &aSupportsWidgets)
{
/* REVISIT: These needs to return FALSE if we are printing! */
if( nsnull == mDC ) aSupportsWidgets = PR_TRUE;
else aSupportsWidgets = PR_FALSE; /* while printing! */
return NS_OK;
}
inline
NS_IMETHODIMP GetScrollBarDimensions(float &aWidth, float &aHeight) const
{
/* Revisit: the scroll bar sizes is a gross guess based on Phab */
float scale;
GetCanonicalPixelScale(scale);
aWidth = mScrollbarWidth * mPixelsToTwips * scale;
aHeight = mScrollbarHeight * mPixelsToTwips * scale;
return NS_OK;
}
NS_IMETHOD GetScrollBarDimensions(float &aWidth, float &aHeight) const;
NS_IMETHOD GetSystemFont(nsSystemFontID anID, nsFont *aFont) const;
//get a low level drawing surface for rendering. the rendering context
@ -72,9 +89,22 @@ public:
//already one in the device context. the drawing surface is then cached
//in the device context for re-use.
NS_IMETHOD GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface);
inline
NS_IMETHODIMP GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface)
{
nsRect aRect;
GetClientRect( aRect );
aContext.CreateDrawingSurface(aRect, 0, aSurface);
return nsnull == aSurface ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
}
inline
NS_IMETHODIMP ConvertPixel(nscolor aColor, PRUint32 & aPixel)
{
aPixel = NS_TO_PH_RGB(aColor);
return NS_OK;
}
NS_IMETHOD ConvertPixel(nscolor aColor, PRUint32 & aPixel);
NS_IMETHOD CheckFontExistence(const nsString& aFontName);
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
@ -91,7 +121,12 @@ public:
NS_IMETHOD BeginPage(void);
NS_IMETHOD EndPage(void);
NS_IMETHOD GetDepth(PRUint32& aDepth);
inline
NS_IMETHODIMP GetDepth(PRUint32& aDepth)
{
aDepth = mDepth; // 24;
return NS_OK;
}
static int prefChanged(const char *aPref, void *aClosure);
nsresult SetDPI(PRInt32 dpi);
@ -124,6 +159,8 @@ protected:
private:
nsCOMPtr<nsIScreenManager> mScreenManager;
int ReadSystemFonts( ) const;
void DefaultSystemFonts( ) const;
};
#define NS_FONT_STYLE_ANTIALIAS 0xf0

Просмотреть файл

@ -94,7 +94,7 @@ nsDrawingSurfacePh :: ~nsDrawingSurfacePh( )
{
if(mDrawContext) {
mDrawContext->gc = NULL;
PhDCRelease( mDrawContext ); /* the mDrawContext->gc will be free by the upper classes */
PhDCRelease( mDrawContext ); /* the mDrawContext->gc will be freed by the upper classes */
}
if( mLockDrawContext ) {
@ -107,6 +107,8 @@ nsDrawingSurfacePh :: ~nsDrawingSurfacePh( )
if (NS_SUCCEEDED(rv)) {
prefs->UnregisterCallback("browser.display.internaluse.graphics_changed", prefChanged, (void *)this);
}
if( mGC ) PgDestroyGC( mGC );
}
}
@ -207,33 +209,16 @@ NS_IMETHODIMP nsDrawingSurfacePh :: Unlock( void ) {
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfacePh :: GetDimensions( PRUint32 *aWidth, PRUint32 *aHeight ) {
*aWidth = mWidth;
*aHeight = mHeight;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfacePh :: GetPixelFormat( nsPixelFormat *aFormat ) {
*aFormat = mPixFormat;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfacePh :: Init( PhGC_t *aGC ) {
mGC = aGC;
mIsOffscreen = PR_FALSE;
mDrawContext = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfacePh :: Init( PhGC_t *aGC, PRUint32 aWidth, PRUint32 aHeight, PRUint32 aFlags ) {
NS_IMETHODIMP nsDrawingSurfacePh :: Init( PRUint32 aWidth, PRUint32 aHeight, PRUint32 aFlags ) {
mWidth = aWidth;
mHeight = aHeight;
mFlags = aFlags;
mGC = aGC;
mIsOffscreen = PR_TRUE;
/* an offscreen surface owns its own PhGC_t */
mGC = PgCreateGC( 0 );
mDrawContext = (PhDrawContext_t *)PdCreateOffscreenContext(0, mWidth, mHeight, 0);
if( !mDrawContext ) return NS_ERROR_FAILURE;

Просмотреть файл

@ -58,19 +58,39 @@ public:
void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
PRUint32 aFlags);
NS_IMETHOD Unlock(void);
NS_IMETHOD GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight);
inline
NS_IMETHODIMP GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight)
{
*aWidth = mWidth;
*aHeight = mHeight;
return NS_OK;
}
inline NS_IMETHODIMP IsOffscreen( PRBool *aOffScreen ) { *aOffScreen = mIsOffscreen; return NS_OK; }
inline NS_IMETHODIMP IsPixelAddressable( PRBool *aAddressable ) { *aAddressable = PR_FALSE; return NS_OK; }
NS_IMETHOD GetPixelFormat(nsPixelFormat *aFormat);
inline
NS_IMETHODIMP GetPixelFormat(nsPixelFormat *aFormat)
{
*aFormat = mPixFormat;
return NS_OK;
}
//nsIDrawingSurfacePh interface
/* Initialize a On-Screen Drawing Surface */
NS_IMETHOD Init( PhGC_t *aGC );
inline
NS_IMETHODIMP Init( PhGC_t *aGC )
{
mGC = aGC;
mIsOffscreen = PR_FALSE;
mDrawContext = nsnull;
return NS_OK;
}
/* Initizlize a Off-Screen Drawing Surface */
NS_IMETHOD Init( PhGC_t *aGC, PRUint32 aWidth, PRUint32 aHeight, PRUint32 aFlags );
NS_IMETHOD Init( PRUint32 aWidth, PRUint32 aHeight, PRUint32 aFlags );
/* Make this DrawingSurface active */
inline NS_IMETHODIMP Select( ) { PhDCSetCurrent( mDrawContext ); PgSetGC( mGC ); return NS_OK; }

Просмотреть файл

@ -293,16 +293,6 @@ printf( "In RealizeFont\n" );
#endif
}
NS_IMETHODIMP nsFontMetricsPh::GetLangGroup(nsIAtom** aLangGroup)
{
if( !aLangGroup ) return NS_ERROR_NULL_POINTER;
*aLangGroup = mLangGroup;
NS_IF_ADDREF(*aLangGroup);
return NS_OK;
}
struct nsFontFamily
{
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
@ -324,6 +314,7 @@ typedef struct EnumerateFamilyInfo
}
EnumerateFamilyInfo;
#if 0
static PRIntn EnumerateFamily( PLHashEntry* he, PRIntn i, void* arg )
{
EnumerateFamilyInfo* info = (EnumerateFamilyInfo*) arg;
@ -345,21 +336,7 @@ static PRIntn EnumerateFamily( PLHashEntry* he, PRIntn i, void* arg )
return HT_ENUMERATE_NEXT;
}
static int CompareFontNames(const void* aArg1, const void* aArg2, void* aClosure)
{
const PRUnichar* str1 = *((const PRUnichar**) aArg1);
const PRUnichar* str2 = *((const PRUnichar**) aArg2);
// XXX add nsICollation stuff
//
return nsCRT::strcmp(str1, str2);
}
NS_IMETHODIMP nsFontEnumeratorPh::EnumerateAllFonts(PRUint32* aCount, PRUnichar*** aResult)
{
return EnumerateFonts( nsnull, nsnull, aCount, aResult );
}
#endif
NS_IMETHODIMP nsFontEnumeratorPh::EnumerateFonts( const char* aLangGroup, const char* aGeneric, PRUint32* aCount, PRUnichar*** aResult )
{
@ -430,31 +407,3 @@ NS_IMETHODIMP nsFontEnumeratorPh::EnumerateFonts( const char* aLangGroup, const
return NS_OK;
}
NS_IMETHODIMP
nsFontEnumeratorPh::HaveFontFor(const char* aLangGroup, PRBool* aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = PR_TRUE; // always return true for now.
return NS_OK;
}
NS_IMETHODIMP
nsFontEnumeratorPh::GetDefaultFont(const char *aLangGroup,
const char *aGeneric, PRUnichar **aResult)
{
// aLangGroup=null or "" means any (i.e., don't care)
// aGeneric=null or "" means any (i.e, don't care)
NS_ENSURE_ARG_POINTER(aResult);
*aResult = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsFontEnumeratorPh::UpdateFontList(PRBool *updateFontList)
{
*updateFontList = PR_FALSE; // always return false for now
return NS_OK;
}

Просмотреть файл

@ -64,7 +64,14 @@ public:
NS_IMETHOD Init(const nsFont& aFont, nsIAtom* aLangGroup,
nsIDeviceContext* aContext);
NS_IMETHOD GetLangGroup(nsIAtom** aLangGroup);
inline
NS_IMETHODIMP GetLangGroup(nsIAtom** aLangGroup)
{
if( !aLangGroup ) return NS_ERROR_NULL_POINTER;
*aLangGroup = mLangGroup;
NS_IF_ADDREF(*aLangGroup);
return NS_OK;
}
NS_IMETHODIMP Destroy()
{
@ -206,7 +213,39 @@ class nsFontEnumeratorPh : public nsIFontEnumerator
public:
nsFontEnumeratorPh();
NS_DECL_ISUPPORTS
NS_DECL_NSIFONTENUMERATOR
// NS_DECL_NSIFONTENUMERATOR
inline NS_IMETHODIMP HaveFontFor(const char* aLangGroup, PRBool* aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = PR_TRUE; // always return true for now.
return NS_OK;
}
inline NS_IMETHODIMP GetDefaultFont(const char *aLangGroup, const char *aGeneric, PRUnichar **aResult)
{
// aLangGroup=null or "" means any (i.e., don't care)
// aGeneric=null or "" means any (i.e, don't care)
NS_ENSURE_ARG_POINTER(aResult);
*aResult = nsnull;
return NS_OK;
}
inline NS_IMETHODIMP UpdateFontList(PRBool *updateFontList)
{
*updateFontList = PR_FALSE; // always return false for now
return NS_OK;
}
inline NS_IMETHODIMP EnumerateAllFonts(PRUint32* aCount, PRUnichar*** aResult)
{
return EnumerateFonts( nsnull, nsnull, aCount, aResult );
}
NS_IMETHOD EnumerateFonts( const char* aLangGroup, const char* aGeneric,
PRUint32* aCount, PRUnichar*** aResult );
};
#endif

Просмотреть файл

@ -38,57 +38,6 @@
#include "nsGraphicsStatePh.h"
//////////////////////////////////////////////////////////////////////////
nsGraphicsState::nsGraphicsState()
{
mMatrix = nsnull;
mClipRegion = nsnull;
mColor = NS_RGB(0, 0, 0);
mLineStyle = nsLineStyle_kSolid;
mFontMetrics = nsnull;
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsState::~nsGraphicsState()
{
NS_IF_RELEASE(mFontMetrics);
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool::nsGraphicsStatePool()
{
mFreeList = nsnull;
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
// Public nsGraphicsStatePool
//
//////////////////////////////////////////////////////////////////////////
/* static */ nsGraphicsState *
nsGraphicsStatePool::GetNewGS()
{
nsGraphicsStatePool * thePool = PrivateGetPool();
return thePool->PrivateGetNewGS();
}
//////////////////////////////////////////////////////////////////////////
/* static */ void
nsGraphicsStatePool::ReleaseGS(nsGraphicsState* aGS)
{
nsGraphicsStatePool * thePool = PrivateGetPool();
thePool->PrivateReleaseGS(aGS);
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
// Private nsGraphicsStatePool
//
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
@ -96,7 +45,7 @@ nsGraphicsStatePool *
nsGraphicsStatePool::gsThePool = nsnull;
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool *
inline nsGraphicsStatePool *
nsGraphicsStatePool::PrivateGetPool()
{
if (nsnull == gsThePool)
@ -106,20 +55,8 @@ nsGraphicsStatePool::PrivateGetPool()
return gsThePool;
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool::~nsGraphicsStatePool()
{
nsGraphicsState* gs = mFreeList;
while (gs != nsnull) {
nsGraphicsState* next = gs->mNext;
delete gs;
gs = next;
}
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsState *
inline nsGraphicsState *
nsGraphicsStatePool::PrivateGetNewGS()
{
nsGraphicsState* gs = mFreeList;
@ -130,12 +67,11 @@ nsGraphicsStatePool::PrivateGetNewGS()
return new nsGraphicsState;
}
//////////////////////////////////////////////////////////////////////////
void
nsGraphicsStatePool::PrivateReleaseGS(nsGraphicsState* aGS)
inline void nsGraphicsStatePool::PrivateReleaseGS(nsGraphicsState* aGS)
{
// aGS->Clear();
aGS->mNext = mFreeList;
mFreeList = aGS;
// aGS->Clear();
aGS->mNext = mFreeList;
mFreeList = aGS;
}
//////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -64,27 +64,59 @@ public:
#endif
private:
nsGraphicsState();
~nsGraphicsState();
inline nsGraphicsState()
{
mMatrix = nsnull;
mClipRegion = nsnull;
mColor = NS_RGB(0, 0, 0);
mLineStyle = nsLineStyle_kSolid;
mFontMetrics = nsnull;
}
inline
~nsGraphicsState()
{
NS_IF_RELEASE(mFontMetrics);
}
};
class nsGraphicsStatePool
{
public:
static nsGraphicsState * GetNewGS();
static void ReleaseGS(nsGraphicsState* aGS);
static
inline nsGraphicsState * GetNewGS()
{
nsGraphicsStatePool * thePool = PrivateGetPool();
return thePool->PrivateGetNewGS();
}
static inline void ReleaseGS(nsGraphicsState* aGS)
{
nsGraphicsStatePool * thePool = PrivateGetPool();
thePool->PrivateReleaseGS(aGS);
}
nsGraphicsStatePool();
~nsGraphicsStatePool();
inline
nsGraphicsStatePool() { mFreeList = nsnull; }
inline ~nsGraphicsStatePool()
{
nsGraphicsState* gs = mFreeList;
while (gs != nsnull) {
nsGraphicsState* next = gs->mNext;
delete gs;
gs = next;
}
}
private:
nsGraphicsState* mFreeList;
static nsGraphicsStatePool * PrivateGetPool();
nsGraphicsState * PrivateGetNewGS();
void PrivateReleaseGS(nsGraphicsState* aGS);
inline static nsGraphicsStatePool * PrivateGetPool();
inline nsGraphicsState * PrivateGetNewGS();
inline void PrivateReleaseGS(nsGraphicsState* aGS);
static nsGraphicsStatePool * gsThePool;
};

Просмотреть файл

@ -75,7 +75,7 @@ public:
* surface created
* @return error status
**/
NS_IMETHOD Init( PhGC_t *aGC, PRUint32 aWidth, PRUint32 aHeight,
NS_IMETHOD Init( PRUint32 aWidth, PRUint32 aHeight,
PRUint32 aFlags) = 0;
};

Просмотреть файл

@ -378,104 +378,6 @@ nsresult nsImagePh :: Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth,nsMas
return NS_OK;
}
//------------------------------------------------------------
/* Creates a shared memory image if allowed...otherwise mallocs it... */
PRUint8 * nsImagePh::CreateSRamImage (PRUint32 size)
{
/* TODO: add code to check for remote drivers (no shmem then) */
return (PRUint8 *) PgShmemCreate(size,NULL);
}
PRBool nsImagePh::DestroySRamImage (PRUint8 * ptr)
{
PgShmemDestroy(ptr);
return PR_TRUE;
}
PRInt32 nsImagePh::GetHeight()
{
return mHeight;
}
PRInt32 nsImagePh::GetWidth()
{
return mWidth;
}
PRUint8* nsImagePh::GetBits()
{
return mImageBits;
}
void* nsImagePh::GetBitInfo()
{
return nsnull;
}
PRInt32 nsImagePh::GetLineStride()
{
return mRowBytes;
}
nsColorMap* nsImagePh::GetColorMap()
{
return nsnull;
}
PRBool nsImagePh::IsOptimized()
{
return mIsOptimized;
}
PRUint8* nsImagePh::GetAlphaBits()
{
return mAlphaBits;
}
PRInt32 nsImagePh::GetAlphaWidth()
{
return mAlphaWidth;
}
PRInt32 nsImagePh::GetAlphaHeight()
{
return mAlphaHeight;
}
PRInt32 nsImagePh::GetAlphaLineStride()
{
return mAlphaRowBytes;
}
nsIImage *nsImagePh::DuplicateImage()
{
return nsnull;
}
void nsImagePh::SetAlphaLevel(PRInt32 aAlphaLevel)
{
mAlphaLevel=aAlphaLevel;
}
PRInt32 nsImagePh::GetAlphaLevel()
{
return(mAlphaLevel);
}
void nsImagePh::MoveAlphaMask(PRInt32 aX, PRInt32 aY)
{
}
void nsImagePh :: ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect)
{
PRInt32 y = aUpdateRect->YMost();
PRInt32 x = aUpdateRect->XMost();
if( y > mDecodedY2 ) mDecodedY2 = y;
if( x > mDecodedX2 ) mDecodedX2 = x;
mDirtyFlags = aFlags;
}
/** ----------------------------------------------------------------
* Draw the bitmap, this method has a source and destination coordinates
* @update dc - 11/20/98
@ -815,35 +717,6 @@ nsresult nsImagePh :: Optimize(nsIDeviceContext* aContext)
}
//------------------------------------------------------------
// lock the image pixels. Implement this if you need it.
NS_IMETHODIMP
nsImagePh::LockImagePixels(PRBool aMaskPixels)
{
return NS_OK;
}
//------------------------------------------------------------
// unlock the image pixels. Implement this if you need it.
NS_IMETHODIMP
nsImagePh::UnlockImagePixels(PRBool aMaskPixels)
{
return NS_OK;
}
/** ---------------------------------------------------
* Set the decoded dimens of the image
*/
NS_IMETHODIMP
nsImagePh::SetDecodedRect(PRInt32 x1, PRInt32 y1, PRInt32 x2, PRInt32 y2 )
{
mDecodedX1 = x1;
mDecodedY1 = y1;
mDecodedX2 = x2;
mDecodedY2 = y2;
return NS_OK;
}
/**
* BitBlit the entire (no cropping) nsIImage to another nsImage, the source and dest can be scaled
* @update - saari 03/08/01

Просмотреть файл

@ -41,6 +41,7 @@
#include <Pt.h>
#include "nsIImage.h"
#include "nsRect.h"
class nsImagePh : public nsIImage {
public:
@ -53,14 +54,26 @@ public:
@see nsIImage.h
*/
virtual PRInt32 GetBytesPix() { return mNumBytesPixel; }
virtual PRInt32 GetHeight();
virtual PRInt32 GetWidth();
virtual PRUint8* GetBits();
virtual void* GetBitInfo();
virtual PRBool GetIsRowOrderTopToBottom() { return mIsTopToBottom; }
virtual PRInt32 GetLineStride();
virtual PRInt32 GetHeight() { return mHeight; }
virtual PRInt32 GetWidth() { return mWidth; }
virtual PRUint8* GetBits() { return mImageBits; }
virtual void* GetBitInfo() { return nsnull; }
virtual PRBool GetIsRowOrderTopToBottom() { return mIsTopToBottom; }
virtual PRInt32 GetLineStride() { return mRowBytes; }
inline
NS_IMETHODIMP SetDecodedRect(PRInt32 x1, PRInt32 y1, PRInt32 x2, PRInt32 y2)
{
mDecodedX1 = x1;
mDecodedY1 = y1;
mDecodedX2 = x2;
mDecodedY2 = y2;
return NS_OK;
}
NS_IMETHOD SetDecodedRect(PRInt32 x1, PRInt32 y1, PRInt32 x2, PRInt32 y2);
virtual PRInt32 GetDecodedX1() { return mDecodedX1;}
virtual PRInt32 GetDecodedY1() { return mDecodedY1;}
virtual PRInt32 GetDecodedX2() { return mDecodedX2;}
@ -72,7 +85,8 @@ public:
virtual PRInt32 GetNaturalHeight() {return mNaturalHeight; }
virtual nsColorMap* GetColorMap();
virtual nsColorMap* GetColorMap() { return nsnull; }
NS_IMETHOD Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface, PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
NS_IMETHOD Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface, PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, \
PRInt32 aSHeight, PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
@ -86,36 +100,57 @@ public:
NS_IMETHOD DrawTile(nsIRenderingContext &aContext, nsDrawingSurface aSurface,
PRInt32 aSXOffset, PRInt32 aSYOffset, const nsRect &aTileRect);
virtual void ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect);
virtual void ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect)
{
PRInt32 y = aUpdateRect->YMost();
PRInt32 x = aUpdateRect->XMost();
if( y > mDecodedY2 ) mDecodedY2 = y;
if( x > mDecodedX2 ) mDecodedX2 = x;
mDirtyFlags = aFlags;
}
virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequirements aMaskRequirements);
virtual PRBool IsOptimized();
virtual PRBool IsOptimized() { return mIsOptimized; }
virtual nsresult Optimize(nsIDeviceContext* aContext);
virtual PRBool GetHasAlphaMask() { return mAlphaBits != nsnull; }
virtual PRUint8* GetAlphaBits();
virtual PRInt32 GetAlphaWidth();
virtual PRInt32 GetAlphaHeight();
virtual PRInt32 GetAlphaLineStride();
virtual nsIImage* DuplicateImage();
virtual PRBool GetHasAlphaMask() { return mAlphaBits != nsnull; }
virtual PRUint8* GetAlphaBits() { return mAlphaBits; }
virtual PRInt32 GetAlphaWidth() { return mAlphaWidth; }
virtual PRInt32 GetAlphaHeight() { return mAlphaHeight; }
virtual PRInt32 GetAlphaLineStride() { return mAlphaRowBytes; }
virtual nsIImage* DuplicateImage() { return nsnull; }
virtual void SetAlphaLevel(PRInt32 aAlphaLevel);
virtual PRInt32 GetAlphaLevel();
virtual void SetAlphaLevel(PRInt32 aAlphaLevel) { mAlphaLevel=aAlphaLevel; }
virtual PRInt32 GetAlphaLevel() { return mAlphaLevel; }
/**
* Get the alpha depth for the image mask
* @update - lordpixel 2001/05/16
* @return the alpha mask depth for the image, ie, 0, 1 or 8
*/
virtual PRInt8 GetAlphaDepth() {return(mAlphaDepth);}
virtual void MoveAlphaMask(PRInt32 aX, PRInt32 aY);
virtual PRInt8 GetAlphaDepth() { return mAlphaDepth; }
virtual void MoveAlphaMask(PRInt32 aX, PRInt32 aY) { }
NS_IMETHOD LockImagePixels(PRBool aMaskPixels);
NS_IMETHOD UnlockImagePixels(PRBool aMaskPixels);
inline
NS_IMETHODIMP LockImagePixels(PRBool aMaskPixels) { return NS_OK; }
inline
NS_IMETHODIMP UnlockImagePixels(PRBool aMaskPixels) { return NS_OK; }
private:
void ComputePaletteSize(PRIntn nBitCount);
PRUint8 * CreateSRamImage(PRUint32 size);
PRBool DestroySRamImage(PRUint8 *ptr);
inline PRUint8 * CreateSRamImage(PRUint32 size)
{
/* TODO: add code to check for remote drivers (no shmem then) */
return (PRUint8 *) PgShmemCreate(size,NULL);
}
inline PRBool DestroySRamImage(PRUint8 *ptr)
{
PgShmemDestroy(ptr);
return PR_TRUE;
}
private:

Просмотреть файл

@ -37,7 +37,6 @@
* ***** END LICENSE BLOCK ***** */
#include "nsRegionPh.h"
#include "prmem.h"
/* Turn debug off to limit all the output to PhGfxLog */
#undef DEBUG
@ -57,69 +56,8 @@ static NS_DEFINE_IID(kRegionIID, NS_IREGION_IID);
#define clrx c->rect.lr.x
#define clry c->rect.lr.y
nsRegionPh :: nsRegionPh( ) {
NS_INIT_ISUPPORTS();
mRegion = NULL;
mRegionType = eRegionComplexity_empty;
}
nsRegionPh :: nsRegionPh( PhTile_t *tiles ) {
NS_INIT_ISUPPORTS();
mRegion = tiles; /* assume ownership */
mRegionType = (mRegion == NULL) ? eRegionComplexity_empty : eRegionComplexity_complex;
}
nsRegionPh :: ~nsRegionPh( ) {
if( mRegion ) PhFreeTiles( mRegion );
mRegion = nsnull;
}
NS_IMPL_ISUPPORTS1(nsRegionPh, nsIRegion)
nsresult nsRegionPh :: Init( void ) {
SetRegionEmpty();
return NS_OK;
}
void nsRegionPh :: SetTo( const nsIRegion &aRegion ) {
PhTile_t *tiles;
aRegion.GetNativeRegion( ( void*& ) tiles );
SetRegionEmpty( );
mRegion = PhCopyTiles( tiles );
}
void nsRegionPh :: SetTo( PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight ) {
SetRegionEmpty( );
if ( aWidth > 0 && aHeight > 0 ) {
/* Create a temporary tile to assign to mRegion */
PhTile_t *tile = PhGetTile( );
tile->rect.ul.x = aX;
tile->rect.ul.y = aY;
tile->rect.lr.x = (aX+aWidth-1);
tile->rect.lr.y = (aY+aHeight-1);
tile->next = NULL;
mRegion = tile;
}
}
void nsRegionPh :: Intersect( const nsIRegion &aRegion )
{
PhTile_t *original = mRegion;
PhTile_t *tiles;
aRegion.GetNativeRegion( ( void*& ) tiles );
mRegion = PhIntersectTilings( original, tiles, NULL);
if( mRegion )
mRegion = PhCoalesceTiles( PhMergeTiles( PhSortTiles( mRegion )));
PhFreeTiles( original );
if ( mRegion == NULL )
SetTo(0, 0, 1, 1);
}
void nsRegionPh :: Intersect( PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight )
{
@ -143,60 +81,6 @@ void nsRegionPh :: Intersect( PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aH
}
void nsRegionPh :: Union( const nsIRegion &aRegion ) {
PhTile_t *tiles;
aRegion.GetNativeRegion( ( void*& ) tiles );
mRegion = PhAddMergeTiles( mRegion, PhCopyTiles( tiles ), NULL );
}
void nsRegionPh :: Union( PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight ) {
if( aWidth > 0 && aHeight > 0 ) {
/* Create a temporary tile to assign to mRegion */
PhTile_t *tile = PhGetTile();
tile->rect.ul.x = aX;
tile->rect.ul.y = aY;
tile->rect.lr.x = (aX+aWidth-1);
tile->rect.lr.y = (aY+aHeight-1);
tile->next = NULL;
mRegion = PhAddMergeTiles( mRegion, tile, NULL );
}
}
void nsRegionPh :: Subtract( const nsIRegion &aRegion ) {
PhTile_t *tiles;
aRegion.GetNativeRegion((void*&)tiles);
mRegion = PhClipTilings( mRegion, tiles, NULL );
}
void nsRegionPh :: Subtract( PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight ) {
if( aWidth > 0 && aHeight > 0 ) {
/* Create a temporary tile to assign to mRegion */
PhTile_t tile;
tile.rect.ul.x = aX;
tile.rect.ul.y = aY;
tile.rect.lr.x = aX + aWidth - 1;
tile.rect.lr.y = aY + aHeight - 1;
tile.next = NULL;
mRegion = PhClipTilings( mRegion, &tile, NULL );
}
}
PRBool nsRegionPh :: IsEmpty( void )
{
if ( !mRegion )
return PR_TRUE;
if ( mRegion->rect.ul.x == 0 && mRegion->rect.ul.y == 0 &&
mRegion->rect.lr.x == 0 && mRegion->rect.lr.y == 0 )
return PR_TRUE;
return PR_FALSE;
}
PRBool nsRegionPh :: IsEqual( const nsIRegion &aRegion ) {
PRBool result = PR_TRUE;
PhTile_t *tiles;
@ -253,17 +137,6 @@ void nsRegionPh :: GetBoundingBox( PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PR
}
void nsRegionPh :: Offset( PRInt32 aXOffset, PRInt32 aYOffset ) {
if( ( aXOffset || aYOffset ) && mRegion ) {
PhPoint_t p = { aXOffset, aYOffset };
/* 99.99% there is only one tile - so simplify things, while allow the general case to work as well */
if( !mRegion->next ) PtTranslateRect( &mRegion->rect, &p );
else PhTranslateTiles( mRegion, &p );
}
}
PRBool nsRegionPh :: ContainsRect( PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight ) {
if( !mRegion ) return PR_FALSE;
@ -344,30 +217,3 @@ NS_IMETHODIMP nsRegionPh :: GetRects( nsRegionRectSet **aRects ) {
*aRects = rects;
return NS_OK;
}
NS_IMETHODIMP nsRegionPh :: FreeRects( nsRegionRectSet *aRects ) {
if( nsnull != aRects ) PR_Free( ( void * )aRects );
return NS_OK;
}
NS_IMETHODIMP nsRegionPh :: GetNativeRegion(void *&aRegion) const {
aRegion = (void *) mRegion;
return NS_OK;
}
NS_IMETHODIMP nsRegionPh :: GetRegionComplexity(nsRegionComplexity &aComplexity) const {
aComplexity = mRegionType;
return NS_OK;
}
void nsRegionPh :: SetRegionEmpty( void ) {
if( mRegion ) PhFreeTiles( mRegion );
mRegion = NULL;
mRegionType = eRegionComplexity_empty;
}

Просмотреть файл

@ -40,41 +40,177 @@
#define nsRegionPh_h___
#include "nsIRegion.h"
#include "prmem.h"
#include <Pt.h>
class nsRegionPh : public nsIRegion
{
public:
nsRegionPh();
nsRegionPh(PhTile_t *tiles);
inline nsRegionPh()
{
NS_INIT_ISUPPORTS();
mRegion = NULL;
mRegionType = eRegionComplexity_empty;
}
virtual ~nsRegionPh();
inline nsRegionPh(PhTile_t *tiles)
{
NS_INIT_ISUPPORTS();
mRegion = tiles; /* assume ownership */
mRegionType = (mRegion == NULL) ? eRegionComplexity_empty : eRegionComplexity_complex;
}
virtual ~nsRegionPh()
{
if( mRegion ) PhFreeTiles( mRegion );
mRegion = nsnull;
}
NS_DECL_ISUPPORTS
virtual nsresult Init();
virtual nsresult Init()
{
SetRegionEmpty();
return NS_OK;
}
virtual void SetTo(const nsIRegion &aRegion)
{
PhTile_t *tiles;
aRegion.GetNativeRegion( ( void*& ) tiles );
SetRegionEmpty( );
mRegion = PhCopyTiles( tiles );
}
virtual void SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
SetRegionEmpty( );
if ( aWidth > 0 && aHeight > 0 ) {
/* Create a temporary tile to assign to mRegion */
PhTile_t *tile = PhGetTile( );
tile->rect.ul.x = aX;
tile->rect.ul.y = aY;
tile->rect.lr.x = (aX+aWidth-1);
tile->rect.lr.y = (aY+aHeight-1);
tile->next = NULL;
mRegion = tile;
}
}
virtual void Intersect(const nsIRegion &aRegion)
{
PhTile_t *original = mRegion;
PhTile_t *tiles;
aRegion.GetNativeRegion( ( void*& ) tiles );
mRegion = PhIntersectTilings( original, tiles, NULL);
if( mRegion )
mRegion = PhCoalesceTiles( PhMergeTiles( PhSortTiles( mRegion )));
PhFreeTiles( original );
if ( mRegion == NULL )
SetTo(0, 0, 1, 1);
}
virtual void SetTo(const nsIRegion &aRegion);
virtual void SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
virtual void Intersect(const nsIRegion &aRegion);
virtual void Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
virtual void Union(const nsIRegion &aRegion);
virtual void Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
virtual void Subtract(const nsIRegion &aRegion);
virtual void Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
virtual PRBool IsEmpty(void);
virtual void Union(const nsIRegion &aRegion)
{
PhTile_t *tiles;
aRegion.GetNativeRegion( ( void*& ) tiles );
mRegion = PhAddMergeTiles( mRegion, PhCopyTiles( tiles ), NULL );
}
virtual void Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
if( aWidth > 0 && aHeight > 0 ) {
/* Create a temporary tile to assign to mRegion */
PhTile_t *tile = PhGetTile();
tile->rect.ul.x = aX;
tile->rect.ul.y = aY;
tile->rect.lr.x = (aX+aWidth-1);
tile->rect.lr.y = (aY+aHeight-1);
tile->next = NULL;
mRegion = PhAddMergeTiles( mRegion, tile, NULL );
}
}
virtual void Subtract(const nsIRegion &aRegion)
{
PhTile_t *tiles;
aRegion.GetNativeRegion((void*&)tiles);
mRegion = PhClipTilings( mRegion, tiles, NULL );
}
virtual void Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
if( aWidth > 0 && aHeight > 0 ) {
/* Create a temporary tile to assign to mRegion */
PhTile_t tile;
tile.rect.ul.x = aX;
tile.rect.ul.y = aY;
tile.rect.lr.x = aX + aWidth - 1;
tile.rect.lr.y = aY + aHeight - 1;
tile.next = NULL;
mRegion = PhClipTilings( mRegion, &tile, NULL );
}
}
virtual PRBool IsEmpty(void)
{
if ( !mRegion )
return PR_TRUE;
if ( mRegion->rect.ul.x == 0 && mRegion->rect.ul.y == 0 &&
mRegion->rect.lr.x == 0 && mRegion->rect.lr.y == 0 )
return PR_TRUE;
return PR_FALSE;
}
virtual PRBool IsEqual(const nsIRegion &aRegion);
virtual void GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight);
virtual void Offset(PRInt32 aXOffset, PRInt32 aYOffset);
virtual void Offset(PRInt32 aXOffset, PRInt32 aYOffset)
{
if( ( aXOffset || aYOffset ) && mRegion ) {
PhPoint_t p = { aXOffset, aYOffset };
/* 99.99% there is only one tile - so simplify things, while allow the general case to work as well */
if( !mRegion->next ) PtTranslateRect( &mRegion->rect, &p );
else PhTranslateTiles( mRegion, &p );
}
}
virtual PRBool ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
NS_IMETHOD GetRects(nsRegionRectSet **aRects);
NS_IMETHOD FreeRects(nsRegionRectSet *aRects);
NS_IMETHOD GetNativeRegion(void *&aRegion) const;
NS_IMETHOD GetRegionComplexity(nsRegionComplexity &aComplexity) const;
NS_IMETHOD GetNumRects(PRUint32 *aRects) const { *aRects = 0; return NS_OK; }
inline NS_IMETHODIMP FreeRects(nsRegionRectSet *aRects)
{
if( nsnull != aRects ) PR_Free( ( void * )aRects );
return NS_OK;
}
inline NS_IMETHODIMP GetNativeRegion(void *&aRegion) const
{
aRegion = (void *) mRegion;
return NS_OK;
}
inline NS_IMETHODIMP GetRegionComplexity(nsRegionComplexity &aComplexity) const
{
aComplexity = mRegionType;
return NS_OK;
}
inline NS_IMETHOD GetNumRects(PRUint32 *aRects) const { *aRects = 0; return NS_OK; }
private:
virtual void SetRegionEmpty();
virtual void SetRegionEmpty()
{
if( mRegion ) PhFreeTiles( mRegion );
mRegion = NULL;
mRegionType = eRegionComplexity_empty;
}
PhTile_t *mRegion;
nsRegionComplexity mRegionType; // Not really used!

Просмотреть файл

@ -55,11 +55,6 @@ static NS_DEFINE_IID(kIDrawingSurfaceIID, NS_IDRAWING_SURFACE_IID);
static NS_DEFINE_IID(kDrawingSurfaceCID, NS_DRAWING_SURFACE_CID);
static NS_DEFINE_CID(kRegionCID, NS_REGION_CID);
// Macro for converting from nscolor to PtColor_t
// Photon RGB values are stored as 00 RR GG BB
// nscolor RGB values are 00 BB GG RR
#define NS_TO_PH_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff)
#define PH_TO_NS_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff)
#include <prlog.h>
PRLogModuleInfo *PhGfxLog = PR_NewLogModule("PhGfxLog");
@ -89,8 +84,6 @@ nsRenderingContextPh :: nsRenderingContextPh()
PushState();
}
static int xxx;
nsRenderingContextPh :: ~nsRenderingContextPh()
{
@ -176,91 +169,6 @@ NS_IMETHODIMP nsRenderingContextPh :: Init( nsIDeviceContext* aContext, nsIWidge
return CommonInit();
}
NS_IMETHODIMP nsRenderingContextPh :: Init( nsIDeviceContext* aContext, nsDrawingSurface aSurface )
{
mContext = aContext;
NS_IF_ADDREF(mContext);
mSurface = (nsDrawingSurfacePh *) aSurface;
NS_ADDREF(mSurface);
mGC = mSurface->GetGC();
mOwner = PR_FALSE;
return CommonInit();
}
NS_IMETHODIMP nsRenderingContextPh::CommonInit()
{
if( mContext && mTranMatrix ) {
mContext->GetDevUnitsToAppUnits(mP2T);
float app2dev;
mContext->GetAppUnitsToDevUnits(app2dev);
mTranMatrix->AddScale(app2dev, app2dev);
}
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: GetHints( PRUint32& aResult )
{
PRUint32 result = 0;
// Most X servers implement 8 bit text rendering alot faster than
// XChar2b rendering. In addition, we can avoid the PRUnichar to
// XChar2b conversion. So we set this bit...
result |= NS_RENDERING_HINT_FAST_8BIT_TEXT;
/* this flag indicates that the system prefers 8bit chars over wide chars */
/* It may or may not be faster under photon... */
aResult = result;
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: LockDrawingSurface( PRInt32 aX, PRInt32 aY,
PRUint32 aWidth, PRUint32 aHeight,
void **aBits, PRInt32 *aStride,
PRInt32 *aWidthBytes, PRUint32 aFlags )
{
PushState();
return mSurface->Lock( aX, aY, aWidth, aHeight, aBits, aStride, aWidthBytes, aFlags );
}
NS_IMETHODIMP nsRenderingContextPh::UnlockDrawingSurface( void )
{
PRBool clipstate;
PopState( clipstate );
mSurface->Unlock();
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: SelectOffScreenDrawingSurface( nsDrawingSurface aSurface )
{
if( nsnull==aSurface )
mSurface = mOffscreenSurface;
else
mSurface = (nsDrawingSurfacePh *) aSurface;
mSurface->Select( );
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: GetDrawingSurface( nsDrawingSurface *aSurface )
{
*aSurface = (void *) mSurface;
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: GetDeviceContext( nsIDeviceContext *&aContext )
{
NS_IF_ADDREF( mContext );
aContext = mContext;
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: PushState( void )
{
// Get a new GS
@ -343,12 +251,6 @@ NS_IMETHODIMP nsRenderingContextPh :: PopState( PRBool &aClipEmpty )
}
NS_IMETHODIMP nsRenderingContextPh :: IsVisibleRect( const nsRect& aRect, PRBool &aVisible )
{
aVisible = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: GetClipRect( nsRect &aRect, PRBool &aClipValid )
{
PRInt32 x, y, w, h;
@ -457,13 +359,6 @@ NS_IMETHODIMP nsRenderingContextPh :: SetClipRegion( const nsIRegion& aRegion, n
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: CopyClipRegion( nsIRegion &aRegion )
{
if( !mClipRegion ) return NS_ERROR_FAILURE;
aRegion.SetTo(*NS_STATIC_CAST(nsIRegion*, mClipRegion));
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: GetClipRegion( nsIRegion **aRegion )
{
nsresult rv = NS_ERROR_FAILURE;
@ -489,20 +384,6 @@ NS_IMETHODIMP nsRenderingContextPh :: GetClipRegion( nsIRegion **aRegion )
return rv;
}
NS_IMETHODIMP nsRenderingContextPh :: SetColor( nscolor aColor )
{
// ATENTIE if( nsnull == mContext ) return NS_ERROR_FAILURE;
mCurrentColor = aColor;
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: GetColor( nscolor &aColor ) const
{
aColor = mCurrentColor;
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: SetLineStyle( nsLineStyle aLineStyle )
{
mCurrentLineStyle = aLineStyle;
@ -525,25 +406,6 @@ NS_IMETHODIMP nsRenderingContextPh :: SetLineStyle( nsLineStyle aLineStyle )
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: GetLineStyle( nsLineStyle &aLineStyle )
{
aLineStyle = mCurrentLineStyle;
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: SetFont( const nsFont& aFont, nsIAtom* aLangGroup )
{
nsIFontMetrics* newMetrics;
nsresult rv = mContext->GetMetricsFor( aFont, aLangGroup, newMetrics );
if( NS_SUCCEEDED( rv ) ) {
rv = SetFont( newMetrics );
NS_RELEASE( newMetrics );
}
return rv;
}
NS_IMETHODIMP nsRenderingContextPh :: SetFont( nsIFontMetrics *aFontMetrics )
{
if( mFontMetrics == aFontMetrics ) return NS_OK;
@ -563,38 +425,11 @@ NS_IMETHODIMP nsRenderingContextPh :: SetFont( nsIFontMetrics *aFontMetrics )
if( pFontHandle ) {
if( mPhotonFontName ) free( mPhotonFontName );
mPhotonFontName = strdup( pFontHandle );
}
}
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: GetFontMetrics( nsIFontMetrics *&aFontMetrics )
{
NS_IF_ADDREF(mFontMetrics);
aFontMetrics = mFontMetrics;
return NS_OK;
}
// add the passed in translation to the current translation
NS_IMETHODIMP nsRenderingContextPh :: Translate( nscoord aX, nscoord aY )
{
mTranMatrix->AddTranslation((float)aX,(float)aY);
return NS_OK;
}
// add the passed in scale to the current scale
NS_IMETHODIMP nsRenderingContextPh :: Scale( float aSx, float aSy )
{
mTranMatrix->AddScale(aSx, aSy);
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: GetCurrentTransform( nsTransform2D *&aTransform )
{
aTransform = mTranMatrix;
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: CreateDrawingSurface( const nsRect &aBounds, PRUint32 aSurfFlags, nsDrawingSurface &aSurface )
{
if( nsnull == mSurface ) {
@ -605,7 +440,7 @@ NS_IMETHODIMP nsRenderingContextPh :: CreateDrawingSurface( const nsRect &aBound
nsDrawingSurfacePh *surf = new nsDrawingSurfacePh();
if( surf ) {
NS_ADDREF(surf);
surf->Init( NULL, aBounds.width, aBounds.height, aSurfFlags ); /* we pass NULL as aGC here / it means use the default photon gc */
surf->Init( aBounds.width, aBounds.height, aSurfFlags ); /* we pass NULL as aGC here / it means use the default photon gc */
}
else
return NS_ERROR_FAILURE;
@ -616,14 +451,6 @@ NS_IMETHODIMP nsRenderingContextPh :: CreateDrawingSurface( const nsRect &aBound
}
NS_IMETHODIMP nsRenderingContextPh :: DestroyDrawingSurface( nsDrawingSurface aDS )
{
nsDrawingSurfacePh *surf = (nsDrawingSurfacePh *) aDS;
NS_IF_RELEASE(surf);
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: DrawLine( nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1 )
{
mTranMatrix->TransformCoord( &aX0, &aY0 );
@ -650,16 +477,6 @@ NS_IMETHODIMP nsRenderingContextPh :: DrawStdLine( nscoord aX0, nscoord aY0, nsc
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: DrawPolyline( const nsPoint aPoints[], PRInt32 aNumPoints )
{
return DrawPolygon( aPoints, aNumPoints );
}
NS_IMETHODIMP nsRenderingContextPh :: DrawRect( const nsRect& aRect )
{
return DrawRect( aRect.x, aRect.y, aRect.width, aRect.height );
}
NS_IMETHODIMP nsRenderingContextPh :: DrawRect( nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight )
{
nscoord x,y,w,h;
@ -677,11 +494,6 @@ NS_IMETHODIMP nsRenderingContextPh :: DrawRect( nscoord aX, nscoord aY, nscoord
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: FillRect( const nsRect& aRect )
{
return FillRect( aRect.x, aRect.y, aRect.width, aRect.height );
}
NS_IMETHODIMP nsRenderingContextPh :: FillRect( nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight )
{
nscoord x,y,w,h;
@ -705,11 +517,6 @@ NS_IMETHODIMP nsRenderingContextPh :: FillRect( nscoord aX, nscoord aY, nscoord
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: InvertRect( const nsRect& aRect )
{
return InvertRect( aRect.x, aRect.y, aRect.width, aRect.height );
}
NS_IMETHODIMP nsRenderingContextPh :: InvertRect( nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight )
{
if( nsnull == mTranMatrix || nsnull == mSurface ) return NS_ERROR_FAILURE;
@ -784,12 +591,6 @@ NS_IMETHODIMP nsRenderingContextPh :: FillPolygon( const nsPoint aPoints[], PRIn
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: DrawEllipse( const nsRect& aRect )
{
DrawEllipse( aRect.x, aRect.y, aRect.width, aRect.height );
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: DrawEllipse( nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight )
{
nscoord x,y,w,h;
@ -811,13 +612,6 @@ NS_IMETHODIMP nsRenderingContextPh :: DrawEllipse( nscoord aX, nscoord aY, nscoo
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: FillEllipse( const nsRect& aRect )
{
FillEllipse( aRect.x, aRect.y, aRect.width, aRect.height );
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: FillEllipse( nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight )
{
nscoord x,y,w,h;
@ -840,13 +634,6 @@ NS_IMETHODIMP nsRenderingContextPh :: FillEllipse( nscoord aX, nscoord aY, nscoo
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: DrawArc( const nsRect& aRect, float aStartAngle, float aEndAngle )
{
return DrawArc(aRect.x,aRect.y,aRect.width,aRect.height,aStartAngle,aEndAngle);
}
NS_IMETHODIMP nsRenderingContextPh :: DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, float aStartAngle, float aEndAngle )
{
nscoord x,y,w,h;
@ -870,11 +657,6 @@ NS_IMETHODIMP nsRenderingContextPh :: DrawArc(nscoord aX, nscoord aY, nscoord aW
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: FillArc( const nsRect& aRect, float aStartAngle, float aEndAngle )
{
return FillArc(aRect.x,aRect.y,aRect.width,aRect.height,aStartAngle,aEndAngle);
}
NS_IMETHODIMP nsRenderingContextPh :: FillArc( nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, float aStartAngle, float aEndAngle )
{
nscoord x,y,w,h;
@ -897,31 +679,6 @@ NS_IMETHODIMP nsRenderingContextPh :: FillArc( nscoord aX, nscoord aY, nscoord a
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: GetWidth( char ch, nscoord& aWidth )
{
// Check for the very common case of trying to get the width of a single
// space.
if(ch == ' ' && nsnull != mFontMetrics ) {
return mFontMetrics->GetSpaceWidth(aWidth);
}
return GetWidth( &ch, 1, aWidth );
}
NS_IMETHODIMP nsRenderingContextPh :: GetWidth( PRUnichar ch, nscoord &aWidth, PRInt32 *aFontID )
{
PRUnichar buf[2];
/* turn it into a string */
buf[0] = ch;
buf[1] = nsnull;
return GetWidth( buf, 1, aWidth, aFontID );
}
NS_IMETHODIMP nsRenderingContextPh :: GetWidth( const char* aString, nscoord& aWidth )
{
return GetWidth( aString, strlen( aString ), aWidth );
}
NS_IMETHODIMP nsRenderingContextPh :: GetWidth(const char* aString, PRUint32 aLength, nscoord& aWidth )
{
@ -944,12 +701,6 @@ NS_IMETHODIMP nsRenderingContextPh :: GetWidth(const char* aString, PRUint32 aLe
return ret_code;
}
NS_IMETHODIMP nsRenderingContextPh :: GetWidth( const nsString& aString, nscoord& aWidth, PRInt32 *aFontID )
{
return GetWidth( aString.get(), aString.Length(), aWidth, aFontID );
}
NS_IMETHODIMP nsRenderingContextPh :: GetWidth( const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth, PRInt32 *aFontID )
{
nsresult ret_code = NS_ERROR_FAILURE;
@ -964,14 +715,6 @@ NS_IMETHODIMP nsRenderingContextPh :: GetWidth( const PRUnichar *aString, PRUint
return ret_code;
}
NS_IMETHODIMP nsRenderingContextPh::GetTextDimensions(const char* aString, PRUint32 aLength, nsTextDimensions& aDimensions)
{
aDimensions.Clear();
mFontMetrics->GetMaxAscent(aDimensions.ascent);
mFontMetrics->GetMaxDescent(aDimensions.descent);
return GetWidth(aString, aLength, aDimensions.width);
}
NS_IMETHODIMP nsRenderingContextPh::GetTextDimensions(const PRUnichar* aString, PRUint32 aLength,
nsTextDimensions& aDimensions, PRInt32* aFontID)
{
@ -990,13 +733,6 @@ NS_IMETHODIMP nsRenderingContextPh::GetTextDimensions(const PRUnichar* aString,
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh :: DrawString( const nsString& aString, nscoord aX, nscoord aY, PRInt32 aFontID, const nscoord* aSpacing )
{
NS_ConvertUCS2toUTF8 theUnicodeString( aString.get(), aString.Length() );
const char *p = theUnicodeString.get();
return DrawString( p, strlen( p ), aX, aY, aSpacing );
}
NS_IMETHODIMP nsRenderingContextPh::DrawString(const char *aString, PRUint32 aLength,
nscoord aX, nscoord aY,
const nscoord* aSpacing)
@ -1031,44 +767,6 @@ NS_IMETHODIMP nsRenderingContextPh::DrawString(const char *aString, PRUint32 aLe
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh::DrawString(const PRUnichar* aString, PRUint32 aLength,
nscoord aX, nscoord aY,
PRInt32 aFontID,
const nscoord* aSpacing)
{
NS_ConvertUCS2toUTF8 theUnicodeString( aString, aLength );
const char *p = theUnicodeString.get( );
return DrawString( p, strlen( p ), aX, aY, aSpacing );
}
NS_IMETHODIMP nsRenderingContextPh::DrawImage( nsIImage *aImage, nscoord aX, nscoord aY )
{
nscoord width, height;
// we have to do this here because we are doing a transform below
width = NSToCoordRound(mP2T * aImage->GetWidth());
height = NSToCoordRound(mP2T * aImage->GetHeight());
return DrawImage( aImage, aX, aY, width, height );
}
NS_IMETHODIMP nsRenderingContextPh::DrawImage( nsIImage *aImage, const nsRect& aRect )
{
return DrawImage( aImage, aRect.x, aRect.y, aRect.width, aRect.height );
}
NS_IMETHODIMP nsRenderingContextPh::DrawImage( nsIImage *aImage, nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight )
{
nscoord x, y, w, h;
x = aX;
y = aY;
w = aWidth;
h = aHeight;
mTranMatrix->TransformCoord(&x, &y, &w, &h);
return (aImage->Draw(*this, mSurface, x, y, w, h));
}
NS_IMETHODIMP nsRenderingContextPh::DrawImage( nsIImage *aImage, const nsRect& aSRect, const nsRect& aDRect )
{
nsRect sr,dr;
@ -1155,13 +853,6 @@ NS_IMETHODIMP nsRenderingContextPh :: CopyOffScreenBits( nsDrawingSurface aSrcSu
darea.size.h = sarea.size.h;
PgContextBlitArea( (PdOffscreenContext_t *) ((nsDrawingSurfacePh *)aSrcSurf)->GetDC(), &sarea,
(PdOffscreenContext_t *) ((nsDrawingSurfacePh *)destsurf)->GetDC(), &darea );
// ATENTIE PgFlush();
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextPh::RetrieveCurrentNativeGraphicData( PRUint32 * ngd )
{
if( ngd != nsnull ) *ngd = nsnull;
return NS_OK;
}
@ -1190,16 +881,6 @@ NS_IMETHODIMP nsRenderingContextPh::GetBoundingMetrics(const PRUnichar* aStrin
#endif /* MOZ_MATHML */
void nsRenderingContextPh::UpdateGC()
{
PgSetGC( mGC ); /* new */
PgSetStrokeColor( NS_TO_PH_RGB( mCurrentColor ) );
PgSetTextColor( NS_TO_PH_RGB( mCurrentColor ) );
PgSetFillColor( NS_TO_PH_RGB( mCurrentColor ) );
PgSetStrokeDash( mLineStyle, strlen((char *)mLineStyle), 0x10000 );
ApplyClipping( mGC );
}
void nsRenderingContextPh::ApplyClipping( PhGC_t *gc )
{

Просмотреть файл

@ -57,6 +57,12 @@
#include "nsDrawingSurfacePh.h"
#include "nsRegionPh.h"
// Macro for converting from nscolor to PtColor_t
// Photon RGB values are stored as 00 RR GG BB
// nscolor RGB values are 00 BB GG RR
#define NS_TO_PH_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff)
#define PH_TO_NS_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff)
class nsRenderingContextPh : public nsRenderingContextImpl
{
public:
@ -68,86 +74,208 @@ public:
NS_DECL_ISUPPORTS
NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWindow);
NS_IMETHOD Init(nsIDeviceContext* aContext, nsDrawingSurface aSurface);
inline
NS_IMETHODIMP Init(nsIDeviceContext* aContext, nsDrawingSurface aSurface)
{
mContext = aContext;
NS_IF_ADDREF(mContext);
mSurface = (nsDrawingSurfacePh *) aSurface;
NS_ADDREF(mSurface);
mGC = mSurface->GetGC();
mOwner = PR_FALSE;
return CommonInit();
}
inline NS_IMETHODIMP Reset(void) { return NS_OK; }
NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext);
inline
NS_IMETHODIMP GetDeviceContext(nsIDeviceContext *&aContext)
{ NS_IF_ADDREF( mContext );
aContext = mContext;
return NS_OK;
}
NS_IMETHOD LockDrawingSurface(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
inline
NS_IMETHODIMP LockDrawingSurface(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
PRUint32 aFlags);
NS_IMETHOD UnlockDrawingSurface(void);
PRUint32 aFlags)
{
PushState();
return mSurface->Lock( aX, aY, aWidth, aHeight, aBits, aStride, aWidthBytes, aFlags );
}
inline
NS_IMETHODIMP UnlockDrawingSurface(void)
{ PRBool clipstate;
PopState( clipstate );
mSurface->Unlock();
return NS_OK;
}
NS_IMETHOD SelectOffScreenDrawingSurface(nsDrawingSurface aSurface);
NS_IMETHOD GetDrawingSurface(nsDrawingSurface *aSurface);
NS_IMETHOD GetHints(PRUint32& aResult);
inline
NS_IMETHODIMP SelectOffScreenDrawingSurface(nsDrawingSurface aSurface)
{ mSurface = nsnull==aSurface ? mOffscreenSurface : (nsDrawingSurfacePh *) aSurface;
mSurface->Select( );
return NS_OK;
}
inline
NS_IMETHODIMP GetDrawingSurface(nsDrawingSurface *aSurface) { *aSurface = (void *) mSurface; return NS_OK; }
inline
NS_IMETHODIMP GetHints(PRUint32& aResult)
{ /* this flag indicates that the system prefers 8bit chars over wide chars */
/* It may or may not be faster under photon... */
aResult = NS_RENDERING_HINT_FAST_8BIT_TEXT;
return NS_OK;
}
NS_IMETHOD PushState(void);
NS_IMETHOD PopState(PRBool &aClipState);
NS_IMETHOD IsVisibleRect(const nsRect& aRect, PRBool &aClipState);
inline
NS_IMETHODIMP IsVisibleRect( const nsRect& aRect, PRBool &aVisible )
{ aVisible = PR_TRUE;
return NS_OK;
}
NS_IMETHOD SetClipRect(const nsRect& aRect, nsClipCombine aCombine, PRBool &aCilpState);
NS_IMETHOD GetClipRect(nsRect &aRect, PRBool &aClipState);
NS_IMETHOD SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine, PRBool &aClipState);
NS_IMETHOD CopyClipRegion(nsIRegion &aRegion);
inline
NS_IMETHODIMP CopyClipRegion(nsIRegion &aRegion)
{ if( !mClipRegion ) return NS_ERROR_FAILURE;
aRegion.SetTo(*NS_STATIC_CAST(nsIRegion*, mClipRegion));
return NS_OK;
}
NS_IMETHOD GetClipRegion(nsIRegion **aRegion);
NS_IMETHOD SetLineStyle(nsLineStyle aLineStyle);
NS_IMETHOD GetLineStyle(nsLineStyle &aLineStyle);
inline
NS_IMETHODIMP GetLineStyle(nsLineStyle &aLineStyle)
{ aLineStyle = mCurrentLineStyle;
return NS_OK;
}
NS_IMETHOD SetColor(nscolor aColor);
NS_IMETHOD GetColor(nscolor &aColor) const;
inline
NS_IMETHODIMP SetColor(nscolor aColor) { mCurrentColor = aColor; return NS_OK; }
inline
NS_IMETHODIMP GetColor(nscolor &aColor) const { aColor = mCurrentColor; return NS_OK; }
NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup);
inline
NS_IMETHODIMP SetFont(const nsFont& aFont, nsIAtom* aLangGroup)
{ nsIFontMetrics* newMetrics;
nsresult rv = mContext->GetMetricsFor( aFont, aLangGroup, newMetrics );
if( NS_SUCCEEDED( rv ) ) {
rv = SetFont( newMetrics );
NS_RELEASE( newMetrics );
}
return rv;
}
NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);
inline
NS_IMETHODIMP GetFontMetrics(nsIFontMetrics *&aFontMetrics)
{ NS_IF_ADDREF(mFontMetrics);
aFontMetrics = mFontMetrics;
return NS_OK;
}
NS_IMETHOD Translate(nscoord aX, nscoord aY);
NS_IMETHOD Scale(float aSx, float aSy);
NS_IMETHOD GetCurrentTransform(nsTransform2D *&aTransform);
inline
NS_IMETHODIMP Translate(nscoord aX, nscoord aY) { mTranMatrix->AddTranslation((float)aX,(float)aY); return NS_OK; }
inline
NS_IMETHODIMP Scale(float aSx, float aSy) { mTranMatrix->AddScale(aSx, aSy); return NS_OK; }
inline
NS_IMETHODIMP GetCurrentTransform(nsTransform2D *&aTransform) { aTransform = mTranMatrix; return NS_OK; }
NS_IMETHOD CreateDrawingSurface(const nsRect &aBounds, PRUint32 aSurfFlags, nsDrawingSurface &aSurface);
NS_IMETHOD DestroyDrawingSurface(nsDrawingSurface aDS);
inline
NS_IMETHODIMP DestroyDrawingSurface(nsDrawingSurface aDS)
{ nsDrawingSurfacePh *surf = (nsDrawingSurfacePh *) aDS;
NS_IF_RELEASE(surf);
return NS_OK;
}
NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
NS_IMETHOD DrawStdLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
NS_IMETHOD DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints);
inline
NS_IMETHODIMP DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints) { return DrawPolygon( aPoints, aNumPoints ); }
NS_IMETHOD DrawRect(const nsRect& aRect);
inline
NS_IMETHODIMP DrawRect(const nsRect& aRect) { return DrawRect( aRect.x, aRect.y, aRect.width, aRect.height ); }
NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
NS_IMETHOD FillRect(const nsRect& aRect);
inline
NS_IMETHODIMP FillRect(const nsRect& aRect) { return FillRect( aRect.x, aRect.y, aRect.width, aRect.height ); }
NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
NS_IMETHOD InvertRect(const nsRect& aRect);
inline
NS_IMETHODIMP InvertRect(const nsRect& aRect) { return InvertRect( aRect.x, aRect.y, aRect.width, aRect.height ); }
NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
NS_IMETHOD DrawEllipse(const nsRect& aRect);
inline
NS_IMETHODIMP DrawEllipse(const nsRect& aRect) { return DrawEllipse( aRect.x, aRect.y, aRect.width, aRect.height ); }
NS_IMETHOD DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
NS_IMETHOD FillEllipse(const nsRect& aRect);
inline
NS_IMETHODIMP FillEllipse(const nsRect& aRect) { return FillEllipse( aRect.x, aRect.y, aRect.width, aRect.height ); }
NS_IMETHOD FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
NS_IMETHOD DrawArc(const nsRect& aRect,
float aStartAngle, float aEndAngle);
inline
NS_IMETHODIMP DrawArc(const nsRect& aRect, float aStartAngle, float aEndAngle) { return DrawArc(aRect.x,aRect.y,aRect.width,aRect.height,aStartAngle,aEndAngle); }
NS_IMETHOD DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
float aStartAngle, float aEndAngle);
NS_IMETHOD FillArc(const nsRect& aRect,
float aStartAngle, float aEndAngle);
inline
NS_IMETHODIMP FillArc(const nsRect& aRect, float aStartAngle, float aEndAngle) { return FillArc(aRect.x,aRect.y,aRect.width,aRect.height,aStartAngle,aEndAngle); }
NS_IMETHOD FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
float aStartAngle, float aEndAngle);
NS_IMETHOD GetWidth(char aC, nscoord& aWidth);
NS_IMETHOD GetWidth(PRUnichar aC, nscoord& aWidth,
PRInt32 *aFontID);
NS_IMETHOD GetWidth(const nsString& aString, nscoord& aWidth,
PRInt32 *aFontID);
NS_IMETHOD GetWidth(const char* aString, nscoord& aWidth);
inline
NS_IMETHODIMP GetWidth(char aC, nscoord& aWidth)
{ // Check for the very common case of trying to get the width of a single space
if(aC == ' ' && nsnull != mFontMetrics )
return mFontMetrics->GetSpaceWidth(aWidth);
return GetWidth( &aC, 1, aWidth );
}
inline
NS_IMETHODIMP GetWidth(PRUnichar aC, nscoord& aWidth, PRInt32 *aFontID)
{ /* turn it into a string */
PRUnichar buf[2];
buf[0] = aC;
buf[1] = nsnull;
return GetWidth( buf, 1, aWidth, aFontID );
}
inline
NS_IMETHODIMP GetWidth(const nsString& aString, nscoord& aWidth, PRInt32 *aFontID) { return GetWidth( aString.get(), aString.Length(), aWidth, aFontID ); }
inline
NS_IMETHODIMP GetWidth(const char* aString, nscoord& aWidth) { return GetWidth( aString, strlen( aString ), aWidth ); }
NS_IMETHOD GetWidth(const char* aString, PRUint32 aLength, nscoord& aWidth);
NS_IMETHOD GetWidth(const PRUnichar* aString, PRUint32 aLength,
nscoord& aWidth, PRInt32 *aFontID);
@ -155,22 +283,63 @@ public:
NS_IMETHOD DrawString(const char *aString, PRUint32 aLength,
nscoord aX, nscoord aY,
const nscoord* aSpacing);
NS_IMETHOD DrawString(const PRUnichar *aString, PRUint32 aLength,
inline
NS_IMETHODIMP DrawString(const PRUnichar *aString, PRUint32 aLength,
nscoord aX, nscoord aY,
PRInt32 aFontID,
const nscoord* aSpacing);
NS_IMETHOD DrawString(const nsString& aString, nscoord aX, nscoord aY,
PRInt32 aFontID,
const nscoord* aSpacing);
NS_IMETHOD GetTextDimensions(const char* aString, PRUint32 aLength,
nsTextDimensions& aDimensions);
const nscoord* aSpacing)
{
NS_ConvertUCS2toUTF8 theUnicodeString( aString, aLength );
const char *p = theUnicodeString.get( );
return DrawString( p, strlen( p ), aX, aY, aSpacing );
}
inline
NS_IMETHODIMP DrawString(const nsString& aString, nscoord aX, nscoord aY, PRInt32 aFontID, const nscoord* aSpacing)
{
NS_ConvertUCS2toUTF8 theUnicodeString( aString.get(), aString.Length() );
const char *p = theUnicodeString.get();
return DrawString( p, strlen( p ), aX, aY, aSpacing );
}
inline
NS_IMETHODIMP GetTextDimensions(const char* aString, PRUint32 aLength, nsTextDimensions& aDimensions)
{
aDimensions.Clear();
mFontMetrics->GetMaxAscent(aDimensions.ascent);
mFontMetrics->GetMaxDescent(aDimensions.descent);
return GetWidth(aString, aLength, aDimensions.width);
}
NS_IMETHOD GetTextDimensions(const PRUnichar *aString, PRUint32 aLength,
nsTextDimensions& aDimensions, PRInt32 *aFontID);
NS_IMETHOD DrawImage(nsIImage *aImage, nscoord aX, nscoord aY);
NS_IMETHOD DrawImage(nsIImage *aImage, nscoord aX, nscoord aY,
nscoord aWidth, nscoord aHeight);
NS_IMETHOD DrawImage(nsIImage *aImage, const nsRect& aRect);
inline
NS_IMETHODIMP DrawImage(nsIImage *aImage, nscoord aX, nscoord aY)
{
// we have to do this here because we are doing a transform below
return DrawImage( aImage, aX, aY,
NSToCoordRound(mP2T * aImage->GetWidth()),
NSToCoordRound(mP2T * aImage->GetHeight())
);
}
inline
NS_IMETHODIMP DrawImage(nsIImage *aImage, nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
{
nscoord x, y, w, h;
x = aX;
y = aY;
w = aWidth;
h = aHeight;
mTranMatrix->TransformCoord(&x, &y, &w, &h);
return (aImage->Draw(*this, mSurface, x, y, w, h));
}
inline
NS_IMETHODIMP DrawImage(nsIImage *aImage, const nsRect& aRect) { return DrawImage( aImage, aRect.x, aRect.y, aRect.width, aRect.height ); }
NS_IMETHOD DrawImage(nsIImage *aImage, const nsRect& aSRect, const nsRect& aDRect);
NS_IMETHOD DrawTile(nsIImage *aImage,nscoord aX0,nscoord aY0,nscoord aX1,nscoord aY1,
nscoord aWidth,nscoord aHeight);
@ -179,7 +348,13 @@ public:
NS_IMETHOD CopyOffScreenBits(nsDrawingSurface aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY,
const nsRect &aDestBounds, PRUint32 aCopyFlags);
NS_IMETHOD RetrieveCurrentNativeGraphicData(PRUint32 * ngd);
inline
NS_IMETHODIMP RetrieveCurrentNativeGraphicData(PRUint32 * ngd)
{
if( ngd != nsnull ) *ngd = nsnull;
return NS_OK;
}
#ifdef MOZ_MATHML
/**
@ -202,10 +377,28 @@ public:
private:
NS_IMETHOD CommonInit();
inline NS_IMETHODIMP CommonInit()
{
if( mContext && mTranMatrix ) {
mContext->GetDevUnitsToAppUnits(mP2T);
float app2dev;
mContext->GetAppUnitsToDevUnits(app2dev);
mTranMatrix->AddScale(app2dev, app2dev);
}
return NS_OK;
}
void ApplyClipping( PhGC_t * );
void CreateClipRegion( );
void UpdateGC( );
inline void UpdateGC( )
{
PgSetGC( mGC ); /* new */
PgSetStrokeColor( NS_TO_PH_RGB( mCurrentColor ) );
PgSetTextColor( NS_TO_PH_RGB( mCurrentColor ) );
PgSetFillColor( NS_TO_PH_RGB( mCurrentColor ) );
PgSetStrokeDash( mLineStyle, strlen((char *)mLineStyle), 0x10000 );
ApplyClipping( mGC );
}
PhGC_t *mGC;
nscolor mCurrentColor;