* Set up a GWorld in the record */
| 119 | * Set up a GWorld in the record |
| 120 | */ |
| 121 | static short |
| 122 | allocate_offscreen_world(tty_record *record) |
| 123 | { |
| 124 | GWorldPtr gw = (GWorldPtr) 0; |
| 125 | GWorldFlags world_flags = 0; |
| 126 | long mem_here, mem_there, other, required_mem; |
| 127 | Point p = { 0, 0 }; |
| 128 | Rect r_screen; |
| 129 | GDHandle gdh; |
| 130 | short s_err; |
| 131 | |
| 132 | select_onscreen_window(record); |
| 133 | LocalToGlobal(&p); |
| 134 | r_screen = record->its_bits.bounds; |
| 135 | OffsetRect(&r_screen, p.h, p.v); |
| 136 | |
| 137 | gdh = GetMaxDevice(&r_screen); |
| 138 | required_mem = (long) (*((*gdh)->gdPMap))->pixelSize |
| 139 | * ((long) record->its_bits.bounds.right |
| 140 | * record->its_bits.bounds.bottom) |
| 141 | >> 3; |
| 142 | |
| 143 | PurgeSpace(&other, &mem_here); |
| 144 | if (other < mem_here + MEMORY_MARGIN) { |
| 145 | mem_here = other - MEMORY_MARGIN; |
| 146 | } |
| 147 | dprintf("Heap %ld Required %ld", mem_here, required_mem); |
| 148 | if (required_mem > mem_here) { |
| 149 | mem_there = required_mem; |
| 150 | if (required_mem > TempMaxMem(&mem_there)) { |
| 151 | dprintf("No memory"); |
| 152 | return memFullErr; |
| 153 | } |
| 154 | world_flags |= useTempMem; |
| 155 | } |
| 156 | s_err = NewGWorld(&gw, 0, &r_screen, (CTabHandle) 0, (GDHandle) 0, |
| 157 | world_flags); |
| 158 | if (!s_err) { |
| 159 | record->offscreen_world = gw; |
| 160 | select_offscreen_port(record); |
| 161 | SetOrigin(0, 0); |
| 162 | select_onscreen_window(record); |
| 163 | dprintf("New GWorld @ %lx;dm", gw); |
| 164 | } |
| 165 | return s_err; |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | * Done with GWorld, release data |
no test coverage detected