Changeset 214406 in webkit
- Timestamp:
- Mar 25, 2017, 5:53:24 PM (8 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r214404 r214406 1 2017-03-25 Andy Estes <aestes@apple.com> 2 3 [iOS] Use snapshotting instead of printing to draw single-page PDFs 4 https://bugs.webkit.org/show_bug.cgi?id=170103 5 <rdar://problem/30542960> 6 7 Reviewed by Tim Horton. 8 9 * WebProcess/WebPage/WebPage.cpp: 10 (WebKit::paintSnapshotAtSize): Moved the painting logic from WebPage::snapshotAtSize() to here. 11 (WebKit::WebPage::snapshotAtSize): Changed to call paintSnapshotAtSize() with the 12 WebImage's graphics context. 13 (WebKit::WebPage::pdfSnapshotAtSize): Created a CGPDFGraphicsContext, passed it to 14 paintSnapshotAtSize(), and returned the context's data. 15 * WebProcess/WebPage/WebPage.h: Made snapshotAtSize() and snapshotNode() private, changed 16 their return values from PassRefPtr to RefPtr, and declared pdfSnapshotAtSize(). 17 * WebProcess/WebPage/ios/WebPageIOS.mm: 18 (WebKit::WebPage::computePagesForPrintingAndDrawToPDF): If snapshotting the first page, 19 returned a page count of 1 and created a PDF using pdfSnapshotAtSize(). 20 1 21 2017-03-25 John Wilander <wilander@apple.com> 2 22 -
trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp
r214284 r214406 1946 1946 } 1947 1947 1948 PassRefPtr<WebImage> WebPage::snapshotAtSize(const IntRect& rect, const IntSize& bitmapSize, SnapshotOptions options) 1949 { 1950 Frame* coreFrame = m_mainFrame->coreFrame(); 1951 if (!coreFrame) 1952 return nullptr; 1953 1954 FrameView* frameView = coreFrame->view(); 1955 if (!frameView) 1956 return nullptr; 1957 1948 static void paintSnapshotAtSize(const IntRect& rect, const IntSize& bitmapSize, SnapshotOptions options, Frame& frame, FrameView& frameView, GraphicsContext& graphicsContext) 1949 { 1958 1950 IntRect snapshotRect = rect; 1959 1951 float horizontalScaleFactor = static_cast<float>(bitmapSize.width()) / rect.width(); … … 1961 1953 float scaleFactor = std::max(horizontalScaleFactor, verticalScaleFactor); 1962 1954 1963 auto snapshot = WebImage::create(bitmapSize, snapshotOptionsToImageOptions(options));1964 1965 auto graphicsContext = snapshot->bitmap().createGraphicsContext();1966 1967 1955 if (options & SnapshotOptionsPrinting) { 1968 PrintContext::spoolAllPagesWithBoundaries( *coreFrame, *graphicsContext, snapshotRect.size());1969 return snapshot;1970 } 1971 1972 Color documentBackgroundColor = frameView ->documentBackgroundColor();1973 Color backgroundColor = ( coreFrame->settings().backgroundShouldExtendBeyondPage() && documentBackgroundColor.isValid()) ? documentBackgroundColor : frameView->baseBackgroundColor();1974 graphicsContext ->fillRect(IntRect(IntPoint(), bitmapSize), backgroundColor);1956 PrintContext::spoolAllPagesWithBoundaries(frame, graphicsContext, snapshotRect.size()); 1957 return; 1958 } 1959 1960 Color documentBackgroundColor = frameView.documentBackgroundColor(); 1961 Color backgroundColor = (frame.settings().backgroundShouldExtendBeyondPage() && documentBackgroundColor.isValid()) ? documentBackgroundColor : frameView.baseBackgroundColor(); 1962 graphicsContext.fillRect(IntRect(IntPoint(), bitmapSize), backgroundColor); 1975 1963 1976 1964 if (!(options & SnapshotOptionsExcludeDeviceScaleFactor)) { 1977 double deviceScaleFactor = corePage()->deviceScaleFactor();1978 graphicsContext ->applyDeviceScaleFactor(deviceScaleFactor);1965 double deviceScaleFactor = frame.page()->deviceScaleFactor(); 1966 graphicsContext.applyDeviceScaleFactor(deviceScaleFactor); 1979 1967 scaleFactor /= deviceScaleFactor; 1980 1968 } 1981 1969 1982 graphicsContext ->scale(scaleFactor);1983 graphicsContext ->translate(-snapshotRect.x(), -snapshotRect.y());1970 graphicsContext.scale(scaleFactor); 1971 graphicsContext.translate(-snapshotRect.x(), -snapshotRect.y()); 1984 1972 1985 1973 FrameView::SelectionInSnapshot shouldPaintSelection = FrameView::IncludeSelection; … … 1991 1979 coordinateSpace = FrameView::ViewCoordinates; 1992 1980 1993 frameView ->paintContentsForSnapshot(*graphicsContext, snapshotRect, shouldPaintSelection, coordinateSpace);1981 frameView.paintContentsForSnapshot(graphicsContext, snapshotRect, shouldPaintSelection, coordinateSpace); 1994 1982 1995 1983 if (options & SnapshotOptionsPaintSelectionRectangle) { 1996 FloatRect selectionRectangle = m_mainFrame->coreFrame()->selection().selectionBounds(); 1997 graphicsContext->setStrokeColor(Color(0xFF, 0, 0)); 1998 graphicsContext->strokeRect(selectionRectangle, 1); 1999 } 2000 1984 FloatRect selectionRectangle = frame.selection().selectionBounds(); 1985 graphicsContext.setStrokeColor(Color(0xFF, 0, 0)); 1986 graphicsContext.strokeRect(selectionRectangle, 1); 1987 } 1988 } 1989 1990 RefPtr<WebImage> WebPage::snapshotAtSize(const IntRect& rect, const IntSize& bitmapSize, SnapshotOptions options) 1991 { 1992 Frame* coreFrame = m_mainFrame->coreFrame(); 1993 if (!coreFrame) 1994 return nullptr; 1995 1996 FrameView* frameView = coreFrame->view(); 1997 if (!frameView) 1998 return nullptr; 1999 2000 auto snapshot = WebImage::create(bitmapSize, snapshotOptionsToImageOptions(options)); 2001 auto graphicsContext = snapshot->bitmap().createGraphicsContext(); 2002 2003 paintSnapshotAtSize(rect, bitmapSize, options, *coreFrame, *frameView, *graphicsContext); 2004 2001 2005 return snapshot; 2002 2006 } 2003 2007 2004 PassRefPtr<WebImage> WebPage::snapshotNode(WebCore::Node& node, SnapshotOptions options, unsigned maximumPixelCount) 2008 #if USE(CF) 2009 RetainPtr<CFDataRef> WebPage::pdfSnapshotAtSize(const IntRect& rect, const IntSize& bitmapSize, SnapshotOptions options) 2010 { 2011 Frame* coreFrame = m_mainFrame->coreFrame(); 2012 if (!coreFrame) 2013 return nullptr; 2014 2015 FrameView* frameView = coreFrame->view(); 2016 if (!frameView) 2017 return nullptr; 2018 2019 auto data = adoptCF(CFDataCreateMutable(kCFAllocatorDefault, 0)); 2020 2021 #if USE(CG) 2022 auto dataConsumer = adoptCF(CGDataConsumerCreateWithCFData(data.get())); 2023 auto mediaBox = CGRectMake(0, 0, bitmapSize.width(), bitmapSize.height()); 2024 auto pdfContext = adoptCF(CGPDFContextCreate(dataConsumer.get(), &mediaBox, nullptr)); 2025 2026 CGPDFContextBeginPage(pdfContext.get(), nullptr); 2027 2028 GraphicsContext graphicsContext { pdfContext.get() }; 2029 graphicsContext.scale({ 1, -1 }); 2030 graphicsContext.translate(0, -bitmapSize.height()); 2031 paintSnapshotAtSize(rect, bitmapSize, options, *coreFrame, *frameView, graphicsContext); 2032 2033 CGPDFContextEndPage(pdfContext.get()); 2034 CGPDFContextClose(pdfContext.get()); 2035 #endif 2036 2037 return WTFMove(data); 2038 } 2039 #endif 2040 2041 RefPtr<WebImage> WebPage::snapshotNode(WebCore::Node& node, SnapshotOptions options, unsigned maximumPixelCount) 2005 2042 { 2006 2043 Frame* coreFrame = m_mainFrame->coreFrame(); -
trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h
r214113 r214406 491 491 492 492 PassRefPtr<WebImage> scaledSnapshotWithOptions(const WebCore::IntRect&, double additionalScaleFactor, SnapshotOptions); 493 PassRefPtr<WebImage> snapshotAtSize(const WebCore::IntRect&, const WebCore::IntSize& bitmapSize, SnapshotOptions);494 PassRefPtr<WebImage> snapshotNode(WebCore::Node&, SnapshotOptions, unsigned maximumPixelCount = std::numeric_limits<unsigned>::max());495 493 496 494 static const WebEvent* currentEvent(); … … 1275 1273 void urlSchemeHandlerTaskDidComplete(uint64_t handlerIdentifier, uint64_t taskIdentifier, const WebCore::ResourceError&); 1276 1274 1275 RefPtr<WebImage> snapshotAtSize(const WebCore::IntRect&, const WebCore::IntSize& bitmapSize, SnapshotOptions); 1276 RefPtr<WebImage> snapshotNode(WebCore::Node&, SnapshotOptions, unsigned maximumPixelCount = std::numeric_limits<unsigned>::max()); 1277 #if USE(CF) 1278 RetainPtr<CFDataRef> pdfSnapshotAtSize(const WebCore::IntRect&, const WebCore::IntSize& bitmapSize, SnapshotOptions); 1279 #endif 1280 1277 1281 uint64_t m_pageID; 1278 1282 -
trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm
r214266 r214406 3253 3253 void WebPage::computePagesForPrintingAndDrawToPDF(uint64_t frameID, const PrintInfo& printInfo, uint64_t callbackID, PassRefPtr<Messages::WebPage::ComputePagesForPrintingAndDrawToPDF::DelayedReply> reply) 3254 3254 { 3255 if (printInfo.snapshotFirstPage) { 3256 reply->send(1); 3257 IntSize snapshotSize { FloatSize { printInfo.availablePaperWidth, printInfo.availablePaperHeight } }; 3258 IntRect snapshotRect { {0, 0}, snapshotSize }; 3259 auto pdfData = pdfSnapshotAtSize(snapshotRect, snapshotSize, 0); 3260 send(Messages::WebPageProxy::DrawToPDFCallback(IPC::DataReference(CFDataGetBytePtr(pdfData.get()), CFDataGetLength(pdfData.get())), callbackID)); 3261 return; 3262 } 3263 3255 3264 Vector<WebCore::IntRect> pageRects; 3256 3265 double totalScaleFactor; … … 3258 3267 3259 3268 ASSERT(pageRects.size() >= 1); 3260 std::size_t pageCount = p rintInfo.snapshotFirstPage ? 1 : pageRects.size();3269 std::size_t pageCount = pageRects.size(); 3261 3270 ASSERT(pageCount <= std::numeric_limits<uint32_t>::max()); 3262 3271 reply->send(pageCount);
Note:
See TracChangeset
for help on using the changeset viewer.