add init arg

This commit is contained in:
Jay 2019-12-10 08:06:54 +00:00
parent 169b79d0cb
commit 02dd5bac3d
2 changed files with 15 additions and 9 deletions

View File

@ -32,6 +32,7 @@ import (
"unsafe" "unsafe"
) )
// Framebuffer -
type Framebuffer struct { type Framebuffer struct {
Fd int Fd int
BitsPerPixel int BitsPerPixel int
@ -44,6 +45,7 @@ type Framebuffer struct {
Screensize int Screensize int
} }
// NewFramebuffer -
func NewFramebuffer() *Framebuffer { func NewFramebuffer() *Framebuffer {
return &Framebuffer{} return &Framebuffer{}
} }
@ -57,9 +59,13 @@ func _ShowCursor() {
fmt.Printf("\033[?25h") fmt.Printf("\033[?25h")
} }
func (f *Framebuffer) Init() { // Init -
func (f *Framebuffer) Init(dev string) {
if len(dev) == 0 {
dev = "/dev/fb0"
}
_HideCursor() _HideCursor()
dev_file := C.CString("/dev/fb0") dev_file := C.CString(dev)
fd, err := C.OpenFrameBuffer(dev_file) fd, err := C.OpenFrameBuffer(dev_file)
C.free(unsafe.Pointer(dev_file)) C.free(unsafe.Pointer(dev_file))

View File

@ -10,7 +10,7 @@ import (
func BenchmarkFill(b *testing.B) { func BenchmarkFill(b *testing.B) {
fb := NewFramebuffer() fb := NewFramebuffer()
fb.Init() fb.Init("")
defer fb.Release() defer fb.Release()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
@ -39,7 +39,7 @@ func BenchmarkMakeSurfaceImage(b *testing.B) {
func BenchmarkDrawImage(b *testing.B) { func BenchmarkDrawImage(b *testing.B) {
fb := NewFramebuffer() fb := NewFramebuffer()
fb.Init() fb.Init("")
defer fb.Release() defer fb.Release()
image := image.NewRGBA(image.Rect(0, 0, fb.Xres, fb.Yres)) image := image.NewRGBA(image.Rect(0, 0, fb.Xres, fb.Yres))
@ -53,7 +53,7 @@ func BenchmarkDrawImage(b *testing.B) {
func BenchmarkCairoGetData(b *testing.B) { func BenchmarkCairoGetData(b *testing.B) {
fb := NewFramebuffer() fb := NewFramebuffer()
fb.Init() fb.Init("")
defer fb.Release() defer fb.Release()
surface := cairo.NewSurface(cairo.FORMAT_ARGB32, fb.Xres, fb.Yres) surface := cairo.NewSurface(cairo.FORMAT_ARGB32, fb.Xres, fb.Yres)
@ -68,7 +68,7 @@ func BenchmarkCairoGetData(b *testing.B) {
func BenchmarkDrawData(b *testing.B) { func BenchmarkDrawData(b *testing.B) {
fb := NewFramebuffer() fb := NewFramebuffer()
fb.Init() fb.Init("")
defer fb.Release() defer fb.Release()
data := make([]byte, fb.Xres*fb.Yres*4, fb.Xres*fb.Yres*4) data := make([]byte, fb.Xres*fb.Yres*4, fb.Xres*fb.Yres*4)
@ -81,7 +81,7 @@ func BenchmarkDrawData(b *testing.B) {
func BenchmarkCopyDataByLine(b *testing.B) { func BenchmarkCopyDataByLine(b *testing.B) {
fb := NewFramebuffer() fb := NewFramebuffer()
fb.Init() fb.Init("")
defer fb.Release() defer fb.Release()
data1 := make([]byte, fb.Xres*fb.Yres*4, fb.Xres*fb.Yres*4) data1 := make([]byte, fb.Xres*fb.Yres*4, fb.Xres*fb.Yres*4)
@ -97,7 +97,7 @@ func BenchmarkCopyDataByLine(b *testing.B) {
func BenchmarkCopyDataAllInOne(b *testing.B) { func BenchmarkCopyDataAllInOne(b *testing.B) {
fb := NewFramebuffer() fb := NewFramebuffer()
fb.Init() fb.Init("")
defer fb.Release() defer fb.Release()
data1 := make([]byte, fb.Xres*fb.Yres*4, fb.Xres*fb.Yres*4) data1 := make([]byte, fb.Xres*fb.Yres*4, fb.Xres*fb.Yres*4)
@ -111,7 +111,7 @@ func BenchmarkCopyDataAllInOne(b *testing.B) {
func BenchmarkAnimation(b *testing.B) { func BenchmarkAnimation(b *testing.B) {
fb := NewFramebuffer() fb := NewFramebuffer()
fb.Init() fb.Init("")
defer fb.Release() defer fb.Release()
surface := cairo.NewSurface(cairo.FORMAT_ARGB32, fb.Xres, fb.Yres) surface := cairo.NewSurface(cairo.FORMAT_ARGB32, fb.Xres, fb.Yres)