bool GraphicsSurface::platformCreate(const IntSize& size, Flags flags) { unsigned pixelFormat = 'BGRA'; unsigned bytesPerElement = 4; int width = size.width(); int height = size.height(); unsigned long bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, width * bytesPerElement); if (!bytesPerRow) return false; unsigned long allocSize = IOSurfaceAlignProperty(kIOSurfaceAllocSize, height * bytesPerRow); if (!allocSize) return false; const void *keys[7]; const void *values[7]; keys[0] = kIOSurfaceWidth; values[0] = CFNumberCreate(0, kCFNumberIntType, &width); keys[1] = kIOSurfaceHeight; values[1] = CFNumberCreate(0, kCFNumberIntType, &height); keys[2] = kIOSurfacePixelFormat; values[2] = CFNumberCreate(0, kCFNumberIntType, &pixelFormat); keys[3] = kIOSurfaceBytesPerElement; values[3] = CFNumberCreate(0, kCFNumberIntType, &bytesPerElement); keys[4] = kIOSurfaceBytesPerRow; values[4] = CFNumberCreate(0, kCFNumberLongType, &bytesPerRow); keys[5] = kIOSurfaceAllocSize; values[5] = CFNumberCreate(0, kCFNumberLongType, &allocSize); keys[6] = kIOSurfaceIsGlobal; values[6] = (flags & GraphicsSurface::SupportsSharing) ? kCFBooleanTrue : kCFBooleanFalse; CFDictionaryRef dict = CFDictionaryCreate(0, keys, values, 7, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); for (unsigned i = 0; i < 7; i++) CFRelease(values[i]); m_platformSurface = IOSurfaceCreate(dict); return !!m_platformSurface; }
static RetainPtr<IOSurfaceRef> createIOSurface(const IntSize& size) { unsigned pixelFormat = 'BGRA'; unsigned bytesPerElement = 4; int width = size.width(); int height = size.height(); unsigned long bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, size.width() * bytesPerElement); if (!bytesPerRow) return 0; unsigned long allocSize = IOSurfaceAlignProperty(kIOSurfaceAllocSize, size.height() * bytesPerRow); if (!allocSize) return 0; const void *keys[7]; const void *values[7]; keys[0] = kIOSurfaceWidth; values[0] = CFNumberCreate(0, kCFNumberIntType, &width); keys[1] = kIOSurfaceHeight; values[1] = CFNumberCreate(0, kCFNumberIntType, &height); keys[2] = kIOSurfacePixelFormat; values[2] = CFNumberCreate(0, kCFNumberIntType, &pixelFormat); keys[3] = kIOSurfaceBytesPerElement; values[3] = CFNumberCreate(0, kCFNumberIntType, &bytesPerElement); keys[4] = kIOSurfaceBytesPerRow; values[4] = CFNumberCreate(0, kCFNumberLongType, &bytesPerRow); keys[5] = kIOSurfaceAllocSize; values[5] = CFNumberCreate(0, kCFNumberLongType, &allocSize); keys[6] = kIOSurfaceMemoryRegion; values[6] = CFSTR("PurpleGfxMem"); RetainPtr<CFDictionaryRef> dict(AdoptCF, CFDictionaryCreate(0, keys, values, 7, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); for (unsigned i = 0; i < 7; i++) CFRelease(values[i]); return RetainPtr<IOSurfaceRef>(AdoptCF, IOSurfaceCreate(dict.get())); }
GraphicsSurfacePrivate(const PlatformGraphicsContext3D shareContext, const IntSize& size, GraphicsSurface::Flags flags) : m_context(0) , m_size(size) , m_frontBufferTexture(0) , m_frontBufferReadTexture(0) , m_backBufferTexture(0) , m_backBufferReadTexture(0) , m_readFbo(0) , m_drawFbo(0) { #if PLATFORM(QT) QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface(); CGLContextObj shareContextObject = static_cast<CGLContextObj>(nativeInterface->nativeResourceForContext(QByteArrayLiteral("cglContextObj"), shareContext)); if (!shareContextObject) return; CGLPixelFormatObj pixelFormatObject = CGLGetPixelFormat(shareContextObject); if (kCGLNoError != CGLCreateContext(pixelFormatObject, shareContextObject, &m_context)) return; CGLRetainContext(m_context); #endif unsigned pixelFormat = 'BGRA'; unsigned bytesPerElement = 4; int width = m_size.width(); int height = m_size.height(); unsigned long bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, width * bytesPerElement); if (!bytesPerRow) return; unsigned long allocSize = IOSurfaceAlignProperty(kIOSurfaceAllocSize, height * bytesPerRow); if (!allocSize) return; const void *keys[6]; const void *values[6]; keys[0] = kIOSurfaceWidth; values[0] = CFNumberCreate(0, kCFNumberIntType, &width); keys[1] = kIOSurfaceHeight; values[1] = CFNumberCreate(0, kCFNumberIntType, &height); keys[2] = kIOSurfacePixelFormat; values[2] = CFNumberCreate(0, kCFNumberIntType, &pixelFormat); keys[3] = kIOSurfaceBytesPerElement; values[3] = CFNumberCreate(0, kCFNumberIntType, &bytesPerElement); keys[4] = kIOSurfaceBytesPerRow; values[4] = CFNumberCreate(0, kCFNumberLongType, &bytesPerRow); keys[5] = kIOSurfaceAllocSize; values[5] = CFNumberCreate(0, kCFNumberLongType, &allocSize); CFDictionaryRef dict = CFDictionaryCreate(0, keys, values, 6, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); for (unsigned i = 0; i < 6; i++) CFRelease(values[i]); m_frontBuffer = IOSurfaceCreate(dict); m_backBuffer = IOSurfaceCreate(dict); if (!(flags & GraphicsSurface::SupportsSharing)) return; m_token = GraphicsSurfaceToken(IOSurfaceCreateMachPort(m_frontBuffer), IOSurfaceCreateMachPort(m_backBuffer)); }
c_width=CFNumberCreate(0,kCFNumberSInt32Type,&tmp_width); SInt32 tmp_height=b->height; c_height=CFNumberCreate(0,kCFNumberSInt32Type,&tmp_height); SInt32 tmp_bpp=bpp; c_bpp=CFNumberCreate(0,kCFNumberSInt32Type,&tmp_bpp); SInt32 tmp_pitch=b->pitch; c_pitch=CFNumberCreate(0,kCFNumberSInt32Type,&tmp_pitch); OSType tmp_pxlfmt=pxlfmt; c_pxlfmt=CFNumberCreate(0,kCFNumberSInt32Type,&tmp_pxlfmt); CFDictionaryRef prop=CFDictionaryCreate(0, (const void*[]){kIOSurfaceWidth,kIOSurfaceHeight,kIOSurfaceBytesPerElement,kIOSurfaceBytesPerRow,kIOSurfacePixelFormat,kIOSurfaceIsGlobal}, (const void*[]){c_width,c_height,c_bpp,c_pitch,c_pxlfmt,kCFBooleanTrue}, 6,&kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks); // TODO m_surface might be set into clientdata... IOSurfaceRef m_surface = IOSurfaceCreate(prop); CFRelease(c_width); CFRelease(c_height); CFRelease(c_bpp); CFRelease(c_pitch); b->bufid = IOSurfaceGetID( m_surface ); b->clientdata = NULL; b->type = SkypekitVideoTransportBase::IOSurfaceBuffer; return true; } void IOSurfaceTransport::FreeBuffer( bufferstruct *b ) {