ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/screen.C
(Generate patch)

Comparing rxvt-unicode/src/screen.C (file contents):
Revision 1.414 by sf-exg, Tue Jan 24 17:05:05 2012 UTC vs.
Revision 1.415 by root, Mon May 28 14:25:16 2012 UTC

98 98
99/* Fill part/all of a line with blanks. */ 99/* Fill part/all of a line with blanks. */
100void 100void
101rxvt_term::scr_blank_line (line_t &l, unsigned int col, unsigned int width, rend_t efs) const NOTHROW 101rxvt_term::scr_blank_line (line_t &l, unsigned int col, unsigned int width, rend_t efs) const NOTHROW
102{ 102{
103 if (!l.t) 103 if (!l.valid ())
104 { 104 {
105 lalloc (l); 105 l.alloc ();
106 col = 0; 106 col = 0;
107 width = ncol; 107 width = ncol;
108 } 108 }
109 109
110 l.touch (); 110 l.touch ();
157/* ------------------------------------------------------------------------- * 157/* ------------------------------------------------------------------------- *
158 * SCREEN INITIALISATION * 158 * SCREEN INITIALISATION *
159 * ------------------------------------------------------------------------- */ 159 * ------------------------------------------------------------------------- */
160 160
161void 161void
162rxvt_term::scr_alloc ()
163{
164 int tsize = sizeof (text_t) * ncol;
165 int rsize = sizeof (rend_t) * ncol;
166
167 // we assume that rend_t size is a sufficient alignment
168 // factor for tetx_t and line_t values, and we only
169 // need to adjust tsize.
170 tsize = (tsize + sizeof (rend_t) - 1);
171 tsize -= tsize % sizeof (rend_t);
172
173 int all_rows = total_rows + nrow + nrow;
174
175 chunk_size = (sizeof (line_t) + rsize + tsize) * all_rows;
176 chunk = rxvt_malloc (chunk_size);
177
178 char *base = (char *)chunk + sizeof (line_t) * all_rows;
179
180 for (int row = 0; row < all_rows; ++row)
181 {
182 line_t &l = ((line_t *)chunk) [row];
183
184 l.t = (text_t *)base; base += tsize;
185 l.r = (rend_t *)base; base += rsize;
186 l.l = -1;
187 l.f = 0;
188 }
189
190 drawn_buf = (line_t *)chunk;
191 swap_buf = drawn_buf + nrow;
192 row_buf = swap_buf + nrow;
193}
194
195void
162rxvt_term::scr_reset () 196rxvt_term::scr_reset ()
163{ 197{
164#if ENABLE_OVERLAY 198#if ENABLE_OVERLAY
165 scr_overlay_off (); 199 scr_overlay_off ();
166#endif 200#endif
192 total_rows = nrow + saveLines; 226 total_rows = nrow + saveLines;
193 227
194 screen.tscroll = 0; 228 screen.tscroll = 0;
195 screen.bscroll = nrow - 1; 229 screen.bscroll = nrow - 1;
196 230
231 void *prev_chunk = chunk;
232 line_t *prev_drawn_buf = drawn_buf;
233 line_t *prev_swap_buf = swap_buf;
234 line_t *prev_row_buf = row_buf;
235
236 int common_col = min (prev_ncol, ncol);
237
238 scr_alloc ();
239
197 if (!row_buf) 240 if (!prev_row_buf)
198 { 241 {
199 /* 242 /*
200 * first time called so just malloc everything: don't rely on realloc 243 * first time called so just malloc everything: don't rely on realloc
201 */ 244 */
202 top_row = 0; 245 top_row = 0;
203 term_start = 0; 246 term_start = 0;
204
205 talloc = new rxvt_salloc (ncol * sizeof (text_t));
206 ralloc = new rxvt_salloc (ncol * sizeof (rend_t));
207
208 row_buf = (line_t *)rxvt_calloc (total_rows , sizeof (line_t));
209 drawn_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t));
210 swap_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t));
211
212 for (int row = nrow; row--; )
213 {
214 scr_blank_screen_mem (ROW (row), DEFAULT_RSTYLE);
215 scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE);
216 scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE);
217 }
218 247
219 memset (charsets, 'B', sizeof (charsets)); 248 memset (charsets, 'B', sizeof (charsets));
220 rstyle = DEFAULT_RSTYLE; 249 rstyle = DEFAULT_RSTYLE;
221 screen.flags = Screen_DefaultFlags; 250 screen.flags = Screen_DefaultFlags;
222 screen.cur.row = screen.cur.col = 0; 251 screen.cur.row = screen.cur.col = 0;
245 { 274 {
246 /* 275 /*
247 * add or delete rows as appropriate 276 * add or delete rows as appropriate
248 */ 277 */
249 278
250 rxvt_salloc *old_ta = talloc; talloc = new rxvt_salloc (ncol * sizeof (text_t));
251 rxvt_salloc *old_ra = ralloc; ralloc = new rxvt_salloc (ncol * sizeof (rend_t));
252
253#if 0
254 if (nrow < prev_nrow)
255 {
256 for (int row = nrow; row < prev_nrow; row++)
257 {
258 lfree (swap_buf [row]);
259 lfree (drawn_buf[row]);
260 }
261 }
262#endif
263
264 drawn_buf = (line_t *)rxvt_realloc (drawn_buf, nrow * sizeof (line_t));
265 swap_buf = (line_t *)rxvt_realloc (swap_buf , nrow * sizeof (line_t));
266
267 for (int row = min (nrow, prev_nrow); row--; ) 279 for (int row = min (nrow, prev_nrow); row--; )
268 { 280 {
269 lresize (drawn_buf[row]); 281 scr_blank_screen_mem (drawn_buf [row], DEFAULT_RSTYLE);
270 lresize (swap_buf [row]); 282 scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE);
271 }
272 283
273 for (int row = prev_nrow; row < nrow; row++) 284 memcpy (drawn_buf [row].t, prev_drawn_buf [row].t, sizeof (text_t) * common_col);
285 memcpy (drawn_buf [row].r, prev_drawn_buf [row].r, sizeof (rend_t) * common_col);
286 memcpy (swap_buf [row].t, prev_swap_buf [row].t, sizeof (text_t) * common_col);
287 memcpy (swap_buf [row].r, prev_swap_buf [row].r, sizeof (rend_t) * common_col);
274 { 288 }
275 swap_buf [row].clear (); scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE);
276 drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE);
277 }
278
279 line_t *old_buf = row_buf;
280 row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t));
281 289
282 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row 290 int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row
283 int pend = MOD (term_start + top_row , prev_total_rows); 291 int pend = MOD (term_start + top_row , prev_total_rows);
284 int q = total_rows; // rewrapped row 292 int q = total_rows; // rewrapped row
285 293
293 ocur.row = MOD (term_start + ocur.row, prev_total_rows); 301 ocur.row = MOD (term_start + ocur.row, prev_total_rows);
294 302
295 do 303 do
296 { 304 {
297 p = MOD (p - 1, prev_total_rows); 305 p = MOD (p - 1, prev_total_rows);
298 assert (old_buf [MOD (p, prev_total_rows)].t); 306 assert (prev_row_buf [MOD (p, prev_total_rows)].t);
299 int plines = 1; 307 int plines = 1;
300 int llen = old_buf [MOD (p, prev_total_rows)].l; 308 int llen = prev_row_buf [MOD (p, prev_total_rows)].l;
301 309
302 while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ()) 310 while (p != pend && prev_row_buf [MOD (p - 1, prev_total_rows)].is_longer ())
303 { 311 {
304 p = MOD (p - 1, prev_total_rows); 312 p = MOD (p - 1, prev_total_rows);
305 313
306 plines++; 314 plines++;
307 llen += prev_ncol; 315 llen += prev_ncol;
320 328
321 // re-assemble the full line by destination lines 329 // re-assemble the full line by destination lines
322 for (int qrow = q; qlines--; qrow++) 330 for (int qrow = q; qlines--; qrow++)
323 { 331 {
324 qline = row_buf + qrow; 332 qline = row_buf + qrow;
325 lalloc (*qline); 333 qline->alloc (); // redundant with next line
326 qline->l = ncol; 334 qline->l = ncol;
327 qline->is_longer (1); 335 qline->is_longer (1);
328 336
329 int qcol = 0; 337 int qcol = 0;
330 338
345 // this seems to upset applications/shells/readline 353 // this seems to upset applications/shells/readline
346 // least. 354 // least.
347 if (prow == ocur.row) 355 if (prow == ocur.row)
348 screen.cur.row = q - (total_rows - nrow); 356 screen.cur.row = q - (total_rows - nrow);
349 357
350 line_t &pline = old_buf [prow]; 358 line_t &pline = prev_row_buf [prow];
351 359
352 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); 360 int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs);
353 361
354 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t)); 362 memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t));
355 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t)); 363 memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t));
376 { 384 {
377 // if no scrollback exists (yet), wing, instead of wrap 385 // if no scrollback exists (yet), wing, instead of wrap
378 386
379 for (int row = min (nrow, prev_nrow); row--; ) 387 for (int row = min (nrow, prev_nrow); row--; )
380 { 388 {
381 line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)]; 389 line_t &src = prev_row_buf [MOD (term_start + row, prev_total_rows)];
382 line_t &qline = row_buf [row]; 390 line_t &dst = row_buf [row];
383 391
384 qline = pline; 392 scr_blank_screen_mem (dst, DEFAULT_RSTYLE);
385 lresize (qline); 393
394 memcpy (dst.t, src.t, sizeof (text_t) * common_col);
395 memcpy (dst.r, src.r, sizeof (rend_t) * common_col);
386 } 396 }
387 397
388 for (int row = prev_nrow; row < nrow; row++) 398 for (int row = prev_nrow; row < nrow; row++)
389 {
390 row_buf [row].clear (); scr_blank_screen_mem (row_buf [row], DEFAULT_RSTYLE); 399 scr_blank_screen_mem (row_buf [row], DEFAULT_RSTYLE);
391 }
392 400
393 term_start = 0; 401 term_start = 0;
394 } 402 }
395
396 free (old_buf);
397 delete old_ta;
398 delete old_ra;
399 403
400 clamp_it (screen.cur.row, 0, nrow - 1); 404 clamp_it (screen.cur.row, 0, nrow - 1);
401 clamp_it (screen.cur.col, 0, ncol - 1); 405 clamp_it (screen.cur.col, 0, ncol - 1);
402 } 406 }
403 407
408 for (int row = nrow; row--; )
409 {
410 if (!ROW (row).valid ()) scr_blank_screen_mem (ROW (row), DEFAULT_RSTYLE);
411 if (!swap_buf [row].valid ()) scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE);
412 if (!drawn_buf [row].valid ()) scr_blank_screen_mem (drawn_buf [row], DEFAULT_RSTYLE);
413 }
414
415 free (prev_chunk);
416
404 free (tabs); 417 free (tabs);
405 tabs = (char *)rxvt_malloc (ncol); 418 tabs = (char *)rxvt_malloc (ncol);
406 419
407 for (int col = ncol; col--; ) 420 for (int col = ncol; col--; )
408 tabs [col] = col % TABSIZE == 0; 421 tabs [col] = col % TABSIZE == 0;
422 * Free everything. That way malloc debugging can find leakage. 435 * Free everything. That way malloc debugging can find leakage.
423 */ 436 */
424void 437void
425rxvt_term::scr_release () NOTHROW 438rxvt_term::scr_release () NOTHROW
426{ 439{
427 if (row_buf) 440 free (chunk);
428 {
429 delete talloc; talloc = 0;
430 delete ralloc; ralloc = 0;
431
432 free (row_buf);
433 free (swap_buf);
434 free (drawn_buf);
435 row_buf = 0; // signal that we freed all the arrays above
436
437 free (tabs); 441 free (tabs);
438 tabs = 0;
439 }
440} 442}
441 443
442/* ------------------------------------------------------------------------- */ 444/* ------------------------------------------------------------------------- */
443/* 445/*
444 * Hard/Soft reset 446 * Hard/Soft reset
445 */ 447 */
446void 448void
447rxvt_term::scr_poweron () 449rxvt_term::scr_poweron ()
448{ 450{
449 scr_release (); 451 scr_release ();
452
453 row_buf = 0;
454 tabs = 0;
450 prev_nrow = prev_ncol = 0; 455 prev_nrow = prev_ncol = 0;
451 rvideo_mode = false; 456 rvideo_mode = false;
452 scr_soft_reset (); 457 scr_soft_reset ();
453 scr_reset (); 458 scr_reset ();
454 459
2503} 2508}
2504 2509
2505void 2510void
2506rxvt_term::scr_remap_chars (line_t &l) NOTHROW 2511rxvt_term::scr_remap_chars (line_t &l) NOTHROW
2507{ 2512{
2508 if (!l.t) 2513 if (!l.valid ())
2509 return; 2514 return;
2510 2515
2511 l.touch (); // maybe a bit of an overkill, but it's not performance-relevant 2516 l.touch (); // maybe a bit of an overkill, but it's not performance-relevant
2512 2517
2513 for (int i = ncol; i--; ) 2518 for (int i = ncol; i--; )

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines