diff --git a/dom/ipc/BrowserParent.cpp b/dom/ipc/BrowserParent.cpp index c629a256fe80..75bfbd150b13 100644 --- a/dom/ipc/BrowserParent.cpp +++ b/dom/ipc/BrowserParent.cpp @@ -2320,12 +2320,9 @@ mozilla::ipc::IPCResult BrowserParent::RecvAsyncMessage( } mozilla::ipc::IPCResult BrowserParent::RecvSetCursor( - const nsCursor& aCursor, const bool& aHasCustomCursor, - Maybe&& aCursorData, const uint32_t& aWidth, - const uint32_t& aHeight, const float& aResolutionX, - const float& aResolutionY, const uint32_t& aStride, - const gfx::SurfaceFormat& aFormat, const uint32_t& aHotspotX, - const uint32_t& aHotspotY, const bool& aForce) { + const nsCursor& aCursor, Maybe&& aCustomCursor, + const float& aResolutionX, const float& aResolutionY, + const uint32_t& aHotspotX, const uint32_t& aHotspotY, const bool& aForce) { nsCOMPtr widget = GetWidget(); if (!widget) { return IPC_OK(); @@ -2335,38 +2332,21 @@ mozilla::ipc::IPCResult BrowserParent::RecvSetCursor( widget->ClearCachedCursor(); } - nsCOMPtr cursorImage; - if (aHasCustomCursor) { - const bool cursorDataValid = [&] { - if (!aCursorData) { - return false; - } - auto expectedSize = CheckedInt(aHeight) * aStride; - if (!expectedSize.isValid() || - expectedSize.value() != aCursorData->Size()) { - return false; - } - auto minStride = - CheckedInt(aWidth) * gfx::BytesPerPixel(aFormat); - if (!minStride.isValid() || aStride < minStride.value()) { - return false; - } - return true; - }(); - if (!cursorDataValid) { + nsCOMPtr customCursorImage; + if (aCustomCursor) { + RefPtr customCursorSurface = + nsContentUtils::IPCImageToSurface(*aCustomCursor); + if (!customCursorSurface) { return IPC_FAIL(this, "Invalid custom cursor data"); } - const gfx::IntSize size(aWidth, aHeight); - RefPtr customCursor = - gfx::CreateDataSourceSurfaceFromData(size, aFormat, aCursorData->Data(), - aStride); - RefPtr drawable = new gfxSurfaceDrawable(customCursor, size); - cursorImage = image::ImageOps::CreateFromDrawable(drawable); + RefPtr drawable = new gfxSurfaceDrawable( + customCursorSurface, customCursorSurface->GetSize()); + customCursorImage = image::ImageOps::CreateFromDrawable(drawable); } mCursor = nsIWidget::Cursor{aCursor, - std::move(cursorImage), + std::move(customCursorImage), aHotspotX, aHotspotY, {aResolutionX, aResolutionY}}; diff --git a/dom/ipc/BrowserParent.h b/dom/ipc/BrowserParent.h index aff7f6925e54..c7fc196c2525 100644 --- a/dom/ipc/BrowserParent.h +++ b/dom/ipc/BrowserParent.h @@ -383,12 +383,9 @@ class BrowserParent final : public PBrowserParent, nsTArray&& aDisabledCommands); mozilla::ipc::IPCResult RecvSetCursor( - const nsCursor& aValue, const bool& aHasCustomCursor, - Maybe&& aCursorData, const uint32_t& aWidth, - const uint32_t& aHeight, const float& aResolutionX, - const float& aResolutionY, const uint32_t& aStride, - const gfx::SurfaceFormat& aFormat, const uint32_t& aHotspotX, - const uint32_t& aHotspotY, const bool& aForce); + const nsCursor& aValue, Maybe&& aCustomCursor, + const float& aResolutionX, const float& aResolutionY, + const uint32_t& aHotspotX, const uint32_t& aHotspotY, const bool& aForce); mozilla::ipc::IPCResult RecvSetLinkStatus(const nsString& aStatus); diff --git a/dom/ipc/PBrowser.ipdl b/dom/ipc/PBrowser.ipdl index 372a81b13934..e8df017ca276 100644 --- a/dom/ipc/PBrowser.ipdl +++ b/dom/ipc/PBrowser.ipdl @@ -376,23 +376,12 @@ parent: * Set the native cursor. * @param value * The widget cursor to set. - * @param hasCustomCursor - * Whether there's any custom cursor represented by cursorData and - * company. - * @param customCursorData - * Serialized image data. - * @param width - * Width of the image. - * @param height - * Height of the image. + * @param customCursor + * Serialized image data for custom cursor. * @param resolutionX * Resolution of the image X axis in dppx units. * @param resolutionY * Resolution of the image Y axis in dppx units. - * @param stride - * Stride used in the image data. - * @param format - * Image format, see gfx::SurfaceFormat for possible values. * @param hotspotX * Horizontal hotspot of the image, as specified by the css cursor property. * @param hotspotY @@ -402,11 +391,8 @@ parent: * update. */ async SetCursor(nsCursor value, - bool hasCustomCursor, - BigBuffer? customCursorData, - uint32_t width, uint32_t height, + IPCImage? customCursor, float resolutionX, float resolutionY, - uint32_t stride, SurfaceFormat format, uint32_t hotspotX, uint32_t hotspotY, bool force); /** diff --git a/widget/PuppetWidget.cpp b/widget/PuppetWidget.cpp index 07b22d9a2b1c..7da6de3eaaf8 100644 --- a/widget/PuppetWidget.cpp +++ b/widget/PuppetWidget.cpp @@ -900,17 +900,14 @@ void PuppetWidget::SetCursor(const Cursor& aCursor) { return; } - bool hasCustomCursor = false; - Maybe customCursorData; - size_t length = 0; - IntSize customCursorSize; - int32_t stride = 0; - auto format = SurfaceFormat::B8G8R8A8; ImageResolution resolution = aCursor.mResolution; + Maybe customCursor; if (aCursor.IsCustom()) { - int32_t width = 0, height = 0; + int32_t width = 0; + int32_t height = 0; aCursor.mContainer->GetWidth(&width); aCursor.mContainer->GetHeight(&height); + const int32_t flags = imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY; RefPtr surface; @@ -928,22 +925,17 @@ void PuppetWidget::SetCursor(const Cursor& aCursor) { surface = aCursor.mContainer->GetFrame(imgIContainer::FRAME_CURRENT, flags); } + if (surface) { if (RefPtr dataSurface = surface->GetDataSurface()) { - hasCustomCursor = true; - customCursorData = - nsContentUtils::GetSurfaceData(*dataSurface, &length, &stride); - customCursorSize = dataSurface->GetSize(); - format = dataSurface->GetFormat(); + customCursor = nsContentUtils::SurfaceToIPCImage(*dataSurface); } } } if (!mBrowserChild->SendSetCursor( - aCursor.mDefaultCursor, hasCustomCursor, std::move(customCursorData), - customCursorSize.width, customCursorSize.height, resolution.mX, - resolution.mY, stride, format, aCursor.mHotspotX, aCursor.mHotspotY, - force)) { + aCursor.mDefaultCursor, std::move(customCursor), resolution.mX, + resolution.mY, aCursor.mHotspotX, aCursor.mHotspotY, force)) { return; } mCursor = aCursor;