void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator compositeOp) { if (!m_page) return; FrameView* view = m_page->mainFrame()->view(); context->save(); context->setCompositeOperation(compositeOp); context->clip(enclosingIntRect(dstRect)); if (compositeOp != CompositeSourceOver) context->beginTransparencyLayer(1); context->translate(dstRect.location().x(), dstRect.location().y()); context->scale(FloatSize(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height())); view->resize(size()); if (view->needsLayout()) view->layout(); view->paint(context, enclosingIntRect(srcRect)); if (compositeOp != CompositeSourceOver) context->endTransparencyLayer(); context->restore(); if (imageObserver()) imageObserver()->didDraw(this); }
void InspectorOverlay::paint(GraphicsContext& context) { if (m_pausedInDebuggerMessage.isNull() && !m_highlightNode && !m_highlightQuad && m_size.isEmpty()) return; GraphicsContextStateSaver stateSaver(context); FrameView* view = overlayPage()->mainFrame()->view(); ASSERT(!view->needsLayout()); view->paint(&context, IntRect(0, 0, view->width(), view->height())); }
void InspectorOverlay::paint(GraphicsContext& context) { if (isEmpty()) return; GraphicsContextStateSaver stateSaver(context); FrameView* view = overlayPage()->mainFrame()->view(); ASSERT(!view->needsLayout()); view->paint(&context, IntRect(0, 0, view->width(), view->height())); }
void paintPageOverlay(const PageOverlay&, GraphicsContext& graphicsContext, const WebSize& webViewSize) const override { if (m_overlay->isEmpty()) return; FrameView* view = m_overlay->overlayMainFrame()->view(); DCHECK(!view->needsLayout()); view->paint(graphicsContext, CullRect(IntRect(0, 0, view->width(), view->height()))); }
void InspectorOverlay::paint(GraphicsContext& context) { if (!shouldShowOverlay()) return; GraphicsContextStateSaver stateSaver(context); FrameView* view = overlayPage()->mainFrame().view(); view->updateLayoutAndStyleIfNeededRecursive(); view->paint(&context, IntRect(0, 0, view->width(), view->height())); }
void paintPageOverlay(const PageOverlay&, GraphicsContext& graphicsContext, const WebSize& webViewSize) const override { if (m_overlay->isEmpty()) return; // Skip cache because the following paint may conflict with the view's real painting. DisplayItemCacheSkipper cacheSkipper(graphicsContext); FrameView* view = m_overlay->overlayMainFrame()->view(); ASSERT(!view->needsLayout()); view->paint(graphicsContext, CullRect(IntRect(0, 0, view->width(), view->height()))); }
void WebView::paint(HDC hDC, const IntRect& clipRect) { FrameView* frameView = view(); if (!frameView) return; OwnPtr<HRGN> clipRgn = adoptPtr(CreateRectRgn(clipRect.x(), clipRect.y(), clipRect.maxX(), clipRect.maxY())); SelectClipRgn(hDC, clipRgn.get()); frameView->updateLayoutAndStyleIfNeededRecursive(); GraphicsContext gc(hDC); frameView->paint(&gc, clipRect); }
PassRefPtr<WebImage> InjectedBundleRangeHandle::renderedImage(SnapshotOptions options) { Document& ownerDocument = m_range->ownerDocument(); Frame* frame = ownerDocument.frame(); if (!frame) return nullptr; FrameView* frameView = frame->view(); if (!frameView) return nullptr; Ref<Frame> protector(*frame); VisibleSelection oldSelection = frame->selection().selection(); frame->selection().setSelection(VisibleSelection(*m_range)); float scaleFactor = (options & SnapshotOptionsExcludeDeviceScaleFactor) ? 1 : frame->page()->deviceScaleFactor(); IntRect paintRect = enclosingIntRect(m_range->absoluteBoundingRect()); IntSize backingStoreSize = paintRect.size(); backingStoreSize.scale(scaleFactor); RefPtr<ShareableBitmap> backingStore = ShareableBitmap::createShareable(backingStoreSize, ShareableBitmap::SupportsAlpha); if (!backingStore) return nullptr; auto graphicsContext = backingStore->createGraphicsContext(); graphicsContext->scale(scaleFactor); paintRect.move(frameView->frameRect().x(), frameView->frameRect().y()); paintRect.moveBy(-frameView->scrollPosition()); graphicsContext->translate(-paintRect.x(), -paintRect.y()); PaintBehavior oldPaintBehavior = frameView->paintBehavior(); PaintBehavior paintBehavior = oldPaintBehavior | PaintBehaviorSelectionOnly | PaintBehaviorFlattenCompositingLayers; if (options & SnapshotOptionsForceBlackText) paintBehavior |= PaintBehaviorForceBlackText; if (options & SnapshotOptionsForceWhiteText) paintBehavior |= PaintBehaviorForceWhiteText; frameView->setPaintBehavior(paintBehavior); ownerDocument.updateLayout(); frameView->paint(*graphicsContext, paintRect); frameView->setPaintBehavior(oldPaintBehavior); frame->selection().setSelection(oldSelection); return WebImage::create(backingStore); }
void SVGImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& dstRect, const FloatRect& srcRect, RespectImageOrientationEnum, ImageClampingMode) { if (!m_page) return; FrameView* view = frameView(); view->resize(containerSize()); // Always call processUrlFragment, even if the url is empty, because // there may have been a previous url/fragment that needs to be reset. view->processUrlFragment(m_url); SkPictureBuilder imagePicture(dstRect); { ClipRecorder clipRecorder(imagePicture.context(), *this, DisplayItem::ClipNodeImage, LayoutRect(enclosingIntRect(dstRect))); // We can only draw the entire frame, clipped to the rect we want. So compute where the top left // of the image would be if we were drawing without clipping, and translate accordingly. FloatSize scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height()); FloatSize topLeftOffset(srcRect.location().x() * scale.width(), srcRect.location().y() * scale.height()); FloatPoint destOffset = dstRect.location() - topLeftOffset; AffineTransform transform = AffineTransform::translation(destOffset.x(), destOffset.y()); transform.scale(scale.width(), scale.height()); TransformRecorder transformRecorder(imagePicture.context(), *this, transform); view->updateAllLifecyclePhases(); view->paint(&imagePicture.context(), enclosingIntRect(srcRect)); ASSERT(!view->needsLayout()); } { SkAutoCanvasRestore ar(canvas, false); if (drawNeedsLayer(paint)) { SkRect layerRect = dstRect; canvas->saveLayer(&layerRect, &paint); } RefPtr<const SkPicture> recording = imagePicture.endRecording(); canvas->drawPicture(recording.get()); } if (imageObserver()) imageObserver()->didDraw(this); // Start any (SMIL) animations if needed. This will restart or continue // animations if preceded by calls to resetAnimation or stopAnimation // respectively. startAnimation(); }
void SVGImage::draw(GraphicsContext& context, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator compositeOp, BlendMode blendMode, ImageOrientationDescription) { if (!m_page) return; FrameView* view = frameView(); ASSERT(view); GraphicsContextStateSaver stateSaver(context); context.setCompositeOperation(compositeOp, blendMode); context.clip(enclosingIntRect(dstRect)); float alpha = context.alpha(); bool compositingRequiresTransparencyLayer = compositeOp != CompositeSourceOver || blendMode != BlendModeNormal || alpha < 1; if (compositingRequiresTransparencyLayer) { context.beginTransparencyLayer(alpha); context.setCompositeOperation(CompositeSourceOver, BlendModeNormal); } FloatSize scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height()); // We can only draw the entire frame, clipped to the rect we want. So compute where the top left // of the image would be if we were drawing without clipping, and translate accordingly. FloatSize topLeftOffset(srcRect.location().x() * scale.width(), srcRect.location().y() * scale.height()); FloatPoint destOffset = dstRect.location() - topLeftOffset; context.translate(destOffset.x(), destOffset.y()); context.scale(scale); view->resize(containerSize()); if (!m_url.isEmpty()) view->scrollToFragment(m_url); if (view->needsLayout()) view->layout(); view->paint(context, intersection(context.clipBounds(), enclosingIntRect(srcRect))); if (compositingRequiresTransparencyLayer) context.endTransparencyLayer(); stateSaver.restore(); if (imageObserver()) imageObserver()->didDraw(this); }
void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator compositeOp, blink::WebBlendMode blendMode) { if (!m_page) return; GraphicsContextStateSaver stateSaver(*context); context->setCompositeOperation(compositeOp, blendMode); context->clip(enclosingIntRect(dstRect)); bool compositingRequiresTransparencyLayer = compositeOp != CompositeSourceOver || blendMode != blink::WebBlendModeNormal; float opacity = context->getNormalizedAlpha() / 255.f; bool requiresTransparencyLayer = compositingRequiresTransparencyLayer || opacity < 1; if (requiresTransparencyLayer) { context->beginTransparencyLayer(opacity); if (compositingRequiresTransparencyLayer) context->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); } FloatSize scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height()); // We can only draw the entire frame, clipped to the rect we want. So compute where the top left // of the image would be if we were drawing without clipping, and translate accordingly. FloatSize topLeftOffset(srcRect.location().x() * scale.width(), srcRect.location().y() * scale.height()); FloatPoint destOffset = dstRect.location() - topLeftOffset; context->translate(destOffset.x(), destOffset.y()); context->scale(scale); FrameView* view = frameView(); view->resize(containerSize()); if (view->needsLayout()) view->layout(); view->paint(context, enclosingIntRect(srcRect)); if (requiresTransparencyLayer) context->endLayer(); stateSaver.restore(); if (imageObserver()) imageObserver()->didDraw(this); }
HBITMAP imageFromSelection(Frame* frame, bool forceBlackText) { if (!frame->view()) return 0; frame->view()->setPaintRestriction(forceBlackText ? PaintRestrictionSelectionOnlyBlackText : PaintRestrictionSelectionOnly); FloatRect fr = frame->selection()->bounds(); IntRect ir((int)fr.x(), (int)fr.y(), (int)fr.width(), (int)fr.height()); if (ir.isEmpty()) return 0; int w; int h; FrameView* view = frame->view(); if (view->parent()) { ir.setLocation(view->parent()->convertChildToSelf(view, ir.location())); w = ir.width() * view->zoomFactor() + 0.5; h = ir.height() * view->zoomFactor() + 0.5; } else { ir = view->contentsToWindow(ir); w = ir.width(); h = ir.height(); } OwnPtr<HDC> bmpDC(CreateCompatibleDC(g_screenDC)); HBITMAP hBmp = MemoryManager::createCompatibleBitmap(g_screenDC, w, h); if (!hBmp) return 0; HBITMAP hbmpOld = (HBITMAP)SelectObject(bmpDC.get(), hBmp); { GraphicsContext gc(bmpDC.get()); frame->document()->updateLayout(); view->paint(&gc, ir); } SelectObject(bmpDC.get(), hbmpOld); frame->view()->setPaintRestriction(PaintRestrictionNone); return hBmp; }
void PageWidgetDelegate::paint(Page* page, PageOverlayList* overlays, WebCanvas* canvas, const WebRect& rect, CanvasBackground background) { if (rect.isEmpty()) return; GraphicsContextBuilder builder(canvas); GraphicsContext& gc = builder.context(); gc.platformContext()->setDrawingToImageBuffer(background == Opaque ? false : true); gc.applyDeviceScaleFactor(page->deviceScaleFactor()); IntRect dirtyRect(rect); gc.save(); FrameView* view = mainFrameView(page); // FIXME: Can we remove the mainFrame()->document() check? if (view && page->mainFrame()->document()) { gc.clip(dirtyRect); view->paint(&gc, dirtyRect); if (overlays) overlays->paintWebFrame(gc); } else gc.fillRect(dirtyRect, Color::white, ColorSpaceDeviceRGB); gc.restore(); }
void PageWidgetDelegate::paint(Page* page, PageOverlayList* overlays, WebCanvas* canvas, const WebRect& rect, CanvasBackground background) { if (rect.isEmpty()) return; GraphicsContext gc(canvas); gc.setCertainlyOpaque(background == Opaque); gc.applyDeviceScaleFactor(page->deviceScaleFactor()); gc.setUseHighResMarkers(page->deviceScaleFactor() > 1.5f); IntRect dirtyRect(rect); gc.save(); // Needed to save the canvas, not the GraphicsContext. FrameView* view = mainFrameView(page); // FIXME: Can we remove the mainFrame()->document() check? if (view && page->mainFrame()->document()) { gc.clip(dirtyRect); view->paint(&gc, dirtyRect); if (overlays) overlays->paintWebFrame(gc); } else { gc.fillRect(dirtyRect, Color::white); } gc.restore(); }
void PageWidgetDelegate::paint(Page& page, PageOverlayList* overlays, WebCanvas* canvas, const WebRect& rect, CanvasBackground background, LocalFrame& root) { if (rect.isEmpty()) return; GraphicsContext gc(canvas, nullptr); gc.setCertainlyOpaque(background == Opaque); float scaleFactor = page.deviceScaleFactor(); gc.scale(scaleFactor, scaleFactor); gc.setDeviceScaleFactor(scaleFactor); IntRect dirtyRect(rect); gc.save(); // Needed to save the canvas, not the GraphicsContext. FrameView* view = root.view(); if (view) { gc.clip(dirtyRect); view->paint(&gc, dirtyRect); if (overlays) overlays->paintWebFrame(gc); } else { gc.fillRect(dirtyRect, Color::white); } gc.restore(); }
void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace, CompositeOperator compositeOp) { if (!m_page) return; FrameView* view = m_page->mainFrame()->view(); context->save(); context->setCompositeOperation(compositeOp); context->clip(enclosingIntRect(dstRect)); if (compositeOp != CompositeSourceOver) context->beginTransparencyLayer(1); FloatSize scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height()); // We can only draw the entire frame, clipped to the rect we want. So compute where the top left // of the image would be if we were drawing without clipping, and translate accordingly. FloatSize topLeftOffset(srcRect.location().x() * scale.width(), srcRect.location().y() * scale.height()); FloatPoint destOffset = dstRect.location() - topLeftOffset; context->translate(destOffset.x(), destOffset.y()); context->scale(scale); view->resize(size()); if (view->needsLayout()) view->layout(); view->paint(context, IntRect(0, 0, view->width(), view->height())); if (compositeOp != CompositeSourceOver) context->endTransparencyLayer(); context->restore(); if (imageObserver()) imageObserver()->didDraw(this); }