From e0a79ba9f2ba9024598ce01348bf357c5cc6520c Mon Sep 17 00:00:00 2001 From: Timothy Nikkel Date: Tue, 3 Sep 2019 15:36:23 +0000 Subject: [PATCH] Bug 1578164. Use async notifications when requesting decode of an image in most places. r=aosmond Most of things will likely be no real change because they ask for the exact frame they want immediately before. Differential Revision: https://phabricator.services.mozilla.com/D44359 --HG-- extra : moz-landing-system : lando --- dom/base/nsContentUtils.cpp | 3 ++- dom/canvas/ImageBitmap.cpp | 5 +++-- image/imgTools.cpp | 14 ++++++++------ layout/xul/nsImageBoxFrame.cpp | 2 +- widget/PuppetWidget.cpp | 3 ++- widget/cocoa/nsClipboard.mm | 3 ++- widget/cocoa/nsCocoaUtils.mm | 3 ++- widget/gtk/nsImageToPixbuf.cpp | 3 ++- widget/windows/ToastNotificationHandler.cpp | 3 ++- widget/windows/WinUtils.cpp | 3 ++- widget/windows/nsWindowGfx.cpp | 3 ++- 11 files changed, 28 insertions(+), 17 deletions(-) diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index d2967dfe84da..852a414be477 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -7379,7 +7379,8 @@ void nsContentUtils::TransferableToIPCTransferable( } else if (nsCOMPtr image = do_QueryInterface(data)) { // Images to be placed on the clipboard are imgIContainers. RefPtr surface = image->GetFrame( - imgIContainer::FRAME_CURRENT, imgIContainer::FLAG_SYNC_DECODE); + imgIContainer::FRAME_CURRENT, + imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY); if (!surface) { continue; } diff --git a/dom/canvas/ImageBitmap.cpp b/dom/canvas/ImageBitmap.cpp index 9c178711f295..8d4661f5102d 100644 --- a/dom/canvas/ImageBitmap.cpp +++ b/dom/canvas/ImageBitmap.cpp @@ -1544,8 +1544,9 @@ CreateImageBitmapFromBlob::OnImageReady(imgIContainer* aImgContainer, MOZ_ASSERT(aImgContainer); // Get the surface out. - uint32_t frameFlags = - imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_WANT_DATA_SURFACE; + uint32_t frameFlags = imgIContainer::FLAG_SYNC_DECODE | + imgIContainer::FLAG_ASYNC_NOTIFY | + imgIContainer::FLAG_WANT_DATA_SURFACE; uint32_t whichFrame = imgIContainer::FRAME_FIRST; RefPtr surface = aImgContainer->GetFrame(whichFrame, frameFlags); diff --git a/image/imgTools.cpp b/image/imgTools.cpp index f415be660964..dd87c049afd5 100644 --- a/image/imgTools.cpp +++ b/image/imgTools.cpp @@ -335,7 +335,8 @@ imgTools::EncodeImage(imgIContainer* aContainer, const nsACString& aMimeType, nsIInputStream** aStream) { // Use frame 0 from the image container. RefPtr frame = aContainer->GetFrame( - imgIContainer::FRAME_FIRST, imgIContainer::FLAG_SYNC_DECODE); + imgIContainer::FRAME_FIRST, + imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY); NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE); RefPtr dataSurface; @@ -380,10 +381,10 @@ imgTools::EncodeScaledImage(imgIContainer* aContainer, aScaledHeight == 0 ? imageHeight : aScaledHeight); // Use frame 0 from the image container. - RefPtr frame = - aContainer->GetFrameAtSize(scaledSize, imgIContainer::FRAME_FIRST, - imgIContainer::FLAG_HIGH_QUALITY_SCALING | - imgIContainer::FLAG_SYNC_DECODE); + RefPtr frame = aContainer->GetFrameAtSize( + scaledSize, imgIContainer::FRAME_FIRST, + imgIContainer::FLAG_HIGH_QUALITY_SCALING | + imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY); NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE); // If the given surface is the right size/format, we can encode it directly. @@ -445,7 +446,8 @@ imgTools::EncodeCroppedImage(imgIContainer* aContainer, // Use frame 0 from the image container. RefPtr frame = aContainer->GetFrame( - imgIContainer::FRAME_FIRST, imgIContainer::FLAG_SYNC_DECODE); + imgIContainer::FRAME_FIRST, + imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY); NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE); int32_t frameWidth = frame->GetSize().width; diff --git a/layout/xul/nsImageBoxFrame.cpp b/layout/xul/nsImageBoxFrame.cpp index 5f1172dc4874..3ea65b7da639 100644 --- a/layout/xul/nsImageBoxFrame.cpp +++ b/layout/xul/nsImageBoxFrame.cpp @@ -277,7 +277,7 @@ void nsImageBoxFrame::UpdateImage() { mIntrinsicSize.SizeTo(0, 0); } else { // We don't want discarding or decode-on-draw for xul images. - mImageRequest->StartDecoding(imgIContainer::FLAG_NONE); + mImageRequest->StartDecoding(imgIContainer::FLAG_ASYNC_NOTIFY); mImageRequest->LockImage(); } diff --git a/widget/PuppetWidget.cpp b/widget/PuppetWidget.cpp index 0f582c3ba8c6..44f64ff96014 100644 --- a/widget/PuppetWidget.cpp +++ b/widget/PuppetWidget.cpp @@ -939,7 +939,8 @@ void PuppetWidget::SetCursor(nsCursor aCursor, imgIContainer* aCursorImage, if (aCursorImage) { RefPtr surface = aCursorImage->GetFrame( - imgIContainer::FRAME_CURRENT, imgIContainer::FLAG_SYNC_DECODE); + imgIContainer::FRAME_CURRENT, + imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY); if (surface) { if (RefPtr dataSurface = surface->GetDataSurface()) { hasCustomCursor = true; diff --git a/widget/cocoa/nsClipboard.mm b/widget/cocoa/nsClipboard.mm index 08bffbd6bd8d..0b4923040800 100644 --- a/widget/cocoa/nsClipboard.mm +++ b/widget/cocoa/nsClipboard.mm @@ -511,7 +511,8 @@ NSDictionary* nsClipboard::PasteboardDictFromTransferable(nsITransferable* aTran } RefPtr surface = - image->GetFrame(imgIContainer::FRAME_CURRENT, imgIContainer::FLAG_SYNC_DECODE); + image->GetFrame(imgIContainer::FRAME_CURRENT, + imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY); if (!surface) { continue; } diff --git a/widget/cocoa/nsCocoaUtils.mm b/widget/cocoa/nsCocoaUtils.mm index ef7212df312e..49074f95e8d6 100644 --- a/widget/cocoa/nsCocoaUtils.mm +++ b/widget/cocoa/nsCocoaUtils.mm @@ -500,7 +500,8 @@ nsresult nsCocoaUtils::CreateNSImageFromImageContainer(imgIContainer* aImage, ui surface = drawTarget->Snapshot(); } else { - surface = aImage->GetFrame(aWhichFrame, imgIContainer::FLAG_SYNC_DECODE); + surface = aImage->GetFrame(aWhichFrame, + imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY); } NS_ENSURE_TRUE(surface, NS_ERROR_FAILURE); diff --git a/widget/gtk/nsImageToPixbuf.cpp b/widget/gtk/nsImageToPixbuf.cpp index 76d41080b8b9..c70e58957676 100644 --- a/widget/gtk/nsImageToPixbuf.cpp +++ b/widget/gtk/nsImageToPixbuf.cpp @@ -29,7 +29,8 @@ nsImageToPixbuf::ConvertImageToPixbuf(imgIContainer* aImage) { GdkPixbuf* nsImageToPixbuf::ImageToPixbuf(imgIContainer* aImage) { RefPtr surface = aImage->GetFrame( - imgIContainer::FRAME_CURRENT, imgIContainer::FLAG_SYNC_DECODE); + imgIContainer::FRAME_CURRENT, + imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY); // If the last call failed, it was probably because our call stack originates // in an imgINotificationObserver event, meaning that we're not allowed diff --git a/widget/windows/ToastNotificationHandler.cpp b/widget/windows/ToastNotificationHandler.cpp index b96f7763edf3..62b928643125 100644 --- a/widget/windows/ToastNotificationHandler.cpp +++ b/widget/windows/ToastNotificationHandler.cpp @@ -528,7 +528,8 @@ nsresult ToastNotificationHandler::AsyncSaveImage(imgIRequest* aRequest) { nsCOMPtr imageFile(mImageFile); RefPtr surface = imgContainer->GetFrame( - imgIContainer::FRAME_FIRST, imgIContainer::FLAG_SYNC_DECODE); + imgIContainer::FRAME_FIRST, + imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY); nsCOMPtr r = NS_NewRunnableFunction( "ToastNotificationHandler::AsyncWriteBitmap", [self, imageFile, surface]() -> void { diff --git a/widget/windows/WinUtils.cpp b/widget/windows/WinUtils.cpp index 161c8922da9d..89f276050a88 100644 --- a/widget/windows/WinUtils.cpp +++ b/widget/windows/WinUtils.cpp @@ -1637,7 +1637,8 @@ void WinUtils::SetupKeyModifiersSequence(nsTArray* aArray, /* static */ nsresult WinUtils::WriteBitmap(nsIFile* aFile, imgIContainer* aImage) { RefPtr surface = aImage->GetFrame( - imgIContainer::FRAME_FIRST, imgIContainer::FLAG_SYNC_DECODE); + imgIContainer::FRAME_FIRST, + imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY); NS_ENSURE_TRUE(surface, NS_ERROR_FAILURE); return WriteBitmap(aFile, surface); diff --git a/widget/windows/nsWindowGfx.cpp b/widget/windows/nsWindowGfx.cpp index 3d7dcbbf9dbc..a154f2c1d58c 100644 --- a/widget/windows/nsWindowGfx.cpp +++ b/widget/windows/nsWindowGfx.cpp @@ -439,7 +439,8 @@ nsresult nsWindowGfx::CreateIcon(imgIContainer* aContainer, bool aIsCursor, // Get the image data RefPtr surface = aContainer->GetFrame( - imgIContainer::FRAME_CURRENT, imgIContainer::FLAG_SYNC_DECODE); + imgIContainer::FRAME_CURRENT, + imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY); NS_ENSURE_TRUE(surface, NS_ERROR_NOT_AVAILABLE); IntSize frameSize = surface->GetSize();