├── .gitignore ├── LICENSE ├── README.md ├── fb1 ├── README.md └── fb.h ├── fb2 ├── README.md ├── fbtool.c ├── fbtool.h ├── test └── test.c ├── fb3 ├── README.md ├── fbtool.c ├── fbtool.h ├── test └── test.c ├── fb4-fix ├── README.md ├── fbtool.c ├── fbtool.h ├── test └── test.c ├── fb5 ├── Makefile ├── README.md ├── fbtool.c ├── fbtool.h ├── page.h ├── screenshot.jpg ├── test └── test.c ├── fb6 ├── Makefile ├── README.md ├── color.h ├── fbtool.c ├── fbtool.h ├── jiafei.gif ├── page.h ├── test └── test.c └── fb7 ├── Makefile ├── README.md ├── circle.c ├── circle.h ├── color.h ├── fbtool.c ├── fbtool.h ├── line.c ├── line.h ├── page.h ├── point.c ├── point.h ├── rectangle.c ├── rectangle.h ├── test.c └── video.mp4 /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fb 2 | 该库首先是学习framebuffer的一些例程,后面就是使用framebuffer实现linux的屏幕截屏,然后再使用framebuffer实现一款android app的屏幕截屏,最后,尝试使用frame buffer来实现屏幕录制. 3 | -------------------------------------------------------------------------------- /fb1/README.md: -------------------------------------------------------------------------------- 1 | **(一):写在前面** 2 | 3 | 这是我学习framebuffer的第一篇笔记,我个人认为,要学习一个知识,就要从他的根本上学起.就像我现在刚刚接触的framebuffer,如果我想要进行framebuffer编程,就要了解framebuffer如何被定义的,以及内核中都是定义了哪些对framebuffer的ioctl的操作.所以,我首先做的就是对linux内核源码根目录/include/linux/fb.h中的有关与framebuffer的内容进行了大略的学习,将其中的关键部分进行了较为详细的注释. 4 | 5 | **(二):重点内容介绍** 6 | 7 | 在整个内核fb.h代码的阅读期间,我感觉理解framebuffer比较重要的几个结构体和函数: 8 | 9 | *1:struct fb_fix_screeninfo* 10 | 11 | 该结构体用于描述显卡自身的属性包括识别符,缓存地址,显卡类型等 12 | 13 | *2:struct fb_var_screeninfo* 14 | 15 | 用于描述显卡的一般特性,比如实际分辨率,虚拟分辨率,实际分辨率和虚拟分辨率之间的位移等 16 | 17 | *3:struct fb_ops* 18 | 19 | 该结构体主要定义了对framebuffer的一些操作 20 | 21 | *4:struct fb_info* 22 | 23 | 该结构体主要定义了一些关于framebuffer的一些信息以及其相关的操作 24 | 25 | **(三):后面内容介绍** 26 | 27 | 在后面的内容中,首先进行framebuffer编程的实验操作,打开framebuffer,打印相关属性等的操作.后铺面再进行更加深入的学习. 28 | 29 | **(四):写在后面** 30 | 31 | 冰冻三尺,非一日之寒.每天进步一点点,加油. -------------------------------------------------------------------------------- /fb1/fb.h: -------------------------------------------------------------------------------- 1 | #ifndef _LINUX_FB_H 2 | #define _LINUX_FB_H 3 | 4 | #include 5 | #include 6 | 7 | struct dentry; 8 | 9 | /* Definitions of frame buffers frame buffer的定义 */ 10 | 11 | #define FB_MAX 32 /* sufficient for now  对于现在来说足够了 */ 12 | 13 | /* ioctls 14 | 0x46 is 'F' */ 15 | #define FBIOGET_VSCREENINFO 0x4600 16 | #define FBIOPUT_VSCREENINFO 0x4601 17 | #define FBIOGET_FSCREENINFO 0x4602 18 | #define FBIOGETCMAP 0x4604 19 | #define FBIOPUTCMAP 0x4605 20 | #define FBIOPAN_DISPLAY 0x4606 21 | #ifdef __KERNEL__ 22 | #define FBIO_CURSOR _IOWR('F', 0x08, struct fb_cursor_user) 23 | #else 24 | #define FBIO_CURSOR _IOWR('F', 0x08, struct fb_cursor) 25 | #endif 26 | /* 0x4607-0x460B are defined below */ 27 | /* #define FBIOGET_MONITORSPEC 0x460C */ 28 | /* #define FBIOPUT_MONITORSPEC 0x460D */ 29 | /* #define FBIOSWITCH_MONIBIT 0x460E */ 30 | #define FBIOGET_CON2FBMAP 0x460F 31 | #define FBIOPUT_CON2FBMAP 0x4610 32 | #define FBIOBLANK 0x4611 /* arg: 0 or vesa level + 1 */ 33 | #define FBIOGET_VBLANK _IOR('F', 0x12, struct fb_vblank) 34 | #define FBIO_ALLOC 0x4613 35 | #define FBIO_FREE 0x4614 36 | #define FBIOGET_GLYPH 0x4615 37 | #define FBIOGET_HWCINFO 0x4616 38 | #define FBIOPUT_MODEINFO 0x4617 39 | #define FBIOGET_DISPINFO 0x4618 40 | 41 | 42 | #define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels 填充的像素 */ 43 | #define FB_TYPE_PLANES 1 /* Non interleaved planes 非交错平面 */ 44 | #define FB_TYPE_INTERLEAVED_PLANES 2 /* Interleaved planes 交错的平面 */ 45 | #define FB_TYPE_TEXT 3 /* Text/attributes 文本/属性 */ 46 | #define FB_TYPE_VGA_PLANES 4 /* EGA/VGA planes EGA/VGA 平面 */ 47 | 48 | #define FB_AUX_TEXT_MDA 0 /* Monochrome text 单色文本 */ 49 | #define FB_AUX_TEXT_CGA 1 /* CGA/EGA/VGA Color text CGA/EGA/VGA色彩文本 */ 50 | #define FB_AUX_TEXT_S3_MMIO 2 /* S3 MMIO fasttext */ 51 | #define FB_AUX_TEXT_MGA_STEP16 3 /* MGA Millenium I: text, attr, 14 reserved bytes */ 52 | #define FB_AUX_TEXT_MGA_STEP8 4 /* other MGAs: text, attr, 6 reserved bytes */ 53 | #define FB_AUX_TEXT_SVGA_GROUP 8 /* 8-15: SVGA tileblit compatible modes */ 54 | #define FB_AUX_TEXT_SVGA_MASK 7 /* lower three bits says step */ 55 | #define FB_AUX_TEXT_SVGA_STEP2 8 /* SVGA text mode: text, attr */ 56 | #define FB_AUX_TEXT_SVGA_STEP4 9 /* SVGA text mode: text, attr, 2 reserved bytes */ 57 | #define FB_AUX_TEXT_SVGA_STEP8 10 /* SVGA text mode: text, attr, 6 reserved bytes */ 58 | #define FB_AUX_TEXT_SVGA_STEP16 11 /* SVGA text mode: text, attr, 14 reserved bytes */ 59 | #define FB_AUX_TEXT_SVGA_LAST 15 /* reserved up to 15 */ 60 | 61 | #define FB_AUX_VGA_PLANES_VGA4 0 /* 16 color planes (EGA/VGA) */ 62 | #define FB_AUX_VGA_PLANES_CFB4 1 /* CFB4 in planes (VGA) */ 63 | #define FB_AUX_VGA_PLANES_CFB8 2 /* CFB8 in planes (VGA) */ 64 | 65 | #define FB_VISUAL_MONO01 0 /* Monochr. 1=Black 0=White  1=黑色,2=白色*/ 66 | #define FB_VISUAL_MONO10 1 /* Monochr. 1=White 0=Black 1=白色,2=黑色*/ 67 | #define FB_VISUAL_TRUECOLOR 2 /* True color 真实的颜色 */ 68 | #define FB_VISUAL_PSEUDOCOLOR 3 /* Pseudo color (like atari) 伪颜色*/ 69 | #define FB_VISUAL_DIRECTCOLOR 4 /* Direct color 直接颜色 */ 70 | #define FB_VISUAL_STATIC_PSEUDOCOLOR 5 /* Pseudo color readonly 只读伪颜色*/ 71 | 72 | #define FB_ACCEL_NONE 0 /* no hardware accelerator 没有硬件加速 */ 73 | #define FB_ACCEL_ATARIBLITT 1 /* Atari Blitter */ 74 | #define FB_ACCEL_AMIGABLITT 2 /* Amiga Blitter */ 75 | #define FB_ACCEL_S3_TRIO64 3 /* Cybervision64 (S3 Trio64) */ 76 | #define FB_ACCEL_NCR_77C32BLT 4 /* RetinaZ3 (NCR 77C32BLT) */ 77 | #define FB_ACCEL_S3_VIRGE 5 /* Cybervision64/3D (S3 ViRGE) */ 78 | #define FB_ACCEL_ATI_MACH64GX 6 /* ATI Mach 64GX family */ 79 | #define FB_ACCEL_DEC_TGA 7 /* DEC 21030 TGA */ 80 | #define FB_ACCEL_ATI_MACH64CT 8 /* ATI Mach 64CT family */ 81 | #define FB_ACCEL_ATI_MACH64VT 9 /* ATI Mach 64CT family VT class */ 82 | #define FB_ACCEL_ATI_MACH64GT 10 /* ATI Mach 64CT family GT class */ 83 | #define FB_ACCEL_SUN_CREATOR 11 /* Sun Creator/Creator3D */ 84 | #define FB_ACCEL_SUN_CGSIX 12 /* Sun cg6 */ 85 | #define FB_ACCEL_SUN_LEO 13 /* Sun leo/zx */ 86 | #define FB_ACCEL_IMS_TWINTURBO 14 /* IMS Twin Turbo */ 87 | #define FB_ACCEL_3DLABS_PERMEDIA2 15 /* 3Dlabs Permedia 2 */ 88 | #define FB_ACCEL_MATROX_MGA2064W 16 /* Matrox MGA2064W (Millenium) */ 89 | #define FB_ACCEL_MATROX_MGA1064SG 17 /* Matrox MGA1064SG (Mystique) */ 90 | #define FB_ACCEL_MATROX_MGA2164W 18 /* Matrox MGA2164W (Millenium II) */ 91 | #define FB_ACCEL_MATROX_MGA2164W_AGP 19 /* Matrox MGA2164W (Millenium II) */ 92 | #define FB_ACCEL_MATROX_MGAG100 20 /* Matrox G100 (Productiva G100) */ 93 | #define FB_ACCEL_MATROX_MGAG200 21 /* Matrox G200 (Myst, Mill, ...) */ 94 | #define FB_ACCEL_SUN_CG14 22 /* Sun cgfourteen */ 95 | #define FB_ACCEL_SUN_BWTWO 23 /* Sun bwtwo */ 96 | #define FB_ACCEL_SUN_CGTHREE 24 /* Sun cgthree */ 97 | #define FB_ACCEL_SUN_TCX 25 /* Sun tcx */ 98 | #define FB_ACCEL_MATROX_MGAG400 26 /* Matrox G400 */ 99 | #define FB_ACCEL_NV3 27 /* nVidia RIVA 128 */ 100 | #define FB_ACCEL_NV4 28 /* nVidia RIVA TNT */ 101 | #define FB_ACCEL_NV5 29 /* nVidia RIVA TNT2 */ 102 | #define FB_ACCEL_CT_6555x 30 /* C&T 6555x */ 103 | #define FB_ACCEL_3DFX_BANSHEE 31 /* 3Dfx Banshee */ 104 | #define FB_ACCEL_ATI_RAGE128 32 /* ATI Rage128 family */ 105 | #define FB_ACCEL_IGS_CYBER2000 33 /* CyberPro 2000 */ 106 | #define FB_ACCEL_IGS_CYBER2010 34 /* CyberPro 2010 */ 107 | #define FB_ACCEL_IGS_CYBER5000 35 /* CyberPro 5000 */ 108 | #define FB_ACCEL_SIS_GLAMOUR 36 /* SiS 300/630/540 */ 109 | #define FB_ACCEL_3DLABS_PERMEDIA3 37 /* 3Dlabs Permedia 3 */ 110 | #define FB_ACCEL_ATI_RADEON 38 /* ATI Radeon family */ 111 | #define FB_ACCEL_I810 39 /* Intel 810/815 */ 112 | #define FB_ACCEL_SIS_GLAMOUR_2 40 /* SiS 315, 650, 740 */ 113 | #define FB_ACCEL_SIS_XABRE 41 /* SiS 330 ("Xabre") */ 114 | #define FB_ACCEL_I830 42 /* Intel 830M/845G/85x/865G */ 115 | #define FB_ACCEL_NV_10 43 /* nVidia Arch 10 */ 116 | #define FB_ACCEL_NV_20 44 /* nVidia Arch 20 */ 117 | #define FB_ACCEL_NV_30 45 /* nVidia Arch 30 */ 118 | #define FB_ACCEL_NV_40 46 /* nVidia Arch 40 */ 119 | #define FB_ACCEL_XGI_VOLARI_V 47 /* XGI Volari V3XT, V5, V8 */ 120 | #define FB_ACCEL_XGI_VOLARI_Z 48 /* XGI Volari Z7 */ 121 | #define FB_ACCEL_OMAP1610 49 /* TI OMAP16xx */ 122 | #define FB_ACCEL_TRIDENT_TGUI 50 /* Trident TGUI */ 123 | #define FB_ACCEL_TRIDENT_3DIMAGE 51 /* Trident 3DImage */ 124 | #define FB_ACCEL_TRIDENT_BLADE3D 52 /* Trident Blade3D */ 125 | #define FB_ACCEL_TRIDENT_BLADEXP 53 /* Trident BladeXP */ 126 | #define FB_ACCEL_CIRRUS_ALPINE 53 /* Cirrus Logic 543x/544x/5480 */ 127 | #define FB_ACCEL_NEOMAGIC_NM2070 90 /* NeoMagic NM2070 */ 128 | #define FB_ACCEL_NEOMAGIC_NM2090 91 /* NeoMagic NM2090 */ 129 | #define FB_ACCEL_NEOMAGIC_NM2093 92 /* NeoMagic NM2093 */ 130 | #define FB_ACCEL_NEOMAGIC_NM2097 93 /* NeoMagic NM2097 */ 131 | #define FB_ACCEL_NEOMAGIC_NM2160 94 /* NeoMagic NM2160 */ 132 | #define FB_ACCEL_NEOMAGIC_NM2200 95 /* NeoMagic NM2200 */ 133 | #define FB_ACCEL_NEOMAGIC_NM2230 96 /* NeoMagic NM2230 */ 134 | #define FB_ACCEL_NEOMAGIC_NM2360 97 /* NeoMagic NM2360 */ 135 | #define FB_ACCEL_NEOMAGIC_NM2380 98 /* NeoMagic NM2380 */ 136 | #define FB_ACCEL_PXA3XX 99 /* PXA3xx */ 137 | 138 | #define FB_ACCEL_SAVAGE4 0x80 /* S3 Savage4 */ 139 | #define FB_ACCEL_SAVAGE3D 0x81 /* S3 Savage3D */ 140 | #define FB_ACCEL_SAVAGE3D_MV 0x82 /* S3 Savage3D-MV */ 141 | #define FB_ACCEL_SAVAGE2000 0x83 /* S3 Savage2000 */ 142 | #define FB_ACCEL_SAVAGE_MX_MV 0x84 /* S3 Savage/MX-MV */ 143 | #define FB_ACCEL_SAVAGE_MX 0x85 /* S3 Savage/MX */ 144 | #define FB_ACCEL_SAVAGE_IX_MV 0x86 /* S3 Savage/IX-MV */ 145 | #define FB_ACCEL_SAVAGE_IX 0x87 /* S3 Savage/IX */ 146 | #define FB_ACCEL_PROSAVAGE_PM 0x88 /* S3 ProSavage PM133 */ 147 | #define FB_ACCEL_PROSAVAGE_KM 0x89 /* S3 ProSavage KM133 */ 148 | #define FB_ACCEL_S3TWISTER_P 0x8a /* S3 Twister */ 149 | #define FB_ACCEL_S3TWISTER_K 0x8b /* S3 TwisterK */ 150 | #define FB_ACCEL_SUPERSAVAGE 0x8c /* S3 Supersavage */ 151 | #define FB_ACCEL_PROSAVAGE_DDR 0x8d /* S3 ProSavage DDR */ 152 | #define FB_ACCEL_PROSAVAGE_DDRK 0x8e /* S3 ProSavage DDR-K */ 153 | 154 | 155 | /** 156 | * 该结构体用于描述显卡自身的属性 157 | * 包括识别符,缓存地址,显卡类型等 158 | * 159 | */ 160 | struct fb_fix_screeninfo { 161 | char id[16]; /* identification string eg "TT Builtin" 标识符字符串*/ 162 | unsigned long smem_start; /* Start of frame buffer mem  frame buffer所占内存的开始地址 */ 163 | /* (physical address) 这里说的是物理地址 */ 164 | __u32 smem_len; /* Length of frame buffer mem frame buffer所占内存的长度 */ 165 | __u32 type; /* see FB_TYPE_* 查看FB_BYTE_* */ 166 | __u32 type_aux; /* Interleave for interleaved Planes 交织交错的平面 */ 167 | __u32 visual; /* see FB_VISUAL_* 查看FB_VISUAL_* */ 168 | __u16 xpanstep; /* zero if no hardware panning 如何没有硬件支持的话为0 */ 169 | __u16 ypanstep; /* zero if no hardware panning 如果没有硬件支持的话为0*/ 170 | __u16 ywrapstep; /* zero if no hardware ywrap 如果没有硬件ywrap的话为0 */ 171 | __u32 line_length; /* length of a line in bytes 一行的长度,以byte为单位 */ 172 | unsigned long mmio_start; /* Start of Memory Mapped I/O 映射到I/O的内存的开始地址 */ 173 | /* (physical address) 物理地址*/ 174 | __u32 mmio_len; /* Length of Memory Mapped I/O 映射到I/O的内存长度*/ 175 | __u32 accel; /* Indicate to driver which 指示到驱动程序 */ 176 | /* specific chip/card we have 特别是我们拥有的芯片/卡*/ 177 | __u16 reserved[3]; /* Reserved for future compatibility 为后来的兼容性保留*/ 178 | }; 179 | 180 | /* Interpretation of offset for color fields: All offsets are from the right, 181 | * inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you 182 | * can use the offset as right argument to <<). A pixel afterwards is a bit 183 | * stream and is written to video memory as that unmodified. 184 | * 185 | * 色域偏移的解释:所有的偏移量都来自于右边,在一个"像素"值里面,实际上是'bits_per_pixel' 186 | * 的宽度(也就是说:你可以使用该偏移量作为 << 的右参数).一个像素之后是一个位流,并且 187 | * 作为未被修改而被写到视频内存中. 188 | * 189 | * For pseudocolor: offset and length should be the same for all color 190 | * components. Offset specifies the position of the least significant bit 191 | * of the pallette index in a pixel value. Length indicates the number 192 | * of available palette entries (i.e. # of entries = 1 << length). 193 | * 194 | * 对于伪色彩来说:对于所有的颜色部分,偏移量和长度应该是相同的.偏移量指定了 195 | * 在一个像素值里的调色板索引的最低有效位的位置.长度指明了可用的调色板入口的 196 | * 数量. 197 | */  198 | struct fb_bitfield { 199 | __u32 offset; /* 位域的开始 */ 200 | __u32 length; /* length of bitfield 位域的长度 */ 201 | __u32 msb_right; /* != 0 : Most significant bit is 不等于0,大多数重要的位是右边的 */ 202 | /* right */ 203 | }; 204 | 205 | #define FB_NONSTD_HAM 1 /* Hold-And-Modify (HAM) 保持和修改 */ 206 | #define FB_NONSTD_REV_PIX_IN_B 2 /* order of pixels in each byte is reversed 在每一个字节中的像素的顺序被保留下来 */ 207 | 208 | #define FB_ACTIVATE_NOW 0 /* set values immediately (or vbl) 立即设定颜色 */ 209 | #define FB_ACTIVATE_NXTOPEN 1 /* activate on next open 在下一个打开的时候激活 */ 210 | #define FB_ACTIVATE_TEST 2 /* don't set, round up impossible 不设置 */ 211 | #define FB_ACTIVATE_MASK 15 212 | /* values */ 213 | #define FB_ACTIVATE_VBL 16 /* activate values on next vbl 在下一个vbl的时候激活值 */ 214 | #define FB_CHANGE_CMAP_VBL 32 /* change colormap on vbl 在vbl的时候改变色彩映射 */ 215 | #define FB_ACTIVATE_ALL 64 /* change all VCs on this fb 在这个fb中改变所有的VC */ 216 | #define FB_ACTIVATE_FORCE 128 /* force apply even when no change */ 217 | #define FB_ACTIVATE_INV_MODE 256 /* invalidate videomode 即使在没有改变无效视频模式的时候强制应用 */ 218 | 219 | #define FB_ACCELF_TEXT 1 /* (OBSOLETE) see fb_info.flags and vc_mode 已过时 */ 220 | 221 | #define FB_SYNC_HOR_HIGH_ACT 1 /* horizontal sync high active 高活性水平同步 */ 222 | #define FB_SYNC_VERT_HIGH_ACT 2 /* vertical sync high active 高活性垂直同步 */ 223 | #define FB_SYNC_EXT 4 /* external sync 外部同步 */ 224 | #define FB_SYNC_COMP_HIGH_ACT 8 /* composite sync high active 高活性复合同步  */ 225 | #define FB_SYNC_BROADCAST 16 /* broadcast video timings 广播视频时序 */ 226 | /* vtotal = 144d/288n/576i => PAL */ 227 | /* vtotal = 121d/242n/484i => NTSC */ 228 | #define FB_SYNC_ON_GREEN 32 /* sync on green 在绿色下同步 */ 229 | 230 | #define FB_VMODE_NONINTERLACED 0 /* non interlaced 非交错模式 */ 231 | #define FB_VMODE_INTERLACED 1 /* interlaced 交错模式 */ 232 | #define FB_VMODE_DOUBLE 2 /* double scan 双扫描模式 */ 233 | #define FB_VMODE_ODD_FLD_FIRST 4 /* interlaced: top line first 交错的:顶行优先 */ 234 | #define FB_VMODE_MASK 255 235 | 236 | #define FB_VMODE_YWRAP 256 /* ywrap instead of panning ywrap而不是panning */ 237 | #define FB_VMODE_SMOOTH_XPAN 512 /* smooth xpan possible (internally used) 平滑的xpan(内部使用) */ 238 | #define FB_VMODE_CONUPDATE 512 /* don't update x/yoffset 不要更新 x/yoffset*/ 239 | 240 | /* 241 | * Display rotation support 242 | * 243 | * 旋转支持显示 244 | */ 245 | #define FB_ROTATE_UR 0 246 | #define FB_ROTATE_CW 1 247 | #define FB_ROTATE_UD 2 248 | #define FB_ROTATE_CCW 3 249 | 250 | #define PICOS2KHZ(a) (1000000000UL/(a)) 251 | #define KHZ2PICOS(a) (1000000000UL/(a)) 252 | 253 | /** 254 | * 用于描述显卡的一般特性,比如实际分辨率,虚拟分辨率,实际分辨率和虚拟 255 | * 分辨率之间的位移等 256 |  */ 257 | struct fb_var_screeninfo { 258 | __u32 xres; /* visible resolution 可见解析度 */ 259 | __u32 yres; 260 | __u32 xres_virtual; /* virtual resolution 虚拟解析度 */ 261 | __u32 yres_virtual; 262 | __u32 xoffset; /* offset from virtual to visible 虚拟到可见的偏移量 */ 263 | __u32 yoffset; /* resolution */ 264 | 265 | __u32 bits_per_pixel; /* guess what BPP : 每个像素的位数 */ 266 | __u32 grayscale; /* != 0 Graylevels instead of colors !=0指灰度而不是颜色 */ 267 | 268 | //如果是真实的颜色的话表示在fb内存中的位域,如果不是颜色的话,仅仅就是长度 269 | //在这里保存的是fb缓存的R/G/B位域 270 | struct fb_bitfield red; /* bitfield in fb mem if true color, */ 271 | struct fb_bitfield green; /* else only length is significant */ 272 | struct fb_bitfield blue; 273 | struct fb_bitfield transp; /* transparency 透明度 */ 274 | 275 | __u32 nonstd; /* != 0 Non standard pixel format !=0 非标准像素格式 */ 276 | 277 | __u32 activate; /* see FB_ACTIVATE_* 查看FB_ACTIVATE_* */ 278 | 279 | __u32 height; /* height of picture in mm 在内存中图片的高度 */ 280 | __u32 width; /* width of picture in mm 在内存中图片的宽度 */ 281 | 282 | __u32 accel_flags; /* (OBSOLETE) see fb_info.flags 已过时*/ 283 | 284 | /* Timing: All values in pixclocks, except pixclock (of course) */ 285 | /* 除了pixclock本身外,其他的都已pixclock为单位*/ 286 | __u32 pixclock; /* pixel clock in ps (pico seconds) 像素时钟(皮秒)*/ 287 | __u32 left_margin; /* time from sync to picture 行切换:从绘图到同步之间的延迟 */ 288 | __u32 right_margin; /* time from picture to sync 行切换:从绘图到同步之间的延迟 */ 289 | __u32 upper_margin; /* time from sync to picture 帧切换:从同步到绘图之间的延迟 */ 290 | __u32 lower_margin;     // 帧切换,从绘图到同步之间的延迟  291 | __u32 hsync_len; /* length of horizontal sync 水平同步的长度 */ 292 | __u32 vsync_len; /* length of vertical sync 垂直同步的长度 */ 293 | __u32 sync; /* see FB_SYNC_* 查看FB_SYNC_* */ 294 | __u32 vmode; /* see FB_VMODE_* 查看 FB_VMODE_* */ 295 | __u32 rotate; /* angle we rotate counter clockwise 顺时针旋转的角度 */ 296 | __u32 reserved[5]; /* Reserved for future compatibility 保留 */ 297 | }; 298 | 299 | /** 300 | * 用于描述设备无关的颜色映射信息 301 | */ 302 | struct fb_cmap { 303 | __u32 start; /* First entry 第一个元素入口 */ 304 | __u32 len; /* Number of entries 元素的数量*/ 305 | //R,G,B,透明度 306 | __u16 *red; /* Red values */ 307 | __u16 *green; 308 | __u16 *blue; 309 | __u16 *transp; /* transparency, can be NULL 透明度,可以为空 */ 310 | }; 311 | 312 | struct fb_con2fbmap { 313 | __u32 console; 314 | __u32 framebuffer; 315 | }; 316 | 317 | /* VESA Blanking Levels */ 318 | #define VESA_NO_BLANKING 0 319 | #define VESA_VSYNC_SUSPEND 1 320 | #define VESA_HSYNC_SUSPEND 2 321 | #define VESA_POWERDOWN 3 322 | 323 | 324 | enum { 325 | /* screen: unblanked, hsync: on, vsync: on */ 326 | FB_BLANK_UNBLANK = VESA_NO_BLANKING, 327 | 328 | /* screen: blanked, hsync: on, vsync: on */ 329 | FB_BLANK_NORMAL = VESA_NO_BLANKING + 1, 330 | 331 | /* screen: blanked, hsync: on, vsync: off */ 332 | FB_BLANK_VSYNC_SUSPEND = VESA_VSYNC_SUSPEND + 1, 333 | 334 | /* screen: blanked, hsync: off, vsync: on */ 335 | FB_BLANK_HSYNC_SUSPEND = VESA_HSYNC_SUSPEND + 1, 336 | 337 | /* screen: blanked, hsync: off, vsync: off */ 338 | FB_BLANK_POWERDOWN = VESA_POWERDOWN + 1 339 | }; 340 | 341 | #define FB_VBLANK_VBLANKING 0x001 /* currently in a vertical blank */ 342 | #define FB_VBLANK_HBLANKING 0x002 /* currently in a horizontal blank */ 343 | #define FB_VBLANK_HAVE_VBLANK 0x004 /* vertical blanks can be detected */ 344 | #define FB_VBLANK_HAVE_HBLANK 0x008 /* horizontal blanks can be detected */ 345 | #define FB_VBLANK_HAVE_COUNT 0x010 /* global retrace counter is available */ 346 | #define FB_VBLANK_HAVE_VCOUNT 0x020 /* the vcount field is valid */ 347 | #define FB_VBLANK_HAVE_HCOUNT 0x040 /* the hcount field is valid */ 348 | #define FB_VBLANK_VSYNCING 0x080 /* currently in a vsync */ 349 | #define FB_VBLANK_HAVE_VSYNC 0x100 /* verical syncs can be detected */ 350 | 351 | struct fb_vblank { 352 | __u32 flags; /* FB_VBLANK flags FB_VBLANK标志 */ 353 | __u32 count; /* counter of retraces since boot 启动之后追溯的次数 */ 354 | __u32 vcount; /* current scanline position 当前扫描行位置 */ 355 | __u32 hcount; /* current scandot position 当前扫描点位置 */ 356 | __u32 reserved[4]; /* reserved for future compatibility 保留 */ 357 | }; 358 | 359 | /* Internal HW accel 内部硬件加速 */ 360 | #define ROP_COPY 0 361 | #define ROP_XOR 1 362 | 363 | //复制区域  364 | struct fb_copyarea { 365 | __u32 dx; 366 | __u32 dy; 367 | __u32 width; 368 | __u32 height; 369 | __u32 sx; 370 | __u32 sy; 371 | }; 372 | 373 | //回执矩形 374 | struct fb_fillrect { 375 | __u32 dx; /* screen-relative 屏幕相关 */ 376 | __u32 dy; 377 | __u32 width; 378 | __u32 height; 379 | __u32 color; 380 | __u32 rop; 381 | }; 382 | 383 | struct fb_image { 384 | __u32 dx; /* Where to place image 图像放在哪里 */ 385 | __u32 dy; 386 | __u32 width; /* Size of image 图像的宽度和高度 */ 387 | __u32 height; 388 | __u32 fg_color; /* Only used when a mono bitmap 仅仅是单色图像的时候使用 */ 389 | __u32 bg_color; 390 | __u8 depth; /* Depth of the image 图像的深度 */ 391 | const char *data; /* Pointer to image data 指向图像数据的指针 */ 392 | struct fb_cmap cmap; /* color map info 颜色映射信息 */ 393 | }; 394 | 395 | /* 396 | * hardware cursor control 397 | * 硬件光标控制  398 | */ 399 | 400 | #define FB_CUR_SETIMAGE 0x01 401 | #define FB_CUR_SETPOS 0x02 402 | #define FB_CUR_SETHOT 0x04 403 | #define FB_CUR_SETCMAP 0x08 404 | #define FB_CUR_SETSHAPE 0x10 405 | #define FB_CUR_SETSIZE 0x20 406 | #define FB_CUR_SETALL 0xFF 407 | 408 | // 光标位置  409 | struct fbcurpos { 410 | __u16 x, y; 411 | }; 412 | 413 | struct fb_cursor { 414 | __u16 set; /* what to set 设置成什么 */ 415 | __u16 enable; /* cursor on/off 光标打开/关闭 */ 416 | __u16 rop; /* bitop operation 位操作 */ 417 | const char *mask; /* cursor mask bits 光标掩码位 */ 418 | struct fbcurpos hot; /* cursor hot spot 光标热点 */ 419 | struct fb_image image; /* Cursor image 光标图像 */ 420 | }; 421 | 422 | #ifdef CONFIG_FB_BACKLIGHT 423 | /* Settings for the generic backlight code */ 424 | #define FB_BACKLIGHT_LEVELS 128 425 | #define FB_BACKLIGHT_MAX 0xFF 426 | #endif 427 | 428 | #ifdef __KERNEL__ 429 | 430 | #include 431 | #include 432 | #include 433 | #include 434 | #include 435 | #include 436 | #include 437 | #include 438 | 439 | struct vm_area_struct; 440 | struct fb_info; 441 | struct device; 442 | struct file; 443 | 444 | /* Definitions below are used in the parsed monitor specs */ 445 | #define FB_DPMS_ACTIVE_OFF 1 446 | #define FB_DPMS_SUSPEND 2 447 | #define FB_DPMS_STANDBY 4 448 | 449 | #define FB_DISP_DDI 1 450 | #define FB_DISP_ANA_700_300 2 451 | #define FB_DISP_ANA_714_286 4 452 | #define FB_DISP_ANA_1000_400 8 453 | #define FB_DISP_ANA_700_000 16 454 | 455 | #define FB_DISP_MONO 32 456 | #define FB_DISP_RGB 64 457 | #define FB_DISP_MULTI 128 458 | #define FB_DISP_UNKNOWN 256 459 | 460 | #define FB_SIGNAL_NONE 0 461 | #define FB_SIGNAL_BLANK_BLANK 1 462 | #define FB_SIGNAL_SEPARATE 2 463 | #define FB_SIGNAL_COMPOSITE 4 464 | #define FB_SIGNAL_SYNC_ON_GREEN 8 465 | #define FB_SIGNAL_SERRATION_ON 16 466 | 467 | #define FB_MISC_PRIM_COLOR 1 468 | #define FB_MISC_1ST_DETAIL 2 /* First Detailed Timing is preferred 第一次详细的时间是首选 */ 469 | 470 | struct fb_chroma { 471 | __u32 redx; /* in fraction of 1024 1024的一小部分 */ 472 | __u32 greenx; 473 | __u32 bluex; 474 | __u32 whitex; 475 | __u32 redy; 476 | __u32 greeny; 477 | __u32 bluey; 478 | __u32 whitey; 479 | }; 480 | 481 | struct fb_monspecs { 482 | struct fb_chroma chroma; 483 | struct fb_videomode *modedb; /* mode database 模式数据库 */ 484 | __u8 manufacturer[4]; /* Manufacturer 制造商 */ 485 | __u8 monitor[14]; /* Monitor String 监视字符串 */ 486 | __u8 serial_no[14]; /* Serial Number 序列号 */ 487 | __u8 ascii[14]; /* ? */ 488 | __u32 modedb_len; /* mode database length 模式数据库长度 */ 489 | __u32 model; /* Monitor Model 监视模型 */ 490 | __u32 serial; /* Serial Number - Integer 序列号-整数 */ 491 | __u32 year; /* Year manufactured 制造年*/ 492 | __u32 week; /* Week Manufactured 制造周 */ 493 | __u32 hfmin; /* hfreq lower limit (Hz) hfreq最低限制*/ 494 | __u32 hfmax; /* hfreq upper limit (Hz) hfreq最高限制*/ 495 | __u32 dclkmin; /* pixelclock lower limit (Hz) pixelclock最低限制*/ 496 | __u32 dclkmax; /* pixelclock upper limit (Hz) pixelclock最高限制*/ 497 | __u16 input; /* display type - see FB_DISP_* 显示类型 - 查看FB_DISP_* */ 498 | __u16 dpms; /* DPMS support - see FB_DPMS_ DPMS支持-查看FB_DPMS_ */ 499 | __u16 signal; /* Signal Type - see FB_SIGNAL_* 信号类型 - 查看FB_SIGNAL_* */ 500 | __u16 vfmin; /* vfreq lower limit (Hz) vfreq最低限制 */ 501 | __u16 vfmax; /* vfreq upper limit (Hz) vfreq最高限制 */ 502 | __u16 gamma; /* Gamma - in fractions of 100 100的分数 */ 503 | __u16 gtf : 1; /* supports GTF 支持 GTF */ 504 | __u16 misc; /* Misc flags - see FB_MISC_* Misc标识 - 查看FB_MISC_*  */ 505 | __u8 version; /* EDID version... EDID版本 */ 506 | __u8 revision; /* ...and revision 修订版本 */ 507 | __u8 max_x; /* Maximum horizontal size (cm) 最大水平大小 */ 508 | __u8 max_y; /* Maximum vertical size (cm) 最大垂直大小 */ 509 | }; 510 | 511 | struct fb_cmap_user { 512 | __u32 start; /* First entry 第一元素入口  */ 513 | __u32 len; /* Number of entries 元素的数量 */ 514 | //R,G,B和透明度  515 | __u16 __user *red; /* Red values */ 516 | __u16 __user *green; 517 | __u16 __user *blue; 518 | __u16 __user *transp; /* transparency, can be NULL */ 519 | }; 520 | 521 | struct fb_image_user { 522 | __u32 dx; /* Where to place image */ 523 | __u32 dy; 524 | __u32 width; /* Size of image */ 525 | __u32 height; 526 | __u32 fg_color; /* Only used when a mono bitmap */ 527 | __u32 bg_color; 528 | __u8 depth; /* Depth of the image */ 529 | const char __user *data; /* Pointer to image data */ 530 | struct fb_cmap_user cmap; /* color map info */ 531 | }; 532 | 533 | struct fb_cursor_user { 534 | __u16 set; /* what to set */ 535 | __u16 enable; /* cursor on/off */ 536 | __u16 rop; /* bitop operation */ 537 | const char __user *mask; /* cursor mask bits */ 538 | struct fbcurpos hot; /* cursor hot spot */ 539 | struct fb_image_user image; /* Cursor image */ 540 | }; 541 | 542 | /* 543 | * Register/unregister for framebuffer events 544 |  * framebuffer事件的注册/注销 545 | */ 546 | 547 | /* The resolution of the passed in fb_info about to change */ 548 | // 在fb_info中通过的分辨率将要改变 549 | #define FB_EVENT_MODE_CHANGE 0x01 550 | /* The display on this fb_info is beeing suspended, no access to the 551 | * framebuffer is allowed any more after that call returns 552 | * 在这个fb_info的显示是被悬挂着的,在那个调用返回之后的对framebuffer 553 | * 的访问是不被允许的. 554 | */ 555 | #define FB_EVENT_SUSPEND 0x02 556 | /* The display on this fb_info was resumed, you can restore the display 557 | * if you own it 558 |  * 在这个fb_info中的显示恢复了,如果你拥有他,你可以恢复显示 559 | * 560 | */ 561 | #define FB_EVENT_RESUME 0x03 562 | /* An entry from the modelist was removed */ 563 | // 模式列表中的一个元素被移走了 564 | #define FB_EVENT_MODE_DELETE 0x04 565 | /* A driver registered itself */ 566 | // 一个驱动注册了他自己 567 | #define FB_EVENT_FB_REGISTERED 0x05 568 | /* A driver unregistered itself */ 569 | // 一个驱动注销了他自己  570 | #define FB_EVENT_FB_UNREGISTERED 0x06 571 | /* CONSOLE-SPECIFIC: get console to framebuffer mapping */ 572 | // 获取framebuffer映射的控制台 573 | #define FB_EVENT_GET_CONSOLE_MAP 0x07 574 | /* CONSOLE-SPECIFIC: set console to framebuffer mapping */ 575 | // 设置framebuffer映射的控制台 576 | #define FB_EVENT_SET_CONSOLE_MAP 0x08 577 | /* A hardware display blank change occured */ 578 | // 一个硬件显示空改变发生了 579 | #define FB_EVENT_BLANK 0x09 580 | /* Private modelist is to be replaced */ 581 | // 内部的模式列表将被替换 582 | #define FB_EVENT_NEW_MODELIST 0x0A 583 | /* The resolution of the passed in fb_info about to change and 584 | all vc's should be changed */ 585 | // 在fb_info中通过的分辨率将要改变,并且所有的vc应该被改变 586 | #define FB_EVENT_MODE_CHANGE_ALL 0x0B 587 | /* A software display blank change occured */ 588 | // 一个软件显示空改变发生了 589 | #define FB_EVENT_CONBLANK 0x0C 590 | /* Get drawing requirements */ 591 | // 获取画图需求 592 | #define FB_EVENT_GET_REQ 0x0D 593 | /* Unbind from the console if possible */ 594 | // 如果可能的话从控制台中接触绑定 595 | #define FB_EVENT_FB_UNBIND 0x0E 596 | /* CONSOLE-SPECIFIC: remap all consoles to new fb - for vga switcheroo */ 597 | // 重新将所有的控制台映射到新的fb -- 对于vga switcheroo来说的 598 | #define FB_EVENT_REMAP_ALL_CONSOLE 0x0F 599 | 600 | struct fb_event { 601 | struct fb_info *info; 602 | void *data; 603 | }; 604 | 605 | struct fb_blit_caps { 606 | u32 x; 607 | u32 y; 608 | u32 len; 609 | u32 flags; 610 | }; 611 | 612 | extern int fb_register_client(struct notifier_block *nb); 613 | extern int fb_unregister_client(struct notifier_block *nb); 614 | extern int fb_notifier_call_chain(unsigned long val, void *v); 615 | /* 616 | * Pixmap structure definition 617 | * Pixmap 结构体定义  618 | * The purpose of this structure is to translate data 619 | * from the hardware independent format of fbdev to what 620 | * format the hardware needs. 621 | * 该结构体的目的就是将数据从fbdev的硬件独立的格式转换成 622 | * 硬件需要的格式 623 | * 624 | */ 625 | 626 | #define FB_PIXMAP_DEFAULT 1 /* used internally by fbcon 被fvbcon内部使用*/ 627 | #define FB_PIXMAP_SYSTEM 2 /* memory is in system RAM 内存在系统RAM中*/ 628 | #define FB_PIXMAP_IO 4 /* memory is iomapped 内存被io映射了*/ 629 | #define FB_PIXMAP_SYNC 256 /* set if GPU can DMA 如果GPU能够使用DMA的话设置*/ 630 | 631 | struct fb_pixmap { 632 | u8 *addr; /* pointer to memory 指向内存的指针 */ 633 | u32 size; /* size of buffer in bytes 缓冲的字节数大小 */ 634 | u32 offset; /* current offset to buffer  当前到buffer的偏移量   */ 635 | u32 buf_align; /* byte alignment of each bitmap  每一个位图的字节对齐 */ 636 | u32 scan_align; /* alignment per scanline 每一个扫描行的对齐 */ 637 | u32 access_align; /* alignment per read/write (bits) 每一个读写位的对齐 */ 638 | u32 flags; /* see FB_PIXMAP_* 查看FB_PIXMAP_* */ 639 | u32 blit_x; /* supported bit block dimensions (1-32) 支持位块尺寸(1-32) */ 640 | u32 blit_y; /* Format: blit_x = 1 << (width - 1) */ 641 | /* blit_y = 1 << (height - 1) */ 642 | /* if 0, will be set to 0xffffffff (all) 如果是0,则被设置为0xffffffff */ 643 | /* access methods 访问方法 */ 644 | void (*writeio)(struct fb_info *info, void __iomem *dst, void *src, unsigned int size); 645 | void (*readio) (struct fb_info *info, void *dst, void __iomem *src, unsigned int size); 646 | }; 647 | 648 | #ifdef CONFIG_FB_DEFERRED_IO 649 | struct fb_deferred_io { 650 | /* delay between mkwrite and deferred handler  在mkwrite和延期的处理程序的时间 */ 651 | unsigned long delay; 652 | struct mutex lock; /* mutex that protects the page list 保护页列表的互斥锁 */ 653 | struct list_head pagelist; /* list of touched pages 被创建的页的列表*/ 654 | /* callback 回调函数*/ 655 | void (*deferred_io)(struct fb_info *info, struct list_head *pagelist); 656 | }; 657 | #endif 658 | 659 | /* 660 | * Frame buffer operations 661 | * Frame buffer 的操作 662 | * LOCKING NOTE: those functions must _ALL_ be called with the console 663 | * semaphore held, this is the only suitable locking mechanism we have 664 | * in 2.6. Some may be called at interrupt time at this point though. 665 |  * 这些函数必须要使用semaphore锁. 666 | */ 667 | 668 | struct fb_ops { 669 | /* open/release and usage marking */ 670 | // 打开/释放和使用标记 671 | struct module *owner; 672 | int (*fb_open)(struct fb_info *info, int user); 673 | int (*fb_release)(struct fb_info *info, int user); 674 | 675 | /* For framebuffers with strange non linear layouts or that do not 676 | * work with normal memory mapped access 677 | * 对于拥有陌生的非线性布局的framebuffer来说,不能使用普通的内存 678 | * 映射访问来工作 679 | */ 680 | ssize_t (*fb_read)(struct fb_info *info, char __user *buf, 681 | size_t count, loff_t *ppos); 682 | ssize_t (*fb_write)(struct fb_info *info, const char __user *buf, 683 | size_t count, loff_t *ppos); 684 | 685 | /* checks var and eventually tweaks it to something supported, 686 | * DO NOT MODIFY PAR */ 687 | // 检查var并且事件性的调整到可支持状态.不要修改PAR 688 | int (*fb_check_var)(struct fb_var_screeninfo *var, struct fb_info *info); 689 | 690 | /* set the video mode according to info->var */ 691 | // 通过info->var设置视频模式 692 | int (*fb_set_par)(struct fb_info *info); 693 | 694 | /* set color register */ 695 | // 设置颜色寄存器 696 | int (*fb_setcolreg)(unsigned regno, unsigned red, unsigned green, 697 | unsigned blue, unsigned transp, struct fb_info *info); 698 | 699 | /* set color registers in batch */ 700 | // 批处理设置颜色寄存器 701 | int (*fb_setcmap)(struct fb_cmap *cmap, struct fb_info *info); 702 | 703 | /* blank display */ 704 | // 空显示 705 | int (*fb_blank)(int blank, struct fb_info *info); 706 | 707 | /* pan display */ 708 | // pan 显示 709 | int (*fb_pan_display)(struct fb_var_screeninfo *var, struct fb_info *info); 710 | 711 | /* Draws a rectangle */ 712 | // 绘制一个矩形 713 | void (*fb_fillrect) (struct fb_info *info, const struct fb_fillrect *rect); 714 | /* Copy data from area to another */ 715 | // 从一个区域复制数据到另外一个区域 716 | void (*fb_copyarea) (struct fb_info *info, const struct fb_copyarea *region); 717 | /* Draws a image to the display */ 718 | // 在显示器上绘制一个图像 719 | void (*fb_imageblit) (struct fb_info *info, const struct fb_image *image); 720 | 721 | /* Draws cursor */ 722 | // 绘制光标 723 | int (*fb_cursor) (struct fb_info *info, struct fb_cursor *cursor); 724 | 725 | /* Rotates the display */ 726 | // 旋转显示 727 | void (*fb_rotate)(struct fb_info *info, int angle); 728 | 729 | /* wait for blit idle, optional */ 730 | // 等待blit空闲,可选 731 | int (*fb_sync)(struct fb_info *info); 732 | 733 | /* perform fb specific ioctl (optional) */ 734 | // 运行fb指定的ioctl(可选) 735 | int (*fb_ioctl)(struct fb_info *info, unsigned int cmd, 736 | unsigned long arg); 737 | 738 | /* Handle 32bit compat ioctl (optional) */ 739 | // 处理32位兼容的ioctl 740 | int (*fb_compat_ioctl)(struct fb_info *info, unsigned cmd, 741 | unsigned long arg); 742 | 743 | /* perform fb specific mmap */ 744 | // 运行fb指定的mmap 745 | int (*fb_mmap)(struct fb_info *info, struct vm_area_struct *vma); 746 | 747 | /* get capability given var */ 748 | // 获取给定的var的能力 749 | void (*fb_get_caps)(struct fb_info *info, struct fb_blit_caps *caps, 750 | struct fb_var_screeninfo *var); 751 | 752 | /* teardown any resources to do with this framebuffer */ 753 | // 卸载与该framebuffer相关的任何资源 754 | void (*fb_destroy)(struct fb_info *info); 755 | }; 756 | 757 | #ifdef CONFIG_FB_TILEBLITTING 758 | #define FB_TILE_CURSOR_NONE 0 759 | #define FB_TILE_CURSOR_UNDERLINE 1 760 | #define FB_TILE_CURSOR_LOWER_THIRD 2 761 | #define FB_TILE_CURSOR_LOWER_HALF 3 762 | #define FB_TILE_CURSOR_TWO_THIRDS 4 763 | #define FB_TILE_CURSOR_BLOCK 5 764 | 765 | struct fb_tilemap { 766 | __u32 width; /* width of each tile in pixels 像素的宽度 */ 767 | __u32 height; /* height of each tile in scanlines 扫描行的高度 */ 768 | __u32 depth; /* color depth of each tile 颜色深度 */ 769 | __u32 length; /* number of tiles in the map 在映射中的数量 */ 770 | const __u8 *data; /* actual tile map: a bitmap array, packed 771 | to the nearest byte 实际映射:一个位图数组,被打包到最近的位 */ 772 | }; 773 | 774 | struct fb_tilerect { 775 | __u32 sx; /* origin in the x-axis 在x轴中原点*/ 776 | __u32 sy; /* origin in the y-axis 在y轴中的原点*/ 777 | __u32 width; /* number of tiles in the x-axis 在x-axis 中的数量 */ 778 | __u32 height; /* number of tiles in the y-axis 在y-axis中的数量 */ 779 | __u32 index; /* what tile to use: index to tile map 使用哪一个tile:到tile映射的索引 */ 780 | __u32 fg; /* foreground color 前景色 */ 781 | __u32 bg; /* background color 后景色 */ 782 | __u32 rop; /* raster operation 光栅操作 */ 783 | }; 784 | 785 | struct fb_tilearea { 786 | __u32 sx; /* source origin in the x-axis 在X轴的源原点 */ 787 | __u32 sy; /* source origin in the y-axis 在y轴的源原点 */ 788 | __u32 dx; /* destination origin in the x-axis 在x轴的目的原点 */ 789 | __u32 dy; /* destination origin in the y-axis 在y轴的目的原点 */ 790 | __u32 width; /* number of tiles in the x-axis 在x轴中的tiles的数量 */ 791 | __u32 height; /* number of tiles in the y-axis 在y轴中的tiles的数量 */ 792 | }; 793 | 794 | struct fb_tileblit { 795 | __u32 sx; /* origin in the x-axis 在x轴的原点 */ 796 | __u32 sy; /* origin in the y-axis 在y轴的原点*/ 797 | __u32 width; /* number of tiles in the x-axis 在x轴上的tiles的数量 */ 798 | __u32 height; /* number of tiles in the y-axis 在y轴上的tiles的数量 */ 799 | __u32 fg; /* foreground color 前景色*/ 800 | __u32 bg; /* background color 后景色*/ 801 | __u32 length; /* number of tiles to draw 要绘制的tiles的数量 */ 802 | __u32 *indices; /* array of indices to tile map 到tile映射的指数数组 */ 803 | }; 804 | 805 | struct fb_tilecursor { 806 | __u32 sx; /* cursor position in the x-axis 在x轴的光标位置*/ 807 | __u32 sy; /* cursor position in the y-axis 在y轴的光标位置 */ 808 | __u32 mode; /* 0 = erase, 1 = draw 0 = 擦除,1=绘制*/ 809 | __u32 shape; /* see FB_TILE_CURSOR_* 查看FB_TILE_CURSOR_* */ 810 | __u32 fg; /* foreground color 前景色*/ 811 | __u32 bg; /* background color 后景色*/ 812 | }; 813 | 814 | struct fb_tile_ops { 815 | /* set tile characteristics  设置tile的特征*/ 816 | void (*fb_settile)(struct fb_info *info, struct fb_tilemap *map); 817 | 818 | /* all dimensions from hereon are in terms of tiles */ 819 | // 从现在起,所有尺寸都在tiles方面 820 | /* move a rectangular region of tiles from one area to another*/ 821 | // 移动一个矩形区域从一个地方到另外一个地方 822 | void (*fb_tilecopy)(struct fb_info *info, struct fb_tilearea *area); 823 | /* fill a rectangular region with a tile */ 824 | // 使用一个tile填充一个矩形区域 825 | void (*fb_tilefill)(struct fb_info *info, struct fb_tilerect *rect); 826 | /* copy an array of tiles */ 827 | // 复制一个tile数组 828 | void (*fb_tileblit)(struct fb_info *info, struct fb_tileblit *blit); 829 | /* cursor */ 830 | // 光标 831 | void (*fb_tilecursor)(struct fb_info *info, 832 | struct fb_tilecursor *cursor); 833 | /* get maximum length of the tile map */ 834 | // 获取tile映射的最大长度 835 | int (*fb_get_tilemax)(struct fb_info *info); 836 | }; 837 | #endif /* CONFIG_FB_TILEBLITTING */ 838 | 839 | /* FBINFO_* = fb_info.flags bit flags FBINFO_* = fb_info.flags 位标识 */ 840 | #define FBINFO_MODULE 0x0001 /* Low-level driver is a module 底层驱动是一个模块 */ 841 | #define FBINFO_HWACCEL_DISABLED 0x0002 842 | /* When FBINFO_HWACCEL_DISABLED is set: 843 | * Hardware acceleration is turned off. Software implementations 844 | * of required functions (copyarea(), fillrect(), and imageblit()) 845 | * takes over; acceleration engine should be in a quiescent state */ 846 | /* 当FBINFO_HWACCEL_DISABLED被设置的时候: 847 | * 硬件加速被关掉.所需功能的软件实现(copyarea(),fillrect()和imageblit()) 848 | * 接管.加速引擎应该位域静态状态 849 | * 850 | /* hints 提示*/ 851 | #define FBINFO_VIRTFB 0x0004 /* FB is System RAM, not device. FB是系统RAM,不是设备*/ 852 | #define FBINFO_PARTIAL_PAN_OK 0x0040 /* otw use pan only for double-buffering otw使用pan仅仅用于双缓冲 */ 853 | #define FBINFO_READS_FAST 0x0080 /* soft-copy faster than rendering 软拷贝快于渲染 */ 854 | 855 | /* hardware supported ops */ 856 | /* semantics: when a bit is set, it indicates that the operation is 857 | * accelerated by hardware. 858 |  * 支持的硬件操作 859 |  * 语义:当一个位被设置,意味着操作被硬件加速了 860 | * 861 | * required functions will still work even if the bit is not set. 862 |  * 即使位没有被设置,所需的功能依旧工作. 863 | * optional functions may not even exist if the flag bit is not set. 864 | * 如果标识位没有被设置,可选的功能可能甚至不存在 865 | */ 866 | #define FBINFO_HWACCEL_NONE 0x0000 867 | #define FBINFO_HWACCEL_COPYAREA 0x0100 /* required 需要*/ 868 | #define FBINFO_HWACCEL_FILLRECT 0x0200 /* required 需要*/ 869 | #define FBINFO_HWACCEL_IMAGEBLIT 0x0400 /* required 需要*/ 870 | #define FBINFO_HWACCEL_ROTATE 0x0800 /* optional 可选*/ 871 | #define FBINFO_HWACCEL_XPAN 0x1000 /* optional 可选*/ 872 | #define FBINFO_HWACCEL_YPAN 0x2000 /* optional */ 873 | #define FBINFO_HWACCEL_YWRAP 0x4000 /* optional */ 874 | 875 | #define FBINFO_MISC_USEREVENT 0x10000 /* event request  876 | from userspace 从用户空间时间需要*/ 877 | #define FBINFO_MISC_TILEBLITTING 0x20000 /* use tile blitting 使用tile blitting*/ 878 | #define FBINFO_MISC_FIRMWARE 0x40000 /* a replaceable firmware 879 | inited framebuffer 一个可替换的固件初始化的framebuffer*/ 880 | 881 | /* A driver may set this flag to indicate that it does want a set_par to be 882 | * called every time when fbcon_switch is executed. The advantage is that with 883 | * this flag set you can really be sure that set_par is always called before 884 | * any of the functions dependant on the correct hardware state or altering 885 | * that state, even if you are using some broken X releases. The disadvantage 886 | * is that it introduces unwanted delays to every console switch if set_par 887 | * is slow. It is a good idea to try this flag in the drivers initialization 888 | * code whenever there is a bug report related to switching between X and the 889 | * framebuffer console. 890 | * 一个驱动可能会设置这个标识来表明每次当fbcon_switch被执行的时候,他不想调用set_par(). 891 | * 他的优点就是伴随着这个标识的设置,你可以确定set_par在任何依赖于正确的硬件状态 892 | * 或者是改变那个状态之前被一直调用,即使你整在使用一些x发行版.他的缺点就是如果 893 | * set_par太慢的话,在显示在每一个控制台的时候,会导致不希望的延迟. 894 | * 895 | * 896 | */ 897 | #define FBINFO_MISC_ALWAYS_SETPAR 0x40000 898 | 899 | /* 900 | * Host and GPU endianness differ. 901 |  * 主机和GPU端不同 902 | */ 903 | #define FBINFO_FOREIGN_ENDIAN 0x100000 904 | /* 905 | * Big endian math. This is the same flags as above, but with different 906 | * meaning, it is set by the fb subsystem depending FOREIGN_ENDIAN flag 907 | * and host endianness. Drivers should not use this flag. 908 | * 大端数学.这个是和上面一样的标识,但是意义却是不一样的,他是被依赖于FOREIGN_ENDIAN端 909 | * 和主机端的fb子系统所设置的.驱动不应该使用这个标识 910 | * 911 | */ 912 | #define FBINFO_BE_MATH 0x100000 913 | 914 | struct fb_info { 915 | int node; 916 | int flags; 917 | struct mutex lock; /* Lock for open/release/ioctl funcs 用于open/release/ioctl函数的锁 */ 918 | struct mutex mm_lock; /* Lock for fb_mmap and smem_* fields 用于fb_mmap和smem_* 域的锁 */ 919 | struct fb_var_screeninfo var; /* Current var 可变参数*/ 920 | struct fb_fix_screeninfo fix; /* Current fix 固定参数 */ 921 | struct fb_monspecs monspecs; /* Current Monitor specs  显示器标准 */ 922 | struct work_struct queue; /* Framebuffer event queue 帧缓冲事件队列 */ 923 | struct fb_pixmap pixmap; /* Image hardware mapper 图像硬件mapper */ 924 | struct fb_pixmap sprite; /* Cursor hardware mapper 光标硬件mapper */ 925 | struct fb_cmap cmap; /* Current cmap 目前的颜色表 */ 926 | struct list_head modelist; /* mode list 模式列表 */ 927 | struct fb_videomode *mode; /* current mode 当前的video模式 */ 928 | 929 | #ifdef CONFIG_FB_BACKLIGHT 930 | /* assigned backlight device 对应的背光设备*/ 931 | /* set before framebuffer registration, 932 | remove after unregister 在framebuffer注册之前被设置,在注销之后移走 */ 933 | struct backlight_device *bl_dev; 934 | 935 | /* Backlight level curve 背光调整 */ 936 | struct mutex bl_curve_mutex; 937 | u8 bl_curve[FB_BACKLIGHT_LEVELS]; 938 | #endif 939 | #ifdef CONFIG_FB_DEFERRED_IO 940 | struct delayed_work deferred_work; 941 | struct fb_deferred_io *fbdefio; 942 | #endif 943 | 944 | struct fb_ops *fbops; // 帧缓冲操作 945 | struct device *device; /* This is the parent 辐射被*/ 946 | struct device *dev; /* This is this fb device fb设备 */ 947 | int class_flag; /* private sysfs flags 私有sysfs标识 */ 948 | #ifdef CONFIG_FB_TILEBLITTING 949 | struct fb_tile_ops *tileops; /* Tile Blitting 图块blitting */ 950 | #endif 951 | char __iomem *screen_base; /* Virtual address 虚拟基地址 */ 952 | unsigned long screen_size; /* Amount of ioremapped VRAM or 0 ioremapped的虚拟内存大小 或者是 0*/ 953 | void *pseudo_palette; /* Fake palette of 16 colors 伪16色颜色表  */ 954 | #define FBINFO_STATE_RUNNING 0 955 | #define FBINFO_STATE_SUSPENDED 1 956 | u32 state; /* Hardware state i.e suspend 硬件状态,如挂起 */ 957 | void *fbcon_par; /* fbcon use-only private area fbcon仅仅用于私有区域*/ 958 | /* From here on everything is device dependent 从这里开始所有的事物都是设备依赖的 */ 959 | void *par; 960 | /* we need the PCI or similiar aperture base/size not 961 | smem_start/size as smem_start may just be an object 962 | allocated inside the aperture so may not actually overlap */ 963 | resource_size_t aperture_base; 964 | resource_size_t aperture_size; 965 | }; 966 | 967 | #ifdef MODULE 968 | #define FBINFO_DEFAULT FBINFO_MODULE 969 | #else 970 | #define FBINFO_DEFAULT 0 971 | #endif 972 | 973 | // This will go away 这将会走开 974 | #define FBINFO_FLAG_MODULE FBINFO_MODULE 975 | #define FBINFO_FLAG_DEFAULT FBINFO_DEFAULT 976 | 977 | /* This will go away 978 | * fbset currently hacks in FB_ACCELF_TEXT into var.accel_flags 979 | * when it wants to turn the acceleration engine on. This is 980 | * really a separate operation, and should be modified via sysfs. 981 | * But for now, we leave it broken with the following define 982 | * 这将会走开.当他想要打开加速引擎的时候,fbset会到var.accel_falgs. 983 | * 这个事实上是一个分离的操作,并且应该有sysfs修改.但是,对于现在来说, 984 | *  我们把他打破与下面的定义. 985 | */ 986 | #define STUPID_ACCELF_TEXT_SHIT 987 | 988 | // This will go away 989 | // 这个将走开 990 | #if defined(__sparc__) 991 | 992 | /* We map all of our framebuffers such that big-endian accesses 993 | * are what we want, so the following is sufficient. 994 |  * 995 | * 我们映射所有的framebuffers,例如大端访问是我们需要的,所以下面的就足够了 996 | */ 997 | 998 | // This will go away 999 | #define fb_readb sbus_readb 1000 | #define fb_readw sbus_readw 1001 | #define fb_readl sbus_readl 1002 | #define fb_readq sbus_readq 1003 | #define fb_writeb sbus_writeb 1004 | #define fb_writew sbus_writew 1005 | #define fb_writel sbus_writel 1006 | #define fb_writeq sbus_writeq 1007 | #define fb_memset sbus_memset_io 1008 | 1009 | #elif defined(__i386__) || defined(__alpha__) || defined(__x86_64__) || defined(__hppa__) || defined(__sh__) || defined(__powerpc__) || defined(__avr32__) || defined(__bfin__) 1010 | 1011 | #define fb_readb __raw_readb 1012 | #define fb_readw __raw_readw 1013 | #define fb_readl __raw_readl 1014 | #define fb_readq __raw_readq 1015 | #define fb_writeb __raw_writeb 1016 | #define fb_writew __raw_writew 1017 | #define fb_writel __raw_writel 1018 | #define fb_writeq __raw_writeq 1019 | #define fb_memset memset_io 1020 | 1021 | #else 1022 | 1023 | #define fb_readb(addr) (*(volatile u8 *) (addr)) 1024 | #define fb_readw(addr) (*(volatile u16 *) (addr)) 1025 | #define fb_readl(addr) (*(volatile u32 *) (addr)) 1026 | #define fb_readq(addr) (*(volatile u64 *) (addr)) 1027 | #define fb_writeb(b,addr) (*(volatile u8 *) (addr) = (b)) 1028 | #define fb_writew(b,addr) (*(volatile u16 *) (addr) = (b)) 1029 | #define fb_writel(b,addr) (*(volatile u32 *) (addr) = (b)) 1030 | #define fb_writeq(b,addr) (*(volatile u64 *) (addr) = (b)) 1031 | #define fb_memset memset 1032 | 1033 | #endif 1034 | 1035 | #define FB_LEFT_POS(p, bpp) (fb_be_math(p) ? (32 - (bpp)) : 0) 1036 | #define FB_SHIFT_HIGH(p, val, bits) (fb_be_math(p) ? (val) >> (bits) : \ 1037 | (val) << (bits)) 1038 | #define FB_SHIFT_LOW(p, val, bits) (fb_be_math(p) ? (val) << (bits) : \ 1039 | (val) >> (bits)) 1040 | 1041 | /* 1042 | * `Generic' versions of the frame buffer device operations 1043 | * framebuffer的'Generis'版本的设备操作 1044 | * 1045 | */ 1046 | 1047 | extern int fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var); 1048 | extern int fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var); 1049 | extern int fb_blank(struct fb_info *info, int blank); 1050 | extern void cfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect); 1051 | extern void cfb_copyarea(struct fb_info *info, const struct fb_copyarea *area); 1052 | extern void cfb_imageblit(struct fb_info *info, const struct fb_image *image); 1053 | /* 1054 | * Drawing operations where framebuffer is in system RAM 1055 | * 在framebuffer所在的系统RAM绘制操作 1056 | * 1057 | */ 1058 | extern void sys_fillrect(struct fb_info *info, const struct fb_fillrect *rect); 1059 | extern void sys_copyarea(struct fb_info *info, const struct fb_copyarea *area); 1060 | extern void sys_imageblit(struct fb_info *info, const struct fb_image *image); 1061 | extern ssize_t fb_sys_read(struct fb_info *info, char __user *buf, 1062 | size_t count, loff_t *ppos); 1063 | extern ssize_t fb_sys_write(struct fb_info *info, const char __user *buf, 1064 | size_t count, loff_t *ppos); 1065 | 1066 | /* drivers/video/fbmem.c */ 1067 | extern int register_framebuffer(struct fb_info *fb_info); 1068 | extern int unregister_framebuffer(struct fb_info *fb_info); 1069 | extern int fb_prepare_logo(struct fb_info *fb_info, int rotate); 1070 | extern int fb_show_logo(struct fb_info *fb_info, int rotate); 1071 | extern char* fb_get_buffer_offset(struct fb_info *info, struct fb_pixmap *buf, u32 size); 1072 | extern void fb_pad_unaligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 idx, 1073 | u32 height, u32 shift_high, u32 shift_low, u32 mod); 1074 | extern void fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, u32 height); 1075 | extern void fb_set_suspend(struct fb_info *info, int state); 1076 | extern int fb_get_color_depth(struct fb_var_screeninfo *var, 1077 | struct fb_fix_screeninfo *fix); 1078 | extern int fb_get_options(char *name, char **option); 1079 | extern int fb_new_modelist(struct fb_info *info); 1080 | 1081 | extern struct fb_info *registered_fb[FB_MAX]; 1082 | extern int num_registered_fb; 1083 | extern struct class *fb_class; 1084 | 1085 | extern int lock_fb_info(struct fb_info *info); 1086 | 1087 | static inline void unlock_fb_info(struct fb_info *info) 1088 | { 1089 | mutex_unlock(&info->lock); 1090 | } 1091 | 1092 | static inline void __fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, 1093 | u8 *src, u32 s_pitch, u32 height) 1094 | { 1095 | int i, j; 1096 | 1097 | d_pitch -= s_pitch; 1098 | 1099 | for (i = height; i--; ) { 1100 | /* s_pitch is a few bytes at the most, memcpy is suboptimal */ 1101 | for (j = 0; j < s_pitch; j++) 1102 | *dst++ = *src++; 1103 | dst += d_pitch; 1104 | } 1105 | } 1106 | 1107 | /* drivers/video/fb_defio.c */ 1108 | extern void fb_deferred_io_init(struct fb_info *info); 1109 | extern void fb_deferred_io_open(struct fb_info *info, 1110 | struct inode *inode, 1111 | struct file *file); 1112 | extern void fb_deferred_io_cleanup(struct fb_info *info); 1113 | extern int fb_deferred_io_fsync(struct file *file, struct dentry *dentry, 1114 | int datasync); 1115 | 1116 | static inline bool fb_be_math(struct fb_info *info) 1117 | { 1118 | #ifdef CONFIG_FB_FOREIGN_ENDIAN 1119 | #if defined(CONFIG_FB_BOTH_ENDIAN) 1120 | return info->flags & FBINFO_BE_MATH; 1121 | #elif defined(CONFIG_FB_BIG_ENDIAN) 1122 | return true; 1123 | #elif defined(CONFIG_FB_LITTLE_ENDIAN) 1124 | return false; 1125 | #endif /* CONFIG_FB_BOTH_ENDIAN */ 1126 | #else 1127 | #ifdef __BIG_ENDIAN 1128 | return true; 1129 | #else 1130 | return false; 1131 | #endif /* __BIG_ENDIAN */ 1132 | #endif /* CONFIG_FB_FOREIGN_ENDIAN */ 1133 | } 1134 | 1135 | /* drivers/video/fbsysfs.c */ 1136 | extern struct fb_info *framebuffer_alloc(size_t size, struct device *dev); 1137 | extern void framebuffer_release(struct fb_info *info); 1138 | extern int fb_init_device(struct fb_info *fb_info); 1139 | extern void fb_cleanup_device(struct fb_info *head); 1140 | extern void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max); 1141 | 1142 | /* drivers/video/fbmon.c */ 1143 | #define FB_MAXTIMINGS 0 1144 | #define FB_VSYNCTIMINGS 1 1145 | #define FB_HSYNCTIMINGS 2 1146 | #define FB_DCLKTIMINGS 3 1147 | #define FB_IGNOREMON 0x100 1148 | 1149 | #define FB_MODE_IS_UNKNOWN 0 1150 | #define FB_MODE_IS_DETAILED 1 1151 | #define FB_MODE_IS_STANDARD 2 1152 | #define FB_MODE_IS_VESA 4 1153 | #define FB_MODE_IS_CALCULATED 8 1154 | #define FB_MODE_IS_FIRST 16 1155 | #define FB_MODE_IS_FROM_VAR 32 1156 | 1157 | extern int fbmon_dpms(const struct fb_info *fb_info); 1158 | extern int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var, 1159 | struct fb_info *info); 1160 | extern int fb_validate_mode(const struct fb_var_screeninfo *var, 1161 | struct fb_info *info); 1162 | extern int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var); 1163 | extern const unsigned char *fb_firmware_edid(struct device *device); 1164 | extern void fb_edid_to_monspecs(unsigned char *edid, 1165 | struct fb_monspecs *specs); 1166 | extern void fb_destroy_modedb(struct fb_videomode *modedb); 1167 | extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb); 1168 | extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter); 1169 | 1170 | /* drivers/video/modedb.c */ 1171 | #define VESA_MODEDB_SIZE 34 1172 | extern void fb_var_to_videomode(struct fb_videomode *mode, 1173 | const struct fb_var_screeninfo *var); 1174 | extern void fb_videomode_to_var(struct fb_var_screeninfo *var, 1175 | const struct fb_videomode *mode); 1176 | extern int fb_mode_is_equal(const struct fb_videomode *mode1, 1177 | const struct fb_videomode *mode2); 1178 | extern int fb_add_videomode(const struct fb_videomode *mode, 1179 | struct list_head *head); 1180 | extern void fb_delete_videomode(const struct fb_videomode *mode, 1181 | struct list_head *head); 1182 | extern const struct fb_videomode *fb_match_mode(const struct fb_var_screeninfo *var, 1183 | struct list_head *head); 1184 | extern const struct fb_videomode *fb_find_best_mode(const struct fb_var_screeninfo *var, 1185 | struct list_head *head); 1186 | extern const struct fb_videomode *fb_find_nearest_mode(const struct fb_videomode *mode, 1187 | struct list_head *head); 1188 | extern void fb_destroy_modelist(struct list_head *head); 1189 | extern void fb_videomode_to_modelist(const struct fb_videomode *modedb, int num, 1190 | struct list_head *head); 1191 | extern const struct fb_videomode *fb_find_best_display(const struct fb_monspecs *specs, 1192 | struct list_head *head); 1193 | 1194 | /* drivers/video/fbcmap.c */ 1195 | extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp); 1196 | extern void fb_dealloc_cmap(struct fb_cmap *cmap); 1197 | extern int fb_copy_cmap(const struct fb_cmap *from, struct fb_cmap *to); 1198 | extern int fb_cmap_to_user(const struct fb_cmap *from, struct fb_cmap_user *to); 1199 | extern int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *fb_info); 1200 | extern int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *fb_info); 1201 | extern const struct fb_cmap *fb_default_cmap(int len); 1202 | extern void fb_invert_cmaps(void); 1203 | 1204 | struct fb_videomode { 1205 | const char *name; /* optional */ 1206 | u32 refresh; /* optional */ 1207 | u32 xres; 1208 | u32 yres; 1209 | u32 pixclock; 1210 | u32 left_margin; 1211 | u32 right_margin; 1212 | u32 upper_margin; 1213 | u32 lower_margin; 1214 | u32 hsync_len; 1215 | u32 vsync_len; 1216 | u32 sync; 1217 | u32 vmode; 1218 | u32 flag; 1219 | }; 1220 | 1221 | extern const char *fb_mode_option; 1222 | extern const struct fb_videomode vesa_modes[]; 1223 | 1224 | struct fb_modelist { 1225 | struct list_head list; 1226 | struct fb_videomode mode; 1227 | }; 1228 | 1229 | extern int fb_find_mode(struct fb_var_screeninfo *var, 1230 | struct fb_info *info, const char *mode_option, 1231 | const struct fb_videomode *db, 1232 | unsigned int dbsize, 1233 | const struct fb_videomode *default_mode, 1234 | unsigned int default_bpp); 1235 | 1236 | #endif /* __KERNEL__ */ 1237 | 1238 | #endif /* _LINUX_FB_H */ 1239 | -------------------------------------------------------------------------------- /fb2/README.md: -------------------------------------------------------------------------------- 1 | **(一):写在前面** 2 | 3 | 在这里我们主要实现了打印frame buffer的一些信息,其中包括分辨率,所占内存地址的开始地址,偏移量,BPP以及所占内存的宽度和高度等信息.主要是通过对这些参数的打印操作来实现对frame buffer的进一步深入的了解. 4 | 5 | **(二):如何编译以及运行** 6 | 7 | 首先,我们看到,在我们的目录中有三个文件,fbtool.h,fbtool.c以及test.c,其中main函数位于test.c文件中.下面是我们的编译命令. 8 | 9 | ``` 10 | gcc fbtool.h fbtool.c test.c -o test 11 | ``` 12 | 13 | 编译完成之后,就会生成test的可执行文件. 14 | 15 | 一般情况下,我们只要使用 16 | ``` 17 | ./test 18 | ``` 19 | 便能够运行该程序文件,但是由于在运行过程中,需要打开/dev/fb0文件,所以需要使用特权用户运行该程序,我们使用下面的命令来运行我们的程序文件. 20 | 21 | ``` 22 | sudo ./test 23 | ``` 24 | 这样程序就能够顺利执行了. 25 | 26 | **(三):执行结果展示** 27 | 28 | 下面我们来看一下我们的执行结果: 29 | 30 | ``` 31 | frame buffer所占内存的开始地址为:-1341710336 32 | frame buffer 的类型为:0 33 | frame buffer的可见清晰度为: 34 | x = 1366 35 | y = 768 36 | frame buffer的虚拟清晰度为: 37 | x = 1366 38 | y = 768 39 | frame buffer的虚拟分辨率到可见分辨率的偏移量为: 40 | x = 0 41 | y = 0 42 | frame buffer的BPP为:32 43 | 这个后面再说!! 44 | frame buffer在内存中所占的高度和宽度分别是: 45 | 宽度 = -1 46 | 高度 = -1 47 | ``` 48 | 49 | 这样就能明显的看出frame buffer的一些属性了. 50 | 51 | **(四):该程序的构成** 52 | 53 | 在这里我们说一下我们如果构建的该程序. 54 | 55 | 1:首先我们需要定义一个结构体,该结构体包括四个变量: 56 | ``` 57 | int fb; //framebuffer打开后的唯一标识符 58 | struct fb_fix_screeninfo fb_fix; 59 | struct fb_var_screeninfo fb_var; 60 | char dev[20]; //设备名称 61 | ``` 62 | 63 | 2:定义完成结构体之后,我们就需要定义操作frame buffer的各个方法,包括打开,关闭fb0设备,打印相关信息的函数等 64 | ``` 65 | //打开framebuffer 66 | int fb_open(PFBDEV pFbdev); 67 | //关闭framebuffer 68 | int fb_close(PFBDEV pFbdev); 69 | //打印frame buffer 所占内存的开始地址  70 | void pmem_start(PFBDEV pFbdev); 71 | //打印FB_TYPE 72 | void p_type(PFBDEV pFbdev); 73 | //打印可见清晰度 74 | void p_visible_res(PFBDEV pFbdev); 75 | //打印虚拟分辨率 76 | void p_virt_res(PFBDEV pFbdev); 77 | //打印虚拟到可见的偏移量 78 | void p_offset(PFBDEV pFbdev); 79 | //打印每个像素的位数 80 | void p_bpp(PFBDEV pFbdev); 81 | //打印R,G,B和透明度 82 | void p_rgbt(PFBDEV pFbdev); 83 | //打印在内存中的高度和宽度 84 | void p_hw(PFBDEV pFbdev); 85 | ``` 86 | 87 | 3:接着就是这些函数的实现 88 | 89 | 这些函数的实现都是比较简单的,基本上是打印结构体中的一些信息. 90 | 91 | 4:编写测试程序,运行测试 92 | 93 | 最后就是编写我们的main函数,进行编译测试. 94 | 95 | **(五):后期展望** 96 | 97 | 在后面一个测试中,着重讲解fb_var里面的R,G,B和透明度的值. 98 | 99 | **(六):写在后面** 100 | 101 | 宝剑锋从磨砺出,梅花香自苦寒来. 102 | 103 | 104 | -------------------------------------------------------------------------------- /fb2/fbtool.c: -------------------------------------------------------------------------------- 1 | #include "fbtool.h" 2 | 3 | //打开并且初始化该frame buffer 4 | int fb_open(PFBDEV pFbdev) 5 | { 6 | //打开frame buffer 7 | pFbdev->fb = open(pFbdev->dev,O_RDWR); 8 | 9 | if(pFbdev->fb < 0) 10 | { 11 | printf("打开错误 %s : %n.请检查内核配置\n",pFbdev->dev); 12 | return 0; 13 | } 14 | 15 | // 初始化fb_var 16 | if(-1 == ioctl(pFbdev->fb,FBIOGET_VSCREENINFO,&(pFbdev->fb_var))) 17 | { 18 | printf("ioctl FBIOGET_VSCREENINFO\n"); 19 | return 0; 20 | } 21 | 22 | // 初始化fb_fix 23 | if(-1 == ioctl(pFbdev->fb,FBIOGET_FSCREENINFO,&(pFbdev->fb_fix))) 24 | { 25 | printf("ioctl FBIOGET_FSCREENINFO\n"); 26 | return 0; 27 | } 28 | 29 | return 1; 30 | } 31 | 32 | //关闭frame buffer 33 | int fb_close(PFBDEV pFbdev) 34 | { 35 | close(pFbdev->fb); 36 | pFbdev->fb = -1; 37 | } 38 | 39 | //打印frame buffer 所占内存的开始地址  40 | void pmem_start(PFBDEV pFbdev) 41 | { 42 | printf("frame buffer所占内存的开始地址为:%d\n",pFbdev->fb_fix.smem_start); 43 | } 44 | 45 | //打印FB_TYPE 46 | void p_type(PFBDEV pFbdev) 47 | { 48 | printf("frame buffer 的类型为:%d\n",pFbdev->fb_fix.type); 49 | } 50 | 51 | //打印可见清晰度 52 | void p_visible_res(PFBDEV pFbdev) 53 | { 54 | printf("frame buffer的可见清晰度为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres,pFbdev->fb_var.yres); 55 | } 56 | 57 | //打印虚拟分辨率 58 | void p_virt_res(PFBDEV pFbdev) 59 | { 60 | printf("frame buffer的虚拟清晰度为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres_virtual,pFbdev->fb_var.yres_virtual); 61 | } 62 | 63 | //打印虚拟到可见的偏移量 64 | void p_offset(PFBDEV pFbdev) 65 | { 66 | printf("frame buffer的虚拟分辨率到可见分辨率的偏移量为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xoffset,pFbdev->fb_var.yoffset); 67 | } 68 | 69 | //打印每个像素的位数 70 | void p_bpp(PFBDEV pFbdev) 71 | { 72 | printf("frame buffer的BPP为:%d\n",pFbdev->fb_var.bits_per_pixel); 73 | } 74 | 75 | //打印R,G,B和透明度 76 | void p_rgbt(PFBDEV pFbdev) 77 | { 78 | printf("这个后面再说!!\n"); 79 | } 80 | 81 | //打印在内存中的高度和宽度 82 | void p_hw(PFBDEV pFbdev) 83 | { 84 | printf("frame buffer在内存中所占的高度和宽度分别是:\n\t宽度 = %d\n\t高度 = %d\n",pFbdev->fb_var.height,pFbdev->fb_var.width); 85 | } 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /fb2/fbtool.h: -------------------------------------------------------------------------------- 1 | #ifndef __FBTOOL_H_ 2 | #define __FBTOOL_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | typedef struct fbdev{ 14 | int fb; //framebuffer打开后的唯一标识符 15 | struct fb_fix_screeninfo fb_fix; 16 | struct fb_var_screeninfo fb_var; 17 | char dev[20]; 18 | }FBDEV,*PFBDEV; 19 | 20 | //打开framebuffer 21 | int fb_open(PFBDEV pFbdev); 22 | //关闭framebuffer 23 | int fb_close(PFBDEV pFbdev); 24 | //打印frame buffer 所占内存的开始地址  25 | void pmem_start(PFBDEV pFbdev); 26 | //打印FB_TYPE 27 | void p_type(PFBDEV pFbdev); 28 | //打印可见清晰度 29 | void p_visible_res(PFBDEV pFbdev); 30 | //打印虚拟分辨率 31 | void p_virt_res(PFBDEV pFbdev); 32 | //打印虚拟到可见的偏移量 33 | void p_offset(PFBDEV pFbdev); 34 | //打印每个像素的位数 35 | void p_bpp(PFBDEV pFbdev); 36 | //打印R,G,B和透明度 37 | void p_rgbt(PFBDEV pFbdev); 38 | //打印在内存中的高度和宽度 39 | void p_hw(PFBDEV pFbdev); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /fb2/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongbochen/fb/57e26b8fca539db14184df71466e6a5a070db9a8/fb2/test -------------------------------------------------------------------------------- /fb2/test.c: -------------------------------------------------------------------------------- 1 | #include "fbtool.h" 2 | 3 | int main() 4 | { 5 | FBDEV fbdev; 6 | memset(&fbdev,0,sizeof(FBDEV)); 7 | strcpy(fbdev.dev,"/dev/fb0"); 8 | 9 | if(0 == fb_open(&fbdev)){ 10 | printf("Open fail!!\n"); 11 | return -1; 12 | } 13 | 14 | //打印frame buffer 所占内存的开始地址  15 | pmem_start(&fbdev); 16 | //打印FB_TYPE 17 | p_type(&fbdev); 18 | //打印可见清晰度 19 | p_visible_res(&fbdev); 20 | //打印虚拟分辨率 21 | p_virt_res(&fbdev); 22 | //打印虚拟到可见的偏移量 23 | p_offset(&fbdev); 24 | //打印每个像素的位数 25 | p_bpp(&fbdev); 26 | //打印R,G,B和透明度 27 | p_rgbt(&fbdev); 28 | //打印在内存中的高度和宽度 29 | p_hw(&fbdev); 30 | 31 | fb_close(&fbdev); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /fb3/README.md: -------------------------------------------------------------------------------- 1 | **(一):写在前面** 2 | 3 | 在这个小节中,主要介绍了frame buffer中的R,G,B以及透明度的位域属性.由于在上一个小节当中,我自私的以为这几个位域能够获得相应的R,G,B以及透明度的数值,然后再将其转化为图像,但是,经过我后来的学习,发现我错了.正确的将frame buffer读取并转换为图像的方法是首先读取(read)frame buffer,然后,再将读取的char数组转换为相应的图片.所以,后面,着重学习如何读取frame buffer,以及如何将其转化为图片. 4 | 5 | **(二):R,G,B以及透明度位域** 6 | 7 | 在fb.h头文件中的结构 fb_var_screeninfo中定义了R,G,B以及透明度的位域,他们都是一个结构体fb_bitfield的一个实例.下面我们来看一下bitfield的定义: 8 | 9 | ``` 10 | struct fb_bitfield { 11 | __u32 offset; /* 位域的开始 */ 12 | __u32 length; /* length of bitfield 位域的长度 */ 13 | __u32 msb_right; /* != 0 : Most significant bit is right 不等于0,大多数重要的位是右边的 */ 14 | }; 15 | ``` 16 | 17 | 那么如果要打印该值的话,我们就需要使用该结构体. 18 | 19 | **(三):完善上一节中的p_rgbt(PFBDEV pFbdev)函数** 20 | 21 | 在我们的上一节中,我们留下了这个函数而没有去实现,这个来源于我的无知.所以,现在我们来完善一下这个函数.在上面我们知道这个关系之后,这个函数的实现就显得相对简单了. 22 | 23 | ``` 24 | //打印R,G,B和透明度 25 | void p_rgbt(PFBDEV pFbdev) 26 | { 27 | //R位域 28 | printf("R位域:\n"); 29 | struct fb_bitfield bf = pFbdev->fb_var.red; 30 | printf("\t开始:%d\n",bf.offset); 31 | printf("\t长度:%d\n",bf.length); 32 | printf("\tMSB:%d\n",bf.msb_right); 33 | 34 | //G位域 35 | printf("G位域:\n"); 36 | bf = pFbdev->fb_var.green; 37 | printf("\t开始:%d\n",bf.offset); 38 | printf("\t长度:%d\n",bf.length); 39 | printf("\tMSB:%d\n",bf.msb_right); 40 | 41 | // B位域 42 | printf("B位域:\n"); 43 | bf = pFbdev->fb_var.blue; 44 | printf("\t开始:%d\n",bf.offset); 45 | printf("\t长度:%d\n",bf.length); 46 | printf("\tMSB:%d\n",bf.msb_right); 47 | 48 | // 透明度位域 49 | printf("透明度位域:\n"); 50 | bf = pFbdev->fb_var.transp; 51 | printf("\t开始:%d\n",bf.offset); 52 | printf("\t长度:%d\n",bf.length); 53 | printf("\tMSB:%d\n",bf.msb_right); 54 | } 55 | ``` 56 | 57 | **(四):编译运行方法** 58 | 59 | 编译和运行方法和上一节的编译运行方法是一样的. 60 | 61 | **(五):运行结果展示** 62 | 63 | 下面我们来看一下我们的运行结果: 64 | 65 | ``` 66 | frame buffer所占内存的开始地址为:-1341710336 67 | frame buffer 的类型为:0 68 | frame buffer的可见清晰度为: 69 | x = 1366 70 | y = 768 71 | frame buffer的虚拟清晰度为: 72 | x = 1366 73 | y = 768 74 | frame buffer的虚拟分辨率到可见分辨率的偏移量为: 75 | x = 0 76 | y = 0 77 | frame buffer的BPP为:32 78 | R位域: 79 | 开始:16 80 | 长度:8 81 | MSB:0 82 | G位域: 83 | 开始:8 84 | 长度:8 85 | MSB:0 86 | B位域: 87 | 开始:0 88 | 长度:8 89 | MSB:0 90 | 透明度位域: 91 | 开始:0 92 | 长度:0 93 | MSB:0 94 | frame buffer在内存中所占的高度和宽度分别是: 95 | 宽度 = -1 96 | 高度 = -1 97 | R位域: 98 | 开始:16 99 | 长度:8 100 | MSB:0 101 | G位域: 102 | 开始:8 103 | 长度:8 104 | MSB:0 105 | B位域: 106 | 开始:0 107 | 长度:8 108 | MSB:0 109 | 透明度位域: 110 | 开始:0 111 | 长度:0 112 | MSB:0 113 | 114 | ``` 115 | 116 | **(六):写在后面** 117 | 118 | 今天很残酷,明天很残酷,后天很没有,但是绝大多数人死在了明天晚上.----马云 -------------------------------------------------------------------------------- /fb3/fbtool.c: -------------------------------------------------------------------------------- 1 | #include "fbtool.h" 2 | 3 | //打开并且初始化该frame buffer 4 | int fb_open(PFBDEV pFbdev) 5 | { 6 | //打开frame buffer 7 | pFbdev->fb = open(pFbdev->dev,O_RDWR); 8 | 9 | if(pFbdev->fb < 0) 10 | { 11 | printf("打开错误 %s : %n.请检查内核配置\n",pFbdev->dev); 12 | return 0; 13 | } 14 | 15 | // 初始化fb_var 16 | if(-1 == ioctl(pFbdev->fb,FBIOGET_VSCREENINFO,&(pFbdev->fb_var))) 17 | { 18 | printf("ioctl FBIOGET_VSCREENINFO\n"); 19 | return 0; 20 | } 21 | 22 | // 初始化fb_fix 23 | if(-1 == ioctl(pFbdev->fb,FBIOGET_FSCREENINFO,&(pFbdev->fb_fix))) 24 | { 25 | printf("ioctl FBIOGET_FSCREENINFO\n"); 26 | return 0; 27 | } 28 | 29 | return 1; 30 | } 31 | 32 | //关闭frame buffer 33 | int fb_close(PFBDEV pFbdev) 34 | { 35 | close(pFbdev->fb); 36 | pFbdev->fb = -1; 37 | } 38 | 39 | //打印frame buffer 所占内存的开始地址  40 | void pmem_start(PFBDEV pFbdev) 41 | { 42 | printf("frame buffer所占内存的开始地址为:%d\n",pFbdev->fb_fix.smem_start); 43 | } 44 | 45 | //打印FB_TYPE 46 | void p_type(PFBDEV pFbdev) 47 | { 48 | printf("frame buffer 的类型为:%d\n",pFbdev->fb_fix.type); 49 | } 50 | 51 | //打印可见清晰度 52 | void p_visible_res(PFBDEV pFbdev) 53 | { 54 | printf("frame buffer的可见清晰度为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres,pFbdev->fb_var.yres); 55 | } 56 | 57 | //打印虚拟分辨率 58 | void p_virt_res(PFBDEV pFbdev) 59 | { 60 | printf("frame buffer的虚拟清晰度为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres_virtual,pFbdev->fb_var.yres_virtual); 61 | } 62 | 63 | //打印虚拟到可见的偏移量 64 | void p_offset(PFBDEV pFbdev) 65 | { 66 | printf("frame buffer的虚拟分辨率到可见分辨率的偏移量为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xoffset,pFbdev->fb_var.yoffset); 67 | } 68 | 69 | //打印每个像素的位数 70 | void p_bpp(PFBDEV pFbdev) 71 | { 72 | printf("frame buffer的BPP为:%d\n",pFbdev->fb_var.bits_per_pixel); 73 | } 74 | 75 | //打印R,G,B和透明度 76 | void p_rgbt(PFBDEV pFbdev) 77 | { 78 | //R位域 79 | printf("R位域:\n"); 80 | struct fb_bitfield bf = pFbdev->fb_var.red; 81 | printf("\t开始:%d\n",bf.offset); 82 | printf("\t长度:%d\n",bf.length); 83 | printf("\tMSB:%d\n",bf.msb_right); 84 | 85 | //G位域 86 | printf("G位域:\n"); 87 | bf = pFbdev->fb_var.green; 88 | printf("\t开始:%d\n",bf.offset); 89 | printf("\t长度:%d\n",bf.length); 90 | printf("\tMSB:%d\n",bf.msb_right); 91 | 92 | // B位域 93 | printf("B位域:\n"); 94 | bf = pFbdev->fb_var.blue; 95 | printf("\t开始:%d\n",bf.offset); 96 | printf("\t长度:%d\n",bf.length); 97 | printf("\tMSB:%d\n",bf.msb_right); 98 | 99 | // 透明度位域 100 | printf("透明度位域:\n"); 101 | bf = pFbdev->fb_var.transp; 102 | printf("\t开始:%d\n",bf.offset); 103 | printf("\t长度:%d\n",bf.length); 104 | printf("\tMSB:%d\n",bf.msb_right); 105 | } 106 | 107 | //打印在内存中的高度和宽度 108 | void p_hw(PFBDEV pFbdev) 109 | { 110 | printf("frame buffer在内存中所占的高度和宽度分别是:\n\t宽度 = %d\n\t高度 = %d\n",pFbdev->fb_var.height,pFbdev->fb_var.width); 111 | } 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /fb3/fbtool.h: -------------------------------------------------------------------------------- 1 | #ifndef __FBTOOL_H_ 2 | #define __FBTOOL_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | typedef struct fbdev{ 14 | int fb; //framebuffer打开后的唯一标识符 15 | struct fb_fix_screeninfo fb_fix; 16 | struct fb_var_screeninfo fb_var; 17 | char dev[20]; 18 | }FBDEV,*PFBDEV; 19 | 20 | //打开framebuffer 21 | int fb_open(PFBDEV pFbdev); 22 | //关闭framebuffer 23 | int fb_close(PFBDEV pFbdev); 24 | //打印frame buffer 所占内存的开始地址  25 | void pmem_start(PFBDEV pFbdev); 26 | //打印FB_TYPE 27 | void p_type(PFBDEV pFbdev); 28 | //打印可见清晰度 29 | void p_visible_res(PFBDEV pFbdev); 30 | //打印虚拟分辨率 31 | void p_virt_res(PFBDEV pFbdev); 32 | //打印虚拟到可见的偏移量 33 | void p_offset(PFBDEV pFbdev); 34 | //打印每个像素的位数 35 | void p_bpp(PFBDEV pFbdev); 36 | //打印R,G,B和透明度 37 | void p_rgbt(PFBDEV pFbdev); 38 | //打印在内存中的高度和宽度 39 | void p_hw(PFBDEV pFbdev); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /fb3/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongbochen/fb/57e26b8fca539db14184df71466e6a5a070db9a8/fb3/test -------------------------------------------------------------------------------- /fb3/test.c: -------------------------------------------------------------------------------- 1 | #include "fbtool.h" 2 | 3 | int main() 4 | { 5 | FBDEV fbdev; 6 | 7 | memset(&fbdev,0,sizeof(FBDEV)); 8 | strcpy(fbdev.dev,"/dev/fb0"); 9 | 10 | if(0 == fb_open(&fbdev)){ 11 | printf("Open fail!!\n"); 12 | return -1; 13 | } 14 | 15 | //打印frame buffer 所占内存的开始地址  16 | pmem_start(&fbdev); 17 | //打印FB_TYPE 18 | p_type(&fbdev); 19 | //打印可见清晰度 20 | p_visible_res(&fbdev); 21 | //打印虚拟分辨率 22 | p_virt_res(&fbdev); 23 | //打印虚拟到可见的偏移量 24 | p_offset(&fbdev); 25 | //打印每个像素的位数 26 | p_bpp(&fbdev); 27 | //打印R,G,B和透明度 28 | p_rgbt(&fbdev); 29 | //打印在内存中的高度和宽度 30 | p_hw(&fbdev); 31 | //打印fb的RGB和透明度的位域 32 | p_rgbt(&fbdev); 33 | 34 | fb_close(&fbdev); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /fb4-fix/README.md: -------------------------------------------------------------------------------- 1 | **(一):写在前面** 2 | 3 | 在这里需要修正一下我犯得一个错误,就是在结构体fb_fix_screeninfo中的smem_start的类型是unsigned long.而我在输出的时候使用的参数是"%d",是我的疏忽造成了如此大的错误.在这里我纠正一下,输出的时候应该为"%lu".还有一个地方就是在打印frame buffer在内存中的高度和宽度的时候,应该使用"%u". 4 | 5 | **(二):修改的位置** 6 | 7 | 1:该错误修改的位置在fbtool.c的41行: 8 | 9 | ``` 10 | 11 | //打印frame buffer 所占内存的开始地址  12 | void pmem_start(PFBDEV pFbdev) 13 | { 14 | printf("frame buffer所占内存的开始地址为:%lu\n",pFbdev->fb_fix.smem_start); 15 | } 16 | 17 | ``` 18 | 19 | 2:该错误在fbtool.c的82行: 20 | 21 | ``` 22 | //打印在内存中的高度和宽度 23 | void p_hw(PFBDEV pFbdev) 24 | { 25 | printf("frame buffer在内存中所占的高度和宽度分别是:\n\t宽度 = %u\n\t高度 = %u\n",pFbdev->fb_var.height,pFbdev->fb_var.width); 26 | } 27 | ``` 28 | 29 | 3:还有其他的输出的参数都是有点问题的.改动在代码中,如果还有问题的话,希望大家能够指正. 30 | 31 | **(三):执行结果展示** 32 | 33 | 下面我们来看一下我们的执行结果: 34 | 35 | ``` 36 | frame buffer所占内存的开始地址为:2953256960 37 | frame buffer 的类型为:0 38 | frame buffer的可见清晰度为: 39 | x = 1366 40 | y = 768 41 | frame buffer的虚拟清晰度为: 42 | x = 1366 43 | y = 768 44 | frame buffer的虚拟分辨率到可见分辨率的偏移量为: 45 | x = 0 46 | y = 0 47 | frame buffer的BPP为:32 48 | 这个后面再说!! 49 | frame buffer在内存中所占的高度和宽度分别是: 50 | 宽度 = 4294967295 51 | 高度 = 4294967295 52 | 53 | ``` 54 | 55 | **(五):特别感谢** 56 | 57 | 在这里我要特别感谢我的校友:WANG-lp 58 | 他的github地址为: 59 | 60 | [WANG-lp](https://github.com/WANG-lp) 61 | 62 | **(六):写在后面** 63 | 64 | 过而能改,善莫大焉. 65 | 66 | 在这里给大家道个歉: 67 | 68 | ![sorry](http://face.zhaoxi.org/upload/201359/20070110120842.gif) 69 | 70 | 71 | -------------------------------------------------------------------------------- /fb4-fix/fbtool.c: -------------------------------------------------------------------------------- 1 | #include "fbtool.h" 2 | 3 | //打开并且初始化该frame buffer 4 | int fb_open(PFBDEV pFbdev) 5 | { 6 | //打开frame buffer 7 | pFbdev->fb = open(pFbdev->dev,O_RDWR); 8 | 9 | if(pFbdev->fb < 0) 10 | { 11 | printf("打开错误 %s : %n.请检查内核配置\n",pFbdev->dev); 12 | return 0; 13 | } 14 | 15 | // 初始化fb_var 16 | if(-1 == ioctl(pFbdev->fb,FBIOGET_VSCREENINFO,&(pFbdev->fb_var))) 17 | { 18 | printf("ioctl FBIOGET_VSCREENINFO\n"); 19 | return 0; 20 | } 21 | 22 | // 初始化fb_fix 23 | if(-1 == ioctl(pFbdev->fb,FBIOGET_FSCREENINFO,&(pFbdev->fb_fix))) 24 | { 25 | printf("ioctl FBIOGET_FSCREENINFO\n"); 26 | return 0; 27 | } 28 | 29 | return 1; 30 | } 31 | 32 | //关闭frame buffer 33 | int fb_close(PFBDEV pFbdev) 34 | { 35 | close(pFbdev->fb); 36 | pFbdev->fb = -1; 37 | } 38 | 39 | //打印frame buffer 所占内存的开始地址  40 | void pmem_start(PFBDEV pFbdev) 41 | { 42 | printf("frame buffer所占内存的开始地址为:%lu\n",pFbdev->fb_fix.smem_start); 43 | } 44 | 45 | //打印FB_TYPE 46 | void p_type(PFBDEV pFbdev) 47 | { 48 | printf("frame buffer 的类型为:%u\n",pFbdev->fb_fix.type); 49 | } 50 | 51 | //打印可见清晰度 52 | void p_visible_res(PFBDEV pFbdev) 53 | { 54 | printf("frame buffer的可见清晰度为:\n\tx = %u\n\ty = %u\n",pFbdev->fb_var.xres,pFbdev->fb_var.yres); 55 | } 56 | 57 | //打印虚拟分辨率 58 | void p_virt_res(PFBDEV pFbdev) 59 | { 60 | printf("frame buffer的虚拟清晰度为:\n\tx = %u\n\ty = %u\n",pFbdev->fb_var.xres_virtual,pFbdev->fb_var.yres_virtual); 61 | } 62 | 63 | //打印虚拟到可见的偏移量 64 | void p_offset(PFBDEV pFbdev) 65 | { 66 | printf("frame buffer的虚拟分辨率到可见分辨率的偏移量为:\n\tx = %u\n\ty = %u\n",pFbdev->fb_var.xoffset,pFbdev->fb_var.yoffset); 67 | } 68 | 69 | //打印每个像素的位数 70 | void p_bpp(PFBDEV pFbdev) 71 | { 72 | printf("frame buffer的BPP为:%d\n",pFbdev->fb_var.bits_per_pixel); 73 | } 74 | 75 | //打印R,G,B和透明度 76 | void p_rgbt(PFBDEV pFbdev) 77 | { 78 | printf("这个后面再说!!\n"); 79 | } 80 | 81 | //打印在内存中的高度和宽度 82 | void p_hw(PFBDEV pFbdev) 83 | { 84 | printf("frame buffer在内存中所占的高度和宽度分别是:\n\t宽度 = %u\n\t高度 = %u\n",pFbdev->fb_var.height,pFbdev->fb_var.width); 85 | } 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /fb4-fix/fbtool.h: -------------------------------------------------------------------------------- 1 | #ifndef __FBTOOL_H_ 2 | #define __FBTOOL_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | typedef struct fbdev{ 14 | int fb; //framebuffer打开后的唯一标识符 15 | struct fb_fix_screeninfo fb_fix; 16 | struct fb_var_screeninfo fb_var; 17 | char dev[20]; 18 | }FBDEV,*PFBDEV; 19 | 20 | //打开framebuffer 21 | int fb_open(PFBDEV pFbdev); 22 | //关闭framebuffer 23 | int fb_close(PFBDEV pFbdev); 24 | //打印frame buffer 所占内存的开始地址  25 | void pmem_start(PFBDEV pFbdev); 26 | //打印FB_TYPE 27 | void p_type(PFBDEV pFbdev); 28 | //打印可见清晰度 29 | void p_visible_res(PFBDEV pFbdev); 30 | //打印虚拟分辨率 31 | void p_virt_res(PFBDEV pFbdev); 32 | //打印虚拟到可见的偏移量 33 | void p_offset(PFBDEV pFbdev); 34 | //打印每个像素的位数 35 | void p_bpp(PFBDEV pFbdev); 36 | //打印R,G,B和透明度 37 | void p_rgbt(PFBDEV pFbdev); 38 | //打印在内存中的高度和宽度 39 | void p_hw(PFBDEV pFbdev); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /fb4-fix/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongbochen/fb/57e26b8fca539db14184df71466e6a5a070db9a8/fb4-fix/test -------------------------------------------------------------------------------- /fb4-fix/test.c: -------------------------------------------------------------------------------- 1 | #include "fbtool.h" 2 | 3 | int main() 4 | { 5 | FBDEV fbdev; 6 | memset(&fbdev,0,sizeof(FBDEV)); 7 | strcpy(fbdev.dev,"/dev/fb0"); 8 | 9 | if(0 == fb_open(&fbdev)){ 10 | printf("Open fail!!\n"); 11 | return -1; 12 | } 13 | 14 | //打印frame buffer 所占内存的开始地址  15 | pmem_start(&fbdev); 16 | //打印FB_TYPE 17 | p_type(&fbdev); 18 | //打印可见清晰度 19 | p_visible_res(&fbdev); 20 | //打印虚拟分辨率 21 | p_virt_res(&fbdev); 22 | //打印虚拟到可见的偏移量 23 | p_offset(&fbdev); 24 | //打印每个像素的位数 25 | p_bpp(&fbdev); 26 | //打印R,G,B和透明度 27 | p_rgbt(&fbdev); 28 | //打印在内存中的高度和宽度 29 | p_hw(&fbdev); 30 | 31 | fb_close(&fbdev); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /fb5/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | gcc page.h fbtool.h fbtool.c test.c -o test 3 | clean: 4 | rm test 5 | -------------------------------------------------------------------------------- /fb5/README.md: -------------------------------------------------------------------------------- 1 | **(一):写在前面** 2 | 3 | 在这一小节当中,我主要是实现了对frame buffer的操作编程,实现了将内存中的地址映射到逻辑地址空间,然后对其内存进行操作,包括在屏幕上画点,画线,画四边形,填充四边形等.然后,再将数据映射到内存中进行显示.这里的操作比较简单,只要实现一个画点的操作,就能以画点为基础,实现各种操作. 4 | 5 | **(二):画点的实现** 6 | 7 | 首先,我们在上一个小节中已经将内存中的地址映射到相应的逻辑地址内存空间.就是使用mmap()函数.有关与mmap()函数的参数,在网上一搜即可. 8 | 9 | 当获取到相应的地址之后,我们就是根据相应地址的偏移量来对内存设置RGB和透明度的值. 10 | 11 | ``` 12 | uint32_t offset; 13 | uint8_t color[4]; 14 | color[0] = b; 15 | color[1] = g; 16 | color[2] = r; 17 | color[3] = 0x0; //透明度 18 | 19 | //偏移量 20 | offset = p.y * pFbdev->fb_fix.line_length + 4 * p.x; 21 | 22 | ``` 23 | 24 | 颜色设置完成之后,我们需要将相应的值写入到内存当中,在这里,我们重新实现了一个函数,那就是memcpy()函数. 25 | 26 | ``` 27 | //映射到内存 28 | void fb_memcpy(void *addr,void *color,size_t len) 29 | { 30 | memcpy(addr,color,len); 31 | } 32 | 33 | ``` 34 | 35 | 最后,我们使用该函数,将相应的内容映射到内存中. 36 | 37 | ``` 38 | //将操作映射到内存中 39 | fb_memcpy((void*)pFbdev->fb_mem + pFbdev->fb_mem_offset + offset,color,4); 40 | 41 | ``` 42 | 43 | **(四):编译运行方法** 44 | 45 | 在此次源码文件中,我添加了一个Makefile文件,所以,如果要编译文件的话,只需使用make命令,就能将相应的test可执行文件编译出来.编译完成之后,我们使用ctrl+alt+f1进入到命令行界面,然后,进入到该目录运行.就可看出相应的运行结果. 46 | 47 | **(五):运行结果展示** 48 | 49 | 下面是我使用手机拍摄的一张我的运行结果的照片.还是很漂亮的. 50 | 51 | **(六):后期规划** 52 | 53 | 后面我打算能不能在命令行界面上实现一个图形化界面的库.这个难度其实是很大的,不过我觉着还是很有意思的.慢慢来吧,一个函数一个函数的写,一个函数一个函数的测试,脚踏实地. 54 | 55 | **(七):写在后面** 56 | 57 | 昨天已经过去,明天还未来临,我们能做到只有活在当下. 58 | -------------------------------------------------------------------------------- /fb5/fbtool.c: -------------------------------------------------------------------------------- 1 | #include "fbtool.h" 2 | 3 | //打开并且初始化该frame buffer 4 | int fb_open(PFBDEV pFbdev) 5 | { 6 | //打开frame buffer 7 | pFbdev->fb = open(pFbdev->dev,O_RDWR); 8 | 9 | if(pFbdev->fb < 0) 10 | { 11 | printf("打开错误 %s : %n.请检查内核配置\n",pFbdev->dev); 12 | return 0; 13 | } 14 | 15 | // 初始化fb_var 16 | if(-1 == ioctl(pFbdev->fb,FBIOGET_VSCREENINFO,&(pFbdev->fb_var))) 17 | { 18 | printf("ioctl FBIOGET_VSCREENINFO\n"); 19 | return 0; 20 | } 21 | 22 | // 初始化fb_fix 23 | if(-1 == ioctl(pFbdev->fb,FBIOGET_FSCREENINFO,&(pFbdev->fb_fix))) 24 | { 25 | printf("ioctl FBIOGET_FSCREENINFO\n"); 26 | return 0; 27 | } 28 | 29 | //将物理地址映射到虚拟地址 30 | pFbdev->fb_mem_offset = (unsigned long)pFbdev->fb_fix.smem_start & (~PAGE_MASK); 31 | 32 | pFbdev->fb_mem = (unsigned long int)mmap(NULL,pFbdev->fb_fix.smem_len + pFbdev->fb_mem_offset,PROT_READ|PROT_WRITE,MAP_SHARED,pFbdev->fb,0); 33 | 34 | if(-1L == (long)pFbdev->fb_mem){ 35 | printf("mmap error with mem:%lu,mem_offset:%lu\n",pFbdev->fb_mem_offset,pFbdev->fb_mem); 36 | return 0; 37 | } 38 | 39 | return 1; 40 | } 41 | 42 | //关闭frame buffer 43 | int fb_close(PFBDEV pFbdev) 44 | { 45 | close(pFbdev->fb); 46 | pFbdev->fb = -1; 47 | } 48 | 49 | //打印frame buffer 所占内存的开始地址  50 | void pmem_start(PFBDEV pFbdev) 51 | { 52 | printf("frame buffer所占内存的开始地址为:%lu\n",pFbdev->fb_fix.smem_start); 53 | } 54 | 55 | //打印FB_TYPE 56 | void p_type(PFBDEV pFbdev) 57 | { 58 | printf("frame buffer 的类型为:%d\n",pFbdev->fb_fix.type); 59 | } 60 | 61 | //打印可见清晰度 62 | void p_visible_res(PFBDEV pFbdev) 63 | { 64 | printf("frame buffer的可见清晰度为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres,pFbdev->fb_var.yres); 65 | } 66 | 67 | //打印虚拟分辨率 68 | void p_virt_res(PFBDEV pFbdev) 69 | { 70 | printf("frame buffer的虚拟清晰度为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres_virtual,pFbdev->fb_var.yres_virtual); 71 | } 72 | 73 | //打印虚拟到可见的偏移量 74 | void p_offset(PFBDEV pFbdev) 75 | { 76 | printf("frame buffer的虚拟分辨率到可见分辨率的偏移量为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xoffset,pFbdev->fb_var.yoffset); 77 | } 78 | 79 | //打印每个像素的位数 80 | void p_bpp(PFBDEV pFbdev) 81 | { 82 | printf("frame buffer的BPP为:%d\n",pFbdev->fb_var.bits_per_pixel); 83 | } 84 | 85 | //打印R,G,B和透明度 86 | void p_rgbt(PFBDEV pFbdev) 87 | { 88 | //R位域 89 | printf("R位域:\n"); 90 | struct fb_bitfield bf = pFbdev->fb_var.red; 91 | printf("\t开始:%d\n",bf.offset); 92 | printf("\t长度:%d\n",bf.length); 93 | printf("\tMSB:%d\n",bf.msb_right); 94 | 95 | //G位域 96 | printf("G位域:\n"); 97 | bf = pFbdev->fb_var.green; 98 | printf("\t开始:%d\n",bf.offset); 99 | printf("\t长度:%d\n",bf.length); 100 | printf("\tMSB:%d\n",bf.msb_right); 101 | 102 | // B位域 103 | printf("B位域:\n"); 104 | bf = pFbdev->fb_var.blue; 105 | printf("\t开始:%d\n",bf.offset); 106 | printf("\t长度:%d\n",bf.length); 107 | printf("\tMSB:%d\n",bf.msb_right); 108 | 109 | // 透明度位域 110 | printf("透明度位域:\n"); 111 | bf = pFbdev->fb_var.transp; 112 | printf("\t开始:%d\n",bf.offset); 113 | printf("\t长度:%d\n",bf.length); 114 | printf("\tMSB:%d\n",bf.msb_right); 115 | } 116 | 117 | //打印在内存中的高度和宽度 118 | void p_hw(PFBDEV pFbdev) 119 | { 120 | printf("frame buffer在内存中所占的高度和宽度分别是:\n\t宽度 = %d\n\t高度 = %d\n",pFbdev->fb_var.height,pFbdev->fb_var.width); 121 | } 122 | 123 | //清空控制台  124 | void clear_con(void *addr,int n,size_t len) 125 | { 126 | memset(addr,n,len); 127 | } 128 | 129 | //映射到内存 130 | void fb_memcpy(void *addr,void *color,size_t len) 131 | { 132 | memcpy(addr,color,len); 133 | } 134 | 135 | //画点 136 | void draw_dot(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b) 137 | { 138 | uint32_t offset; 139 | uint8_t color[4]; 140 | color[0] = b; 141 | color[1] = g; 142 | color[2] = r; 143 | color[3] = 0x0; //透明度 144 | 145 | offset = p.y * pFbdev->fb_fix.line_length + 4 * p.x; 146 | //将操作映射到内存中 147 | fb_memcpy((void*)pFbdev->fb_mem + pFbdev->fb_mem_offset + offset,color,4); 148 | 149 | } 150 | 151 | //画横线 152 | void draw_h_line(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b) 153 | { 154 | int m; 155 | 156 | int length = maxX.x - minX.x; 157 | for(m = 0;m < length;m++){ 158 | POINT tp; 159 | tp.x = minX.x + m; 160 | tp.y = minX.y; 161 | 162 | draw_dot(pFbdev,tp,r,g,b); 163 | } 164 | } 165 | 166 | //画竖线 167 | void draw_v_line(PFBDEV pFbdev,POINT minY,POINT maxY,uint8_t r,uint8_t g,uint8_t b) 168 | { 169 | int m; 170 | 171 | int length = maxY.y - minY.y; 172 | for(m = 0;m < length;m++){ 173 | POINT tp; 174 | tp.x = minY.x; 175 | tp.y = minY.y + m; 176 | 177 | draw_dot(pFbdev,tp,r,g,b); 178 | } 179 | } 180 | 181 | 182 | //画一个矩形框 183 | void draw_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b) 184 | { 185 | draw_h_line(pFbdev,lu,ru,r,g,b); 186 | draw_h_line(pFbdev,ld,rd,r,g,b); 187 | draw_v_line(pFbdev,lu,ld,r,g,b); 188 | draw_v_line(pFbdev,ru,rd,r,g,b); 189 | } 190 | 191 | //填充一个矩形框 192 | void fill_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b) 193 | { 194 | int xlen = ru.x - lu.x; 195 | int ylen = ld.y - lu.y; 196 | 197 | int m,n; 198 | 199 | for(m = 0;m < ylen;m++){ 200 | for(n = 0;n < xlen;n++){ 201 | POINT p; 202 | p.x = lu.x + n; 203 | p.y = lu.y + m; 204 | 205 | draw_dot(pFbdev,p,r,g,b); 206 | } 207 | } 208 | } 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | -------------------------------------------------------------------------------- /fb5/fbtool.h: -------------------------------------------------------------------------------- 1 | #ifndef __FBTOOL_H_ 2 | #define __FBTOOL_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "page.h" 16 | 17 | typedef struct fbdev{ 18 | int fb; //framebuffer打开后的唯一标识符 19 | struct fb_fix_screeninfo fb_fix; 20 | struct fb_var_screeninfo fb_var; 21 | /* 新增 */ 22 | unsigned long fb_mem_offset; //frame buffer所占内存的偏移量 23 | unsigned long fb_mem; //frame buffer的映射到进程内存空间的起始地址 24 | 25 | char dev[20]; 26 | }FBDEV,*PFBDEV; 27 | 28 | typedef struct point{ 29 | int x; 30 | int y; 31 | int z; 32 | }POINT,*PPOINT; 33 | 34 | //打开framebuffer 35 | int fb_open(PFBDEV pFbdev); 36 | //关闭framebuffer 37 | int fb_close(PFBDEV pFbdev); 38 | //打印frame buffer 所占内存的开始地址  39 | void pmem_start(PFBDEV pFbdev); 40 | //打印FB_TYPE 41 | void p_type(PFBDEV pFbdev); 42 | //打印可见清晰度 43 | void p_visible_res(PFBDEV pFbdev); 44 | //打印虚拟分辨率 45 | void p_virt_res(PFBDEV pFbdev); 46 | //打印虚拟到可见的偏移量 47 | void p_offset(PFBDEV pFbdev); 48 | //打印每个像素的位数 49 | void p_bpp(PFBDEV pFbdev); 50 | //打印R,G,B和透明度 51 | void p_rgbt(PFBDEV pFbdev); 52 | //打印在内存中的高度和宽度 53 | void p_hw(PFBDEV pFbdev); 54 | //清空控制台  55 | void clear_con(void *addr,int n,size_t len); 56 | //映射到内存 57 | void fb_memcpy(void *addr,void *color,size_t len); 58 | //画点 59 | void draw_dot(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b); 60 | //画横线 61 | void draw_h_line(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b); 62 | //画竖线 63 | void draw_v_line(PFBDEV pFbdev,POINT minY,POINT maxY,uint8_t r,uint8_t g,uint8_t b); 64 | //画一个矩形框 65 | void draw_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b); 66 | //填充一个矩形框 67 | void fill_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b); 68 | #endif 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /fb5/page.h: -------------------------------------------------------------------------------- 1 | #ifndef _I386_PAGE_H 2 | #define _I386_PAGE_H 3 | /* PAGE_SHIFT determines the page size */ 4 | #define PAGE_SHIFT 12 5 | #define PAGE_SIZE (1UL << PAGE_SHIFT) 6 | #define PAGE_MASK (~(PAGE_SIZE-1)) 7 | #define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1)) 8 | #define LARGE_PAGE_SIZE (1UL << PMD_SHIFT) 9 | #ifdef __KERNEL__ 10 | #ifndef __ASSEMBLY__ 11 | #include 12 | #ifdef CONFIG_X86_USE_3DNOW 13 | #include 14 | #define clear_page(page) mmx_clear_page((void *)(page)) 15 | #define copy_page(to,from) mmx_copy_page(to,from) 16 | #else 17 | /* 18 | * On older X86 processors it's not a win to use MMX here it seems. 19 | * Maybe the K6-III ? 20 | */ 21 | #define clear_page(page) memset((void *)(page), 0, PAGE_SIZE) 22 | #define copy_page(to,from) memcpy((void *)(to), (void *)(from), PAGE_SIZE) 23 | #endif 24 | #define clear_user_page(page, vaddr, pg) clear_page(page) 25 | #define copy_user_page(to, from, vaddr, pg) copy_page(to, from) 26 | /* 27 | * These are used to make use of C type-checking.. 28 | */ 29 | #ifdef CONFIG_X86_PAE 30 | typedef struct { unsigned long pte_low, pte_high; } pte_t; 31 | typedef struct { unsigned long long pmd; } pmd_t; 32 | typedef struct { unsigned long long pgd; } pgd_t; 33 | #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32)) 34 | #define HPAGE_SHIFT 21 35 | #else 36 | typedef struct { unsigned long pte_low; } pte_t; 37 | typedef struct { unsigned long pmd; } pmd_t; 38 | typedef struct { unsigned long pgd; } pgd_t; 39 | #define boot_pte_t pte_t /* or would you rather have a typedef */ 40 | #define pte_val(x) ((x).pte_low) 41 | #define HPAGE_SHIFT 22 42 | #endif 43 | #define PTE_MASK PAGE_MASK 44 | #ifdef CONFIG_HUGETLB_PAGE 45 | #define HPAGE_SIZE ((1UL) << HPAGE_SHIFT) 46 | #define HPAGE_MASK (~(HPAGE_SIZE - 1)) 47 | #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT) 48 | #endif 49 | typedef struct { unsigned long pgprot; } pgprot_t; 50 | #define pmd_val(x) ((x).pmd) 51 | #define pgd_val(x) ((x).pgd) 52 | #define pgprot_val(x) ((x).pgprot) 53 | #define __pte(x) ((pte_t) { (x) } ) 54 | #define __pmd(x) ((pmd_t) { (x) } ) 55 | #define __pgd(x) ((pgd_t) { (x) } ) 56 | #define __pgprot(x) ((pgprot_t) { (x) } ) 57 | #endif /* !__ASSEMBLY__ */ 58 | /* to align the pointer to the (next) page boundary */ 59 | #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) 60 | /* 61 | * This handles the memory map.. We could make this a config 62 | * option, but too many people screw it up, and too few need 63 | * it. 64 | * 65 | * A __PAGE_OFFSET of 0xC0000000 means that the kernel has 66 | * a virtual address space of one gigabyte, which limits the 67 | * amount of physical memory you can use to about 950MB. 68 | * 69 | * If you want more physical memory than this then see the CONFIG_HIGHMEM4G 70 | * and CONFIG_HIGHMEM64G options in the kernel configuration. 71 | */ 72 | /* 73 | * This much address space is reserved for vmalloc() and iomap() 74 | * as well as fixmap mappings. 75 | */ 76 | #define __VMALLOC_RESERVE (128 << 20) 77 | #ifndef __ASSEMBLY__ 78 | /* Pure 2^n version of get_order */ 79 | static __inline__ int get_order(unsigned long size) 80 | { 81 | int order; 82 | size = (size-1) >> (PAGE_SHIFT-1); 83 | order = -1; 84 | do { 85 | size >>= 1; 86 | order++; 87 | } while (size); 88 | return order; 89 | } 90 | #endif /* __ASSEMBLY__ */ 91 | #ifdef __ASSEMBLY__ 92 | #define __PAGE_OFFSET (0xC0000000) 93 | #else 94 | #define __PAGE_OFFSET (0xC0000000UL) 95 | #endif 96 | #define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET) 97 | #define VMALLOC_RESERVE ((unsigned long)__VMALLOC_RESERVE) 98 | #define MAXMEM (-__PAGE_OFFSET-__VMALLOC_RESERVE) 99 | #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) 100 | #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET)) 101 | #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) 102 | #ifndef CONFIG_DISCONTIGMEM 103 | #define pfn_to_page(pfn) (mem_map + (pfn)) 104 | #define page_to_pfn(page) ((unsigned long)((page) - mem_map)) 105 | #define pfn_valid(pfn) ((pfn) < max_mapnr) 106 | #endif /* !CONFIG_DISCONTIGMEM */ 107 | #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) 108 | #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) 109 | #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | / 110 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) 111 | #endif /* __KERNEL__ */ 112 | #endif /* _I386_PAGE_H */ 113 | -------------------------------------------------------------------------------- /fb5/screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongbochen/fb/57e26b8fca539db14184df71466e6a5a070db9a8/fb5/screenshot.jpg -------------------------------------------------------------------------------- /fb5/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongbochen/fb/57e26b8fca539db14184df71466e6a5a070db9a8/fb5/test -------------------------------------------------------------------------------- /fb5/test.c: -------------------------------------------------------------------------------- 1 | #include "fbtool.h" 2 | 3 | int main() 4 | { 5 | FBDEV fbdev; 6 | 7 | memset(&fbdev,0,sizeof(FBDEV)); 8 | strcpy(fbdev.dev,"/dev/fb0"); 9 | 10 | if(0 == fb_open(&fbdev)){ 11 | printf("Open fail!!\n"); 12 | return -1; 13 | } 14 | /** 15 | //打印frame buffer 所占内存的开始地址  16 | pmem_start(&fbdev); 17 | //打印FB_TYPE 18 | p_type(&fbdev); 19 | //打印可见清晰度 20 | p_visible_res(&fbdev); 21 | //打印虚拟分辨率 22 | p_virt_res(&fbdev); 23 | //打印虚拟到可见的偏移量 24 | p_offset(&fbdev); 25 | //打印每个像素的位数 26 | p_bpp(&fbdev); 27 | //打印R,G,B和透明度 28 | p_rgbt(&fbdev); 29 | //打印在内存中的高度和宽度 30 | p_hw(&fbdev); 31 | //打印fb的RGB和透明度的位域 32 | p_rgbt(&fbdev); 33 | 34 | getchar(); 35 | 36 | //清屏 37 | clear_con(fbdev.fb_mem + fbdev.fb_mem_offset,-1,fbdev.fb_fix.smem_len); */ 38 | 39 | POINT p; 40 | p.x = 100; 41 | p.y = 100; 42 | //画点 43 | draw_dot(&fbdev,p,0x0,0xff,0x0); 44 | 45 | //划横线 46 | //画横线 47 | POINT p21; 48 | p21.x = 120; 49 | p21.y = 100; 50 | POINT p2; 51 | p2.x = 160; 52 | p2.y = 160; 53 | draw_h_line(&fbdev,p21,p2,0x0,0xff,0x0); 54 | 55 | //画竖线 56 | POINT p31; 57 | p31.x = 100; 58 | p31.y = 120; 59 | POINT p3; 60 | p3.x = 100; 61 | p3.y = 160; 62 | draw_v_line(&fbdev,p31,p3,0x0,0xff,0x0); 63 | 64 | POINT p40; 65 | p40.x = 120; 66 | p40.y = 120; 67 | POINT p41; 68 | p41.x = 160; 69 | p41.y = 120; 70 | POINT p42; 71 | p42.x = 120; 72 | p42.y = 160; 73 | POINT p43; 74 | p43.x = 160; 75 | p43.y = 160; 76 | //画矩形 77 | draw_rec(&fbdev,p40,p42,p41,p43,0x0,0xff,0x0); 78 | 79 | POINT p50; 80 | p50.x = 100; 81 | p50.y = 180; 82 | POINT p51; 83 | p51.x = 160; 84 | p51.y = 180; 85 | POINT p52; 86 | p52.x = 100; 87 | p52.y = 220; 88 | POINT p53; 89 | p53.x = 160; 90 | p53.y = 220; 91 | //填充矩形 92 | fill_rec(&fbdev,p50,p52,p51,p53,0x0,0xff,0x0); 93 | return 0; 94 | } 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /fb6/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | gcc page.h fbtool.h fbtool.c test.c -o test -lm 3 | clean: 4 | rm test 5 | -------------------------------------------------------------------------------- /fb6/README.md: -------------------------------------------------------------------------------- 1 | **(一):写在前面** 2 | 3 | 这一次进行了一个比较大的迭代,在这里我先把相对于上一个版本的改进做一个解释: 4 | 5 | - 1:进一步完善画点,增加了使用字符串代替RGBT值 6 | - 2:实现字符串解析出RGBT值 7 | - 3:增加了画圆的算法 8 | - 4:进一步增强了代码注释 9 | 10 | 这四个点是这一节实现的主要内容.这样的修改为下面进一步的实现提供了方便. 11 | 12 | **(二):功能介绍** 13 | 14 | 首先我做的是把颜色相关的代码单独分离开来,新增加一个color.h文件,专用于颜色相关的操作和属性表示.下面就是对画点,画线,和画圆的进一步增强. 15 | 16 | *1:画点的进一步增强* 17 | 18 | 在画点的时候,之前都是使用结构体POINT来代替点的位置,但是,平时我们在使用的时候,比较方便的就是直接指定点的x,y值,所以,我首先增加了指定点的x,y值来画点. 19 | 20 | ``` 21 | /* 22 | * 该函数用于指定点的横坐标,纵坐标的值来画点 23 | * @param pFbdev 参考结构体 fbdev 24 | * @param x 点的坐标对应的横坐标的值 25 | * @param y 点的坐标对应的纵坐标的值 26 | * @param r 颜色对应的R值 27 |  * @param g 颜色对应的G值 28 | * @param b 颜色对应的B值 29 | */ 30 | void draw_x_y_dot(PFBDEV pFbdev,int x,int y,uint8_t r,uint8_t g,uint8_t b); 31 | 32 | ``` 33 | 34 | 另一方面,之前无论是在画点,画线还是画其他形状的时候,我们都仅仅是指定他们颜色的RGB值,但是没有对透明度的指定,所以,在这里,我又新增了一个指定透明度来画点的实现. 35 | 36 | ``` 37 | /* 38 | * 该函数用于实现画点,不过在这个函数中需要设定透明度参数 39 | * @param pFbdev 参考结构体 fbdev 40 | * @param p 点的坐标 41 | * @param r 颜色对应的R值 42 |  * @param g 颜色对应的G值 43 | * @param b 颜色对应的B值 44 |  * @param t 颜色对应的透明度值 45 | * @return void 46 | */ 47 | void draw_dot_with_trans(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b,uint8_t t); 48 | 49 | ``` 50 | 51 | 还有就是把指定透明度和指定x,y值相结合实现一个画点的函数实现. 52 | 53 | ``` 54 | /* 55 | * 该函数用于指定点的横坐标,纵坐标的值,并且必须指明透明度来画点 56 | * @param pFbdev 参考结构体 fbdev 57 | * @param x 点的坐标对应的横坐标的值 58 | * @param y 点的坐标对应的纵坐标的值 59 | * @param r 颜色对应的R值 60 | * @param g 颜色对应的G值 61 | * @param b 颜色对应的B值 62 | * @param t 颜色对应的透明度值 63 | */ 64 | void draw_x_y_dot_with_trans(PFBDEV pFbdev,int x,int y,uint8_t r,uint8_t g,uint8_t b,uint8_t t); 65 | 66 | ``` 67 | 68 | 后面又增加了一些别的画点的函数,包括在RGBT结构体中指定透明度啊等等函数.这里不再赘余. 69 | 70 | *2:字符串代表颜色* 71 | 72 | 在我们的程序中,我们可以知道,无论是颜色的RGBT值,都是使用uint8_t作为其类型的.也就是8为的正整形数字.我们可以使用两个16进制数来表示8位,例如0xff,转换成二进制数就是11111111.这样就能代表颜色了.对于RGBT都是这样表示,所以,我们使用"FFFFFFFF"来表示RGBT很合适. 73 | 74 | 下面这个代码是我将字符串转换成RGBT的算法,这个算法现在我感觉很不好,后期还需要修改. 75 | 76 | ``` 77 | RGBT getRGBT(const char *temp){ 78 | RGBT rgbt; 79 | 80 | char *c_tmp; 81 | c_tmp = (char *)malloc(4 * sizeof(int)); 82 | 83 | c_tmp[0] = '0'; 84 | c_tmp[1] = 'x'; 85 | int r,g,b,t; 86 | 87 | //RGBT值的计算 88 | c_tmp[2] = temp[0]; 89 | c_tmp[3] = temp[1]; 90 | 91 | r = strtol(c_tmp,NULL,16); 92 | 93 | c_tmp[2] = temp[2]; 94 | c_tmp[3] = temp[3]; 95 | 96 | g = strtol(c_tmp,NULL,16); 97 | 98 | c_tmp[2] = temp[4]; 99 | c_tmp[3] = temp[5]; 100 | 101 | b = strtol(c_tmp,NULL,16); 102 | 103 | c_tmp[2] = temp[6]; 104 | c_tmp[3] = temp[7]; 105 | 106 | t = strtol(c_tmp,NULL,16); 107 | 108 | rgbt.r = r; 109 | rgbt.g = g; 110 | rgbt.b = b; 111 | rgbt.t = t; 112 | 113 | return rgbt; 114 | } 115 | 116 | ``` 117 | 118 | 这样,以后就可以方便的时候字符串来代替RGBT值了. 119 | 120 | *3:画圆的实现* 121 | 122 | 画圆的实现比较简单,就是使用方程式: 123 | $$(x-a)^2 + (y-b)^2 = c^2$$ 124 | 125 | 这样,我们已经知道圆的中心点(a,b),还有圆的半径R了.那么我们就可以使用上面的公式将圆画出来. 126 | 127 | ``` 128 | //画圆 129 | void draw_circle(PFBDEV pFbdev,int x,int y,int radius,const char *color) 130 | { 131 | double i; 132 | 133 | int tmp; 134 | 135 | for(i = x - radius; i < x + radius;i+=0.01){ 136 | tmp = sqrt(radius * radius - (i - x) * (i - x)); 137 | 138 | draw_x_y_color_dot_with_string(pFbdev,i,(tmp + y),color); 139 | draw_x_y_color_dot_with_string(pFbdev,i,(-tmp + y),color); 140 | } 141 | } 142 | 143 | ``` 144 | 145 | 注意 i+= 0.01 这个地方,如果将0.01换成别的,会有不一样的效果,大家如果有兴趣可以尝试一下. 146 | 147 | **(三):后期规划** 148 | 149 | 在后面的时候,我们将画点,画线,画各种图形分开来,正确实现一个在命令行界面下的一个小型的图形库.主要是为了好玩,有趣. 150 | 151 | **(四):写在后面** 152 | 153 | 生活的乐趣就是充满了很多不定因素. 154 | 155 | ![jiafei](jiafei.gif) 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /fb6/color.h: -------------------------------------------------------------------------------- 1 | #ifndef _COLOR_H_ 2 | #define _COLOR_H_ 3 | 4 | /** 5 | * 代表颜色的结构体 6 | * @property r 颜色对应的R值 7 | * @property g 颜色对应的G值 8 |  * @property b 颜色对应的B值 9 | * @property t 颜色对应的T值 10 | */ 11 | typedef struct rgbt{ 12 | uint8_t r; 13 | uint8_t g; 14 | uint8_t b; 15 | uint8_t t; 16 | }RGBT; 17 | 18 | //定义一些常用的颜色属性 19 | #define BLACK "00000000"  //黑色 20 | #define YELLOW "ffff0000" //黄色 21 | #define BLUE_LIGHT "B0E0E600" //淡蓝色 22 | #define YELLOW_BANANA "E3CF5700" //香蕉色 23 | #define BLUE_SKY "87CEEB00" //天蓝色 24 | #define ORIANGE "ff610000" //橙色 25 | #define GREEN "00ff0000" //绿色 26 | #define PURPLE "A020F000" //紫色 27 | #define RED "FF000000" //红色 28 | 29 | 30 | #endif //_COLOR_H_ 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /fb6/fbtool.c: -------------------------------------------------------------------------------- 1 | #include "fbtool.h" 2 | 3 | //打开并且初始化该frame buffer 4 | int fb_open(PFBDEV pFbdev) 5 | { 6 | //打开frame buffer 7 | pFbdev->fb = open(pFbdev->dev,O_RDWR); 8 | 9 | if(pFbdev->fb < 0) 10 | { 11 | printf("打开错误 %s : %n.请检查内核配置\n",pFbdev->dev); 12 | return 0; 13 | } 14 | 15 | // 初始化fb_var 16 | if(-1 == ioctl(pFbdev->fb,FBIOGET_VSCREENINFO,&(pFbdev->fb_var))) 17 | { 18 | printf("ioctl FBIOGET_VSCREENINFO\n"); 19 | return 0; 20 | } 21 | 22 | // 初始化fb_fix 23 | if(-1 == ioctl(pFbdev->fb,FBIOGET_FSCREENINFO,&(pFbdev->fb_fix))) 24 | { 25 | printf("ioctl FBIOGET_FSCREENINFO\n"); 26 | return 0; 27 | } 28 | 29 | //将物理地址映射到虚拟地址 30 | pFbdev->fb_mem_offset = (unsigned long)pFbdev->fb_fix.smem_start & (~PAGE_MASK); 31 | 32 | pFbdev->fb_mem = (unsigned long int)mmap(NULL,pFbdev->fb_fix.smem_len + pFbdev->fb_mem_offset,PROT_READ|PROT_WRITE,MAP_SHARED,pFbdev->fb,0); 33 | 34 | if(-1L == (long)pFbdev->fb_mem){ 35 | printf("mmap error with mem:%lu,mem_offset:%lu\n",pFbdev->fb_mem_offset,pFbdev->fb_mem); 36 | return 0; 37 | } 38 | 39 | return 1; 40 | } 41 | 42 | //关闭frame buffer 43 | int fb_close(PFBDEV pFbdev) 44 | { 45 | int r = close(pFbdev->fb); 46 | pFbdev->fb = -1; 47 | 48 | return r; 49 | } 50 | 51 | //打印frame buffer 所占内存的开始地址  52 | void pmem_start(PFBDEV pFbdev) 53 | { 54 | printf("frame buffer所占内存的开始地址为:%lu\n",pFbdev->fb_fix.smem_start); 55 | } 56 | 57 | //打印FB_TYPE 58 | void p_type(PFBDEV pFbdev) 59 | { 60 | printf("frame buffer 的类型为:%d\n",pFbdev->fb_fix.type); 61 | } 62 | 63 | //打印可见清晰度 64 | void p_visible_res(PFBDEV pFbdev) 65 | { 66 | printf("frame buffer的可见清晰度为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres,pFbdev->fb_var.yres); 67 | } 68 | 69 | //打印虚拟分辨率 70 | void p_virt_res(PFBDEV pFbdev) 71 | { 72 | printf("frame buffer的虚拟清晰度为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres_virtual,pFbdev->fb_var.yres_virtual); 73 | } 74 | 75 | //打印虚拟到可见的偏移量 76 | void p_offset(PFBDEV pFbdev) 77 | { 78 | printf("frame buffer的虚拟分辨率到可见分辨率的偏移量为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xoffset,pFbdev->fb_var.yoffset); 79 | } 80 | 81 | //打印每个像素的位数 82 | void p_bpp(PFBDEV pFbdev) 83 | { 84 | printf("frame buffer的BPP为:%d\n",pFbdev->fb_var.bits_per_pixel); 85 | } 86 | 87 | //打印R,G,B和透明度 88 | void p_rgbt(PFBDEV pFbdev) 89 | { 90 | //R位域 91 | printf("R位域:\n"); 92 | struct fb_bitfield bf = pFbdev->fb_var.red; 93 | printf("\t开始:%d\n",bf.offset); 94 | printf("\t长度:%d\n",bf.length); 95 | printf("\tMSB:%d\n",bf.msb_right); 96 | 97 | //G位域 98 | printf("G位域:\n"); 99 | bf = pFbdev->fb_var.green; 100 | printf("\t开始:%d\n",bf.offset); 101 | printf("\t长度:%d\n",bf.length); 102 | printf("\tMSB:%d\n",bf.msb_right); 103 | 104 | // B位域 105 | printf("B位域:\n"); 106 | bf = pFbdev->fb_var.blue; 107 | printf("\t开始:%d\n",bf.offset); 108 | printf("\t长度:%d\n",bf.length); 109 | printf("\tMSB:%d\n",bf.msb_right); 110 | 111 | // 透明度位域 112 | printf("透明度位域:\n"); 113 | bf = pFbdev->fb_var.transp; 114 | printf("\t开始:%d\n",bf.offset); 115 | printf("\t长度:%d\n",bf.length); 116 | printf("\tMSB:%d\n",bf.msb_right); 117 | } 118 | 119 | //打印在内存中的高度和宽度 120 | void p_hw(PFBDEV pFbdev) 121 | { 122 | printf("frame buffer在内存中所占的高度和宽度分别是:\n\t宽度 = %d\n\t高度 = %d\n",pFbdev->fb_var.height,pFbdev->fb_var.width); 123 | } 124 | 125 | //清空控制台  126 | void clear_con(void *addr,int n,size_t len) 127 | { 128 | memset(addr,n,len); 129 | } 130 | 131 | //映射到内存 132 | void fb_memcpy(void *addr,void *color,size_t len) 133 | { 134 | memcpy(addr,color,len); 135 | } 136 | 137 | //画点 138 | void draw_dot(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b) 139 | { 140 | uint32_t offset; 141 | uint8_t color[4]; 142 | color[0] = b; 143 | color[1] = g; 144 | color[2] = r; 145 | color[3] = 0x0; //透明度 146 | 147 | offset = p.y * pFbdev->fb_fix.line_length + 4 * p.x; 148 | //将操作映射到内存中 149 | fb_memcpy((void*)pFbdev->fb_mem + pFbdev->fb_mem_offset + offset,color,4); 150 | } 151 | 152 | //画点 153 | void draw_dot_with_trans(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b,uint8_t t) 154 | { 155 | uint32_t offset; 156 | uint8_t color[4]; 157 | color[0] = b; 158 | color[1] = g; 159 | color[2] = r; 160 | color[3] = t; //透明度 161 | 162 | offset = p.y * pFbdev->fb_fix.line_length + 4 * p.x; 163 | //将操作映射到内存中 164 | fb_memcpy((void*)pFbdev->fb_mem + pFbdev->fb_mem_offset + offset,color,4); 165 | } 166 | 167 | //画横线 168 | void draw_h_line(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b) 169 | { 170 | int m; 171 | 172 | int length = maxX.x - minX.x; 173 | for(m = 0;m < length;m++){ 174 | POINT tp; 175 | tp.x = minX.x + m; 176 | tp.y = minX.y; 177 | 178 | draw_dot(pFbdev,tp,r,g,b); 179 | } 180 | } 181 | 182 | void draw_h_line_with_trans(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b,uint8_t t){ 183 | int m; 184 | 185 | int length = maxX.x - minX.x; 186 | for(m = 0;m < length;m++){ 187 | POINT tp; 188 | tp.x = minX.x + m; 189 | tp.y = minX.y; 190 | 191 | draw_dot_with_trans(pFbdev,tp,r,g,b,t); 192 | } 193 | } 194 | 195 | //画竖线 196 | void draw_v_line(PFBDEV pFbdev,POINT minY,POINT maxY,uint8_t r,uint8_t g,uint8_t b) 197 | { 198 | int m; 199 | 200 | int length = maxY.y - minY.y; 201 | for(m = 0;m < length;m++){ 202 | POINT tp; 203 | tp.x = minY.x; 204 | tp.y = minY.y + m; 205 | 206 | draw_dot(pFbdev,tp,r,g,b); 207 | } 208 | } 209 | 210 | 211 | //画一个矩形框 212 | void draw_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b) 213 | { 214 | draw_h_line(pFbdev,lu,ru,r,g,b); 215 | draw_h_line(pFbdev,ld,rd,r,g,b); 216 | draw_v_line(pFbdev,lu,ld,r,g,b); 217 | draw_v_line(pFbdev,ru,rd,r,g,b); 218 | } 219 | 220 | //填充一个矩形框 221 | void fill_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b) 222 | { 223 | int xlen = ru.x - lu.x; 224 | int ylen = ld.y - lu.y; 225 | 226 | int m,n; 227 | 228 | for(m = 0;m < ylen;m++){ 229 | for(n = 0;n < xlen;n++){ 230 | POINT p; 231 | p.x = lu.x + n; 232 | p.y = lu.y + m; 233 | 234 | draw_dot(pFbdev,p,r,g,b); 235 | } 236 | } 237 | } 238 | 239 | //画点 240 | void draw_x_y_dot(PFBDEV pFbdev,int x,int y,uint8_t r,uint8_t g,uint8_t b) 241 | { 242 | POINT p; 243 | p.x = x; 244 | p.y = y; 245 | 246 | draw_dot(pFbdev,p,r,g,b); 247 | } 248 | 249 | //画点 250 | void draw_x_y_dot_with_trans(PFBDEV pFbdev,int x,int y,uint8_t r,uint8_t g,uint8_t b,uint8_t t) 251 | { 252 | POINT p; 253 | p.x = x; 254 | p.y = y; 255 | 256 | draw_dot_with_trans(pFbdev,p,r,g,b,t); 257 | } 258 | 259 | //画点 260 | void draw_x_y_color_dot(PFBDEV pFbdev,int x,int y,RGBT c) 261 | { 262 | draw_x_y_dot(pFbdev,x,y,c.r,c.g,c.b); 263 | } 264 | 265 | //画点 266 | void draw_x_y_color_dot_with_trans(PFBDEV pFbdev,int x,int y,RGBT c) 267 | { 268 | draw_x_y_dot_with_trans(pFbdev,x,y,c.r,c.g,c.b,c.t); 269 | } 270 | 271 | RGBT getRGBT(const char *temp){ 272 | RGBT rgbt; 273 | 274 | char *c_tmp; 275 | c_tmp = (char *)malloc(4 * sizeof(int)); 276 | 277 | c_tmp[0] = '0'; 278 | c_tmp[1] = 'x'; 279 | int r,g,b,t; 280 | 281 | //RGBT值的计算 282 | c_tmp[2] = temp[0]; 283 | c_tmp[3] = temp[1]; 284 | 285 | r = strtol(c_tmp,NULL,16); 286 | 287 | c_tmp[2] = temp[2]; 288 | c_tmp[3] = temp[3]; 289 | 290 | g = strtol(c_tmp,NULL,16); 291 | 292 | c_tmp[2] = temp[4]; 293 | c_tmp[3] = temp[5]; 294 | 295 | b = strtol(c_tmp,NULL,16); 296 | 297 | c_tmp[2] = temp[6]; 298 | c_tmp[3] = temp[7]; 299 | 300 | t = strtol(c_tmp,NULL,16); 301 | 302 | rgbt.r = r; 303 | rgbt.g = g; 304 | rgbt.b = b; 305 | rgbt.t = t; 306 | 307 | return rgbt; 308 | } 309 | 310 | //画点 color8位,分别代表RGBT 311 | void draw_x_y_color_dot_with_string(PFBDEV pFbdev,int x,int y,const char *temp) 312 | { 313 | RGBT rgbt = getRGBT(temp); 314 | 315 | draw_x_y_dot_with_trans(pFbdev,x,y,rgbt.r,rgbt.g,rgbt.b,rgbt.t); 316 | } 317 | 318 | //划横线 319 | void draw_h_line_with_string(PFBDEV pFbdev,POINT minX,POINT maxX,const char *color) 320 | { 321 | RGBT rgbt = getRGBT(color); 322 | 323 | draw_h_line_with_trans(pFbdev,minX,maxX,rgbt.r,rgbt.g,rgbt.b,rgbt.t); 324 | } 325 | 326 | //画圆 327 | void draw_circle(PFBDEV pFbdev,int x,int y,int radius,const char *color) 328 | { 329 | double i; 330 | 331 | int tmp; 332 | 333 | for(i = x - radius; i < x + radius;i+=0.01){ 334 | tmp = sqrt(radius * radius - (i - x) * (i - x)); 335 | 336 | draw_x_y_color_dot_with_string(pFbdev,i,(tmp + y),color); 337 | draw_x_y_color_dot_with_string(pFbdev,i,(-tmp + y),color); 338 | } 339 | } 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | -------------------------------------------------------------------------------- /fb6/fbtool.h: -------------------------------------------------------------------------------- 1 | #ifndef __FBTOOL_H_ 2 | #define __FBTOOL_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "page.h" 16 | #include "color.h" 17 | 18 | /** 19 | * 该结构体主要是定义了一组保存frame buffer的属性 20 | * @property fb frame buffer打开后的唯一标识符 21 | * @property fb_fix frame buffer的固定属性就保存在这个结构体中 22 | * @property fb_var frame buffer的可变属性保存在这个结构体中 23 | * @property fb_mem_offset frame buffer所占内存的偏移量 24 | * @property fb_mem frame buffer的映射到进程内存空间的起始地址 25 | */ 26 | typedef struct fbdev{ 27 | int fb; 28 | struct fb_fix_screeninfo fb_fix; 29 | struct fb_var_screeninfo fb_var; 30 | /* 新增 */ 31 | unsigned long fb_mem_offset; 32 | unsigned long fb_mem; 33 | 34 | char dev[20]; 35 | }FBDEV,*PFBDEV; 36 | 37 | /** 38 | * 该结构体用于定位点的位置,包括横坐标,纵坐标,深坐标 39 | * @property x 横坐标 40 | * @property y 纵坐标 41 | * @property z 深坐标(这个用于3D) 42 | */ 43 | typedef struct point{ 44 | int x; 45 | int y; 46 | int z; 47 | }POINT,*PPOINT; 48 | 49 | /* 50 | * 该函数用于打开frame buffer 51 | * @param pFbdev 参照结构体 fbdev 52 | * @return 0 - 打开失败 53 |  * 1 - 打开成功 54 | */ 55 | int fb_open(PFBDEV pFbdev); 56 | 57 | /* 58 | * 该函数用于关闭frame buffer设备 59 | * @param pFbdev 参照结构体 fbdev 60 | * @return 0 - 关闭成功 61 | * >0 - 关闭失败 62 | */ 63 | int fb_close(PFBDEV pFbdev); 64 | 65 | /* 66 | * 该函数用于打印frame buffer 所占内存的开始地址  67 | * @param pFbdev 参照结构体 fbdev 68 | * @return void 69 | */ 70 | void pmem_start(PFBDEV pFbdev); 71 | 72 | /* 73 | * 该函数用于打印FB_TYPE 74 | * @param pFbdev 参照结构体 fbdev 75 | * @return void 76 | */ 77 | void p_type(PFBDEV pFbdev); 78 | 79 | /* 80 | * 该函数用于打印可见清晰度 81 | * @param pFbdev 参照结构体 fbdev 82 | * @return void 83 | */ 84 | void p_visible_res(PFBDEV pFbdev); 85 | 86 | /* 87 | * 该函数用于打印虚拟分辨率 88 | * @param pFbdev 参照结构体 fbdev 89 | * @return void 90 | */ 91 | void p_virt_res(PFBDEV pFbdev); 92 | 93 | /* 94 | * 该函数用于打印虚拟到可见的偏移量 95 | * @param pFbdev 参照结构体 fbdev 96 | * @return void 97 | */ 98 | void p_offset(PFBDEV pFbdev); 99 | 100 | /* 101 | * 该函数用于打印每个像素的位数 102 | * @param pFbdev 参照结构体 fbdev 103 | * @return void 104 | */ 105 | void p_bpp(PFBDEV pFbdev); 106 | 107 | /* 108 | * 该函数用于打印R,G,B和透明度 109 | * @param pFbdev 参照结构体 fbdev 110 | * @return void 111 | */ 112 | void p_rgbt(PFBDEV pFbdev); 113 | 114 | /* 115 | * 该函数用于打印在内存中的高度和宽度 116 | * @param pFbdev 参照结构体 fbdev 117 | * @return void 118 | */ 119 | void p_hw(PFBDEV pFbdev); 120 | 121 | /* 122 | * 将addr开始的len个字符用n替换 123 | * @param addr 开始的地址 124 | * @param n 替换后的字符 125 | * @param len 要替换的字符的个数 126 | * @return void 127 | */ 128 | void clear_con(void *addr,int n,size_t len); 129 | 130 | /* 131 | * 该函数将逻辑地址空间的数据映射到内存当中 132 | * @param addr 内存空间的地址 133 | * @param color 颜色值 134 | * @param len 需要映射的长度 135 |  * @return void 136 | */ 137 | void fb_memcpy(void *addr,void *color,size_t len); 138 | 139 | /* 140 | * 该函数用于在命令行中画点 141 | * @param pFbdev 参考结构体 fbdev 142 | * @param p 点的坐标 143 | * @param r 颜色对应的R值 144 |  * @param g 颜色对应的G值 145 | * @param b 颜色对应的B值 146 | * @return void 147 | */ 148 | void draw_dot(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b); 149 | 150 | /* 151 | * 该函数用于实现画点,不过在这个函数中需要设定透明度参数 152 | * @param pFbdev 参考结构体 fbdev 153 | * @param p 点的坐标 154 | * @param r 颜色对应的R值 155 |  * @param g 颜色对应的G值 156 | * @param b 颜色对应的B值 157 |  * @param t 颜色对应的透明度值 158 | * @return void 159 | */ 160 | void draw_dot_with_trans(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b,uint8_t t); 161 | 162 | /* 163 | * 该函数用于指定点的横坐标,纵坐标的值来画点 164 | * @param pFbdev 参考结构体 fbdev 165 | * @param x 点的坐标对应的横坐标的值 166 | * @param y 点的坐标对应的纵坐标的值 167 | * @param r 颜色对应的R值 168 |  * @param g 颜色对应的G值 169 | * @param b 颜色对应的B值 170 | */ 171 | void draw_x_y_dot(PFBDEV pFbdev,int x,int y,uint8_t r,uint8_t g,uint8_t b); 172 | 173 | /* 174 | * 该函数用于指定点的横坐标,纵坐标的值,并且必须指明透明度来画点 175 | * @param pFbdev 参考结构体 fbdev 176 | * @param x 点的坐标对应的横坐标的值 177 | * @param y 点的坐标对应的纵坐标的值 178 | * @param r 颜色对应的R值 179 |  * @param g 颜色对应的G值 180 | * @param b 颜色对应的B值 181 |  * @param t 颜色对应的透明度值 182 | */ 183 | void draw_x_y_dot_with_trans(PFBDEV pFbdev,int x,int y,uint8_t r,uint8_t g,uint8_t b,uint8_t t); 184 | 185 | /* 186 | * 该函数指定点的横纵坐标,然后使用结构体rgbt来代替颜色来画点 187 | * @param pFbdev 参考结构体 fbdev 188 | * @param x 点的坐标对应的横坐标的值 189 | * @param y 点的坐标对应的纵坐标的值 190 | * @param c 用来代表颜色的结构体 191 | * @return void 192 | * 193 | */ 194 | void draw_x_y_color_dot(PFBDEV pFbdev,int x,int y,RGBT c); 195 | 196 | /* 197 | * 该函数指定点的横纵坐标,然后使用结构体rgbt来代替颜色来画点,不过在这里指明透明度是有效果 198 | * @param pFbdev 参考结构体 fbdev 199 | * @param x 点的坐标对应的横坐标的值 200 | * @param y 点的坐标对应的纵坐标的值 201 | * @param c 用来代表颜色的结构体 202 | * @return void 203 | * 204 | */ 205 | void draw_x_y_color_dot_with_trans(PFBDEV pFbdev,int x,int y,RGBT c); 206 | 207 | /* 208 | * 该函数指定点的横纵坐标,然后使用八位的字符串来指明颜色来画点 209 |  * 注意:这里的字符串里面都是16进制的数值,例如,"ffff0000" 210 | * 211 | * @param pFbdev 参考结构体 fbdev 212 | * @param x 点的坐标对应的横坐标的值 213 | * @param y 点的坐标对应的纵坐标的值 214 | * @param c 用来代表颜色的结构体 215 | * @param color 用来指明颜色的字符串 216 | * @return void 217 | * 218 | */ 219 | void draw_x_y_color_dot_with_string(PFBDEV pFbdev,int x,int y,const char *color); 220 | 221 | /* 222 | * 指定x值较小的点和x值较大的点,并指定颜色的rgb值画一条横线 223 | * @param pFbdev 参考结构体 fbdev 224 | * @param minX x较小的点 225 | * @param maxX x较大的点 226 |  * @param r 颜色对应的R值 227 | * @param g 颜色对应的G值 228 | * @param b 颜色对应的B值 229 | * @return void 230 | */ 231 | void draw_h_line(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b); 232 | 233 | /* 234 | * 指定x值较小的点和x值较大的点,并指定颜色的rgb值和透明度画一条横线 235 | * @param pFbdev 参考结构体 fbdev 236 | * @param minX x较小的点 237 | * @param maxX x较大的点 238 |  * @param r 颜色对应的R值 239 | * @param g 颜色对应的G值 240 | * @param b 颜色对应的B值 241 |  * @param t 颜色对应的透明度 242 | * @return void 243 | * 244 | */ 245 | void draw_h_line_with_trans(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b,uint8_t t); 246 | 247 | /* 248 | * 使用字符串作为颜色的表示来画一条横线 249 | * @param pFbdev 参考结构体 fbdev 250 | * @param minX x较小的点 251 | * @param maxX x较大的点 252 | * @param color 颜色所对应的字符串 253 | * @return void 254 | */ 255 | void draw_h_line_with_string(PFBDEV pFbdev,POINT minX,POINT maxX,const char *color); 256 | 257 | /* 258 | * 指明y最小的一个点和一个y较大的点,并指明RGB值画一条竖线 259 | * @param pFbdev 参考结构体 fbdev 260 | * @param minY y较小的点 261 | * @param maxY y较大的点 262 |  * @param r 颜色对应的R值 263 | * @param g 颜色对应的G值 264 | * @param b 颜色对应的B值 265 | */ 266 | void draw_v_line(PFBDEV pFbdev,POINT minY,POINT maxY,uint8_t r,uint8_t g,uint8_t b); 267 | 268 | /* 269 | * 画一个矩形框 270 | * @param pFbdev 参考结构体 fbdev 271 | * @param lu 矩形框左上角的点 272 | * @param ld 矩形框左下角的点 273 |  * @param ru 矩形框右上角的点 274 | * @param rd 矩形框右下角的点 275 | * @param r 颜色对应的R值 276 | * @param g 颜色对应的G值 277 | * @param b 颜色对应的B值 278 |  * @return void 279 | */ 280 | void draw_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b); 281 | 282 | /* 283 | * 填充一个矩形框 284 | * @param pFbdev 参考结构体 fbdev 285 | * @param lu 矩形框左上角的点 286 | * @param ld 矩形框左下角的点 287 |  * @param ru 矩形框右上角的点 288 | * @param rd 矩形框右下角的点 289 | * @param r 颜色对应的R值 290 | * @param g 颜色对应的G值 291 | * @param b 颜色对应的B值 292 |  * @return void 293 | */ 294 | void fill_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b); 295 | 296 | /* 297 | * 根据字符串获得相应的RGBT 298 | * @param color 颜色对应的字符串 299 | * @return 返回代表颜色的结构体 RGBT 300 | */ 301 | RGBT getRGBT(const char *color); 302 | 303 | /* 304 | * 画一个圆 305 | * @param pFbdev 参考结构体 fbdev 306 |  * @param x 圆的圆心所在的点的x值 307 | * @param y 圆的圆心所在的点的y值 308 | * @param radius 圆的半径的长度 309 | * @color 代表颜色的字符串 310 | * @return void 311 | */ 312 | void draw_circle(PFBDEV pFbdev,int x,int y,int radius,const char *color); 313 | 314 | #endif 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | -------------------------------------------------------------------------------- /fb6/jiafei.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongbochen/fb/57e26b8fca539db14184df71466e6a5a070db9a8/fb6/jiafei.gif -------------------------------------------------------------------------------- /fb6/page.h: -------------------------------------------------------------------------------- 1 | #ifndef _I386_PAGE_H 2 | #define _I386_PAGE_H 3 | /* PAGE_SHIFT determines the page size */ 4 | #define PAGE_SHIFT 12 5 | #define PAGE_SIZE (1UL << PAGE_SHIFT) 6 | #define PAGE_MASK (~(PAGE_SIZE-1)) 7 | #define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1)) 8 | #define LARGE_PAGE_SIZE (1UL << PMD_SHIFT) 9 | #ifdef __KERNEL__ 10 | #ifndef __ASSEMBLY__ 11 | #include 12 | #ifdef CONFIG_X86_USE_3DNOW 13 | #include 14 | #define clear_page(page) mmx_clear_page((void *)(page)) 15 | #define copy_page(to,from) mmx_copy_page(to,from) 16 | #else 17 | /* 18 | * On older X86 processors it's not a win to use MMX here it seems. 19 | * Maybe the K6-III ? 20 | */ 21 | #define clear_page(page) memset((void *)(page), 0, PAGE_SIZE) 22 | #define copy_page(to,from) memcpy((void *)(to), (void *)(from), PAGE_SIZE) 23 | #endif 24 | #define clear_user_page(page, vaddr, pg) clear_page(page) 25 | #define copy_user_page(to, from, vaddr, pg) copy_page(to, from) 26 | /* 27 | * These are used to make use of C type-checking.. 28 | */ 29 | #ifdef CONFIG_X86_PAE 30 | typedef struct { unsigned long pte_low, pte_high; } pte_t; 31 | typedef struct { unsigned long long pmd; } pmd_t; 32 | typedef struct { unsigned long long pgd; } pgd_t; 33 | #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32)) 34 | #define HPAGE_SHIFT 21 35 | #else 36 | typedef struct { unsigned long pte_low; } pte_t; 37 | typedef struct { unsigned long pmd; } pmd_t; 38 | typedef struct { unsigned long pgd; } pgd_t; 39 | #define boot_pte_t pte_t /* or would you rather have a typedef */ 40 | #define pte_val(x) ((x).pte_low) 41 | #define HPAGE_SHIFT 22 42 | #endif 43 | #define PTE_MASK PAGE_MASK 44 | #ifdef CONFIG_HUGETLB_PAGE 45 | #define HPAGE_SIZE ((1UL) << HPAGE_SHIFT) 46 | #define HPAGE_MASK (~(HPAGE_SIZE - 1)) 47 | #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT) 48 | #endif 49 | typedef struct { unsigned long pgprot; } pgprot_t; 50 | #define pmd_val(x) ((x).pmd) 51 | #define pgd_val(x) ((x).pgd) 52 | #define pgprot_val(x) ((x).pgprot) 53 | #define __pte(x) ((pte_t) { (x) } ) 54 | #define __pmd(x) ((pmd_t) { (x) } ) 55 | #define __pgd(x) ((pgd_t) { (x) } ) 56 | #define __pgprot(x) ((pgprot_t) { (x) } ) 57 | #endif /* !__ASSEMBLY__ */ 58 | /* to align the pointer to the (next) page boundary */ 59 | #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) 60 | /* 61 | * This handles the memory map.. We could make this a config 62 | * option, but too many people screw it up, and too few need 63 | * it. 64 | * 65 | * A __PAGE_OFFSET of 0xC0000000 means that the kernel has 66 | * a virtual address space of one gigabyte, which limits the 67 | * amount of physical memory you can use to about 950MB. 68 | * 69 | * If you want more physical memory than this then see the CONFIG_HIGHMEM4G 70 | * and CONFIG_HIGHMEM64G options in the kernel configuration. 71 | */ 72 | /* 73 | * This much address space is reserved for vmalloc() and iomap() 74 | * as well as fixmap mappings. 75 | */ 76 | #define __VMALLOC_RESERVE (128 << 20) 77 | #ifndef __ASSEMBLY__ 78 | /* Pure 2^n version of get_order */ 79 | static __inline__ int get_order(unsigned long size) 80 | { 81 | int order; 82 | size = (size-1) >> (PAGE_SHIFT-1); 83 | order = -1; 84 | do { 85 | size >>= 1; 86 | order++; 87 | } while (size); 88 | return order; 89 | } 90 | #endif /* __ASSEMBLY__ */ 91 | #ifdef __ASSEMBLY__ 92 | #define __PAGE_OFFSET (0xC0000000) 93 | #else 94 | #define __PAGE_OFFSET (0xC0000000UL) 95 | #endif 96 | #define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET) 97 | #define VMALLOC_RESERVE ((unsigned long)__VMALLOC_RESERVE) 98 | #define MAXMEM (-__PAGE_OFFSET-__VMALLOC_RESERVE) 99 | #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) 100 | #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET)) 101 | #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) 102 | #ifndef CONFIG_DISCONTIGMEM 103 | #define pfn_to_page(pfn) (mem_map + (pfn)) 104 | #define page_to_pfn(page) ((unsigned long)((page) - mem_map)) 105 | #define pfn_valid(pfn) ((pfn) < max_mapnr) 106 | #endif /* !CONFIG_DISCONTIGMEM */ 107 | #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) 108 | #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) 109 | #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | / 110 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) 111 | #endif /* __KERNEL__ */ 112 | #endif /* _I386_PAGE_H */ 113 | -------------------------------------------------------------------------------- /fb6/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongbochen/fb/57e26b8fca539db14184df71466e6a5a070db9a8/fb6/test -------------------------------------------------------------------------------- /fb6/test.c: -------------------------------------------------------------------------------- 1 | #include "fbtool.h" 2 | 3 | int main() 4 | { 5 | FBDEV fbdev; 6 | 7 | memset(&fbdev,0,sizeof(FBDEV)); 8 | strcpy(fbdev.dev,"/dev/fb0"); 9 | 10 | if(0 == fb_open(&fbdev)){ 11 | printf("Open fail!!\n"); 12 | return -1; 13 | } 14 | 15 | /** 16 | //打印frame buffer 所占内存的开始地址  17 | pmem_start(&fbdev); 18 | //打印FB_TYPE 19 | p_type(&fbdev); 20 | //打印可见清晰度 21 | p_visible_res(&fbdev); 22 | //打印虚拟分辨率 23 | p_virt_res(&fbdev); 24 | //打印虚拟到可见的偏移量 25 | p_offset(&fbdev); 26 | //打印每个像素的位数 27 | p_bpp(&fbdev); 28 | //打印R,G,B和透明度 29 | p_rgbt(&fbdev); 30 | //打印在内存中的高度和宽度 31 | p_hw(&fbdev); 32 | //打印fb的RGB和透明度的位域 33 | p_rgbt(&fbdev); 34 | 35 | getchar(); 36 | 37 | //清屏 38 | clear_con(fbdev.fb_mem + fbdev.fb_mem_offset,-1,fbdev.fb_fix.smem_len); */ 39 | 40 | 41 | POINT p; 42 | p.x = 100; 43 | p.y = 100; 44 | //画点 45 | draw_x_y_dot(&fbdev,100,100,0x0,0xff,0x0); 46 | /* 47 | RGBT c; 48 | c.r = 0xff; 49 | c.g = 0xff; 50 | c.b = 0xff; 51 | c.t = 0x00; 52 | //draw_x_y_color_dot_with_trans(&fbdev,100,100,RED); 53 | draw_x_y_color_dot_with_string(&fbdev,100,100,YELLOW); 54 | 55 | //划横线 56 | //画横线 57 | POINT p21; 58 | p21.x = 120; 59 | p21.y = 100; 60 | POINT p2; 61 | p2.x = 160; 62 | p2.y = 160; 63 | //draw_h_line(&fbdev,p21,p2,0x0,0xff,0x0); 64 | draw_h_line_with_string(&fbdev,p21,p2,RED); 65 | 66 | //画竖线 67 | POINT p31; 68 | p31.x = 100; 69 | p31.y = 120; 70 | POINT p3; 71 | p3.x = 100; 72 | p3.y = 160; 73 | draw_v_line(&fbdev,p31,p3,0x0,0xff,0x0); 74 | 75 | POINT p40; 76 | p40.x = 120; 77 | p40.y = 120; 78 | POINT p41; 79 | p41.x = 160; 80 | p41.y = 120; 81 | POINT p42; 82 | p42.x = 120; 83 | p42.y = 160; 84 | POINT p43; 85 | p43.x = 160; 86 | p43.y = 160; 87 | //画矩形 88 | draw_rec(&fbdev,p40,p42,p41,p43,0x0,0xff,0x0); 89 | 90 | POINT p50; 91 | p50.x = 100; 92 | p50.y = 180; 93 | POINT p51; 94 | p51.x = 160; 95 | p51.y = 180; 96 | POINT p52; 97 | p52.x = 100; 98 | p52.y = 220; 99 | POINT p53; 100 | p53.x = 160; 101 | p53.y = 220; 102 | //填充矩形 103 | fill_rec(&fbdev,p50,p52,p51,p53,0x0,0xff,0x0);*/ 104 | 105 | //draw_circle(&fbdev,500,400,100,RED); 106 | 107 | fb_close(&fbdev); 108 | 109 | return 0; 110 | } 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /fb7/Makefile: -------------------------------------------------------------------------------- 1 | objects = fbtool.o point.o line.o rectangle.o circle.o 2 | test : test.c $(objects) 3 | gcc test.c $(objects) -o test -lm 4 | fbtool.o : page.h color.h fbtool.h fbtool.c 5 | gcc -c page.h color.h fbtool.h fbtool.c 6 | point.o : fbtool.h point.h point.c 7 | gcc -c fbtool.h point.h point.c 8 | line.o : fbtool.h point.h line.h line.c 9 | gcc -c fbtool.h point.h line.h line.c 10 | rectangle.o : fbtool.h point.h line.h rectangle.h rectangle.c 11 | gcc -c fbtool.h point.h line.h rectangle.h rectangle.c 12 | circle.o : fbtool.h point.h circle.h circle.c 13 | gcc -c fbtool.h point.h circle.h circle.c -lm 14 | clean: 15 | rm *.o *.gch test 16 | -------------------------------------------------------------------------------- /fb7/README.md: -------------------------------------------------------------------------------- 1 | **(一):写在前面** 2 | 3 | 这一次没有进行功能上的改进,主要是为了后来修改方便,而将画点,画线,画长方形,画圆等的提取出来,对Makefile进行了修改,方便于后期的维护.同时,为了后面实现我的思路,我进行了一个测试,就是实现一个运动的圆的效果.圆是可以运动了,但是效果不是特别好.后面再了解一下图形化界面是怎么实现的.我再试一下别的思路. 4 | 5 | 6 | **(二):功能介绍** 7 | 8 | *1:Makefile文件的修改* 9 | 10 | ``` 11 | objects = fbtool.o point.o line.o rectangle.o circle.o 12 | test : test.c $(objects) 13 | gcc test.c $(objects) -o test -lm 14 | fbtool.o : page.h color.h fbtool.h fbtool.c 15 | gcc -c page.h color.h fbtool.h fbtool.c 16 | point.o : fbtool.h point.h point.c 17 | gcc -c fbtool.h point.h point.c 18 | line.o : fbtool.h point.h line.h line.c 19 | gcc -c fbtool.h point.h line.h line.c 20 | rectangle.o : fbtool.h point.h line.h rectangle.h rectangle.c 21 | gcc -c fbtool.h point.h line.h rectangle.h rectangle.c 22 | circle.o : fbtool.h point.h circle.h circle.c 23 | gcc -c fbtool.h point.h circle.h circle.c -lm 24 | clean: 25 | rm *.o *.gch test 26 | ``` 27 | 28 | *2:测试实现圆的运动* 29 | 30 | ``` 31 | int x = 500; 32 | while(1){ 33 | draw_circle(&fbdev,x,400,100,RED); 34 | usleep(100); 35 | 36 | x++; 37 | 38 | if(x == 1200) 39 | break; 40 | 41 | clear_con(fbdev.fb_mem + fbdev.fb_mem_offset,1,fbdev.fb_fix.smem_len); 42 | 43 | } 44 | ``` 45 | 46 | 这次测试暂时是这样实现的,不过界面的刷新和图形的运动是在同时发生的,也就是说是同一个频率的.这样是不行的.就会出现闪频的问题.后面我将修改这个,初步思路是将界面刷新放到一个单独的线程当中,或者是根据时钟来刷新,这个后面再说吧. 47 | 48 | **(三):后期规划** 49 | 50 | 后面的话主要的想法就是先实现图形的刷新,让图形能够移动或者是使图形能够一直存在.完成这个之后,就是纯图形库的编写工作了. 51 | 52 | 53 | **(四):写在后面** 54 | 55 | 众里寻他千百度,蓦然回首,那人却在灯火阑珊处. 56 | 57 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /fb7/circle.c: -------------------------------------------------------------------------------- 1 | #include "circle.h" 2 | 3 | //画圆 4 | void draw_circle(PFBDEV pFbdev,int x,int y,int radius,const char *color) 5 | { 6 | double i; 7 | 8 | int tmp; 9 | 10 | for(i = x - radius; i < x + radius;i+=0.01){ 11 | tmp = sqrt(radius * radius - (i - x) * (i - x)); 12 | 13 | draw_x_y_color_dot_with_string(pFbdev,i,(tmp + y),color); 14 | draw_x_y_color_dot_with_string(pFbdev,i,(-tmp + y),color); 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /fb7/circle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 画圆或者是填充圆的实现 3 | * @作者 陈洪波 4 | */ 5 | 6 | #ifndef _CIRCLE_H_ 7 | #define _CIRCLE_H_ 8 | 9 | #include "fbtool.h" 10 | #include "point.h" 11 | #include 12 | 13 | /* 14 | * 画一个圆 15 | * @param pFbdev 参考结构体 fbdev 16 |  * @param x 圆的圆心所在的点的x值 17 | * @param y 圆的圆心所在的点的y值 18 | * @param radius 圆的半径的长度 19 | * @color 代表颜色的字符串 20 | * @return void 21 | */ 22 | void draw_circle(PFBDEV pFbdev,int x,int y,int radius,const char *color); 23 | 24 | #endif //_CIRCLE_H_ 25 | -------------------------------------------------------------------------------- /fb7/color.h: -------------------------------------------------------------------------------- 1 | #ifndef _COLOR_H_ 2 | #define _COLOR_H_ 3 | 4 | 5 | #include 6 | /** 7 | * 代表颜色的结构体 8 | * @property r 颜色对应的R值 9 | * @property g 颜色对应的G值 10 |  * @property b 颜色对应的B值 11 | * @property t 颜色对应的T值 12 | */ 13 | typedef struct rgbt{ 14 | uint8_t r; 15 | uint8_t g; 16 | uint8_t b; 17 | uint8_t t; 18 | }RGBT; 19 | 20 | //定义一些常用的颜色属性 21 | #define BLACK "00000000"  //黑色 22 | #define YELLOW "ffff0000" //黄色 23 | #define BLUE_LIGHT "B0E0E600" //淡蓝色 24 | #define YELLOW_BANANA "E3CF5700" //香蕉色 25 | #define BLUE_SKY "87CEEB00" //天蓝色 26 | #define ORIANGE "ff610000" //橙色 27 | #define GREEN "00ff0000" //绿色 28 | #define PURPLE "A020F000" //紫色 29 | #define RED "FF000000" //红色 30 | 31 | 32 | #endif //_COLOR_H_ 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /fb7/fbtool.c: -------------------------------------------------------------------------------- 1 | #include "fbtool.h" 2 | 3 | //打开并且初始化该frame buffer 4 | int fb_open(PFBDEV pFbdev) 5 | { 6 | //打开frame buffer 7 | pFbdev->fb = open(pFbdev->dev,O_RDWR); 8 | 9 | if(pFbdev->fb < 0) 10 | { 11 | printf("打开错误 %s.请检查内核配置\n",pFbdev->dev); 12 | return 0; 13 | } 14 | 15 | // 初始化fb_var 16 | if(-1 == ioctl(pFbdev->fb,FBIOGET_VSCREENINFO,&(pFbdev->fb_var))) 17 | { 18 | printf("ioctl FBIOGET_VSCREENINFO\n"); 19 | return 0; 20 | } 21 | 22 | // 初始化fb_fix 23 | if(-1 == ioctl(pFbdev->fb,FBIOGET_FSCREENINFO,&(pFbdev->fb_fix))) 24 | { 25 | printf("ioctl FBIOGET_FSCREENINFO\n"); 26 | return 0; 27 | } 28 | 29 | //将物理地址映射到虚拟地址 30 | pFbdev->fb_mem_offset = (unsigned long)pFbdev->fb_fix.smem_start & (~PAGE_MASK); 31 | 32 | pFbdev->fb_mem = (unsigned long int)mmap(NULL,pFbdev->fb_fix.smem_len + pFbdev->fb_mem_offset,PROT_READ|PROT_WRITE,MAP_SHARED,pFbdev->fb,0); 33 | 34 | if(-1L == (long)pFbdev->fb_mem){ 35 | printf("mmap error with mem:%lu,mem_offset:%lu\n",pFbdev->fb_mem_offset,pFbdev->fb_mem); 36 | return 0; 37 | } 38 | 39 | return 1; 40 | } 41 | 42 | //关闭frame buffer 43 | int fb_close(PFBDEV pFbdev) 44 | { 45 | int r = close(pFbdev->fb); 46 | pFbdev->fb = -1; 47 | 48 | return r; 49 | } 50 | 51 | //打印frame buffer 所占内存的开始地址  52 | void pmem_start(PFBDEV pFbdev) 53 | { 54 | printf("frame buffer所占内存的开始地址为:%lu\n",pFbdev->fb_fix.smem_start); 55 | } 56 | 57 | //打印FB_TYPE 58 | void p_type(PFBDEV pFbdev) 59 | { 60 | printf("frame buffer 的类型为:%d\n",pFbdev->fb_fix.type); 61 | } 62 | 63 | //打印可见清晰度 64 | void p_visible_res(PFBDEV pFbdev) 65 | { 66 | printf("frame buffer的可见清晰度为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres,pFbdev->fb_var.yres); 67 | } 68 | 69 | //打印虚拟分辨率 70 | void p_virt_res(PFBDEV pFbdev) 71 | { 72 | printf("frame buffer的虚拟清晰度为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xres_virtual,pFbdev->fb_var.yres_virtual); 73 | } 74 | 75 | //打印虚拟到可见的偏移量 76 | void p_offset(PFBDEV pFbdev) 77 | { 78 | printf("frame buffer的虚拟分辨率到可见分辨率的偏移量为:\n\tx = %d\n\ty = %d\n",pFbdev->fb_var.xoffset,pFbdev->fb_var.yoffset); 79 | } 80 | 81 | //打印每个像素的位数 82 | void p_bpp(PFBDEV pFbdev) 83 | { 84 | printf("frame buffer的BPP为:%d\n",pFbdev->fb_var.bits_per_pixel); 85 | } 86 | 87 | //打印R,G,B和透明度 88 | void p_rgbt(PFBDEV pFbdev) 89 | { 90 | //R位域 91 | printf("R位域:\n"); 92 | struct fb_bitfield bf = pFbdev->fb_var.red; 93 | printf("\t开始:%d\n",bf.offset); 94 | printf("\t长度:%d\n",bf.length); 95 | printf("\tMSB:%d\n",bf.msb_right); 96 | 97 | //G位域 98 | printf("G位域:\n"); 99 | bf = pFbdev->fb_var.green; 100 | printf("\t开始:%d\n",bf.offset); 101 | printf("\t长度:%d\n",bf.length); 102 | printf("\tMSB:%d\n",bf.msb_right); 103 | 104 | // B位域 105 | printf("B位域:\n"); 106 | bf = pFbdev->fb_var.blue; 107 | printf("\t开始:%d\n",bf.offset); 108 | printf("\t长度:%d\n",bf.length); 109 | printf("\tMSB:%d\n",bf.msb_right); 110 | 111 | // 透明度位域 112 | printf("透明度位域:\n"); 113 | bf = pFbdev->fb_var.transp; 114 | printf("\t开始:%d\n",bf.offset); 115 | printf("\t长度:%d\n",bf.length); 116 | printf("\tMSB:%d\n",bf.msb_right); 117 | } 118 | 119 | //打印在内存中的高度和宽度 120 | void p_hw(PFBDEV pFbdev) 121 | { 122 | printf("frame buffer在内存中所占的高度和宽度分别是:\n\t宽度 = %d\n\t高度 = %d\n",pFbdev->fb_var.height,pFbdev->fb_var.width); 123 | } 124 | 125 | //清空控制台  126 | void clear_con(void *addr,int n,size_t len) 127 | { 128 | memset(addr,n,len); 129 | } 130 | 131 | //映射到内存 132 | void fb_memcpy(void *addr,void *color,size_t len) 133 | { 134 | memcpy(addr,color,len); 135 | } 136 | 137 | RGBT getRGBT(const char *temp){ 138 | RGBT rgbt; 139 | 140 | char *c_tmp; 141 | c_tmp = (char *)malloc(4 * sizeof(int)); 142 | 143 | c_tmp[0] = '0'; 144 | c_tmp[1] = 'x'; 145 | int r,g,b,t; 146 | 147 | //RGBT值的计算 148 | c_tmp[2] = temp[0]; 149 | c_tmp[3] = temp[1]; 150 | 151 | r = strtol(c_tmp,NULL,16); 152 | 153 | c_tmp[2] = temp[2]; 154 | c_tmp[3] = temp[3]; 155 | 156 | g = strtol(c_tmp,NULL,16); 157 | 158 | c_tmp[2] = temp[4]; 159 | c_tmp[3] = temp[5]; 160 | 161 | b = strtol(c_tmp,NULL,16); 162 | 163 | c_tmp[2] = temp[6]; 164 | c_tmp[3] = temp[7]; 165 | 166 | t = strtol(c_tmp,NULL,16); 167 | 168 | rgbt.r = r; 169 | rgbt.g = g; 170 | rgbt.b = b; 171 | rgbt.t = t; 172 | 173 | return rgbt; 174 | } 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /fb7/fbtool.h: -------------------------------------------------------------------------------- 1 | #ifndef __FBTOOL_H_ 2 | #define __FBTOOL_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "page.h" 14 | #include "color.h" 15 | 16 | /** 17 | * 该结构体主要是定义了一组保存frame buffer的属性 18 | * @property fb frame buffer打开后的唯一标识符 19 | * @property fb_fix frame buffer的固定属性就保存在这个结构体中 20 | * @property fb_var frame buffer的可变属性保存在这个结构体中 21 | * @property fb_mem_offset frame buffer所占内存的偏移量 22 | * @property fb_mem frame buffer的映射到进程内存空间的起始地址 23 | */ 24 | typedef struct fbdev{ 25 | int fb; 26 | struct fb_fix_screeninfo fb_fix; 27 | struct fb_var_screeninfo fb_var; 28 | /* 新增 */ 29 | unsigned long fb_mem_offset; 30 | unsigned long fb_mem; 31 | 32 | char dev[20]; 33 | }FBDEV,*PFBDEV; 34 | 35 | /** 36 | * 该结构体用于定位点的位置,包括横坐标,纵坐标,深坐标 37 | * @property x 横坐标 38 | * @property y 纵坐标 39 | * @property z 深坐标(这个用于3D) 40 | */ 41 | typedef struct point{ 42 | int x; 43 | int y; 44 | int z; 45 | }POINT,*PPOINT; 46 | 47 | /* 48 | * 该函数用于打开frame buffer 49 | * @param pFbdev 参照结构体 fbdev 50 | * @return 0 - 打开失败 51 |  * 1 - 打开成功 52 | */ 53 | int fb_open(PFBDEV pFbdev); 54 | 55 | /* 56 | * 该函数用于关闭frame buffer设备 57 | * @param pFbdev 参照结构体 fbdev 58 | * @return 0 - 关闭成功 59 | * >0 - 关闭失败 60 | */ 61 | int fb_close(PFBDEV pFbdev); 62 | 63 | /* 64 | * 该函数用于打印frame buffer 所占内存的开始地址  65 | * @param pFbdev 参照结构体 fbdev 66 | * @return void 67 | */ 68 | void pmem_start(PFBDEV pFbdev); 69 | 70 | /* 71 | * 该函数用于打印FB_TYPE 72 | * @param pFbdev 参照结构体 fbdev 73 | * @return void 74 | */ 75 | void p_type(PFBDEV pFbdev); 76 | 77 | /* 78 | * 该函数用于打印可见清晰度 79 | * @param pFbdev 参照结构体 fbdev 80 | * @return void 81 | */ 82 | void p_visible_res(PFBDEV pFbdev); 83 | 84 | /* 85 | * 该函数用于打印虚拟分辨率 86 | * @param pFbdev 参照结构体 fbdev 87 | * @return void 88 | */ 89 | void p_virt_res(PFBDEV pFbdev); 90 | 91 | /* 92 | * 该函数用于打印虚拟到可见的偏移量 93 | * @param pFbdev 参照结构体 fbdev 94 | * @return void 95 | */ 96 | void p_offset(PFBDEV pFbdev); 97 | 98 | /* 99 | * 该函数用于打印每个像素的位数 100 | * @param pFbdev 参照结构体 fbdev 101 | * @return void 102 | */ 103 | void p_bpp(PFBDEV pFbdev); 104 | 105 | /* 106 | * 该函数用于打印R,G,B和透明度 107 | * @param pFbdev 参照结构体 fbdev 108 | * @return void 109 | */ 110 | void p_rgbt(PFBDEV pFbdev); 111 | 112 | /* 113 | * 该函数用于打印在内存中的高度和宽度 114 | * @param pFbdev 参照结构体 fbdev 115 | * @return void 116 | */ 117 | void p_hw(PFBDEV pFbdev); 118 | 119 | /* 120 | * 将addr开始的len个字符用n替换 121 | * @param addr 开始的地址 122 | * @param n 替换后的字符 123 | * @param len 要替换的字符的个数 124 | * @return void 125 | */ 126 | void clear_con(void *addr,int n,size_t len); 127 | 128 | /* 129 | * 该函数将逻辑地址空间的数据映射到内存当中 130 | * @param addr 内存空间的地址 131 | * @param color 颜色值 132 | * @param len 需要映射的长度 133 |  * @return void 134 | */ 135 | void fb_memcpy(void *addr,void *color,size_t len); 136 | 137 | 138 | 139 | 140 | /* 141 | * 根据字符串获得相应的RGBT 142 | * @param color 颜色对应的字符串 143 | * @return 返回代表颜色的结构体 RGBT 144 | */ 145 | RGBT getRGBT(const char *color); 146 | 147 | 148 | 149 | #endif 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /fb7/line.c: -------------------------------------------------------------------------------- 1 | #include "line.h" 2 | 3 | //画横线 4 | void draw_h_line(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b) 5 | { 6 | int m; 7 | 8 | int length = maxX.x - minX.x; 9 | for(m = 0;m < length;m++){ 10 | POINT tp; 11 | tp.x = minX.x + m; 12 | tp.y = minX.y; 13 | 14 | draw_dot(pFbdev,tp,r,g,b); 15 | } 16 | } 17 | 18 | void draw_h_line_with_trans(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b,uint8_t t){ 19 | int m; 20 | 21 | int length = maxX.x - minX.x; 22 | for(m = 0;m < length;m++){ 23 | POINT tp; 24 | tp.x = minX.x + m; 25 | tp.y = minX.y; 26 | 27 | draw_dot_with_trans(pFbdev,tp,r,g,b,t); 28 | } 29 | } 30 | 31 | //画竖线 32 | void draw_v_line(PFBDEV pFbdev,POINT minY,POINT maxY,uint8_t r,uint8_t g,uint8_t b) 33 | { 34 | int m; 35 | 36 | int length = maxY.y - minY.y; 37 | for(m = 0;m < length;m++){ 38 | POINT tp; 39 | tp.x = minY.x; 40 | tp.y = minY.y + m; 41 | 42 | draw_dot(pFbdev,tp,r,g,b); 43 | } 44 | } 45 | 46 | //划横线 47 | void draw_h_line_with_string(PFBDEV pFbdev,POINT minX,POINT maxX,const char *color) 48 | { 49 | RGBT rgbt = getRGBT(color); 50 | 51 | draw_h_line_with_trans(pFbdev,minX,maxX,rgbt.r,rgbt.g,rgbt.b,rgbt.t); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /fb7/line.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 画线的实现 3 | * @作者 陈洪波 4 | */ 5 | 6 | #ifndef _LINE_H_ 7 | #define _LINE_H_ 8 | 9 | #include "fbtool.h" 10 | #include "point.h" 11 | 12 | /* 13 | * 指定x值较小的点和x值较大的点,并指定颜色的rgb值画一条横线 14 | * @param pFbdev 参考结构体 fbdev 15 | * @param minX x较小的点 16 | * @param maxX x较大的点 17 |  * @param r 颜色对应的R值 18 | * @param g 颜色对应的G值 19 | * @param b 颜色对应的B值 20 | * @return void 21 | */ 22 | void draw_h_line(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b); 23 | 24 | /* 25 | * 指定x值较小的点和x值较大的点,并指定颜色的rgb值和透明度画一条横线 26 | * @param pFbdev 参考结构体 fbdev 27 | * @param minX x较小的点 28 | * @param maxX x较大的点 29 |  * @param r 颜色对应的R值 30 | * @param g 颜色对应的G值 31 | * @param b 颜色对应的B值 32 |  * @param t 颜色对应的透明度 33 | * @return void 34 | * 35 | */ 36 | void draw_h_line_with_trans(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b,uint8_t t); 37 | 38 | /* 39 | * 使用字符串作为颜色的表示来画一条横线 40 | * @param pFbdev 参考结构体 fbdev 41 | * @param minX x较小的点 42 | * @param maxX x较大的点 43 | * @param color 颜色所对应的字符串 44 | * @return void 45 | */ 46 | void draw_h_line_with_string(PFBDEV pFbdev,POINT minX,POINT maxX,const char *color); 47 | 48 | /* 49 | * 指明y最小的一个点和一个y较大的点,并指明RGB值画一条竖线 50 | * @param pFbdev 参考结构体 fbdev 51 | * @param minY y较小的点 52 | * @param maxY y较大的点 53 |  * @param r 颜色对应的R值 54 | * @param g 颜色对应的G值 55 | * @param b 颜色对应的B值 56 | */ 57 | void draw_v_line(PFBDEV pFbdev,POINT minY,POINT maxY,uint8_t r,uint8_t g,uint8_t b); 58 | 59 | 60 | #endif //_LINE_H_ 61 | -------------------------------------------------------------------------------- /fb7/page.h: -------------------------------------------------------------------------------- 1 | #ifndef _I386_PAGE_H 2 | #define _I386_PAGE_H 3 | /* PAGE_SHIFT determines the page size */ 4 | #define PAGE_SHIFT 12 5 | #define PAGE_SIZE (1UL << PAGE_SHIFT) 6 | #define PAGE_MASK (~(PAGE_SIZE-1)) 7 | #define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1)) 8 | #define LARGE_PAGE_SIZE (1UL << PMD_SHIFT) 9 | #ifdef __KERNEL__ 10 | #ifndef __ASSEMBLY__ 11 | #include 12 | #ifdef CONFIG_X86_USE_3DNOW 13 | #include 14 | #define clear_page(page) mmx_clear_page((void *)(page)) 15 | #define copy_page(to,from) mmx_copy_page(to,from) 16 | #else 17 | /* 18 | * On older X86 processors it's not a win to use MMX here it seems. 19 | * Maybe the K6-III ? 20 | */ 21 | #define clear_page(page) memset((void *)(page), 0, PAGE_SIZE) 22 | #define copy_page(to,from) memcpy((void *)(to), (void *)(from), PAGE_SIZE) 23 | #endif 24 | #define clear_user_page(page, vaddr, pg) clear_page(page) 25 | #define copy_user_page(to, from, vaddr, pg) copy_page(to, from) 26 | /* 27 | * These are used to make use of C type-checking.. 28 | */ 29 | #ifdef CONFIG_X86_PAE 30 | typedef struct { unsigned long pte_low, pte_high; } pte_t; 31 | typedef struct { unsigned long long pmd; } pmd_t; 32 | typedef struct { unsigned long long pgd; } pgd_t; 33 | #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32)) 34 | #define HPAGE_SHIFT 21 35 | #else 36 | typedef struct { unsigned long pte_low; } pte_t; 37 | typedef struct { unsigned long pmd; } pmd_t; 38 | typedef struct { unsigned long pgd; } pgd_t; 39 | #define boot_pte_t pte_t /* or would you rather have a typedef */ 40 | #define pte_val(x) ((x).pte_low) 41 | #define HPAGE_SHIFT 22 42 | #endif 43 | #define PTE_MASK PAGE_MASK 44 | #ifdef CONFIG_HUGETLB_PAGE 45 | #define HPAGE_SIZE ((1UL) << HPAGE_SHIFT) 46 | #define HPAGE_MASK (~(HPAGE_SIZE - 1)) 47 | #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT) 48 | #endif 49 | typedef struct { unsigned long pgprot; } pgprot_t; 50 | #define pmd_val(x) ((x).pmd) 51 | #define pgd_val(x) ((x).pgd) 52 | #define pgprot_val(x) ((x).pgprot) 53 | #define __pte(x) ((pte_t) { (x) } ) 54 | #define __pmd(x) ((pmd_t) { (x) } ) 55 | #define __pgd(x) ((pgd_t) { (x) } ) 56 | #define __pgprot(x) ((pgprot_t) { (x) } ) 57 | #endif /* !__ASSEMBLY__ */ 58 | /* to align the pointer to the (next) page boundary */ 59 | #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) 60 | /* 61 | * This handles the memory map.. We could make this a config 62 | * option, but too many people screw it up, and too few need 63 | * it. 64 | * 65 | * A __PAGE_OFFSET of 0xC0000000 means that the kernel has 66 | * a virtual address space of one gigabyte, which limits the 67 | * amount of physical memory you can use to about 950MB. 68 | * 69 | * If you want more physical memory than this then see the CONFIG_HIGHMEM4G 70 | * and CONFIG_HIGHMEM64G options in the kernel configuration. 71 | */ 72 | /* 73 | * This much address space is reserved for vmalloc() and iomap() 74 | * as well as fixmap mappings. 75 | */ 76 | #define __VMALLOC_RESERVE (128 << 20) 77 | #ifndef __ASSEMBLY__ 78 | /* Pure 2^n version of get_order */ 79 | static __inline__ int get_order(unsigned long size) 80 | { 81 | int order; 82 | size = (size-1) >> (PAGE_SHIFT-1); 83 | order = -1; 84 | do { 85 | size >>= 1; 86 | order++; 87 | } while (size); 88 | return order; 89 | } 90 | #endif /* __ASSEMBLY__ */ 91 | #ifdef __ASSEMBLY__ 92 | #define __PAGE_OFFSET (0xC0000000) 93 | #else 94 | #define __PAGE_OFFSET (0xC0000000UL) 95 | #endif 96 | #define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET) 97 | #define VMALLOC_RESERVE ((unsigned long)__VMALLOC_RESERVE) 98 | #define MAXMEM (-__PAGE_OFFSET-__VMALLOC_RESERVE) 99 | #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) 100 | #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET)) 101 | #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) 102 | #ifndef CONFIG_DISCONTIGMEM 103 | #define pfn_to_page(pfn) (mem_map + (pfn)) 104 | #define page_to_pfn(page) ((unsigned long)((page) - mem_map)) 105 | #define pfn_valid(pfn) ((pfn) < max_mapnr) 106 | #endif /* !CONFIG_DISCONTIGMEM */ 107 | #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) 108 | #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) 109 | #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | / 110 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) 111 | #endif /* __KERNEL__ */ 112 | #endif /* _I386_PAGE_H */ 113 | -------------------------------------------------------------------------------- /fb7/point.c: -------------------------------------------------------------------------------- 1 | #include "point.h" 2 | 3 | //画点 4 | void draw_dot(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b) 5 | { 6 | uint32_t offset; 7 | uint8_t color[4]; 8 | color[0] = b; 9 | color[1] = g; 10 | color[2] = r; 11 | color[3] = 0x0; //透明度 12 | 13 | offset = p.y * pFbdev->fb_fix.line_length + 4 * p.x; 14 | //将操作映射到内存中 15 | fb_memcpy((void*)pFbdev->fb_mem + pFbdev->fb_mem_offset + offset,color,4); 16 | } 17 | 18 | //画点 19 | void draw_dot_with_trans(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b,uint8_t t) 20 | { 21 | uint32_t offset; 22 | uint8_t color[4]; 23 | color[0] = b; 24 | color[1] = g; 25 | color[2] = r; 26 | color[3] = t; //透明度 27 | 28 | offset = p.y * pFbdev->fb_fix.line_length + 4 * p.x; 29 | //将操作映射到内存中 30 | fb_memcpy((void*)pFbdev->fb_mem + pFbdev->fb_mem_offset + offset,color,4); 31 | } 32 | 33 | //画点 34 | void draw_x_y_dot(PFBDEV pFbdev,int x,int y,uint8_t r,uint8_t g,uint8_t b) 35 | { 36 | POINT p; 37 | p.x = x; 38 | p.y = y; 39 | 40 | draw_dot(pFbdev,p,r,g,b); 41 | } 42 | 43 | //画点 44 | void draw_x_y_dot_with_trans(PFBDEV pFbdev,int x,int y,uint8_t r,uint8_t g,uint8_t b,uint8_t t) 45 | { 46 | POINT p; 47 | p.x = x; 48 | p.y = y; 49 | 50 | draw_dot_with_trans(pFbdev,p,r,g,b,t); 51 | } 52 | 53 | //画点 54 | void draw_x_y_color_dot(PFBDEV pFbdev,int x,int y,RGBT c) 55 | { 56 | draw_x_y_dot(pFbdev,x,y,c.r,c.g,c.b); 57 | } 58 | 59 | //画点 60 | void draw_x_y_color_dot_with_trans(PFBDEV pFbdev,int x,int y,RGBT c) 61 | { 62 | draw_x_y_dot_with_trans(pFbdev,x,y,c.r,c.g,c.b,c.t); 63 | } 64 | 65 | //画点 color8位,分别代表RGBT 66 | void draw_x_y_color_dot_with_string(PFBDEV pFbdev,int x,int y,const char *temp) 67 | { 68 | RGBT rgbt = getRGBT(temp); 69 | 70 | draw_x_y_dot_with_trans(pFbdev,x,y,rgbt.r,rgbt.g,rgbt.b,rgbt.t); 71 | } 72 | 73 | -------------------------------------------------------------------------------- /fb7/point.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 画点实现 3 | * @作者 陈洪波 4 | */ 5 | 6 | #ifndef _POINT_H_ 7 | #define _POINT_H_ 8 | 9 | #include "fbtool.h" 10 | 11 | /* 12 | * 该函数用于在命令行中画点 13 | * @param pFbdev 参考结构体 fbdev 14 | * @param p 点的坐标 15 | * @param r 颜色对应的R值 16 |  * @param g 颜色对应的G值 17 | * @param b 颜色对应的B值 18 | * @return void 19 | */ 20 | void draw_dot(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b); 21 | 22 | /* 23 | * 该函数用于实现画点,不过在这个函数中需要设定透明度参数 24 | * @param pFbdev 参考结构体 fbdev 25 | * @param p 点的坐标 26 | * @param r 颜色对应的R值 27 |  * @param g 颜色对应的G值 28 | * @param b 颜色对应的B值 29 |  * @param t 颜色对应的透明度值 30 | * @return void 31 | */ 32 | void draw_dot_with_trans(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b,uint8_t t); 33 | 34 | /* 35 | * 该函数用于指定点的横坐标,纵坐标的值来画点 36 | * @param pFbdev 参考结构体 fbdev 37 | * @param x 点的坐标对应的横坐标的值 38 | * @param y 点的坐标对应的纵坐标的值 39 | * @param r 颜色对应的R值 40 |  * @param g 颜色对应的G值 41 | * @param b 颜色对应的B值 42 | */ 43 | void draw_x_y_dot(PFBDEV pFbdev,int x,int y,uint8_t r,uint8_t g,uint8_t b); 44 | 45 | /* 46 | * 该函数用于指定点的横坐标,纵坐标的值,并且必须指明透明度来画点 47 | * @param pFbdev 参考结构体 fbdev 48 | * @param x 点的坐标对应的横坐标的值 49 | * @param y 点的坐标对应的纵坐标的值 50 | * @param r 颜色对应的R值 51 |  * @param g 颜色对应的G值 52 | * @param b 颜色对应的B值 53 |  * @param t 颜色对应的透明度值 54 | */ 55 | void draw_x_y_dot_with_trans(PFBDEV pFbdev,int x,int y,uint8_t r,uint8_t g,uint8_t b,uint8_t t); 56 | 57 | /* 58 | * 该函数指定点的横纵坐标,然后使用结构体rgbt来代替颜色来画点 59 | * @param pFbdev 参考结构体 fbdev 60 | * @param x 点的坐标对应的横坐标的值 61 | * @param y 点的坐标对应的纵坐标的值 62 | * @param c 用来代表颜色的结构体 63 | * @return void 64 | * 65 | */ 66 | void draw_x_y_color_dot(PFBDEV pFbdev,int x,int y,RGBT c); 67 | 68 | /* 69 | * 该函数指定点的横纵坐标,然后使用结构体rgbt来代替颜色来画点,不过在这里指明透明度是有效果 70 | * @param pFbdev 参考结构体 fbdev 71 | * @param x 点的坐标对应的横坐标的值 72 | * @param y 点的坐标对应的纵坐标的值 73 | * @param c 用来代表颜色的结构体 74 | * @return void 75 | * 76 | */ 77 | void draw_x_y_color_dot_with_trans(PFBDEV pFbdev,int x,int y,RGBT c); 78 | 79 | /* 80 | * 该函数指定点的横纵坐标,然后使用八位的字符串来指明颜色来画点 81 |  * 注意:这里的字符串里面都是16进制的数值,例如,"ffff0000" 82 | * 83 | * @param pFbdev 参考结构体 fbdev 84 | * @param x 点的坐标对应的横坐标的值 85 | * @param y 点的坐标对应的纵坐标的值 86 | * @param c 用来代表颜色的结构体 87 | * @param color 用来指明颜色的字符串 88 | * @return void 89 | * 90 | */ 91 | void draw_x_y_color_dot_with_string(PFBDEV pFbdev,int x,int y,const char *color); 92 | 93 | #endif //_POINT_H_ 94 | 95 | 96 | -------------------------------------------------------------------------------- /fb7/rectangle.c: -------------------------------------------------------------------------------- 1 | #include "rectangle.h" 2 | 3 | //画一个矩形框 4 | void draw_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b) 5 | { 6 | draw_h_line(pFbdev,lu,ru,r,g,b); 7 | draw_h_line(pFbdev,ld,rd,r,g,b); 8 | draw_v_line(pFbdev,lu,ld,r,g,b); 9 | draw_v_line(pFbdev,ru,rd,r,g,b); 10 | } 11 | 12 | //填充一个矩形框 13 | void fill_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b) 14 | { 15 | int xlen = ru.x - lu.x; 16 | int ylen = ld.y - lu.y; 17 | 18 | int m,n; 19 | 20 | for(m = 0;m < ylen;m++){ 21 | for(n = 0;n < xlen;n++){ 22 | POINT p; 23 | p.x = lu.x + n; 24 | p.y = lu.y + m; 25 | 26 | draw_dot(pFbdev,p,r,g,b); 27 | } 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /fb7/rectangle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 实现画矩形或者是填充矩形 3 | * @作者 陈洪波 4 | */ 5 | 6 | #ifndef _RECTANGLE_H_ 7 | #define _RECTANGLE_H_ 8 | 9 | #include "fbtool.h" 10 | #include "point.h" 11 | #include "line.h" 12 | 13 | /* 14 | * 画一个矩形框 15 | * @param pFbdev 参考结构体 fbdev 16 | * @param lu 矩形框左上角的点 17 | * @param ld 矩形框左下角的点 18 |  * @param ru 矩形框右上角的点 19 | * @param rd 矩形框右下角的点 20 | * @param r 颜色对应的R值 21 | * @param g 颜色对应的G值 22 | * @param b 颜色对应的B值 23 |  * @return void 24 | */ 25 | void draw_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b); 26 | 27 | /* 28 | * 填充一个矩形框 29 | * @param pFbdev 参考结构体 fbdev 30 | * @param lu 矩形框左上角的点 31 | * @param ld 矩形框左下角的点 32 |  * @param ru 矩形框右上角的点 33 | * @param rd 矩形框右下角的点 34 | * @param r 颜色对应的R值 35 | * @param g 颜色对应的G值 36 | * @param b 颜色对应的B值 37 |  * @return void 38 | */ 39 | void fill_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b); 40 | 41 | 42 | 43 | #endif //_RECTANGLE_H_ 44 | 45 | -------------------------------------------------------------------------------- /fb7/test.c: -------------------------------------------------------------------------------- 1 | #include "line.h" 2 | #include "point.h" 3 | #include "rectangle.h" 4 | #include "circle.h" 5 | 6 | int main() 7 | { 8 | FBDEV fbdev; 9 | 10 | memset(&fbdev,0,sizeof(FBDEV)); 11 | strcpy(fbdev.dev,"/dev/fb0"); 12 | 13 | if(0 == fb_open(&fbdev)){ 14 | printf("Open fail!!\n"); 15 | return -1; 16 | } 17 | 18 | /** 19 | //打印frame buffer 所占内存的开始地址  20 | pmem_start(&fbdev); 21 | //打印FB_TYPE-c kbd.c 22 | p_type(&fbdev); 23 | //打印可见清晰度 24 | p_visible_res(&fbdev); 25 | //打印虚拟分辨率 26 | p_virt_res(&fbdev); 27 | //打印虚拟到可见的偏移量 28 | p_offset(&fbdev); 29 | //打印每个像素的位数 30 | p_bpp(&fbdev); 31 | //打印R,G,B和透明度 32 | p_rgbt(&fbdev); 33 | //打印在内存中的高度和宽度 34 | p_hw(&fbdev); 35 | //打印fb的RGB和透明度的位域 36 | p_rgbt(&fbdev); 37 | 38 | getchar(); 39 | 40 | //清屏 41 | clear_con(fbdev.fb_mem + fbdev.fb_mem_offset,-1,fbdev.fb_fix.smem_len); */ 42 | 43 | 44 | POINT p; 45 | p.x = 100; 46 | p.y = 100; 47 | 48 | /* 49 | //画点 50 | draw_x_y_dot(&fbdev,100,100,0x0,0xff,0x0); 51 | 52 | RGBT c; 53 | c.r = 0xff; 54 | c.g = 0xff; 55 | c.b = 0xff; 56 | c.t = 0x00; 57 | //draw_x_y_color_dot_with_trans(&fbdev,100,100,RED); 58 | draw_x_y_color_dot_with_string(&fbdev,100,100,YELLOW); 59 | 60 | //划横线 61 | //画横线 62 | POINT p21; 63 | p21.x = 120; 64 | p21.y = 100; 65 | POINT p2; 66 | p2.x = 160; 67 | p2.y = 160; 68 | //draw_h_line(&fbdev,p21,p2,0x0,0xff,0x0); 69 | draw_h_line_with_string(&fbdev,p21,p2,RED); 70 | 71 | //画竖线 72 | POINT p31; 73 | p31.x = 100; 74 | p31.y = 120; 75 | POINT p3; 76 | p3.x = 100; 77 | p3.y = 160; 78 | draw_v_line(&fbdev,p31,p3,0x0,0xff,0x0); 79 | 80 | POINT p40; 81 | p40.x = 120; 82 | p40.y = 120; 83 | POINT p41; 84 | p41.x = 160; 85 | p41.y = 120; 86 | POINT p42; 87 | p42.x = 120; 88 | p42.y = 160; 89 | POINT p43; 90 | p43.x = 160; 91 | p43.y = 160; 92 | //画矩形 93 | draw_rec(&fbdev,p40,p42,p41,p43,0x0,0xff,0x0); 94 | 95 | POINT p50; 96 | p50.x = 100; 97 | p50.y = 180; 98 | POINT p51; 99 | p51.x = 160; 100 | p51.y = 180; 101 | POINT p52; 102 | p52.x = 100; 103 | p52.y = 220; 104 | POINT p53; 105 | p53.x = 160; 106 | p53.y = 220; 107 | //填充 108 | fill_rec(&fbdev,p50,p52,p51,p53,0x0,0xff,0x0);*/ 109 | 110 | int x = 500; 111 | while(1){ 112 | draw_circle(&fbdev,x,400,100,RED); 113 | usleep(100); 114 | 115 | x++; 116 | 117 | if(x == 1200) 118 | break; 119 | 120 | clear_con(fbdev.fb_mem + fbdev.fb_mem_offset,1,fbdev.fb_fix.smem_len); 121 | 122 | } 123 | 124 | fb_close(&fbdev); 125 | 126 | return 0; 127 | } 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /fb7/video.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongbochen/fb/57e26b8fca539db14184df71466e6a5a070db9a8/fb7/video.mp4 --------------------------------------------------------------------------------