[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]
[XaraXtreme-dev] Commit Complete
Commit by : luke
Repository : xara
Revision : 707
Date : Wed Mar 22 15:54:20 GMT 2006
Changed paths:
M /Trunk/XaraLX/Kernel/fntcache.cpp
M /Trunk/XaraLX/Kernel/fntcache.h
M /Trunk/XaraLX/Kernel/gcache.cpp
M /Trunk/XaraLX/Kernel/gcache.h
Martin Wuerthners fixes for CamCache
Diff:
Index: Trunk/XaraLX/Kernel/fntcache.h
===================================================================
--- Trunk/XaraLX/Kernel/fntcache.h (revision 706)
+++ Trunk/XaraLX/Kernel/fntcache.h (revision 707)
@@ -133,14 +133,14 @@
********************************************************************************************/
-// The simpler FontCache defined below is simply a wrapper around a GCache
+// The simpler FontCache defined below is simply a wrapper around a CamCache
class FontCache
{
// All data/methods must be static
public:
- // This method must be called before we can use the GCache
+ // This method must be called before we can use the CamCache
static BOOL Init();
static BOOL InitCalled; // = FALSE, set to TRUE only if Init function has been called
@@ -152,7 +152,7 @@
static BOOL GetPath(CharDescription& ChDesc, INT32** Points, BYTE** Types, UINT32 *Length);
// The path cache is used to map a Path Handle to path data
- static GCache* pPathCache;
+ static CamCache* pPathCache;
static BOOL GetBounds(DocRect* pBounds, CharDescription& CharDesc);
static BOOL CalcDefaultCharBounds(DocRect* pRect, CharDescription& CharDesc);
@@ -281,7 +281,7 @@
public:
- // This method must be called before we can use the GCache
+ // This method must be called before we can use the CamCache
static BOOL Init();
static BOOL InitCalled; // = FALSE, set to TRUE only if Init function has been called
@@ -324,7 +324,7 @@
INT32** Points, BYTE** Types, UINT32* Length);
// The path cache is used to map a Path Handle to path data
- static GCache* pPathCache;
+ static CamCache* pPathCache;
static PathHandleItem* AllocatePathHandle(UINT32 Key, CharDescription& ChDesc);
Index: Trunk/XaraLX/Kernel/gcache.cpp
===================================================================
--- Trunk/XaraLX/Kernel/gcache.cpp (revision 706)
+++ Trunk/XaraLX/Kernel/gcache.cpp (revision 707)
@@ -102,28 +102,36 @@
*/
#include "camtypes.h"
-#include <afxwin.h>
-#include <iostream.h>
-#include "gcmaths.h"
+//#include <afxwin.h>
+#include <iostream>
+//#include "gcmaths.h"
#include "gcache.h"
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
-GCache::GCache( size_t Size, UINT32 Log2MaxEntries )
+CamCache::CamCache( size_t Size, UINT32 Log2MaxEntries )
{
HashTableSize = 1<<Log2MaxEntries ;
HashTableMask = HashTableSize-1 ;
HashTable = NULL ;
CacheStart = NULL ;
- TRY {
- HashTable = new ( CacheBlock* [HashTableSize] ) ;
- CacheStart = (CacheBlock*) new BYTE[Size+2*FreeCacheBlockSize] ;
- } CATCH_ALL (e) {
- delete [] HashTable ; HashTable = NULL ;
- delete [] CacheStart ; CacheStart = NULL ;
+
+ HashTable = new ( CacheBlock* [HashTableSize] ) ;
+ CacheStart = (CacheBlock*) new BYTE[Size+2*FreeCacheBlockSize] ;
+
+ if (!HashTable || !CacheStart)
+ {
+ if (HashTable)
+ {
+ delete [] HashTable ; HashTable = NULL ;
+ }
+ if (CacheStart)
+ {
+ delete [] CacheStart ; CacheStart = NULL ;
+ }
return ;
- } END_CATCH_ALL ;
+ }
for ( size_t i=0 ; i<HashTableSize ; i++ )
HashTable[i] = NULL ;
CacheBlock *FreeBlock ;
@@ -143,16 +151,16 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
//
-// Verify should be used after creation of a GCache object to ensure that it was created OK.
+// Verify should be used after creation of a CamCache object to ensure that it was created OK.
//
-BOOL GCache::Verify()
+BOOL CamCache::Verify()
{
return HashTable && CacheStart ;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
-GCache::~GCache()
+CamCache::~CamCache()
{
delete [] HashTable ; HashTable = NULL ;
delete [] CacheStart ; CacheStart = NULL ;
@@ -161,7 +169,7 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
-BOOL GCache::FindPath( UINT32 Handle, INT32* &Points, BYTE* &Types, UINT32 &Length )
+BOOL CamCache::FindPath( UINT32 Handle, INT32* &Points, BYTE* &Types, UINT32 &Length )
{
INT32 *Object = (INT32*) FindEntry( Handle ) ;
if ( Object )
@@ -173,12 +181,13 @@
return Object!=NULL ;
}
-void GCache::AddPath( UINT32 Handle, INT32* Points, BYTE* Types, UINT32 Length )
+void CamCache::AddPath( UINT32 Handle, INT32* Points, BYTE* Types, UINT32 Length )
{
INT32 *DPtr = (INT32*) AddEntry( Handle,Length*9+4 ) ;
*DPtr++ = Length ;
INT32 *SPtr = Points ;
- for ( size_t i=0 ; i<2*Length ; i++ )
+ size_t i;
+ for ( i=0 ; i<2*Length ; i++ )
*DPtr++ = *SPtr++ ;
SPtr = (INT32*) Types ;
Length = (Length+3)>>2 ; /* Word length */
@@ -189,12 +198,15 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
-char* GCache::FindString( UINT32 Handle )
+PORTNOTE("other","not used - removed because AddString looks dodgy")
+#ifndef EXCLUDE_FROM_XARALX
+
+char* CamCache::FindString( UINT32 Handle )
{
return (char*) FindEntry( Handle ) ;
}
-void GCache::AddString( UINT32 Handle, char* String )
+void CamCache::AddString( UINT32 Handle, char* String )
{
size_t StringLength = cc_strlenBytes(String)+1 ; /* Byte length */
INT32 *SPtr = (INT32*) String ;
@@ -203,12 +215,23 @@
for ( size_t i=0 ; i<StringLength ; i++ )
*DPtr++ = *SPtr++ ;
}
+#endif
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
-void* GCache::FindEntry( UINT32 Handle )
+// converted from asm function in gcmaths
+UINT32 Hash(UINT32 val)
{
+ val ^= (val << 7) | (val >> 25);
+ val ^= (val << 11) | (val >> 21);
+ val ^= (val << 19) | (val >> 13);
+ val ^= (val << 16) | (val >> 16);
+ return val;
+}
+
+void* CamCache::FindEntry( UINT32 Handle )
+{
UINT32 HashIndex = Hash( Handle ) & HashTableMask ;
CacheBlock *Ptr = HashTable[HashIndex] ;
while ( Ptr )
@@ -237,7 +260,7 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
-void* GCache::AddEntry( UINT32 Handle, size_t ObjectSize )
+void* CamCache::AddEntry( UINT32 Handle, size_t ObjectSize )
{
UINT32 HashIndex = Hash( Handle ) & HashTableMask ;
CacheBlock *Ptr = HashTable[HashIndex] ;
@@ -324,7 +347,7 @@
#ifdef _DEBUG
-ostream& operator << ( ostream& os, GCache& Cache )
+ostream& operator << ( ostream& os, CamCache& Cache )
{
for ( size_t i=0 ; i<Cache.HashTableSize ; i++ )
{
@@ -349,7 +372,9 @@
<< ", " << Ptr->PrevUsed << "," << Ptr->NextUsed
<< ", " << Ptr->Link << "," << Ptr->Handle
<< ", " << (char*) Ptr->Object << " (" << hex
+#ifndef EXCLUDE_FROM_XARALX
<< Cache.BlockSize(Ptr)-UsedCacheBlockSize-cc_strlenBytes((char*)Ptr->Object)-1
+#endif
<< dec << ")" << endl ;
Ptr = Ptr->Next ;
}
Index: Trunk/XaraLX/Kernel/fntcache.cpp
===================================================================
--- Trunk/XaraLX/Kernel/fntcache.cpp (revision 706)
+++ Trunk/XaraLX/Kernel/fntcache.cpp (revision 707)
@@ -101,7 +101,7 @@
/*
// */
-// To resolve: allocation of GCache
+// To resolve: allocation of CamCache
// Set CACHE_STATS to 0 if you don't want loads of TRACE
@@ -117,7 +117,9 @@
#include "grndrgn.h"
#include "gdraw.h"
#include "fontman.h"
+#ifdef RALPH
#include "ralphcri.h"
+#endif
#define CACHE_STATS 0
#define new CAM_DEBUG_NEW
@@ -136,7 +138,7 @@
// statics ...
BOOL FontCache::InitCalled = FALSE; // Set to TRUE on entry to Init function
-GCache* FontCache::pPathCache;
+CamCache* FontCache::pPathCache;
INT32 FontCache::BoundsEntries = 0; // number of entries in char bounds cache
@@ -169,7 +171,7 @@
BoundsEntries = 0; // reset number of char bounds cached
// Try to allocate our path cache
- pPathCache = new GCache();
+ pPathCache = new CamCache();
ERROR1IF(pPathCache == NULL, FALSE, _R(IDE_NOMORE_MEMORY));
return TRUE;
}
@@ -328,7 +330,7 @@
ERROR2IF(pBounds==NULL,FALSE,"FontCache::GetBounds() - pBounds==NULL");
// static cache
- const MaxBoundsEntries = 128;
+ const INT32 MaxBoundsEntries = 128;
static AttrdCharBoundsCacheEntry entry[MaxBoundsEntries];
// search cache for desired char
@@ -376,8 +378,6 @@
RalphCriticalSection RalphCS;
#endif
-#if REAL_GDRAW
-
ERROR2IF(pRect==NULL,FALSE,"FontCache::CalcCharBounds() - pRect==NULL");
// create the char's default path
@@ -387,6 +387,7 @@
// calculate the path's bounds
BOOL ok=TRUE;
+ RECT DrawRect = {0, 0, 0, 0};
DocRect TempRect(0,0,0,0);
INT32 points=pCharPath->GetNumCoords();
if (points!=0)
@@ -403,14 +404,27 @@
if (pGDC == NULL)
ok = FALSE;
else
- ok = !pGDC->CalcStrokeBBox((POINT*)pCoords, pVerbs, points, (tagRECT*)(&TempRect), pCharPath->IsFilled, 0, CAPS_BUTT, JOIN_BEVEL, NULL);
+ ok = !pGDC->CalcStrokeBBox((POINT*)pCoords, pVerbs, points, &DrawRect, pCharPath->IsFilled, 0, CAPS_BUTT, JOIN_BEVEL, NULL);
+ // TRACEUSER("wuerthne", _T("CDraw returned %d bbox from CDraw is %d, %d, %d, %d"), ok, DrawRect.left, DrawRect.top, DrawRect.right, DrawRect.bottom);
// if the call to GDraw failed then we fall back to calculating the bounds from the points bounding box.
- if (!ok)
+ if (ok)
{
- TRACE( _T("GDraw CalcStrokeBBox failed (GetLastError=%d) for the following path"), GetLastError());
- pCharPath->DumpPath();
-
+ // GDraw did the job, so copy over the result from its RECT structure
+ // NB: The following assignment *looks* wrong because top and bottom seem to be swapped over,
+ // but it is correct! The fields in RECT are just named in a strange way - GDraw certainly
+ // has the same view of the structure as DocRect, so we only need to copy the fields over
+ // in the order as they are defined and things are OK. Alternatively, we could pass a pointer
+ // to a DocRect to GDraw but this would break things if ever someone changed the representation
+ // of DocRect. I hope noone changes the field names in RECT - the ENSURE protects us:
+ ENSURE(&DrawRect.bottom > &DrawRect.right && &DrawRect.right > &DrawRect.top && &DrawRect.top > &DrawRect.left,
+ "Incompatible change of RECT structure");
+ TempRect = DocRect(DrawRect.left, DrawRect.top, DrawRect.right, DrawRect.bottom);
+ }
+ else
+ {
+ // GDraw failed, so scan the coordinates
+ // pCharPath->DumpPath();
TempRect = pCharPath->GetBoundingRect();
ok = TRUE; // Well not really !
}
@@ -421,10 +435,6 @@
delete pCharPath;
if (ok) *pRect=TempRect;
return ok;
-
-#else
- ERROR2(FALSE,"FontCache::CalcCharBounds() - GDraw does not exist in this build!!!!");
-#endif
}
@@ -488,7 +498,7 @@
PathHandleItem* FontCache::CacheB [CACHE_LIST_SIZE];
PathHandleItem** FontCache::PrimaryC;
PathHandleItem** FontCache::SecondaryC;
-GCache* FontCache::pPathCache;
+CamCache* FontCache::pPathCache;
UINT32 FontCache::NextUniquePathHandle;
UINT32 FontCache::NumItemsInPrimaryCache;
@@ -559,7 +569,7 @@
NumItemsInPrimaryCache = 0;
// Try to allocate our path cache
- pPathCache = new GCache();
+ pPathCache = new CamCache();
ERROR1IF(pPathCache == NULL, FALSE, _R(IDE_NOMORE_MEMORY));
return TRUE;
}
@@ -788,7 +798,7 @@
DeleteCacheLists(PrimaryC);
DeleteCacheLists(SecondaryC);
- // We must also clear the GCache, there is no function to do this so we will
+ // We must also clear the CamCache, there is no function to do this so we will
// use the destructor.
delete (pPathCache);
@@ -910,7 +920,7 @@
// of memory before.
// try to allocate one
- pPathCache = new GCache();
+ pPathCache = new CamCache();
ERROR1IF(pPathCache == NULL, FALSE, _R(IDE_NOMORE_MEMORY));
}
Index: Trunk/XaraLX/Kernel/gcache.h
===================================================================
--- Trunk/XaraLX/Kernel/gcache.h (revision 706)
+++ Trunk/XaraLX/Kernel/gcache.h (revision 707)
@@ -163,15 +163,15 @@
************************************************************************************************/
-class GCache
+class CamCache
{
#ifdef _DEBUG
- friend ostream& operator << ( ostream& os, GCache& Cache ) ;
+ friend ostream& operator << ( ostream& os, CamCache& Cache ) ;
#endif
public:
- GCache( size_t Size = 0x40000, UINT32 Log2MaxEntries = 12 ) ;
- ~GCache() ;
+ CamCache( size_t Size = 0x40000, UINT32 Log2MaxEntries = 12 ) ;
+ ~CamCache() ;
BOOL Verify() ;
BOOL FindPath( UINT32 Handle, INT32* &Points, BYTE* &Types, UINT32 &Length ) ;
Xara