Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

target_fbdev.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: target_fbdev.cpp,v 1.2 2001/03/10 17:26:28 mbn Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 */
00014 
00015 #include "Core/precomp.h"
00016 
00017 #include <API/Display/Display/palette.h>
00018 #include <Display/Display/FBDev/target_fbdev.h>
00019 #include "API/Core/System/cl_assert.h"
00020 
00021 #include <iostream>
00022 #include <string.h>
00023 #include <math.h>
00024 #include <sys/mman.h>
00025 
00026 #include "regs.h"
00027 #include "mmio.h"
00028 
00029 CL_Target_FBDev::CL_Target_FBDev(
00030         bool doublebuffer,
00031         char *fb,
00032         unsigned int width,
00033         unsigned int height,
00034         fb_var_screeninfo* var,
00035         volatile unsigned char *mmioaddr )
00036 {
00037         m_var = var;
00038         m_fb = fb;
00039         m_width = width;
00040         m_height = height;
00041         m_doublebuffer = doublebuffer;
00042         m_mmioaddr = mmioaddr;
00043         
00044         image_size = m_width*m_height * ((get_depth()+7)/8);
00045 
00046         if (m_doublebuffer)
00047         {
00048                 buffer = 1;
00049         } else
00050         {
00051                 m_skip = get_pitch() - (m_width * ((get_depth()+7)/8));
00052                 image_data = new char[image_size];
00053         }
00054 }
00055 
00056 CL_Target_FBDev::~CL_Target_FBDev()
00057 {
00058         if (!m_doublebuffer)
00059         {
00060                 delete image_data;
00061         }
00062 }
00063 
00064 bool CL_Target_FBDev::is_video()
00065 {
00066         return m_doublebuffer;
00067 }
00068 
00069 void CL_Target_FBDev::put_image()
00070 {
00071         if (m_doublebuffer)
00072         {
00073                 buffer = !buffer;
00074         } else
00075         {
00076                 if (m_skip)
00077                 {
00078                         char* to = m_fb;
00079                         char* from = image_data;
00080                         int line_length = m_width * ((get_depth()+7)/8);
00081                         for (unsigned int y=0; y<m_height; y++)
00082                         {
00083                                 memcpy( to, from, line_length );
00084                                 to += get_pitch();
00085                                 from += line_length;
00086                         }
00087                 } else
00088                 {
00089                         memcpy( m_fb, image_data, image_size );
00090                 }
00091         }
00092 }
00093 
00094 void CL_Target_FBDev::lock()
00095 {
00096         if (m_mmioaddr)
00097         {
00098                 mga_waitidle( m_mmioaddr );
00099         }
00100 }
00101         
00102 void CL_Target_FBDev::unlock()
00103 {
00104 }
00105 
00106 void *CL_Target_FBDev::get_data() const
00107 {
00108         if (m_doublebuffer)
00109         {
00110                 return m_fb + buffer*get_pitch()*m_height;
00111         } else
00112         {
00113                 return image_data;
00114         }
00115 }
00116 
00117 unsigned int CL_Target_FBDev::get_width() const
00118 {
00119         return m_width;
00120 }
00121 
00122 unsigned int CL_Target_FBDev::get_height() const
00123 {
00124         return m_height;
00125 }
00126 
00127 unsigned int CL_Target_FBDev::get_pitch() const
00128 {
00129         int bytes_per_pixel = (get_depth()+7)/8;
00130 
00131         return m_var->xres_virtual *bytes_per_pixel;
00132 }
00133         
00134 unsigned int CL_Target_FBDev::get_depth() const
00135 {
00136         return 16; //FIXME
00137 }
00138 
00139 unsigned int CL_Target_FBDev::get_red_mask() const
00140 {
00141         return ((int)((pow(2,m_var->red.length))-1) << (m_var->blue.length + m_var->green.length));
00142 }
00143 
00144 unsigned int CL_Target_FBDev::get_green_mask() const
00145 {
00146         return ((int)(pow(2,m_var->green.length))-1) << m_var->blue.length;
00147 }
00148 
00149 unsigned int CL_Target_FBDev::get_blue_mask() const
00150 {
00151         return (int)(pow(2,m_var->blue.length))-1;
00152 }
00153 
00154 bool CL_Target_FBDev::is_indexed() const
00155 {
00156         return false;
00157 }
00158 
00159 unsigned int CL_Target_FBDev::get_alpha_mask() const
00160 {
00161         return 0;
00162 }
00163 
00164 CL_Palette *CL_Target_FBDev::get_palette() const
00165 {
00166         return NULL;
00167 }

Generated at Wed Apr 4 19:54:04 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001