Diff
Modified: trunk/Source/WebKit/ChangeLog (288955 => 288956)
--- trunk/Source/WebKit/ChangeLog 2022-02-02 17:19:22 UTC (rev 288955)
+++ trunk/Source/WebKit/ChangeLog 2022-02-02 17:52:22 UTC (rev 288956)
@@ -1,3 +1,43 @@
+2022-02-02 Wenson Hsieh <[email protected]>
+
+ Adjust some Live Text code to only use VKC-prefixed VisionKit classes if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)
+ https://bugs.webkit.org/show_bug.cgi?id=235991
+
+ Reviewed by Megan Gardner.
+
+ Rather than creating VKCImageAnalysis/VKCImageAnalyzer/VKCImageAnalyzerRequest and statically casting to
+ VKImageAnalysis/VKImageAnalyzer/VKImageAnalyzerRequest respectively, add a typedef that abstracts away the
+ differing VK/VKC prefixes behind CocoaImage(Analysis|Analyzer|AnalyzerRequest), and use this typedef everywhere
+ we currently use the VK-prefixed types.
+
+ Since the VK-prefixed classes are being entirely removed and replaced with VKC-prefixed classes at some point,
+ this allows us to be consistent (at least, within a given OS version) about the VisionKit object types we're
+ creating and passing around in Live Text code.
+
+ No change in behavior.
+
+ * Platform/cocoa/TextRecognitionUtilities.h:
+ * Platform/cocoa/TextRecognitionUtilities.mm:
+ (WebKit::createImageAnalyzer):
+ (WebKit::createImageAnalyzerRequest):
+ (WebKit::makeTextRecognitionResult):
+ (WebKit::hasVisionKitCorePrefixedClasses): Deleted.
+ * UIProcess/Cocoa/WebViewImpl.h:
+ * UIProcess/Cocoa/WebViewImpl.mm:
+ (WebKit::WebViewImpl::ensureImageAnalyzer):
+ (WebKit::createImageAnalyzerRequest):
+ (WebKit::WebViewImpl::requestTextRecognition):
+ (WebKit::WebViewImpl::computeHasImageAnalysisResults):
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKContentView imageAnalyzer]):
+ (-[WKContentView createImageAnalyzerRequest:image:imageURL:]):
+ (-[WKContentView createImageAnalyzerRequest:image:]):
+ (-[WKContentView _updateContextMenuForMachineReadableCodeForImageAnalysis:]):
+ (-[WKContentView requestTextRecognition:imageData:identifier:completionHandler:]):
+ (-[WKContentView imageAnalysisGestureDidBegin:]):
+ (-[WKContentView _completeImageAnalysisRequestForContextMenu:requestIdentifier:hasTextResults:]):
+ (-[WKContentView imageAnalysisGestureDidTimeOut:]):
+
2022-02-02 Youenn Fablet <[email protected]>
RealtimeVideoSource::adaptVideoSample should not create IOSurfaces when running in WebProcess
Modified: trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.h (288955 => 288956)
--- trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.h 2022-02-02 17:19:22 UTC (rev 288955)
+++ trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.h 2022-02-02 17:52:22 UTC (rev 288956)
@@ -31,6 +31,16 @@
#import <wtf/CompletionHandler.h>
#import <wtf/RetainPtr.h>
+#if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)
+using CocoaImageAnalysis = VKCImageAnalysis;
+using CocoaImageAnalyzer = VKCImageAnalyzer;
+using CocoaImageAnalyzerRequest = VKCImageAnalyzerRequest;
+#else
+using CocoaImageAnalysis = VKImageAnalysis;
+using CocoaImageAnalyzer = VKImageAnalyzer;
+using CocoaImageAnalyzerRequest = VKImageAnalyzerRequest;
+#endif
+
namespace WebCore {
struct TextRecognitionResult;
}
@@ -41,14 +51,13 @@
bool textRecognitionEnhancementsSystemFeatureEnabled();
bool imageAnalysisQueueSystemFeatureEnabled();
-WebCore::TextRecognitionResult makeTextRecognitionResult(VKImageAnalysis *);
+WebCore::TextRecognitionResult makeTextRecognitionResult(CocoaImageAnalysis *);
-// FIXME: Replace the return types of these helper functions with VKCImageAnalyzer and VKCImageAnalyzerRequest, respectively.
-RetainPtr<VKImageAnalyzer> createImageAnalyzer();
-RetainPtr<VKImageAnalyzerRequest> createImageAnalyzerRequest(CGImageRef, VKAnalysisTypes);
+RetainPtr<CocoaImageAnalyzer> createImageAnalyzer();
+RetainPtr<CocoaImageAnalyzerRequest> createImageAnalyzerRequest(CGImageRef, VKAnalysisTypes);
#if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)
-void requestImageAnalysisWithIdentifier(VKImageAnalyzer *, const String& identifier, CGImageRef, CompletionHandler<void(WebCore::TextRecognitionResult&&)>&&);
+void requestImageAnalysisWithIdentifier(CocoaImageAnalyzer *, const String& identifier, CGImageRef, CompletionHandler<void(WebCore::TextRecognitionResult&&)>&&);
#endif
}
Modified: trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.mm (288955 => 288956)
--- trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.mm 2022-02-02 17:19:22 UTC (rev 288955)
+++ trunk/Source/WebKit/Platform/cocoa/TextRecognitionUtilities.mm 2022-02-02 17:52:22 UTC (rev 288956)
@@ -36,30 +36,22 @@
namespace WebKit {
using namespace WebCore;
-static bool hasVisionKitCorePrefixedClasses()
+RetainPtr<CocoaImageAnalyzer> createImageAnalyzer()
{
- static bool result = false;
- static std::once_flag onceFlag;
- std::call_once(onceFlag, [&] {
- result = !!PAL::getVKCImageAnalyzerClass();
- });
- return result;
-}
-
-RetainPtr<VKImageAnalyzer> createImageAnalyzer()
-{
- if (hasVisionKitCorePrefixedClasses())
- return adoptNS([static_cast<VKImageAnalyzer *>(PAL::allocVKCImageAnalyzerInstance()) init]);
-
+#if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)
+ return adoptNS([PAL::allocVKCImageAnalyzerInstance() init]);
+#else
return adoptNS([PAL::allocVKImageAnalyzerInstance() init]);
+#endif
}
-RetainPtr<VKImageAnalyzerRequest> createImageAnalyzerRequest(CGImageRef image, VKAnalysisTypes types)
+RetainPtr<CocoaImageAnalyzerRequest> createImageAnalyzerRequest(CGImageRef image, VKAnalysisTypes types)
{
- if (hasVisionKitCorePrefixedClasses())
- return adoptNS([static_cast<VKImageAnalyzerRequest *>(PAL::allocVKCImageAnalyzerRequestInstance()) initWithCGImage:image orientation:VKImageOrientationUp requestType:types]);
-
+#if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)
+ return adoptNS([(PAL::allocVKCImageAnalyzerRequestInstance()) initWithCGImage:image orientation:VKImageOrientationUp requestType:types]);
+#else
return adoptNS([PAL::allocVKImageAnalyzerRequestInstance() initWithCGImage:image orientation:VKImageOrientationUp requestType:types]);
+#endif
}
static FloatQuad floatQuad(VKQuad *quad)
@@ -76,7 +68,7 @@
return quads;
}
-TextRecognitionResult makeTextRecognitionResult(VKImageAnalysis *analysis)
+TextRecognitionResult makeTextRecognitionResult(CocoaImageAnalysis *analysis)
{
NSArray<VKWKLineInfo *> *allLines = analysis.allLines;
TextRecognitionResult result;
Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h (288955 => 288956)
--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h 2022-02-02 17:19:22 UTC (rev 288955)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h 2022-02-02 17:52:22 UTC (rev 288956)
@@ -29,6 +29,7 @@
#include "PDFPluginIdentifier.h"
#include "ShareableBitmap.h"
+#include "TextRecognitionUtilities.h"
#include "WKLayoutMode.h"
#include <WebCore/DOMPasteAccess.h>
#include <WebCore/FocusDirection.h>
@@ -55,7 +56,6 @@
OBJC_CLASS NSTextInputContext;
OBJC_CLASS NSView;
OBJC_CLASS QLPreviewPanel;
-OBJC_CLASS VKImageAnalyzer;
OBJC_CLASS WKAccessibilitySettingsObserver;
OBJC_CLASS WKBrowsingContextController;
OBJC_CLASS WKDOMPasteMenuDelegate;
@@ -741,7 +741,7 @@
#endif
#if ENABLE(IMAGE_ANALYSIS)
- VKImageAnalyzer *ensureImageAnalyzer();
+ PlatformImageAnalyzer *ensureImageAnalyzer();
#endif
WeakObjCPtr<NSView<WebViewImplDelegate>> m_view;
@@ -886,7 +886,7 @@
#if ENABLE(IMAGE_ANALYSIS)
RefPtr<WorkQueue> m_imageAnalyzerQueue;
- RetainPtr<VKImageAnalyzer> m_imageAnalyzer;
+ RetainPtr<PlatformImageAnalyzer> m_imageAnalyzer;
#endif
#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (288955 => 288956)
--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm 2022-02-02 17:19:22 UTC (rev 288955)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm 2022-02-02 17:52:22 UTC (rev 288956)
@@ -53,7 +53,6 @@
#import "StringUtilities.h"
#import "TextChecker.h"
#import "TextCheckerState.h"
-#import "TextRecognitionUtilities.h"
#import "TiledCoreAnimationDrawingAreaProxy.h"
#import "UIGamepadProvider.h"
#import "UndoOrRedo.h"
@@ -186,7 +185,7 @@
namespace WebKit {
-VKImageAnalyzer *WebViewImpl::ensureImageAnalyzer()
+CocoaImageAnalyzer *WebViewImpl::ensureImageAnalyzer()
{
if (!m_imageAnalyzer) {
m_imageAnalyzerQueue = WorkQueue::create("WebKit image analyzer queue");
@@ -196,7 +195,7 @@
return m_imageAnalyzer.get();
}
-static RetainPtr<VKImageAnalyzerRequest> createImageAnalyzerRequest(CGImageRef image, const URL& imageURL, const URL& pageURL, VKAnalysisTypes types)
+static RetainPtr<CocoaImageAnalyzerRequest> createImageAnalyzerRequest(CGImageRef image, const URL& imageURL, const URL& pageURL, VKAnalysisTypes types)
{
auto request = createImageAnalyzerRequest(image, types);
[request setImageURL:imageURL];
@@ -228,7 +227,7 @@
auto request = createImageAnalyzerRequest(cgImage.get(), imageURL, [NSURL _web_URLWithWTFString:m_page->currentURL()], VKAnalysisTypeText);
auto startTime = MonotonicTime::now();
- [ensureImageAnalyzer() processRequest:request.get() progressHandler:nil completionHandler:makeBlockPtr([completion = WTFMove(completion), startTime] (VKImageAnalysis *analysis, NSError *) mutable {
+ [ensureImageAnalyzer() processRequest:request.get() progressHandler:nil completionHandler:makeBlockPtr([completion = WTFMove(completion), startTime] (CocoaImageAnalysis *analysis, NSError *) mutable {
callOnMainRunLoop([completion = WTFMove(completion), result = makeTextRecognitionResult(analysis), startTime] () mutable {
RELEASE_LOG(Images, "Image analysis completed in %.0f ms (found text? %d)", (MonotonicTime::now() - startTime).milliseconds(), !result.isEmpty());
completion(WTFMove(result));
@@ -247,7 +246,7 @@
auto analysisType = type == ImageAnalysisType::VisualSearch ? VKAnalysisTypeVisualSearch : VKAnalysisTypeText;
auto request = createImageAnalyzerRequest(cgImage.get(), imageURL, [NSURL _web_URLWithWTFString:m_page->currentURL()], analysisType);
auto startTime = MonotonicTime::now();
- [ensureImageAnalyzer() processRequest:request.get() progressHandler:nil completionHandler:makeBlockPtr([completion = WTFMove(completion), startTime, analysisType] (VKImageAnalysis *analysis, NSError *) mutable {
+ [ensureImageAnalyzer() processRequest:request.get() progressHandler:nil completionHandler:makeBlockPtr([completion = WTFMove(completion), startTime, analysisType] (CocoaImageAnalysis *analysis, NSError *) mutable {
BOOL result = [analysis hasResultsForAnalysisTypes:analysisType];
CFRunLoopPerformBlock(CFRunLoopGetMain(), (__bridge CFStringRef)NSEventTrackingRunLoopMode, makeBlockPtr([completion = WTFMove(completion), result, analysisType, startTime] () mutable {
RELEASE_LOG(Images, "Image analysis completed in %.0f ms (found %s? %d)", (MonotonicTime::now() - startTime).milliseconds(), analysisType == VKAnalysisTypeVisualSearch ? "visual search results" : "text", result);
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (288955 => 288956)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2022-02-02 17:19:22 UTC (rev 288955)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2022-02-02 17:52:22 UTC (rev 288956)
@@ -10250,7 +10250,7 @@
#pragma mark - Image Extraction
-- (VKImageAnalyzer *)imageAnalyzer
+- (CocoaImageAnalyzer *)imageAnalyzer
{
if (!_imageAnalyzer)
_imageAnalyzer = WebKit::createImageAnalyzer();
@@ -10320,7 +10320,7 @@
_elementPendingImageAnalysis = std::nullopt;
}
-- (RetainPtr<VKImageAnalyzerRequest>)createImageAnalyzerRequest:(VKAnalysisTypes)analysisTypes image:(CGImageRef)image imageURL:(NSURL *)imageURL
+- (RetainPtr<CocoaImageAnalyzerRequest>)createImageAnalyzerRequest:(VKAnalysisTypes)analysisTypes image:(CGImageRef)image imageURL:(NSURL *)imageURL
{
auto request = WebKit::createImageAnalyzerRequest(image, analysisTypes);
[request setImageURL:imageURL];
@@ -10328,7 +10328,7 @@
return request;
}
-- (RetainPtr<VKImageAnalyzerRequest>)createImageAnalyzerRequest:(VKAnalysisTypes)analysisTypes image:(CGImageRef)image
+- (RetainPtr<CocoaImageAnalyzerRequest>)createImageAnalyzerRequest:(VKAnalysisTypes)analysisTypes image:(CGImageRef)image
{
return [self createImageAnalyzerRequest:analysisTypes image:image imageURL:_positionInformation.imageURL];
}
@@ -10335,7 +10335,7 @@
#if USE(UICONTEXTMENU) && ENABLE(IMAGE_ANALYSIS_FOR_MACHINE_READABLE_CODES)
-- (void)_updateContextMenuForMachineReadableCodeForImageAnalysis:(VKImageAnalysis *)analysis
+- (void)_updateContextMenuForMachineReadableCodeForImageAnalysis:(CocoaImageAnalysis *)analysis
{
analysis.presentingViewControllerForMrcAction = [UIViewController _viewControllerForFullScreenPresentationFromView:self];
_contextMenuForMachineReadableCode = [analysis hasResultsForAnalysisTypes:VKAnalysisTypeMachineReadableCode | VKAnalysisTypeAppClip] ? analysis.mrcMenu : nil;
@@ -10380,7 +10380,7 @@
#endif
auto request = [self createImageAnalyzerRequest:VKAnalysisTypeText image:cgImage.get()];
- [self.imageAnalyzer processRequest:request.get() progressHandler:nil completionHandler:makeBlockPtr([completion = WTFMove(completion)] (VKImageAnalysis *result, NSError *) mutable {
+ [self.imageAnalyzer processRequest:request.get() progressHandler:nil completionHandler:makeBlockPtr([completion = WTFMove(completion)] (CocoaImageAnalysis *result, NSError *) mutable {
completion(WebKit::makeTextRecognitionResult(result));
}).get()];
}
@@ -10460,7 +10460,7 @@
}
auto textAnalysisStartTime = MonotonicTime::now();
- [[strongSelf imageAnalyzer] processRequest:requestForTextSelection.get() progressHandler:nil completionHandler:[requestIdentifier = WTFMove(requestIdentifier), weakSelf, elementContext, requestLocation, requestForContextMenu, gestureDeferralToken, textAnalysisStartTime] (VKImageAnalysis *result, NSError *error) mutable {
+ [[strongSelf imageAnalyzer] processRequest:requestForTextSelection.get() progressHandler:nil completionHandler:[requestIdentifier = WTFMove(requestIdentifier), weakSelf, elementContext, requestLocation, requestForContextMenu, gestureDeferralToken, textAnalysisStartTime] (CocoaImageAnalysis *result, NSError *error) mutable {
auto strongSelf = weakSelf.get();
if (![strongSelf validateImageAnalysisRequestIdentifier:requestIdentifier])
return;
@@ -10492,10 +10492,10 @@
} forRequest:request];
}
-- (void)_completeImageAnalysisRequestForContextMenu:(VKImageAnalyzerRequest *)requestForContextMenu requestIdentifier:(WebKit::ImageAnalysisRequestIdentifier)requestIdentifier hasTextResults:(BOOL)hasTextResults
+- (void)_completeImageAnalysisRequestForContextMenu:(CocoaImageAnalyzerRequest *)requestForContextMenu requestIdentifier:(WebKit::ImageAnalysisRequestIdentifier)requestIdentifier hasTextResults:(BOOL)hasTextResults
{
auto visualSearchAnalysisStartTime = MonotonicTime::now();
- [self.imageAnalyzer processRequest:requestForContextMenu progressHandler:nil completionHandler:[requestIdentifier = WTFMove(requestIdentifier), weakSelf = WeakObjCPtr<WKContentView>(self), hasTextResults, visualSearchAnalysisStartTime] (VKImageAnalysis *result, NSError *error) mutable {
+ [self.imageAnalyzer processRequest:requestForContextMenu progressHandler:nil completionHandler:[requestIdentifier = WTFMove(requestIdentifier), weakSelf = WeakObjCPtr<WKContentView>(self), hasTextResults, visualSearchAnalysisStartTime] (CocoaImageAnalysis *result, NSError *error) mutable {
auto strongSelf = weakSelf.get();
if (![strongSelf validateImageAnalysisRequestIdentifier:requestIdentifier])
return;
@@ -10564,7 +10564,7 @@
auto visualSearchAnalysisStartTime = MonotonicTime::now();
auto requestForContextMenu = [strongSelf createImageAnalyzerRequest:VKAnalysisTypeVisualSearch | VKAnalysisTypeMachineReadableCode | VKAnalysisTypeAppClip image:cgImage.get()];
- [[strongSelf imageAnalyzer] processRequest:requestForContextMenu.get() progressHandler:nil completionHandler:[weakSelf, location, visualSearchAnalysisStartTime] (VKImageAnalysis *result, NSError *error) {
+ [[strongSelf imageAnalyzer] processRequest:requestForContextMenu.get() progressHandler:nil completionHandler:[weakSelf, location, visualSearchAnalysisStartTime] (CocoaImageAnalysis *result, NSError *error) {
auto strongSelf = weakSelf.get();
if (!strongSelf)
return;