Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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) |
|
gkalsi
2016/03/09 21:13:37
DEBUG_ASSERT(fb);
cdotstout
2016/03/09 22:48:00
Done.
| |
| 661 { | 661 { |
| 662 gfx_surface *surface; | 662 gfx_surface *surface; |
| 663 gfx_format format; | 663 gfx_format format; |
| 664 switch (info->format) { | 664 switch (fb->image.format) { |
| 665 case DISPLAY_FORMAT_RGB_565: | 665 case IMAGE_FORMAT_RGB_565: |
| 666 format = GFX_FORMAT_RGB_565; | 666 format = GFX_FORMAT_RGB_565; |
| 667 break; | 667 break; |
| 668 case DISPLAY_FORMAT_RGB_332: | 668 case IMAGE_FORMAT_RGB_332: |
| 669 format = GFX_FORMAT_RGB_332; | 669 format = GFX_FORMAT_RGB_332; |
| 670 break; | 670 break; |
| 671 case DISPLAY_FORMAT_RGB_2220: | 671 case IMAGE_FORMAT_RGB_2220: |
| 672 format = GFX_FORMAT_RGB_2220; | 672 format = GFX_FORMAT_RGB_2220; |
| 673 break; | 673 break; |
| 674 case DISPLAY_FORMAT_ARGB_8888: | 674 case IMAGE_FORMAT_ARGB_8888: |
| 675 format = GFX_FORMAT_ARGB_8888; | 675 format = GFX_FORMAT_ARGB_8888; |
| 676 break; | 676 break; |
| 677 case DISPLAY_FORMAT_RGB_x888: | 677 case IMAGE_FORMAT_RGB_x888: |
| 678 format = GFX_FORMAT_RGB_x888; | 678 format = GFX_FORMAT_RGB_x888; |
| 679 break; | 679 break; |
| 680 case DISPLAY_FORMAT_MONO_8: | 680 case IMAGE_FORMAT_MONO_8: |
| 681 format = GFX_FORMAT_MONO; | 681 format = GFX_FORMAT_MONO; |
| 682 break; | 682 break; |
| 683 default: | 683 default: |
| 684 dprintf(INFO, "invalid graphics format)"); | 684 dprintf(INFO, "invalid graphics format)"); |
| 685 DEBUG_ASSERT(0); | 685 DEBUG_ASSERT(0); |
| 686 return NULL; | 686 return NULL; |
| 687 } | 687 } |
| 688 | 688 |
| 689 surface = gfx_create_surface(info->framebuffer, info->width, info->height, i nfo->stride, format); | 689 surface = gfx_create_surface(fb->image.pixels, fb->image.width, fb->image.he ight, fb->image.rowbytes, format); |
| 690 | 690 |
| 691 surface->flush = info->flush; | 691 surface->flush = fb->flush; |
| 692 | 692 |
| 693 return surface; | 693 return surface; |
| 694 } | 694 } |
| 695 | 695 |
| 696 /** | 696 /** |
| 697 * @brief Destroy a graphics surface and free all resources allocated to it. | 697 * @brief Destroy a graphics surface and free all resources allocated to it. |
| 698 * | 698 * |
| 699 * @param surface Surface to destroy. This pointer is no longer valid after | 699 * @param surface Surface to destroy. This pointer is no longer valid after |
| 700 * this call. | 700 * this call. |
| 701 */ | 701 */ |
| 702 void gfx_surface_destroy(struct gfx_surface *surface) | 702 void gfx_surface_destroy(struct gfx_surface *surface) |
| 703 { | 703 { |
| 704 if (surface->free_on_destroy) | 704 if (surface->free_on_destroy) |
| 705 free(surface->ptr); | 705 free(surface->ptr); |
| 706 free(surface); | 706 free(surface); |
| 707 } | 707 } |
| 708 | 708 |
| 709 /** | 709 /** |
| 710 * @brief Write a test pattern to the default display. | 710 * @brief Write a test pattern to the default display. |
| 711 */ | 711 */ |
| 712 void gfx_draw_pattern(void) | 712 void gfx_draw_pattern(void) |
| 713 { | 713 { |
| 714 struct display_info info; | 714 struct display_framebuffer fb; |
| 715 if (display_get_info(&info) < 0) | 715 if (display_get_framebuffer(&fb) < 0) |
| 716 return; | 716 return; |
| 717 | 717 |
| 718 gfx_surface *surface = gfx_create_surface_from_display(&info); | 718 gfx_surface *surface = gfx_create_surface_from_display(&fb); |
| 719 | 719 |
| 720 uint x, y; | 720 uint x, y; |
| 721 for (y = 0; y < surface->height; y++) { | 721 for (y = 0; y < surface->height; y++) { |
| 722 for (x = 0; x < surface->width; x++) { | 722 for (x = 0; x < surface->width; x++) { |
| 723 uint scaledx; | 723 uint scaledx; |
| 724 uint scaledy; | 724 uint scaledy; |
| 725 | 725 |
| 726 scaledx = x * 256 / surface->width; | 726 scaledx = x * 256 / surface->width; |
| 727 scaledy = y * 256 / surface->height; | 727 scaledy = y * 256 / surface->height; |
| 728 | 728 |
| 729 gfx_putpixel(surface, x, y, (0xff << 24) | (scaledx * scaledy) << 16 | (scaledx >> 1) << 8 | scaledy >> 1); | 729 gfx_putpixel(surface, x, y, (0xff << 24) | (scaledx * scaledy) << 16 | (scaledx >> 1) << 8 | scaledy >> 1); |
| 730 } | 730 } |
| 731 } | 731 } |
| 732 | 732 |
| 733 gfx_flush(surface); | 733 gfx_flush(surface); |
| 734 | 734 |
| 735 gfx_surface_destroy(surface); | 735 gfx_surface_destroy(surface); |
| 736 } | 736 } |
| 737 | 737 |
| 738 /** | 738 /** |
| 739 * @brief Fill default display with white | 739 * @brief Fill default display with white |
| 740 */ | 740 */ |
| 741 void gfx_draw_pattern_white(void) | 741 void gfx_draw_pattern_white(void) |
| 742 { | 742 { |
| 743 struct display_info info; | 743 struct display_framebuffer fb; |
| 744 if (display_get_info(&info) < 0) | 744 if (display_get_framebuffer(&fb) < 0) |
| 745 return; | 745 return; |
| 746 | 746 |
| 747 gfx_surface *surface = gfx_create_surface_from_display(&info); | 747 gfx_surface *surface = gfx_create_surface_from_display(&fb); |
| 748 | 748 |
| 749 uint x, y; | 749 uint x, y; |
| 750 for (y = 0; y < surface->height; y++) { | 750 for (y = 0; y < surface->height; y++) { |
| 751 for (x = 0; x < surface->width; x++) { | 751 for (x = 0; x < surface->width; x++) { |
| 752 gfx_putpixel(surface, x, y, 0xFFFFFFFF); | 752 gfx_putpixel(surface, x, y, 0xFFFFFFFF); |
| 753 } | 753 } |
| 754 } | 754 } |
| 755 | 755 |
| 756 gfx_flush(surface); | 756 gfx_flush(surface); |
| 757 | 757 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 802 if (argc < 2) { | 802 if (argc < 2) { |
| 803 printf("not enough arguments:\n"); | 803 printf("not enough arguments:\n"); |
| 804 printf("%s display_info : output information bout the current display\n" , argv[0].str); | 804 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) ; | 805 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); | 806 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); | 807 printf("%s fill r g b : Fill frame buffer with RGB888 value and force update\n", argv[0].str); |
| 808 | 808 |
| 809 return -1; | 809 return -1; |
| 810 } | 810 } |
| 811 | 811 |
| 812 struct display_info info; | 812 struct display_framebuffer fb; |
| 813 if (display_get_info(&info) < 0) { | 813 if (display_get_framebuffer(&fb) < 0) { |
| 814 printf("no display to draw on!\n"); | 814 printf("no display to draw on!\n"); |
| 815 return -1; | 815 return -1; |
| 816 } | 816 } |
| 817 | 817 |
| 818 gfx_surface *surface = gfx_create_surface_from_display(&info); | 818 gfx_surface *surface = gfx_create_surface_from_display(&fb); |
| 819 | 819 |
| 820 if (!strcmp(argv[1].str, "display_info")) { | 820 if (!strcmp(argv[1].str, "display_info")) { |
| 821 printf("display:\n"); | 821 printf("display:\n"); |
| 822 printf("\tframebuffer %p\n", info.framebuffer); | 822 printf("\tframebuffer %p\n", fb.image.pixels); |
| 823 printf("\twidth %u height %u stride %u\n", info.width, info.height, info .stride); | 823 printf("\twidth %u height %u stride %u\n", fb.image.width, fb.image.heig ht, fb.image.rowbytes); |
| 824 printf("\tformat %u\n", info.format); | 824 printf("\tformat %u\n", fb.image.format); |
| 825 } else if (!strcmp(argv[1].str, "rgb_bars")) { | 825 } else if (!strcmp(argv[1].str, "rgb_bars")) { |
| 826 gfx_draw_rgb_bars(surface); | 826 gfx_draw_rgb_bars(surface); |
| 827 } else if (!strcmp(argv[1].str, "test_pattern")) { | 827 } else if (!strcmp(argv[1].str, "test_pattern")) { |
| 828 gfx_draw_pattern(); | 828 gfx_draw_pattern(); |
| 829 } else if (!strcmp(argv[1].str, "fill")) { | 829 } else if (!strcmp(argv[1].str, "fill")) { |
| 830 uint x, y; | 830 uint x, y; |
| 831 | 831 |
| 832 for (y = 0; y < surface->height; y++) { | 832 for (y = 0; y < surface->height; y++) { |
| 833 for (x = 0; x < surface->width; x++) { | 833 for (x = 0; x < surface->width; x++) { |
| 834 /* write pixel to frame buffer */ | 834 /* write pixel to frame buffer */ |
| 835 gfx_putpixel(surface, x, y, (0xff << 24) | (argv[2].i << 16) | ( argv[3].i << 8) | argv[4].i); | 835 gfx_putpixel(surface, x, y, (0xff << 24) | (argv[2].i << 16) | ( argv[3].i << 8) | argv[4].i); |
| 836 } | 836 } |
| 837 } | 837 } |
| 838 } | 838 } |
| 839 | 839 |
| 840 gfx_flush(surface); | 840 gfx_flush(surface); |
| 841 | 841 |
| 842 gfx_surface_destroy(surface); | 842 gfx_surface_destroy(surface); |
| 843 | 843 |
| 844 return 0; | 844 return 0; |
| 845 } | 845 } |
| 846 | 846 |
| 847 #endif | 847 #endif |
| 848 #endif | 848 #endif |
| OLD | NEW |