Added nsGraphicState and made changes in nsRenderingContext to use it.

General clean-up of code for Photon.
This commit is contained in:
Jerry.Kirk%Nexwarecorp.com 1999-09-30 12:21:33 +00:00
Родитель 24d9e54d0f
Коммит 9baf9f953d
14 изменённых файлов: 773 добавлений и 423 удалений

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

@ -36,11 +36,13 @@ CPPSRCS = \
nsGfxFactoryPh.cpp \
nsImagePh.cpp \
nsRegionPh.cpp \
nsGraphicsStatePh.cpp \
nsRenderingContextPh.cpp \
clip.cpp \
$(NULL)
EXPORTS = nsIRenderingContextPh.h
# Force Debug on to make logging work
DEFINES += -DDEBUG
include $(topsrcdir)/config/rules.mk

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

@ -16,20 +16,34 @@
* Reserved.
*/
#include "nsDeviceContextPh.h"
#include "nsRenderingContextPh.h"
#include "nsDeviceContextSpecPh.h"
#include <math.h>
#include "nspr.h"
#include "nsIPref.h"
#include "nsIServiceManager.h"
#include "il_util.h"
#include "nsCRT.h"
#include "nsDeviceContextPh.h"
#include "nsRenderingContextPh.h"
#include "nsDeviceContextSpecPh.h"
#include "nsPhGfxLog.h"
static NS_DEFINE_IID(kIDeviceContextSpecIID, NS_IDEVICE_CONTEXT_SPEC_IID);
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
static NS_DEFINE_IID(kIPrefIID, NS_IPREF_IID);
NS_IMPL_ISUPPORTS1(nsDeviceContextPh, nsIDeviceContext)
nsDeviceContextPh :: nsDeviceContextPh()
: DeviceContextImpl()
{
NS_INIT_REFCNT();
mTwipsToPixels = 1.0;
mPixelsToTwips = 1.0;
mDepth = 0 ;
mSurface = NULL;
mPaletteInfo.isPaletteDevice = PR_FALSE;
mPaletteInfo.sizePalette = 0;
@ -69,8 +83,6 @@ nsDeviceContextPh :: ~nsDeviceContextPh()
NS_IF_RELEASE(mSpec);
}
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
static NS_DEFINE_IID(kIPrefIID, NS_IPREF_IID);
NS_IMETHODIMP nsDeviceContextPh :: Init(nsNativeWidget aWidget)
{

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

@ -20,6 +20,12 @@
#define nsDeviceContextPh_h___
#include "nsDeviceContext.h"
#include "nsUnitConversion.h"
#include "nsIWidget.h"
#include "nsIView.h"
#include "nsIRenderingContext.h"
#include "nsRenderingContextPh.h"
#include <Pt.h>
class nsDeviceContextPh : public DeviceContextImpl
@ -27,6 +33,8 @@ class nsDeviceContextPh : public DeviceContextImpl
public:
nsDeviceContextPh();
NS_DECL_ISUPPORTS
NS_IMETHOD Init(nsNativeWidget aWidget);
NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext);

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

@ -16,35 +16,14 @@
* Reserved.
*/
#ifdef NGLAYOUT_DDRAW
#define INITGUID
#endif
#include "nsDrawingSurfacePh.h"
#include "prmem.h"
#include "nsCRT.h"
#include "nsPhGfxLog.h"
#include <photon/PhRender.h>
#include <Pt.h>
//#define GFX_DEBUG
#ifdef GFX_DEBUG
#define BREAK_TO_DEBUGGER DebugBreak()
#else
#define BREAK_TO_DEBUGGER
#endif
#ifdef GFX_DEBUG
#define VERIFY(exp) ((exp) ? 0: (GetLastError(), BREAK_TO_DEBUGGER))
#else // !_DEBUG
#define VERIFY(exp) (exp)
#endif // !_DEBUG
static NS_DEFINE_IID(kIDrawingSurfaceIID, NS_IDRAWING_SURFACE_IID);
static NS_DEFINE_IID(kIDrawingSurfacePhIID, NS_IDRAWING_SURFACE_PH_IID);
NS_IMPL_ISUPPORTS2(nsDrawingSurfacePh, nsIDrawingSurface, nsIDrawingSurfacePh)
nsDrawingSurfacePh :: nsDrawingSurfacePh()
{
@ -86,44 +65,6 @@ nsDrawingSurfacePh :: ~nsDrawingSurfacePh()
}
}
NS_IMETHODIMP nsDrawingSurfacePh :: QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(kIDrawingSurfaceIID))
{
nsIDrawingSurface* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDrawingSurfacePhIID))
{
nsIDrawingSurfacePh* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
if (aIID.Equals(kISupportsIID))
{
nsIDrawingSurface* tmp = this;
nsISupports* tmp2 = tmp;
*aInstancePtr = (void*) tmp2;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsDrawingSurfacePh)
NS_IMPL_RELEASE(nsDrawingSurfacePh)
/**
* Lock a rect of a drawing surface and return a
* pointer to the upper left hand corner of the
@ -146,7 +87,8 @@ NS_IMETHODIMP nsDrawingSurfacePh :: Lock(PRInt32 aX, PRInt32 aY,
void **aBits, PRInt32 *aStride,
PRInt32 *aWidthBytes, PRUint32 aFlags)
{
//printf ("lock\n");
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsDrawingSurfacePh::Lock mLocked=<%d>\n"));
if (mLocked)
{
NS_ASSERTION(0, "nested lock attempt");
@ -160,11 +102,13 @@ NS_IMETHODIMP nsDrawingSurfacePh :: Lock(PRInt32 aX, PRInt32 aY,
mLockHeight = aHeight;
mLockFlags = aFlags;
PhImage_t *image;
PhDim_t dim;
short bytes_per_pixel = 3;
PhImage_t *image;
PhDim_t dim;
short bytes_per_pixel = 3;
image = PR_Malloc(sizeof(PhImage_t));
// kirk - replaced Malloc with Calloc and got rid of memset further down
// image = PR_Malloc(sizeof(PhImage_t));
image = PR_CALLOC(sizeof(PhImage_t) );
if (image == NULL)
return NS_ERROR_FAILURE;
@ -173,21 +117,23 @@ NS_IMETHODIMP nsDrawingSurfacePh :: Lock(PRInt32 aX, PRInt32 aY,
dim.w = mLockWidth;
dim.h = mLockHeight;
memset( image, 0, sizeof(PhImage_t) );
// memset( image, 0, sizeof(PhImage_t) );
image->type = Pg_IMAGE_DIRECT_888; // 3 bytes per pixel with this type
image->size = dim;
// image->image = (char *) PgShmemCreate( dim.w * dim.h * bytes_per_pixel, NULL);
image->image = (char *) PR_Malloc( dim.w * dim.h * bytes_per_pixel);
if (image->image == NULL)
return NS_ERROR_FAILURE;
image->bpl = bytes_per_pixel*dim.w;
int y;
for (y=0;y<dim.h;y++)
memcpy(image->image+y*dim.w*3,mPixmap->image+3*mLockX+(mLockY+y)*mPixmap->bpl,dim.w*3);
// *aBits = mImage->image+mLockX*3+mLockY*mImage->bpl;
int y;
for (y=0;y<dim.h;y++)
{
memcpy( image->image+y*dim.w*3,
mPixmap->image+3*mLockX+(mLockY+y)*mPixmap->bpl,
dim.w*3);
}
*aBits = mImage->image;
*aWidthBytes = aWidth*3;
*aStride = mImage->bpl;
@ -198,55 +144,76 @@ for (y=0;y<dim.h;y++)
NS_IMETHODIMP nsDrawingSurfacePh :: XOR(PRInt32 aX, PRInt32 aY,
PRUint32 aWidth, PRUint32 aHeight)
{
//printf ("XOR: %d, %d %d %d %d\n",mIsOffscreen,aX,aY,aWidth,aHeight);
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsDrawingSurfacePh::XOR this=<%p> mIsOffscreen=<%d> area=(%ld,%ld,%ld,%ld)\n",
this, mIsOffscreen, aX, aY, aWidth, aHeight));
int x;
int y;
unsigned char *ptr;
int x, y, err;
unsigned char *ptr;
PmMemFlush( (PmMemoryContext_t *) mGC, mPixmap ); // get the image
ptr = mPixmap->image;
err=PmMemFlush( (PmMemoryContext_t *) mGC, mPixmap ); // get the image
NS_ASSERTION(err != -1, "nsDrawingSurfacePh::XOR PmMemFlush failed");
if (err == -1)
return NS_ERROR_FAILURE;
ptr = mPixmap->image;
for (y=aY;y<aY+aHeight;y++)
{
for (x=aX;x<aX+aWidth;x++)
{
ptr[3*x+0+(y*mPixmap->bpl)]^=255;
ptr[3*x+1+(y*mPixmap->bpl)]^=255;
ptr[3*x+2+(y*mPixmap->bpl)]^=255;
}
}
for (y=aY;y<aY+aHeight;y++)
{
for (x=aX;x<aX+aWidth;x++)
{
ptr[3*x+0+(y*mPixmap->bpl)]^=255;
ptr[3*x+1+(y*mPixmap->bpl)]^=255;
ptr[3*x+2+(y*mPixmap->bpl)]^=255;
}
}
return NS_OK;
return NS_OK;
}
extern void *Mask;
NS_IMETHODIMP nsDrawingSurfacePh :: Unlock(void)
{
//printf ("unlock: %p\n",Mask);
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsDrawingSurfacePh::Unlock this=<%p> mLocked=<%d> \n", this, mLocked));
if (!mLocked)
{
NS_ASSERTION(0, "attempting to unlock an DS that isn't locked");
NS_ASSERTION(0, "nsDrawingSurfacePh::Unlock - attempting to unlock an DS that isn't locked");
return NS_ERROR_FAILURE;
}
// If the lock was not read only, put the bits back on the pixmap
if (!(mLockFlags & NS_LOCK_SURFACE_READ_ONLY))
{
//printf ("really put data back: %d %d %d %d (%d %d)\n",mLockX,mLockY,mLockWidth,mLockHeight,mImage->size.w,mImage->size.h);
PhPoint_t pos = { mLockX, mLockY };
PhPoint_t pos = { mLockX, mLockY };
int err;
Select();
/* Kirk Hack to see what this does 9/27/99 */
/* No apparent problems improvements or problems... */
#if 1
if (Mask)
{
// printf ("use mask\n");
int bpl;
bpl = (mLockWidth+7)/8;
bpl = (bpl + 3) & ~0x3;
PgDrawTImage( mImage->image, mImage->type, &pos, &mImage->size, mImage->bpl, 0 ,Mask,bpl);
int bpl;
bpl = (mLockWidth+7)/8;
bpl = (bpl + 3) & ~0x3;
err=PgDrawTImage( mImage->image, mImage->type, &pos, &mImage->size, mImage->bpl, 0 ,Mask,bpl);
if (err == -1)
{
NS_ASSERTION(0, "nsDrawingSurfacePh::Unlock PgDrawTImage failed");
return NS_ERROR_FAILURE;
}
}
else
PgDrawImage( mImage->image, mImage->type, &pos, &mImage->size, mImage->bpl, 0 );
{
err=PgDrawImage( mImage->image, mImage->type, &pos, &mImage->size, mImage->bpl, 0 );
if (err == -1)
{
NS_ASSERTION(0, "nsDrawingSurfacePh::Unlock PgDrawImage failed");
return NS_ERROR_FAILURE;
}
}
#endif
}
PR_Free(mImage->image);
@ -262,30 +229,26 @@ NS_IMETHODIMP nsDrawingSurfacePh :: GetDimensions(PRUint32 *aWidth, PRUint32 *aH
*aWidth = mWidth;
*aHeight = mHeight;
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsDrawingSurfacePh::GetDimensions - Not Implemented\n"));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsDrawingSurfacePh::GetDimensions this=<%p> w,h=(%ld,%ld)\n", this, mWidth, mHeight));
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfacePh :: IsOffscreen(PRBool *aOffScreen)
{
*aOffScreen = mIsOffscreen;
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsDrawingSurfacePh::IsOffScreen - Not Implemented\n"));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsDrawingSurfacePh::IsOffScreen mIsOffscreen=<%d>\n", mIsOffscreen));
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfacePh :: IsPixelAddressable(PRBool *aAddressable)
{
// FIXME
printf ("ispixeladdressable\n");
*aAddressable = PR_FALSE;
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsDrawingSurfacePh::IsPixelAddressable - Not Implemented\n"));
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfacePh :: GetPixelFormat(nsPixelFormat *aFormat)
{
//printf ("getpixelformat\n");
*aFormat = mPixFormat;
return NS_OK;
}
@ -296,7 +259,7 @@ NS_IMETHODIMP nsDrawingSurfacePh :: Init( PhGC_t * &aGC )
mIsOffscreen = PR_FALSE; // is onscreen
mPixmap = NULL; // is onscreen
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsDrawingSurfacePh::Init with PhGC_t\n"));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsDrawingSurfacePh::Init with PhGC_t this=<%p>\n",this));
return NS_OK;
}
@ -304,8 +267,7 @@ NS_IMETHODIMP nsDrawingSurfacePh :: Init( PhGC_t * &aGC )
NS_IMETHODIMP nsDrawingSurfacePh :: Init( PhGC_t * &aGC, PRUint32 aWidth,
PRUint32 aHeight, PRUint32 aFlags)
{
//printf ("kedl: init with width and height\n");
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsDrawingSurfacePh::Init with PhGC_t + width/height\n"));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsDrawingSurfacePh::Init with PhGC_t + width/height this=<%p> w,h=(%ld,%ld)\n", this, aWidth, aHeight));
mholdGC = aGC;
mWidth = aWidth;
@ -320,43 +282,65 @@ NS_IMETHODIMP nsDrawingSurfacePh :: Init( PhGC_t * &aGC, PRUint32 aWidth,
PhArea_t area;
PtArg_t arg[3];
image = PR_Malloc(sizeof(PhImage_t));
// kirk - replaced Malloc with Calloc and got rid of memset further down
// image = PR_Malloc(sizeof(PhImage_t));
image = PR_CALLOC(sizeof(PhImage_t) );
if (image == NULL)
return NS_ERROR_FAILURE;
mPixmap = image;
mPixmap = image;
area.pos.x = 0;
area.pos.y = 0;
area.size.w = aWidth;
area.size.h = aHeight;
dim.w = area.size.w;
dim.h = area.size.h;
area.pos.x=0;
area.pos.y=0;
area.size.w=aWidth;
area.size.h=aHeight;
dim.w = area.size.w;
dim.h = area.size.h;
dim.h += 100; // kedl, uggggg hack! weird font not drawing unless
// the surface is somewhat bigger??
dim.w ++;
#if 1
// kedl, hack! weird font not drawing unless
// the surface is somewhat bigger??
dim.h += 100;
dim.w ++;
#endif
//printf ("kedl: create drawing surface: %d %d %d %d, %lu\n",area.pos.x,area.pos.y,area.size.w,area.size.h,image);
PhPoint_t translation = { 0, 0 }, center, radii;
PhPoint_t translation = { 0, 0 };
PmMemoryContext_t *mc;
short bytes_per_pixel = 3;
memset( image, 0, sizeof(PhImage_t) );
// memset( image, 0, sizeof(PhImage_t) );
image->type = Pg_IMAGE_DIRECT_888; // 3 bytes per pixel with this type
image->size = dim;
image->image = (char *) PgShmemCreate( dim.w * dim.h * bytes_per_pixel, NULL);
image->bpl = bytes_per_pixel*dim.w;
if (image->image == NULL)
{
NS_ASSERTION(0,"nsDrawingSurfacePh::Init Out of Memory calling PgShmemCreate");
return NS_ERROR_FAILURE;
}
image->bpl = bytes_per_pixel * dim.w;
mc = PmMemCreateMC( image, &dim, &translation );
mGC = (PhGC_t *)mc;
if (mc == NULL)
{
NS_ASSERTION(0, "nsDrawingSurfacePh::Init Out of Memory calling PmMemCreateMC");
return NS_ERROR_FAILURE;
}
mGC = (PhGC_t *) mc;
// now all drawing goes into the memory context
PmMemStart( mc );
// PgSetRegion( mholdGC->rid );
PhDrawContext_t *oldDC;
oldDC = PmMemStart( mc );
if (oldDC == NULL)
{
NS_ASSERTION(0, "nsDrawingSurfacePh::Init - Error calling PmMemStart");
return NS_ERROR_FAILURE;
}
return NS_OK;
}
@ -374,43 +358,72 @@ NS_IMETHODIMP nsDrawingSurfacePh :: ReleaseGC( void )
NS_IMETHODIMP nsDrawingSurfacePh :: Select( void )
{
PhGC_t *gc=PgGetGC();
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsDrawingSurfacePh::Select mIsOffscreen=<%d>\n", mIsOffscreen));
if (mholdGC==nsnull) mholdGC = mGC;
PhGC_t *gc = PgGetGC();
if (mholdGC==nsnull)
mholdGC = mGC;
if (gc==mGC)
if (gc == mGC)
{
//printf ("don't set gc\n");
return 0;
return NS_OK; // kirk - this was a 0, I think its the same?
}
else
{
if (mIsOffscreen)
{
//printf ("going offscreen: %p\n",mGC); fflush(stdout);
PmMemFlush( (PmMemoryContext_t *) mGC, mPixmap ); // get the image
PmMemStart( (PmMemoryContext_t *) mGC);
// PgSetRegion(mGC->rid);
int err;
PhDrawContext_t *oldDC;
err=PmMemFlush( (PmMemoryContext_t *) mGC, mPixmap ); // get the image
if (err == -1)
{
NS_ASSERTION(0, "nsDrawingSurfacePh::Select - Error calling PmMemFlush");
return NS_ERROR_FAILURE;
}
oldDC=PmMemStart( (PmMemoryContext_t *) mGC);
if (oldDC == NULL)
{
NS_ASSERTION(0, "nsDrawingSurfacePh::Select - Error calling PmMemStart");
return NS_ERROR_FAILURE;
}
}
else
{
//printf ("going onscreen: %p\n",mGC); fflush(stdout);
PgSetGC(mGC);
// PgSetRegion(mGC->rid);
}
}
return 1;
return NS_OK;
}
void nsDrawingSurfacePh::Stop(void)
{
// printf ("offscreen: %d\n",mIsOffscreen);
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsDrawingSurfacePh::Stop mIsOffscreen=<%d>\n", mIsOffscreen));
if (mIsOffscreen)
{
PmMemFlush( (PmMemoryContext_t *) mGC, mPixmap ); // get the image
PmMemStop( (PmMemoryContext_t *) mGC );
int err;
PhDrawContext_t *theMC;
err=PmMemFlush( (PmMemoryContext_t *) mGC, mPixmap ); // get the image
if (err == -1)
{
NS_ASSERTION(0, "nsDrawingSurfacePh::Stop - Error calling PmMemFlush");
return;
}
theMC = PmMemStop( (PmMemoryContext_t *) mGC );
if (theMC == NULL)
{
NS_ASSERTION(0, "nsDrawingSurfacePh::Stop - Error calling PmMemStop");
return;
}
}
}

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

@ -24,11 +24,11 @@
class nsDrawingSurfacePh : public nsIDrawingSurface,
nsIDrawingSurfacePh
public nsIDrawingSurfacePh
{
public:
nsDrawingSurfacePh();
NS_DECL_ISUPPORTS
//nsIDrawingSurface interface

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

@ -23,9 +23,7 @@ static NS_DEFINE_IID(kIFontMetricsIID, NS_IFONT_METRICS_IID);
nsFontMetricsPh :: nsFontMetricsPh()
{
/* stolen from GTK version */
NS_INIT_REFCNT();
mDeviceContext = nsnull;
mFont = nsnull;
@ -58,7 +56,7 @@ nsFontMetricsPh :: ~nsFontMetricsPh()
mDeviceContext = nsnull;
}
NS_IMPL_ISUPPORTS(nsFontMetricsPh, kIFontMetricsIID)
NS_IMPL_ISUPPORTS1(nsFontMetricsPh, nsIFontMetrics)
NS_IMETHODIMP
nsFontMetricsPh :: Init(const nsFont& aFont, nsIDeviceContext *aContext)

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

@ -38,13 +38,15 @@ static NS_DEFINE_IID(kCDeviceContext, NS_DEVICE_CONTEXT_CID);
static NS_DEFINE_IID(kCRegion, NS_REGION_CID);
static NS_DEFINE_IID(kCBlender, NS_BLENDER_CID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kCDeviceContextSpec, NS_DEVICE_CONTEXT_SPEC_CID);
static NS_DEFINE_IID(kCDeviceContextSpecFactory, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID);
static NS_DEFINE_IID(kCDrawingSurface, NS_DRAWING_SURFACE_CID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
//static NS_DEFINE_IID(kCDrawingSurface, NS_DRAWING_SURFACE_CID);
//static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
//static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
class nsGfxFactoryPh : public nsIFactory
{
@ -80,7 +82,7 @@ nsGfxFactoryPh::~nsGfxFactoryPh()
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsGfxFactoryPh::~nsGfxFactoryPh Destructor\n"));
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
NS_ASSERTION(mRefCnt == 0, "nsGfxFactoryGTK::~nsGfxFactoryGTK non-zero refcnt at destruction");
}
nsresult nsGfxFactoryPh::QueryInterface(const nsIID &aIID,
@ -141,27 +143,19 @@ nsresult nsGfxFactoryPh::CreateInstance(nsISupports *aOuter,
if (mClassID.Equals(kCFontMetrics))
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsGfxFactoryPh::CreateInstance asking for nsFontMetricsPh.\n"));
nsFontMetricsPh* fm;
NS_NEWXPCOM(fm, nsFontMetricsPh);
inst = (nsISupports *)fm;
inst = (nsISupports *) new nsFontMetricsPh();
}
else if (mClassID.Equals(kCDeviceContext)) {
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsGfxFactoryPh::CreateInstance asking for nsDeviceContextPh.\n"));
nsDeviceContextPh* dc;
NS_NEWXPCOM(dc, nsDeviceContextPh);
inst = (nsISupports *)dc;
inst = (nsISupports *)new nsDeviceContextPh();
}
else if (mClassID.Equals(kCRenderingContext)) {
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsGfxFactoryPh::CreateInstance asking for nsRenderingContextPh.\n"));
nsRenderingContextPh* rc;
NS_NEWXPCOM(rc, nsRenderingContextPh);
inst = (nsISupports *)((nsIRenderingContext*)rc);
inst = (nsISupports *)new nsRenderingContextPh();
}
else if (mClassID.Equals(kCImage)) {
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsGfxFactoryPh::CreateInstance asking for nsImagePh.\n"));
nsImagePh* image;
NS_NEWXPCOM(image, nsImagePh);
inst = (nsISupports *)image;
inst = (nsISupports *)new nsImagePh();
}
else if (mClassID.Equals(kCRegion)) {
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsGfxFactoryPh::CreateInstance asking for nsRegionPh.\n"));

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

@ -0,0 +1,122 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#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(mClipRegion);
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
//
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool *
nsGraphicsStatePool::gsThePool = nsnull;
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool *
nsGraphicsStatePool::PrivateGetPool()
{
if (nsnull == gsThePool)
{
gsThePool = new nsGraphicsStatePool();
}
return gsThePool;
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool::~nsGraphicsStatePool()
{
nsGraphicsState* gs = mFreeList;
while (gs != nsnull) {
nsGraphicsState* next = gs->mNext;
delete gs;
gs = next;
}
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsState *
nsGraphicsStatePool::PrivateGetNewGS()
{
nsGraphicsState* gs = mFreeList;
if (gs != nsnull) {
mFreeList = gs->mNext;
return gs;
}
return new nsGraphicsState;
}
//////////////////////////////////////////////////////////////////////////
void
nsGraphicsStatePool::PrivateReleaseGS(nsGraphicsState* aGS)
{
// aGS->Clear();
aGS->mNext = mFreeList;
mFreeList = aGS;
}
//////////////////////////////////////////////////////////////////////////

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

@ -0,0 +1,71 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsGraphicsStatePh_h___
#define nsGraphicsStatePh_h___
#include "nsIRenderingContext.h"
#include "nsIFontMetrics.h"
#include "nsTransform2D.h"
#include "nsRegionPh.h"
class nsGraphicsState
{
public:
nsTransform2D *mMatrix;
nsIRegion *mClipRegion;
nscolor mColor;
nsLineStyle mLineStyle;
nsIFontMetrics *mFontMetrics;
nsGraphicsState *mNext; // link into free list of graphics states.
friend class nsGraphicsStatePool;
#ifndef USE_GS_POOL
friend class nsRenderingContextPh;
#endif
private:
nsGraphicsState();
~nsGraphicsState();
};
class nsGraphicsStatePool
{
public:
static nsGraphicsState * GetNewGS();
static void ReleaseGS(nsGraphicsState* aGS);
nsGraphicsStatePool();
~nsGraphicsStatePool();
private:
nsGraphicsState* mFreeList;
static nsGraphicsStatePool * PrivateGetPool();
nsGraphicsState * PrivateGetNewGS();
void PrivateReleaseGS(nsGraphicsState* aGS);
static nsGraphicsStatePool * gsThePool;
};
#endif /* nsGraphicsStatePh_h___ */

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

@ -31,6 +31,8 @@
class nsIDrawingSurfacePh : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDRAWING_SURFACE_PH_IID)
/**
* Initialize a drawing surface using a windows DC.
* aDC is "owned" by the drawing surface until the drawing

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

@ -23,11 +23,9 @@
static NS_DEFINE_IID(kIImageIID, NS_IIMAGE_IID);
NS_IMPL_ISUPPORTS1(nsImagePh, nsIImage)
/** ----------------------------------------------------------------
* Constructor for nsImagePh
* @update dc - 11/20/98
*/
// ----------------------------------------------------------------
nsImagePh :: nsImagePh()
{
NS_INIT_REFCNT();
@ -53,10 +51,7 @@ nsImagePh :: nsImagePh()
mImage.image = nsnull;
}
/** ----------------------------------------------------------------
* destructor for nsImagePh
* @update dc - 11/20/98
*/
// ----------------------------------------------------------------
nsImagePh :: ~nsImagePh()
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsImagePh::~nsImagePh Destructor called\n"));
@ -65,11 +60,8 @@ nsImagePh :: ~nsImagePh()
CleanUp(PR_TRUE);
}
NS_IMPL_ISUPPORTS(nsImagePh, kIImageIID);
/** ----------------------------------------------------------------
* Initialize the nsImagePh object
* @update dc - 11/20/98
* @param aWidth - Width of the image
* @param aHeight - Height of the image
* @param aDepth - Depth of the image
@ -78,12 +70,8 @@ NS_IMPL_ISUPPORTS(nsImagePh, kIImageIID);
*/
nsresult nsImagePh :: Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth,nsMaskRequirements aMaskRequirements)
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsImagePh::Init (%p) - aWidth=%d aHeight=%d aDepth=%d\n", this,
aWidth, aHeight, aDepth));
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsImagePh::Init (%p) - aWidth=%d aHeight=%d aDepth=%d\n", this, aWidth, aHeight, aDepth));
// mHBitmap = nsnull;
// mAlphaHBitmap = nsnull;
CleanUp(PR_TRUE);
if (8 == aDepth)
@ -271,7 +259,8 @@ NS_IMETHODIMP nsImagePh :: Draw(nsIRenderingContext &aContext, nsDrawingSurface
PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight)
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsImagePh::Draw1 (%p)\n", this ));
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsImagePh::Draw1 this=<%p> aS=(%d,%d,%d,%d) aD=(%d,%d,%d,%d)\n", this,
aSX, aSY, aSWidth, aSHeight, aDX, aDY, aDWidth, aDHeight ));
if( !mImage.image )
{
@ -280,20 +269,44 @@ NS_IMETHODIMP nsImagePh :: Draw(nsIRenderingContext &aContext, nsDrawingSurface
}
PhPoint_t pos = { aDX, aDY };
// PgDrawPhImagemx( &pos, &mImage, 0 );
int err;
if( mColorMap )
{
PgSetPalette( (PgColor_t*) mColorMap->Index, 0, 0, mColorMap->NumColors, Pg_PALSET_SOFT, 0 );
err=PgSetPalette( (PgColor_t*) mColorMap->Index, 0, 0, mColorMap->NumColors, Pg_PALSET_SOFT, 0 );
if (err == -1)
{
NS_ASSERTION(0,"nsImagePh::Draw Error calling PgSetPalette");
return NS_ERROR_FAILURE;
}
}
if( mAlphaBits )
PgDrawTImage( mImage.image, mImage.type, &pos, &mImage.size, mImage.bpl, 0, mAlphaBits, mARowBytes );
else
PgDrawImage( mImage.image, mImage.type, &pos, &mImage.size, mImage.bpl, 0 );
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsImagePh::Draw1 this=<%p> mImage.size=(%ld,%ld)\n", this, mImage.size.w, mImage.size.h));
// PgFlush();
/* Kirk Hack to see what this does 9/27/99 */
/* I think this is needed... but I can't find anything that calls it... */
/* This draw may be able to call the other draw to save space */
#if 1
if( mAlphaBits )
{
err=PgDrawTImage( mImage.image, mImage.type, &pos, &mImage.size, mImage.bpl, 0, mAlphaBits, mARowBytes );
if (err == -1)
{
NS_ASSERTION(0,"nsImagePh::Draw Error calling PgDrawTImage");
return NS_ERROR_FAILURE;
}
}
else
{
err=PgDrawImage( mImage.image, mImage.type, &pos, &mImage.size, mImage.bpl, 0 );
if (err == -1)
{
NS_ASSERTION(0,"nsImagePh::Draw Error calling PgDrawImage");
return NS_ERROR_FAILURE;
}
}
#endif
return NS_OK;
}
@ -313,9 +326,8 @@ NS_IMETHODIMP nsImagePh :: Draw(nsIRenderingContext &aContext, nsDrawingSurface
NS_IMETHODIMP nsImagePh :: Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface,
PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsImagePh::Draw2 (%p) (%ld,%ld,%ld,%ld)\n", this, aX, aY, aWidth, aHeight ));
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsImagePh::Draw2 this=(%p) dest=(%ld,%ld,%ld,%ld) aSurface=<%p>\n", this, aX, aY, aWidth, aHeight, aSurface ));
//printf ("kedl: draw2\n");
// REVISIT - this is a brute-force implementation. We currently have no h/w blit
// capabilities.
@ -326,20 +338,39 @@ NS_IMETHODIMP nsImagePh :: Draw(nsIRenderingContext &aContext, nsDrawingSurface
}
PhPoint_t pos = { aX, aY };
int err;
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsImagePh::Draw2 this=<%p> mImage.size=(%ld,%ld)\n", this, mImage.size.w, mImage.size.h));
/* Kirk Hack to see what this does 9/27/99 */
/* No Images draw without this enabled.. Check out Test 2 */
#if 1
if( mAlphaBits )
PgDrawTImage( mImage.image, mImage.type, &pos, &mImage.size, mImage.bpl, 0, mAlphaBits, mARowBytes );
{
err=PgDrawTImage( mImage.image, mImage.type, &pos, &mImage.size, mImage.bpl, 0, mAlphaBits, mARowBytes );
if (err == -1)
{
NS_ASSERTION(0,"nsImagePh::Draw Error calling PgDrawTImage");
return NS_ERROR_FAILURE;
}
}
else
PgDrawImage( mImage.image, mImage.type, &pos, &mImage.size, mImage.bpl, 0 );
// PgDrawPhImagemx( &pos, &mImage, 0 );
// PgFlush();
{
err=PgDrawImage( mImage.image, mImage.type, &pos, &mImage.size, mImage.bpl, 0 );
if (err == -1)
{
NS_ASSERTION(0,"nsImagePh::Draw Error calling PgDrawImage");
return NS_ERROR_FAILURE;
}
}
#endif
return NS_OK;
}
/** ----------------------------------------------------------------
* Create an optimezed bitmap, -- this routine may need to be deleted, not really used now
* Create an optimized bitmap, -- this routine may need to be deleted, not really used now
* @update dc - 11/20/98
* @param aContext - The device context to use for the optimization
*/

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

@ -64,7 +64,7 @@ nsRegionPh :: nsRegionPh()
nsRegionPh :: ~nsRegionPh()
{
// PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRegionPh::~nsRegion Destructor called\n"));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRegionPh::~nsRegion Destructor\n"));
#ifdef DEBUG_REGION
DumpTiles(mRegion);
@ -74,10 +74,7 @@ nsRegionPh :: ~nsRegionPh()
PhFreeTiles(mRegion);
}
NS_IMPL_QUERY_INTERFACE(nsRegionPh, kRegionIID)
NS_IMPL_ADDREF(nsRegionPh)
NS_IMPL_RELEASE(nsRegionPh)
NS_IMPL_ISUPPORTS1(nsRegionPh, nsIRegion)
nsresult nsRegionPh :: Init(void)
{

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

@ -16,6 +16,8 @@
* Reserved.
*/
#define NEW_GS
#include "nsRenderingContextPh.h"
#include "nsRegionPh.h"
#include <math.h>
@ -24,28 +26,22 @@
#include "prprf.h"
#include "nsDrawingSurfacePh.h"
#include "nsGfxCIID.h"
#include <stdlib.h>
#ifdef NEW_GS
#include "nsGraphicsStatePh.h"
#endif
#include <stdlib.h>
#include <mem.h>
#include <photon/PhRender.h>
#include <Pt.h>
#ifdef GFX_DEBUG
#define BREAK_TO_DEBUGGER DebugBreak()
#else
#define BREAK_TO_DEBUGGER
#endif
#ifdef GFX_DEBUG
#define VERIFY(exp) ((exp) ? 0: (GetLastError(), BREAK_TO_DEBUGGER))
#else // !_DEBUG
#define VERIFY(exp) (exp)
#endif // !_DEBUG
static NS_DEFINE_IID(kIRenderingContextIID, NS_IRENDERING_CONTEXT_IID);
static NS_DEFINE_IID(kIRenderingContextPhIID, NS_IRENDERING_CONTEXT_PH_IID);
//static NS_DEFINE_IID(kIRenderingContextPhIID, NS_IRENDERING_CONTEXT_PH_IID);
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);
#define FLAG_CLIP_VALID 0x0001
#define FLAG_CLIP_CHANGED 0x0002
@ -56,7 +52,6 @@ static NS_DEFINE_IID(kDrawingSurfaceCID, NS_DRAWING_SURFACE_CID);
int cur_color = 0;
char FillColorName[8][20] = {"Pg_BLACK","Pg_BLUE","Pg_RED","Pg_YELLOW","Pg_GREEN","Pg_MAGENTA","Pg_CYAN","Pg_WHITE"};
long FillColorVal[8] = {Pg_BLACK,Pg_BLUE,Pg_RED,Pg_YELLOW,Pg_GREEN,Pg_MAGENTA,Pg_CYAN,Pg_WHITE};
//PRBool mBufferIsEmpty;
// Macro for creating a palette relative color if you have a COLORREF instead
// of the reg, green, and blue values. The color is color-matches to the nearest
@ -73,12 +68,19 @@ long FillColorVal[8] = {Pg_BLACK,Pg_BLUE,Pg_RED,Pg_YELLOW,Pg_GREEN,Pg_MAGENTA,Pg
PRLogModuleInfo *PhGfxLog = PR_NewLogModule("PhGfxLog");
#include "nsPhGfxLog.h"
NS_IMPL_ISUPPORTS1(nsRenderingContextPh, nsIRenderingContext)
/* Global Variable for Alpha Blending */
void *Mask;
void *Mask = nsnull;
/* The default Photon Drawing Context */
PhGC_t *nsRenderingContextPh::mPtGC = nsnull;
#define SELECT(surf) mBufferIsEmpty = PR_FALSE; if (surf->Select()) ApplyClipping(surf->GetGC());
//#define SELECT(surf) if (surf->Select()) ApplyClipping(surf->GetGC());
#ifndef NEW_GS
class GraphicsState
{
public:
@ -93,7 +95,7 @@ public:
nscolor mCurrentColor;
nsTransform2D *mMatrix; // transform that all the graphics drawn here will obey
nsIFontMetrics *mFontMetrics;
nsRegionPh *mClipRegion;
nsIRegion *mClipRegion;
};
@ -112,11 +114,7 @@ GraphicsState :: GraphicsState()
GraphicsState :: ~GraphicsState()
{
}
#define NOT_SETUP 0x33
PhGC_t *nsRenderingContextPh::mPtGC = nsnull;
#endif
nsRenderingContextPh :: nsRenderingContextPh()
{
@ -124,8 +122,8 @@ nsRenderingContextPh :: nsRenderingContextPh()
mGC = nsnull;
mTMatrix = new nsTransform2D();
mRegion = new nsRegionPh();
mRegion->Init();
mClipRegion = nsnull ; // new nsRegionPh();
//mClipRegion->Init();
mFontMetrics = nsnull;
mSurface = nsnull;
mMainSurface = nsnull;
@ -135,7 +133,7 @@ nsRenderingContextPh :: nsRenderingContextPh()
mWidget = nsnull;
mPhotonFontName = nsnull;
Mask = nsnull;
mLineStyle = nsLineStyle_kSolid;
mCurrentLineStyle = nsLineStyle_kSolid;
//default objects
//state management
@ -147,10 +145,7 @@ nsRenderingContextPh :: nsRenderingContextPh()
if( mPtGC == nsnull )
mPtGC = PgGetGC();
#ifdef NS_DEBUG
mInitialized = PR_FALSE;
#endif
mInitialized = PR_FALSE;
mBufferIsEmpty = PR_TRUE;
PushState();
@ -159,14 +154,24 @@ nsRenderingContextPh :: nsRenderingContextPh()
nsRenderingContextPh :: ~nsRenderingContextPh()
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh(%p) destructor, mGC = %p\n", this, mGC ));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::~nsRenderingContextPh this=<%p> mGC = %p\n", this, mGC ));
if (mContext)
NS_IF_RELEASE(mContext);
#if 1
// Destroy the State Machine
if (mStateCache)
{
PRInt32 cnt = mStateCache->Count();
if (mFontMetrics)
NS_IF_RELEASE(mFontMetrics);
while (--cnt >= 0)
{
PRBool clipstate;
PopState(clipstate);
}
delete mStateCache;
mStateCache = nsnull;
}
#else
if (nsnull != mStateCache)
{
PRInt32 cnt = mStateCache->Count();
@ -183,6 +188,7 @@ nsRenderingContextPh :: ~nsRenderingContextPh()
delete mStateCache;
mStateCache = nsnull;
}
#endif
if (mTMatrix)
delete mTMatrix;
@ -191,84 +197,34 @@ nsRenderingContextPh :: ~nsRenderingContextPh()
{
if( mGC )
{
// PgDestroyGC( mGC );
PgSetGC( mPtGC );
PgSetRegion( mPtGC->rid );
PgDestroyGC( mGC );
mGC = nsnull;
}
}
else
{
// PmMemStop( (PmMemoryContext_t *)mGC);
}
if (mRegion)
{
delete mRegion;
}
if( mWidget )
{
#ifdef ENABLE_PHOTON_FLUXING
PtEndFlux( PtFindDisjoint( mWidget ));
#endif
// PtContainerRelease(PtFindDisjoint( mWidget ));
// PtFlush();
}
/* We always do this?? */
PgSetGC( mPtGC );
PgSetRegion( mPtGC->rid );
if (mPhotonFontName)
delete [] mPhotonFontName;
NS_IF_RELEASE(mClipRegion); /* do we need to do this? */
// if (mClipRegion)
// delete mClipRegion;
NS_IF_RELEASE(mFontMetrics);
NS_IF_RELEASE(mContext);
}
nsresult nsRenderingContextPh :: QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(kIRenderingContextIID))
{
nsIRenderingContext* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIRenderingContextPhIID))
{
nsIRenderingContextPh* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
if (aIID.Equals(kISupportsIID))
{
nsIRenderingContext* tmp = this;
nsISupports* tmp2 = tmp;
*aInstancePtr = (void*) tmp2;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsRenderingContextPh)
NS_IMPL_RELEASE(nsRenderingContextPh)
NS_IMETHODIMP nsRenderingContextPh :: Init(nsIDeviceContext* aContext,
nsIWidget *aWindow)
nsIWidget *aWindow)
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::Init with a widget\n"));
NS_PRECONDITION(PR_FALSE == mInitialized, "double init");
@ -282,29 +238,29 @@ NS_IMETHODIMP nsRenderingContextPh :: Init(nsIDeviceContext* aContext,
if(!mWidget)
{
printf( "nsRenderingContext::Init (with a widget) mWidget is NULL!\n" );
fflush( stdout );
NS_IF_RELEASE(mContext); // new
NS_ASSERTION(mWidget,"nsRenderingContext::Init (with a widget) mWidget is NULL!");
return NS_ERROR_FAILURE;
}
PhRid_t rid = PtWidgetRid( mWidget );
//PhRid_t rid = PtWidgetRid( PtFindDisjoint(mWidget) );
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::Init this=<%p> mWidget=<%p> rid=<%d>\n", this, mWidget, rid ));
if( !rid )
if (rid == 0)
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::Init Widget (%p) does not have a Rid!\n", mWidget ));
//NS_ASSERTION(rid, "nsRenderingContextPh::Init PtWidgetRid returned 0");
}
NS_ASSERTION(rid, "nsRenderingContextPh::Init PtWidgetRid returned 0");
mGC = PgCreateGC( 4096 );
if( !mGC )
else
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::Init PgCreateGC() failed!\n" ));
}
mGC = PgCreateGC( 4096 );
if( !mGC )
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::Init PgCreateGC() failed!\n" ));
}
NS_ASSERTION(mGC, "nsRenderingContextPh::Init PgCreateGC() failed!");
NS_ASSERTION(mGC, "nsRenderingContextPh::Init PgCreateGC() failed!");
PgSetGC( mGC );
PgDefaultGC( mGC );
@ -314,20 +270,29 @@ NS_IMETHODIMP nsRenderingContextPh :: Init(nsIDeviceContext* aContext,
// PgSetRegion( mPtGC->rid );
mSurface = new nsDrawingSurfacePh();
//printf ("create1: %p\n",mSurface);
res = mSurface->Init(mGC);
if (res != NS_OK)
if (mSurface)
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::Init mSurface->Init(mGC) failed\n"));
res = mSurface->Init(mGC);
if (res != NS_OK)
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::Init mSurface->Init(mGC) failed\n"));
return NS_ERROR_FAILURE;
}
}
else
{
NS_ASSERTION(0, "nsRenderingContextPh::Init Failed to new the mSurface");
return NS_ERROR_FAILURE;
}
// mSurface->Init(mGC,640,480,0);
// SELECT(mSurface);
mOffscreenSurface = mSurface;
NS_IF_ADDREF(aWindow);
// NS_IF_ADDREF(aWindow); /* took this out */
NS_ADDREF(mSurface);
}
mInitialized = PR_TRUE;
return (CommonInit());
}
@ -335,10 +300,21 @@ NS_IMETHODIMP nsRenderingContextPh::CommonInit()
{
float app2dev;
if ( NS_SUCCEEDED(nsComponentManager::CreateInstance(kRegionCID, 0, NS_GET_IID(nsIRegion), (void**)&mClipRegion)) )
{
mClipRegion->Init();
mClipRegion->SetTo(0, 0, 0,0);
if (mSurface)
{
PRUint32 width, height;
mSurface->GetDimensions(&width, &height);
mClipRegion->SetTo(0, 0, width, height);
}
}
mContext->GetAppUnitsToDevUnits(app2dev);
mTMatrix->AddScale(app2dev,app2dev);
mContext->GetDevUnitsToAppUnits(mP2T);
mContext->GetGammaTable(mGammaTable);
return NS_OK;
@ -346,32 +322,23 @@ NS_IMETHODIMP nsRenderingContextPh::CommonInit()
NS_IMETHODIMP nsRenderingContextPh :: Init(nsIDeviceContext* aContext,
nsDrawingSurface aSurface)
nsDrawingSurface aSurface)
{
printf ("kedl: init with a surface!!!! %p\n",aSurface);
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::Init with a Drawing Surface\n"));
printf ("nsRenderingContextPh::Init with a surface!!!! %p\n",aSurface);
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::Init with a Drawing Surface\n"));
NS_PRECONDITION(PR_FALSE == mInitialized, "double init");
mContext = aContext;
NS_IF_ADDREF(mContext);
// mGC = PgCreateGC( 8192 );
// PgSetGC( mGC );
// PgDefaultGC( mGC );
// PgSetRegion( rid );
mSurface = (nsDrawingSurfacePh *)aSurface;
mSurface = (nsDrawingSurfacePh *) aSurface;
mOffscreenSurface=mSurface;
//printf ("kedl: gcs %p %p\n",((nsDrawingSurfacePh *)aSurface)->GetGC(),mSurface->GetGC());
// mSurface->Select();
NS_ADDREF(mSurface);
// NS_ADDREF(mSurface);
// printf( "abs clip = not set from surface!\n" );
// PgSetClipping( 0, NULL );
// PgClearTranslation();
// mTMatrix->SetToTranslate(0,0);
mInitialized = PR_TRUE;
return (CommonInit());
}
@ -401,18 +368,16 @@ NS_IMETHODIMP nsRenderingContextPh::UnlockDrawingSurface(void)
NS_IMETHODIMP nsRenderingContextPh :: SelectOffScreenDrawingSurface(nsDrawingSurface aSurface)
{
// PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::SelectOffScreenDrawingSurface\n"));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::SelectOffScreenDrawingSurface (%s)\n", FillColorName[cur_color]));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::SelectOffScreenDrawingSurface this=<%p> sSurface=<%p>\n", this, aSurface));
// printf ("kedl: surface select: %lu\n",aSurface);
if (nsnull==aSurface)
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, (" selecting offscreen (private)\n"));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::SelectOffScreenDrawingSurface selecting offscreen (private)\n"));
mSurface = mOffscreenSurface;
}
else
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, (" selecting passed-in (%p)\n", aSurface));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::SelectOffScreenDrawingSurface selecting passed-in (%p)\n", aSurface));
mSurface = (nsDrawingSurfacePh *) aSurface;
}
@ -437,7 +402,7 @@ NS_IMETHODIMP nsRenderingContextPh :: GetDrawingSurface(nsDrawingSurface *aSurfa
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::GetDrawingSurface\n"));
// printf ("get drawing surface! %p\n",mSurface);
*aSurface = (void *)mSurface;
*aSurface = (void *) mSurface;
return NS_OK;
}
@ -446,10 +411,18 @@ NS_IMETHODIMP nsRenderingContextPh :: GetHints(PRUint32& aResult)
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::GetHints\n"));
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 = NS_RENDERING_HINT_FAST_8BIT_TEXT;
aResult = result;
return NS_OK;
}
@ -476,6 +449,45 @@ NS_IMETHODIMP nsRenderingContextPh :: PushState(void)
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::PushState\n"));
#ifdef NEW_GS
/* kirk 9/27/99 stole this from GTK */
// Get a new GS
#ifdef USE_GS_POOL
nsGraphicsState *state = nsGraphicsStatePool::GetNewGS();
#else
nsGraphicsState *state = new nsGraphicsState;
#endif
// Push into this state object, add to vector
if (!state)
{
NS_ASSERTION(0, "nsRenderingContextPh::PushState Failed to create a new Graphics State");
return NS_ERROR_FAILURE;
}
state->mMatrix = mTMatrix;
if (nsnull == mTMatrix)
mTMatrix = new nsTransform2D();
else
mTMatrix = new nsTransform2D(mTMatrix);
if (mClipRegion)
{
// set the state's clip region to a new copy of the current clip region
GetClipRegion(&state->mClipRegion);
}
NS_IF_ADDREF(mFontMetrics);
state->mFontMetrics = mFontMetrics;
state->mColor = mCurrentColor;
state->mLineStyle = mCurrentLineStyle;
mStateCache->AppendElement(state);
#else
GraphicsState * state = new GraphicsState();
if (state)
{
@ -486,16 +498,16 @@ NS_IMETHODIMP nsRenderingContextPh :: PushState(void)
state->mMatrix = mTMatrix;
state->mFontMetrics = mFontMetrics;
NS_IF_ADDREF( state->mFontMetrics );
state->mClipRegion = mRegion;
state->mClipRegion = mClipRegion;
/* if the mRegion is not empty make a copy */
if (mRegion != nsnull)
/* if the mClipRegion is not empty make a copy */
if (mClipRegion != nsnull)
{
mRegion = new nsRegionPh();
if (mRegion)
mClipRegion = new nsRegionPh();
if (mClipRegion)
{
mRegion->Init();
mRegion->SetTo(*state->mClipRegion);
mClipRegion->Init();
mClipRegion->SetTo(*state->mClipRegion);
}
else
{
@ -510,6 +522,7 @@ NS_IMETHODIMP nsRenderingContextPh :: PushState(void)
}
else
return NS_ERROR_OUT_OF_MEMORY;
#endif
return NS_OK;
}
@ -519,6 +532,62 @@ NS_IMETHODIMP nsRenderingContextPh :: PopState( PRBool &aClipEmpty )
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::PopState\n"));
#ifdef NEW_GS
/* kirk 9/27/99 stole this code from GTK */
PRUint32 cnt = mStateCache->Count();
nsGraphicsState * state;
if (cnt > 0) {
state = (nsGraphicsState *)mStateCache->ElementAt(cnt - 1);
mStateCache->RemoveElementAt(cnt - 1);
// Assign all local attributes from the state object just popped
if (mTMatrix)
delete mTMatrix;
mTMatrix = state->mMatrix;
// get rid of the current clip region
NS_IF_RELEASE(mClipRegion);
mClipRegion = nsnull;
// restore everything
mClipRegion = (nsRegionPh *) state->mClipRegion;
mFontMetrics = state->mFontMetrics;
if (mSurface && mClipRegion)
{
// kirk what does this do?
// GdkRegion *rgn;
// mClipRegion->GetNativeRegion((void*&)rgn);
// ::gdk_gc_set_clip_region (mSurface->GetGC(), rgn);
}
ApplyClipping(mGC);
if (state->mColor != mCurrentColor)
SetColor(state->mColor);
if (state->mLineStyle != mCurrentLineStyle)
SetLineStyle(state->mLineStyle);
// Delete this graphics state object
#ifdef USE_GS_POOL
nsGraphicsStatePool::ReleaseGS(state);
#else
delete state;
#endif
}
if (mClipRegion)
aClipEmpty = mClipRegion->IsEmpty();
else
aClipEmpty = PR_TRUE;
return NS_OK;
#else
PRUint32 cnt = mStateCache->Count();
PRBool bEmpty=PR_FALSE;
//kedl ?? PRBool bEmpty=aClipEmpty;
@ -541,11 +610,11 @@ NS_IMETHODIMP nsRenderingContextPh :: PopState( PRBool &aClipEmpty )
NS_IF_RELEASE( mFontMetrics );
mFontMetrics = state->mFontMetrics;
if (mRegion)
delete mRegion;
if (mClipRegion)
delete mClipRegion;
mRegion = state->mClipRegion;
if ((mRegion) && (mRegion->IsEmpty() == PR_TRUE))
mClipRegion = state->mClipRegion;
if ((mClipRegion) && (mClipRegion->IsEmpty() == PR_TRUE))
{
bEmpty = PR_TRUE;
}
@ -560,6 +629,8 @@ NS_IMETHODIMP nsRenderingContextPh :: PopState( PRBool &aClipEmpty )
aClipEmpty = bEmpty;
return NS_OK;
#endif
}
@ -579,9 +650,9 @@ NS_IMETHODIMP nsRenderingContextPh :: SetClipRect(const nsRect& aRect, nsClipCom
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::SetClipRect (%ld,%ld,%ld,%ld)\n", aRect.x, aRect.y, aRect.width, aRect.height ));
if ((mTMatrix) && (mRegion))
if ((mTMatrix) && (mClipRegion))
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, (" prev clip empty = %i\n", mRegion->IsEmpty()));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, (" prev clip empty = %i\n", mClipRegion->IsEmpty()));
mTMatrix->TransformCoord(&trect.x, &trect.y,&trect.width, &trect.height);
@ -589,31 +660,31 @@ NS_IMETHODIMP nsRenderingContextPh :: SetClipRect(const nsRect& aRect, nsClipCom
{
case nsClipCombine_kIntersect:
PR_LOG(PhGfxLog, PR_LOG_DEBUG, (" combine type = intersect\n"));
mRegion->Intersect(trect.x,trect.y,trect.width,trect.height);
mClipRegion->Intersect(trect.x,trect.y,trect.width,trect.height);
break;
case nsClipCombine_kUnion:
PR_LOG(PhGfxLog, PR_LOG_DEBUG, (" combine type = union\n"));
mRegion->Union(trect.x,trect.y,trect.width,trect.height);
mClipRegion->Union(trect.x,trect.y,trect.width,trect.height);
break;
case nsClipCombine_kSubtract:
PR_LOG(PhGfxLog, PR_LOG_DEBUG, (" combine type = subtract\n"));
mRegion->Subtract(trect.x,trect.y,trect.width,trect.height);
mClipRegion->Subtract(trect.x,trect.y,trect.width,trect.height);
break;
case nsClipCombine_kReplace:
PR_LOG(PhGfxLog, PR_LOG_DEBUG, (" combine type = replace\n"));
mRegion->SetTo(trect.x,trect.y,trect.width,trect.height);
mClipRegion->SetTo(trect.x,trect.y,trect.width,trect.height);
break;
default:
PR_LOG(PhGfxLog, PR_LOG_ERROR, ("nsRenderingContextPh::SetClipRect Unknown Combine type\n"));
break;
}
aClipEmpty = mRegion->IsEmpty();
aClipEmpty = mClipRegion->IsEmpty();
PR_LOG(PhGfxLog, PR_LOG_DEBUG, (" new clip empty = %i\n", aClipEmpty ));
ApplyClipping(mGC);
// kirk mRegion->GetNativeRegion((void*&)rgn);
// kirk mClipRegion->GetNativeRegion((void*&)rgn);
// kirk PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::SetClipRect Calling PgSetCliping (%ld,%ld,%ld,%ld)\n", rgn->ul.x, rgn->ul.y, rgn->lr.x, rgn->lr.y));
// kirk PgSetClipping(1, rgn);
@ -633,9 +704,9 @@ NS_IMETHODIMP nsRenderingContextPh :: GetClipRect(nsRect &aRect, PRBool &aClipVa
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::GetClipRect\n"));
PRInt32 x, y, w, h;
if (!mRegion->IsEmpty())
if (!mClipRegion->IsEmpty())
{
mRegion->GetBoundingBox(&x,&y,&w,&h);
mClipRegion->GetBoundingBox(&x,&y,&w,&h);
aRect.SetRect(x,y,w,h);
aClipValid = PR_TRUE;
}
@ -656,20 +727,20 @@ NS_IMETHODIMP nsRenderingContextPh :: SetClipRegion(const nsIRegion& aRegion, ns
switch(aCombine)
{
case nsClipCombine_kIntersect:
mRegion->Intersect(aRegion);
mClipRegion->Intersect(aRegion);
break;
case nsClipCombine_kUnion:
mRegion->Union(aRegion);
mClipRegion->Union(aRegion);
break;
case nsClipCombine_kSubtract:
mRegion->Subtract(aRegion);
mClipRegion->Subtract(aRegion);
break;
case nsClipCombine_kReplace:
mRegion->SetTo(aRegion);
mClipRegion->SetTo(aRegion);
break;
}
aClipEmpty = mRegion->IsEmpty();
aClipEmpty = mClipRegion->IsEmpty();
ApplyClipping(mGC);
return NS_OK;
@ -684,6 +755,44 @@ NS_IMETHODIMP nsRenderingContextPh :: CopyClipRegion(nsIRegion &aRegion)
NS_IMETHODIMP nsRenderingContextPh :: GetClipRegion(nsIRegion **aRegion)
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::GetClipRegion\n"));
#ifdef NEW_GS
/* kirk 9/27/99 stole this from GTK */
nsresult rv = NS_ERROR_FAILURE;
if (!aRegion)
return NS_ERROR_NULL_POINTER;
if (*aRegion) // copy it, they should be using CopyClipRegion
{
// printf("you should be calling CopyClipRegion()\n");
(*aRegion)->SetTo(*mClipRegion);
rv = NS_OK;
}
else
{
if ( NS_SUCCEEDED(nsComponentManager::CreateInstance(kRegionCID, 0, NS_GET_IID(nsIRegion),
(void**)aRegion )) )
{
if (mClipRegion)
{
(*aRegion)->Init();
(*aRegion)->SetTo(*mClipRegion);
NS_ADDREF(*aRegion);
rv = NS_OK;
}
else
{
printf("null clip region, can't make a valid copy\n");
NS_RELEASE(*aRegion);
rv = NS_ERROR_FAILURE;
}
}
}
return rv;
#else
nsresult rv = NS_OK;
NS_ASSERTION(!(nsnull == aRegion), "no region ptr");
@ -708,10 +817,11 @@ NS_IMETHODIMP nsRenderingContextPh :: GetClipRegion(nsIRegion **aRegion)
if (rv == NS_OK)
{
(*aRegion)->SetTo(*mRegion);
(*aRegion)->SetTo(*mClipRegion);
}
return rv;
#endif
}
@ -739,7 +849,7 @@ NS_IMETHODIMP nsRenderingContextPh :: GetColor(nscolor &aColor) const
NS_IMETHODIMP nsRenderingContextPh :: SetLineStyle(nsLineStyle aLineStyle)
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::SetLineStyle\n"));
mLineStyle = aLineStyle;
mCurrentLineStyle = aLineStyle;
return NS_OK;
}
@ -747,7 +857,7 @@ NS_IMETHODIMP nsRenderingContextPh :: SetLineStyle(nsLineStyle aLineStyle)
NS_IMETHODIMP nsRenderingContextPh :: GetLineStyle(nsLineStyle &aLineStyle)
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::GetLineStyle - Not Implemented\n"));
aLineStyle = mLineStyle;
aLineStyle = mCurrentLineStyle;
return NS_OK;
}
@ -914,7 +1024,7 @@ NS_IMETHODIMP nsRenderingContextPh :: DrawLine(nscoord aX0, nscoord aY0, nscoord
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::DrawLine (%ld,%ld,%ld,%ld)\n", aX0, aY0, aX1, aY1 ));
if( nsLineStyle_kNone == mLineStyle )
if( nsLineStyle_kNone == mCurrentLineStyle )
return NS_OK;
nscoord x0,y0,x1,y1;
@ -941,7 +1051,7 @@ NS_IMETHODIMP nsRenderingContextPh :: DrawPolyline(const nsPoint aPoints[], PRIn
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("untested nsRenderingContextPh::DrawPolyLine\n"));
if( nsLineStyle_kNone == mLineStyle )
if( nsLineStyle_kNone == mCurrentLineStyle )
return NS_OK;
PhPoint_t *pts;
@ -973,7 +1083,7 @@ NS_IMETHODIMP nsRenderingContextPh :: DrawPolyline(const nsPoint aPoints[], PRIn
NS_IMETHODIMP nsRenderingContextPh :: DrawRect(const nsRect& aRect)
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("untested nsRenderingContextPh::DrawRect\n"));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("untested nsRenderingContextPh::DrawRect 1 \n"));
DrawRect( aRect.x, aRect.y, aRect.width, aRect.height );
@ -983,7 +1093,7 @@ NS_IMETHODIMP nsRenderingContextPh :: DrawRect(const nsRect& aRect)
NS_IMETHODIMP nsRenderingContextPh :: DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("untested nsRenderingContextPh::DrawRect\n"));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("untested nsRenderingContextPh::DrawRect 2 \n"));
nscoord x,y,w,h;
@ -1002,7 +1112,7 @@ NS_IMETHODIMP nsRenderingContextPh :: DrawRect(nscoord aX, nscoord aY, nscoord a
NS_IMETHODIMP nsRenderingContextPh :: FillRect(const nsRect& aRect)
{
// PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::FillRect (%i,%i,%i,%i)\n", aRect.x, aRect.y, aRect.width, aRect.height ));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::FillRect 1 (%i,%i,%i,%i)\n", aRect.x, aRect.y, aRect.width, aRect.height ));
FillRect( aRect.x, aRect.y, aRect.width, aRect.height );
@ -1012,7 +1122,7 @@ NS_IMETHODIMP nsRenderingContextPh :: FillRect(const nsRect& aRect)
NS_IMETHODIMP nsRenderingContextPh :: FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::FillRect (%i,%i,%i,%i)\n", aX, aY, aWidth, aHeight ));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::FillRect 2 (%i,%i,%i,%i)\n", aX, aY, aWidth, aHeight ));
nscoord x,y,w,h;
x = aX;
@ -1023,7 +1133,6 @@ NS_IMETHODIMP nsRenderingContextPh :: FillRect(nscoord aX, nscoord aY, nscoord a
mTMatrix->TransformCoord(&x,&y,&w,&h);
SELECT(mSurface);
PgDrawIRect( x, y, x + w - 1, y + h - 1, Pg_DRAW_FILL_STROKE );
// PgDrawIRect( x, y, x + w - 1, y + h - 1, Pg_DRAW_FILL );
return NS_OK;
}
@ -1031,7 +1140,6 @@ NS_IMETHODIMP nsRenderingContextPh :: FillRect(nscoord aX, nscoord aY, nscoord a
NS_IMETHODIMP
nsRenderingContextPh :: InvertRect(const nsRect& aRect)
{
// NS_NOTYETIMPLEMENTED("nsRenderingContextPh::InvertRect");
InvertRect( aRect.x, aRect.y, aRect.width, aRect.height );
return NS_OK;
@ -1043,8 +1151,6 @@ nsRenderingContextPh :: InvertRect(const nsRect& aRect)
NS_IMETHODIMP
nsRenderingContextPh :: InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
{
// NS_NOTYETIMPLEMENTED("nsRenderingContextPh::InvertRect");
nscoord x,y,w,h;
x = aX;
@ -1534,16 +1640,22 @@ NS_IMETHODIMP nsRenderingContextPh :: CopyOffScreenBits(nsDrawingSurface aSrcSur
const nsRect &aDestBounds,
PRUint32 aCopyFlags)
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::CopyOffScreenBits.\n"));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::CopyOffScreenBits this=<%p> aSrcSurf=<%p> aSrcPt=(%d,%d) aCopyFlags=<%d> DestRect=<%d,%d,%d,%d>\n",
this, aSrcSurf, aSrcX, aSrcY, aCopyFlags, aDestBounds.x, aDestBounds.y, aDestBounds.width, aDestBounds.height));
PhArea_t area;
PhArea_t area;
PRInt32 srcX = aSrcX;
PRInt32 srcY = aSrcY;
nsRect drect = aDestBounds;
nsDrawingSurfacePh *destsurf;
nsDrawingSurfacePh *destsurf;
PhGC_t *saveGC=PgGetGC();
if ( (aSrcSurf==NULL) || (mTMatrix==NULL) || (mSurface==NULL))
{
NS_ASSERTION(0, "nsRenderingContextPh::CopyOffScreenBits STarted with NULL pointer");
return NS_ERROR_FAILURE;
}
PhGC_t *saveGC = PgGetGC();
if (aCopyFlags & NS_COPYBITS_TO_BACK_BUFFER)
{
@ -1555,7 +1667,7 @@ NS_IMETHODIMP nsRenderingContextPh :: CopyOffScreenBits(nsDrawingSurface aSrcSur
if( mBufferIsEmpty )
{
PR_LOG(PhGfxLog, PR_LOG_DEBUG, (" Buffer empty, skipping.\n"));
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::CopyOffScreenBits Buffer empty, skipping.\n"));
SELECT( destsurf );
PgSetGC(saveGC);
return NS_OK;
@ -1594,14 +1706,15 @@ NS_IMETHODIMP nsRenderingContextPh :: CopyOffScreenBits(nsDrawingSurface aSrcSur
// printf ("location: %d, %p %p (%d %d) %d %d %d %d\n",aCopyFlags,aSrcSurf,destsurf,srcX,srcY,area.pos.x,area.pos.y,area.size.w,area.size.h);
nsRect rect;
PRBool valid;
GetClipRect(rect,valid);
if (valid)
{
// printf ("clip: %d %d %d %d\n",rect.x,rect.y,rect.width,rect.height);
area.size.w = rect.width; area.size.h = rect.height;
}
nsRect rect;
PRBool valid;
GetClipRect(rect,valid);
if (valid)
{
//printf ("clip: %d %d %d %d\n",rect.x,rect.y,rect.width,rect.height);
area.size.w = rect.width;
area.size.h = rect.height;
}
((nsDrawingSurfacePh *)aSrcSurf)->Stop();
PhImage_t *image;
@ -1661,14 +1774,6 @@ printf ("unimp pushclipstate\n");
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::PushClipState - Not implemented.\n"));
}
NS_IMETHODIMP nsRenderingContextPh :: CreateDrawingSurface( PhGC_t *aGC, nsDrawingSurface &aSurface)
{
printf ("unimp createdrawingsurface\n");
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsRenderingContextPh::CreateDrawingSurface - Not implemented.\n"));
return NS_OK;
}
void nsRenderingContextPh::ApplyClipping( PhGC_t *gc )
{
@ -1686,7 +1791,7 @@ rid = gc->rid;
//PtArg_t arg;
//PhPoint_t *pos;
if (mRegion)
if (mClipRegion)
{
PhRegion_t my_region;
PhRect_t rect = {{0,0},{0,0}};
@ -1704,7 +1809,7 @@ rid = gc->rid;
//printf ("clip widget: %p %d %d\n",mWidget,pos->x,pos->y);
/* no offset needed use the normal tile list */
mRegion->GetNativeRegion((void*&)tiles);
mClipRegion->GetNativeRegion((void*&)tiles);
if (tiles != nsnull)
{
@ -1725,7 +1830,7 @@ rid = gc->rid;
void nsRenderingContextPh::SetPhLineStyle()
{
switch( mLineStyle )
switch( mCurrentLineStyle )
{
case nsLineStyle_kSolid:
PgSetStrokeDash( nsnull, 0, 0x10000 );

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

@ -30,21 +30,19 @@
#include "nsIViewManager.h"
#include "nsIWidget.h"
#include "nsRect.h"
//#include "nsImagePh.h"
#include "nsIDeviceContext.h"
#include "nsVoidArray.h"
#include "nsIRenderingContextPh.h"
//#include "nsIRenderingContextPh.h"
#include "nsDrawingSurfacePh.h"
//#include "nsRegionPh.h"
class GraphicsState;
class nsDrawingSurfacePh;
class nsImagePh;
class nsIRegion;
class nsRegionPh;
class nsRenderingContextPh : public nsIRenderingContext,
nsIRenderingContextPh
class nsRenderingContextPh : public nsIRenderingContext
{
public:
nsRenderingContextPh();
@ -159,7 +157,7 @@ public:
NS_IMETHOD RetrieveCurrentNativeGraphicData(PRUint32 * ngd);
// nsIRenderingContextPh
NS_IMETHOD CreateDrawingSurface(PhGC_t *aGC, nsDrawingSurface &aSurface);
// NS_IMETHOD CreateDrawingSurface(PhGC_t *aGC, nsDrawingSurface &aSurface);
private:
~nsRenderingContextPh();
@ -176,7 +174,7 @@ protected:
PhGC_t *mholdGC;
PhGC_t *mOldGC;
nscolor mCurrentColor;
nsLineStyle mLineStyle;
nsLineStyle mCurrentLineStyle;
nsTransform2D *mTMatrix; // transform that all the graphics drawn here will obey
nsIFontMetrics *mFontMetrics;
nsDrawingSurfacePh *mOffscreenSurface;
@ -185,7 +183,7 @@ protected:
nsIWidget *mDCOwner;
nsIDeviceContext *mContext;
float mP2T;
nsRegionPh *mRegion;
nsIRegion *mClipRegion;
PtWidget_t *mWidget;
char *mPhotonFontName;
nsRegionPh *mGlobalClip;
@ -196,12 +194,9 @@ protected:
nsVoidArray *mStateCache;
PRUint8 *mGammaTable;
static PhGC_t *mPtGC;
static PhGC_t *mPtGC; /* Default Photon Graphics Context */
PRBool mBufferIsEmpty;
#ifdef NS_DEBUG
PRBool mInitialized;
#endif
};
#endif /* nsRenderingContextPh_h___ */