barcode_detection_impl_mac_vision.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef SERVICES_SHAPE_DETECTION_BARCODE_DETECTION_IMPL_MAC_VISION_H_
  5. #define SERVICES_SHAPE_DETECTION_BARCODE_DETECTION_IMPL_MAC_VISION_H_
  6. #include <os/availability.h>
  7. #include <memory>
  8. #include <utility>
  9. #include <vector>
  10. #include "base/mac/scoped_nsobject.h"
  11. #include "base/memory/weak_ptr.h"
  12. #include "mojo/public/cpp/bindings/self_owned_receiver.h"
  13. #include "services/shape_detection/barcode_detection_impl_mac_vision_api.h"
  14. #include "services/shape_detection/detection_utils_mac.h"
  15. #include "services/shape_detection/public/mojom/barcodedetection.mojom.h"
  16. #include "services/shape_detection/public/mojom/barcodedetection_provider.mojom.h"
  17. class SkBitmap;
  18. class VisionAPIInterface;
  19. namespace shape_detection {
  20. // This class is the implementation of Barcode Detection based on Mac OS Vision
  21. // framework (https://developer.apple.com/documentation/vision).
  22. class BarcodeDetectionImplMacVision : public mojom::BarcodeDetection {
  23. public:
  24. static bool IsBlockedMacOSVersion();
  25. explicit BarcodeDetectionImplMacVision(
  26. mojom::BarcodeDetectorOptionsPtr options);
  27. BarcodeDetectionImplMacVision(const BarcodeDetectionImplMacVision&) = delete;
  28. BarcodeDetectionImplMacVision& operator=(
  29. const BarcodeDetectionImplMacVision&) = delete;
  30. ~BarcodeDetectionImplMacVision() override;
  31. void Detect(const SkBitmap& bitmap,
  32. mojom::BarcodeDetection::DetectCallback callback) override;
  33. void SetReceiver(
  34. mojo::SelfOwnedReceiverRef<mojom::BarcodeDetection> receiver) {
  35. receiver_ = std::move(receiver);
  36. }
  37. static std::vector<shape_detection::mojom::BarcodeFormat>
  38. GetSupportedSymbologies(VisionAPIInterface* vision_api = nullptr);
  39. NSArray<VNBarcodeSymbology>* GetSymbologyHintsForTesting();
  40. private:
  41. void OnBarcodesDetected(VNRequest* request, NSError* error);
  42. CGSize image_size_;
  43. base::scoped_nsobject<NSArray<VNBarcodeSymbology>> symbology_hints_;
  44. std::unique_ptr<VisionAPIAsyncRequestMac> barcodes_async_request_;
  45. DetectCallback detected_callback_;
  46. mojo::SelfOwnedReceiverRef<mojom::BarcodeDetection> receiver_;
  47. base::WeakPtrFactory<BarcodeDetectionImplMacVision> weak_factory_;
  48. };
  49. } // namespace shape_detection
  50. #endif // SERVICES_SHAPE_DETECTION_BARCODE_DETECTION_IMPL_MAC_VISION_H_