github.com/jspc/eggos@v0.5.1-0.20221028160421-556c75c878a5/drivers/vbe/fb.go (about) 1 package vbe 2 3 import ( 4 "image" 5 "unsafe" 6 7 "github.com/jspc/eggos/drivers/multiboot" 8 "github.com/jspc/eggos/drivers/uart" 9 "github.com/jspc/eggos/kernel/mm" 10 ) 11 12 const bootloaderMagic = 0x2BADB002 13 14 type framebufferInfo struct { 15 Addr uint64 16 Pitch uint32 17 Width uint32 18 Height uint32 19 } 20 21 var ( 22 info framebufferInfo 23 buffer []uint8 24 fbbuf []uint8 25 26 DefaultView *View 27 currentView *View 28 ) 29 30 func bufcopy(dst, src []uint8, stride int, rect image.Rectangle, op func([]uint8, []uint8)) { 31 miny := rect.Min.Y 32 maxy := rect.Max.Y 33 minx := rect.Min.X * 4 34 maxx := rect.Max.X * 4 35 for j := miny; j < maxy; j++ { 36 srcline := src[j*stride : (j+1)*stride] 37 dstline := dst[j*stride : (j+1)*stride] 38 op(dstline[minx:maxx], srcline[minx:maxx]) 39 } 40 } 41 42 func SaveCurrView() *View { 43 return currentView 44 } 45 46 func SetCurrView(v *View) { 47 currentView = v 48 v.Commit() 49 } 50 51 func IsEnable() bool { 52 return fbbuf != nil 53 } 54 55 func Init() { 56 bootInfo := &multiboot.BootInfo 57 if bootInfo.Flags&multiboot.FlagInfoVideoInfo == 0 { 58 uart.WriteString("[video] can't found video info from bootloader, video disabled\n") 59 return 60 } 61 if bootInfo.FramebufferType != 1 { 62 uart.WriteString("[video] framebuffer only support RGB color\n") 63 return 64 } 65 if bootInfo.FramebufferBPP != 32 { 66 uart.WriteString("[video] framebuffer only support 32 bit color\n") 67 return 68 } 69 70 info = framebufferInfo{ 71 Addr: bootInfo.FramebufferAddr, 72 Width: bootInfo.FramebufferWidth, 73 Height: bootInfo.FramebufferHeight, 74 Pitch: bootInfo.FramebufferPitch, 75 } 76 77 mm.SysFixedMmap(uintptr(info.Addr), uintptr(info.Addr), uintptr(info.Width*info.Height*4)) 78 fbbuf = (*[10 << 20]uint8)(unsafe.Pointer(uintptr(info.Addr)))[:info.Width*info.Height*4] 79 buffer = make([]uint8, len(fbbuf)) 80 DefaultView = NewView() 81 currentView = DefaultView 82 }