face_detection_provider_mac.mm 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #include "services/shape_detection/face_detection_provider_mac.h"
  5. #include <memory>
  6. #include <utility>
  7. #include "mojo/public/cpp/bindings/pending_receiver.h"
  8. #include "mojo/public/cpp/bindings/self_owned_receiver.h"
  9. #include "services/shape_detection/face_detection_impl_mac.h"
  10. #include "services/shape_detection/face_detection_impl_mac_vision.h"
  11. namespace shape_detection {
  12. FaceDetectionProviderMac::FaceDetectionProviderMac() = default;
  13. FaceDetectionProviderMac::~FaceDetectionProviderMac() = default;
  14. // static
  15. void FaceDetectionProviderMac::Create(
  16. mojo::PendingReceiver<mojom::FaceDetectionProvider> receiver) {
  17. mojo::MakeSelfOwnedReceiver(std::make_unique<FaceDetectionProviderMac>(),
  18. std::move(receiver));
  19. }
  20. void FaceDetectionProviderMac::CreateFaceDetection(
  21. mojo::PendingReceiver<mojom::FaceDetection> receiver,
  22. mojom::FaceDetectorOptionsPtr options) {
  23. // Vision is more accurate than Core Image Framework, but it also needs more
  24. // processing time.
  25. if (options->fast_mode) {
  26. mojo::MakeSelfOwnedReceiver(
  27. std::make_unique<FaceDetectionImplMac>(std::move(options)),
  28. std::move(receiver));
  29. return;
  30. }
  31. auto impl = std::make_unique<FaceDetectionImplMacVision>();
  32. auto* impl_ptr = impl.get();
  33. impl_ptr->SetReceiver(
  34. mojo::MakeSelfOwnedReceiver(std::move(impl), std::move(receiver)));
  35. }
  36. } // namespace shape_detection