mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-24 19:37:15 +00:00
First Checked In.
This commit is contained in:
parent
6d91d63140
commit
991eac0d10
221
gfx/src/mac/nsGraphicState.cpp
Normal file
221
gfx/src/mac/nsGraphicState.cpp
Normal file
@ -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<nsDrawingSurfaceMac*>(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;
|
||||
}
|
||||
|
92
gfx/src/mac/nsGraphicState.h
Normal file
92
gfx/src/mac/nsGraphicState.h
Normal file
@ -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 <QuickDraw.h>
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
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? <anonymous>
|
||||
// - no thanks, <pierre>
|
||||
|
||||
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___
|
3
lib/mac/NSRuntime/ProfilerExport.exp
Normal file
3
lib/mac/NSRuntime/ProfilerExport.exp
Normal file
@ -0,0 +1,3 @@
|
||||
#library
|
||||
__PROFILE_EXIT
|
||||
__PROFILE_ENTRY
|
10
lib/mac/NSStdLib/ProfilerExport.exp
Normal file
10
lib/mac/NSStdLib/ProfilerExport.exp
Normal file
@ -0,0 +1,10 @@
|
||||
#library
|
||||
__PROFILE_EXIT
|
||||
__PROFILE_ENTRY
|
||||
|
||||
#utils
|
||||
ProfileStart
|
||||
ProfileStop
|
||||
ProfileSuspend
|
||||
ProfileResume
|
||||
ProfileInProgress
|
31
lib/mac/NSStdLib/include/ProfilerUtils.h
Normal file
31
lib/mac/NSStdLib/include/ProfilerUtils.h
Normal file
@ -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
|
71
lib/mac/NSStdLib/src/ProfilerUtils.c
Normal file
71
lib/mac/NSStdLib/src/ProfilerUtils.c
Normal file
@ -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 <profiler.h>
|
||||
#include <Events.h>
|
||||
#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
|
Loading…
x
Reference in New Issue
Block a user