Changeset 278565 in webkit
- Timestamp:
- Jun 7, 2021, 11:53:54 AM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 10 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/inspector/agents/InspectorPageAgent.cpp (modified) (1 diff)
-
WebCore/page/FrameSnapshotting.cpp (modified) (9 diffs)
-
WebCore/page/FrameSnapshotting.h (modified) (2 diffs)
-
WebCore/page/PageColorSampler.cpp (modified) (1 diff)
-
WebCore/page/PageConsoleClient.cpp (modified) (1 diff)
-
WebCore/page/TextIndicator.cpp (modified) (4 diffs)
-
WebCore/platform/DragImage.cpp (modified) (3 diffs)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/WebProcess/WebPage/WebFrame.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r278563 r278565 1 2021-06-07 Devin Rousso <drousso@apple.com> 2 3 Convert WebCore::SnapshotOptions into an enum class 4 https://bugs.webkit.org/show_bug.cgi?id=226730 5 6 Reviewed by Wenson Hsieh. 7 8 Convert `SnapshotOptions` into an `enum class SnapshotFlags` and create a container `struct 9 SnapshotOptions` that also allows for changing the `DestinationColorSpace` (defaults to sRGB) 10 and `PixelFormat` (defaults to BGRA8). 11 12 No behavior change. 13 14 * page/FrameSnapshotting.h: 15 * page/FrameSnapshotting.cpp: 16 (WebCore::snapshotFrameRect): 17 (WebCore::snapshotFrameRectWithClip): 18 (WebCore::snapshotSelection): 19 (WebCore::snapshotNode): 20 21 * inspector/agents/InspectorPageAgent.cpp: 22 (WebCore::InspectorPageAgent::snapshotRect): 23 * page/PageColorSampler.cpp: 24 (WebCore::sampleColor): 25 * page/PageConsoleClient.cpp: 26 (WebCore::PageConsoleClient::screenshot): 27 * page/TextIndicator.cpp: 28 (WebCore::snapshotOptionsForTextIndicatorOptions): 29 (WebCore::takeSnapshot): 30 (WebCore::takeSnapshots): 31 * platform/DragImage.cpp: 32 (WebCore::createDragImageForSelection): 33 (WebCore::createDragImageForRange): 34 1 35 2021-06-07 Imanol Fernandez <ifernandez@igalia.com> 2 36 -
trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp
r278516 r278565 1082 1082 Protocol::ErrorStringOr<String> InspectorPageAgent::snapshotRect(int x, int y, int width, int height, Protocol::Page::CoordinateSystem coordinateSystem) 1083 1083 { 1084 SnapshotOptions options = SnapshotOptionsNone;1084 SnapshotOptions options; 1085 1085 if (coordinateSystem == Protocol::Page::CoordinateSystem::Viewport) 1086 options |= SnapshotOptionsInViewCoordinates;1086 options.flags.add(SnapshotFlags::InViewCoordinates); 1087 1087 1088 1088 IntRect rectangle(x, y, width, height); 1089 auto snapshot = snapshotFrameRect(m_inspectedPage.mainFrame(), rectangle, options);1089 auto snapshot = snapshotFrameRect(m_inspectedPage.mainFrame(), rectangle, WTFMove(options)); 1090 1090 1091 1091 if (!snapshot) -
trunk/Source/WebCore/page/FrameSnapshotting.cpp
r277986 r278565 32 32 #include "FrameSnapshotting.h" 33 33 34 #include "DestinationColorSpace.h" 34 35 #include "Document.h" 35 36 #include "FloatRect.h" … … 40 41 #include "ImageBuffer.h" 41 42 #include "Page.h" 43 #include "PixelFormat.h" 42 44 #include "RenderObject.h" 43 45 #include "Settings.h" 46 #include <wtf/OptionSet.h> 44 47 45 48 namespace WebCore { … … 68 71 }; 69 72 70 RefPtr<ImageBuffer> snapshotFrameRect(Frame& frame, const IntRect& imageRect, SnapshotOptions options)73 RefPtr<ImageBuffer> snapshotFrameRect(Frame& frame, const IntRect& imageRect, SnapshotOptions&& options) 71 74 { 72 75 Vector<FloatRect> clipRects; 73 return snapshotFrameRectWithClip(frame, imageRect, clipRects, options);76 return snapshotFrameRectWithClip(frame, imageRect, clipRects, WTFMove(options)); 74 77 } 75 78 76 RefPtr<ImageBuffer> snapshotFrameRectWithClip(Frame& frame, const IntRect& imageRect, const Vector<FloatRect>& clipRects, SnapshotOptions options)79 RefPtr<ImageBuffer> snapshotFrameRectWithClip(Frame& frame, const IntRect& imageRect, const Vector<FloatRect>& clipRects, SnapshotOptions&& options) 77 80 { 78 81 if (!frame.page()) … … 82 85 83 86 FrameView::SelectionInSnapshot shouldIncludeSelection = FrameView::IncludeSelection; 84 if (options & SnapshotOptionsExcludeSelectionHighlighting)87 if (options.flags.contains(SnapshotFlags::ExcludeSelectionHighlighting)) 85 88 shouldIncludeSelection = FrameView::ExcludeSelection; 86 89 87 90 FrameView::CoordinateSpaceForSnapshot coordinateSpace = FrameView::DocumentCoordinates; 88 if (options & SnapshotOptionsInViewCoordinates)91 if (options.flags.contains(SnapshotFlags::InViewCoordinates)) 89 92 coordinateSpace = FrameView::ViewCoordinates; 90 93 … … 92 95 93 96 auto paintBehavior = state.paintBehavior; 94 if (options & SnapshotOptionsForceBlackText)97 if (options.flags.contains(SnapshotFlags::ForceBlackText)) 95 98 paintBehavior.add(PaintBehavior::ForceBlackText); 96 if (options & SnapshotOptionsPaintSelectionOnly)99 if (options.flags.contains(SnapshotFlags::PaintSelectionOnly)) 97 100 paintBehavior.add(PaintBehavior::SelectionOnly); 98 if (options & SnapshotOptionsPaintSelectionAndBackgroundsOnly)101 if (options.flags.contains(SnapshotFlags::PaintSelectionAndBackgroundsOnly)) 99 102 paintBehavior.add(PaintBehavior::SelectionAndBackgroundsOnly); 100 if (options & SnapshotOptionsPaintEverythingExcludingSelection)103 if (options.flags.contains(SnapshotFlags::PaintEverythingExcludingSelection)) 101 104 paintBehavior.add(PaintBehavior::ExcludeSelection); 102 105 … … 109 112 scaleFactor *= frame.page()->pageScaleFactor(); 110 113 111 if (options & SnapshotOptionsPaintWithIntegralScaleFactor)114 if (options.flags.contains(SnapshotFlags::PaintWithIntegralScaleFactor)) 112 115 scaleFactor = ceilf(scaleFactor); 113 116 114 auto buffer = ImageBuffer::create(imageRect.size(), RenderingMode::Unaccelerated, scaleFactor, DestinationColorSpace::SRGB(), PixelFormat::BGRA8);117 auto buffer = ImageBuffer::create(imageRect.size(), RenderingMode::Unaccelerated, scaleFactor, options.colorSpace.value_or(DestinationColorSpace::SRGB()), options.pixelFormat.value_or(PixelFormat::BGRA8)); 115 118 if (!buffer) 116 119 return nullptr; … … 128 131 } 129 132 130 RefPtr<ImageBuffer> snapshotSelection(Frame& frame, SnapshotOptions options)133 RefPtr<ImageBuffer> snapshotSelection(Frame& frame, SnapshotOptions&& options) 131 134 { 132 135 auto& selection = frame.selection(); … … 141 144 return nullptr; 142 145 143 options |= SnapshotOptionsPaintSelectionOnly;144 return snapshotFrameRect(frame, enclosingIntRect(selectionBounds), options);146 options.flags.add(SnapshotFlags::PaintSelectionOnly); 147 return snapshotFrameRect(frame, enclosingIntRect(selectionBounds), WTFMove(options)); 145 148 } 146 149 147 RefPtr<ImageBuffer> snapshotNode(Frame& frame, Node& node )150 RefPtr<ImageBuffer> snapshotNode(Frame& frame, Node& node, SnapshotOptions&& options) 148 151 { 149 152 if (!node.renderer()) … … 156 159 157 160 LayoutRect topLevelRect; 158 return snapshotFrameRect(frame, snappedIntRect(node.renderer()->paintingRootRect(topLevelRect)) );161 return snapshotFrameRect(frame, snappedIntRect(node.renderer()->paintingRootRect(topLevelRect)), WTFMove(options)); 159 162 } 160 163 -
trunk/Source/WebCore/page/FrameSnapshotting.h
r269323 r278565 31 31 32 32 #include <memory> 33 #include <optional> 33 34 #include <wtf/Forward.h> 34 35 35 36 namespace WebCore { 36 37 38 class DestinationColorSpace; 37 39 class FloatRect; 38 40 class Frame; … … 40 42 class ImageBuffer; 41 43 class Node; 44 enum class PixelFormat : uint8_t; 42 45 43 enum { 44 SnapshotOptionsNone = 0, 45 SnapshotOptionsExcludeSelectionHighlighting = 1 << 0, 46 SnapshotOptionsPaintSelectionOnly = 1 << 1, 47 SnapshotOptionsInViewCoordinates = 1 << 2, 48 SnapshotOptionsForceBlackText = 1 << 3, 49 SnapshotOptionsPaintSelectionAndBackgroundsOnly = 1 << 4, 50 SnapshotOptionsPaintEverythingExcludingSelection = 1 << 5, 51 SnapshotOptionsPaintWithIntegralScaleFactor = 1 << 6, 46 enum class SnapshotFlags : uint8_t { 47 ExcludeSelectionHighlighting = 1 << 0, 48 PaintSelectionOnly = 1 << 1, 49 InViewCoordinates = 1 << 2, 50 ForceBlackText = 1 << 3, 51 PaintSelectionAndBackgroundsOnly = 1 << 4, 52 PaintEverythingExcludingSelection = 1 << 5, 53 PaintWithIntegralScaleFactor = 1 << 6, 52 54 }; 53 typedef unsigned SnapshotOptions;54 55 55 WEBCORE_EXPORT RefPtr<ImageBuffer> snapshotFrameRect(Frame&, const IntRect&, SnapshotOptions = SnapshotOptionsNone); 56 RefPtr<ImageBuffer> snapshotFrameRectWithClip(Frame&, const IntRect&, const Vector<FloatRect>& clipRects, SnapshotOptions = SnapshotOptionsNone); 57 RefPtr<ImageBuffer> snapshotNode(Frame&, Node&); 58 WEBCORE_EXPORT RefPtr<ImageBuffer> snapshotSelection(Frame&, SnapshotOptions = SnapshotOptionsNone); 56 struct SnapshotOptions { 57 OptionSet<SnapshotFlags> flags { }; 58 std::optional<PixelFormat> pixelFormat { }; 59 std::optional<DestinationColorSpace> colorSpace { }; 60 }; 61 62 WEBCORE_EXPORT RefPtr<ImageBuffer> snapshotFrameRect(Frame&, const IntRect&, SnapshotOptions&& = { }); 63 RefPtr<ImageBuffer> snapshotFrameRectWithClip(Frame&, const IntRect&, const Vector<FloatRect>& clipRects, SnapshotOptions&& = { }); 64 RefPtr<ImageBuffer> snapshotNode(Frame&, Node&, SnapshotOptions&& = { }); 65 WEBCORE_EXPORT RefPtr<ImageBuffer> snapshotSelection(Frame&, SnapshotOptions&& = { }); 59 66 60 67 } // namespace WebCore -
trunk/Source/WebCore/page/PageColorSampler.cpp
r278340 r278565 117 117 return std::nullopt; 118 118 119 // FIXME: <https://webkit.org/b/225942> (Sampled Page Top Color: support sampling non-RGB values like P3) 120 auto colorSpace = DestinationColorSpace::SRGB(); 121 119 122 ASSERT(document.view()); 120 auto snapshot = snapshotFrameRect(document.view()->frame(), IntRect(location, IntSize(1, 1)), SnapshotOptionsExcludeSelectionHighlighting | SnapshotOptionsPaintEverythingExcludingSelection);123 auto snapshot = snapshotFrameRect(document.view()->frame(), IntRect(location, IntSize(1, 1)), { { SnapshotFlags::ExcludeSelectionHighlighting, SnapshotFlags::PaintEverythingExcludingSelection }, PixelFormat::BGRA8, colorSpace }); 121 124 if (!snapshot) 122 125 return std::nullopt; 123 126 124 auto pixelBuffer = snapshot->getPixelBuffer({ AlphaPremultiplication::Unpremultiplied, PixelFormat::BGRA8, DestinationColorSpace::SRGB()}, { { }, snapshot->logicalSize() });127 auto pixelBuffer = snapshot->getPixelBuffer({ AlphaPremultiplication::Unpremultiplied, PixelFormat::BGRA8, colorSpace }, { { }, snapshot->logicalSize() }); 125 128 if (!pixelBuffer) 126 129 return std::nullopt; -
trunk/Source/WebCore/page/PageConsoleClient.cpp
r278253 r278565 405 405 // If no target is provided, capture an image of the viewport. 406 406 IntRect imageRect(IntPoint::zero(), m_page.mainFrame().view()->sizeForVisibleContent()); 407 if (auto snapshot = WebCore::snapshotFrameRect(m_page.mainFrame(), imageRect, SnapshotOptionsInViewCoordinates))407 if (auto snapshot = WebCore::snapshotFrameRect(m_page.mainFrame(), imageRect, { { SnapshotFlags::InViewCoordinates } })) 408 408 dataURL = snapshot->toDataURL("image/png"_s, std::nullopt, PreserveResolution::Yes); 409 409 } -
trunk/Source/WebCore/page/TextIndicator.cpp
r276331 r278565 128 128 static SnapshotOptions snapshotOptionsForTextIndicatorOptions(OptionSet<TextIndicatorOption> options) 129 129 { 130 SnapshotOptions snapshotOptions = SnapshotOptionsPaintWithIntegralScaleFactor; 130 SnapshotOptions snapshotOptions; 131 snapshotOptions.flags.add(SnapshotFlags::PaintWithIntegralScaleFactor); 131 132 132 133 if (!options.contains(TextIndicatorOption::PaintAllContent)) { 133 134 if (options.contains(TextIndicatorOption::PaintBackgrounds)) 134 snapshotOptions |= SnapshotOptionsPaintSelectionAndBackgroundsOnly;135 snapshotOptions.flags.add(SnapshotFlags::PaintSelectionAndBackgroundsOnly); 135 136 else { 136 snapshotOptions |= SnapshotOptionsPaintSelectionOnly;137 snapshotOptions.flags.add(SnapshotFlags::PaintSelectionOnly); 137 138 138 139 if (!options.contains(TextIndicatorOption::RespectTextColor)) 139 snapshotOptions |= SnapshotOptionsForceBlackText;140 snapshotOptions.flags.add(SnapshotFlags::ForceBlackText); 140 141 } 141 142 } else 142 snapshotOptions |= SnapshotOptionsExcludeSelectionHighlighting;143 snapshotOptions.flags.add(SnapshotFlags::ExcludeSelectionHighlighting); 143 144 144 145 return snapshotOptions; 145 146 } 146 147 147 static RefPtr<Image> takeSnapshot(Frame& frame, IntRect rect, SnapshotOptions options, float& scaleFactor, const Vector<FloatRect>& clipRectsInDocumentCoordinates)148 { 149 auto buffer = snapshotFrameRectWithClip(frame, rect, clipRectsInDocumentCoordinates, options);148 static RefPtr<Image> takeSnapshot(Frame& frame, IntRect rect, SnapshotOptions&& options, float& scaleFactor, const Vector<FloatRect>& clipRectsInDocumentCoordinates) 149 { 150 auto buffer = snapshotFrameRectWithClip(frame, rect, clipRectsInDocumentCoordinates, WTFMove(options)); 150 151 if (!buffer) 151 152 return nullptr; … … 156 157 static bool takeSnapshots(TextIndicatorData& data, Frame& frame, IntRect snapshotRect, const Vector<FloatRect>& clipRectsInDocumentCoordinates) 157 158 { 158 SnapshotOptions snapshotOptions = snapshotOptionsForTextIndicatorOptions(data.options); 159 160 data.contentImage = takeSnapshot(frame, snapshotRect, snapshotOptions, data.contentImageScaleFactor, clipRectsInDocumentCoordinates); 159 data.contentImage = takeSnapshot(frame, snapshotRect, snapshotOptionsForTextIndicatorOptions(data.options), data.contentImageScaleFactor, clipRectsInDocumentCoordinates); 161 160 if (!data.contentImage) 162 161 return false; … … 164 163 if (data.options.contains(TextIndicatorOption::IncludeSnapshotWithSelectionHighlight)) { 165 164 float snapshotScaleFactor; 166 data.contentImageWithHighlight = takeSnapshot(frame, snapshotRect, SnapshotOptionsNone, snapshotScaleFactor, clipRectsInDocumentCoordinates);165 data.contentImageWithHighlight = takeSnapshot(frame, snapshotRect, { }, snapshotScaleFactor, clipRectsInDocumentCoordinates); 167 166 ASSERT(!data.contentImageWithHighlight || data.contentImageScaleFactor >= snapshotScaleFactor); 168 167 } … … 171 170 float snapshotScaleFactor; 172 171 auto snapshotRect = frame.view()->visibleContentRect(); 173 data.contentImageWithoutSelection = takeSnapshot(frame, snapshotRect, SnapshotOptionsPaintEverythingExcludingSelection, snapshotScaleFactor, { });172 data.contentImageWithoutSelection = takeSnapshot(frame, snapshotRect, { { SnapshotFlags::PaintEverythingExcludingSelection } }, snapshotScaleFactor, { }); 174 173 data.contentImageWithoutSelectionRectInRootViewCoordinates = frame.view()->contentsToRootView(snapshotRect); 175 174 } -
trunk/Source/WebCore/platform/DragImage.cpp
r278253 r278565 127 127 DragImageRef createDragImageForSelection(Frame& frame, TextIndicatorData&, bool forceBlackText) 128 128 { 129 SnapshotOptions options = forceBlackText ? SnapshotOptionsForceBlackText : SnapshotOptionsNone; 130 return createDragImageFromSnapshot(snapshotSelection(frame, options), nullptr); 129 SnapshotOptions options; 130 if (forceBlackText) 131 options.flags.add(SnapshotFlags::ForceBlackText); 132 return createDragImageFromSnapshot(snapshotSelection(frame, WTFMove(options)), nullptr); 131 133 } 132 134 … … 183 185 return nullptr; 184 186 185 SnapshotOptions options = SnapshotOptionsPaintSelectionOnly | (forceBlackText ? SnapshotOptionsForceBlackText : SnapshotOptionsNone); 187 SnapshotOptions options; 188 options.flags.add(SnapshotFlags::PaintSelectionOnly); 189 if (forceBlackText) 190 options.flags.add(SnapshotFlags::ForceBlackText); 191 186 192 int startOffset = start.deprecatedEditingOffset(); 187 193 int endOffset = end.deprecatedEditingOffset(); … … 190 196 // We capture using snapshotFrameRect() because we fake up the selection using 191 197 // FrameView but snapshotSelection() uses the selection from the Frame itself. 192 return createDragImageFromSnapshot(snapshotFrameRect(frame, view->selection().boundsClippedToVisibleContent(), options), nullptr);198 return createDragImageFromSnapshot(snapshotFrameRect(frame, view->selection().boundsClippedToVisibleContent(), WTFMove(options)), nullptr); 193 199 } 194 200 -
trunk/Source/WebKit/ChangeLog
r278560 r278565 1 2021-06-07 Devin Rousso <drousso@apple.com> 2 3 Convert WebCore::SnapshotOptions into an enum class 4 https://bugs.webkit.org/show_bug.cgi?id=226730 5 6 Reviewed by Wenson Hsieh. 7 8 Convert `SnapshotOptions` into an `enum class SnapshotFlags` and create a container `struct 9 SnapshotOptions` that also allows for changing the `DestinationColorSpace` (defaults to sRGB) 10 and `PixelFormat` (defaults to BGRA8). 11 12 No behavior change. 13 14 * WebProcess/WebPage/WebFrame.cpp: 15 (WebKit::WebFrame::createSelectionSnapshot const): 16 1 17 2021-06-07 Wenson Hsieh <wenson_hsieh@apple.com> 2 18 -
trunk/Source/WebKit/WebProcess/WebPage/WebFrame.cpp
r278253 r278565 843 843 RefPtr<ShareableBitmap> WebFrame::createSelectionSnapshot() const 844 844 { 845 auto snapshot = snapshotSelection(*coreFrame(), WebCore::SnapshotOptionsForceBlackText);845 auto snapshot = snapshotSelection(*coreFrame(), { { WebCore::SnapshotFlags::ForceBlackText } }); 846 846 if (!snapshot) 847 847 return nullptr;
Note:
See TracChangeset
for help on using the changeset viewer.