void WebCoordinatedSurface::paintToSurface(const IntRect& rect, CoordinatedSurface::Client* client) { ASSERT(client); auto context = createGraphicsContext(rect); client->paintToSurfaceContext(context.get()); }
void BackingStore::paint(WebCore::GraphicsContext* context, const WebCore::IntRect& clipRect) { // FIXME: Honor the clip rect! OwnPtr<GraphicsContext> sourceContext(createGraphicsContext()); // FIXME: This creates an extra copy. RetainPtr<CGImageRef> image(AdoptCF, CGBitmapContextCreateImage(sourceContext->platformContext())); CGContextRef cgContext = context->platformContext(); CGContextSaveGState(cgContext); CGContextDrawImage(context->platformContext(), CGRectMake(0, 0, CGImageGetWidth(image.get()), CGImageGetHeight(image.get())), image.get()); CGContextRestoreGState(cgContext); }
PassRefPtr<ShareableBitmap> WebFrame::createSelectionSnapshot() const { std::unique_ptr<ImageBuffer> snapshot = snapshotSelection(*coreFrame(), WebCore::SnapshotOptionsForceBlackText); if (!snapshot) return nullptr; auto sharedSnapshot = ShareableBitmap::createShareable(snapshot->internalSize(), ShareableBitmap::SupportsAlpha); if (!sharedSnapshot) return nullptr; // FIXME: We should consider providing a way to use subpixel antialiasing for the snapshot // if we're compositing this image onto a solid color (e.g. the modern find indicator style). auto graphicsContext = sharedSnapshot->createGraphicsContext(); float deviceScaleFactor = coreFrame()->page()->deviceScaleFactor(); graphicsContext->scale(FloatSize(deviceScaleFactor, deviceScaleFactor)); graphicsContext->drawConsumingImageBuffer(WTFMove(snapshot), FloatPoint()); return WTFMove(sharedSnapshot); }
void DrawingAreaImpl::display(UpdateInfo& updateInfo) { ASSERT(!m_isPaintingSuspended); ASSERT(!m_layerTreeHost); ASSERT(!m_webPage->size().isEmpty()); // FIXME: It would be better if we could avoid painting altogether when there is a custom representation. if (m_webPage->mainFrameHasCustomRepresentation()) { // ASSUMPTION: the custom representation will be painting the dirty region for us. m_dirtyRegion = Region(); return; } m_webPage->layoutIfNeeded(); // The layout may have put the page into accelerated compositing mode. If the LayerTreeHost is // in charge of displaying, we have nothing more to do. if (m_layerTreeHost) return; updateInfo.viewSize = m_webPage->size(); updateInfo.deviceScaleFactor = m_webPage->corePage()->deviceScaleFactor(); IntRect bounds = m_dirtyRegion.bounds(); ASSERT(m_webPage->bounds().contains(bounds)); IntSize bitmapSize = bounds.size(); float deviceScaleFactor = m_webPage->corePage()->deviceScaleFactor(); bitmapSize.scale(deviceScaleFactor); RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(bitmapSize, ShareableBitmap::SupportsAlpha); if (!bitmap) return; if (!bitmap->createHandle(updateInfo.bitmapHandle)) return; Vector<IntRect> rects = m_dirtyRegion.rects(); if (shouldPaintBoundsRect(bounds, rects)) { rects.clear(); rects.append(bounds); } updateInfo.scrollRect = m_scrollRect; updateInfo.scrollOffset = m_scrollOffset; m_dirtyRegion = Region(); m_scrollRect = IntRect(); m_scrollOffset = IntSize(); OwnPtr<GraphicsContext> graphicsContext = createGraphicsContext(bitmap.get()); graphicsContext->applyDeviceScaleFactor(deviceScaleFactor); updateInfo.updateRectBounds = bounds; graphicsContext->translate(-bounds.x(), -bounds.y()); for (size_t i = 0; i < rects.size(); ++i) { m_webPage->drawRect(*graphicsContext, rects[i]); if (m_webPage->hasPageOverlay()) m_webPage->drawPageOverlay(*graphicsContext, rects[i]); updateInfo.updateRects.append(rects[i]); } // Layout can trigger more calls to setNeedsDisplay and we don't want to process them // until the UI process has painted the update, so we stop the timer here. m_displayTimer.stop(); }
RetainPtr<CGImageRef> ShareableBitmap::makeCGImageCopy() { auto graphicsContext = createGraphicsContext(); RetainPtr<CGImageRef> image = adoptCF(CGBitmapContextCreateImage(graphicsContext->platformContext())); return image; }
PassRefPtr<GraphicsContext3D> GraphicsContext3DPrivate::createGraphicsContextForAnotherThread(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle) { return createGraphicsContext(attrs, hostWindow, renderStyle, ForUseOnAnotherThread); }