Slow access to VRAM

Discussion in 'Mac Programming' started by mif, Aug 22, 2013.

  1. mif
    macrumors regular

    Joined:
    Feb 16, 2010
    Location:
    home
    #1
    I am wondering what have changed in Mountain Lion? I found a way to draw directly to the screen but it is much slower than in Snow Leopard. 8 fps versus 145 fps.
    Code:
    unsigned char *get_display_base_address()
    {
    	kern_return_t		kr;
    	io_connect_t		framebuffer;
    	io_iterator_t		iter;
    	io_service_t		ioServicePort;
    	mach_vm_address_t	vram = 0;
    	mach_vm_size_t		shmemSize;
    	mach_port_t			masterPort;
    	
    	kr = IOMasterPort(bootstrap_port, &masterPort);
    	if (kr == KERN_SUCCESS)
            {
    		kr = IOServiceGetMatchingServices(masterPort, IOServiceMatching(IOFRAMEBUFFER_CONFORMSTO), &iter);
    		if (kr == KERN_SUCCESS)
    		{
    			ioServicePort = IOIteratorNext(iter);
    			IOObjectRelease(iter);
    			kr = IOServiceOpen(ioServicePort, mach_task_self(), kIOFBSharedConnectType, &framebuffer);
    			IOObjectRelease(ioServicePort);
    			if (kr == KERN_SUCCESS)
    			{
    				kr = IOConnectMapMemory(framebuffer, 110, mach_task_self(), &vram, &shmemSize, kIOMapAnywhere);
    				IOServiceClose(framebuffer);
    			}
    		}
    	}
    	return (unsigned char *)vram + 0x180000;	//return (unsigned char *)CGDisplayBaseAddress(CGMainDisplayID());
    }
     
  2. macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #2
    Mountain Lion's window server uses a 'page flipping' design for double buffering. This is much faster in general, but tends to mess up direct access.
     
  3. mif
    thread starter macrumors regular

    Joined:
    Feb 16, 2010
    Location:
    home

Share This Page