This commit is contained in:
pavlov%pavlov.net 1999-04-18 19:31:16 +00:00
Родитель cb26e15abc
Коммит bd72acdf48
4 изменённых файлов: 176 добавлений и 186 удалений

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

@ -29,6 +29,8 @@
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#define NS_TO_GDK_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff)
#define GDK_COLOR_TO_NS_RGB(c) \
((nscolor) NS_RGB(c.red, c.green, c.blue))
@ -251,17 +253,18 @@ NS_IMETHODIMP nsDeviceContextGTK::GetSystemAttribute(nsSystemAttrID anID, System
//---------
// Fonts
//---------
case eSystemAttr_Font_Caption :
case eSystemAttr_Font_Icon :
case eSystemAttr_Font_Menu :
case eSystemAttr_Font_MessageBox :
case eSystemAttr_Font_SmallCaption :
case eSystemAttr_Font_StatusBar :
case eSystemAttr_Font_Tooltips :
case eSystemAttr_Font_Widget :
case eSystemAttr_Font_Caption:
case eSystemAttr_Font_Icon:
case eSystemAttr_Font_Menu:
case eSystemAttr_Font_MessageBox:
case eSystemAttr_Font_SmallCaption:
case eSystemAttr_Font_StatusBar:
case eSystemAttr_Font_Tooltips:
case eSystemAttr_Font_Widget:
status = NS_ERROR_FAILURE;
break;
} // switch
} // switch
gtk_style_unref(style);
return NS_OK;
@ -277,9 +280,7 @@ NS_IMETHODIMP nsDeviceContextGTK::GetDrawingSurface(nsIRenderingContext &aContex
NS_IMETHODIMP nsDeviceContextGTK::ConvertPixel(nscolor aColor,
PRUint32 & aPixel)
{
aPixel = ::gdk_rgb_xpixel_from_rgb ((aColor & 0xff) << 16 |
(aColor & 0xff00) |
((aColor >> 16) & 0xff));
aPixel = ::gdk_rgb_xpixel_from_rgb (NS_TO_GDK_RGB(aColor));
return NS_OK;
}

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

@ -26,8 +26,6 @@
#define IsFlagSet(a,b) (a & b)
#undef CHEAP_PERFORMANCE_MEASUREMENT
// Defining this will trace the allocation of images. This includes
// ctor, dtor and update.
#undef TRACE_IMAGE_ALLOCATION
@ -71,8 +69,8 @@ nsImageGTK::~nsImageGTK()
}
if (nsnull != mImagePixmap) {
gdk_pixmap_unref(mImagePixmap);
}
gdk_pixmap_unref(mImagePixmap);
}
#ifdef TRACE_IMAGE_ALLOCATION
printf("nsImageGTK::~nsImageGTK(this=%p)\n",
@ -84,9 +82,8 @@ NS_IMPL_ISUPPORTS(nsImageGTK, kIImageIID);
//------------------------------------------------------------
nsresult
nsImageGTK::Init(PRInt32 aWidth, PRInt32 aHeight,
PRInt32 aDepth, nsMaskRequirements aMaskRequirements)
nsresult nsImageGTK::Init(PRInt32 aWidth, PRInt32 aHeight,
PRInt32 aDepth, nsMaskRequirements aMaskRequirements)
{
g_return_val_if_fail ((aWidth != 0) || (aHeight != 0), NS_ERROR_FAILURE);
@ -153,7 +150,7 @@ nsresult
// 32-bit align each row
mAlphaRowBytes = (mAlphaRowBytes + 3) & ~0x3;
mAlphaBits = new unsigned char[mAlphaRowBytes * aHeight];
mAlphaBits = new PRUint8[mAlphaRowBytes * aHeight];
mAlphaWidth = aWidth;
mAlphaHeight = aHeight;
break;
@ -162,6 +159,7 @@ nsresult
mAlphaBits = nsnull;
mAlphaWidth = 0;
mAlphaHeight = 0;
mAlphaDepth = 8;
g_print("TODO: want an 8bit mask for an image..\n");
break;
}
@ -171,103 +169,7 @@ nsresult
//------------------------------------------------------------
void nsImageGTK::ComputMetrics()
{
mRowBytes = CalcBytesSpan(mWidth);
mSizeImage = mRowBytes * mHeight;
}
PRInt32
nsImageGTK::GetHeight()
{
return mHeight;
}
PRInt32
nsImageGTK::GetWidth()
{
return mWidth;
}
PRUint8*
nsImageGTK::GetBits()
{
return mImageBits;
}
void*
nsImageGTK::GetBitInfo()
{
return nsnull;
}
PRInt32
nsImageGTK::GetLineStride()
{
return mRowBytes;
}
nsColorMap*
nsImageGTK::GetColorMap()
{
return nsnull;
}
PRBool
nsImageGTK::IsOptimized()
{
return PR_TRUE;
}
PRUint8*
nsImageGTK::GetAlphaBits()
{
return mAlphaBits;
}
PRInt32
nsImageGTK::GetAlphaWidth()
{
return mAlphaWidth;
}
PRInt32
nsImageGTK::GetAlphaHeight()
{
return mAlphaHeight;
}
PRInt32
nsImageGTK::GetAlphaLineStride()
{
return mAlphaRowBytes;
}
nsIImage*
nsImageGTK::DuplicateImage()
{
return nsnull;
}
void
nsImageGTK::SetAlphaLevel(PRInt32 aAlphaLevel)
{
}
PRInt32
nsImageGTK::GetAlphaLevel()
{
return 0;
}
void
nsImageGTK::MoveAlphaMask(PRInt32 aX, PRInt32 aY)
{
}
//------------------------------------------------------------
PRInt32 nsImageGTK::CalcBytesSpan(PRUint32 aWidth)
PRInt32 nsImageGTK::CalcBytesSpan(PRUint32 aWidth)
{
PRInt32 spanbytes;
@ -279,13 +181,92 @@ PRInt32 nsImageGTK::CalcBytesSpan(PRUint32 aWidth)
return(spanbytes);
}
void nsImageGTK::ComputMetrics()
{
mRowBytes = CalcBytesSpan(mWidth);
mSizeImage = mRowBytes * mHeight;
}
PRInt32 nsImageGTK::GetHeight()
{
return mHeight;
}
PRInt32 nsImageGTK::GetWidth()
{
return mWidth;
}
PRUint8 *nsImageGTK::GetBits()
{
return mImageBits;
}
void *nsImageGTK::GetBitInfo()
{
return nsnull;
}
PRInt32 nsImageGTK::GetLineStride()
{
return mRowBytes;
}
nsColorMap *nsImageGTK::GetColorMap()
{
return nsnull;
}
PRBool nsImageGTK::IsOptimized()
{
return PR_TRUE;
}
PRUint8 *nsImageGTK::GetAlphaBits()
{
return mAlphaBits;
}
PRInt32 nsImageGTK::GetAlphaWidth()
{
return mAlphaWidth;
}
PRInt32 nsImageGTK::GetAlphaHeight()
{
return mAlphaHeight;
}
PRInt32
nsImageGTK::GetAlphaLineStride()
{
return mAlphaRowBytes;
}
nsIImage *nsImageGTK::DuplicateImage()
{
return nsnull;
}
void nsImageGTK::SetAlphaLevel(PRInt32 aAlphaLevel)
{
}
PRInt32 nsImageGTK::GetAlphaLevel()
{
return 0;
}
void nsImageGTK::MoveAlphaMask(PRInt32 aX, PRInt32 aY)
{
}
//------------------------------------------------------------
// set up the palette to the passed in color array, RGB only in this array
void
nsImageGTK::ImageUpdated(nsIDeviceContext *aContext,
PRUint8 aFlags,
nsRect *aUpdateRect)
void nsImageGTK::ImageUpdated(nsIDeviceContext *aContext,
PRUint8 aFlags,
nsRect *aUpdateRect)
{
#ifdef TRACE_IMAGE_ALLOCATION
printf("nsImageGTK::ImageUpdated(this=%p,%d)\n",
@ -309,10 +290,6 @@ nsImageGTK::ImageUpdated(nsIDeviceContext *aContext,
}
}
#ifdef CHEAP_PERFORMANCE_MEASUREMENT
static PRTime gConvertTime, gStartTime, gPixmapTime, gEndTime;
#endif
// Draw the bitmap, this method has a source and destination coordinates
NS_IMETHODIMP
nsImageGTK::Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface,
@ -370,10 +347,6 @@ nsImageGTK::Draw(nsIRenderingContext &aContext,
GC gc;
XGCValues gcv;
#ifdef CHEAP_PERFORMANCE_MEASUREMENT
gStartTime = gPixmapTime = PR_Now();
#endif
// Create gc clip-mask on demand
if ((mAlphaBits != nsnull) && (nsnull == mAlphaPixmap))
{
@ -430,11 +403,23 @@ nsImageGTK::Draw(nsIRenderingContext &aContext,
x_image->data = 0; /* Don't free the IL_Pixmap's bits. */
XDestroyImage(x_image);
#ifdef CHEAP_PERFORMANCE_MEASUREMENT
gPixmapTime = PR_Now();
#endif
}
#if 0
// this code doesn't work right. leaving here for future reference.
if ((mAlphaBits != nsnull) && (nsnull == mAlphaPixmap))
{
GdkImage *img;
GdkGC *gc;
mAlphaPixmap = gdk_pixmap_new(nsnull, aWidth, aHeight, 1);
gc = gdk_gc_new(mAlphaPixmap);
gdk_gc_set_function(gc, GDK_COPY);
img = gdk_image_new_bitmap(gdk_rgb_get_visual(), mAlphaBits, aWidth, aHeight);
gdk_draw_image(mAlphaPixmap,gc,img,0,0,0,0,aWidth,aHeight);
gdk_image_destroy(img);
gdk_gc_unref(gc);
}
#endif
// Render unique image bits onto an off screen pixmap only once
// The image bits can change as a result of ImageUpdated() - for
// example: animated GIFs.
@ -448,11 +433,10 @@ nsImageGTK::Draw(nsIRenderingContext &aContext,
mDepth);
#endif
GdkVisual * rgb_visual = gdk_rgb_get_visual();
gint rgb_depth = rgb_visual->depth;
// Create an off screen pixmap to hold the image bits.
mImagePixmap = gdk_pixmap_new(nsnull, aWidth, aHeight, rgb_depth);
mImagePixmap = gdk_pixmap_new(nsnull,
aWidth, aHeight,
gdk_rgb_get_visual()->depth);
// Make sure the clip region is clear, since we are rendering the
// image bits to an off screen pixmap and this always happens at the
@ -484,16 +468,17 @@ nsImageGTK::Draw(nsIRenderingContext &aContext,
aHeight);
#endif
// Draw the image pixmap onto the drawing surface
gdk_draw_pixmap(drawing->GetDrawable(), // drawable
drawing->GetGC(), // gc
mImagePixmap, // src
0, // xsrc
0, // ysrc
aX, // xdest
aY, // ydest
aWidth, // width
aHeight); // height
// copy our off screen pixmap onto the window.
gdk_window_copy_area(drawing->GetDrawable(), // dest window
drawing->GetGC(), // gc
aX, // xsrc
aY, // ysrc
mImagePixmap, // source window
0, // xdest
0, // ydest
aWidth, // width
aHeight); // height
if (mAlphaPixmap != nsnull)
{
@ -502,17 +487,6 @@ nsImageGTK::Draw(nsIRenderingContext &aContext,
gdk_gc_set_clip_mask(drawing->GetGC(), nsnull);
}
#ifdef CHEAP_PERFORMANCE_MEASUREMENT
gEndTime = PR_Now();
printf("nsImageGTK::Draw(this=%p,w=%d,h=%d) total=%lld pixmap=%lld, cvt=%lld\n",
this,
aWidth, aHeight,
gEndTime - gStartTime,
gPixmapTime - gStartTime,
gConvertTime - gPixmapTime);
#endif
return NS_OK;
}

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

@ -269,7 +269,7 @@ NS_IMETHODIMP nsRegionGTK::GetRegionComplexity(nsRegionComplexity &aComplexity)
if (((nsRegionGTK*)this)->IsEmpty())
aComplexity = eRegionComplexity_empty;
else
aComplexity = eRegionComplexity_rect;
aComplexity = eRegionComplexity_complex;
return NS_OK;
}

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

@ -25,6 +25,7 @@
#define NS_TO_GDK_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff)
#define NSRECT_TO_GDKRECT(ns,gdk) \
PR_BEGIN_MACRO \
gdk.x = ns.x; \
@ -711,6 +712,8 @@ NS_IMETHODIMP nsRenderingContextGTK::DrawRect(nscoord aX, nscoord aY, nscoord aW
mTMatrix->TransformCoord(&x,&y,&w,&h);
// FIXME why are we drawign this 1 pixel less than we should be?
::gdk_draw_rectangle(mSurface->GetDrawable(), mSurface->GetGC(),
FALSE,
x, y,
@ -1337,50 +1340,63 @@ nsRenderingContextGTK::DrawString(const nsString& aString,
aX, aY, aFontID, aSpacing);
}
NS_IMETHODIMP nsRenderingContextGTK::DrawImage(nsIImage *aImage, nscoord aX, nscoord aY)
NS_IMETHODIMP nsRenderingContextGTK::DrawImage(nsIImage *aImage,
nscoord aX, nscoord aY)
{
nscoord width,height;
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 nsRenderingContextGTK::DrawImage(nsIImage *aImage, nscoord aX, nscoord aY,
nscoord aWidth, nscoord aHeight)
{
nsRect tr;
tr.x = aX;
tr.y = aY;
tr.width = aWidth;
tr.height = aHeight;
return DrawImage(aImage,tr);
return DrawImage(aImage, aX, aY, width, height);
}
NS_IMETHODIMP nsRenderingContextGTK::DrawImage(nsIImage *aImage, const nsRect& aRect)
{
nsRect tr;
tr = aRect;
mTMatrix->TransformCoord(&tr.x,&tr.y,&tr.width,&tr.height);
return aImage->Draw(*this,mSurface,tr.x,tr.y,tr.width,tr.height);
return DrawImage(aImage,
aRect.x,
aRect.y,
aRect.width,
aRect.height);
}
NS_IMETHODIMP nsRenderingContextGTK::DrawImage(nsIImage *aImage, const nsRect& aSRect, const nsRect& aDRect)
NS_IMETHODIMP nsRenderingContextGTK::DrawImage(nsIImage *aImage,
nscoord aX, nscoord aY,
nscoord aWidth, nscoord aHeight)
{
nscoord x, y, w, h;
x = aX;
y = aY;
w = aWidth;
h = aHeight;
mTMatrix->TransformCoord(&x, &y, &w, &h);
return aImage->Draw(*this, mSurface,
x, y, w, h);
}
NS_IMETHODIMP nsRenderingContextGTK::DrawImage(nsIImage *aImage,
const nsRect& aSRect,
const nsRect& aDRect)
{
nsRect sr,dr;
sr = aSRect;
mTMatrix ->TransformCoord(&sr.x,&sr.y,&sr.width,&sr.height);
mTMatrix->TransformCoord(&sr.x, &sr.y,
&sr.width, &sr.height);
dr = aDRect;
mTMatrix->TransformCoord(&dr.x,&dr.y,&dr.width,&dr.height);
mTMatrix->TransformCoord(&dr.x, &dr.y,
&dr.width, &dr.height);
return aImage->Draw(*this,mSurface,sr.x,sr.y,sr.width,sr.height,
dr.x,dr.y,dr.width,dr.height);
return aImage->Draw(*this, mSurface,
sr.x, sr.y,
sr.width, sr.height,
dr.x, dr.y,
dr.width, dr.height);
}
NS_IMETHODIMP
@ -1433,7 +1449,6 @@ nsRenderingContextGTK::CopyOffScreenBits(nsDrawingSurface aSrcSurf,
//XXX flags are unused. that would seem to mean that there is
//inefficiency somewhere... MMP
// gdk_draw_pixmap and copy_area do the same thing internally.
// copy_area sounds better
::gdk_window_copy_area(destsurf->GetDrawable(),