Skip to content

Commit

Permalink
Unreviewed, reverting r263094@main.
Browse files Browse the repository at this point in the history
  • Loading branch information
webkit-commit-queue authored and fujii committed Apr 19, 2023
1 parent 4dce328 commit b801df7
Show file tree
Hide file tree
Showing 87 changed files with 116 additions and 1,770 deletions.
4 changes: 0 additions & 4 deletions Source/WTF/wtf/PlatformHave.h
Expand Up @@ -1131,10 +1131,6 @@
#define HAVE_WEBGPU_IMPLEMENTATION 1
#endif

#if PLATFORM(COCOA)
#define HAVE_SHAPE_DETECTION_API_IMPLEMENTATION 1
#endif

#if HAVE(WEBGPU_IMPLEMENTATION) && ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 130000) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 160000))
#define HAVE_METAL_BUFFER_BINDING_REFLECTION 1
#endif
Expand Down
16 changes: 0 additions & 16 deletions Source/WebCore/Headers.cmake
@@ -1,20 +1,4 @@
set(WebCore_PRIVATE_FRAMEWORK_HEADERS
Modules/ShapeDetection/Implementation/Cocoa/BarcodeDetectorImplementation.h
Modules/ShapeDetection/Implementation/Cocoa/FaceDetectorImplementation.h
Modules/ShapeDetection/Implementation/Cocoa/TextDetectorImplementation.h

Modules/ShapeDetection/Interfaces/BarcodeDetectorInterface.h
Modules/ShapeDetection/Interfaces/BarcodeDetectorOptionsInterface.h
Modules/ShapeDetection/Interfaces/BarcodeFormatInterface.h
Modules/ShapeDetection/Interfaces/DetectedBarcodeInterface.h
Modules/ShapeDetection/Interfaces/DetectedFaceInterface.h
Modules/ShapeDetection/Interfaces/DetectedTextInterface.h
Modules/ShapeDetection/Interfaces/FaceDetectorInterface.h
Modules/ShapeDetection/Interfaces/FaceDetectorOptionsInterface.h
Modules/ShapeDetection/Interfaces/LandmarkInterface.h
Modules/ShapeDetection/Interfaces/LandmarkTypeInterface.h
Modules/ShapeDetection/Interfaces/TextDetectorInterface.h

Modules/WebGPU/GPU.h
Modules/WebGPU/GPUAdapter.h
Modules/WebGPU/GPUAddressMode.h
Expand Down
64 changes: 23 additions & 41 deletions Source/WebCore/Modules/ShapeDetection/BarcodeDetector.cpp
Expand Up @@ -28,36 +28,27 @@

#include "BarcodeDetectorOptions.h"
#include "BarcodeFormat.h"
#include "Chrome.h"
#include "DetectedBarcode.h"
#include "Document.h"
#include "JSDOMPromiseDeferred.h"
#include "JSDetectedBarcode.h"
#include "Page.h"
#include "ScriptExecutionContext.h"
#include "WorkerGlobalScope.h"

#if PLATFORM(COCOA)
// FIXME: Use the GPU Process.
#include "BarcodeDetectorImplementation.h"
#endif

namespace WebCore {

ExceptionOr<Ref<BarcodeDetector>> BarcodeDetector::create(ScriptExecutionContext& scriptExecutionContext, const BarcodeDetectorOptions& barcodeDetectorOptions)
ExceptionOr<Ref<BarcodeDetector>> BarcodeDetector::create(const BarcodeDetectorOptions& barcodeDetectorOptions)
{
if (is<Document>(scriptExecutionContext)) {
const auto& document = downcast<Document>(scriptExecutionContext);
const auto* page = document.page();
if (!page)
return Exception { AbortError };
auto backing = page->chrome().createBarcodeDetector(barcodeDetectorOptions.convertToBacking());
if (!backing)
return Exception { AbortError };
return adoptRef(*new BarcodeDetector(backing.releaseNonNull()));
}

if (is<WorkerGlobalScope>(scriptExecutionContext)) {
// FIXME: https://bugs.webkit.org/show_bug.cgi?id=255380 Make the Shape Detection API work in Workers
return Exception { AbortError };
}

#if PLATFORM(COCOA)
// FIXME: Use the GPU Process.
auto backing = ShapeDetection::BarcodeDetectorImpl::create(barcodeDetectorOptions.convertToBacking());
return adoptRef(*new BarcodeDetector(WTFMove(backing)));
#else
UNUSED_PARAM(barcodeDetectorOptions);
return Exception { AbortError };
#endif
}


Expand All @@ -68,27 +59,18 @@ BarcodeDetector::BarcodeDetector(Ref<ShapeDetection::BarcodeDetector>&& backing)

BarcodeDetector::~BarcodeDetector() = default;

ExceptionOr<void> BarcodeDetector::getSupportedFormats(ScriptExecutionContext& scriptExecutionContext, GetSupportedFormatsPromise&& promise)
void BarcodeDetector::getSupportedFormats(GetSupportedFormatsPromise&& promise)
{
if (is<Document>(scriptExecutionContext)) {
const auto& document = downcast<Document>(scriptExecutionContext);
const auto* page = document.page();
if (!page)
return Exception { AbortError };
page->chrome().getBarcodeDetectorSupportedFormats(([promise = WTFMove(promise)](Vector<ShapeDetection::BarcodeFormat>&& barcodeFormats) mutable {
promise.resolve(barcodeFormats.map([](auto format) {
return convertFromBacking(format);
}));
#if PLATFORM(COCOA)
// FIXME: Use the GPU Process.
ShapeDetection::BarcodeDetectorImpl::getSupportedFormats([promise = WTFMove(promise)](Vector<ShapeDetection::BarcodeFormat>&& barcodeFormats) mutable {
promise.resolve(barcodeFormats.map([](auto format) {
return convertFromBacking(format);
}));
return { };
}

if (is<WorkerGlobalScope>(scriptExecutionContext)) {
// FIXME: https://bugs.webkit.org/show_bug.cgi?id=255380 Make the Shape Detection API work in Workers
return Exception { AbortError };
}

return Exception { AbortError };
});
#else
promise.resolve({ });
#endif
}

void BarcodeDetector::detect(const ImageBitmap::Source&, DetectPromise&& promise)
Expand Down
5 changes: 2 additions & 3 deletions Source/WebCore/Modules/ShapeDetection/BarcodeDetector.h
Expand Up @@ -37,16 +37,15 @@ namespace WebCore {
struct BarcodeDetectorOptions;
enum class BarcodeFormat : uint8_t;
struct DetectedBarcode;
class ScriptExecutionContext;

class BarcodeDetector : public RefCounted<BarcodeDetector> {
public:
static ExceptionOr<Ref<BarcodeDetector>> create(ScriptExecutionContext&, const BarcodeDetectorOptions&);
static ExceptionOr<Ref<BarcodeDetector>> create(const BarcodeDetectorOptions&);

~BarcodeDetector();

using GetSupportedFormatsPromise = DOMPromiseDeferred<IDLSequence<IDLEnumeration<BarcodeFormat>>>;
static ExceptionOr<void> getSupportedFormats(ScriptExecutionContext&, GetSupportedFormatsPromise&&);
static void getSupportedFormats(GetSupportedFormatsPromise&&);

using DetectPromise = DOMPromiseDeferred<IDLSequence<IDLDictionary<DetectedBarcode>>>;
void detect(const ImageBitmap::Source&, DetectPromise&&);
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/Modules/ShapeDetection/BarcodeDetector.idl
Expand Up @@ -49,8 +49,8 @@ typedef (CanvasImageSource or Blob or ImageData) ImageBitmapSource;
SecureContext
]
interface BarcodeDetector {
[CallWith=CurrentScriptExecutionContext] constructor(optional BarcodeDetectorOptions barcodeDetectorOptions = {});
[CallWith=CurrentScriptExecutionContext] static Promise<sequence<BarcodeFormat>> getSupportedFormats();
constructor(optional BarcodeDetectorOptions barcodeDetectorOptions = {});
static Promise<sequence<BarcodeFormat>> getSupportedFormats();

Promise<sequence<DetectedBarcode>> detect(ImageBitmapSource image);
};
35 changes: 13 additions & 22 deletions Source/WebCore/Modules/ShapeDetection/FaceDetector.cpp
Expand Up @@ -26,37 +26,28 @@
#include "config.h"
#include "FaceDetector.h"

#include "Chrome.h"
#include "DetectedFace.h"
#include "Document.h"
#include "FaceDetectorOptions.h"
#include "JSDOMPromiseDeferred.h"
#include "JSDetectedFace.h"
#include "Page.h"
#include "ScriptExecutionContext.h"
#include "WorkerGlobalScope.h"

#if PLATFORM(COCOA)
// FIXME: Use the GPU Process.
#include "FaceDetectorImplementation.h"
#endif

namespace WebCore {

ExceptionOr<Ref<FaceDetector>> FaceDetector::create(ScriptExecutionContext& scriptExecutionContext, const FaceDetectorOptions& faceDetectorOptions)
ExceptionOr<Ref<FaceDetector>> FaceDetector::create(const FaceDetectorOptions& faceDetectorOptions)
{
if (is<Document>(scriptExecutionContext)) {
const auto& document = downcast<Document>(scriptExecutionContext);
const auto* page = document.page();
if (!page)
return Exception { AbortError };
auto backing = page->chrome().createFaceDetector(faceDetectorOptions.convertToBacking());
if (!backing)
return Exception { AbortError };
return adoptRef(*new FaceDetector(backing.releaseNonNull()));
}

if (is<WorkerGlobalScope>(scriptExecutionContext)) {
// FIXME: https://bugs.webkit.org/show_bug.cgi?id=255380 Make the Shape Detection API work in Workers
return Exception { AbortError };
}

#if PLATFORM(COCOA)
// FIXME: Use the GPU Process.
auto backing = ShapeDetection::FaceDetectorImpl::create(faceDetectorOptions.convertToBacking());
return adoptRef(*new FaceDetector(WTFMove(backing)));
#else
UNUSED_PARAM(faceDetectorOptions);
return Exception { AbortError };
#endif
}

FaceDetector::FaceDetector(Ref<ShapeDetection::FaceDetector>&& backing)
Expand Down
3 changes: 1 addition & 2 deletions Source/WebCore/Modules/ShapeDetection/FaceDetector.h
Expand Up @@ -36,11 +36,10 @@ namespace WebCore {

struct FaceDetectorOptions;
struct DetectedFace;
class ScriptExecutionContext;

class FaceDetector : public RefCounted<FaceDetector> {
public:
static ExceptionOr<Ref<FaceDetector>> create(ScriptExecutionContext&, const FaceDetectorOptions&);
static ExceptionOr<Ref<FaceDetector>> create(const FaceDetectorOptions&);

~FaceDetector();

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/ShapeDetection/FaceDetector.idl
Expand Up @@ -49,6 +49,6 @@ typedef (CanvasImageSource or Blob or ImageData) ImageBitmapSource;
SecureContext
]
interface FaceDetector {
[CallWith=CurrentScriptExecutionContext] constructor(optional FaceDetectorOptions faceDetectorOptions = {});
constructor(optional FaceDetectorOptions faceDetectorOptions = {});
Promise<sequence<DetectedFace>> detect(ImageBitmapSource image);
};
Expand Up @@ -41,10 +41,10 @@ class BarcodeDetectorImpl final : public BarcodeDetector {

virtual ~BarcodeDetectorImpl();

WEBCORE_EXPORT static void getSupportedFormats(CompletionHandler<void(Vector<BarcodeFormat>&&)>&&);
static void getSupportedFormats(CompletionHandler<void(Vector<BarcodeFormat>&&)>&&);

private:
WEBCORE_EXPORT BarcodeDetectorImpl(const BarcodeDetectorOptions&);
BarcodeDetectorImpl(const BarcodeDetectorOptions&);

BarcodeDetectorImpl(const BarcodeDetectorImpl&) = delete;
BarcodeDetectorImpl(BarcodeDetectorImpl&&) = delete;
Expand Down
Expand Up @@ -42,7 +42,7 @@ class FaceDetectorImpl final : public FaceDetector {
virtual ~FaceDetectorImpl();

private:
WEBCORE_EXPORT FaceDetectorImpl(const FaceDetectorOptions&);
FaceDetectorImpl(const FaceDetectorOptions&);

FaceDetectorImpl(const FaceDetectorImpl&) = delete;
FaceDetectorImpl(FaceDetectorImpl&&) = delete;
Expand Down
Expand Up @@ -40,7 +40,7 @@ class TextDetectorImpl final : public TextDetector {
virtual ~TextDetectorImpl();

private:
WEBCORE_EXPORT TextDetectorImpl();
TextDetectorImpl();

TextDetectorImpl(const TextDetectorImpl&) = delete;
TextDetectorImpl(TextDetectorImpl&&) = delete;
Expand Down
Expand Up @@ -25,11 +25,12 @@

#pragma once

#include "BarcodeFormatInterface.h"
#include <wtf/Vector.h>

namespace WebCore::ShapeDetection {

enum class BarcodeFormat : uint8_t;

struct BarcodeDetectorOptions {
Vector<BarcodeFormat> formats;
};
Expand Down
Expand Up @@ -26,7 +26,6 @@
#pragma once

#include <cstdint>
#include <wtf/EnumTraits.h>

namespace WebCore::ShapeDetection {

Expand All @@ -48,27 +47,3 @@ enum class BarcodeFormat : uint8_t {
};

} // namespace WebCore::ShapeDetection

namespace WTF {

template<> struct EnumTraits<WebCore::ShapeDetection::BarcodeFormat> {
using values = EnumValues<
WebCore::ShapeDetection::BarcodeFormat,
WebCore::ShapeDetection::BarcodeFormat::Aztec,
WebCore::ShapeDetection::BarcodeFormat::Code_128,
WebCore::ShapeDetection::BarcodeFormat::Code_39,
WebCore::ShapeDetection::BarcodeFormat::Code_93,
WebCore::ShapeDetection::BarcodeFormat::Codabar,
WebCore::ShapeDetection::BarcodeFormat::Data_matrix,
WebCore::ShapeDetection::BarcodeFormat::Ean_13,
WebCore::ShapeDetection::BarcodeFormat::Ean_8,
WebCore::ShapeDetection::BarcodeFormat::Itf,
WebCore::ShapeDetection::BarcodeFormat::Pdf417,
WebCore::ShapeDetection::BarcodeFormat::Qr_code,
WebCore::ShapeDetection::BarcodeFormat::Unknown,
WebCore::ShapeDetection::BarcodeFormat::Upc_a,
WebCore::ShapeDetection::BarcodeFormat::Upc_e
>;
};

} // namespace WTF
Expand Up @@ -25,12 +25,15 @@

#pragma once

#include "BarcodeFormatInterface.h"
#include "FloatPoint.h"
#include "BarcodeFormat.h"
#include "FloatRect.h"
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>

namespace WebCore {
class FloatPoint;
}

namespace WebCore::ShapeDetection {

struct DetectedBarcode {
Expand Down
Expand Up @@ -26,12 +26,13 @@
#pragma once

#include "FloatRect.h"
#include "LandmarkInterface.h"
#include <optional>
#include <wtf/Vector.h>

namespace WebCore::ShapeDetection {

struct Landmark;

struct DetectedFace {
FloatRect boundingBox;
std::optional<Vector<Landmark>> landmarks;
Expand Down
Expand Up @@ -25,11 +25,14 @@

#pragma once

#include "FloatPoint.h"
#include "FloatRect.h"
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>

namespace WebCore {
class FloatPoint;
}

namespace WebCore::ShapeDetection {

struct DetectedText {
Expand Down
Expand Up @@ -25,10 +25,13 @@

#pragma once

#include "FloatPoint.h"
#include "LandmarkTypeInterface.h"
#include "LandmarkType.h"
#include <wtf/Vector.h>

namespace WebCore {
class FloatPoint;
}

namespace WebCore::ShapeDetection {

struct Landmark {
Expand Down
Expand Up @@ -26,7 +26,6 @@
#pragma once

#include <cstdint>
#include <wtf/EnumTraits.h>

namespace WebCore::ShapeDetection {

Expand All @@ -37,17 +36,3 @@ enum class LandmarkType : uint8_t {
};

} // namespace WebCore::ShapeDetection

namespace WTF {

template<> struct EnumTraits<WebCore::ShapeDetection::LandmarkType> {
using values = EnumValues<
WebCore::ShapeDetection::LandmarkType,
WebCore::ShapeDetection::LandmarkType::Mouth,
WebCore::ShapeDetection::LandmarkType::Eye,
WebCore::ShapeDetection::LandmarkType::Nose
>;
};

} // namespace WTF

0 comments on commit b801df7

Please sign in to comment.