Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: Source/core/frame/LocalFrame.cpp

Issue 1290133002: SkImage-ify DragImage (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: expectations Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/frame/LocalFrame.h ('k') | Source/core/page/DragController.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 * 1999 Lars Knoll <knoll@kde.org> 3 * 1999 Lars Knoll <knoll@kde.org>
4 * 1999 Antti Koivisto <koivisto@kde.org> 4 * 1999 Antti Koivisto <koivisto@kde.org>
5 * 2000 Simon Hausmann <hausmann@kde.org> 5 * 2000 Simon Hausmann <hausmann@kde.org>
6 * 2000 Stefan Schimanski <1Stein@gmx.de> 6 * 2000 Stefan Schimanski <1Stein@gmx.de>
7 * 2001 George Staikos <staikos@kde.org> 7 * 2001 George Staikos <staikos@kde.org>
8 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 8 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
9 * Copyright (C) 2005 Alexey Proskuryakov <ap@nypop.com> 9 * Copyright (C) 2005 Alexey Proskuryakov <ap@nypop.com>
10 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 10 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #include "core/page/Page.h" 61 #include "core/page/Page.h"
62 #include "core/page/scrolling/ScrollingCoordinator.h" 62 #include "core/page/scrolling/ScrollingCoordinator.h"
63 #include "core/paint/DeprecatedPaintLayer.h" 63 #include "core/paint/DeprecatedPaintLayer.h"
64 #include "core/paint/TransformRecorder.h" 64 #include "core/paint/TransformRecorder.h"
65 #include "core/svg/SVGDocumentExtensions.h" 65 #include "core/svg/SVGDocumentExtensions.h"
66 #include "platform/DragImage.h" 66 #include "platform/DragImage.h"
67 #include "platform/PluginScriptForbiddenScope.h" 67 #include "platform/PluginScriptForbiddenScope.h"
68 #include "platform/RuntimeEnabledFeatures.h" 68 #include "platform/RuntimeEnabledFeatures.h"
69 #include "platform/ScriptForbiddenScope.h" 69 #include "platform/ScriptForbiddenScope.h"
70 #include "platform/graphics/GraphicsContext.h" 70 #include "platform/graphics/GraphicsContext.h"
71 #include "platform/graphics/ImageBuffer.h" 71 #include "platform/graphics/StaticBitmapImage.h"
72 #include "platform/graphics/paint/ClipRecorder.h" 72 #include "platform/graphics/paint/ClipRecorder.h"
73 #include "platform/graphics/paint/SkPictureBuilder.h" 73 #include "platform/graphics/paint/SkPictureBuilder.h"
74 #include "platform/text/TextStream.h" 74 #include "platform/text/TextStream.h"
75 #include "third_party/skia/include/core/SkImage.h"
75 #include "wtf/PassOwnPtr.h" 76 #include "wtf/PassOwnPtr.h"
76 #include "wtf/StdLibExtras.h" 77 #include "wtf/StdLibExtras.h"
77 78
78 namespace blink { 79 namespace blink {
79 80
80 using namespace HTMLNames; 81 using namespace HTMLNames;
81 82
82 namespace { 83 namespace {
83 84
84 struct ScopedFramePaintingState { 85 struct ScopedFramePaintingState {
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 { 579 {
579 if (!m_host) 580 if (!m_host)
580 return 0; 581 return 0;
581 582
582 double ratio = m_host->deviceScaleFactor(); 583 double ratio = m_host->deviceScaleFactor();
583 ratio *= pageZoomFactor(); 584 ratio *= pageZoomFactor();
584 return ratio; 585 return ratio;
585 } 586 }
586 587
587 PassOwnPtr<DragImage> LocalFrame::paintIntoDragImage( 588 PassOwnPtr<DragImage> LocalFrame::paintIntoDragImage(
588 const DisplayItemClientWrapper& displayItemClient, DisplayItem::Type clipTyp e, RespectImageOrientationEnum shouldRespectImageOrientation, const GlobalPaintF lags globalPaintFlags, IntRect paintingRect) 589 const DisplayItemClientWrapper& displayItemClient,
590 RespectImageOrientationEnum shouldRespectImageOrientation,
591 const GlobalPaintFlags globalPaintFlags, IntRect paintingRect, float opacity )
589 { 592 {
590 ASSERT(document()->isActive()); 593 ASSERT(document()->isActive());
591 // Not flattening compositing layers will result in a broken image being pai nted. 594 // Not flattening compositing layers will result in a broken image being pai nted.
592 ASSERT(globalPaintFlags & GlobalPaintFlattenCompositingLayers); 595 ASSERT(globalPaintFlags & GlobalPaintFlattenCompositingLayers);
593 596
594 float deviceScaleFactor = m_host->deviceScaleFactor(); 597 float deviceScaleFactor = m_host->deviceScaleFactor();
595 paintingRect.setWidth(paintingRect.width() * deviceScaleFactor); 598 paintingRect.setWidth(paintingRect.width() * deviceScaleFactor);
596 paintingRect.setHeight(paintingRect.height() * deviceScaleFactor); 599 paintingRect.setHeight(paintingRect.height() * deviceScaleFactor);
597 600
598 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(paintingRect.size());
599 if (!buffer)
600 return nullptr;
601
602 SkPictureBuilder pictureBuilder(paintingRect); 601 SkPictureBuilder pictureBuilder(paintingRect);
603 { 602 {
604 GraphicsContext& paintContext = pictureBuilder.context(); 603 GraphicsContext& paintContext = pictureBuilder.context();
605 604
606 AffineTransform transform; 605 AffineTransform transform;
607 transform.scale(deviceScaleFactor, deviceScaleFactor); 606 transform.scale(deviceScaleFactor, deviceScaleFactor);
608 transform.translate(-paintingRect.x(), -paintingRect.y()); 607 transform.translate(-paintingRect.x(), -paintingRect.y());
609 TransformRecorder transformRecorder(paintContext, displayItemClient, tra nsform); 608 TransformRecorder transformRecorder(paintContext, displayItemClient, tra nsform);
610 609
611 ClipRecorder clipRecorder(paintContext, displayItemClient, clipType,
612 LayoutRect(0, 0, paintingRect.maxX(), paintingRect.maxY()));
613
614 m_view->paintContents(&paintContext, globalPaintFlags, paintingRect); 610 m_view->paintContents(&paintContext, globalPaintFlags, paintingRect);
615 611
616 } 612 }
617 RefPtr<const SkPicture> recording = pictureBuilder.endRecording(); 613 RefPtr<const SkPicture> recording = pictureBuilder.endRecording();
618 buffer->canvas()->drawPicture(recording.get()); 614 RefPtr<SkImage> skImage = adoptRef(SkImage::NewFromPicture(recording.get(),
615 SkISize::Make(paintingRect.width(), paintingRect.height()), nullptr, nul lptr));
616 RefPtr<Image> image = StaticBitmapImage::create(skImage.release());
619 617
620 RefPtr<Image> image = buffer->newImageSnapshot(); 618 return DragImage::create(image.get(), shouldRespectImageOrientation, deviceS caleFactor,
621 return DragImage::create(image.get(), shouldRespectImageOrientation, deviceS caleFactor); 619 InterpolationHigh, opacity);
622 } 620 }
623 621
624 PassOwnPtr<DragImage> LocalFrame::nodeImage(Node& node) 622 PassOwnPtr<DragImage> LocalFrame::nodeImage(Node& node)
625 { 623 {
626 if (!node.layoutObject()) 624 if (!node.layoutObject())
627 return nullptr; 625 return nullptr;
628 626
629 const ScopedFramePaintingState state(this, &node); 627 const ScopedFramePaintingState state(this, &node);
630 628
631 m_view->updateAllLifecyclePhases(); 629 m_view->updateAllLifecyclePhases();
632 630
633 m_view->setNodeToDraw(&node); // Enable special sub-tree drawing mode. 631 m_view->setNodeToDraw(&node); // Enable special sub-tree drawing mode.
634 632
635 // Document::updateLayout may have blown away the original LayoutObject. 633 // Document::updateLayout may have blown away the original LayoutObject.
636 LayoutObject* layoutObject = node.layoutObject(); 634 LayoutObject* layoutObject = node.layoutObject();
637 if (!layoutObject) 635 if (!layoutObject)
638 return nullptr; 636 return nullptr;
639 637
640 IntRect rect; 638 IntRect rect;
641 639
642 return paintIntoDragImage(*layoutObject, DisplayItem::ClipNodeImage, layoutO bject->shouldRespectImageOrientation(), GlobalPaintFlattenCompositingLayers, 640 return paintIntoDragImage(*layoutObject, layoutObject->shouldRespectImageOri entation(),
643 layoutObject->paintingRootRect(rect)); 641 GlobalPaintFlattenCompositingLayers, layoutObject->paintingRootRect(rect ));
644 } 642 }
645 643
646 PassOwnPtr<DragImage> LocalFrame::dragImageForSelection() 644 PassOwnPtr<DragImage> LocalFrame::dragImageForSelection(float opacity)
647 { 645 {
648 if (!selection().isRange()) 646 if (!selection().isRange())
649 return nullptr; 647 return nullptr;
650 648
651 const ScopedFramePaintingState state(this, 0); 649 const ScopedFramePaintingState state(this, 0);
652 m_view->updateAllLifecyclePhases(); 650 m_view->updateAllLifecyclePhases();
653 651
654 return paintIntoDragImage(*this, DisplayItem::ClipSelectionImage, DoNotRespe ctImageOrientation, GlobalPaintSelectionOnly | GlobalPaintFlattenCompositingLaye rs, enclosingIntRect(selection().bounds())); 652 return paintIntoDragImage(*this, DoNotRespectImageOrientation,
653 GlobalPaintSelectionOnly | GlobalPaintFlattenCompositingLayers,
654 enclosingIntRect(selection().bounds()), opacity);
655 } 655 }
656 656
657 String LocalFrame::selectedText() const 657 String LocalFrame::selectedText() const
658 { 658 {
659 return selection().selectedText(); 659 return selection().selectedText();
660 } 660 }
661 661
662 String LocalFrame::selectedTextForClipboard() const 662 String LocalFrame::selectedTextForClipboard() const
663 { 663 {
664 return selection().selectedTextForClipboard(); 664 return selection().selectedTextForClipboard();
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 { 844 {
845 if (isLocalRoot()) 845 if (isLocalRoot())
846 m_instrumentingAgents = InstrumentingAgents::create(); 846 m_instrumentingAgents = InstrumentingAgents::create();
847 else 847 else
848 m_instrumentingAgents = localFrameRoot()->m_instrumentingAgents; 848 m_instrumentingAgents = localFrameRoot()->m_instrumentingAgents;
849 } 849 }
850 850
851 DEFINE_WEAK_IDENTIFIER_MAP(LocalFrame); 851 DEFINE_WEAK_IDENTIFIER_MAP(LocalFrame);
852 852
853 } // namespace blink 853 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/frame/LocalFrame.h ('k') | Source/core/page/DragController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698