Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CG] Optimize getting the ImageFrame metadata #28799

Conversation

shallawa
Copy link
Contributor

@shallawa shallawa commented May 20, 2024

828ba37

[CG] Optimize getting the ImageFrame metadata
https://bugs.webkit.org/show_bug.cgi?id=274399
rdar://126232516

Reviewed by Simon Fraser.

BitmapImageSource::cacheMetadataAtIndex() currently makes separate calls to
ImageDecoder functions. Some of them calls CGImageSourceCopyPropertiesAtIndex()
and we end up calling CGImageSourceCopyPropertiesAtIndex() multiple times.

This can be optimized by adding ImageDecoder::frameMetadataAtIndex() which fills
in the ImageFrame metadata. This way CGImageSourceCopyPropertiesAtIndex() will
be called once and its CFDictionary will be used to retrieve all the ImageFrame
metadata.

* Source/WebCore/platform/graphics/BitmapImageSource.cpp:
(WebCore::BitmapImageSource::cacheMetadataAtIndex):
* Source/WebCore/platform/graphics/ImageDecoder.cpp:
(WebCore::ImageDecoder::fetchFrameMetaDataAtIndex const):
* Source/WebCore/platform/graphics/ImageDecoder.h:
(WebCore::ImageDecoder::frameDensityCorrectedSizeAtIndex const):
(WebCore::ImageDecoder::densityCorrectedSizeAtIndex const): Deleted.
* Source/WebCore/platform/graphics/ImageFrame.h:
* Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp:
(WebCore::frameSizeFromProperties):
(WebCore::ImageDecoderCG::encodedDataStatus const):
(WebCore::ImageDecoderCG::hasAlpha const):
(WebCore::ImageDecoderCG::frameSizeAtIndex const):
(WebCore::ImageDecoderCG::frameOrientationAtIndex const):
(WebCore::ImageDecoderCG::frameDensityCorrectedSizeAtIndex const):
(WebCore::ImageDecoderCG::frameHasAlphaAtIndex const):
(WebCore::ImageDecoderCG::fetchFrameMetaDataAtIndex const):
(WebCore::ImageDecoderCG::decodeUTI):
(WebCore::ImageDecoderCG::shouldUseQuickLookForFullscreen const):
(WebCore::ImageDecoderCG::densityCorrectedSizeAtIndex const): Deleted.
* Source/WebCore/platform/graphics/cg/ImageDecoderCG.h:
* Source/WebCore/platform/image-decoders/ScalableImageDecoder.h:

Canonical link: https://commits.webkit.org/279069@main

dfb0a0d

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug   πŸ§ͺ wpe-wk2 βœ… πŸ§ͺ wincairo-tests
βœ… πŸ§ͺ webkitperl   πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ§ͺ api-wpe
  πŸ§ͺ ios-wk2-wpt βœ… πŸ§ͺ mac-wk1 βœ… πŸ›  wpe-cairo
  πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 βœ… πŸ›  gtk
βœ… πŸ›  tv   πŸ§ͺ mac-AS-debug-wk2   πŸ§ͺ gtk-wk2
  πŸ›  tv-sim βœ… πŸ§ͺ mac-wk2-stress   πŸ§ͺ api-gtk
βœ… πŸ›  πŸ§ͺ merge   πŸ›  watch
βœ… πŸ›  watch-sim

@shallawa shallawa self-assigned this May 20, 2024
@shallawa shallawa added the Images For bugs in image handling. label May 20, 2024
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 20, 2024
@shallawa shallawa removed the merging-blocked Applied to prevent a change from being merged label May 20, 2024
@shallawa shallawa force-pushed the eng/CG-Optimize-getting-the-ImageFrame-metadata branch from d8c4323 to 9fef97e Compare May 20, 2024 19:46
@shallawa shallawa requested review from smfr and heycam May 20, 2024 20:48
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 20, 2024
@@ -147,4 +152,21 @@ bool ImageDecoder::supportsMediaType(MediaType type)
return false;
}

bool ImageDecoder::frameMetadataAtIndex(size_t index, SubsamplingLevel subsamplingLevel, const DecodingOptions& options, ImageFrame& frame) const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is a bit vague. From the call site it's hard to see that this is filling some members of frame. Maybe fetchFrameMetaDataAtIndex()?

@shallawa shallawa removed the merging-blocked Applied to prevent a change from being merged label May 21, 2024
@shallawa shallawa force-pushed the eng/CG-Optimize-getting-the-ImageFrame-metadata branch from 9fef97e to dfb0a0d Compare May 21, 2024 17:31
@shallawa shallawa added the merge-queue Applied to send a pull request to merge-queue label May 21, 2024
https://bugs.webkit.org/show_bug.cgi?id=274399
rdar://126232516

Reviewed by Simon Fraser.

BitmapImageSource::cacheMetadataAtIndex() currently makes separate calls to
ImageDecoder functions. Some of them calls CGImageSourceCopyPropertiesAtIndex()
and we end up calling CGImageSourceCopyPropertiesAtIndex() multiple times.

This can be optimized by adding ImageDecoder::frameMetadataAtIndex() which fills
in the ImageFrame metadata. This way CGImageSourceCopyPropertiesAtIndex() will
be called once and its CFDictionary will be used to retrieve all the ImageFrame
metadata.

* Source/WebCore/platform/graphics/BitmapImageSource.cpp:
(WebCore::BitmapImageSource::cacheMetadataAtIndex):
* Source/WebCore/platform/graphics/ImageDecoder.cpp:
(WebCore::ImageDecoder::fetchFrameMetaDataAtIndex const):
* Source/WebCore/platform/graphics/ImageDecoder.h:
(WebCore::ImageDecoder::frameDensityCorrectedSizeAtIndex const):
(WebCore::ImageDecoder::densityCorrectedSizeAtIndex const): Deleted.
* Source/WebCore/platform/graphics/ImageFrame.h:
* Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp:
(WebCore::frameSizeFromProperties):
(WebCore::ImageDecoderCG::encodedDataStatus const):
(WebCore::ImageDecoderCG::hasAlpha const):
(WebCore::ImageDecoderCG::frameSizeAtIndex const):
(WebCore::ImageDecoderCG::frameOrientationAtIndex const):
(WebCore::ImageDecoderCG::frameDensityCorrectedSizeAtIndex const):
(WebCore::ImageDecoderCG::frameHasAlphaAtIndex const):
(WebCore::ImageDecoderCG::fetchFrameMetaDataAtIndex const):
(WebCore::ImageDecoderCG::decodeUTI):
(WebCore::ImageDecoderCG::shouldUseQuickLookForFullscreen const):
(WebCore::ImageDecoderCG::densityCorrectedSizeAtIndex const): Deleted.
* Source/WebCore/platform/graphics/cg/ImageDecoderCG.h:
* Source/WebCore/platform/image-decoders/ScalableImageDecoder.h:

Canonical link: https://commits.webkit.org/279069@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/CG-Optimize-getting-the-ImageFrame-metadata branch from dfb0a0d to 828ba37 Compare May 21, 2024 18:46
@webkit-commit-queue
Copy link
Collaborator

Committed 279069@main (828ba37): https://commits.webkit.org/279069@main

Reviewed commits have been landed. Closing PR #28799 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 828ba37 into WebKit:main May 21, 2024
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Images For bugs in image handling.
Projects
None yet
5 participants