changeset 692:50750b118116

add sgchangeFB,SDL
author hiroki@localhost.localdomain
date Tue, 08 Dec 2009 16:52:04 +0900
parents 9d1bcc07734b
children fc0227b5cb5a
files Renderer/Engine/sgchangeFB.cc Renderer/Engine/sgchangeFB.h Renderer/Engine/sgchangeSDL.cc Renderer/Engine/sgchangeSDL.h
diffstat 4 files changed, 126 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/sgchangeFB.cc	Tue Dec 08 16:52:04 2009 +0900
@@ -0,0 +1,29 @@
+#include "sgchangeFB.h"
+#include "Func.h"
+#include "fb.h"
+
+//extern void post2runLoop(void *);
+
+void
+SgChangeFB::video_init(TaskManager *manager)
+{
+    Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO;
+
+    if (SDL_Init(sdl_flag) < 0) {
+	fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError());
+	exit(1);
+    }
+
+    pixels = (Uint32*)get_fbdev_addr();
+
+    if (pixels == 0) {
+	pixels = (new Uint32[width*height*32/8]);
+    }
+}
+
+void
+SgChangeFB::clean_pixels()
+{
+    //bzero(pixels, sizeof(int)*width*height);
+    //memset(pixels, 0xFF, sizeof(int)*width*height);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/sgchangeFB.h	Tue Dec 08 16:52:04 2009 +0900
@@ -0,0 +1,16 @@
+#ifndef INCLUDED_SGCHANGE_FB
+#define INCLUDED_SGCHANGE_FB
+
+#include "SgChange.h"
+
+class SgChangeFB : public SgChange {
+public:
+SgChangeFB(TaskManager *manager, int bpp, int width, int height, int spenum)
+    :SgChange(bpp, width, height, spenum) {}
+
+    /* override function */
+    void video_init(TaskManager *manager);
+    void clean_pixels(void);
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/sgchangeSDL.cc	Tue Dec 08 16:52:04 2009 +0900
@@ -0,0 +1,60 @@
+#include "sgchangeSDL.h"
+#include "Func.h"
+#include "TaskManager.h"
+
+extern void post2runLoop(void *);
+
+extern
+
+void
+SgChangeSDL::video_init(TaskManager *manager)
+{
+    Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO;
+    Uint32 *p;
+
+    if (SDL_Init(sdl_flag) < 0) {
+	fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError());
+	exit(1);
+    }
+
+    screen = SDL_SetVideoMode(width, height, bpp, SDL_SWSURFACE);
+    if (screen == NULL) {
+	fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
+	SDL_Quit();
+	exit(1);
+    }
+    
+    p = (Uint32*)manager->allocate(screen->pitch*height);
+    bitmap = SDL_CreateRGBSurfaceFrom((void *)p,
+				      screen->w, screen->h,
+				      screen->format->BitsPerPixel,
+				      screen->pitch,
+				      redMask, greenMask, blueMask, alphaMask);
+
+    pixels = p;
+}
+
+void
+SgChangeSDL::clean_pixels()
+{
+    //bzero(pixels, sizeof(int)*width*height);
+    SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
+}
+
+void
+SgChangeSDL::run_loop(HTaskPtr task_next)
+{
+    SDL_BlitSurface(bitmap, NULL, screen, NULL);
+    SDL_UpdateRect(screen, 0, 0, 0, 0);        
+
+    SgChange::run_loop(task_next);
+}
+
+void
+SgChangeSDL::run_finish()
+{
+    free(bitmap->pixels);
+    SDL_FreeSurface(bitmap);
+
+    SgChange::run_finish();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/sgchangeSDL.h	Tue Dec 08 16:52:04 2009 +0900
@@ -0,0 +1,21 @@
+#ifndef INCLUDED_SGCHANGE_SDL
+#define INCLUDED_SGCHANGE_SDL
+
+#include "SgChange.h"
+
+class SgChangeSDL : public SgChange {
+public:
+SgChangeSDL(TaskManager* manager, int bpp, int width, int height, int spenum)
+    :SgChange(bpp, width, height, spenum) {}
+
+    SDL_Surface *screen;
+    SDL_Surface *bitmap;
+
+    /* override function */
+    void video_init(TaskManager *manager);
+    void clean_pixels();
+    void run_loop(HTaskPtr task_next);
+    void run_finish();
+};
+
+#endif