Commit 14340bd7 authored by junweifu's avatar junweifu Committed by Commit Bot

ShapeDetection: Split Mac provider from Barcode Detection implementation

Split the provider in order to support Vision Framework [1] which
recognizes barcode symbologies more than Core Image Framework.

Split original large CL[2] up in smaller subpatches including this CL.

[1] https://developer.apple.com/documentation/vision
[2] https://chromium-review.googlesource.com/c/chromium/src/+/1088466

BUG=848182

Change-Id: I1bc9f1d898e34a04d819db9f90bd88d725b3601e
Reviewed-on: https://chromium-review.googlesource.com/1088321Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Commit-Queue: Junwei Fu <junwei.fu@intel.com>
Cr-Commit-Position: refs/heads/master@{#568321}
parent e25ce181
...@@ -8,7 +8,6 @@ import("//testing/test.gni") ...@@ -8,7 +8,6 @@ import("//testing/test.gni")
source_set("lib") { source_set("lib") {
sources = [ sources = [
"barcode_detection_provider_impl.h",
"shape_detection_service.cc", "shape_detection_service.cc",
"shape_detection_service.h", "shape_detection_service.h",
"text_detection_impl.h", "text_detection_impl.h",
...@@ -18,6 +17,8 @@ source_set("lib") { ...@@ -18,6 +17,8 @@ source_set("lib") {
sources += [ sources += [
"barcode_detection_impl_mac.h", "barcode_detection_impl_mac.h",
"barcode_detection_impl_mac.mm", "barcode_detection_impl_mac.mm",
"barcode_detection_provider_mac.h",
"barcode_detection_provider_mac.mm",
"detection_utils_mac.h", "detection_utils_mac.h",
"detection_utils_mac.mm", "detection_utils_mac.mm",
"face_detection_impl_mac.h", "face_detection_impl_mac.h",
...@@ -33,6 +34,7 @@ source_set("lib") { ...@@ -33,6 +34,7 @@ source_set("lib") {
} else if (is_win) { } else if (is_win) {
sources += [ sources += [
"barcode_detection_provider_impl.cc", "barcode_detection_provider_impl.cc",
"barcode_detection_provider_impl.h",
"detection_utils_win.cc", "detection_utils_win.cc",
"detection_utils_win.h", "detection_utils_win.h",
"face_detection_impl_win.cc", "face_detection_impl_win.cc",
...@@ -45,6 +47,7 @@ source_set("lib") { ...@@ -45,6 +47,7 @@ source_set("lib") {
} else { } else {
sources += [ sources += [
"barcode_detection_provider_impl.cc", "barcode_detection_provider_impl.cc",
"barcode_detection_provider_impl.h",
"face_detection_provider_impl.cc", "face_detection_provider_impl.cc",
"face_detection_provider_impl.h", "face_detection_provider_impl.h",
"text_detection_impl.cc", "text_detection_impl.cc",
......
...@@ -8,29 +8,10 @@ ...@@ -8,29 +8,10 @@
#include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_cftyperef.h"
#include "base/mac/sdk_forward_declarations.h" #include "base/mac/sdk_forward_declarations.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "services/shape_detection/barcode_detection_provider_impl.h"
#include "services/shape_detection/detection_utils_mac.h" #include "services/shape_detection/detection_utils_mac.h"
namespace shape_detection { namespace shape_detection {
// static
void BarcodeDetectionProviderImpl::CreateBarcodeDetection(
shape_detection::mojom::BarcodeDetectionRequest request,
shape_detection::mojom::BarcodeDetectorOptionsPtr options) {
// Barcode detection needs at least MAC OS X 10.10.
if (@available(macOS 10.10, *)) {
mojo::MakeStrongBinding(std::make_unique<BarcodeDetectionImplMac>(),
std::move(request));
}
}
void BarcodeDetectionProviderImpl::EnumerateSupportedFormats(
EnumerateSupportedFormatsCallback callback) {
// Mac implementation supports only one BarcodeFormat.
std::move(callback).Run({mojom::BarcodeFormat::QR_CODE});
}
BarcodeDetectionImplMac::BarcodeDetectionImplMac() { BarcodeDetectionImplMac::BarcodeDetectionImplMac() {
NSDictionary* const options = @{CIDetectorAccuracy : CIDetectorAccuracyHigh}; NSDictionary* const options = @{CIDetectorAccuracy : CIDetectorAccuracyHigh};
detector_.reset([[CIDetector detectorOfType:CIDetectorTypeQRCode detector_.reset([[CIDetector detectorOfType:CIDetectorTypeQRCode
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_SHAPE_DETECTION_BARCODE_DETECTION_PROVIDER_MAC_H_
#define SERVICES_SHAPE_DETECTION_BARCODE_DETECTION_PROVIDER_MAC_H_
#include "base/macros.h"
#include "services/shape_detection/public/mojom/barcodedetection.mojom.h"
#include "services/shape_detection/public/mojom/barcodedetection_provider.mojom.h"
namespace shape_detection {
// The BarcodeDetectionProviderMac class is a provider that binds an
// implementation of mojom::BarcodeDetection with Core Image or Vision
// Framework.
class BarcodeDetectionProviderMac
: public shape_detection::mojom::BarcodeDetectionProvider {
public:
BarcodeDetectionProviderMac();
~BarcodeDetectionProviderMac() override;
// Binds BarcodeDetection provider request to the implementation of
// mojom::BarcodeDetectionProvider.
static void Create(mojom::BarcodeDetectionProviderRequest request);
void CreateBarcodeDetection(
mojom::BarcodeDetectionRequest request,
mojom::BarcodeDetectorOptionsPtr options) override;
void EnumerateSupportedFormats(
EnumerateSupportedFormatsCallback callback) override;
private:
DISALLOW_COPY_AND_ASSIGN(BarcodeDetectionProviderMac);
};
} // namespace shape_detection
#endif // SERVICES_SHAPE_DETECTION_BARCODE_DETECTION_PROVIDER_MAC_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/shape_detection/barcode_detection_provider_mac.h"
#include <memory>
#include <utility>
#include "base/logging.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "services/shape_detection/barcode_detection_impl_mac.h"
namespace shape_detection {
BarcodeDetectionProviderMac::BarcodeDetectionProviderMac() = default;
BarcodeDetectionProviderMac::~BarcodeDetectionProviderMac() = default;
// static
void BarcodeDetectionProviderMac::Create(
mojom::BarcodeDetectionProviderRequest request) {
mojo::MakeStrongBinding(std::make_unique<BarcodeDetectionProviderMac>(),
std::move(request));
}
void BarcodeDetectionProviderMac::CreateBarcodeDetection(
mojom::BarcodeDetectionRequest request,
mojom::BarcodeDetectorOptionsPtr options) {
// Barcode detection needs at least MAC OS X 10.10.
if (@available(macOS 10.10, *)) {
mojo::MakeStrongBinding(std::make_unique<BarcodeDetectionImplMac>(),
std::move(request));
}
}
void BarcodeDetectionProviderMac::EnumerateSupportedFormats(
EnumerateSupportedFormatsCallback callback) {
// Barcode detection needs at least MAC OS X 10.10.
if (@available(macOS 10.10, *)) {
// Mac implementation supports only one BarcodeFormat.
std::move(callback).Run({mojom::BarcodeFormat::QR_CODE});
return;
}
DLOG(ERROR) << "Platform not supported for Barcode Detection.";
std::move(callback).Run({});
}
} // namespace shape_detection
...@@ -11,12 +11,14 @@ ...@@ -11,12 +11,14 @@
#include "base/macros.h" #include "base/macros.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "services/service_manager/public/cpp/service_context.h" #include "services/service_manager/public/cpp/service_context.h"
#include "services/shape_detection/barcode_detection_provider_impl.h"
#if defined(OS_WIN) #if defined(OS_WIN)
#include "services/shape_detection/barcode_detection_provider_impl.h"
#include "services/shape_detection/face_detection_provider_win.h" #include "services/shape_detection/face_detection_provider_win.h"
#elif defined(OS_MACOSX) #elif defined(OS_MACOSX)
#include "services/shape_detection/barcode_detection_provider_mac.h"
#include "services/shape_detection/face_detection_provider_mac.h" #include "services/shape_detection/face_detection_provider_mac.h"
#else #else
#include "services/shape_detection/barcode_detection_provider_impl.h"
#include "services/shape_detection/face_detection_provider_impl.h" #include "services/shape_detection/face_detection_provider_impl.h"
#endif #endif
#include "services/shape_detection/text_detection_impl.h" #include "services/shape_detection/text_detection_impl.h"
...@@ -54,7 +56,7 @@ void ShapeDetectionService::OnStart() { ...@@ -54,7 +56,7 @@ void ShapeDetectionService::OnStart() {
registry_.AddInterface(base::Bind(&TextDetectionImpl::Create)); registry_.AddInterface(base::Bind(&TextDetectionImpl::Create));
registry_.AddInterface(base::Bind(&FaceDetectionProviderWin::Create)); registry_.AddInterface(base::Bind(&FaceDetectionProviderWin::Create));
#elif defined(OS_MACOSX) #elif defined(OS_MACOSX)
registry_.AddInterface(base::Bind(&BarcodeDetectionProviderImpl::Create)); registry_.AddInterface(base::Bind(&BarcodeDetectionProviderMac::Create));
registry_.AddInterface(base::Bind(&TextDetectionImpl::Create)); registry_.AddInterface(base::Bind(&TextDetectionImpl::Create));
registry_.AddInterface(base::Bind(&FaceDetectionProviderMac::Create)); registry_.AddInterface(base::Bind(&FaceDetectionProviderMac::Create));
#else #else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment