1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
20 #define y2log_component "framebuffer"
21 #include <ycp/y2log.h>
23 #include <sys/types.h>
30 #include "YFrameBuffer.h"
33 YFrameBuffer::YFrameBuffer( int width, int height, int depth )
46 case 16: _bytesPerPixel = 2;
50 case 32: _bytesPerPixel = 4;
54 y2warning( "Pixel depth %d not supported", _depth );
59 if ( _bytesPerPixel > 0 )
64 YFrameBuffer::~YFrameBuffer()
70 void YFrameBuffer::mmapFB()
74 y2error( "Framebuffer already mmap()'ed" );
78 _fb_fd = open( "/dev/fb0", O_RDWR );
82 y2error( "Can't open /dev/fb0 - errno %d: %s", errno, strerror( errno ) );
86 _fb_len = _width * _height * _bytesPerPixel;
87 _fb = mmap( 0, // start
89 PROT_READ | PROT_WRITE, // prot
91 _fb_fd, // file descriptor
94 if ( _fb == MAP_FAILED )
96 y2error( "mmap() failed for /dev/fb0 - errno %d: %s", errno, strerror( errno ) );
101 _fb16 = (UINT16 *) _fb;
102 _fb32 = (UINT32 *) _fb;
106 void YFrameBuffer::munmapFB()
111 munmap( _fb, _fb_len );
121 void YFrameBuffer::setPixel( int x, int y, FBPixel pixel )
126 if ( x < _width && y < _height )
128 if ( _bytesPerPixel == 2 )
131 _fb16[ y * _width + x ] = (UINT16) pixel;
133 else if ( _bytesPerPixel == 4 )
135 _fb32[ y * _width + x ] = (UINT32) pixel;
141 YFrameBuffer::FBPixel
142 YFrameBuffer::pixel( int x, int y )
147 if ( x < _width && y < _height )
149 if ( _bytesPerPixel == 2 )
151 return (FBPixel) _fb16[ y * _width + x ];
153 else if ( _bytesPerPixel == 4 )
155 return (FBPixel) _fb32[ y * _width + x ];