Changeset 268145 in webkit


Ignore:
Timestamp:
Oct 7, 2020 1:13:24 PM (4 years ago)
Author:
Wenson Hsieh
Message:

[GPU Process] Support CanvasRenderingContext2D.drawImage() with HTMLVideoElement
https://bugs.webkit.org/show_bug.cgi?id=217339
<rdar://problem/69409029>

Reviewed by Darin Adler.

Source/WebCore:

Implements support for painting the current video frame into a canvas 2D graphics context. See below for more
details.

  • html/HTMLVideoElement.cpp:

(WebCore::HTMLVideoElement::paintCurrentFrameInContext):

Flip this around to call GraphicsContext::paintFrameForMedia with the MediaPlayer, instead of calling into
MediaPlayer with the graphics context. See changes below.

  • platform/graphics/GraphicsContext.cpp:

(WebCore::GraphicsContext::paintFrameForMedia):

  • platform/graphics/GraphicsContext.h:

Add a paintFrameForMedia method that takes a MediaPlayer representing a video, and paints the current frame
of the video into the context. If the graphics context is backed by an platform context (i.e. m_impl is
nullptr), then we simply call through to MediaPlayer's private impl to paint into the context. Otherwise, we
forward the call to the GraphicsContextImpl (see the changes to DisplayListRecorder.cpp below).

  • platform/graphics/GraphicsContextImpl.h:

Add a new virtual function to paint the current frame of the given MediaPlayer into the destination rect.

  • platform/graphics/MediaPlayer.cpp:

(WebCore::MediaPlayer::playerPrivate const):
(WebCore::MediaPlayer::playerPrivate):
(WebCore::MediaPlayer::paintCurrentFrameInContext): Deleted.

  • platform/graphics/MediaPlayer.h:

Remove the existing paintCurrentFrameInContext method on MediaPlayer, which currently takes a graphics
context. Instead, move paintCurrentFrameInContext to GraphicsContext, rename it to paintFrameForMedia, and
pass it a MediaPlayer. Additionally, expose a helper method to get a non-const MediaPlayerPrivateInterface,
and move both method definitions to the implementation file to avoid style checker errors due to MediaPlayer
itself being WEBCORE_EXPORT-ed.

  • platform/graphics/cairo/GraphicsContextImplCairo.cpp:

(WebCore::GraphicsContextImplCairo::paintFrameForMedia):

  • platform/graphics/cairo/GraphicsContextImplCairo.h:
  • platform/graphics/displaylists/DisplayList.h:
  • platform/graphics/displaylists/DisplayListItems.cpp:

(WebCore::DisplayList::Item::sizeInBytes):
(WebCore::DisplayList::PaintFrameForMedia::create):
(WebCore::DisplayList::PaintFrameForMedia::PaintFrameForMedia):
(WebCore::DisplayList::PaintFrameForMedia::apply const):
(WebCore::DisplayList::operator<<):

  • platform/graphics/displaylists/DisplayListItems.h:

(WebCore::DisplayList::PaintFrameForMedia::destination const):
(WebCore::DisplayList::PaintFrameForMedia::identifier const):
(WebCore::DisplayList::PaintFrameForMedia::encode const):
(WebCore::DisplayList::PaintFrameForMedia::decode):
(WebCore::DisplayList::Item::encode const):
(WebCore::DisplayList::Item::decode):

  • platform/graphics/displaylists/DisplayListRecorder.cpp:

(WebCore::DisplayList::Recorder::paintFrameForMedia):

  • platform/graphics/displaylists/DisplayListRecorder.h:

Add a new display list item, PaintFrameForMedia, that paints the current frame of a given MediaPlayer. This
works by serializing and then deserializing a MediaPlayerHandle and destination rect; similar to
PutImageData, the replayer delegate is responsible for applying this item by mapping the MediaPlayerHandle
to a concrete MediaPlayer instance.

  • platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp:

(Nicosia::CairoOperationRecorder::paintFrameForMedia):

  • platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.h:
  • platform/graphics/win/GraphicsContextImplDirect2D.cpp:

(WebCore::GraphicsContextImplDirect2D::paintFrameForMedia):

  • platform/graphics/win/GraphicsContextImplDirect2D.h:
  • rendering/RenderVideo.cpp:

(WebCore::RenderVideo::paintReplaced):

Source/WebKit:

Implements support for painting the current video frame into a canvas 2D graphics context. See below (and
Source/WebCore/ChangeLog) for more details.

  • GPUProcess/graphics/RemoteImageBufferMessageHandlerProxy.h:

(WebKit::RemoteImageBufferMessageHandlerProxy::backend):

  • GPUProcess/graphics/RemoteImageBufferProxy.h:

(WebKit::RemoteImageBufferProxy::apply):

Refactor apply so that it treats PutImageData and PaintFrameForMedia as special cases, and otherwise
returns false by default. Implement apply in the case where the display list item is PaintFrameForMedia by
using the MediaPlayerIdentifier to look up the platform MediaPlayer instance, and then calling
GraphicsContext::paintFrameForMedia with this MediaPlayer.

  • GPUProcess/graphics/RemoteRenderingBackendProxy.cpp:

(WebKit::RemoteRenderingBackendProxy::gpuConnectionToWebProcess const):

  • GPUProcess/graphics/RemoteRenderingBackendProxy.h:
Location:
trunk/Source
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r268144 r268145  
     12020-10-07  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [GPU Process] Support CanvasRenderingContext2D.drawImage() with HTMLVideoElement
     4        https://bugs.webkit.org/show_bug.cgi?id=217339
     5        <rdar://problem/69409029>
     6
     7        Reviewed by Darin Adler.
     8
     9        Implements support for painting the current video frame into a canvas 2D graphics context. See below for more
     10        details.
     11
     12        * html/HTMLVideoElement.cpp:
     13        (WebCore::HTMLVideoElement::paintCurrentFrameInContext):
     14
     15        Flip this around to call `GraphicsContext::paintFrameForMedia` with the `MediaPlayer`, instead of calling into
     16        `MediaPlayer` with the graphics context. See changes below.
     17
     18        * platform/graphics/GraphicsContext.cpp:
     19        (WebCore::GraphicsContext::paintFrameForMedia):
     20        * platform/graphics/GraphicsContext.h:
     21
     22        Add a `paintFrameForMedia` method that takes a `MediaPlayer` representing a video, and paints the current frame
     23        of the video into the context. If the graphics context is backed by an platform context (i.e. `m_impl` is
     24        `nullptr`), then we simply call through to `MediaPlayer`'s private impl to paint into the context. Otherwise, we
     25        forward the call to the `GraphicsContextImpl` (see the changes to `DisplayListRecorder.cpp` below).
     26
     27        * platform/graphics/GraphicsContextImpl.h:
     28
     29        Add a new virtual function to paint the current frame of the given `MediaPlayer` into the destination rect.
     30
     31        * platform/graphics/MediaPlayer.cpp:
     32        (WebCore::MediaPlayer::playerPrivate const):
     33        (WebCore::MediaPlayer::playerPrivate):
     34        (WebCore::MediaPlayer::paintCurrentFrameInContext): Deleted.
     35        * platform/graphics/MediaPlayer.h:
     36
     37        Remove the existing `paintCurrentFrameInContext` method on `MediaPlayer`, which currently takes a graphics
     38        context. Instead, move `paintCurrentFrameInContext` to `GraphicsContext`, rename it to `paintFrameForMedia`, and
     39        pass it a `MediaPlayer`. Additionally, expose a helper method to get a non-const `MediaPlayerPrivateInterface`,
     40        and move both method definitions to the implementation file to avoid style checker errors due to `MediaPlayer`
     41        itself being `WEBCORE_EXPORT`-ed.
     42
     43        * platform/graphics/cairo/GraphicsContextImplCairo.cpp:
     44        (WebCore::GraphicsContextImplCairo::paintFrameForMedia):
     45        * platform/graphics/cairo/GraphicsContextImplCairo.h:
     46        * platform/graphics/displaylists/DisplayList.h:
     47        * platform/graphics/displaylists/DisplayListItems.cpp:
     48        (WebCore::DisplayList::Item::sizeInBytes):
     49        (WebCore::DisplayList::PaintFrameForMedia::create):
     50        (WebCore::DisplayList::PaintFrameForMedia::PaintFrameForMedia):
     51        (WebCore::DisplayList::PaintFrameForMedia::apply const):
     52        (WebCore::DisplayList::operator<<):
     53        * platform/graphics/displaylists/DisplayListItems.h:
     54        (WebCore::DisplayList::PaintFrameForMedia::destination const):
     55        (WebCore::DisplayList::PaintFrameForMedia::identifier const):
     56        (WebCore::DisplayList::PaintFrameForMedia::encode const):
     57        (WebCore::DisplayList::PaintFrameForMedia::decode):
     58        (WebCore::DisplayList::Item::encode const):
     59        (WebCore::DisplayList::Item::decode):
     60        * platform/graphics/displaylists/DisplayListRecorder.cpp:
     61        (WebCore::DisplayList::Recorder::paintFrameForMedia):
     62        * platform/graphics/displaylists/DisplayListRecorder.h:
     63
     64        Add a new display list item, `PaintFrameForMedia`, that paints the current frame of a given `MediaPlayer`. This
     65        works by serializing and then deserializing a `MediaPlayerHandle` and destination rect; similar to
     66        `PutImageData`, the replayer delegate is responsible for applying this item by mapping the `MediaPlayerHandle`
     67        to a concrete `MediaPlayer` instance.
     68
     69        * platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp:
     70        (Nicosia::CairoOperationRecorder::paintFrameForMedia):
     71        * platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.h:
     72        * platform/graphics/win/GraphicsContextImplDirect2D.cpp:
     73        (WebCore::GraphicsContextImplDirect2D::paintFrameForMedia):
     74        * platform/graphics/win/GraphicsContextImplDirect2D.h:
     75        * rendering/RenderVideo.cpp:
     76        (WebCore::RenderVideo::paintReplaced):
     77
    1782020-10-07  Aditya Keerthi  <akeerthi@apple.com>
    279
  • trunk/Source/WebCore/html/HTMLVideoElement.cpp

    r266728 r268145  
    298298   
    299299    player->setVisible(true); // Make player visible or it won't draw.
    300     player->paintCurrentFrameInContext(context, destRect);
     300    context.paintFrameForMedia(*player, destRect);
    301301}
    302302
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp

    r267742 r268145  
    3434#include "ImageBuffer.h"
    3535#include "IntRect.h"
     36#include "MediaPlayer.h"
     37#include "MediaPlayerPrivate.h"
    3638#include "RoundedRect.h"
    3739#include "TextRun.h"
     
    12401242
    12411243#if !USE(CG)
     1244
    12421245bool GraphicsContext::supportsInternalLinks() const
    12431246{
     
    12521255{
    12531256}
    1254 #endif
    1255 
    1256 }
     1257
     1258#endif
     1259
     1260void GraphicsContext::paintFrameForMedia(MediaPlayer& player, const FloatRect& destination)
     1261{
     1262    if (paintingDisabled())
     1263        return;
     1264
     1265    if (m_impl && m_impl->canPaintFrameForMedia()) {
     1266        m_impl->paintFrameForMedia(player, destination);
     1267        return;
     1268    }
     1269
     1270    player.playerPrivate()->paintCurrentFrameInContext(*this, destination);
     1271}
     1272
     1273}
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.h

    r267742 r268145  
    9393class ImageBuffer;
    9494class IntRect;
     95class MediaPlayer;
    9596class RoundedRect;
    9697class GraphicsContextGLOpenGL;
     
    516517    void setContentfulPaintDetected() { m_contenfulPaintDetected = true; }
    517518    bool contenfulPaintDetected() const { return m_contenfulPaintDetected; }
     519
     520    WEBCORE_EXPORT void paintFrameForMedia(MediaPlayer&, const FloatRect& destination);
    518521
    519522#if OS(WINDOWS)
  • trunk/Source/WebCore/platform/graphics/GraphicsContextImpl.h

    r267742 r268145  
    108108    virtual void clipToImageBuffer(ImageBuffer&, const FloatRect&) = 0;
    109109    virtual void clipToDrawingCommands(const FloatRect& destination, ColorSpace, Function<void(GraphicsContext&)>&& drawingFunction) = 0;
     110    virtual void paintFrameForMedia(MediaPlayer&, const FloatRect& destination) = 0;
     111    virtual bool canPaintFrameForMedia() const = 0;
    110112   
    111113    virtual void applyDeviceScaleFactor(float) = 0;
  • trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp

    r268070 r268145  
    3232#include "DeprecatedGlobalSettings.h"
    3333#include "Document.h"
     34#include "GraphicsContext.h"
    3435#include "IntRect.h"
    3536#include "Logging.h"
     
    303304    static MainThreadNeverDestroyed<const AtomString> textPlain("text/plain", AtomString::ConstructFromLiteral);
    304305    return textPlain;
     306}
     307
     308const MediaPlayerPrivateInterface* MediaPlayer::playerPrivate() const
     309{
     310    return m_private.get();
     311}
     312
     313MediaPlayerPrivateInterface* MediaPlayer::playerPrivate()
     314{
     315    return m_private.get();
    305316}
    306317
     
    968979}
    969980
    970 void MediaPlayer::paintCurrentFrameInContext(GraphicsContext& p, const FloatRect& r)
    971 {
    972     m_private->paintCurrentFrameInContext(p, r);
    973 }
    974 
    975981bool MediaPlayer::copyVideoTextureToPlatformTexture(GraphicsContextGLOpenGL* context, PlatformGLObject texture, GCGLenum target, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, bool premultiplyAlpha, bool flipY)
    976982{
  • trunk/Source/WebCore/platform/graphics/MediaPlayer.h

    r268070 r268145  
    423423
    424424    void paint(GraphicsContext&, const FloatRect&);
    425     void paintCurrentFrameInContext(GraphicsContext&, const FloatRect&);
    426425
    427426    // copyVideoTextureToPlatformTexture() is used to do the GPU-GPU textures copy without a readback to system memory.
     
    631630#endif
    632631
    633     const MediaPlayerPrivateInterface* playerPrivate() const { return m_private.get(); }
     632    const MediaPlayerPrivateInterface* playerPrivate() const;
     633    MediaPlayerPrivateInterface* playerPrivate();
    634634
    635635    DynamicRangeMode preferredDynamicRangeMode() const { return m_preferredDynamicRangeMode; }
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.cpp

    r267742 r268145  
    433433}
    434434
     435void GraphicsContextImplCairo::paintFrameForMedia(MediaPlayer&, const FloatRect&)
     436{
     437    // FIXME: Not implemented.
     438}
     439
    435440} // namespace WebCore
    436441
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextImplCairo.h

    r267742 r268145  
    108108    void clipToImageBuffer(ImageBuffer&, const FloatRect&) override;
    109109    void clipToDrawingCommands(const FloatRect& destination, ColorSpace, Function<void(GraphicsContext&)>&&) override;
     110    void paintFrameForMedia(MediaPlayer&, const FloatRect& destination) override;
     111    bool canPaintFrameForMedia() const override { return false; }
    110112   
    111113    void applyDeviceScaleFactor(float) override;
  • trunk/Source/WebCore/platform/graphics/displaylists/DisplayList.h

    r267742 r268145  
    8484    FillEllipse,
    8585    PutImageData,
     86    PaintFrameForMedia,
    8687    StrokeRect,
    8788    StrokePath,
  • trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp

    r267858 r268145  
    3030#include "FontCascade.h"
    3131#include "ImageData.h"
     32#include "MediaPlayer.h"
    3233#include "SharedBuffer.h"
    3334#include <wtf/text/TextStream.h>
     
    146147    case ItemType::PutImageData:
    147148        return sizeof(downcast<PutImageData>(item));
     149    case ItemType::PaintFrameForMedia:
     150        return sizeof(downcast<PaintFrameForMedia>(item));
    148151    case ItemType::StrokeRect:
    149152        return sizeof(downcast<StrokeRect>(item));
     
    12161219    ts.dumpProperty("destPoint", item.destPoint());
    12171220    ts.dumpProperty("destFormat", item.destFormat());
     1221    return ts;
     1222}
     1223
     1224Ref<PaintFrameForMedia> PaintFrameForMedia::create(MediaPlayer& player, const FloatRect& destination)
     1225{
     1226    return adoptRef(*new PaintFrameForMedia(player, destination));
     1227}
     1228
     1229Ref<PaintFrameForMedia> PaintFrameForMedia::create(MediaPlayerIdentifier identifier, const FloatRect& destination)
     1230{
     1231    return adoptRef(*new PaintFrameForMedia(identifier, destination));
     1232}
     1233
     1234PaintFrameForMedia::PaintFrameForMedia(MediaPlayer& player, const FloatRect& destination)
     1235    : DrawingItem(ItemType::PaintFrameForMedia)
     1236    , m_identifier(player.identifier())
     1237    , m_destination(destination)
     1238{
     1239}
     1240
     1241PaintFrameForMedia::PaintFrameForMedia(MediaPlayerIdentifier identifier, const FloatRect& destination)
     1242    : DrawingItem(ItemType::PaintFrameForMedia)
     1243    , m_identifier(identifier)
     1244    , m_destination(destination)
     1245{
     1246}
     1247
     1248PaintFrameForMedia::~PaintFrameForMedia() = default;
     1249
     1250void PaintFrameForMedia::apply(GraphicsContext&) const
     1251{
     1252    // Should be handled by the delegate.
     1253    ASSERT_NOT_REACHED();
     1254}
     1255
     1256static TextStream& operator<<(TextStream& ts, const PaintFrameForMedia& item)
     1257{
     1258    ts << static_cast<const DrawingItem&>(item);
     1259    ts.dumpProperty("destination", item.destination());
    12181260    return ts;
    12191261}
     
    14491491    case ItemType::FillEllipse: ts << "fill-ellipse"; break;
    14501492    case ItemType::PutImageData: ts << "put-image-data"; break;
     1493    case ItemType::PaintFrameForMedia: ts << "paint-frame-for-media"; break;
    14511494    case ItemType::StrokeRect: ts << "stroke-rect"; break;
    14521495    case ItemType::StrokePath: ts << "stroke-path"; break;
     
    15881631        ts << downcast<PutImageData>(item);
    15891632        break;
     1633    case ItemType::PaintFrameForMedia:
     1634        ts << downcast<PaintFrameForMedia>(item);
     1635        break;
    15901636    case ItemType::StrokeRect:
    15911637        ts << downcast<StrokeRect>(item);
  • trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h

    r267782 r268145  
    3434#include "Image.h"
    3535#include "ImageData.h"
     36#include "MediaPlayerIdentifier.h"
    3637#include "Pattern.h"
    3738#include "SharedBuffer.h"
     
    4546
    4647class ImageData;
     48class MediaPlayer;
    4749struct ImagePaintingOptions;
    4850
     
    25832585}
    25842586
     2587class PaintFrameForMedia : public DrawingItem {
     2588public:
     2589    static Ref<PaintFrameForMedia> create(MediaPlayer&, const FloatRect& destination);
     2590
     2591    WEBCORE_EXPORT virtual ~PaintFrameForMedia();
     2592
     2593    const FloatRect& destination() const { return m_destination; }
     2594    MediaPlayerIdentifier identifier() const { return m_identifier; }
     2595
     2596    template<class Encoder> void encode(Encoder&) const;
     2597    template<class Decoder> static Optional<Ref<PaintFrameForMedia>> decode(Decoder&);
     2598
     2599private:
     2600    WEBCORE_EXPORT static Ref<PaintFrameForMedia> create(MediaPlayerIdentifier, const FloatRect& destination);
     2601
     2602    PaintFrameForMedia(MediaPlayer&, const FloatRect& destination);
     2603    PaintFrameForMedia(MediaPlayerIdentifier, const FloatRect& destination);
     2604
     2605    void apply(GraphicsContext&) const override;
     2606
     2607    MediaPlayerIdentifier m_identifier;
     2608    FloatRect m_destination;
     2609};
     2610
     2611template<class Encoder>
     2612void PaintFrameForMedia::encode(Encoder& encoder) const
     2613{
     2614    encoder << m_identifier;
     2615    encoder << m_destination;
     2616}
     2617
     2618template<class Decoder>
     2619Optional<Ref<PaintFrameForMedia>> PaintFrameForMedia::decode(Decoder& decoder)
     2620{
     2621    Optional<MediaPlayerIdentifier> identifier;
     2622    decoder >> identifier;
     2623    if (!identifier)
     2624        return WTF::nullopt;
     2625
     2626    Optional<FloatRect> destination;
     2627    decoder >> destination;
     2628    if (!destination)
     2629        return WTF::nullopt;
     2630
     2631    return PaintFrameForMedia::create(*identifier, *destination);
     2632}
     2633
    25852634class StrokeRect : public DrawingItem {
    25862635public:
     
    29843033        encoder << downcast<PutImageData>(*this);
    29853034        break;
     3035    case ItemType::PaintFrameForMedia:
     3036        encoder << downcast<PaintFrameForMedia>(*this);
     3037        break;
    29863038    case ItemType::StrokeRect:
    29873039        encoder << downcast<StrokeRect>(*this);
     
    31893241    case ItemType::PutImageData:
    31903242        if (auto item = PutImageData::decode(decoder))
     3243            return static_reference_cast<Item>(WTFMove(*item));
     3244        break;
     3245    case ItemType::PaintFrameForMedia:
     3246        if (auto item = PaintFrameForMedia::decode(decoder))
    31913247            return static_reference_cast<Item>(WTFMove(*item));
    31923248        break;
     
    32923348SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(FillEllipse)
    32933349SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(PutImageData)
     3350SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(PaintFrameForMedia)
    32943351SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(StrokeRect)
    32953352SPECIALIZE_TYPE_TRAITS_DISPLAYLIST_ITEM(StrokePath)
     
    33533410    WebCore::DisplayList::ItemType::FillEllipse,
    33543411    WebCore::DisplayList::ItemType::PutImageData,
     3412    WebCore::DisplayList::ItemType::PaintFrameForMedia,
    33553413    WebCore::DisplayList::ItemType::StrokeRect,
    33563414    WebCore::DisplayList::ItemType::StrokePath,
  • trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp

    r267858 r268145  
    390390}
    391391
     392void Recorder::paintFrameForMedia(MediaPlayer& player, const FloatRect& destination)
     393{
     394    appendItem(PaintFrameForMedia::create(player, destination));
     395}
     396
    392397void Recorder::applyDeviceScaleFactor(float deviceScaleFactor)
    393398{
  • trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h

    r267742 r268145  
    138138    void clipToImageBuffer(WebCore::ImageBuffer&, const FloatRect&) override;
    139139    void clipToDrawingCommands(const FloatRect& destination, ColorSpace, Function<void(GraphicsContext&)>&&) override;
     140    void paintFrameForMedia(MediaPlayer&, const FloatRect& destination) override;
     141    bool canPaintFrameForMedia() const override { return true; }
    140142   
    141143    void applyDeviceScaleFactor(float) override;
  • trunk/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.cpp

    r267742 r268145  
    10961096}
    10971097
     1098void CairoOperationRecorder::paintFrameForMedia(MediaPlayer&, const FloatRect&)
     1099{
     1100    // FIXME: Not implemented.
     1101}
     1102
    10981103} // namespace Nicosia
  • trunk/Source/WebCore/platform/graphics/nicosia/cairo/NicosiaCairoOperationRecorder.h

    r267742 r268145  
    101101    void clipToImageBuffer(WebCore::ImageBuffer&, const WebCore::FloatRect&) override;
    102102    void clipToDrawingCommands(const WebCore::FloatRect& destination, WebCore::ColorSpace, Function<void(WebCore::GraphicsContext&)>&&) override;
     103    void paintFrameForMedia(WebCore::MediaPlayer&, const WebCore::FloatRect& destination) override;
     104    bool canPaintFrameForMedia() const override { return false; }
    103105
    104106    void applyDeviceScaleFactor(float) override;
  • trunk/Source/WebCore/platform/graphics/win/GraphicsContextImplDirect2D.cpp

    r267742 r268145  
    442442}
    443443
     444void GraphicsContextImplDirect2D::paintFrameForMedia(MediaPlayer&, const FloatRect&)
     445{
     446    // FIXME: Not implemented.
     447}
     448
    444449} // namespace WebCore
    445450
  • trunk/Source/WebCore/platform/graphics/win/GraphicsContextImplDirect2D.h

    r267742 r268145  
    105105    void clipToImageBuffer(ImageBuffer&, const FloatRect&) override;
    106106    void clipToDrawingCommands(const FloatRect& destination, ColorSpace, Function<void(GraphicsContext&)>&&) override;
     107    void paintFrameForMedia(MediaPlayer&, const FloatRect& destination) override;
     108    bool canPaintFrameForMedia() const override { return false; }
    107109   
    108110    void applyDeviceScaleFactor(float) override;
  • trunk/Source/WebCore/rendering/RenderVideo.cpp

    r265904 r268145  
    227227    else if (!videoElement().isFullscreen() || !mediaPlayer->supportsAcceleratedRendering()) {
    228228        if (paintInfo.paintBehavior.contains(PaintBehavior::FlattenCompositingLayers))
    229             mediaPlayer->paintCurrentFrameInContext(context, rect);
     229            context.paintFrameForMedia(*mediaPlayer, rect);
    230230        else
    231231            mediaPlayer->paint(context, rect);
  • trunk/Source/WebKit/ChangeLog

    r268136 r268145  
     12020-10-07  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [GPU Process] Support CanvasRenderingContext2D.drawImage() with HTMLVideoElement
     4        https://bugs.webkit.org/show_bug.cgi?id=217339
     5        <rdar://problem/69409029>
     6
     7        Reviewed by Darin Adler.
     8
     9        Implements support for painting the current video frame into a canvas 2D graphics context. See below (and
     10        Source/WebCore/ChangeLog) for more details.
     11
     12        * GPUProcess/graphics/RemoteImageBufferMessageHandlerProxy.h:
     13        (WebKit::RemoteImageBufferMessageHandlerProxy::backend):
     14        * GPUProcess/graphics/RemoteImageBufferProxy.h:
     15        (WebKit::RemoteImageBufferProxy::apply):
     16
     17        Refactor `apply` so that it treats `PutImageData` and `PaintFrameForMedia` as special cases, and otherwise
     18        returns `false` by default. Implement `apply` in the case where the display list item is `PaintFrameForMedia` by
     19        using the `MediaPlayerIdentifier` to look up the platform `MediaPlayer` instance, and then calling
     20        `GraphicsContext::paintFrameForMedia` with this `MediaPlayer`.
     21
     22        * GPUProcess/graphics/RemoteRenderingBackendProxy.cpp:
     23        (WebKit::RemoteRenderingBackendProxy::gpuConnectionToWebProcess const):
     24        * GPUProcess/graphics/RemoteRenderingBackendProxy.h:
     25
    1262020-10-07  Youenn Fablet  <youenn@apple.com>
    227
  • trunk/Source/WebKit/GPUProcess/graphics/RemoteImageBufferMessageHandlerProxy.h

    r258253 r268145  
    6060    void commitFlushContext(ImageBufferFlushIdentifier);
    6161
     62    RemoteRenderingBackendProxy& backend() { return m_remoteRenderingBackendProxy; }
     63
    6264private:
    6365    RemoteRenderingBackendProxy& m_remoteRenderingBackendProxy;
  • trunk/Source/WebKit/GPUProcess/graphics/RemoteImageBufferProxy.h

    r267772 r268145  
    2828#if ENABLE(GPU_PROCESS)
    2929
     30#include "GPUConnectionToWebProcess.h"
    3031#include "RemoteImageBufferMessageHandlerProxy.h"
    3132#include <WebCore/ConcreteImageBuffer.h>
     
    8586    }
    8687
    87     bool apply(WebCore::DisplayList::Item& item, WebCore::GraphicsContext&) override
     88    bool apply(WebCore::DisplayList::Item& item, WebCore::GraphicsContext& context) override
    8889    {
    89         if (item.type() != WebCore::DisplayList::ItemType::PutImageData)
    90             return false;
     90        if (item.type() == WebCore::DisplayList::ItemType::PutImageData) {
     91            auto& putImageDataItem = static_cast<WebCore::DisplayList::PutImageData&>(item);
     92            putImageData(putImageDataItem.inputFormat(), putImageDataItem.imageData(), putImageDataItem.srcRect(), putImageDataItem.destPoint(), putImageDataItem.destFormat());
     93            return true;
     94        }
    9195
    92         auto& putImageDataItem = static_cast<WebCore::DisplayList::PutImageData&>(item);
    93         putImageData(putImageDataItem.inputFormat(), putImageDataItem.imageData(), putImageDataItem.srcRect(), putImageDataItem.destPoint(), putImageDataItem.destFormat());
    94         return true;
     96        if (item.type() == WebCore::DisplayList::ItemType::PaintFrameForMedia) {
     97            apply(static_cast<WebCore::DisplayList::PaintFrameForMedia&>(item), context);
     98            return true;
     99        }
     100
     101        return false;
     102    }
     103
     104    void apply(WebCore::DisplayList::PaintFrameForMedia& item, WebCore::GraphicsContext& context)
     105    {
     106        auto process = backend().gpuConnectionToWebProcess();
     107        if (!process)
     108            return;
     109
     110        auto playerProxy = process->remoteMediaPlayerManagerProxy().getProxy(item.identifier());
     111        if (!playerProxy)
     112            return;
     113
     114        auto player = playerProxy->mediaPlayer();
     115        if (!player)
     116            return;
     117
     118        context.paintFrameForMedia(*player, item.destination());
    95119    }
    96120};
  • trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.cpp

    r258253 r268145  
    122122}
    123123
     124GPUConnectionToWebProcess* RemoteRenderingBackendProxy::gpuConnectionToWebProcess() const
     125{
     126    return m_gpuConnectionToWebProcess.get();
     127}
     128
    124129} // namespace WebKit
    125130
  • trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackendProxy.h

    r258253 r268145  
    6161
    6262    RenderingBackendIdentifier renderingBackendIdentifier() const { return m_renderingBackendIdentifier; }
     63    GPUConnectionToWebProcess* gpuConnectionToWebProcess() const;
    6364
    6465private:
Note: See TracChangeset for help on using the changeset viewer.