mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-21 09:49:14 +00:00
Derived nsDeviceContextUnix from nsDeviceContextImpl and removed redudant
methods + fields.
This commit is contained in:
parent
6e577d6fb5
commit
387bd846ea
@ -37,54 +37,29 @@ static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID);
|
||||
|
||||
nsDeviceContextUnix :: nsDeviceContextUnix()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
mFontCache = nsnull;
|
||||
mSurface = nsnull;
|
||||
|
||||
mTwipsToPixels = 1.0;
|
||||
mPixelsToTwips = 1.0;
|
||||
|
||||
mDevUnitsToAppUnits = 1.0f;
|
||||
mAppUnitsToDevUnits = 1.0f;
|
||||
|
||||
mGammaValue = 1.0f;
|
||||
mGammaTable = new PRUint8[256];
|
||||
|
||||
mZoom = 1.0f;
|
||||
|
||||
mVisual = nsnull;
|
||||
|
||||
mRedMask = 0;
|
||||
mGreenMask = 0;
|
||||
mBlueMask = 0;
|
||||
|
||||
mRedBits = 0;
|
||||
mGreenBits = 0;
|
||||
mBlueBits = 0;
|
||||
|
||||
mRedOffset = 0;
|
||||
mGreenOffset = 0;
|
||||
mBlueOffset = 0;
|
||||
|
||||
mNativeWidget = nsnull;
|
||||
|
||||
mDepth = 0 ;
|
||||
mColormap = 0 ;
|
||||
}
|
||||
|
||||
nsDeviceContextUnix :: ~nsDeviceContextUnix()
|
||||
{
|
||||
|
||||
if (nsnull != mGammaTable)
|
||||
{
|
||||
delete mGammaTable;
|
||||
mGammaTable = nsnull;
|
||||
if (mSurface) {
|
||||
delete mSurface;
|
||||
mSurface = nsnull;
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(mFontCache);
|
||||
|
||||
if (mSurface) delete mSurface;
|
||||
}
|
||||
|
||||
NS_IMPL_QUERY_INTERFACE(nsDeviceContextUnix, kDeviceContextIID)
|
||||
@ -101,12 +76,12 @@ nsresult nsDeviceContextUnix :: Init(nsNativeWidget aNativeWidget)
|
||||
// XXX We really need to have Display passed to us since it could be specified
|
||||
// not from the environment, which is the one we use here.
|
||||
|
||||
mNativeWidget = aNativeWidget;
|
||||
mWidget = aNativeWidget;
|
||||
|
||||
if (nsnull != mNativeWidget)
|
||||
if (nsnull != mWidget)
|
||||
{
|
||||
mTwipsToPixels = (((float)::XDisplayWidth(XtDisplay((Widget)mNativeWidget), DefaultScreen(XtDisplay((Widget)mNativeWidget)))) /
|
||||
((float)::XDisplayWidthMM(XtDisplay((Widget)mNativeWidget),DefaultScreen(XtDisplay((Widget)mNativeWidget)) )) * 25.4) /
|
||||
mTwipsToPixels = (((float)::XDisplayWidth(XtDisplay((Widget)mWidget), DefaultScreen(XtDisplay((Widget)mWidget)))) /
|
||||
((float)::XDisplayWidthMM(XtDisplay((Widget)mWidget),DefaultScreen(XtDisplay((Widget)mWidget)) )) * 25.4) /
|
||||
(float)NSIntPointsToTwips(72);
|
||||
|
||||
mPixelsToTwips = 1.0f / mTwipsToPixels;
|
||||
@ -115,36 +90,6 @@ nsresult nsDeviceContextUnix :: Init(nsNativeWidget aNativeWidget)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
float nsDeviceContextUnix :: GetTwipsToDevUnits() const
|
||||
{
|
||||
return mTwipsToPixels;
|
||||
}
|
||||
|
||||
float nsDeviceContextUnix :: GetDevUnitsToTwips() const
|
||||
{
|
||||
return mPixelsToTwips;
|
||||
}
|
||||
|
||||
|
||||
void nsDeviceContextUnix :: SetAppUnitsToDevUnits(float aAppUnits)
|
||||
{
|
||||
mAppUnitsToDevUnits = aAppUnits;
|
||||
}
|
||||
|
||||
void nsDeviceContextUnix :: SetDevUnitsToAppUnits(float aDevUnits)
|
||||
{
|
||||
mDevUnitsToAppUnits = aDevUnits;
|
||||
}
|
||||
|
||||
float nsDeviceContextUnix :: GetAppUnitsToDevUnits() const
|
||||
{
|
||||
return mAppUnitsToDevUnits;
|
||||
}
|
||||
|
||||
float nsDeviceContextUnix :: GetDevUnitsToAppUnits() const
|
||||
{
|
||||
return mDevUnitsToAppUnits;
|
||||
}
|
||||
|
||||
float nsDeviceContextUnix :: GetScrollBarWidth() const
|
||||
{
|
||||
@ -158,125 +103,12 @@ float nsDeviceContextUnix :: GetScrollBarHeight() const
|
||||
return 240.0;
|
||||
}
|
||||
|
||||
nsIRenderingContext * nsDeviceContextUnix :: CreateRenderingContext(nsIView *aView)
|
||||
{
|
||||
nsIRenderingContext *pContext = nsnull;
|
||||
nsIWidget *win = aView->GetWidget();
|
||||
nsresult rv;
|
||||
|
||||
static NS_DEFINE_IID(kRCCID, NS_RENDERING_CONTEXT_CID);
|
||||
static NS_DEFINE_IID(kRCIID, NS_IRENDERING_CONTEXT_IID);
|
||||
|
||||
rv = NSRepository::CreateInstance(kRCCID, nsnull, kRCIID, (void **)&pContext);
|
||||
|
||||
if (NS_OK == rv) {
|
||||
rv = InitRenderingContext(pContext, win);
|
||||
if (NS_OK != rv) {
|
||||
NS_RELEASE(pContext);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(win);
|
||||
return pContext;
|
||||
}
|
||||
|
||||
nsresult nsDeviceContextUnix :: InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWin)
|
||||
{
|
||||
return (aContext->Init(this, aWin));
|
||||
}
|
||||
|
||||
nsIFontCache* nsDeviceContextUnix::GetFontCache()
|
||||
{
|
||||
if (nsnull == mFontCache) {
|
||||
if (NS_OK != CreateFontCache()) {
|
||||
return nsnull;
|
||||
}
|
||||
}
|
||||
NS_ADDREF(mFontCache);
|
||||
return mFontCache;
|
||||
}
|
||||
|
||||
nsresult nsDeviceContextUnix::CreateFontCache()
|
||||
{
|
||||
nsresult rv = NS_NewFontCache(&mFontCache);
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
mFontCache->Init(this);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsDeviceContextUnix::FlushFontCache()
|
||||
{
|
||||
NS_RELEASE(mFontCache);
|
||||
}
|
||||
|
||||
|
||||
nsIFontMetrics* nsDeviceContextUnix::GetMetricsFor(const nsFont& aFont)
|
||||
{
|
||||
if (nsnull == mFontCache) {
|
||||
if (NS_OK != CreateFontCache()) {
|
||||
return nsnull;
|
||||
}
|
||||
}
|
||||
return mFontCache->GetMetricsFor(aFont);
|
||||
}
|
||||
|
||||
void nsDeviceContextUnix :: SetZoom(float aZoom)
|
||||
{
|
||||
mZoom = aZoom;
|
||||
}
|
||||
|
||||
float nsDeviceContextUnix :: GetZoom() const
|
||||
{
|
||||
return mZoom;
|
||||
}
|
||||
|
||||
nsDrawingSurface nsDeviceContextUnix :: GetDrawingSurface(nsIRenderingContext &aContext)
|
||||
{
|
||||
return aContext.CreateDrawingSurface(nsnull);
|
||||
}
|
||||
|
||||
float nsDeviceContextUnix :: GetGamma(void)
|
||||
{
|
||||
return mGammaValue;
|
||||
}
|
||||
|
||||
void nsDeviceContextUnix :: SetGamma(float aGamma)
|
||||
{
|
||||
if (aGamma != mGammaValue)
|
||||
{
|
||||
//we don't need to-recorrect existing images for this case
|
||||
//so pass in 1.0 for the current gamma regardless of what it
|
||||
//really happens to be. existing images will get a one time
|
||||
//re-correction when they're rendered the next time. MMP
|
||||
|
||||
SetGammaTable(mGammaTable, 1.0f, aGamma);
|
||||
|
||||
mGammaValue = aGamma;
|
||||
}
|
||||
}
|
||||
|
||||
PRUint8 * nsDeviceContextUnix :: GetGammaTable(void)
|
||||
{
|
||||
//XXX we really need to ref count this somehow. MMP
|
||||
|
||||
return mGammaTable;
|
||||
}
|
||||
|
||||
void nsDeviceContextUnix :: SetGammaTable(PRUint8 * aTable, float aCurrentGamma, float aNewGamma)
|
||||
{
|
||||
double fgval = (1.0f / aCurrentGamma) * (1.0f / aNewGamma);
|
||||
|
||||
for (PRInt32 cnt = 0; cnt < 256; cnt++)
|
||||
aTable[cnt] = (PRUint8)(pow((double)cnt * (1. / 256.), fgval) * 255.99999999);
|
||||
}
|
||||
|
||||
nsNativeWidget nsDeviceContextUnix :: GetNativeWidget(void)
|
||||
{
|
||||
return mNativeWidget;
|
||||
}
|
||||
|
||||
PRUint32 nsDeviceContextUnix :: ConvertPixel(nscolor aColor)
|
||||
{
|
||||
PRUint32 newcolor = 0;
|
||||
@ -513,12 +345,6 @@ nsDrawingSurface nsDeviceContextUnix :: GetDrawingSurface()
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextUnix :: LoadIconImage(PRInt32 aId, nsIImage*& aImage)
|
||||
{
|
||||
// XXX Unix should be using DeviceContextImpl...
|
||||
aImage = nsnull;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextUnix :: CheckFontExistence(const char * aFontName)
|
||||
{
|
||||
@ -556,25 +382,6 @@ NS_IMETHODIMP nsDeviceContextUnix :: CheckFontExistence(const char * aFontName)
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextUnix::CreateILColorSpace(IL_ColorSpace*& aColorSpace)
|
||||
{
|
||||
IL_RGBBits colorRGBBits;
|
||||
|
||||
// Default is to create a 24-bit color space
|
||||
colorRGBBits.red_shift = 16;
|
||||
colorRGBBits.red_bits = 8;
|
||||
colorRGBBits.green_shift = 8;
|
||||
colorRGBBits.green_bits = 8;
|
||||
colorRGBBits.blue_shift = 0;
|
||||
colorRGBBits.blue_bits = 8;
|
||||
|
||||
aColorSpace = IL_CreateTrueColorSpace(&colorRGBBits, 24);
|
||||
if (nsnull == aColorSpace) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef nsDeviceContextUnix_h___
|
||||
#define nsDeviceContextUnix_h___
|
||||
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsDeviceContext.h"
|
||||
#include "nsUnitConversion.h"
|
||||
#include "nsIFontCache.h"
|
||||
#include "nsIWidget.h"
|
||||
@ -48,62 +48,39 @@ struct nsDrawingSurfaceUnix {
|
||||
#endif
|
||||
};
|
||||
|
||||
class nsDeviceContextUnix : public nsIDeviceContext
|
||||
|
||||
class nsDeviceContextUnix : public DeviceContextImpl
|
||||
{
|
||||
public:
|
||||
nsDeviceContextUnix();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
//get a low level drawing surface for rendering. the rendering context
|
||||
//that is passed in is used to create the drawing surface if there isn't
|
||||
//already one in the device context. the drawing surface is then cached
|
||||
//in the device context for re-use.
|
||||
|
||||
// NS_IMETHOD CheckFontExistence(const char * aFontName);
|
||||
|
||||
// NS_IMETHOD CreateILColorSpace(IL_ColorSpace*& aColorSpace);
|
||||
|
||||
virtual nsresult Init(nsNativeWidget aNativeWidget);
|
||||
|
||||
virtual nsIRenderingContext * CreateRenderingContext(nsIView *aView);
|
||||
virtual nsresult InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWidget);
|
||||
|
||||
virtual float GetTwipsToDevUnits() const;
|
||||
virtual float GetDevUnitsToTwips() const;
|
||||
|
||||
virtual void SetAppUnitsToDevUnits(float aAppUnits);
|
||||
virtual void SetDevUnitsToAppUnits(float aDevUnits);
|
||||
|
||||
virtual float GetAppUnitsToDevUnits() const;
|
||||
virtual float GetDevUnitsToAppUnits() const;
|
||||
|
||||
virtual float GetScrollBarWidth() const;
|
||||
virtual float GetScrollBarHeight() const;
|
||||
|
||||
virtual nsIFontCache * GetFontCache();
|
||||
virtual void FlushFontCache();
|
||||
|
||||
virtual nsIFontMetrics* GetMetricsFor(const nsFont& aFont);
|
||||
|
||||
virtual void SetZoom(float aZoom);
|
||||
virtual float GetZoom() const;
|
||||
|
||||
virtual nsDrawingSurface GetDrawingSurface(nsIRenderingContext &aContext);
|
||||
|
||||
//functions for handling gamma correction of output device
|
||||
virtual float GetGamma(void);
|
||||
virtual void SetGamma(float aGamma);
|
||||
|
||||
//XXX the return from this really needs to be ref counted somehow. MMP
|
||||
virtual PRUint8 * GetGammaTable(void);
|
||||
|
||||
virtual nsNativeWidget GetNativeWidget(void);
|
||||
|
||||
virtual PRUint32 ConvertPixel(nscolor aColor);
|
||||
|
||||
NS_IMETHOD LoadIconImage(PRInt32 aId, nsIImage*& aImage);
|
||||
|
||||
NS_IMETHOD CheckFontExistence(const char * aFontName);
|
||||
|
||||
NS_IMETHOD CreateILColorSpace(IL_ColorSpace*& aColorSpace);
|
||||
|
||||
protected:
|
||||
~nsDeviceContextUnix();
|
||||
nsresult CreateFontCache();
|
||||
|
||||
nsIFontCache *mFontCache;
|
||||
nsDrawingSurfaceUnix * mSurface ;
|
||||
|
||||
PRUint32 mDepth;
|
||||
@ -111,20 +88,10 @@ protected:
|
||||
PRBool mWriteable;
|
||||
PRUint32 mNumCells;
|
||||
Colormap mColormap;
|
||||
// XXX There should be a nsIColormap interface
|
||||
|
||||
float mTwipsToPixels;
|
||||
float mPixelsToTwips;
|
||||
float mAppUnitsToDevUnits;
|
||||
float mDevUnitsToAppUnits;
|
||||
float mZoom;
|
||||
float mGammaValue;
|
||||
PRUint8 *mGammaTable;
|
||||
|
||||
public:
|
||||
void InstallColormap(void);
|
||||
void SetDrawingSurface(nsDrawingSurfaceUnix * aSurface) { mSurface = aSurface; }
|
||||
void SetGammaTable(PRUint8 * aTable, float aCurrentGamma, float aNewGamma);
|
||||
nsDrawingSurface GetDrawingSurface();
|
||||
|
||||
private:
|
||||
@ -138,7 +105,6 @@ private:
|
||||
PRUint32 mGreenOffset;
|
||||
PRUint32 mBlueOffset;
|
||||
|
||||
nsNativeWidget mNativeWidget;
|
||||
};
|
||||
|
||||
#endif /* nsDeviceContextUnix_h___ */
|
||||
|
@ -53,21 +53,21 @@ nsImageUnix :: ~nsImageUnix()
|
||||
}
|
||||
if(nsnull != mConvertedBits)
|
||||
{
|
||||
delete[] (PRUint8*)mConvertedBits;
|
||||
//NOD delete[] (PRUint8*)mConvertedBits;
|
||||
mConvertedBits = nsnull;
|
||||
}
|
||||
|
||||
if(nsnull != mImageBits)
|
||||
{
|
||||
delete[] (PRUint8*)mImageBits;
|
||||
//NOD delete[] (PRUint8*)mImageBits;
|
||||
mImageBits = nsnull;
|
||||
}
|
||||
if(nsnull!= mColorMap)
|
||||
delete mColorMap;
|
||||
//NOD if(nsnull!= mColorMap)
|
||||
//NOD delete mColorMap;
|
||||
|
||||
if (nsnull != mAlphaBits) {
|
||||
delete mAlphaBits;
|
||||
}
|
||||
//NOD if (nsnull != mAlphaBits) {
|
||||
//NOD delete mAlphaBits;
|
||||
//NOD }
|
||||
|
||||
}
|
||||
|
||||
@ -77,16 +77,16 @@ NS_IMPL_ISUPPORTS(nsImageUnix, kIImageIID);
|
||||
|
||||
nsresult nsImageUnix :: Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth,nsMaskRequirements aMaskRequirements)
|
||||
{
|
||||
if(nsnull != mImageBits)
|
||||
delete[] (PRUint8*)mImageBits;
|
||||
//NOD if(nsnull != mImageBits)
|
||||
//NOD delete[] (PRUint8*)mImageBits;
|
||||
|
||||
if(nsnull != mColorMap)
|
||||
delete[] mColorMap;
|
||||
//NOD if(nsnull != mColorMap)
|
||||
//NOD delete[] mColorMap;
|
||||
|
||||
if (nsnull != mImage) {
|
||||
XDestroyImage(mImage);
|
||||
mImage = nsnull;
|
||||
}
|
||||
//NOD if (nsnull != mImage) {
|
||||
//NOD XDestroyImage(mImage);
|
||||
//NOD mImage = nsnull;
|
||||
//NOD }
|
||||
mWidth = aWidth;
|
||||
mHeight = aHeight;
|
||||
mDepth = aDepth;
|
||||
|
Loading…
x
Reference in New Issue
Block a user