Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: lib/gfx/gfx.c

Issue 1777783003: [display] Refactor to avoid implicit framebuffer allocation. (Closed) Base URL: https://github.com/littlekernel/lk.git@master
Patch Set: fix stride confusion Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/lib/gfx.h ('k') | lib/gfxconsole/gfxconsole.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2008-2010, 2015 Travis Geiselbrecht 2 * Copyright (c) 2008-2010, 2015 Travis Geiselbrecht
3 * 3 *
4 * Permission is hereby granted, free of charge, to any person obtaining 4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files 5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction, 6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge, 7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software, 8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so, 9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions: 10 * subject to the following conditions:
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 surface->free_on_destroy = true; 650 surface->free_on_destroy = true;
651 } 651 }
652 surface->ptr = ptr; 652 surface->ptr = ptr;
653 653
654 return surface; 654 return surface;
655 } 655 }
656 656
657 /** 657 /**
658 * @brief Create a new graphics surface object from a display 658 * @brief Create a new graphics surface object from a display
659 */ 659 */
660 gfx_surface *gfx_create_surface_from_display(struct display_info *info) 660 gfx_surface *gfx_create_surface_from_display(struct display_framebuffer *fb)
661 { 661 {
662 DEBUG_ASSERT(fb);
662 gfx_surface *surface; 663 gfx_surface *surface;
663 gfx_format format; 664 gfx_format format;
664 switch (info->format) { 665 switch (fb->image.format) {
665 case DISPLAY_FORMAT_RGB_565: 666 case IMAGE_FORMAT_RGB_565:
666 format = GFX_FORMAT_RGB_565; 667 format = GFX_FORMAT_RGB_565;
667 break; 668 break;
668 case DISPLAY_FORMAT_RGB_332: 669 case IMAGE_FORMAT_RGB_332:
669 format = GFX_FORMAT_RGB_332; 670 format = GFX_FORMAT_RGB_332;
670 break; 671 break;
671 case DISPLAY_FORMAT_RGB_2220: 672 case IMAGE_FORMAT_RGB_2220:
672 format = GFX_FORMAT_RGB_2220; 673 format = GFX_FORMAT_RGB_2220;
673 break; 674 break;
674 case DISPLAY_FORMAT_ARGB_8888: 675 case IMAGE_FORMAT_ARGB_8888:
675 format = GFX_FORMAT_ARGB_8888; 676 format = GFX_FORMAT_ARGB_8888;
676 break; 677 break;
677 case DISPLAY_FORMAT_RGB_x888: 678 case IMAGE_FORMAT_RGB_x888:
678 format = GFX_FORMAT_RGB_x888; 679 format = GFX_FORMAT_RGB_x888;
679 break; 680 break;
680 case DISPLAY_FORMAT_MONO_8: 681 case IMAGE_FORMAT_MONO_8:
681 format = GFX_FORMAT_MONO; 682 format = GFX_FORMAT_MONO;
682 break; 683 break;
683 default: 684 default:
684 dprintf(INFO, "invalid graphics format)"); 685 dprintf(INFO, "invalid graphics format)");
685 DEBUG_ASSERT(0); 686 DEBUG_ASSERT(0);
686 return NULL; 687 return NULL;
687 } 688 }
688 689
689 surface = gfx_create_surface(info->framebuffer, info->width, info->height, i nfo->stride, format); 690 surface = gfx_create_surface(fb->image.pixels, fb->image.width, fb->image.he ight, fb->image.stride, format);
690 691
691 surface->flush = info->flush; 692 surface->flush = fb->flush;
692 693
693 return surface; 694 return surface;
694 } 695 }
695 696
696 /** 697 /**
697 * @brief Destroy a graphics surface and free all resources allocated to it. 698 * @brief Destroy a graphics surface and free all resources allocated to it.
698 * 699 *
699 * @param surface Surface to destroy. This pointer is no longer valid after 700 * @param surface Surface to destroy. This pointer is no longer valid after
700 * this call. 701 * this call.
701 */ 702 */
702 void gfx_surface_destroy(struct gfx_surface *surface) 703 void gfx_surface_destroy(struct gfx_surface *surface)
703 { 704 {
704 if (surface->free_on_destroy) 705 if (surface->free_on_destroy)
705 free(surface->ptr); 706 free(surface->ptr);
706 free(surface); 707 free(surface);
707 } 708 }
708 709
709 /** 710 /**
710 * @brief Write a test pattern to the default display. 711 * @brief Write a test pattern to the default display.
711 */ 712 */
712 void gfx_draw_pattern(void) 713 void gfx_draw_pattern(void)
713 { 714 {
714 struct display_info info; 715 struct display_framebuffer fb;
715 if (display_get_info(&info) < 0) 716 if (display_get_framebuffer(&fb) < 0)
716 return; 717 return;
717 718
718 gfx_surface *surface = gfx_create_surface_from_display(&info); 719 gfx_surface *surface = gfx_create_surface_from_display(&fb);
719 720
720 uint x, y; 721 uint x, y;
721 for (y = 0; y < surface->height; y++) { 722 for (y = 0; y < surface->height; y++) {
722 for (x = 0; x < surface->width; x++) { 723 for (x = 0; x < surface->width; x++) {
723 uint scaledx; 724 uint scaledx;
724 uint scaledy; 725 uint scaledy;
725 726
726 scaledx = x * 256 / surface->width; 727 scaledx = x * 256 / surface->width;
727 scaledy = y * 256 / surface->height; 728 scaledy = y * 256 / surface->height;
728 729
729 gfx_putpixel(surface, x, y, (0xff << 24) | (scaledx * scaledy) << 16 | (scaledx >> 1) << 8 | scaledy >> 1); 730 gfx_putpixel(surface, x, y, (0xff << 24) | (scaledx * scaledy) << 16 | (scaledx >> 1) << 8 | scaledy >> 1);
730 } 731 }
731 } 732 }
732 733
733 gfx_flush(surface); 734 gfx_flush(surface);
734 735
735 gfx_surface_destroy(surface); 736 gfx_surface_destroy(surface);
736 } 737 }
737 738
738 /** 739 /**
739 * @brief Fill default display with white 740 * @brief Fill default display with white
740 */ 741 */
741 void gfx_draw_pattern_white(void) 742 void gfx_draw_pattern_white(void)
742 { 743 {
743 struct display_info info; 744 struct display_framebuffer fb;
744 if (display_get_info(&info) < 0) 745 if (display_get_framebuffer(&fb) < 0)
745 return; 746 return;
746 747
747 gfx_surface *surface = gfx_create_surface_from_display(&info); 748 gfx_surface *surface = gfx_create_surface_from_display(&fb);
748 749
749 uint x, y; 750 uint x, y;
750 for (y = 0; y < surface->height; y++) { 751 for (y = 0; y < surface->height; y++) {
751 for (x = 0; x < surface->width; x++) { 752 for (x = 0; x < surface->width; x++) {
752 gfx_putpixel(surface, x, y, 0xFFFFFFFF); 753 gfx_putpixel(surface, x, y, 0xFFFFFFFF);
753 } 754 }
754 } 755 }
755 756
756 gfx_flush(surface); 757 gfx_flush(surface);
757 758
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 if (argc < 2) { 803 if (argc < 2) {
803 printf("not enough arguments:\n"); 804 printf("not enough arguments:\n");
804 printf("%s display_info : output information bout the current display\n" , argv[0].str); 805 printf("%s display_info : output information bout the current display\n" , argv[0].str);
805 printf("%s rgb_bars : Fill frame buffer with rgb bars\n", argv[0].str) ; 806 printf("%s rgb_bars : Fill frame buffer with rgb bars\n", argv[0].str) ;
806 printf("%s test_pattern : Fill frame with test pattern\n", argv[0].str); 807 printf("%s test_pattern : Fill frame with test pattern\n", argv[0].str);
807 printf("%s fill r g b : Fill frame buffer with RGB888 value and force update\n", argv[0].str); 808 printf("%s fill r g b : Fill frame buffer with RGB888 value and force update\n", argv[0].str);
808 809
809 return -1; 810 return -1;
810 } 811 }
811 812
812 struct display_info info; 813 struct display_framebuffer fb;
813 if (display_get_info(&info) < 0) { 814 if (display_get_framebuffer(&fb) < 0) {
814 printf("no display to draw on!\n"); 815 printf("no display to draw on!\n");
815 return -1; 816 return -1;
816 } 817 }
817 818
818 gfx_surface *surface = gfx_create_surface_from_display(&info); 819 gfx_surface *surface = gfx_create_surface_from_display(&fb);
819 820
820 if (!strcmp(argv[1].str, "display_info")) { 821 if (!strcmp(argv[1].str, "display_info")) {
821 printf("display:\n"); 822 printf("display:\n");
822 printf("\tframebuffer %p\n", info.framebuffer); 823 printf("\tframebuffer %p\n", fb.image.pixels);
823 printf("\twidth %u height %u stride %u\n", info.width, info.height, info .stride); 824 printf("\twidth %u height %u stride %u\n", fb.image.width, fb.image.heig ht, fb.image.stride);
824 printf("\tformat %u\n", info.format); 825 printf("\tformat %u\n", fb.image.format);
825 } else if (!strcmp(argv[1].str, "rgb_bars")) { 826 } else if (!strcmp(argv[1].str, "rgb_bars")) {
826 gfx_draw_rgb_bars(surface); 827 gfx_draw_rgb_bars(surface);
827 } else if (!strcmp(argv[1].str, "test_pattern")) { 828 } else if (!strcmp(argv[1].str, "test_pattern")) {
828 gfx_draw_pattern(); 829 gfx_draw_pattern();
829 } else if (!strcmp(argv[1].str, "fill")) { 830 } else if (!strcmp(argv[1].str, "fill")) {
830 uint x, y; 831 uint x, y;
831 832
832 for (y = 0; y < surface->height; y++) { 833 for (y = 0; y < surface->height; y++) {
833 for (x = 0; x < surface->width; x++) { 834 for (x = 0; x < surface->width; x++) {
834 /* write pixel to frame buffer */ 835 /* write pixel to frame buffer */
835 gfx_putpixel(surface, x, y, (0xff << 24) | (argv[2].i << 16) | ( argv[3].i << 8) | argv[4].i); 836 gfx_putpixel(surface, x, y, (0xff << 24) | (argv[2].i << 16) | ( argv[3].i << 8) | argv[4].i);
836 } 837 }
837 } 838 }
838 } 839 }
839 840
840 gfx_flush(surface); 841 gfx_flush(surface);
841 842
842 gfx_surface_destroy(surface); 843 gfx_surface_destroy(surface);
843 844
844 return 0; 845 return 0;
845 } 846 }
846 847
847 #endif 848 #endif
848 #endif 849 #endif
OLDNEW
« no previous file with comments | « include/lib/gfx.h ('k') | lib/gfxconsole/gfxconsole.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698