Diff
Modified: trunk/Source/WebCore/ChangeLog (278564 => 278565)
--- trunk/Source/WebCore/ChangeLog 2021-06-07 18:10:56 UTC (rev 278564)
+++ trunk/Source/WebCore/ChangeLog 2021-06-07 18:53:54 UTC (rev 278565)
@@ -1,3 +1,37 @@
+2021-06-07 Devin Rousso <drou...@apple.com>
+
+ Convert WebCore::SnapshotOptions into an enum class
+ https://bugs.webkit.org/show_bug.cgi?id=226730
+
+ Reviewed by Wenson Hsieh.
+
+ Convert `SnapshotOptions` into an `enum class SnapshotFlags` and create a container `struct
+ SnapshotOptions` that also allows for changing the `DestinationColorSpace` (defaults to sRGB)
+ and `PixelFormat` (defaults to BGRA8).
+
+ No behavior change.
+
+ * page/FrameSnapshotting.h:
+ * page/FrameSnapshotting.cpp:
+ (WebCore::snapshotFrameRect):
+ (WebCore::snapshotFrameRectWithClip):
+ (WebCore::snapshotSelection):
+ (WebCore::snapshotNode):
+
+ * inspector/agents/InspectorPageAgent.cpp:
+ (WebCore::InspectorPageAgent::snapshotRect):
+ * page/PageColorSampler.cpp:
+ (WebCore::sampleColor):
+ * page/PageConsoleClient.cpp:
+ (WebCore::PageConsoleClient::screenshot):
+ * page/TextIndicator.cpp:
+ (WebCore::snapshotOptionsForTextIndicatorOptions):
+ (WebCore::takeSnapshot):
+ (WebCore::takeSnapshots):
+ * platform/DragImage.cpp:
+ (WebCore::createDragImageForSelection):
+ (WebCore::createDragImageForRange):
+
2021-06-07 Imanol Fernandez <ifernan...@igalia.com>
Change WebXRSpace::efectiveOrigin() matrix multiplication order
Modified: trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp (278564 => 278565)
--- trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp 2021-06-07 18:10:56 UTC (rev 278564)
+++ trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp 2021-06-07 18:53:54 UTC (rev 278565)
@@ -1081,12 +1081,12 @@
Protocol::ErrorStringOr<String> InspectorPageAgent::snapshotRect(int x, int y, int width, int height, Protocol::Page::CoordinateSystem coordinateSystem)
{
- SnapshotOptions options = SnapshotOptionsNone;
+ SnapshotOptions options;
if (coordinateSystem == Protocol::Page::CoordinateSystem::Viewport)
- options |= SnapshotOptionsInViewCoordinates;
+ options.flags.add(SnapshotFlags::InViewCoordinates);
IntRect rectangle(x, y, width, height);
- auto snapshot = snapshotFrameRect(m_inspectedPage.mainFrame(), rectangle, options);
+ auto snapshot = snapshotFrameRect(m_inspectedPage.mainFrame(), rectangle, WTFMove(options));
if (!snapshot)
return makeUnexpected("Could not capture snapshot"_s);
Modified: trunk/Source/WebCore/page/FrameSnapshotting.cpp (278564 => 278565)
--- trunk/Source/WebCore/page/FrameSnapshotting.cpp 2021-06-07 18:10:56 UTC (rev 278564)
+++ trunk/Source/WebCore/page/FrameSnapshotting.cpp 2021-06-07 18:53:54 UTC (rev 278565)
@@ -31,6 +31,7 @@
#include "config.h"
#include "FrameSnapshotting.h"
+#include "DestinationColorSpace.h"
#include "Document.h"
#include "FloatRect.h"
#include "Frame.h"
@@ -39,8 +40,10 @@
#include "GraphicsContext.h"
#include "ImageBuffer.h"
#include "Page.h"
+#include "PixelFormat.h"
#include "RenderObject.h"
#include "Settings.h"
+#include <wtf/OptionSet.h>
namespace WebCore {
@@ -67,13 +70,13 @@
const Color backgroundColor;
};
-RefPtr<ImageBuffer> snapshotFrameRect(Frame& frame, const IntRect& imageRect, SnapshotOptions options)
+RefPtr<ImageBuffer> snapshotFrameRect(Frame& frame, const IntRect& imageRect, SnapshotOptions&& options)
{
Vector<FloatRect> clipRects;
- return snapshotFrameRectWithClip(frame, imageRect, clipRects, options);
+ return snapshotFrameRectWithClip(frame, imageRect, clipRects, WTFMove(options));
}
-RefPtr<ImageBuffer> snapshotFrameRectWithClip(Frame& frame, const IntRect& imageRect, const Vector<FloatRect>& clipRects, SnapshotOptions options)
+RefPtr<ImageBuffer> snapshotFrameRectWithClip(Frame& frame, const IntRect& imageRect, const Vector<FloatRect>& clipRects, SnapshotOptions&& options)
{
if (!frame.page())
return nullptr;
@@ -81,23 +84,23 @@
frame.document()->updateLayout();
FrameView::SelectionInSnapshot shouldIncludeSelection = FrameView::IncludeSelection;
- if (options & SnapshotOptionsExcludeSelectionHighlighting)
+ if (options.flags.contains(SnapshotFlags::ExcludeSelectionHighlighting))
shouldIncludeSelection = FrameView::ExcludeSelection;
FrameView::CoordinateSpaceForSnapshot coordinateSpace = FrameView::DocumentCoordinates;
- if (options & SnapshotOptionsInViewCoordinates)
+ if (options.flags.contains(SnapshotFlags::InViewCoordinates))
coordinateSpace = FrameView::ViewCoordinates;
ScopedFramePaintingState state(frame, nullptr);
auto paintBehavior = state.paintBehavior;
- if (options & SnapshotOptionsForceBlackText)
+ if (options.flags.contains(SnapshotFlags::ForceBlackText))
paintBehavior.add(PaintBehavior::ForceBlackText);
- if (options & SnapshotOptionsPaintSelectionOnly)
+ if (options.flags.contains(SnapshotFlags::PaintSelectionOnly))
paintBehavior.add(PaintBehavior::SelectionOnly);
- if (options & SnapshotOptionsPaintSelectionAndBackgroundsOnly)
+ if (options.flags.contains(SnapshotFlags::PaintSelectionAndBackgroundsOnly))
paintBehavior.add(PaintBehavior::SelectionAndBackgroundsOnly);
- if (options & SnapshotOptionsPaintEverythingExcludingSelection)
+ if (options.flags.contains(SnapshotFlags::PaintEverythingExcludingSelection))
paintBehavior.add(PaintBehavior::ExcludeSelection);
// Other paint behaviors are set by paintContentsForSnapshot.
@@ -108,10 +111,10 @@
if (frame.page()->delegatesScaling())
scaleFactor *= frame.page()->pageScaleFactor();
- if (options & SnapshotOptionsPaintWithIntegralScaleFactor)
+ if (options.flags.contains(SnapshotFlags::PaintWithIntegralScaleFactor))
scaleFactor = ceilf(scaleFactor);
- auto buffer = ImageBuffer::create(imageRect.size(), RenderingMode::Unaccelerated, scaleFactor, DestinationColorSpace::SRGB(), PixelFormat::BGRA8);
+ auto buffer = ImageBuffer::create(imageRect.size(), RenderingMode::Unaccelerated, scaleFactor, options.colorSpace.value_or(DestinationColorSpace::SRGB()), options.pixelFormat.value_or(PixelFormat::BGRA8));
if (!buffer)
return nullptr;
buffer->context().translate(-imageRect.x(), -imageRect.y());
@@ -127,7 +130,7 @@
return buffer;
}
-RefPtr<ImageBuffer> snapshotSelection(Frame& frame, SnapshotOptions options)
+RefPtr<ImageBuffer> snapshotSelection(Frame& frame, SnapshotOptions&& options)
{
auto& selection = frame.selection();
@@ -140,11 +143,11 @@
if (selectionBounds.isEmpty())
return nullptr;
- options |= SnapshotOptionsPaintSelectionOnly;
- return snapshotFrameRect(frame, enclosingIntRect(selectionBounds), options);
+ options.flags.add(SnapshotFlags::PaintSelectionOnly);
+ return snapshotFrameRect(frame, enclosingIntRect(selectionBounds), WTFMove(options));
}
-RefPtr<ImageBuffer> snapshotNode(Frame& frame, Node& node)
+RefPtr<ImageBuffer> snapshotNode(Frame& frame, Node& node, SnapshotOptions&& options)
{
if (!node.renderer())
return nullptr;
@@ -155,7 +158,7 @@
frame.view()->setNodeToDraw(&node);
LayoutRect topLevelRect;
- return snapshotFrameRect(frame, snappedIntRect(node.renderer()->paintingRootRect(topLevelRect)));
+ return snapshotFrameRect(frame, snappedIntRect(node.renderer()->paintingRootRect(topLevelRect)), WTFMove(options));
}
} // namespace WebCore
Modified: trunk/Source/WebCore/page/FrameSnapshotting.h (278564 => 278565)
--- trunk/Source/WebCore/page/FrameSnapshotting.h 2021-06-07 18:10:56 UTC (rev 278564)
+++ trunk/Source/WebCore/page/FrameSnapshotting.h 2021-06-07 18:53:54 UTC (rev 278565)
@@ -30,31 +30,38 @@
#pragma once
#include <memory>
+#include <optional>
#include <wtf/Forward.h>
namespace WebCore {
+class DestinationColorSpace;
class FloatRect;
class Frame;
class IntRect;
class ImageBuffer;
class Node;
+enum class PixelFormat : uint8_t;
-enum {
- SnapshotOptionsNone = 0,
- SnapshotOptionsExcludeSelectionHighlighting = 1 << 0,
- SnapshotOptionsPaintSelectionOnly = 1 << 1,
- SnapshotOptionsInViewCoordinates = 1 << 2,
- SnapshotOptionsForceBlackText = 1 << 3,
- SnapshotOptionsPaintSelectionAndBackgroundsOnly = 1 << 4,
- SnapshotOptionsPaintEverythingExcludingSelection = 1 << 5,
- SnapshotOptionsPaintWithIntegralScaleFactor = 1 << 6,
+enum class SnapshotFlags : uint8_t {
+ ExcludeSelectionHighlighting = 1 << 0,
+ PaintSelectionOnly = 1 << 1,
+ InViewCoordinates = 1 << 2,
+ ForceBlackText = 1 << 3,
+ PaintSelectionAndBackgroundsOnly = 1 << 4,
+ PaintEverythingExcludingSelection = 1 << 5,
+ PaintWithIntegralScaleFactor = 1 << 6,
};
-typedef unsigned SnapshotOptions;
-WEBCORE_EXPORT RefPtr<ImageBuffer> snapshotFrameRect(Frame&, const IntRect&, SnapshotOptions = SnapshotOptionsNone);
-RefPtr<ImageBuffer> snapshotFrameRectWithClip(Frame&, const IntRect&, const Vector<FloatRect>& clipRects, SnapshotOptions = SnapshotOptionsNone);
-RefPtr<ImageBuffer> snapshotNode(Frame&, Node&);
-WEBCORE_EXPORT RefPtr<ImageBuffer> snapshotSelection(Frame&, SnapshotOptions = SnapshotOptionsNone);
+struct SnapshotOptions {
+ OptionSet<SnapshotFlags> flags { };
+ std::optional<PixelFormat> pixelFormat { };
+ std::optional<DestinationColorSpace> colorSpace { };
+};
+WEBCORE_EXPORT RefPtr<ImageBuffer> snapshotFrameRect(Frame&, const IntRect&, SnapshotOptions&& = { });
+RefPtr<ImageBuffer> snapshotFrameRectWithClip(Frame&, const IntRect&, const Vector<FloatRect>& clipRects, SnapshotOptions&& = { });
+RefPtr<ImageBuffer> snapshotNode(Frame&, Node&, SnapshotOptions&& = { });
+WEBCORE_EXPORT RefPtr<ImageBuffer> snapshotSelection(Frame&, SnapshotOptions&& = { });
+
} // namespace WebCore
Modified: trunk/Source/WebCore/page/PageColorSampler.cpp (278564 => 278565)
--- trunk/Source/WebCore/page/PageColorSampler.cpp 2021-06-07 18:10:56 UTC (rev 278564)
+++ trunk/Source/WebCore/page/PageColorSampler.cpp 2021-06-07 18:53:54 UTC (rev 278565)
@@ -116,12 +116,15 @@
if (!isValidSampleLocation(document, location))
return std::nullopt;
+ // FIXME: <https://webkit.org/b/225942> (Sampled Page Top Color: support sampling non-RGB values like P3)
+ auto colorSpace = DestinationColorSpace::SRGB();
+
ASSERT(document.view());
- auto snapshot = snapshotFrameRect(document.view()->frame(), IntRect(location, IntSize(1, 1)), SnapshotOptionsExcludeSelectionHighlighting | SnapshotOptionsPaintEverythingExcludingSelection);
+ auto snapshot = snapshotFrameRect(document.view()->frame(), IntRect(location, IntSize(1, 1)), { { SnapshotFlags::ExcludeSelectionHighlighting, SnapshotFlags::PaintEverythingExcludingSelection }, PixelFormat::BGRA8, colorSpace });
if (!snapshot)
return std::nullopt;
- auto pixelBuffer = snapshot->getPixelBuffer({ AlphaPremultiplication::Unpremultiplied, PixelFormat::BGRA8, DestinationColorSpace::SRGB() }, { { }, snapshot->logicalSize() });
+ auto pixelBuffer = snapshot->getPixelBuffer({ AlphaPremultiplication::Unpremultiplied, PixelFormat::BGRA8, colorSpace }, { { }, snapshot->logicalSize() });
if (!pixelBuffer)
return std::nullopt;
Modified: trunk/Source/WebCore/page/PageConsoleClient.cpp (278564 => 278565)
--- trunk/Source/WebCore/page/PageConsoleClient.cpp 2021-06-07 18:10:56 UTC (rev 278564)
+++ trunk/Source/WebCore/page/PageConsoleClient.cpp 2021-06-07 18:53:54 UTC (rev 278565)
@@ -404,7 +404,7 @@
if (!target) {
// If no target is provided, capture an image of the viewport.
IntRect imageRect(IntPoint::zero(), m_page.mainFrame().view()->sizeForVisibleContent());
- if (auto snapshot = WebCore::snapshotFrameRect(m_page.mainFrame(), imageRect, SnapshotOptionsInViewCoordinates))
+ if (auto snapshot = WebCore::snapshotFrameRect(m_page.mainFrame(), imageRect, { { SnapshotFlags::InViewCoordinates } }))
dataURL = snapshot->toDataURL("image/png"_s, std::nullopt, PreserveResolution::Yes);
}
Modified: trunk/Source/WebCore/page/TextIndicator.cpp (278564 => 278565)
--- trunk/Source/WebCore/page/TextIndicator.cpp 2021-06-07 18:10:56 UTC (rev 278564)
+++ trunk/Source/WebCore/page/TextIndicator.cpp 2021-06-07 18:53:54 UTC (rev 278565)
@@ -127,26 +127,27 @@
static SnapshotOptions snapshotOptionsForTextIndicatorOptions(OptionSet<TextIndicatorOption> options)
{
- SnapshotOptions snapshotOptions = SnapshotOptionsPaintWithIntegralScaleFactor;
+ SnapshotOptions snapshotOptions;
+ snapshotOptions.flags.add(SnapshotFlags::PaintWithIntegralScaleFactor);
if (!options.contains(TextIndicatorOption::PaintAllContent)) {
if (options.contains(TextIndicatorOption::PaintBackgrounds))
- snapshotOptions |= SnapshotOptionsPaintSelectionAndBackgroundsOnly;
+ snapshotOptions.flags.add(SnapshotFlags::PaintSelectionAndBackgroundsOnly);
else {
- snapshotOptions |= SnapshotOptionsPaintSelectionOnly;
+ snapshotOptions.flags.add(SnapshotFlags::PaintSelectionOnly);
if (!options.contains(TextIndicatorOption::RespectTextColor))
- snapshotOptions |= SnapshotOptionsForceBlackText;
+ snapshotOptions.flags.add(SnapshotFlags::ForceBlackText);
}
} else
- snapshotOptions |= SnapshotOptionsExcludeSelectionHighlighting;
+ snapshotOptions.flags.add(SnapshotFlags::ExcludeSelectionHighlighting);
return snapshotOptions;
}
-static RefPtr<Image> takeSnapshot(Frame& frame, IntRect rect, SnapshotOptions options, float& scaleFactor, const Vector<FloatRect>& clipRectsInDocumentCoordinates)
+static RefPtr<Image> takeSnapshot(Frame& frame, IntRect rect, SnapshotOptions&& options, float& scaleFactor, const Vector<FloatRect>& clipRectsInDocumentCoordinates)
{
- auto buffer = snapshotFrameRectWithClip(frame, rect, clipRectsInDocumentCoordinates, options);
+ auto buffer = snapshotFrameRectWithClip(frame, rect, clipRectsInDocumentCoordinates, WTFMove(options));
if (!buffer)
return nullptr;
scaleFactor = buffer->resolutionScale();
@@ -155,15 +156,13 @@
static bool takeSnapshots(TextIndicatorData& data, Frame& frame, IntRect snapshotRect, const Vector<FloatRect>& clipRectsInDocumentCoordinates)
{
- SnapshotOptions snapshotOptions = snapshotOptionsForTextIndicatorOptions(data.options);
-
- data.contentImage = takeSnapshot(frame, snapshotRect, snapshotOptions, data.contentImageScaleFactor, clipRectsInDocumentCoordinates);
+ data.contentImage = takeSnapshot(frame, snapshotRect, snapshotOptionsForTextIndicatorOptions(data.options), data.contentImageScaleFactor, clipRectsInDocumentCoordinates);
if (!data.contentImage)
return false;
if (data.options.contains(TextIndicatorOption::IncludeSnapshotWithSelectionHighlight)) {
float snapshotScaleFactor;
- data.contentImageWithHighlight = takeSnapshot(frame, snapshotRect, SnapshotOptionsNone, snapshotScaleFactor, clipRectsInDocumentCoordinates);
+ data.contentImageWithHighlight = takeSnapshot(frame, snapshotRect, { }, snapshotScaleFactor, clipRectsInDocumentCoordinates);
ASSERT(!data.contentImageWithHighlight || data.contentImageScaleFactor >= snapshotScaleFactor);
}
@@ -170,7 +169,7 @@
if (data.options.contains(TextIndicatorOption::IncludeSnapshotOfAllVisibleContentWithoutSelection)) {
float snapshotScaleFactor;
auto snapshotRect = frame.view()->visibleContentRect();
- data.contentImageWithoutSelection = takeSnapshot(frame, snapshotRect, SnapshotOptionsPaintEverythingExcludingSelection, snapshotScaleFactor, { });
+ data.contentImageWithoutSelection = takeSnapshot(frame, snapshotRect, { { SnapshotFlags::PaintEverythingExcludingSelection } }, snapshotScaleFactor, { });
data.contentImageWithoutSelectionRectInRootViewCoordinates = frame.view()->contentsToRootView(snapshotRect);
}
Modified: trunk/Source/WebCore/platform/DragImage.cpp (278564 => 278565)
--- trunk/Source/WebCore/platform/DragImage.cpp 2021-06-07 18:10:56 UTC (rev 278564)
+++ trunk/Source/WebCore/platform/DragImage.cpp 2021-06-07 18:53:54 UTC (rev 278565)
@@ -126,8 +126,10 @@
DragImageRef createDragImageForSelection(Frame& frame, TextIndicatorData&, bool forceBlackText)
{
- SnapshotOptions options = forceBlackText ? SnapshotOptionsForceBlackText : SnapshotOptionsNone;
- return createDragImageFromSnapshot(snapshotSelection(frame, options), nullptr);
+ SnapshotOptions options;
+ if (forceBlackText)
+ options.flags.add(SnapshotFlags::ForceBlackText);
+ return createDragImageFromSnapshot(snapshotSelection(frame, WTFMove(options)), nullptr);
}
#endif
@@ -182,7 +184,11 @@
if (!startRenderer || !endRenderer)
return nullptr;
- SnapshotOptions options = SnapshotOptionsPaintSelectionOnly | (forceBlackText ? SnapshotOptionsForceBlackText : SnapshotOptionsNone);
+ SnapshotOptions options;
+ options.flags.add(SnapshotFlags::PaintSelectionOnly);
+ if (forceBlackText)
+ options.flags.add(SnapshotFlags::ForceBlackText);
+
int startOffset = start.deprecatedEditingOffset();
int endOffset = end.deprecatedEditingOffset();
ASSERT(startOffset >= 0 && endOffset >= 0);
@@ -189,7 +195,7 @@
view->selection().set({ startRenderer, endRenderer, static_cast<unsigned>(startOffset), static_cast<unsigned>(endOffset) }, SelectionRangeData::RepaintMode::Nothing);
// We capture using snapshotFrameRect() because we fake up the selection using
// FrameView but snapshotSelection() uses the selection from the Frame itself.
- return createDragImageFromSnapshot(snapshotFrameRect(frame, view->selection().boundsClippedToVisibleContent(), options), nullptr);
+ return createDragImageFromSnapshot(snapshotFrameRect(frame, view->selection().boundsClippedToVisibleContent(), WTFMove(options)), nullptr);
}
#endif
Modified: trunk/Source/WebKit/ChangeLog (278564 => 278565)
--- trunk/Source/WebKit/ChangeLog 2021-06-07 18:10:56 UTC (rev 278564)
+++ trunk/Source/WebKit/ChangeLog 2021-06-07 18:53:54 UTC (rev 278565)
@@ -1,3 +1,19 @@
+2021-06-07 Devin Rousso <drou...@apple.com>
+
+ Convert WebCore::SnapshotOptions into an enum class
+ https://bugs.webkit.org/show_bug.cgi?id=226730
+
+ Reviewed by Wenson Hsieh.
+
+ Convert `SnapshotOptions` into an `enum class SnapshotFlags` and create a container `struct
+ SnapshotOptions` that also allows for changing the `DestinationColorSpace` (defaults to sRGB)
+ and `PixelFormat` (defaults to BGRA8).
+
+ No behavior change.
+
+ * WebProcess/WebPage/WebFrame.cpp:
+ (WebKit::WebFrame::createSelectionSnapshot const):
+
2021-06-07 Wenson Hsieh <wenson_hs...@apple.com>
[Cocoa] Find-in-page should match text inside image overlays
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebFrame.cpp (278564 => 278565)
--- trunk/Source/WebKit/WebProcess/WebPage/WebFrame.cpp 2021-06-07 18:10:56 UTC (rev 278564)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebFrame.cpp 2021-06-07 18:53:54 UTC (rev 278565)
@@ -842,7 +842,7 @@
RefPtr<ShareableBitmap> WebFrame::createSelectionSnapshot() const
{
- auto snapshot = snapshotSelection(*coreFrame(), WebCore::SnapshotOptionsForceBlackText);
+ auto snapshot = snapshotSelection(*coreFrame(), { { WebCore::SnapshotFlags::ForceBlackText } });
if (!snapshot)
return nullptr;