diff --git a/mozilla/gfx/src/mac/nsGraphicState.cpp b/mozilla/gfx/src/mac/nsGraphicState.cpp new file mode 100644 index 00000000000..da2099241dc --- /dev/null +++ b/mozilla/gfx/src/mac/nsGraphicState.cpp @@ -0,0 +1,221 @@ +/* -*- 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 "nsGraphicState.h" +#include "nsDrawingSurfaceMac.h" +#include "nsTransform2D.h" +#include "nsRegionMac.h" + + +nsGraphicStatePool sGraphicStatePool; + + +//------------------------------------------------------------------------ + +nsGraphicStatePool::nsGraphicStatePool() +{ + for (short i = 0; i < kGSPoolCount; i ++) + { + mGSArray[i].mGS = new nsGraphicState(); + mGSArray[i].mFree = PR_TRUE; + } +} + +//------------------------------------------------------------------------ + +nsGraphicStatePool::~nsGraphicStatePool() +{ + for (short i = 0; i < kGSPoolCount; i ++) + { + delete mGSArray[i].mGS; + } +} + +//------------------------------------------------------------------------ + +nsGraphicState* nsGraphicStatePool::GetNewGS() +{ + for (short i = 0; i < kGSPoolCount; i ++) + { + if (mGSArray[i].mFree) + { + mGSArray[i].mFree = PR_FALSE; + return mGSArray[i].mGS; + } + } + return (new nsGraphicState()); // we overflew the pool: return a new GraphicState +} + +//------------------------------------------------------------------------ + +void nsGraphicStatePool::ReleaseGS(nsGraphicState* aGS) +{ + for (short i = 0; i < kGSPoolCount; i ++) + { + if (mGSArray[i].mGS == aGS) + { + mGSArray[i].mGS->Clear(); + mGSArray[i].mFree = PR_TRUE; + return; + } + } + delete aGS; // we overflew the pool: delete the GraphicState +} + + +#pragma mark - +//------------------------------------------------------------------------ + +nsGraphicState::nsGraphicState() +{ + // everything is initialized to 0 through the 'new' operator +} + +//------------------------------------------------------------------------ + +nsGraphicState::~nsGraphicState() +{ + Clear(); +} + +//------------------------------------------------------------------------ + +void nsGraphicState::Clear() +{ + if (mTMatrix) + { + delete mTMatrix; + mTMatrix = nsnull; + } + + if (mMainRegion) + { + sNativeRegionPool.ReleaseRegion(mMainRegion); //::DisposeRgn(mMainRegion); + mMainRegion = nsnull; + } + + if (mClipRegion) + { + sNativeRegionPool.ReleaseRegion(mClipRegion); //::DisposeRgn(mClipRegion); + mClipRegion = nsnull; + } + + NS_IF_RELEASE(mFontMetrics); + + mOffx = 0; + mOffy = 0; + mColor = NS_RGB(255,255,255); + mFont = 0; + mFontMetrics = nsnull; + mCurrFontHandle = 0; +} + +//------------------------------------------------------------------------ + +void nsGraphicState::Init(nsDrawingSurface aSurface) +{ + // retrieve the grafPort + nsDrawingSurfaceMac* surface = static_cast(aSurface); + GrafPtr port; + surface->GetGrafPtr(&port); + + // init from grafPort + Init(port); +} + +//------------------------------------------------------------------------ + +void nsGraphicState::Init(GrafPtr aPort) +{ + // delete old values + Clear(); + + // init from grafPort (usually an offscreen port) + RgnHandle rgn = sNativeRegionPool.GetNewRegion(); //::NewRgn(); +#if TARGET_CARBON + if ( rgn ) { + Rect bounds; + ::RectRgn(rgn, ::GetPortBounds(aPort, &bounds)); + } +#else + if (rgn) + ::RectRgn(rgn, &aPort->portRect); +#endif + + mMainRegion = rgn; + mClipRegion = DuplicateRgn(rgn); +} + +//------------------------------------------------------------------------ + +void nsGraphicState::Init(nsIWidget* aWindow) +{ + // delete old values + Clear(); + + // init from widget + mOffx = (PRInt32)aWindow->GetNativeData(NS_NATIVE_OFFSETX); + mOffy = (PRInt32)aWindow->GetNativeData(NS_NATIVE_OFFSETY); + + RgnHandle widgetRgn = (RgnHandle)aWindow->GetNativeData(NS_NATIVE_REGION); + mMainRegion = DuplicateRgn(widgetRgn); + mClipRegion = DuplicateRgn(widgetRgn); +} + +//------------------------------------------------------------------------ + +void nsGraphicState::Duplicate(nsGraphicState* aGS) +{ + // delete old values + Clear(); + + // copy new ones + if (aGS->mTMatrix) + mTMatrix = new nsTransform2D(aGS->mTMatrix); + else + mTMatrix = nsnull; + + mOffx = aGS->mOffx; + mOffy = aGS->mOffy; + + mMainRegion = DuplicateRgn(aGS->mMainRegion); + mClipRegion = DuplicateRgn(aGS->mClipRegion); + + mColor = aGS->mColor; + mFont = aGS->mFont; + mFontMetrics = aGS->mFontMetrics; + NS_IF_ADDREF(mFontMetrics); + + mCurrFontHandle = aGS->mCurrFontHandle; +} + + +//------------------------------------------------------------------------ + +RgnHandle nsGraphicState::DuplicateRgn(RgnHandle aRgn) +{ + RgnHandle dupRgn = nsnull; + if (aRgn) + { + dupRgn = sNativeRegionPool.GetNewRegion(); //::NewRgn(); + if (dupRgn) + ::CopyRgn(aRgn, dupRgn); + } + return dupRgn; +} + diff --git a/mozilla/gfx/src/mac/nsGraphicState.h b/mozilla/gfx/src/mac/nsGraphicState.h new file mode 100644 index 00000000000..68087141d10 --- /dev/null +++ b/mozilla/gfx/src/mac/nsGraphicState.h @@ -0,0 +1,92 @@ +/* -*- 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 nsGraphicState_h___ +#define nsGraphicState_h___ + +#include "nsIRenderingContext.h" +#include "nsCRT.h" +#include + +//------------------------------------------------------------------------ + +class nsGraphicState +{ +public: + nsGraphicState(); + ~nsGraphicState(); + + NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW + + void Clear(); + void Init(nsDrawingSurface aSurface); + void Init(GrafPtr aPort); + void Init(nsIWidget* aWindow); + void Duplicate(nsGraphicState* aGS); // would you prefer an '=' operator? + // - no thanks, + +protected: + RgnHandle DuplicateRgn(RgnHandle aRgn); + +public: + nsTransform2D * mTMatrix; // transform that all the graphics drawn here will obey + + PRInt32 mOffx; + PRInt32 mOffy; + + RgnHandle mMainRegion; + RgnHandle mClipRegion; + + nscolor mColor; + PRInt32 mFont; + nsIFontMetrics * mFontMetrics; + PRInt32 mCurrFontHandle; +}; + +//------------------------------------------------------------------------ + +class nsGraphicStatePool +{ +public: + nsGraphicStatePool(); + ~nsGraphicStatePool(); + + nsGraphicState* GetNewGS(); + void ReleaseGS(nsGraphicState* aGS); + +private: + static const short kGSPoolCount = 80; // sizeof(nsGraphicState) = 36 bytes + + typedef struct nsGSRec + { + nsGraphicState* mGS; + PRBool mFree; + } nsGSRec; + + nsGSRec mGSArray[kGSPoolCount]; +}; + +//------------------------------------------------------------------------ + +extern nsGraphicStatePool sGraphicStatePool; + +//------------------------------------------------------------------------ + + +#endif //nsGraphicState_h___ diff --git a/mozilla/lib/mac/NSRuntime/ProfilerExport.exp b/mozilla/lib/mac/NSRuntime/ProfilerExport.exp new file mode 100644 index 00000000000..68e7d4e9f61 --- /dev/null +++ b/mozilla/lib/mac/NSRuntime/ProfilerExport.exp @@ -0,0 +1,3 @@ +#library +__PROFILE_EXIT +__PROFILE_ENTRY diff --git a/mozilla/lib/mac/NSStdLib/ProfilerExport.exp b/mozilla/lib/mac/NSStdLib/ProfilerExport.exp new file mode 100644 index 00000000000..06f1874cb64 --- /dev/null +++ b/mozilla/lib/mac/NSStdLib/ProfilerExport.exp @@ -0,0 +1,10 @@ +#library +__PROFILE_EXIT +__PROFILE_ENTRY + +#utils +ProfileStart +ProfileStop +ProfileSuspend +ProfileResume +ProfileInProgress diff --git a/mozilla/lib/mac/NSStdLib/include/ProfilerUtils.h b/mozilla/lib/mac/NSStdLib/include/ProfilerUtils.h new file mode 100644 index 00000000000..2a9988397eb --- /dev/null +++ b/mozilla/lib/mac/NSStdLib/include/ProfilerUtils.h @@ -0,0 +1,31 @@ +/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */ +/* + * 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. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +extern void ProfileStart(); +extern void ProfileStop(); +extern void ProfileSuspend(); +extern void ProfileResume(); +extern Boolean ProfileInProgress(); + +#ifdef __cplusplus +} +#endif diff --git a/mozilla/lib/mac/NSStdLib/src/ProfilerUtils.c b/mozilla/lib/mac/NSStdLib/src/ProfilerUtils.c new file mode 100644 index 00000000000..0612ddd412a --- /dev/null +++ b/mozilla/lib/mac/NSStdLib/src/ProfilerUtils.c @@ -0,0 +1,71 @@ +/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */ +/* + * 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. + */ + + +#ifdef DEBUG + +#include +#include +#include "ProfilerUtils.h" + +//--------------------------------------------- + +static Boolean sProfileInProgress = false; +void ProfileStart() +{ + if (! sProfileInProgress) + { + sProfileInProgress = true; + if (ProfilerInit(collectDetailed, microsecondsTimeBase, 5000, 500)) + return; + ProfilerSetStatus(true); + } +} + +//--------------------------------------------- +void ProfileStop() +{ + if (sProfileInProgress) + { + ProfilerDump("\pMozilla Profile"); + ProfilerTerm(); + sProfileInProgress = false; + } +} + +//--------------------------------------------- +void ProfileSuspend() +{ + if (sProfileInProgress) + ProfilerSetStatus(false); +} + +//--------------------------------------------- +void ProfileResume() +{ + if (sProfileInProgress) + ProfilerSetStatus(true); +} + +//--------------------------------------------- +Boolean ProfileInProgress() +{ + return sProfileInProgress; +} + +#endif //DEBUG