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

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

Issue 2751433002: [SPv2] Flatten property trees in PaintRecordBuilder into a single display list. (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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 #include "third_party/skia/include/core/SkImage.h" 100 #include "third_party/skia/include/core/SkImage.h"
101 #include "wtf/PtrUtil.h" 101 #include "wtf/PtrUtil.h"
102 #include "wtf/StdLibExtras.h" 102 #include "wtf/StdLibExtras.h"
103 103
104 namespace blink { 104 namespace blink {
105 105
106 using namespace HTMLNames; 106 using namespace HTMLNames;
107 107
108 namespace { 108 namespace {
109 109
110 // Convenience class for initializing a GraphicsContext to build a DragImage 110 // Converts from bounds in CSS space to device space based on the given
111 // from a specific region specified by |bounds|. After painting the using 111 // frame.
112 // context(), the DragImage returned from createImage() will only contain the 112 static FloatRect deviceSpaceBounds(const FloatRect cssBounds,
113 // content in |bounds| with the appropriate device scale factor included. 113 const LocalFrame& frame) {
114 class DragImageBuilder { 114 float deviceScaleFactor = frame.page()->deviceScaleFactorDeprecated();
115 STACK_ALLOCATED(); 115 float pageScaleFactor = frame.page()->visualViewport().scale();
116 FloatRect deviceBounds(cssBounds);
117 deviceBounds.setWidth(cssBounds.width() * deviceScaleFactor *
118 pageScaleFactor);
119 deviceBounds.setHeight(cssBounds.height() * deviceScaleFactor *
120 pageScaleFactor);
121 return deviceBounds;
122 }
116 123
117 public: 124 // Returns a DragImage whose bitmap contains |contents|, positioned and scaled
118 DragImageBuilder(const LocalFrame& localFrame, const FloatRect& bounds) 125 // in device space.
119 : m_localFrame(&localFrame), m_bounds(bounds) { 126 static std::unique_ptr<DragImage> createDragImage(
120 // TODO(oshima): Remove this when all platforms are migrated to 127 const LocalFrame& frame,
121 // use-zoom-for-dsf. 128 float opacity,
122 float deviceScaleFactor = 129 RespectImageOrientationEnum imageOrientation,
123 m_localFrame->page()->deviceScaleFactorDeprecated(); 130 const FloatRect& cssBounds,
124 float pageScaleFactor = m_localFrame->page()->visualViewport().scale(); 131 sk_sp<PaintRecord> contents) {
125 m_bounds.setWidth(m_bounds.width() * deviceScaleFactor * pageScaleFactor); 132 float deviceScaleFactor = frame.page()->deviceScaleFactorDeprecated();
126 m_bounds.setHeight(m_bounds.height() * deviceScaleFactor * pageScaleFactor); 133 float pageScaleFactor = frame.page()->visualViewport().scale();
127 m_builder = WTF::wrapUnique(new PaintRecordBuilder(
128 SkRect::MakeIWH(m_bounds.width(), m_bounds.height())));
129 134
130 AffineTransform transform; 135 FloatRect deviceBounds = deviceSpaceBounds(cssBounds, frame);
131 transform.scale(deviceScaleFactor * pageScaleFactor,
132 deviceScaleFactor * pageScaleFactor);
133 transform.translate(-m_bounds.x(), -m_bounds.y());
134 context().getPaintController().createAndAppend<BeginTransformDisplayItem>(
135 *m_builder, transform);
136 }
137 136
138 GraphicsContext& context() { return m_builder->context(); } 137 AffineTransform transform;
138 transform.scale(deviceScaleFactor * pageScaleFactor);
139 transform.translate(-deviceBounds.x(), -deviceBounds.y());
139 140
140 std::unique_ptr<DragImage> createImage( 141 PaintRecorder recorder;
141 float opacity, 142 PaintCanvas* canvas = recorder.beginRecording(deviceBounds);
142 RespectImageOrientationEnum imageOrientation = 143 canvas->concat(affineTransformToSkMatrix(transform));
143 DoNotRespectImageOrientation) { 144 canvas->drawPicture(contents);
144 context().getPaintController().endItem<EndTransformDisplayItem>(*m_builder);
145 // TODO(fmalita): endRecording() should return a non-const SKP.
146 sk_sp<PaintRecord> record(
147 const_cast<PaintRecord*>(m_builder->endRecording().release()));
148 145
149 // Rasterize upfront, since DragImage::create() is going to do it anyway 146 // Rasterize upfront, since DragImage::create() is going to do it anyway
150 // (SkImage::asLegacyBitmap). 147 // (SkImage::asLegacyBitmap).
151 SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry); 148 SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry);
152 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( 149 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(
153 m_bounds.width(), m_bounds.height(), &surfaceProps); 150 deviceBounds.width(), deviceBounds.height(), &surfaceProps);
154 if (!surface) 151 if (!surface)
155 return nullptr; 152 return nullptr;
153 recorder.finishRecordingAsPicture()->playback(surface->getCanvas());
154 RefPtr<Image> image = StaticBitmapImage::create(surface->makeImageSnapshot());
155 float screenDeviceScaleFactor =
156 frame.page()->chromeClient().screenInfo().deviceScaleFactor;
156 157
157 record->playback(surface->getCanvas()); 158 return DragImage::create(image.get(), imageOrientation,
158 RefPtr<Image> image = 159 screenDeviceScaleFactor, InterpolationHigh, opacity);
159 StaticBitmapImage::create(surface->makeImageSnapshot()); 160 }
160
161 float screenDeviceScaleFactor =
162 m_localFrame->page()->chromeClient().screenInfo().deviceScaleFactor;
163
164 return DragImage::create(image.get(), imageOrientation,
165 screenDeviceScaleFactor, InterpolationHigh,
166 opacity);
167 }
168
169 private:
170 const Member<const LocalFrame> m_localFrame;
171 FloatRect m_bounds;
172 std::unique_ptr<PaintRecordBuilder> m_builder;
173 };
174 161
175 class DraggedNodeImageBuilder { 162 class DraggedNodeImageBuilder {
176 STACK_ALLOCATED(); 163 STACK_ALLOCATED();
177 164
178 public: 165 public:
179 DraggedNodeImageBuilder(const LocalFrame& localFrame, Node& node) 166 DraggedNodeImageBuilder(const LocalFrame& localFrame, Node& node)
180 : m_localFrame(&localFrame), 167 : m_localFrame(&localFrame),
181 m_node(&node) 168 m_node(&node)
182 #if DCHECK_IS_ON() 169 #if DCHECK_IS_ON()
183 , 170 ,
(...skipping 27 matching lines...) Expand all
211 // stacking context which stacked below. 198 // stacking context which stacked below.
212 PaintLayer* layer = draggedLayoutObject->enclosingLayer(); 199 PaintLayer* layer = draggedLayoutObject->enclosingLayer();
213 if (!layer->stackingNode()->isStackingContext()) 200 if (!layer->stackingNode()->isStackingContext())
214 layer = layer->stackingNode()->ancestorStackingContextNode()->layer(); 201 layer = layer->stackingNode()->ancestorStackingContextNode()->layer();
215 IntRect absoluteBoundingBox = 202 IntRect absoluteBoundingBox =
216 draggedLayoutObject->absoluteBoundingBoxRectIncludingDescendants(); 203 draggedLayoutObject->absoluteBoundingBoxRectIncludingDescendants();
217 FloatRect boundingBox = 204 FloatRect boundingBox =
218 layer->layoutObject() 205 layer->layoutObject()
219 .absoluteToLocalQuad(FloatQuad(absoluteBoundingBox), UseTransforms) 206 .absoluteToLocalQuad(FloatQuad(absoluteBoundingBox), UseTransforms)
220 .boundingBox(); 207 .boundingBox();
221 DragImageBuilder dragImageBuilder(*m_localFrame, boundingBox); 208 PaintLayerPaintingInfo paintingInfo(layer, LayoutRect(boundingBox),
222 { 209 GlobalPaintFlattenCompositingLayers,
223 PaintLayerPaintingInfo paintingInfo(layer, LayoutRect(boundingBox), 210 LayoutSize());
224 GlobalPaintFlattenCompositingLayers, 211 PaintLayerFlags flags = PaintLayerHaveTransparency |
225 LayoutSize()); 212 PaintLayerAppliedTransform |
226 PaintLayerFlags flags = PaintLayerHaveTransparency | 213 PaintLayerUncachedClipRects;
227 PaintLayerAppliedTransform | 214 PaintRecordBuilder builder(deviceSpaceBounds(boundingBox, *m_localFrame));
228 PaintLayerUncachedClipRects; 215 PaintLayerPainter(*layer).paint(builder.context(), paintingInfo, flags);
229 PaintLayerPainter(*layer).paint(dragImageBuilder.context(), paintingInfo, 216 return createDragImage(
230 flags); 217 *m_localFrame, 1.0f,
231 } 218 LayoutObject::shouldRespectImageOrientation(draggedLayoutObject),
232 return dragImageBuilder.createImage( 219 boundingBox, builder.endRecording());
233 1.0f, LayoutObject::shouldRespectImageOrientation(draggedLayoutObject));
234 } 220 }
235 221
236 private: 222 private:
237 const Member<const LocalFrame> m_localFrame; 223 const Member<const LocalFrame> m_localFrame;
238 const Member<Node> m_node; 224 const Member<Node> m_node;
239 #if DCHECK_IS_ON() 225 #if DCHECK_IS_ON()
240 const uint64_t m_domTreeVersion; 226 const uint64_t m_domTreeVersion;
241 #endif 227 #endif
242 }; 228 };
243 229
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 } 707 }
722 708
723 std::unique_ptr<DragImage> LocalFrame::dragImageForSelection(float opacity) { 709 std::unique_ptr<DragImage> LocalFrame::dragImageForSelection(float opacity) {
724 if (!selection().computeVisibleSelectionInDOMTreeDeprecated().isRange()) 710 if (!selection().computeVisibleSelectionInDOMTreeDeprecated().isRange())
725 return nullptr; 711 return nullptr;
726 712
727 m_view->updateAllLifecyclePhasesExceptPaint(); 713 m_view->updateAllLifecyclePhasesExceptPaint();
728 ASSERT(document()->isActive()); 714 ASSERT(document()->isActive());
729 715
730 FloatRect paintingRect = FloatRect(selection().bounds()); 716 FloatRect paintingRect = FloatRect(selection().bounds());
731 DragImageBuilder dragImageBuilder(*this, paintingRect);
732 GlobalPaintFlags paintFlags = 717 GlobalPaintFlags paintFlags =
733 GlobalPaintSelectionOnly | GlobalPaintFlattenCompositingLayers; 718 GlobalPaintSelectionOnly | GlobalPaintFlattenCompositingLayers;
734 m_view->paintContents(dragImageBuilder.context(), paintFlags, 719
720 PaintRecordBuilder builder(deviceSpaceBounds(paintingRect, *this));
721 m_view->paintContents(builder.context(), paintFlags,
735 enclosingIntRect(paintingRect)); 722 enclosingIntRect(paintingRect));
736 return dragImageBuilder.createImage(opacity); 723 return createDragImage(*this, opacity, DoNotRespectImageOrientation,
724 paintingRect, builder.endRecording());
737 } 725 }
738 726
739 String LocalFrame::selectedText() const { 727 String LocalFrame::selectedText() const {
740 return selection().selectedText(); 728 return selection().selectedText();
741 } 729 }
742 730
743 String LocalFrame::selectedTextForClipboard() const { 731 String LocalFrame::selectedTextForClipboard() const {
744 if (!document()) 732 if (!document())
745 return emptyString; 733 return emptyString;
746 DCHECK(!document()->needsLayoutTreeUpdate()); 734 DCHECK(!document()->needsLayoutTreeUpdate());
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext()) 902 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext())
915 m_frame->client()->frameBlameContext()->Enter(); 903 m_frame->client()->frameBlameContext()->Enter();
916 } 904 }
917 905
918 ScopedFrameBlamer::~ScopedFrameBlamer() { 906 ScopedFrameBlamer::~ScopedFrameBlamer() {
919 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext()) 907 if (m_frame && m_frame->client() && m_frame->client()->frameBlameContext())
920 m_frame->client()->frameBlameContext()->Leave(); 908 m_frame->client()->frameBlameContext()->Leave();
921 } 909 }
922 910
923 } // namespace blink 911 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698