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

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

Issue 2564163003: ShapeDetection: Add ShapeDetectionProvider (Closed)
Patch Set: Fix layout tests, 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 "public/platform/InterfaceProvider.h" 13 #include "public/platform/InterfaceProvider.h"
14 #include "public/platform/modules/shapedetection/facedetection_provider.mojom-bl ink.h"
14 15
15 namespace blink { 16 namespace blink {
16 17
17 FaceDetector* FaceDetector::create(Document& document, 18 FaceDetector* FaceDetector::create(Document& document,
18 const FaceDetectorOptions& options) { 19 const FaceDetectorOptions& options) {
19 return new FaceDetector(*document.frame(), options); 20 return new FaceDetector(*document.frame(), options);
20 } 21 }
21 22
22 FaceDetector::FaceDetector(LocalFrame& frame, 23 FaceDetector::FaceDetector(LocalFrame& frame,
23 const FaceDetectorOptions& options) 24 const FaceDetectorOptions& options)
24 : ShapeDetector(frame), 25 : ShapeDetector(frame) {
25 m_faceDetectorOptions(mojom::blink::FaceDetectorOptions::New()) { 26 mojom::blink::FaceDetectorOptionsPtr faceDetectorOptions =
26 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_faceService)); 27 mojom::blink::FaceDetectorOptions::New();
28 faceDetectorOptions->max_detected_faces = options.maxDetectedFaces();
29 faceDetectorOptions->fast_mode = options.fastMode();
30 mojom::blink::FaceDetectionProviderPtr provider;
31 frame.interfaceProvider()->getInterface(mojo::GetProxy(&provider));
32 provider->CreateFaceDetection(mojo::GetProxy(&m_faceService),
33 std::move(faceDetectorOptions));
34
27 m_faceService.set_connection_error_handler(convertToBaseCallback(WTF::bind( 35 m_faceService.set_connection_error_handler(convertToBaseCallback(WTF::bind(
28 &FaceDetector::onFaceServiceConnectionError, wrapWeakPersistent(this)))); 36 &FaceDetector::onFaceServiceConnectionError, wrapWeakPersistent(this))));
29 m_faceDetectorOptions->max_detected_faces = options.maxDetectedFaces();
30 m_faceDetectorOptions->fast_mode = options.fastMode();
31 } 37 }
32 38
33 ScriptPromise FaceDetector::doDetect( 39 ScriptPromise FaceDetector::doDetect(
34 ScriptPromiseResolver* resolver, 40 ScriptPromiseResolver* resolver,
35 mojo::ScopedSharedBufferHandle sharedBufferHandle, 41 mojo::ScopedSharedBufferHandle sharedBufferHandle,
36 int imageWidth, 42 int imageWidth,
37 int imageHeight) { 43 int imageHeight) {
38 ScriptPromise promise = resolver->promise(); 44 ScriptPromise promise = resolver->promise();
39 if (!m_faceService) { 45 if (!m_faceService) {
40 resolver->reject(DOMException::create( 46 resolver->reject(DOMException::create(
41 NotSupportedError, "Face detection service unavailable.")); 47 NotSupportedError, "Face detection service unavailable."));
42 return promise; 48 return promise;
43 } 49 }
44 m_faceServiceRequests.add(resolver); 50 m_faceServiceRequests.add(resolver);
45 m_faceService->Detect(std::move(sharedBufferHandle), imageWidth, imageHeight, 51 m_faceService->Detect(std::move(sharedBufferHandle), imageWidth, imageHeight,
46 m_faceDetectorOptions.Clone(),
47 convertToBaseCallback(WTF::bind( 52 convertToBaseCallback(WTF::bind(
48 &FaceDetector::onDetectFaces, wrapPersistent(this), 53 &FaceDetector::onDetectFaces, wrapPersistent(this),
49 wrapPersistent(resolver)))); 54 wrapPersistent(resolver))));
50 return promise; 55 return promise;
51 } 56 }
52 57
53 void FaceDetector::onDetectFaces( 58 void FaceDetector::onDetectFaces(
54 ScriptPromiseResolver* resolver, 59 ScriptPromiseResolver* resolver,
55 mojom::blink::FaceDetectionResultPtr faceDetectionResult) { 60 mojom::blink::FaceDetectionResultPtr faceDetectionResult) {
56 DCHECK(m_faceServiceRequests.contains(resolver)); 61 DCHECK(m_faceServiceRequests.contains(resolver));
(...skipping 17 matching lines...) Expand all
74 m_faceServiceRequests.clear(); 79 m_faceServiceRequests.clear();
75 m_faceService.reset(); 80 m_faceService.reset();
76 } 81 }
77 82
78 DEFINE_TRACE(FaceDetector) { 83 DEFINE_TRACE(FaceDetector) {
79 ShapeDetector::trace(visitor); 84 ShapeDetector::trace(visitor);
80 visitor->trace(m_faceServiceRequests); 85 visitor->trace(m_faceServiceRequests);
81 } 86 }
82 87
83 } // namespace blink 88 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698