| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/shapedetection/FaceDetector.h" | 5 #include "modules/shapedetection/FaceDetector.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMException.h" | 7 #include "core/dom/DOMException.h" |
| 8 #include "core/dom/DOMRect.h" | 8 #include "core/dom/DOMRect.h" |
| 9 #include "core/frame/LocalDOMWindow.h" | 9 #include "core/frame/LocalDOMWindow.h" |
| 10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| 11 #include "core/html/canvas/CanvasImageSource.h" | 11 #include "core/html/canvas/CanvasImageSource.h" |
| 12 #include "public/platform/InterfaceProvider.h" | 12 #include "public/platform/InterfaceProvider.h" |
| 13 #include "public/platform/modules/shapedetection/shapedetection_provider.mojom-b
link.h" |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 | 16 |
| 16 FaceDetector* FaceDetector::create(Document& document, | 17 FaceDetector* FaceDetector::create(Document& document, |
| 17 const FaceDetectorOptions& options) { | 18 const FaceDetectorOptions& options) { |
| 18 return new FaceDetector(*document.frame(), options); | 19 return new FaceDetector(*document.frame(), options); |
| 19 } | 20 } |
| 20 | 21 |
| 21 FaceDetector::FaceDetector(LocalFrame& frame, | 22 FaceDetector::FaceDetector(LocalFrame& frame, |
| 22 const FaceDetectorOptions& options) | 23 const FaceDetectorOptions& options) |
| 23 : ShapeDetector(frame), | 24 : ShapeDetector(frame) { |
| 24 m_faceDetectorOptions(mojom::blink::FaceDetectorOptions::New()) { | 25 mojom::blink::FaceDetectorOptionsPtr faceDetectorOptions = |
| 25 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_faceService)); | 26 mojom::blink::FaceDetectorOptions::New(); |
| 27 faceDetectorOptions->max_detected_faces = options.maxDetectedFaces(); |
| 28 faceDetectorOptions->fast_mode = options.fastMode(); |
| 29 mojom::blink::ShapeDetectionProviderPtr provider; |
| 30 frame.interfaceProvider()->getInterface(mojo::GetProxy(&provider)); |
| 31 provider->CreateFaceDetection(mojo::GetProxy(&m_faceService), |
| 32 std::move(faceDetectorOptions)); |
| 33 |
| 26 m_faceService.set_connection_error_handler(convertToBaseCallback(WTF::bind( | 34 m_faceService.set_connection_error_handler(convertToBaseCallback(WTF::bind( |
| 27 &FaceDetector::onFaceServiceConnectionError, wrapWeakPersistent(this)))); | 35 &FaceDetector::onFaceServiceConnectionError, wrapWeakPersistent(this)))); |
| 28 m_faceDetectorOptions->max_detected_faces = options.maxDetectedFaces(); | |
| 29 m_faceDetectorOptions->fast_mode = options.fastMode(); | |
| 30 } | 36 } |
| 31 | 37 |
| 32 ScriptPromise FaceDetector::doDetect( | 38 ScriptPromise FaceDetector::doDetect( |
| 33 ScriptPromiseResolver* resolver, | 39 ScriptPromiseResolver* resolver, |
| 34 mojo::ScopedSharedBufferHandle sharedBufferHandle, | 40 mojo::ScopedSharedBufferHandle sharedBufferHandle, |
| 35 int imageWidth, | 41 int imageWidth, |
| 36 int imageHeight) { | 42 int imageHeight) { |
| 37 ScriptPromise promise = resolver->promise(); | 43 ScriptPromise promise = resolver->promise(); |
| 38 if (!m_faceService) { | 44 if (!m_faceService) { |
| 39 resolver->reject(DOMException::create( | 45 resolver->reject(DOMException::create( |
| 40 NotSupportedError, "Face detection service unavailable.")); | 46 NotSupportedError, "Face detection service unavailable.")); |
| 41 return promise; | 47 return promise; |
| 42 } | 48 } |
| 43 m_faceServiceRequests.add(resolver); | 49 m_faceServiceRequests.add(resolver); |
| 44 m_faceService->Detect(std::move(sharedBufferHandle), imageWidth, imageHeight, | 50 m_faceService->Detect(std::move(sharedBufferHandle), imageWidth, imageHeight, |
| 45 m_faceDetectorOptions.Clone(), | |
| 46 convertToBaseCallback(WTF::bind( | 51 convertToBaseCallback(WTF::bind( |
| 47 &FaceDetector::onDetectFaces, wrapPersistent(this), | 52 &FaceDetector::onDetectFaces, wrapPersistent(this), |
| 48 wrapPersistent(resolver)))); | 53 wrapPersistent(resolver)))); |
| 49 return promise; | 54 return promise; |
| 50 } | 55 } |
| 51 | 56 |
| 52 void FaceDetector::onDetectFaces( | 57 void FaceDetector::onDetectFaces( |
| 53 ScriptPromiseResolver* resolver, | 58 ScriptPromiseResolver* resolver, |
| 54 mojom::blink::FaceDetectionResultPtr faceDetectionResult) { | 59 mojom::blink::FaceDetectionResultPtr faceDetectionResult) { |
| 55 DCHECK(m_faceServiceRequests.contains(resolver)); | 60 DCHECK(m_faceServiceRequests.contains(resolver)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 73 m_faceServiceRequests.clear(); | 78 m_faceServiceRequests.clear(); |
| 74 m_faceService.reset(); | 79 m_faceService.reset(); |
| 75 } | 80 } |
| 76 | 81 |
| 77 DEFINE_TRACE(FaceDetector) { | 82 DEFINE_TRACE(FaceDetector) { |
| 78 ShapeDetector::trace(visitor); | 83 ShapeDetector::trace(visitor); |
| 79 visitor->trace(m_faceServiceRequests); | 84 visitor->trace(m_faceServiceRequests); |
| 80 } | 85 } |
| 81 | 86 |
| 82 } // namespace blink | 87 } // namespace blink |
| OLD | NEW |