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

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

Issue 2528743002: Shape Detection: Implement FaceDetection on Mac as out-of-process service (Closed)
Patch Set: Test content_browser_manifest.json 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/ShapeDetector.h" 5 #include "modules/shapedetection/ShapeDetector.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/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/fetch/ImageResource.h" 10 #include "core/fetch/ImageResource.h"
11 #include "core/frame/ImageBitmap.h" 11 #include "core/frame/ImageBitmap.h"
12 #include "core/frame/LocalDOMWindow.h" 12 #include "core/frame/LocalDOMWindow.h"
13 #include "core/frame/LocalFrame.h" 13 #include "core/frame/LocalFrame.h"
14 #include "core/html/HTMLImageElement.h" 14 #include "core/html/HTMLImageElement.h"
15 #include "core/html/HTMLVideoElement.h" 15 #include "core/html/HTMLVideoElement.h"
16 #include "core/html/canvas/CanvasImageSource.h" 16 #include "core/html/canvas/CanvasImageSource.h"
17 #include "modules/shapedetection/DetectedBarcode.h" 17 #include "modules/shapedetection/DetectedBarcode.h"
18 #include "platform/ServiceConnector.h"
18 #include "platform/graphics/Image.h" 19 #include "platform/graphics/Image.h"
19 #include "public/platform/InterfaceProvider.h" 20 #include "public/platform/InterfaceProvider.h"
21 #include "services/shape_detection/public/interfaces/constants.mojom-blink.h"
20 #include "third_party/skia/include/core/SkImage.h" 22 #include "third_party/skia/include/core/SkImage.h"
21 #include "third_party/skia/include/core/SkImageInfo.h" 23 #include "third_party/skia/include/core/SkImageInfo.h"
22 #include "wtf/CheckedNumeric.h" 24 #include "wtf/CheckedNumeric.h"
23 25
24 namespace blink { 26 namespace blink {
25 27
26 namespace { 28 namespace {
27 29
28 static CanvasImageSource* toImageSourceInternal( 30 static CanvasImageSource* toImageSourceInternal(
29 const CanvasImageSourceUnion& value) { 31 const CanvasImageSourceUnion& value) {
30 if (value.isHTMLImageElement()) 32 if (value.isHTMLImageElement())
31 return value.getAsHTMLImageElement(); 33 return value.getAsHTMLImageElement();
32 34
33 if (value.isImageBitmap() && 35 if (value.isImageBitmap() &&
34 !static_cast<ImageBitmap*>(value.getAsImageBitmap())->isNeutered()) { 36 !static_cast<ImageBitmap*>(value.getAsImageBitmap())->isNeutered()) {
35 return value.getAsImageBitmap(); 37 return value.getAsImageBitmap();
36 } 38 }
37 39
38 if (value.isHTMLVideoElement()) 40 if (value.isHTMLVideoElement())
39 return value.getAsHTMLVideoElement(); 41 return value.getAsHTMLVideoElement();
40 42
41 return nullptr; 43 return nullptr;
42 } 44 }
43 45
44 } // anonymous namespace 46 } // anonymous namespace
45 47
48 // TODO(xianglu): We don't need a service per frame. Remove this argument.
46 ShapeDetector::ShapeDetector(LocalFrame& frame) { 49 ShapeDetector::ShapeDetector(LocalFrame& frame) {
47 DCHECK(!m_faceService.is_bound()); 50 DCHECK(!m_faceService.is_bound());
48 DCHECK(!m_barcodeService.is_bound()); 51 DCHECK(!m_barcodeService.is_bound());
52 #if OS(MACOSX)
53 ServiceConnector::instance().ConnectToInterface(
yzshen1 2016/12/01 21:28:26 Do we always need both m_faceService and m_barcode
xianglu 2016/12/02 18:11:24 That's a good point. I separated them to two const
yzshen1 2016/12/05 17:41:19 Depending on which constructor is called, this ins
xianglu 2016/12/05 18:50:02 Yes. ShapeDetector only serves one task, and users
54 shape_detection::mojom::blink::kServiceName,
55 mojo::GetProxy(&m_faceService));
56 ServiceConnector::instance().ConnectToInterface(
57 shape_detection::mojom::blink::kServiceName,
58 mojo::GetProxy(&m_barcodeService));
59 #else
60 // TODO(xianglu): Move Android implementation to service/ as well.
49 DCHECK(frame.interfaceProvider()); 61 DCHECK(frame.interfaceProvider());
50 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_faceService)); 62 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_faceService));
51 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_barcodeService)); 63 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_barcodeService));
64 #endif
52 m_faceService.set_connection_error_handler(convertToBaseCallback(WTF::bind( 65 m_faceService.set_connection_error_handler(convertToBaseCallback(WTF::bind(
53 &ShapeDetector::onFaceServiceConnectionError, wrapWeakPersistent(this)))); 66 &ShapeDetector::onFaceServiceConnectionError, wrapWeakPersistent(this))));
54 m_barcodeService.set_connection_error_handler(convertToBaseCallback( 67 m_barcodeService.set_connection_error_handler(convertToBaseCallback(
55 WTF::bind(&ShapeDetector::onBarcodeServiceConnectionError, 68 WTF::bind(&ShapeDetector::onBarcodeServiceConnectionError,
56 wrapWeakPersistent(this)))); 69 wrapWeakPersistent(this))));
57 } 70 }
58 71
59 ShapeDetector::ShapeDetector(LocalFrame& frame, 72 ShapeDetector::ShapeDetector(LocalFrame& frame,
60 const FaceDetectorOptions& options) 73 const FaceDetectorOptions& options)
61 : ShapeDetector(frame) { 74 : ShapeDetector(frame) {
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 m_barcodeServiceRequests.clear(); 409 m_barcodeServiceRequests.clear();
397 m_barcodeService.reset(); 410 m_barcodeService.reset();
398 } 411 }
399 412
400 DEFINE_TRACE(ShapeDetector) { 413 DEFINE_TRACE(ShapeDetector) {
401 visitor->trace(m_faceServiceRequests); 414 visitor->trace(m_faceServiceRequests);
402 visitor->trace(m_barcodeServiceRequests); 415 visitor->trace(m_barcodeServiceRequests);
403 } 416 }
404 417
405 } // namespace blink 418 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698