.developing rainbow

git-svn-id: svn://ultimatepp.org/upp/trunk@3582 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2011-07-01 09:29:40 +00:00
parent c4953990f2
commit 67d68eecae
2 changed files with 221 additions and 221 deletions

View file

@ -1,60 +1,60 @@
class ViewDraw : public SystemDraw { class ViewDraw : public SystemDraw {
ImageBuffer ib; ImageBuffer ib;
Vector<Rect> dummy_invalid; Vector<Rect> dummy_invalid;
public: public:
ViewDraw(Ctrl *ctrl) : SystemDraw(ib, dummy_invalid) { _DBG_ } ViewDraw(Ctrl *ctrl) : SystemDraw(ib, dummy_invalid) { _DBG_ }
~ViewDraw() {} ~ViewDraw() {}
}; };
class DHCtrl : Ctrl {}; class DHCtrl : Ctrl {};
void InitFB(); void InitFB();
#ifdef PLATFORM_WIN32 #ifdef PLATFORM_WIN32
Vector<WString>& coreCmdLine__(); Vector<WString>& coreCmdLine__();
Vector<WString> SplitCmdLine__(const char *cmd); Vector<WString> SplitCmdLine__(const char *cmd);
void FBInit(HINSTANCE hInstance); void FBInit(HINSTANCE hInstance);
#define GUI_APP_MAIN \ #define GUI_APP_MAIN \
void GuiMainFn_();\ void GuiMainFn_();\
\ \
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nCmdShow) \ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nCmdShow) \
{ \ { \
UPP::coreCmdLine__() = UPP::SplitCmdLine__(UPP::FromSystemCharset(lpCmdLine)); \ UPP::coreCmdLine__() = UPP::SplitCmdLine__(UPP::FromSystemCharset(lpCmdLine)); \
UPP::AppInitEnvironment__(); \ UPP::AppInitEnvironment__(); \
UPP::FBInit(hInstance); \ UPP::FBInit(hInstance); \
GuiMainFn_(); \ GuiMainFn_(); \
UPP::Ctrl::CloseTopCtrls(); \ UPP::Ctrl::CloseTopCtrls(); \
UPP::UsrLog("---------- About to delete this log of WinFB..."); \ UPP::UsrLog("---------- About to delete this log of WinFB..."); \
UPP::DeleteUsrLog(); \ UPP::DeleteUsrLog(); \
return UPP::GetExitCode(); \ return UPP::GetExitCode(); \
} \ } \
\ \
void GuiMainFn_() void GuiMainFn_()
#endif #endif
#ifdef PLATFORM_POSIX #ifdef PLATFORM_POSIX
void FBInit(const String& fbdevice); void FBInit(const String& fbdevice);
#define GUI_APP_MAIN \ #define GUI_APP_MAIN \
void GuiMainFn_();\ void GuiMainFn_();\
\ \
int main(int argc, const char **argv, const char **envptr) { \ int main(int argc, const char **argv, const char **envptr) { \
UPP::AppInit__(argc, argv, envptr); \ UPP::AppInit__(argc, argv, envptr); \
FBInit("/dev/fb0"); \ FBInit("/dev/fb0"); \
GuiMainFn_(); \ GuiMainFn_(); \
UPP::Ctrl::CloseTopCtrls(); \ UPP::Ctrl::CloseTopCtrls(); \
UPP::UsrLog("---------- About to delete this log of WinFB..."); \ UPP::UsrLog("---------- About to delete this log of LinuxFB..."); \
UPP::DeleteUsrLog(); \ UPP::DeleteUsrLog(); \
return UPP::GetExitCode(); \ return UPP::GetExitCode(); \
} \ } \
\ \
void GuiMainFn_() void GuiMainFn_()
#endif #endif
void SetDesktop(Ctrl& desktop); void SetDesktop(Ctrl& desktop);
Ctrl *GetDesktop(); Ctrl *GetDesktop();

View file

@ -1,161 +1,161 @@
#include "LinuxFb.h" #include "LinuxFb.h"
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <fcntl.h> #include <fcntl.h>
#include <linux/fb.h> #include <linux/fb.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
NAMESPACE_UPP NAMESPACE_UPP
#define LLOG(x) LOG(x) #define LLOG(x) LOG(x)
int fbfd = 0; int fbfd = 0;
struct fb_var_screeninfo vinfo; struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo; struct fb_fix_screeninfo finfo;
long int screensize = 0; long int screensize = 0;
char *fbp = 0; char *fbp = 0;
//FIXME get input events //FIXME get input events
bool GetShift() { return false; }//!!(GetKeyState(VK_SHIFT) & 0x8000); } bool GetShift() { return false; }//!!(GetKeyState(VK_SHIFT) & 0x8000); }
bool GetCtrl() { return false; }//!!(GetKeyState(VK_CONTROL) & 0x8000); } bool GetCtrl() { return false; }//!!(GetKeyState(VK_CONTROL) & 0x8000); }
bool GetAlt() { return false; }//!!(GetKeyState(VK_MENU) & 0x8000); } bool GetAlt() { return false; }//!!(GetKeyState(VK_MENU) & 0x8000); }
bool GetCapsLock() { return false; }//!!(GetKeyState(VK_CAPITAL) & 1); } bool GetCapsLock() { return false; }//!!(GetKeyState(VK_CAPITAL) & 1); }
bool GetMouseLeft() { return false; }//!!(GetKeyState(VK_LBUTTON) & 0x8000); } bool GetMouseLeft() { return false; }//!!(GetKeyState(VK_LBUTTON) & 0x8000); }
bool GetMouseRight() { return false; }//!!(GetKeyState(VK_RBUTTON) & 0x8000); } bool GetMouseRight() { return false; }//!!(GetKeyState(VK_RBUTTON) & 0x8000); }
bool GetMouseMiddle() { return false; }//!!(GetKeyState(VK_MBUTTON) & 0x8000); } bool GetMouseMiddle() { return false; }//!!(GetKeyState(VK_MBUTTON) & 0x8000); }
bool FBEndSession() bool FBEndSession()
{ {
return false;//fbEndSession; return false;//fbEndSession;
} }
bool FBIsWaitingEvent() bool FBIsWaitingEvent()
{ {
//MSG msg; //MSG msg;
return false; //PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); return false; //PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
} }
bool FBProcessEvent(bool *quit) bool FBProcessEvent(bool *quit)
{ {
/* /*
MSG msg; MSG msg;
if(PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { if(PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
if(msg.message == WM_QUIT && quit) if(msg.message == WM_QUIT && quit)
*quit = true; *quit = true;
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessageW(&msg); DispatchMessageW(&msg);
return true; return true;
} }
*/ */
static int i = 10; static int i = 10;
if(--i > 0) return true; //fake message processing if(--i > 0) return true; //fake message processing
return false; return false;
} }
void FBSleep(int ms) void FBSleep(int ms)
{ {
// MsgWaitForMultipleObjects(0, NULL, FALSE, ms, QS_ALLINPUT); // MsgWaitForMultipleObjects(0, NULL, FALSE, ms, QS_ALLINPUT);
} }
void FBUpdate(const Vector<Rect>& inv) void FBUpdate(const Vector<Rect>& inv)
{ {
// if(fbHWND) // if(fbHWND)
// for(int i = 0; i < inv.GetCount(); i++) // for(int i = 0; i < inv.GetCount(); i++)
// ::InvalidateRect(fbHWND, inv[i], false); // ::InvalidateRect(fbHWND, inv[i], false);
//FIXME direct paint //FIXME direct paint
//here currently just copy over //here currently just copy over
/* /*
int x = 0, y = 0; int x = 0, y = 0;
long int location = 0; long int location = 0;
x = 100; y = 100; // Where we are going to put the pixel x = 100; y = 100; // Where we are going to put the pixel
// Figure out where in memory to put the pixel // Figure out where in memory to put the pixel
for (y = 100; y < 300; y++) for (y = 100; y < 300; y++)
for (x = 100; x < 300; x++) { for (x = 100; x < 300; x++) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) + location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length; (y+vinfo.yoffset) * finfo.line_length;
if (vinfo.bits_per_pixel == 32) { if (vinfo.bits_per_pixel == 32) {
*(fbp + location) = 100; // Some blue *(fbp + location) = 100; // Some blue
*(fbp + location + 1) = 15+(x-100)/2; // A little green *(fbp + location + 1) = 15+(x-100)/2; // A little green
*(fbp + location + 2) = 200-(y-100)/5; // A lot of red *(fbp + location + 2) = 200-(y-100)/5; // A lot of red
*(fbp + location + 3) = 0; // No transparency *(fbp + location + 3) = 0; // No transparency
} else { //assume 16bpp } else { //assume 16bpp
int b = 10; int b = 10;
int g = (x-100)/6; // A little green int g = (x-100)/6; // A little green
int r = 31-(y-100)/16; // A lot of red int r = 31-(y-100)/16; // A lot of red
unsigned short int t = r<<11 | g << 5 | b; unsigned short int t = r<<11 | g << 5 | b;
*((unsigned short int*)(fbp + location)) = t; *((unsigned short int*)(fbp + location)) = t;
} }
} }
*/ */
memcpy(fbp, (const char*)~framebuffer, framebuffer.GetLength() * sizeof(RGBA)); memcpy(fbp, (const char*)~framebuffer, framebuffer.GetLength() * sizeof(RGBA));
} }
void FBUpdate(const Rect& inv) void FBUpdate(const Rect& inv)
{ {
// if(fbHWND) // if(fbHWND)
// ::InvalidateRect(fbHWND, inv, false); // ::InvalidateRect(fbHWND, inv, false);
memcpy(fbp, (const char*)~framebuffer, framebuffer.GetLength() * sizeof(RGBA)); memcpy(fbp, (const char*)~framebuffer, framebuffer.GetLength() * sizeof(RGBA));
} }
void FBSync() void FBSync()
{ {
// if(fbHWND) // if(fbHWND)
// ::UpdateWindow(fbHWND); // ::UpdateWindow(fbHWND);
} }
void FBInit(const String& fbdevice) void FBInit(const String& fbdevice)
{ {
Ctrl::InitFB(); Ctrl::InitFB();
// Open the file for reading and writing // Open the file for reading and writing
fbfd = open(fbdevice, O_RDWR); fbfd = open(fbdevice, O_RDWR);
if (!fbfd) { if (!fbfd) {
printf("Error: cannot open framebuffer device.\n"); printf("Error: cannot open framebuffer device.\n");
exit(1); exit(1);
} }
RLOG("The framebuffer device was opened successfully.\n"); RLOG("The framebuffer device was opened successfully.\n");
// Get fixed screen information // Get fixed screen information
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) { if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
printf("Error reading fixed information.\n"); printf("Error reading fixed information.\n");
exit(2); exit(2);
} }
// Get variable screen information // Get variable screen information
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) { if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
printf("Error reading variable information.\n"); printf("Error reading variable information.\n");
exit(3); exit(3);
} }
RLOG(vinfo.xres << "x" << vinfo.yres << " @ " << vinfo.bits_per_pixel); RLOG(vinfo.xres << "x" << vinfo.yres << " @ " << vinfo.bits_per_pixel);
// Figure out the size of the screen in bytes // Figure out the size of the screen in bytes
screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
// Map the device to memory // Map the device to memory
fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,
fbfd, 0); fbfd, 0);
if ((int)fbp == -1) { if ((intptr_t)fbp == -1) {
printf("Error: failed to map framebuffer device to memory.\n"); printf("Error: failed to map framebuffer device to memory.\n");
exit(4); exit(4);
} }
RLOG("The framebuffer device was mapped to memory successfully.\n"); RLOG("The framebuffer device was mapped to memory successfully.\n");
//FIXME //FIXME
/* /*
munmap(fbp, screensize); munmap(fbp, screensize);
close(fbfd); close(fbfd);
*/ */
framebuffer.Create(vinfo.xres, vinfo.yres); framebuffer.Create(vinfo.xres, vinfo.yres);
} }
END_UPP_NAMESPACE END_UPP_NAMESPACE