⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 278614 in webkit


Ignore:
Timestamp:
Jun 8, 2021, 9:53:06 AM (5 years ago)
Author:
Devin Rousso
Message:

Require that callsites of SnapshotOptions specify a PixelFormat and DestinationColorSpace
https://bugs.webkit.org/show_bug.cgi?id=226756

Reviewed by Sam Weinig.

Don't wrap PixelFormat or DestinationColorSpace with std::optional as we want each
callsite to explicity configure them. This makes it easier to find where values for each
are used as there's no implicit behavior.

No behavior change. Followup after r278565.

Source/WebCore:

  • page/FrameSnapshotting.h:
  • page/FrameSnapshotting.cpp:

(WebCore::snapshotFrameRect):
(WebCore::snapshotFrameRectWithClip):
(WebCore::snapshotNode):
(WebCore::snapshotSelection):

  • inspector/agents/InspectorPageAgent.cpp:

(WebCore::InspectorPageAgent::snapshotNode):
(WebCore::InspectorPageAgent::snapshotRect):

  • page/PageConsoleClient.cpp:

(WebCore::PageConsoleClient::screenshot):

  • page/TextIndicator.cpp:

(WebCore::snapshotOptionsForTextIndicatorOptions):
(WebCore::takeSnapshots):

  • platform/DragImage.cpp:

(WebCore::createDragImageForNode):
(WebCore::createDragImageForSelection):
(WebCore::createDragImageForRange):
(WebCore::createDragImageForImage):

Source/WebKit:

  • WebProcess/WebPage/WebFrame.cpp:

(WebKit::WebFrame::createSelectionSnapshot const):

Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r278611 r278614  
     12021-06-08  Devin Rousso  <drousso@apple.com>
     2
     3        Require that callsites of `SnapshotOptions` specify a `PixelFormat` and `DestinationColorSpace`
     4        https://bugs.webkit.org/show_bug.cgi?id=226756
     5
     6        Reviewed by Sam Weinig.
     7
     8        Don't wrap `PixelFormat` or `DestinationColorSpace` with `std::optional` as we want each
     9        callsite to explicity configure them. This makes it easier to find where values for each
     10        are used as there's no implicit behavior.
     11
     12        No behavior change. Followup after r278565.
     13
     14        * page/FrameSnapshotting.h:
     15        * page/FrameSnapshotting.cpp:
     16        (WebCore::snapshotFrameRect):
     17        (WebCore::snapshotFrameRectWithClip):
     18        (WebCore::snapshotNode):
     19        (WebCore::snapshotSelection):
     20
     21        * inspector/agents/InspectorPageAgent.cpp:
     22        (WebCore::InspectorPageAgent::snapshotNode):
     23        (WebCore::InspectorPageAgent::snapshotRect):
     24        * page/PageConsoleClient.cpp:
     25        (WebCore::PageConsoleClient::screenshot):
     26        * page/TextIndicator.cpp:
     27        (WebCore::snapshotOptionsForTextIndicatorOptions):
     28        (WebCore::takeSnapshots):
     29        * platform/DragImage.cpp:
     30        (WebCore::createDragImageForNode):
     31        (WebCore::createDragImageForSelection):
     32        (WebCore::createDragImageForRange):
     33        (WebCore::createDragImageForImage):
     34
    1352021-06-08  Sam Weinig  <weinig@apple.com>
    236
  • trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp

    r278565 r278614  
    10731073        return makeUnexpected(errorString);
    10741074
    1075     auto snapshot = WebCore::snapshotNode(m_inspectedPage.mainFrame(), *node);
     1075    auto snapshot = WebCore::snapshotNode(m_inspectedPage.mainFrame(), *node, { { }, PixelFormat::BGRA8, DestinationColorSpace::SRGB() });
    10761076    if (!snapshot)
    10771077        return makeUnexpected("Could not capture snapshot"_s);
     
    10821082Protocol::ErrorStringOr<String> InspectorPageAgent::snapshotRect(int x, int y, int width, int height, Protocol::Page::CoordinateSystem coordinateSystem)
    10831083{
    1084     SnapshotOptions options;
     1084    SnapshotOptions options { { }, PixelFormat::BGRA8, DestinationColorSpace::SRGB() };
    10851085    if (coordinateSystem == Protocol::Page::CoordinateSystem::Viewport)
    10861086        options.flags.add(SnapshotFlags::InViewCoordinates);
  • trunk/Source/WebCore/page/FrameSnapshotting.cpp

    r278565 r278614  
    3232#include "FrameSnapshotting.h"
    3333
    34 #include "DestinationColorSpace.h"
    3534#include "Document.h"
    3635#include "FloatRect.h"
     
    4140#include "ImageBuffer.h"
    4241#include "Page.h"
    43 #include "PixelFormat.h"
    4442#include "RenderObject.h"
    4543#include "Settings.h"
     
    115113        scaleFactor = ceilf(scaleFactor);
    116114
    117     auto buffer = ImageBuffer::create(imageRect.size(), RenderingMode::Unaccelerated, scaleFactor, options.colorSpace.value_or(DestinationColorSpace::SRGB()), options.pixelFormat.value_or(PixelFormat::BGRA8));
     115    auto buffer = ImageBuffer::create(imageRect.size(), RenderingMode::Unaccelerated, scaleFactor, options.colorSpace, options.pixelFormat);
    118116    if (!buffer)
    119117        return nullptr;
  • trunk/Source/WebCore/page/FrameSnapshotting.h

    r278565 r278614  
    3030#pragma once
    3131
     32#include "DestinationColorSpace.h"
     33#include "PixelFormat.h"
    3234#include <memory>
    33 #include <optional>
    3435#include <wtf/Forward.h>
    3536
    3637namespace WebCore {
    3738
    38 class DestinationColorSpace;
    3939class FloatRect;
    4040class Frame;
     
    4242class ImageBuffer;
    4343class Node;
    44 enum class PixelFormat : uint8_t;
    4544
    4645enum class SnapshotFlags : uint8_t {
     
    5554
    5655struct SnapshotOptions {
    57     OptionSet<SnapshotFlags> flags { };
    58     std::optional<PixelFormat> pixelFormat { };
    59     std::optional<DestinationColorSpace> colorSpace { };
     56    OptionSet<SnapshotFlags> flags;
     57    PixelFormat pixelFormat;
     58    DestinationColorSpace colorSpace;
    6059};
    6160
    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&& = { });
     61WEBCORE_EXPORT RefPtr<ImageBuffer> snapshotFrameRect(Frame&, const IntRect&, SnapshotOptions&&);
     62RefPtr<ImageBuffer> snapshotFrameRectWithClip(Frame&, const IntRect&, const Vector<FloatRect>& clipRects, SnapshotOptions&&);
     63RefPtr<ImageBuffer> snapshotNode(Frame&, Node&, SnapshotOptions&&);
     64WEBCORE_EXPORT RefPtr<ImageBuffer> snapshotSelection(Frame&, SnapshotOptions&&);
    6665
    6766} // namespace WebCore
  • trunk/Source/WebCore/page/PageConsoleClient.cpp

    r278565 r278614  
    359359                if (dataURL.isEmpty()) {
    360360                    if (!snapshot)
    361                         snapshot = WebCore::snapshotNode(m_page.mainFrame(), *node);
     361                        snapshot = WebCore::snapshotNode(m_page.mainFrame(), *node, { { }, PixelFormat::BGRA8, DestinationColorSpace::SRGB() });
    362362
    363363                    if (snapshot)
     
    405405            // If no target is provided, capture an image of the viewport.
    406406            IntRect imageRect(IntPoint::zero(), m_page.mainFrame().view()->sizeForVisibleContent());
    407             if (auto snapshot = WebCore::snapshotFrameRect(m_page.mainFrame(), imageRect, { { SnapshotFlags::InViewCoordinates } }))
     407            if (auto snapshot = WebCore::snapshotFrameRect(m_page.mainFrame(), imageRect, { { SnapshotFlags::InViewCoordinates }, PixelFormat::BGRA8, DestinationColorSpace::SRGB() }))
    408408                dataURL = snapshot->toDataURL("image/png"_s, std::nullopt, PreserveResolution::Yes);
    409409        }
  • trunk/Source/WebCore/page/TextIndicator.cpp

    r278565 r278614  
    128128static SnapshotOptions snapshotOptionsForTextIndicatorOptions(OptionSet<TextIndicatorOption> options)
    129129{
    130     SnapshotOptions snapshotOptions;
    131     snapshotOptions.flags.add(SnapshotFlags::PaintWithIntegralScaleFactor);
     130    SnapshotOptions snapshotOptions { { SnapshotFlags::PaintWithIntegralScaleFactor }, PixelFormat::BGRA8, DestinationColorSpace::SRGB() };
    132131
    133132    if (!options.contains(TextIndicatorOption::PaintAllContent)) {
     
    163162    if (data.options.contains(TextIndicatorOption::IncludeSnapshotWithSelectionHighlight)) {
    164163        float snapshotScaleFactor;
    165         data.contentImageWithHighlight = takeSnapshot(frame, snapshotRect, { }, snapshotScaleFactor, clipRectsInDocumentCoordinates);
     164        data.contentImageWithHighlight = takeSnapshot(frame, snapshotRect, { { }, PixelFormat::BGRA8, DestinationColorSpace::SRGB() }, snapshotScaleFactor, clipRectsInDocumentCoordinates);
    166165        ASSERT(!data.contentImageWithHighlight || data.contentImageScaleFactor >= snapshotScaleFactor);
    167166    }
     
    170169        float snapshotScaleFactor;
    171170        auto snapshotRect = frame.view()->visibleContentRect();
    172         data.contentImageWithoutSelection = takeSnapshot(frame, snapshotRect, { { SnapshotFlags::PaintEverythingExcludingSelection } }, snapshotScaleFactor, { });
     171        data.contentImageWithoutSelection = takeSnapshot(frame, snapshotRect, { { SnapshotFlags::PaintEverythingExcludingSelection }, PixelFormat::BGRA8, DestinationColorSpace::SRGB() }, snapshotScaleFactor, { });
    173172        data.contentImageWithoutSelectionRectInRootViewCoordinates = frame.view()->contentsToRootView(snapshotRect);
    174173    }
  • trunk/Source/WebCore/platform/DragImage.cpp

    r278565 r278614  
    120120{
    121121    ScopedNodeDragEnabler enableDrag(frame, node);
    122     return createDragImageFromSnapshot(snapshotNode(frame, node), &node);
     122    return createDragImageFromSnapshot(snapshotNode(frame, node, { { }, PixelFormat::BGRA8, DestinationColorSpace::SRGB() }), &node);
    123123}
    124124
     
    127127DragImageRef createDragImageForSelection(Frame& frame, TextIndicatorData&, bool forceBlackText)
    128128{
    129     SnapshotOptions options;
     129    SnapshotOptions options { { }, PixelFormat::BGRA8, DestinationColorSpace::SRGB() };
    130130    if (forceBlackText)
    131131        options.flags.add(SnapshotFlags::ForceBlackText);
     
    185185        return nullptr;
    186186
    187     SnapshotOptions options;
    188     options.flags.add(SnapshotFlags::PaintSelectionOnly);
     187    SnapshotOptions options { { SnapshotFlags::PaintSelectionOnly }, PixelFormat::BGRA8, DestinationColorSpace::SRGB() };
    189188    if (forceBlackText)
    190189        options.flags.add(SnapshotFlags::ForceBlackText);
     
    219218    imageRect = paintingRect;
    220219
    221     return createDragImageFromSnapshot(snapshotNode(frame, node), &node);
     220    return createDragImageFromSnapshot(snapshotNode(frame, node, { { }, PixelFormat::BGRA8, DestinationColorSpace::SRGB() }), &node);
    222221}
    223222
  • trunk/Source/WebKit/ChangeLog

    r278603 r278614  
     12021-06-08  Devin Rousso  <drousso@apple.com>
     2
     3        Require that callsites of `SnapshotOptions` specify a `PixelFormat` and `DestinationColorSpace`
     4        https://bugs.webkit.org/show_bug.cgi?id=226756
     5
     6        Reviewed by Sam Weinig.
     7
     8        Don't wrap `PixelFormat` or `DestinationColorSpace` with `std::optional` as we want each
     9        callsite to explicity configure them. This makes it easier to find where values for each
     10        are used as there's no implicit behavior.
     11
     12        No behavior change. Followup after r278565.
     13
     14        * WebProcess/WebPage/WebFrame.cpp:
     15        (WebKit::WebFrame::createSelectionSnapshot const):
     16
    1172021-06-08  Jean-Yves Avenard  <jya@apple.com>
    218
  • trunk/Source/WebKit/WebProcess/WebPage/WebFrame.cpp

    r278565 r278614  
    843843RefPtr<ShareableBitmap> WebFrame::createSelectionSnapshot() const
    844844{
    845     auto snapshot = snapshotSelection(*coreFrame(), { { WebCore::SnapshotFlags::ForceBlackText } });
     845    auto snapshot = snapshotSelection(*coreFrame(), { { WebCore::SnapshotFlags::ForceBlackText }, PixelFormat::BGRA8, DestinationColorSpace::SRGB() });
    846846    if (!snapshot)
    847847        return nullptr;
Note: See TracChangeset for help on using the changeset viewer.