Пример #1
0
void
NWindowScreen::ScreenConnected(bool connected)
{
	PRINT(("ScreenConnected()\n"));
	fflush(stdout);
	if(connected)
	{
		if(SetSpace(B_8_BIT_640x480) < B_OK)
		{
			//SetFrameBuffer(640, 480);
			PRINT(("SetSpace() failed\n"));
			// properly set the framebuffer. exit if an error occurs.
			be_app->PostMessage(B_QUIT_REQUESTED);
			return;
		}
		// get the framebuffer-related info, each time the
		// WindowScreen is connected (multiple monitor)
		frame_buffer = (uint8*)(CardInfo()->frame_buffer);
		line_length = FrameBufferInfo()->bytes_per_row;
		if(tid == 0)
		{
			// clean the framebuffer
			PRINT(("zeroing the framebuffer\n"));
			memset(frame_buffer,0,480*line_length);
			// spawn the rendering thread. exit if an error occurs.
			PRINT(("spawning the render thread.\n"));
			tid = spawn_thread(Entry,"rendering thread", B_URGENT_DISPLAY_PRIORITY,this);
			if(resume_thread(tid) < B_OK)
			{
				be_app->PostMessage(B_QUIT_REQUESTED);
				return;
			}
		}
		else
		{
			for(int y=0;y<480;y++)
			{
				// restore the framebuffer when switching back from
				// another workspace.
            	memcpy(frame_buffer+y*line_length,save_buffer+640*y,640);
            }
		}
		// set our color list.
		rgb_color palette[256];
		rgb_color c1;
		for(int i=0,j=0;i<256;i++,j++)
		{
			if(i<64)
			{
				c1.red = j*4; // greys
				c1.green = j*4;
				c1.blue = j*4;
				c1.alpha = 255;
			}
			if((i>=64) && (i<128))
			{
				c1.red = j*4; // reds
				c1.green = 0;
				c1.blue = 0;
				c1.alpha = 255;
			}
			if((i>=128) && (i<192))
			{
				c1.red = 0; // greens
				c1.green = j*4;
				c1.blue = 0;
				c1.alpha = 255;
			}
			if((i>=192) && (i<256))
			{
				c1.red = 0; // blues
				c1.green = 0;
				c1.blue = j*4;
				c1.alpha = 255;
			}
			if(j == 64)
				j=0;
			palette[i]=c1;
		}
		SetColorList(palette);
		
		// allow the rendering thread to run.
		thread_is_locked = false;
		release_sem(sem);
	}
	else /* !connected */
	{
		// block the rendering thread.
		if(!thread_is_locked)
		{
			acquire_sem(sem);
			thread_is_locked = true;
		}
		// kill the rendering and clean up when quitting
		if((((NApplication*)be_app)->is_quitting))
		{
			status_t ret;
			kill_thread(tid);
			wait_for_thread(tid,&ret);
			delete_sem(sem);
			delete_area(area);
			free(particle_list);
		}
		else
		{
			// set the color list black so that the screen doesn't seem
			// to freeze while saving the framebuffer
			rgb_color c={0,0,0,255};
			rgb_color palette[256];
			// build the palette
			for(int i=0;i<256;i++)
				palette[i] = c;
			// set the palette
			SetColorList(palette);
			// save the framebuffer
			for(int y=0;y<480;y++)
				memcpy(save_buffer+640*y,frame_buffer+y*line_length,640);
		}
	}
}
Пример #2
0
void MacScreen::ScreenConnected(bool active)
{
	graphics_card_info *info = CardInfo();
	screen_active = active;
	const video_mode &mode = monitor.get_current_mode();

	if (active == true) {

		// Set VideoMonitor
#if REAL_ADDRESSING
		monitor.set_mac_frame_base((uint32)info->frame_buffer);
#else
		monitor.set_mac_frame_base(MacFrameBaseMac);
#endif

#if !REAL_ADDRESSING
		// Set variables for UAE memory mapping
		MacFrameBaseHost = (uint8 *)info->frame_buffer;
		MacFrameSize = mode.bytes_per_row * mode.y;
		switch (info->bits_per_pixel) {
			case 15:
				MacFrameLayout = FLAYOUT_HOST_555;
				break;
			case 16:
				MacFrameLayout = FLAYOUT_HOST_565;
				break;
			case 32:
				MacFrameLayout = FLAYOUT_HOST_888;
				break;
			default:
				MacFrameLayout = FLAYOUT_DIRECT;
				break;
		}
#endif

		// Copy from backup store to frame buffer
		if (frame_backup != NULL) {
			memcpy(info->frame_buffer, frame_backup, mode.bytes_per_row * mode.y);
			delete[] frame_backup;			
			frame_backup = NULL;
		}

		// Restore palette
		if (mode.depth == VDEPTH_8BIT)
			SetColorList(palette);

		// Restart/signal emulator thread
		release_sem(mac_os_lock);

	} else {

		if (!quitting) {

			// Stop emulator thread
			acquire_sem(mac_os_lock);

			// Create backup store and save frame buffer
			frame_backup = new uint8[mode.bytes_per_row * mode.y];
			memcpy(frame_backup, info->frame_buffer, mode.bytes_per_row * mode.y);
		}
	}
}