Browse Source

add init arg

master
Jay 2 years ago
parent
commit
02dd5bac3d
  1. 10
      framebuffer.go
  2. 14
      framebuffer_test.go

10
framebuffer.go

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

14
framebuffer_test.go

@ -10,7 +10,7 @@ import (
func BenchmarkFill(b *testing.B) {
fb := NewFramebuffer()
fb.Init()
fb.Init("")
defer fb.Release()
for i := 0; i < b.N; i++ {
@ -39,7 +39,7 @@ func BenchmarkMakeSurfaceImage(b *testing.B) {
func BenchmarkDrawImage(b *testing.B) {
fb := NewFramebuffer()
fb.Init()
fb.Init("")
defer fb.Release()
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) {
fb := NewFramebuffer()
fb.Init()
fb.Init("")
defer fb.Release()
surface := cairo.NewSurface(cairo.FORMAT_ARGB32, fb.Xres, fb.Yres)
@ -68,7 +68,7 @@ func BenchmarkCairoGetData(b *testing.B) {
func BenchmarkDrawData(b *testing.B) {
fb := NewFramebuffer()
fb.Init()
fb.Init("")
defer fb.Release()
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) {
fb := NewFramebuffer()
fb.Init()
fb.Init("")
defer fb.Release()
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) {
fb := NewFramebuffer()
fb.Init()
fb.Init("")
defer fb.Release()
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) {
fb := NewFramebuffer()
fb.Init()
fb.Init("")
defer fb.Release()
surface := cairo.NewSurface(cairo.FORMAT_ARGB32, fb.Xres, fb.Yres)

Loading…
Cancel
Save