From d429f1ba4f06923f6d6a88d4bbb50bca937b133a Mon Sep 17 00:00:00 2001 From: Mike Lowis Date: Mon, 26 Sep 2016 16:42:28 -0400 Subject: [PATCH] Added debugging code to debug xft issue on redrawing the screen --- Makefile | 2 +- docs/numbers.txt | 1001 ++++++++++++++++++++++++++++++++++++++++++++++ xedit.c | 78 ++-- 3 files changed, 1039 insertions(+), 42 deletions(-) create mode 100644 docs/numbers.txt diff --git a/Makefile b/Makefile index cc38fda..56f78e1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -LDFLAGS = -L/opt/X11/lib -lXft -lX11 +LDFLAGS = -L/opt/X11/lib -lX11 -lXft CFLAGS = --std=c99 -Wall -Wextra -I. -I/opt/X11/include -I/opt/local/include/freetype2 -I/usr/include/freetype2 SRCS = xedit.c buf.c OBJS = $(SRCS:.c=.o) diff --git a/docs/numbers.txt b/docs/numbers.txt new file mode 100644 index 0000000..bcd5f06 --- /dev/null +++ b/docs/numbers.txt @@ -0,0 +1,1001 @@ +10000000 +10000001 +10000002 +10000003 +10000004 +10000005 +10000006 +10000007 +10000008 +10000009 +10000010 +10000011 +10000012 +10000013 +10000014 +10000015 +10000016 +10000017 +10000018 +10000019 +10000020 +10000021 +10000022 +10000023 +10000024 +10000025 +10000026 +10000027 +10000028 +10000029 +10000030 +10000031 +10000032 +10000033 +10000034 +10000035 +10000036 +10000037 +10000038 +10000039 +10000040 +10000041 +10000042 +10000043 +10000044 +10000045 +10000046 +10000047 +10000048 +10000049 +10000050 +10000051 +10000052 +10000053 +10000054 +10000055 +10000056 +10000057 +10000058 +10000059 +10000060 +10000061 +10000062 +10000063 +10000064 +10000065 +10000066 +10000067 +10000068 +10000069 +10000070 +10000071 +10000072 +10000073 +10000074 +10000075 +10000076 +10000077 +10000078 +10000079 +10000080 +10000081 +10000082 +10000083 +10000084 +10000085 +10000086 +10000087 +10000088 +10000089 +10000090 +10000091 +10000092 +10000093 +10000094 +10000095 +10000096 +10000097 +10000098 +10000099 +10000100 +10000101 +10000102 +10000103 +10000104 +10000105 +10000106 +10000107 +10000108 +10000109 +10000110 +10000111 +10000112 +10000113 +10000114 +10000115 +10000116 +10000117 +10000118 +10000119 +10000120 +10000121 +10000122 +10000123 +10000124 +10000125 +10000126 +10000127 +10000128 +10000129 +10000130 +10000131 +10000132 +10000133 +10000134 +10000135 +10000136 +10000137 +10000138 +10000139 +10000140 +10000141 +10000142 +10000143 +10000144 +10000145 +10000146 +10000147 +10000148 +10000149 +10000150 +10000151 +10000152 +10000153 +10000154 +10000155 +10000156 +10000157 +10000158 +10000159 +10000160 +10000161 +10000162 +10000163 +10000164 +10000165 +10000166 +10000167 +10000168 +10000169 +10000170 +10000171 +10000172 +10000173 +10000174 +10000175 +10000176 +10000177 +10000178 +10000179 +10000180 +10000181 +10000182 +10000183 +10000184 +10000185 +10000186 +10000187 +10000188 +10000189 +10000190 +10000191 +10000192 +10000193 +10000194 +10000195 +10000196 +10000197 +10000198 +10000199 +10000200 +10000201 +10000202 +10000203 +10000204 +10000205 +10000206 +10000207 +10000208 +10000209 +10000210 +10000211 +10000212 +10000213 +10000214 +10000215 +10000216 +10000217 +10000218 +10000219 +10000220 +10000221 +10000222 +10000223 +10000224 +10000225 +10000226 +10000227 +10000228 +10000229 +10000230 +10000231 +10000232 +10000233 +10000234 +10000235 +10000236 +10000237 +10000238 +10000239 +10000240 +10000241 +10000242 +10000243 +10000244 +10000245 +10000246 +10000247 +10000248 +10000249 +10000250 +10000251 +10000252 +10000253 +10000254 +10000255 +10000256 +10000257 +10000258 +10000259 +10000260 +10000261 +10000262 +10000263 +10000264 +10000265 +10000266 +10000267 +10000268 +10000269 +10000270 +10000271 +10000272 +10000273 +10000274 +10000275 +10000276 +10000277 +10000278 +10000279 +10000280 +10000281 +10000282 +10000283 +10000284 +10000285 +10000286 +10000287 +10000288 +10000289 +10000290 +10000291 +10000292 +10000293 +10000294 +10000295 +10000296 +10000297 +10000298 +10000299 +10000300 +10000301 +10000302 +10000303 +10000304 +10000305 +10000306 +10000307 +10000308 +10000309 +10000310 +10000311 +10000312 +10000313 +10000314 +10000315 +10000316 +10000317 +10000318 +10000319 +10000320 +10000321 +10000322 +10000323 +10000324 +10000325 +10000326 +10000327 +10000328 +10000329 +10000330 +10000331 +10000332 +10000333 +10000334 +10000335 +10000336 +10000337 +10000338 +10000339 +10000340 +10000341 +10000342 +10000343 +10000344 +10000345 +10000346 +10000347 +10000348 +10000349 +10000350 +10000351 +10000352 +10000353 +10000354 +10000355 +10000356 +10000357 +10000358 +10000359 +10000360 +10000361 +10000362 +10000363 +10000364 +10000365 +10000366 +10000367 +10000368 +10000369 +10000370 +10000371 +10000372 +10000373 +10000374 +10000375 +10000376 +10000377 +10000378 +10000379 +10000380 +10000381 +10000382 +10000383 +10000384 +10000385 +10000386 +10000387 +10000388 +10000389 +10000390 +10000391 +10000392 +10000393 +10000394 +10000395 +10000396 +10000397 +10000398 +10000399 +10000400 +10000401 +10000402 +10000403 +10000404 +10000405 +10000406 +10000407 +10000408 +10000409 +10000410 +10000411 +10000412 +10000413 +10000414 +10000415 +10000416 +10000417 +10000418 +10000419 +10000420 +10000421 +10000422 +10000423 +10000424 +10000425 +10000426 +10000427 +10000428 +10000429 +10000430 +10000431 +10000432 +10000433 +10000434 +10000435 +10000436 +10000437 +10000438 +10000439 +10000440 +10000441 +10000442 +10000443 +10000444 +10000445 +10000446 +10000447 +10000448 +10000449 +10000450 +10000451 +10000452 +10000453 +10000454 +10000455 +10000456 +10000457 +10000458 +10000459 +10000460 +10000461 +10000462 +10000463 +10000464 +10000465 +10000466 +10000467 +10000468 +10000469 +10000470 +10000471 +10000472 +10000473 +10000474 +10000475 +10000476 +10000477 +10000478 +10000479 +10000480 +10000481 +10000482 +10000483 +10000484 +10000485 +10000486 +10000487 +10000488 +10000489 +10000490 +10000491 +10000492 +10000493 +10000494 +10000495 +10000496 +10000497 +10000498 +10000499 +10000500 +10000501 +10000502 +10000503 +10000504 +10000505 +10000506 +10000507 +10000508 +10000509 +10000510 +10000511 +10000512 +10000513 +10000514 +10000515 +10000516 +10000517 +10000518 +10000519 +10000520 +10000521 +10000522 +10000523 +10000524 +10000525 +10000526 +10000527 +10000528 +10000529 +10000530 +10000531 +10000532 +10000533 +10000534 +10000535 +10000536 +10000537 +10000538 +10000539 +10000540 +10000541 +10000542 +10000543 +10000544 +10000545 +10000546 +10000547 +10000548 +10000549 +10000550 +10000551 +10000552 +10000553 +10000554 +10000555 +10000556 +10000557 +10000558 +10000559 +10000560 +10000561 +10000562 +10000563 +10000564 +10000565 +10000566 +10000567 +10000568 +10000569 +10000570 +10000571 +10000572 +10000573 +10000574 +10000575 +10000576 +10000577 +10000578 +10000579 +10000580 +10000581 +10000582 +10000583 +10000584 +10000585 +10000586 +10000587 +10000588 +10000589 +10000590 +10000591 +10000592 +10000593 +10000594 +10000595 +10000596 +10000597 +10000598 +10000599 +10000600 +10000601 +10000602 +10000603 +10000604 +10000605 +10000606 +10000607 +10000608 +10000609 +10000610 +10000611 +10000612 +10000613 +10000614 +10000615 +10000616 +10000617 +10000618 +10000619 +10000620 +10000621 +10000622 +10000623 +10000624 +10000625 +10000626 +10000627 +10000628 +10000629 +10000630 +10000631 +10000632 +10000633 +10000634 +10000635 +10000636 +10000637 +10000638 +10000639 +10000640 +10000641 +10000642 +10000643 +10000644 +10000645 +10000646 +10000647 +10000648 +10000649 +10000650 +10000651 +10000652 +10000653 +10000654 +10000655 +10000656 +10000657 +10000658 +10000659 +10000660 +10000661 +10000662 +10000663 +10000664 +10000665 +10000666 +10000667 +10000668 +10000669 +10000670 +10000671 +10000672 +10000673 +10000674 +10000675 +10000676 +10000677 +10000678 +10000679 +10000680 +10000681 +10000682 +10000683 +10000684 +10000685 +10000686 +10000687 +10000688 +10000689 +10000690 +10000691 +10000692 +10000693 +10000694 +10000695 +10000696 +10000697 +10000698 +10000699 +10000700 +10000701 +10000702 +10000703 +10000704 +10000705 +10000706 +10000707 +10000708 +10000709 +10000710 +10000711 +10000712 +10000713 +10000714 +10000715 +10000716 +10000717 +10000718 +10000719 +10000720 +10000721 +10000722 +10000723 +10000724 +10000725 +10000726 +10000727 +10000728 +10000729 +10000730 +10000731 +10000732 +10000733 +10000734 +10000735 +10000736 +10000737 +10000738 +10000739 +10000740 +10000741 +10000742 +10000743 +10000744 +10000745 +10000746 +10000747 +10000748 +10000749 +10000750 +10000751 +10000752 +10000753 +10000754 +10000755 +10000756 +10000757 +10000758 +10000759 +10000760 +10000761 +10000762 +10000763 +10000764 +10000765 +10000766 +10000767 +10000768 +10000769 +10000770 +10000771 +10000772 +10000773 +10000774 +10000775 +10000776 +10000777 +10000778 +10000779 +10000780 +10000781 +10000782 +10000783 +10000784 +10000785 +10000786 +10000787 +10000788 +10000789 +10000790 +10000791 +10000792 +10000793 +10000794 +10000795 +10000796 +10000797 +10000798 +10000799 +10000800 +10000801 +10000802 +10000803 +10000804 +10000805 +10000806 +10000807 +10000808 +10000809 +10000810 +10000811 +10000812 +10000813 +10000814 +10000815 +10000816 +10000817 +10000818 +10000819 +10000820 +10000821 +10000822 +10000823 +10000824 +10000825 +10000826 +10000827 +10000828 +10000829 +10000830 +10000831 +10000832 +10000833 +10000834 +10000835 +10000836 +10000837 +10000838 +10000839 +10000840 +10000841 +10000842 +10000843 +10000844 +10000845 +10000846 +10000847 +10000848 +10000849 +10000850 +10000851 +10000852 +10000853 +10000854 +10000855 +10000856 +10000857 +10000858 +10000859 +10000860 +10000861 +10000862 +10000863 +10000864 +10000865 +10000866 +10000867 +10000868 +10000869 +10000870 +10000871 +10000872 +10000873 +10000874 +10000875 +10000876 +10000877 +10000878 +10000879 +10000880 +10000881 +10000882 +10000883 +10000884 +10000885 +10000886 +10000887 +10000888 +10000889 +10000890 +10000891 +10000892 +10000893 +10000894 +10000895 +10000896 +10000897 +10000898 +10000899 +10000900 +10000901 +10000902 +10000903 +10000904 +10000905 +10000906 +10000907 +10000908 +10000909 +10000910 +10000911 +10000912 +10000913 +10000914 +10000915 +10000916 +10000917 +10000918 +10000919 +10000920 +10000921 +10000922 +10000923 +10000924 +10000925 +10000926 +10000927 +10000928 +10000929 +10000930 +10000931 +10000932 +10000933 +10000934 +10000935 +10000936 +10000937 +10000938 +10000939 +10000940 +10000941 +10000942 +10000943 +10000944 +10000945 +10000946 +10000947 +10000948 +10000949 +10000950 +10000951 +10000952 +10000953 +10000954 +10000955 +10000956 +10000957 +10000958 +10000959 +10000960 +10000961 +10000962 +10000963 +10000964 +10000965 +10000966 +10000967 +10000968 +10000969 +10000970 +10000971 +10000972 +10000973 +10000974 +10000975 +10000976 +10000977 +10000978 +10000979 +10000980 +10000981 +10000982 +10000983 +10000984 +10000985 +10000986 +10000987 +10000988 +10000989 +10000990 +10000991 +10000992 +10000993 +10000994 +10000995 +10000996 +10000997 +10000998 +10000999 +10001000 diff --git a/xedit.c b/xedit.c index e092175..a1a0656 100644 --- a/xedit.c +++ b/xedit.c @@ -42,6 +42,17 @@ static uint64_t time_ms(void) { return (ts.tv_sec * 1000000000L + ts.tv_nsec) / 1000000L; } +static XftColor xftcolor(enum ColorId cid) { + Color c = Palette[cid][ColorBase]; + XftColor xc; + xc.color.red = ((c & 0x00FF0000) >> 8); + xc.color.green = ((c & 0x0000FF00)); + xc.color.blue = ((c & 0x000000FF) << 8); + xc.color.alpha = UINT16_MAX; + XftColorAllocValue(X.display, X.visual, X.colormap, &xc.color, &xc); + return xc; +} + static int init(void) { signal(SIGPIPE, SIG_IGN); // Ignore the SIGPIPE signal /* open the X display and get basic attributes */ @@ -201,26 +212,10 @@ static void handle_event(XEvent* e) { } } -static XftColor xftcolor(enum ColorId cid) { - Color c = Palette[cid][ColorBase]; - XftColor xc; - xc.color.red = ((c & 0x00FF0000) >> 8); - xc.color.green = ((c & 0x0000FF00)); - xc.color.blue = ((c & 0x000000FF) << 8); - xc.color.alpha = UINT16_MAX; - XftColorAllocValue(X.display, X.visual, X.colormap, &xc.color, &xc); - return xc; -} - static void redraw(void) { - static uint64_t last_draw = 0; - uint64_t current = time_ms(); - //if (current - last_draw < 200) - // return; - last_draw = current; - - puts("redraw"); - uint64_t t1start = time_ms(), t1end; + uint64_t tstart; + + tstart = time_ms(); int fheight = X.font->height; int fwidth = X.font->max_advance_width; /* Allocate the colors */ @@ -232,8 +227,10 @@ static void redraw(void) { XftDrawRect(X.xft, &bkgclr, 0, 0, X.width, X.height); /* draw the status background */ XftDrawRect(X.xft, >rclr, 0, 0, X.width, fheight); + printf("\nT1: %lu\n", time_ms() - tstart); + /* Draw document text */ - uint64_t t2start = time_ms(), t2end; + tstart = time_ms(); int x = 0, y = 2; for (LastDrawnPos = StartRow; LastDrawnPos < buf_end(&Buffer); LastDrawnPos++) { if (x * fwidth >= X.width) @@ -257,37 +254,36 @@ static void redraw(void) { x++; } EndRow = buf_bol(&Buffer, LastDrawnPos-2); - t2end = time_ms(); - printf("text time: %lu\n", t2end - t2start); + printf("T2: %lu\n", time_ms() - tstart); + + + tstart = time_ms(); /* flush the pixels to the screen */ XCopyArea(X.display, X.pixmap, X.window, X.gc, 0, 0, X.width, X.height, 0, 0); + printf("T3: %lu\n", time_ms() - tstart); + + tstart = time_ms(); XFlush(X.display); - t1end = time_ms(); - printf("redraw time: %lu\n", t1end - t1start); + printf("T4: %lu\n", time_ms() - tstart); } int main(int argc, char** argv) { - init(); + /* load the buffer */ buf_init(&Buffer); if (argc > 1) buf_load(&Buffer, argv[1]); + /* main x11 event loop */ + init(); XEvent e; - - while(XNextEvent(X.display, &e) >= 0) { - handle_event(&e); - if (!XPending(X.display)) { - redraw(); - } - } - //while (true) { - //XPeekEvent(X.display,&e); - //while (XPending(X.display)) { - // XNextEvent(X.display, &e); - // if (!XFilterEvent(&e, None)) - // handle_event(&e); - //} - //redraw(); - //} + while (true) { + XPeekEvent(X.display,&e); + while (XPending(X.display)) { + XNextEvent(X.display, &e); + if (!XFilterEvent(&e, None)) + handle_event(&e); + } + redraw(); + } deinit(); return 0; } -- 2.51.0