Esempio n. 1
0
void VboManager::FreeObject(VboObject* object)
{
	if (object)
	{
		VboBufRec& data = vBuffers[object->GetBufferId()];
		PLuint len = data.vObjects.size();
		for(PLuint i = 0; i<len; i++)
		{
			if (data.vObjects[i] == object)
			{
				if (i == len-1)
				{
					data.iUsedSpace -= data.vObjects.back()->GetDataLength();
					data.vObjects.pop_back();
					delete object;
				}
				else
				{
					data.vObjects[i] = 0;
					data.uFragmBlock++;
					data.uFragmLost += object->GetDataLength();
					delete object;
					Compact();
				}
				break;
			}
		}
	}
}
NS_IMETHODIMP nsFolderCompactState::CompactFolders(nsIArray *aArrayOfFoldersToCompact,
                                                   nsIArray *aOfflineFolderArray,
                                                   nsIUrlListener *aUrlListener,
                                                   nsIMsgWindow *aMsgWindow)
{
  m_window = aMsgWindow;
  m_listener = aUrlListener;
  if (aArrayOfFoldersToCompact)
    m_folderArray = aArrayOfFoldersToCompact;
  else if (aOfflineFolderArray)
  {
    m_folderArray = aOfflineFolderArray;
    m_compactingOfflineFolders = true;
    aOfflineFolderArray = nsnull;
  }
  if (!m_folderArray)
    return NS_OK;
 
  m_compactAll = true;
  m_compactOfflineAlso = aOfflineFolderArray != nsnull;
  if (m_compactOfflineAlso)
    m_offlineFolderArray = aOfflineFolderArray;

  m_folderIndex = 0;
  nsresult rv = NS_OK;
  nsCOMPtr<nsIMsgFolder> firstFolder = do_QueryElementAt(m_folderArray,
                                                         m_folderIndex, &rv);

  if (NS_SUCCEEDED(rv) && firstFolder)
    Compact(firstFolder, m_compactingOfflineFolders, aUrlListener, 
            aMsgWindow);   //start with first folder from here.
  
  return rv;
}
Esempio n. 3
0
void UndoRedoMgr::StartBlock(char* name){
	URAction* pAction = new URAction();
	pAction->lpszDescription = name;

	//-----[ are there too many Undo's ? ]--------------------------[
	if(NumUndoGroups>=MAX_NUM_UNDOREDO_OPERATIONS){
		DeleteOneUndoChain(UndoGroups[0]); // the oldest "undo" chain
	}
	//--------------------------------------------------------------/

	//-----[ try to compact ]-------------[
	if(!NumActionsStarted){
		Compact();
	}
	//------------------------------------/

	//--------[ link in linked-list ]------------[
	if(NumActionsStarted){
		pAction->pPrevAction = pLastActionStarted;
		pLastActionStarted->pNextAction = pAction;
	}
	pLastActionStarted = pAction;
	NumActionsStarted++;
	//-------------------------------------------/

	//------[ send the "action created" msg ]---------------------[
	// this could change "NumActionsStarted"!!
	pAction->OnCreate();
	//------------------------------------------------------------/

}
nsresult
nsFolderCompactState::CompactNextFolder()
{
  m_folderIndex++;
  PRUint32 cnt = 0;
  nsresult rv = m_folderArray->GetLength(&cnt);
  NS_ENSURE_SUCCESS(rv, rv);
  // m_folderIndex might be > cnt if we compact offline stores,
  // and get back here from OnStopRunningUrl.
  if (m_folderIndex >= cnt)
  {
    if (!m_compactOfflineAlso || m_compactingOfflineFolders)
    {
      CompactCompleted(NS_OK);
      return rv;
    }
    m_compactingOfflineFolders = true;
    nsCOMPtr<nsIMsgFolder> folder = do_QueryElementAt(m_folderArray,
                                                      m_folderIndex-1, &rv);
    if (NS_SUCCEEDED(rv) && folder)
      return folder->CompactAllOfflineStores(this, m_window, m_offlineFolderArray);
    else
      NS_WARNING("couldn't get folder to compact offline stores");

  }
  nsCOMPtr<nsIMsgFolder> folder = do_QueryElementAt(m_folderArray,
                                                    m_folderIndex, &rv);

  if (NS_SUCCEEDED(rv) && folder)
    rv = Compact(folder, m_compactingOfflineFolders, m_listener, m_window);
  else
    CompactCompleted(rv);
  return rv;
}
Esempio n. 5
0
bool CudaAllocBuckets::Free(void* p) {
	AddressMap::iterator it = _addressMap.find(p);
	if(it == _addressMap.end()) {
		// If the pointer was not found in the address map, cudaFree it anyways
		// but return false.
		if(p) cudaFree(p);
		return false;
	}

	// Because we're freeing a page, it had better not be in the priority queue.
	MemList::iterator memIt = it->second;
	assert(memIt->priority == _priorityMap.end());

	// Always free allocations larger than the largest bucket
	if(NumBuckets == memIt->bucket)
		FreeNode(memIt);
	else {
		it->second->priority = _priorityMap.insert(
			std::make_pair(_counter++ - memIt->bucket, memIt));

		// Freed nodes are moved to the front, committed nodes are moved to the
		// end.
		MemList& list = _memLists[memIt->bucket];
		list.splice(list.begin(), list, memIt);
		_committed -= BucketSizes[memIt->bucket];
	}
	Compact(0);
	return true;
}
Esempio n. 6
0
void
SourceBuffer::Complete(nsresult aStatus)
{
  MutexAutoLock lock(mMutex);

  if (MOZ_UNLIKELY(mStatus)) {
    MOZ_ASSERT_UNREACHABLE("Called Complete more than once");
    return;
  }

  if (MOZ_UNLIKELY(NS_SUCCEEDED(aStatus) && IsEmpty())) {
    // It's illegal to succeed without writing anything.
    aStatus = NS_ERROR_FAILURE;
  }

  mStatus = Some(aStatus);

  // Resume any waiting consumers now that we're complete.
  ResumeWaitingConsumers();

  // If we still have active consumers, just return.
  if (mConsumerCount > 0) {
    return;
  }

  // Attempt to compact our buffer down to a single chunk.
  Compact();
}
Esempio n. 7
0
void cStringList::FromPopen(cString cmdline) {
	ClearAll();
	FILE* fileptr=NULL;
	fileptr=popen(cmdline, "r" );
	if(fileptr!=NULL) {
		FromFile(fileptr);
		pclose(fileptr);
	}
	
	Compact();
	if(Length()>1)
		if((*this)[-1]==(*this)[-2]) {
			(*this)[-1]="";
		}
	Compact();
}
Esempio n. 8
0
void FGXImage::Rotate(FGXImage &undo, int angle) {
	undo.width = width;
	undo.height = height;
	undo.res = res;
	undo.unit = unit;

	float a = angle * 3.14159 / 180;
	CPoint center(width / 2, height / 2);

	for (int i = 0; i < layers.size(); i++) {
		CPoint oldCenter = layers[i]->GetPosition().CenterPoint() - center;
		CPoint newCenter(center.x + oldCenter.x * cos(a) - oldCenter.y * sin(a), center.y + oldCenter.x * sin(a) + oldCenter.y * cos(a));

		layers[i]->Rotate(*undo.AddLayer(), angle);

		CRect rect = layers[i]->GetPosition();
		rect.OffsetRect(newCenter - rect.CenterPoint());
		layers[i]->MoveTo(rect.left, rect.top);
	}

	Compact();

	width = height = 0;
	RevealAll();
}
BOOL SimpleStorage::Create( LPCSTR fileName, LPCSTR groupName, UINT32 fileType, UINT8* data, UINT32 dataLength )
{
    BOOL retVal = FALSE;
    SIMPLESTORAGE_FILE_HEADER header;
    INT32 available;

    if(fileName == NULL) return FALSE;
    if(!Initialize()) return FALSE;

    if(!SeekToFile(fileName, groupName, header, TRUE))
    {
        Compact();

        if(!SeekToFile(fileName, groupName, header, TRUE)) return FALSE;
    }

    available = s_pCurrentStream->Length - s_pCurrentStream->CurrentIndex;

    if(available < (INT32)dataLength)
    {
        Compact();

        if(!SeekToFile(fileName, groupName, header, TRUE)) return FALSE;
    }

    header.Signature = SIMPLESTORAGE_FILE_SIGNATURE;
    hal_strcpy_s(header.FileName, ARRAYSIZE(header.FileName), fileName);
    if(groupName == NULL)
    {
        header.Group[0] = 0;
    }
    else
    {
        hal_strcpy_s(header.Group, ARRAYSIZE(header.Group), groupName);
    }
    header.FileType = fileType;
    header.Length = dataLength;
    header.Attrib = 0xFFFFFFFF; // uninitialized flash
    header.HeaderCRC = SUPPORT_ComputeCRC(&header, sizeof(header) - sizeof(header.HeaderCRC) - sizeof(header.Attrib), 0);

    if(s_pCurrentStream->Write((UINT8*)&header, sizeof(header)))
    {
        retVal = s_pCurrentStream->Write((UINT8*)data, dataLength);
    }

    return retVal;
}
Esempio n. 10
0
bool CGLRTable::BuildGLRTable(Stroka /*GrammarFileName*/)
{
    YASSERT(m_pWorkGrammar != NULL);

    // initializing m_RuleInfos, in order to be independent
    // from class CWorkGrammar while  parsing
    BuildRuleInfo(m_pWorkGrammar->m_EncodedRules, m_RuleInfos);

    // creating a canonical LR(0) index item set collection
    CLRCollectionSet S;
    S.Compute(m_pWorkGrammar);

    yvector< yvector<CSLRCell> > table(S.m_ItemSets.size());

    // building @table by CLRCollectionSet
    for (size_t i = 0; i < S.m_ItemSets.size(); ++i) {
        const yset<CLRItem>& items = S.m_ItemSets[i];

        // tableLine is a new table line in SLR table, which should  be added to the end of the table
        // we resize it to contain all symbols
        yvector<CSLRCell>& tableLine = table[i];
        tableLine.resize(m_pWorkGrammar->m_UniqueGrammarItems.size());

        // initializing shift actions and reduce actions
        for (yset<CLRItem>::const_iterator it = items.begin(); it != items.end(); ++it) {
            // "For terminal a, if A->X.aY in Ii and goto(Ii,a) = Ij, then set action[i,a] to shift j"
            if  (!it->IsFinished() && m_pWorkGrammar->m_UniqueGrammarItems[it->GetSymbolNo()].m_Type != siMeta) {
                int SymbolNo = it->GetSymbolNo();
                size_t NextState;
                if (S.GetGotoValue(SymbolNo, i, NextState) && (size_t)tableLine[SymbolNo].m_GotoLine != NextState) {
                    YASSERT(tableLine[SymbolNo].m_GotoLine == -1);
                    YASSERT(!tableLine[SymbolNo].m_bShift);
                    tableLine[SymbolNo].m_bShift = true;
                    tableLine[SymbolNo].m_GotoLine = NextState;
                }
            }
            // if A->X. is in Ii and A != S',  for all terminals  a in Follow(A) set action [i,a]
            // to  reduce A->X
            if  (it->IsFinished() && it->m_pRule->m_LeftPart != m_pWorkGrammar->GetNewRoot()) {
                const yset<size_t>& follow = m_pWorkGrammar->m_FollowSets[it->m_pRule->m_LeftPart];
                for (yset<size_t>::const_iterator it1 = follow.begin(); it1 != follow.end(); ++it1)
                    tableLine[*it1].m_ReduceRules.push_back(GetRuleInfo(it->m_pRule));
            }
        }
        //  going  through non-terminal symbols, initializing GOTO table  for non terminals
        for (size_t symbolNo = 0; symbolNo < m_pWorkGrammar->m_UniqueGrammarItems.size(); ++symbolNo)
            if (m_pWorkGrammar->m_UniqueGrammarItems[symbolNo].m_Type == siMeta) {
                size_t nextState;
                if (S.GetGotoValue(symbolNo, i, nextState)) {
                    YASSERT(tableLine[symbolNo].m_GotoLine == -1);
                    tableLine[symbolNo].m_GotoLine = nextState;
                }
            }
    }

    Compact(table);
    return true;
};
Esempio n. 11
0
 int Engine::CompactAll(Context& ctx)
 {
     DataArray nss;
     ListNameSpaces(ctx, nss);
     for (size_t i = 0; i < nss.size(); i++)
     {
         KeyObject start, end;
         start.SetNameSpace(nss[i]);
         Compact(ctx, start, end);
     }
     return 0;
 }
void Table::doRecovery() {
#ifdef WIN32_NOLIB
	recoveryDlg = CreateDialog(db->GetInstance(), MAKEINTRESOURCE(IDD_NDE_RECOVERY), NULL, RecoveryDlgProc);
	ShowWindow(recoveryDlg, SW_NORMAL);
	SetWindowPos(recoveryDlg, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
	SetForegroundWindow(recoveryDlg);
	UpdateWindow(recoveryDlg);
#endif
	Compact();
#ifdef WIN32_NOLIB
	EnableWindow(GetDlgItem(recoveryDlg, IDOK), 1);
#endif
}
Esempio n. 13
0
void SvnLogHandler::Process(const wxString& output)
{
    // create new editor and set the output to it
    wxString changeLog (output);
    if(m_compact) {
        // remove non interesting lines
        changeLog = Compact(changeLog);
    }

    ChangeLogPage *page = new ChangeLogPage(GetPlugin()->GetManager()->GetTheApp()->GetTopWindow(), GetPlugin());
    page->SetUrl(m_url);
    page->AppendText( changeLog );
    GetPlugin()->GetManager()->AddPage( page, _("Change Log"), _("Change Log"), wxNullBitmap, true );
}
Esempio n. 14
0
URAction* UndoRedoMgr::NewAction(URAction* pAction){

	//-----[ are there too many Undo's ? ]--------------------------[
	if(NumUndoGroups>=MAX_NUM_UNDOREDO_OPERATIONS){
		DeleteOneUndoChain(UndoGroups[0]); // the oldest "undo" chain
	}
	//--------------------------------------------------------------/

	//-----[ try to compact ]-------------[
	if(!NumActionsStarted){
		Compact();
	}
	//------------------------------------/

	//--------[ link in linked-list ]------------[
	if(NumActionsStarted){
		pAction->pPrevAction = pLastActionStarted;
		pLastActionStarted->pNextAction = pAction;
	}
	pLastActionStarted = pAction;
	NumActionsStarted++;
	//-------------------------------------------/

	//------[ send the "action created" msg ]---------------------[
	// this could change "NumActionsStarted"!!
	pAction->OnCreate();
	//------------------------------------------------------------/

	NumActionsStarted--;
	if(NumActionsStarted)return pAction; // if this action is not a group



	//--------[ register the UndoGroup[CurUndo] ]------[
	URAction* edx = pLastActionStarted;
	pLastActionStarted = 0;
	while(edx->pPrevAction)edx = edx->pPrevAction;
	
	UndoGroups[NumUndoGroups]=edx;
	NumUndoGroups++;
	//-------------------------------------------------/
	
	
	//--------[ delete all RedoGroups ]---------[
	ClearRedoChains();
	//------------------------------------------/

	return pAction;
}
Esempio n. 15
0
bool cStringList::GetFiles(cString path, cString pattern, bool norec) {
	cString cmdline="find "+path;
	if(norec) cmdline+=" -maxdepth 1";
	cmdline+=" -iname \""+pattern+"\" -type f";
	ClearAll();
	
	FromPopen(cmdline);
	if(Length()==0) {
//		cerr<<"length is 0, returning false"<<endl;
		return false;
	}
	
	//(*this)[-1]="";
	Compact();
	return true;
}
Esempio n. 16
0
void
SourceBuffer::OnIteratorRelease()
{
  MutexAutoLock lock(mMutex);

  MOZ_ASSERT(mConsumerCount > 0, "Consumer count doesn't add up");
  mConsumerCount--;

  // If we still have active consumers, or we're not complete yet, then return.
  if (mConsumerCount > 0 || !mStatus) {
    return;
  }

  // Attempt to compact our buffer down to a single chunk.
  Compact();
}
Esempio n. 17
0
void FreeTypeFontCache::AddGlyphData(UINT glyphindex, int width, int gdiWidth, FT_Referenced_BitmapGlyph glyph, FT_Render_Mode render_mode, int AAMode)
{
	if (glyphindex & 0xffff0000 /*|| !g_ccbCache*/) {
		return;
	}
	//GC
	if (AddIncrement() >= FREETYPE_REQCOUNTMAX) {
		//TRACE(_T("Compact(0x%p)\n"), this);
		Compact();
	}

#ifdef _USE_ARRAY
	FreeTypeCharData** ppGlyph  = _GetGlyph(glyphindex);
	if (*ppGlyph) {
		(*ppGlyph)->SetGlyph(render_mode, glyph);
		(*ppGlyph)->SetMruCounter(this);
		return;
	}
#else
	GlyphCache::iterator it=m_GlyphCache.find(-(int)glyphindex);
	if (it!=m_GlyphCache.end())	//找到了旧数据
	{
		FreeTypeCharData* ppChar  = it->second;
		if (ppChar) {
			(ppChar)->SetGlyph(render_mode, glyph);
			(ppChar)->SetMruCounter(this);
			ppChar->SetWidth(width);
			ppChar->SetGDIWidth(gdiWidth);
			return;
		}	
	}
#endif

	//捛壛(glyph偺傒)
	FreeTypeCharData* p = new FreeTypeCharData(NULL, /*ppGlyph*/NULL, 0, glyphindex, width, MruIncrement(), gdiWidth, AAMode);
	if (p == NULL) {
		return;
	}
	p->SetGlyph(render_mode, glyph);

#ifdef _USE_ARRAY
	*ppGlyph = p;
#else
	m_GlyphCache[-(int)glyphindex]=p;
#endif
}
Esempio n. 18
0
cudaError_t CudaAllocBuckets::Malloc(size_t size, void** p) {

	// Locate the bucket index and adjust the size of the allocation to the 
	// bucket size.
	int bucket = LocateBucket(size);
	if(bucket < NumBuckets)
		size = BucketSizes[bucket];

	// Peel off an already-allocated node and reuse it.
	MemList& list = _memLists[bucket];
	if(list.size() && list.front().priority != _priorityMap.end()) {
		MemList::iterator memIt = list.begin();
		
		_priorityMap.erase(memIt->priority);
		memIt->priority = _priorityMap.end();

		list.splice(list.end(), list, memIt);
		_committed += size;

		*p = memIt->address->first;
		return cudaSuccess;
	}

	// Shrink if this allocation would put us over the limit.
	Compact(size);
	 
	cudaError_t error = cudaSuccess;
	*p = 0;
	if(size) error = cudaMalloc(p, size);
	while((cudaErrorMemoryAllocation == error) && (_committed < _allocated)) {
		SetCapacity(_capacity - _capacity / 10);
		error = cudaMalloc(&p, size);
	}
	if(cudaSuccess != error) return error;

	MemList::iterator memIt = 
		_memLists[bucket].insert(_memLists[bucket].end(), MemNode());
	memIt->bucket = bucket;
	memIt->address = _addressMap.insert(std::make_pair(*p, memIt)).first;
	memIt->priority = _priorityMap.end();
	_allocated += size;
	_committed += size;

	return cudaSuccess;
}
Esempio n. 19
0
nsVoidArray& nsVoidArray::operator=(const nsVoidArray& other)
{
  PRInt32 otherCount = other.Count();
  PRInt32 maxCount = GetArraySize();
  if (otherCount)
  {
    if (otherCount > maxCount)
    {
      // frees old mImpl IF this succeeds
      if (!GrowArrayBy(otherCount-maxCount))
        return *this;      // XXX The allocation failed - don't do anything

      memcpy(mImpl->mArray, other.mImpl->mArray, otherCount * sizeof(mImpl->mArray[0]));
      mImpl->mCount = otherCount;
    }
    else
    {
      // the old array can hold the new array
      memcpy(mImpl->mArray, other.mImpl->mArray, otherCount * sizeof(mImpl->mArray[0]));
      mImpl->mCount = otherCount;
      // if it shrank a lot, compact it anyways
      if ((otherCount*2) < maxCount && maxCount > 100)
      {
        Compact();  // shrank by at least 50 entries
      }
    }
#if DEBUG_VOIDARRAY
     if (mImpl->mCount > mMaxCount &&
         mImpl->mCount < (PRInt32)(sizeof(MaxElements)/sizeof(MaxElements[0])))
     {
       MaxElements[mImpl->mCount]++;
       MaxElements[mMaxCount]--;
       mMaxCount = mImpl->mCount;
     }
#endif
  }
  else
  {
    // Why do we drop the buffer here when we don't in Clear()?
    SizeTo(0);
  }

  return *this;
}
Esempio n. 20
0
void FreeTypeFontCache::AddCharData(WCHAR wch, UINT glyphindex, int width, int gdiWidth, FT_Referenced_BitmapGlyph glyph, FT_Render_Mode render_mode, int AAMode)
{
	if (glyphindex & 0xffff0000 /*|| !g_ccbCache*/) {
		return;
	}
	if (AddIncrement() >= FREETYPE_REQCOUNTMAX) {	//先压缩,避免压缩后丢失的问题
		Compact();
	}

#ifdef _USE_ARRAY
	FreeTypeCharData** ppChar  = _GetChar(wch);
	if (*ppChar) {
		(*ppChar)->SetGlyph(render_mode, glyph);
		(*ppChar)->SetMruCounter(this);
		return;
	}
#else
	GlyphCache::iterator it=m_GlyphCache.find(wch);
	if (it!=m_GlyphCache.end())	//找到了旧数据
	{
		FreeTypeCharData* ppChar  = it->second;
		if (ppChar) {
			ppChar->SetGlyph(render_mode, glyph);
			ppChar->SetMruCounter(this);
			ppChar->SetWidth(width);
			ppChar->SetGDIWidth(gdiWidth);
			return;
		}	
	}
#endif
	FreeTypeCharData* p = new FreeTypeCharData(/*ppChar*/NULL, NULL, wch, glyphindex, width, MruIncrement(), gdiWidth, AAMode);
	if (p == NULL) {
		return;
	}
	p->SetGlyph(render_mode, glyph);

#ifdef _USE_ARRAY
	*ppChar = p;
#else
	m_GlyphCache[wch]=p;
#endif

}
Esempio n. 21
0
bool ON_Brep::SplitKinkyFaces( 
        double kink_tol_radians,
        bool bCompactIfNeeded
        )
{
  bool rc = true;
  // see if splitting is required
  const int ecount = m_E.Count();
  const int fcount = m_F.Count();
  for (int j=0; j<fcount; j++)
  {
    if ( !SplitKinkyFace(j,kink_tol_radians) )
      rc = false;
  }
  if (bCompactIfNeeded && ( fcount != m_F.Count() || ecount != m_E.Count()) )
  {
    Compact();
  }
  return true;
}
Esempio n. 22
0
bool cFileList::GetList(cString starting_path, cString pattern) {
	cString cmdline;
	if(cis) cmdline="find "+starting_path+" -iname \""+pattern+"\"";
	else cmdline="find "+starting_path+" -name \""+pattern+"\"";
	
	if(!rec) cmdline+=" -maxdepth 1";
//	cout<<"about to execute:"<<cmdline<<endl;
//	pclose(FromFile(popen(cmdline+" -type f","r")));
	pclose(FromFile(popen(cmdline,"r")));
	cout<<endl;
	
//	cerr<<"found "<<Length()<<" entries"<<endl;
	
	if(Length()==0) return false;
	
//	for(int j=0; j<Length(); j++) cerr<<j+1<<"/"<<Length()<<":"<<Array[j]<<endl;
//	cout<<endl;
	
	Array[Length()-1]="";
	//UCompact();
	cFile *temp;
	if(starting_path[0]!='/') {
		for(int i=0; i<Length(); i++) {
			Array[i]=Array[i].ChopLf('/');
			if(Array[i]!="") {
				temp=new cFile(Array[i],false,false,false);
				if(temp->IsDirectory()) Array[i]="";
				delete temp;
			}
		}
	}
//	cout<<endl;
//	for(int j=0; j<Length(); j++) cerr<<j+1<<"/"<<Length()<<":"<<Array[j]<<endl;
//	cout<<endl;
	Compact();
//	cout<<endl;
//	for(int j=0; j<Length(); j++) cerr<<j+1<<"/"<<Length()<<":"<<Array[j]<<endl;
//	cout<<endl;
	return true;
}
Esempio n. 23
0
FreeTypeFontCache* FreeTypeFontInfo::GetCache(FTC_ScalerRec& scaler, const LOGFONT& lf)
{
	CCriticalSectionLock __lock(CCriticalSectionLock::CS_FONTCACHE);

	if (AddIncrement() > m_nMaxSizes) {	//先压缩
		Compact();
	}
	int weight = lf.lfWeight;
	weight = weight < FW_BOLD ? 0: 1/*FW_BOLD*/;
	const bool italic = !!lf.lfItalic;
	if (scaler.height>0xfff || scaler.width>0xfff/* || scaler.height<0 || scaler.width<0*/)	//超大字体不渲染
		return NULL;
	FreeTypeFontCache* p = NULL;
	UINT hash=getCacheHash(scaler.height, weight, italic, lf.lfWidth ? scaler.width : 0);	//计算hash
	CacheArray::iterator it=m_cache.find(hash); //寻找cache
	if (it!=m_cache.end())//cache存在
	{
		p = it->second;
		goto OK; //返回cache
	}
	
	p = new FreeTypeFontCache(/*scaler.height, weight, italic,*/ MruIncrement());
	if (!p) {
		return NULL;
	}
	if (m_cache[hash]=p) {
		goto OK;
	}
	delete p;
	return NULL;

OK:
	Assert(p != NULL);
	if (p && p->Activate()) {
		DecIncrement();	//重复使用则减计数值
	}
	return p;
}
Esempio n. 24
0
NS_IMETHODIMP nsFolderCompactState::OnStopRunningUrl(nsIURI *url, nsresult status)
{
  if (m_parsingFolder)
  {
    m_parsingFolder = false;
    if (NS_SUCCEEDED(status))
      status = Compact(m_folder, m_compactingOfflineFolders, m_listener, m_window);
    else if (m_compactAll)
      CompactNextFolder();
  }
  else if (m_compactAll) // this should be the imap case only
  {
    nsCOMPtr <nsIMsgFolder> prevFolder = do_QueryElementAt(m_folderArray,
                                                           m_folderIndex);
    if (prevFolder)
      prevFolder->SetMsgDatabase(nsnull);
    CompactNextFolder();
  }
  else if (m_listener)
  {
    CompactCompleted(status);
  }
  return NS_OK;
}
Esempio n. 25
0
LRESULT CALLBACK DlgWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
	OPENFILENAME opfn;
	BROWSEINFO bi;
	TCHAR fn[512];
	TCHAR fn2[512];
	switch(uMsg)
	{
	case WM_COMMAND:
		switch((wParam<<16)>>16)
		{
		case IDC_BROWSEORI:
			memset(fn,0,512);
			memset(&opfn,0,sizeof(opfn));
			opfn.lStructSize =sizeof(opfn);
			opfn.hwndOwner =hwnd;
			opfn.lpstrFilter =TEXT("DAT文件(*.dat)\0*.dat\0\0");
			opfn.lpstrFile =fn;
			opfn.nMaxFile =512;
			opfn.Flags=OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
			if(::GetOpenFileName(&opfn))
			{
				::SetDlgItemText(hwnd,IDC_ORINAME,fn);
			}
			break;
		case IDC_RUN:
			if(::IsDlgButtonChecked(hwnd,IDC_RADIO_EXT)==BST_CHECKED)
			{
				::GetDlgItemText(hwnd,IDC_ORINAME,fn,512);
				if(Extract(fn)==-1)
					MessageBox(hwnd,TEXT("解包失败!"),TEXT("摔14"),MB_OK|MB_ICONERROR);
				else
					MessageBox(hwnd,TEXT("解包完成!"),TEXT("摔14"),MB_OK);
			}
			else
			{
				::GetDlgItemText(hwnd,IDC_NEWFOLDER,fn,512);
				::GetDlgItemText(hwnd,IDC_ORINAME,fn2,512);
				if(Compact(fn,fn2)==-1)
					MessageBox(hwnd,TEXT("封装失败!"),TEXT("摔14"),MB_OK|MB_ICONERROR);
				else
					MessageBox(hwnd,TEXT("封装完成!"),TEXT("摔14"),MB_OK);
			}
			break;
		case IDC_BROWSENEW:
			memset(&bi,0,sizeof (bi));
			bi.hwndOwner=hwnd;
			bi.pszDisplayName=fn;
			bi.lpszTitle=TEXT("选择文件夹");
			bi.ulFlags=BIF_USENEWUI;
			LPITEMIDLIST idl;
			idl=SHBrowseForFolder(&bi);
			if(idl==NULL)
				break;
			if(!SHGetPathFromIDList(idl,fn))
				break;
			::SetDlgItemText(hwnd,IDC_NEWFOLDER,fn);
			break;
		case IDC_RADIO_EXT:
			if(wParam>>16==BN_CLICKED)
			{
				ext_main:
				EnableWindow(GetDlgItem(hwnd,IDC_BROWSENEW),FALSE);
				EnableWindow(GetDlgItem(hwnd,IDC_NEWFOLDER),FALSE);
				SetDlgItemText(hwnd,IDC_STATIC1,TEXT("原始脚本(如scr.dat)"));
//				SetDlgItemText(hwnd,IDC_STATIC2,TEXT("待封包目录(如scr文件夹)"));
			}
			break;
		case IDC_RADIO_COM:
			if(wParam>>16==BN_CLICKED)
			{
				EnableWindow(GetDlgItem(hwnd,IDC_BROWSENEW),TRUE);
				EnableWindow(GetDlgItem(hwnd,IDC_NEWFOLDER),TRUE);
				SetDlgItemText(hwnd,IDC_STATIC1,TEXT("新脚本(如scr1.dat)"));
//				SetDlgItemText(hwnd,IDC_STATIC2,TEXT("待封包目录(如scr文件夹)"));
			}
			break;
		}
		break;
	case WM_INITDIALOG:
		g_hWinMain=hwnd;
		CheckDlgButton(hwnd,IDC_RADIO_EXT,BST_CHECKED);
		goto ext_main;
		break;
	case WM_CLOSE:
		EndDialog(hwnd,0);
	}
	return 0;
}
Esempio n. 26
0
IO_stat MCParagraph::load(IO_handle stream, const char *version)
{
	IO_stat stat;
	stat = IO_NORMAL;

	if (stat == IO_NORMAL)
		stat = IO_read_uint2(&m_text_size, stream);

	if (m_text_size == 1)
	{
		if (stat == IO_NORMAL)
		{
			char t_temp;
			uint4 t_temp_count;
			t_temp_count = 1;
			stat = IO_read(&t_temp, sizeof(uint1), t_temp_count, stream);
		}

		if (stat == IO_NORMAL)
			m_text_size = 0;
	}
	else if (m_text_size > 1)
	{
		if (stat == IO_NORMAL)
		{
			m_text = malloc(m_text_size);
			if (m_text == NULL)
				stat = IO_ERROR;
		}

		if (stat == IO_NORMAL)
		{
			uint4 t_temp_text_size;
			t_temp_text_size = m_text_size;
			stat = IO_read(m_text, sizeof(uint1), t_temp_text_size, stream);
		}

		if (stat == IO_NORMAL)
		{
			if (MCencryptstring != NULL)
				MCX_passde((char *)m_text, MCencryptstring, m_text_size);

			m_text_size -= 1;
		}
	}

	while(stat == IO_NORMAL)
	{
		uint1 t_type;
		stat = IO_read_uint1(&t_type, stream);
		if (stat != IO_NORMAL)
			break;

		uint4 t_block_offset, t_block_length, t_block_style;
		stat = load_block(stream, version, t_block_offset, t_block_length, t_block_style);
		if (stat != IO_NORMAL)
			break;

		// Make sure the block doesn't overrun the text buffer (shouldn't ever be
		// necessary...)
		t_block_length = MCU_min(m_text_size - t_block_offset, t_block_length);

		// Byte-swap the text to native byte-order if its unicode, otherwise translate
		// Mac<->ISO if necessary.
		const MCParagraphCharStyle *t_style_info;
		t_style_info = FetchCharStyle(t_block_style);
		if (t_style_info -> is_unicode)
		{
			uint4 t_length;
			t_length = t_block_length / 2;

			uint2 *t_ptr;
			t_ptr = (uint2 *)((uint1 *)m_text + t_block_offset);

			for(; t_length > 0; t_length -= 1)
				swap_uint2(t_ptr++);
		}
		else if (MCtranslatechars)
		{
#ifdef _MACOSX
			IO_iso_to_mac((char *)m_text + t_block_offset, t_block_length);
#else
			IO_mac_to_iso((char *)m_text + t_block_offset, t_block_length);
#endif
		}

		// Replace the style in the given range with the style
		ReplaceStyles(t_block_offset, t_block_length, t_block_style);
	}

	if (stat == IO_NORMAL)
	{
		// If no styles were applied, we need to translate the text
		if (m_styles_size == 0 && MCtranslatechars && m_text_size > 0)
#ifdef _MACOSX
			IO_iso_to_mac((char *)m_text, m_text_size);
#else
			IO_mac_to_iso((char *)m_text, m_text_size);
#endif

		Compact();

		MCS_seek_cur(stream, -1);
	}

	return stat;
}
Esempio n. 27
0
void CudaAllocBuckets::Clear() {
	Compact(0);
}
nsresult
nsFontCache::GetMetricsFor(const nsFont& aFont, nsIAtom* aLanguage,
  gfxUserFontSet* aUserFontSet, nsIFontMetrics*& aMetrics)
{
    // First check our cache
    // start from the end, which is where we put the most-recent-used element

    nsIFontMetrics* fm;
    PRInt32 n = mFontMetrics.Length() - 1;
    for (PRInt32 i = n; i >= 0; --i) {
        fm = mFontMetrics[i];
        nsIThebesFontMetrics* tfm = static_cast<nsIThebesFontMetrics*>(fm);
        if (fm->Font().Equals(aFont) && tfm->GetUserFontSet() == aUserFontSet) {
            nsCOMPtr<nsIAtom> language;
            fm->GetLanguage(getter_AddRefs(language));
            if (aLanguage == language.get()) {
                if (i != n) {
                    // promote it to the end of the cache
                    mFontMetrics.RemoveElementAt(i);
                    mFontMetrics.AppendElement(fm);
                }
                tfm->GetThebesFontGroup()->UpdateFontList();
                NS_ADDREF(aMetrics = fm);
                return NS_OK;
            }
        }
    }

    // It's not in the cache. Get font metrics and then cache them.

    aMetrics = nsnull;
    nsresult rv = CreateFontMetricsInstance(&fm);
    if (NS_FAILED(rv)) return rv;
    rv = fm->Init(aFont, aLanguage, mContext, aUserFontSet);
    if (NS_SUCCEEDED(rv)) {
        // the mFontMetrics list has the "head" at the end, because append
        // is cheaper than insert
        mFontMetrics.AppendElement(fm);
        aMetrics = fm;
        NS_ADDREF(aMetrics);
        return NS_OK;
    }
    fm->Destroy();
    NS_RELEASE(fm);

    // One reason why Init() fails is because the system is running out of
    // resources. e.g., on Win95/98 only a very limited number of GDI
    // objects are available. Compact the cache and try again.

    Compact();
    rv = CreateFontMetricsInstance(&fm);
    if (NS_FAILED(rv)) return rv;
    rv = fm->Init(aFont, aLanguage, mContext, aUserFontSet);
    if (NS_SUCCEEDED(rv)) {
        mFontMetrics.AppendElement(fm);
        aMetrics = fm;
        NS_ADDREF(aMetrics);
        return NS_OK;
    }
    fm->Destroy();
    NS_RELEASE(fm);

    // could not setup a new one, send an old one (XXX search a "best
    // match"?)

    n = mFontMetrics.Length() - 1; // could have changed in Compact()
    if (n >= 0) {
        aMetrics = mFontMetrics[n];
        NS_ADDREF(aMetrics);
        return NS_OK;
    }

    NS_POSTCONDITION(NS_SUCCEEDED(rv), "font metrics should not be null - bug 136248");
    return rv;
}
Esempio n. 29
0
ptr<File> MemoryStream::ToFile()
{
	Compact();
	return dataSize < files[0]->GetSize() ? NEW(PartFile(files[0], files[0]->GetData(), dataSize)) : files[0];
}
Esempio n. 30
0
void cStringList::FromPopen(cString cmdline, cString grepme) {
	FromPopen(cmdline);
	for(int i=0; i<Length(); i++) 
		if(!(*this)[i].Contains(grepme)) { (*this)[i]=""; }
	Compact();
}