Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: third_party/WebKit/Source/modules/shapedetection/FaceDetector.cpp

Issue 2564163003: ShapeDetection: Add ShapeDetectionProvider (Closed)
Patch Set: Name change: mockFaceDetectionProviderReady, rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "modules/shapedetection/DetectedFace.h" 12 #include "modules/shapedetection/DetectedFace.h"
13 #include "modules/shapedetection/FaceDetectorOptions.h"
13 #include "public/platform/InterfaceProvider.h" 14 #include "public/platform/InterfaceProvider.h"
15 #include "public/platform/modules/shapedetection/facedetection_provider.mojom-bl ink.h"
14 16
15 namespace blink { 17 namespace blink {
16 18
17 FaceDetector* FaceDetector::create(Document& document, 19 FaceDetector* FaceDetector::create(Document& document,
18 const FaceDetectorOptions& options) { 20 const FaceDetectorOptions& options) {
19 return new FaceDetector(*document.frame(), options); 21 return new FaceDetector(*document.frame(), options);
20 } 22 }
21 23
22 FaceDetector::FaceDetector(LocalFrame& frame, 24 FaceDetector::FaceDetector(LocalFrame& frame,
23 const FaceDetectorOptions& options) 25 const FaceDetectorOptions& options)
24 : ShapeDetector(frame), 26 : ShapeDetector(frame) {
25 m_faceDetectorOptions(mojom::blink::FaceDetectorOptions::New()) { 27 mojom::blink::FaceDetectorOptionsPtr faceDetectorOptions =
26 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_faceService)); 28 mojom::blink::FaceDetectorOptions::New();
29 faceDetectorOptions->max_detected_faces = options.maxDetectedFaces();
30 faceDetectorOptions->fast_mode = options.fastMode();
31 mojom::blink::FaceDetectionProviderPtr provider;
32 frame.interfaceProvider()->getInterface(mojo::GetProxy(&provider));
33 provider->CreateFaceDetection(mojo::GetProxy(&m_faceService),
34 std::move(faceDetectorOptions));
35
27 m_faceService.set_connection_error_handler(convertToBaseCallback(WTF::bind( 36 m_faceService.set_connection_error_handler(convertToBaseCallback(WTF::bind(
28 &FaceDetector::onFaceServiceConnectionError, wrapWeakPersistent(this)))); 37 &FaceDetector::onFaceServiceConnectionError, wrapWeakPersistent(this))));
29 m_faceDetectorOptions->max_detected_faces = options.maxDetectedFaces();
30 m_faceDetectorOptions->fast_mode = options.fastMode();
31 } 38 }
32 39
33 ScriptPromise FaceDetector::doDetect( 40 ScriptPromise FaceDetector::doDetect(
34 ScriptPromiseResolver* resolver, 41 ScriptPromiseResolver* resolver,
35 mojo::ScopedSharedBufferHandle sharedBufferHandle, 42 mojo::ScopedSharedBufferHandle sharedBufferHandle,
36 int imageWidth, 43 int imageWidth,
37 int imageHeight) { 44 int imageHeight) {
38 ScriptPromise promise = resolver->promise(); 45 ScriptPromise promise = resolver->promise();
39 if (!m_faceService) { 46 if (!m_faceService) {
40 resolver->reject(DOMException::create( 47 resolver->reject(DOMException::create(
41 NotSupportedError, "Face detection service unavailable.")); 48 NotSupportedError, "Face detection service unavailable."));
42 return promise; 49 return promise;
43 } 50 }
44 m_faceServiceRequests.add(resolver); 51 m_faceServiceRequests.add(resolver);
45 m_faceService->Detect(std::move(sharedBufferHandle), imageWidth, imageHeight, 52 m_faceService->Detect(std::move(sharedBufferHandle), imageWidth, imageHeight,
46 m_faceDetectorOptions.Clone(),
47 convertToBaseCallback(WTF::bind( 53 convertToBaseCallback(WTF::bind(
48 &FaceDetector::onDetectFaces, wrapPersistent(this), 54 &FaceDetector::onDetectFaces, wrapPersistent(this),
49 wrapPersistent(resolver)))); 55 wrapPersistent(resolver))));
50 return promise; 56 return promise;
51 } 57 }
52 58
53 void FaceDetector::onDetectFaces( 59 void FaceDetector::onDetectFaces(
54 ScriptPromiseResolver* resolver, 60 ScriptPromiseResolver* resolver,
55 mojom::blink::FaceDetectionResultPtr faceDetectionResult) { 61 mojom::blink::FaceDetectionResultPtr faceDetectionResult) {
56 DCHECK(m_faceServiceRequests.contains(resolver)); 62 DCHECK(m_faceServiceRequests.contains(resolver));
(...skipping 17 matching lines...) Expand all
74 m_faceServiceRequests.clear(); 80 m_faceServiceRequests.clear();
75 m_faceService.reset(); 81 m_faceService.reset();
76 } 82 }
77 83
78 DEFINE_TRACE(FaceDetector) { 84 DEFINE_TRACE(FaceDetector) {
79 ShapeDetector::trace(visitor); 85 ShapeDetector::trace(visitor);
80 visitor->trace(m_faceServiceRequests); 86 visitor->trace(m_faceServiceRequests);
81 } 87 }
82 88
83 } // namespace blink 89 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/shapedetection/FaceDetector.h ('k') | third_party/WebKit/public/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698