static void * my_temp_malloc(size_t size) { OSErr result; struct my_block **block; long version; char *ret_ptr; size=(size+3)&~3; if (Gestalt(gestaltSystemVersion,&version) || version<0x700) return(nil); if (size>MY_BLOCK_SIZE) { if (TempFreeMem()<1024*1024+size) return(nil); block=(struct my_block **)TempNewHandle(size+sizeof(struct my_block **),&result); if (!block || !*block || result) return(nil); TempHLock((Handle)block,&result); (*block)->next=temp_mem_blocks; temp_mem_blocks=block; return((void *)&(*block)->storage); } if (size>my_cur_avail) { if (TempFreeMem()<1024*1024+MY_BLOCK_SIZE) return(nil); block=(struct my_block **)TempNewHandle(sizeof(struct my_block),&result); if (!block || !*block || result) return(nil); TempHLock((Handle)block,&result); (*block)->next=temp_mem_blocks; temp_mem_blocks=block; my_cur_block=(*block)->storage; my_cur_avail=MY_BLOCK_SIZE; } ret_ptr=my_cur_block; my_cur_block+=size; my_cur_avail-=size; return((void *)ret_ptr); }
void * __sys_alloc(mem_size size, struct mem_pool_obj * ) { PoolHandlePtr slot; OSErr err; slot = NewPoolListSlot(); assert ( slot != 0 ); // (slot is dereferenced from poolList, and we dont want it to move) HLock( (Handle)poolList ); // Allocate a new handle. // Use temporary memory if asked to. // Use application heap if temporary memory fails. if (use_temporary_memory) *slot = (PoolHandle)TempNewHandle( size, &err ); if ( !use_temporary_memory || *slot == nil || err!=noErr ) *slot = (PoolHandle)NewHandle( size ); assert( *slot != 0 ); HUnlock( (Handle)poolList ); HLock( *slot ); return(**slot); }
Ptr GC_MacTemporaryNewPtr(size_t size, Boolean clearMemory) { static Boolean firstTime = true; OSErr result; TemporaryMemoryHandle tempMemBlock; Ptr tempPtr = nil; tempMemBlock = (TemporaryMemoryHandle)TempNewHandle(size + sizeof(TemporaryMemoryBlock), &result); if (tempMemBlock && result == noErr) { HLockHi((Handle)tempMemBlock); tempPtr = (**tempMemBlock).data; if (clearMemory) memset(tempPtr, 0, size); tempPtr = StripAddress(tempPtr); // keep track of the allocated blocks. (**tempMemBlock).nextBlock = theTemporaryMemory; theTemporaryMemory = tempMemBlock; } # if !defined(SHARED_LIBRARY_BUILD) // install an exit routine to clean up the memory used at the end. if (firstTime) { atexit(&GC_MacFreeTemporaryMemory); firstTime = false; } # endif return tempPtr; }
static Handle debuggetnewhandle (char * filename, unsigned long linenumber, unsigned long threadid, long ctbytes, boolean fltemp) { /* 2.1b3 dmb: new fltemp parameter. if true, try temp memory first, then our heap. */ register Handle h; OSErr err; long extrasize; extrasize = strlen(filename) + 1 + sizeof(long) + sizeof(long) + sizeof(long) + (2 * (sizeof(Handle))) + 4; #ifdef MACVERSION if (fltemp) { /*try grabbing temp memory first*/ h = TempNewHandle (ctbytes + extrasize, &err); if (h != nil) { debugaddmemhandle (h, ctbytes, filename, linenumber, threadid); #ifdef fldebug ++cttemphandles; tempzone = HandleZone (h); #endif return (h); } } #endif if (hsafetycushion == nil) { /*don't allocate new stuff w/out safety cushion*/ if (!getsafetycushion ()) return (nil); } flholdsafetycushion = true; #ifdef MACVERSION h = NewHandle (ctbytes); if (h != nil) debugaddmemhandle (h, ctbytes, filename, linenumber, threadid); #endif #ifdef WIN95VERSION h = debugfrontierAlloc (filename, linenumber, threadid, ctbytes); #endif flholdsafetycushion = false; return (h); } /*getnewhandle*/
static Handle getnewhandle (long ctbytes, boolean fltemp) { /* 2.1b3 dmb: new fltemp parameter. if true, try temp memory first, then our heap. */ register Handle h; OSErr err; #ifdef MACVERSION if (fltemp) { /*try grabbing temp memory first*/ h = TempNewHandle (ctbytes, &err); if (h != nil) { #ifdef fldebug ++cttemphandles; tempzone = HandleZone (h); #endif return (h); } } #endif if (hsafetycushion == nil) { /*don't allocate new stuff w/out safety cushion*/ if (!getsafetycushion ()) return (nil); } flholdsafetycushion = true; h = NewHandle (ctbytes); flholdsafetycushion = false; return (h); } /*getnewhandle*/
void MolDisplayWin::WriteQTMovie(wxString & filepath) { //Create a QuickTime movie using the standard animation codecs with normal quality, and //temporal compression. The final file is flattened for cross platform compatability QTExport * QTOptions = new QTExport(this); //setup controls for the current data if (MainData->GetNumFrames() > 1) { //default to frame animation QTOptions->SetMovieChoice(0); } else { QTOptions->EnableFrameMovie(false); } if (MainData->cFrame->GetNumberNormalModes() <= 0) { QTOptions->EnableModeMovie(false); } if (QTOptions->ShowModal() != wxID_OK) { //user cancelled the operation QTOptions->Destroy(); return; } //retrieve the value of each option int MovieType = QTOptions->GetMovieChoice(); bool IncludeEPlot = QTOptions->AddEnergyPlot(); int compressorChoice = QTOptions->GetCompressorChoice(); int keyFrameRate = QTOptions->GetKeyFrameRate(); if (keyFrameRate < 0) keyFrameRate = 0; QTOptions->Destroy(); CodecType mCodec; switch (compressorChoice) { case 0: mCodec = kCinepakCodecType; break; case 1: mCodec = kGraphicsCodecType; break; case 2: mCodec = kAnimationCodecType; break; case 3: default: mCodec = kMPEG4VisualCodecType; } OSStatus s; OSErr myErr = myErr; FSSpec targetSpec; //ugh I need to get an FSSpec to hand to quicktime, but these calls only seem to work if //the file already exists... const char * t = filepath.mb_str(wxConvUTF8); FILE * temp = fopen(t, "wb"); fclose(temp); #ifdef __WXOSX_COCOA__ //This function is not found in the wxCocoa implementation, it is probably possible to work around it //Otherwise the code appears to link and run currently. However, it is probably better to redue the //code to use the Cocoa qtKit framework rather than the old Carbon QT library. //This path is not tested as the current Cocoa code does not properly support the extended save dialog. // void wxMacFilename2FSSpec( const wxString& path , FSSpec *spec ) { OSStatus err = noErr; FSRef fsRef; wxMacPathToFSRef( filepath , &fsRef ); err = FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &targetSpec, NULL); verify_noerr( err ); } #else wxMacFilename2FSSpec(filepath, &targetSpec); #endif Movie theMovie = NULL; FSSpec tempSpec = targetSpec; strcpy((char *) &(tempSpec.name[1]), "MacMolPlt8933tempMovie"); tempSpec.name[0] = 22; BeginOperation(); ProgressInd->ChangeText("Creating movie..."); myErr = EnterMovies(); //initialize the quicktime manager if (myErr != noErr) { FinishOperation(); MessageAlert("Error initializing QuickTime!"); return; } //Create the movie file and initialize file data //Use Quicktime creator code 'TVOD' instead of simpletext 'ttxt' short resRefNum = 0; short resId = 0; myErr = CreateMovieFile(&tempSpec, 'TVOD', smCurrentScript, createMovieFileDeleteCurFile, &resRefNum, &theMovie); if (myErr != noErr) { MessageAlert("Error creating movie file!"); } else { bool KillEPlot = false; int width, height, savedEPlotWidth, savedEPlotHeight; glCanvas->GetClientSize(&width, &height); Rect lDisplayRect={0,0,0,0}; lDisplayRect.right = width; lDisplayRect.bottom = height; Rect gRect = lDisplayRect; Rect EPlotRect = lDisplayRect; //If we are including an energy plot add space for it here if (IncludeEPlot && (MovieType == 0)) { EPlotRect.left = EPlotRect.right; EPlotRect.right = EPlotRect.left + height; if (!energyPlotWindow) { energyPlotWindow = new EnergyPlotDialog(this); KillEPlot = true; } else { energyPlotWindow->GetSize(&savedEPlotWidth, &savedEPlotHeight); } gRect.right += height; width += height; energyPlotWindow->Show(false); energyPlotWindow->SetSize(height, height); energyPlotWindow->Update(); //This is needed to initialise the window if we just created it } LocalToGlobal ((Point *) &(gRect.top)); LocalToGlobal ((Point *) &(gRect.bottom)); WindowRef TempWindow; s = CreateNewWindow(kDocumentWindowClass, kWindowNoAttributes, &gRect, &TempWindow); if (s == noErr) { //Create the video track Track theTrack = NewMovieTrack (theMovie, FixRatio(width,1), FixRatio(height,1), kNoVolume); if ((noErr == GetMoviesError())&&theTrack) { Media theMedia = NewTrackMedia (theTrack, VideoMediaType, 60, // Video Time Scale NULL, 0); if ((noErr == GetMoviesError())&&theMedia) { myErr = BeginMediaEdits (theMedia); if (myErr == noErr) { //create the actual movie frames GWorldPtr lgWorld=NULL; if (! NewGWorld (&lgWorld, 0, &gRect, (CTabHandle) NULL, (GDHandle) NULL, (GWorldFlags) (pixPurge + useTempMem))) { long MaxCompressedSize; ImageSequence seqID; ImageDescriptionHandle imageDesc = (ImageDescriptionHandle)NewHandle(4); PixMapHandle myPixMap = GetPortPixMap(lgWorld); LockPixels (myPixMap); myErr = CompressSequenceBegin(&seqID, myPixMap, NULL, &gRect, &gRect, 0, mCodec, bestCompressionCodec, codecNormalQuality, codecNormalQuality, keyFrameRate, NULL, codecFlagUpdatePreviousComp, imageDesc); GetMaxCompressionSize (myPixMap, &gRect, 0, codecNormalQuality, mCodec, (CompressorComponent) anyCodec, &MaxCompressedSize); Handle Buffer = TempNewHandle(MaxCompressedSize, &myErr); if (!Buffer) Buffer = NewHandle(MaxCompressedSize); if (Buffer) { qtData myqtData = {theMedia, imageDesc, seqID, lDisplayRect, gRect}; if (MovieType == 0) { CreateFrameMovie(lgWorld, Buffer, myqtData, IncludeEPlot); } else { CreateModeMovie(lgWorld, Buffer, myqtData); } DisposeHandle(Buffer); } myErr = CDSequenceEnd(seqID); if (lgWorld != NULL) DisposeGWorld (lgWorld); if (imageDesc) DisposeHandle((Handle) imageDesc); } myErr = EndMediaEdits (theMedia); } myErr = InsertMediaIntoTrack (theTrack, 0,/* track start time */ 0, /* media start time */ GetMediaDuration (theMedia), FixRatio(1,1)); } myErr = AddMovieResource (theMovie, resRefNum, &resId, NULL); } if (resRefNum) { //Create the actual file as a flat data fork so it can be placed on the www ProgressInd->ChangeText("Flattening movieÉ"); FlattenMovie(theMovie, flattenAddMovieToDataFork, &targetSpec, 'TVOD', smCurrentScript, createMovieFileDeleteCurFile, &resId, NULL); CloseMovieFile (resRefNum); } DisposeWindow(TempWindow); } DisposeMovie (theMovie); DeleteMovieFile (&tempSpec); //delete the temp file after disposing of the movie if (energyPlotWindow) { if (KillEPlot) { delete energyPlotWindow; energyPlotWindow = NULL; } else { energyPlotWindow->SetSize(savedEPlotWidth, savedEPlotHeight); energyPlotWindow->FrameChanged(); energyPlotWindow->Show(true); } } } ExitMovies(); //Close out quicktime as we are done with it for now FinishOperation(); }