PassOwnPtr<GraphicsContext> BackingStore::createGraphicsContext() { RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB()); RetainPtr<CGContextRef> bitmapContext(AdoptCF, CGBitmapContextCreate(data(), m_size.width(), m_size.height(), 8, m_size.width() * 4, colorSpace.get(), kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host)); // We want the origin to be in the top left corner so flip the backing store context. CGContextTranslateCTM(bitmapContext.get(), 0, m_size.height()); CGContextScaleCTM(bitmapContext.get(), 1, -1); return adoptPtr(new GraphicsContext(bitmapContext.get())); }
void ChunkedUpdateDrawingArea::paintIntoUpdateChunk(UpdateChunk* updateChunk) { RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB()); RetainPtr<CGContextRef> bitmapContext(AdoptCF, CGBitmapContextCreate(updateChunk->data(), updateChunk->rect().width(), updateChunk->rect().height(), 8, updateChunk->rect().width() * 4, colorSpace.get(), kCGImageAlphaPremultipliedLast)); // WebCore expects a flipped coordinate system. CGContextTranslateCTM(bitmapContext.get(), 0.0, updateChunk->rect().height()); CGContextScaleCTM(bitmapContext.get(), 1.0, -1.0); // Now paint into the backing store. GraphicsContext graphicsContext(bitmapContext.get()); graphicsContext.translate(-updateChunk->rect().x(), -updateChunk->rect().y()); m_webPage->drawRect(graphicsContext, updateChunk->rect()); }
PassRefPtr<BitmapImage> BitmapImage::create(HBITMAP hBitmap) { DIBSECTION dibSection; if (!GetObject(hBitmap, sizeof(DIBSECTION), &dibSection)) return 0; ASSERT(dibSection.dsBm.bmBitsPixel == 32); if (dibSection.dsBm.bmBitsPixel != 32) return 0; ASSERT(dibSection.dsBm.bmBits); if (!dibSection.dsBm.bmBits) return 0; RetainPtr<CGContextRef> bitmapContext(AdoptCF, CGBitmapContextCreate(dibSection.dsBm.bmBits, dibSection.dsBm.bmWidth, dibSection.dsBm.bmHeight, 8, dibSection.dsBm.bmWidthBytes, deviceRGBColorSpaceRef(), kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst)); // The BitmapImage takes ownership of this. CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext.get()); return adoptRef(new BitmapImage(cgImage)); }