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

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

Issue 2791043002: Draw recorded content directly into the containing PaintCanvas, when possible. (Closed)
Patch Set: none Created 3 years, 8 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
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 8 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
9 * rights reserved. 9 * rights reserved.
10 * Copyright (C) 2005 Alexey Proskuryakov <ap@nypop.com> 10 * Copyright (C) 2005 Alexey Proskuryakov <ap@nypop.com>
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 return deviceBounds; 121 return deviceBounds;
122 } 122 }
123 123
124 // Returns a DragImage whose bitmap contains |contents|, positioned and scaled 124 // Returns a DragImage whose bitmap contains |contents|, positioned and scaled
125 // in device space. 125 // in device space.
126 static std::unique_ptr<DragImage> createDragImage( 126 static std::unique_ptr<DragImage> createDragImage(
127 const LocalFrame& frame, 127 const LocalFrame& frame,
128 float opacity, 128 float opacity,
129 RespectImageOrientationEnum imageOrientation, 129 RespectImageOrientationEnum imageOrientation,
130 const FloatRect& cssBounds, 130 const FloatRect& cssBounds,
131 sk_sp<PaintRecord> contents) { 131 PaintRecordBuilder& builder,
132 const PropertyTreeState& propertyTreeState) {
132 float deviceScaleFactor = frame.page()->deviceScaleFactorDeprecated(); 133 float deviceScaleFactor = frame.page()->deviceScaleFactorDeprecated();
133 float pageScaleFactor = frame.page()->visualViewport().scale(); 134 float pageScaleFactor = frame.page()->visualViewport().scale();
134 135
135 FloatRect deviceBounds = deviceSpaceBounds(cssBounds, frame); 136 FloatRect deviceBounds = deviceSpaceBounds(cssBounds, frame);
136 137
137 AffineTransform transform; 138 AffineTransform transform;
138 transform.scale(deviceScaleFactor * pageScaleFactor); 139 transform.scale(deviceScaleFactor * pageScaleFactor);
139 transform.translate(-deviceBounds.x(), -deviceBounds.y()); 140 transform.translate(-deviceBounds.x(), -deviceBounds.y());
140 141
141 PaintRecorder recorder;
142 PaintCanvas* canvas = recorder.beginRecording(deviceBounds);
143 canvas->concat(affineTransformToSkMatrix(transform));
144 canvas->drawPicture(contents);
145
146 // Rasterize upfront, since DragImage::create() is going to do it anyway 142 // Rasterize upfront, since DragImage::create() is going to do it anyway
147 // (SkImage::asLegacyBitmap). 143 // (SkImage::asLegacyBitmap).
148 SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry); 144 SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry);
149 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( 145 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(
150 deviceBounds.width(), deviceBounds.height(), &surfaceProps); 146 deviceBounds.width(), deviceBounds.height(), &surfaceProps);
151 if (!surface) 147 if (!surface)
152 return nullptr; 148 return nullptr;
153 recorder.finishRecordingAsPicture()->playback(surface->getCanvas()); 149
150 SkiaPaintCanvas skiaPaintCanvas(surface->getCanvas());
151 skiaPaintCanvas.concat(affineTransformToSkMatrix(transform));
152 builder.endRecording(skiaPaintCanvas, propertyTreeState);
153
154 RefPtr<Image> image = StaticBitmapImage::create(surface->makeImageSnapshot()); 154 RefPtr<Image> image = StaticBitmapImage::create(surface->makeImageSnapshot());
155 float screenDeviceScaleFactor = 155 float screenDeviceScaleFactor =
156 frame.page()->chromeClient().screenInfo().deviceScaleFactor; 156 frame.page()->chromeClient().screenInfo().deviceScaleFactor;
157 157
158 return DragImage::create(image.get(), imageOrientation, 158 return DragImage::create(image.get(), imageOrientation,
159 screenDeviceScaleFactor, InterpolationHigh, opacity); 159 screenDeviceScaleFactor, InterpolationHigh, opacity);
160 } 160 }
161 161
162 class DraggedNodeImageBuilder { 162 class DraggedNodeImageBuilder {
163 STACK_ALLOCATED(); 163 STACK_ALLOCATED();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 PaintRecordBuilder builder(deviceSpaceBounds(boundingBox, *m_localFrame)); 214 PaintRecordBuilder builder(deviceSpaceBounds(boundingBox, *m_localFrame));
215 PaintLayerPainter(*layer).paint(builder.context(), paintingInfo, flags); 215 PaintLayerPainter(*layer).paint(builder.context(), paintingInfo, flags);
216 PropertyTreeState borderBoxProperties = PropertyTreeState::root(); 216 PropertyTreeState borderBoxProperties = PropertyTreeState::root();
217 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { 217 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) {
218 borderBoxProperties = 218 borderBoxProperties =
219 *layer->layoutObject().paintProperties()->localBorderBoxProperties(); 219 *layer->layoutObject().paintProperties()->localBorderBoxProperties();
220 } 220 }
221 return createDragImage( 221 return createDragImage(
222 *m_localFrame, 1.0f, 222 *m_localFrame, 1.0f,
223 LayoutObject::shouldRespectImageOrientation(draggedLayoutObject), 223 LayoutObject::shouldRespectImageOrientation(draggedLayoutObject),
224 boundingBox, builder.endRecording(borderBoxProperties)); 224 boundingBox, builder, borderBoxProperties);
225 } 225 }
226 226
227 private: 227 private:
228 const Member<const LocalFrame> m_localFrame; 228 const Member<const LocalFrame> m_localFrame;
229 const Member<Node> m_node; 229 const Member<Node> m_node;
230 #if DCHECK_IS_ON() 230 #if DCHECK_IS_ON()
231 const uint64_t m_domTreeVersion; 231 const uint64_t m_domTreeVersion;
232 #endif 232 #endif
233 }; 233 };
234 234
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 ASSERT(document()->isActive()); 736 ASSERT(document()->isActive());
737 737
738 FloatRect paintingRect = FloatRect(selection().bounds()); 738 FloatRect paintingRect = FloatRect(selection().bounds());
739 GlobalPaintFlags paintFlags = 739 GlobalPaintFlags paintFlags =
740 GlobalPaintSelectionOnly | GlobalPaintFlattenCompositingLayers; 740 GlobalPaintSelectionOnly | GlobalPaintFlattenCompositingLayers;
741 741
742 PaintRecordBuilder builder(deviceSpaceBounds(paintingRect, *this)); 742 PaintRecordBuilder builder(deviceSpaceBounds(paintingRect, *this));
743 m_view->paintContents(builder.context(), paintFlags, 743 m_view->paintContents(builder.context(), paintFlags,
744 enclosingIntRect(paintingRect)); 744 enclosingIntRect(paintingRect));
745 return createDragImage(*this, opacity, DoNotRespectImageOrientation, 745 return createDragImage(*this, opacity, DoNotRespectImageOrientation,
746 paintingRect, builder.endRecording()); 746 paintingRect, builder, PropertyTreeState::root());
747 } 747 }
748 748
749 String LocalFrame::selectedText() const { 749 String LocalFrame::selectedText() const {
750 return selection().selectedText(); 750 return selection().selectedText();
751 } 751 }
752 752
753 String LocalFrame::selectedTextForClipboard() const { 753 String LocalFrame::selectedTextForClipboard() const {
754 if (!document()) 754 if (!document())
755 return emptyString; 755 return emptyString;
756 DCHECK(!document()->needsLayoutTreeUpdate()); 756 DCHECK(!document()->needsLayoutTreeUpdate());
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext()) 928 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext())
929 m_frame->client()->frameBlameContext()->Enter(); 929 m_frame->client()->frameBlameContext()->Enter();
930 } 930 }
931 931
932 ScopedFrameBlamer::~ScopedFrameBlamer() { 932 ScopedFrameBlamer::~ScopedFrameBlamer() {
933 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext()) 933 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext())
934 m_frame->client()->frameBlameContext()->Leave(); 934 m_frame->client()->frameBlameContext()->Leave();
935 } 935 }
936 936
937 } // namespace blink 937 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698