| 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/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()); | |
| 48 DCHECK(!m_barcodeService.is_bound()); | 50 DCHECK(!m_barcodeService.is_bound()); |
| 51 #if OS(MACOSX) |
| 52 ServiceConnector::instance().ConnectToInterface( |
| 53 shape_detection::mojom::blink::kServiceName, |
| 54 mojo::GetProxy(&m_barcodeService)); |
| 55 #else |
| 56 // TODO(xianglu): Move Android implementation to service/ as well. |
| 49 DCHECK(frame.interfaceProvider()); | 57 DCHECK(frame.interfaceProvider()); |
| 50 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_faceService)); | |
| 51 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_barcodeService)); | 58 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_barcodeService)); |
| 52 m_faceService.set_connection_error_handler(convertToBaseCallback(WTF::bind( | 59 #endif |
| 53 &ShapeDetector::onFaceServiceConnectionError, wrapWeakPersistent(this)))); | |
| 54 m_barcodeService.set_connection_error_handler(convertToBaseCallback( | 60 m_barcodeService.set_connection_error_handler(convertToBaseCallback( |
| 55 WTF::bind(&ShapeDetector::onBarcodeServiceConnectionError, | 61 WTF::bind(&ShapeDetector::onBarcodeServiceConnectionError, |
| 56 wrapWeakPersistent(this)))); | 62 wrapWeakPersistent(this)))); |
| 57 } | 63 } |
| 58 | 64 |
| 59 ShapeDetector::ShapeDetector(LocalFrame& frame, | 65 ShapeDetector::ShapeDetector(LocalFrame& frame, |
| 60 const FaceDetectorOptions& options) | 66 const FaceDetectorOptions& options) |
| 61 : ShapeDetector(frame) { | 67 : m_faceDetectorOptions(mojom::blink::FaceDetectorOptions::New()) { |
| 62 m_faceDetectorOptions = mojom::blink::FaceDetectorOptions::New(); | 68 DCHECK(!m_faceService.is_bound()); |
| 69 #if OS(MACOSX) |
| 70 ServiceConnector::instance().ConnectToInterface( |
| 71 shape_detection::mojom::blink::kServiceName, |
| 72 mojo::GetProxy(&m_faceService)); |
| 73 #else |
| 74 // TODO(xianglu): Move Android implementation to service/ as well. |
| 75 DCHECK(frame.interfaceProvider()); |
| 76 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_faceService)); |
| 77 #endif |
| 78 m_faceService.set_connection_error_handler(convertToBaseCallback(WTF::bind( |
| 79 &ShapeDetector::onFaceServiceConnectionError, wrapWeakPersistent(this)))); |
| 80 |
| 63 m_faceDetectorOptions->max_detected_faces = options.maxDetectedFaces(); | 81 m_faceDetectorOptions->max_detected_faces = options.maxDetectedFaces(); |
| 64 m_faceDetectorOptions->fast_mode = options.fastMode(); | 82 m_faceDetectorOptions->fast_mode = options.fastMode(); |
| 65 } | 83 } |
| 66 | 84 |
| 67 ScriptPromise ShapeDetector::detectShapes( | 85 ScriptPromise ShapeDetector::detectShapes( |
| 68 ScriptState* scriptState, | 86 ScriptState* scriptState, |
| 69 DetectorType detectorType, | 87 DetectorType detectorType, |
| 70 const CanvasImageSourceUnion& imageSource) { | 88 const CanvasImageSourceUnion& imageSource) { |
| 71 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); | 89 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); |
| 72 | 90 |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 m_barcodeServiceRequests.clear(); | 414 m_barcodeServiceRequests.clear(); |
| 397 m_barcodeService.reset(); | 415 m_barcodeService.reset(); |
| 398 } | 416 } |
| 399 | 417 |
| 400 DEFINE_TRACE(ShapeDetector) { | 418 DEFINE_TRACE(ShapeDetector) { |
| 401 visitor->trace(m_faceServiceRequests); | 419 visitor->trace(m_faceServiceRequests); |
| 402 visitor->trace(m_barcodeServiceRequests); | 420 visitor->trace(m_barcodeServiceRequests); |
| 403 } | 421 } |
| 404 | 422 |
| 405 } // namespace blink | 423 } // namespace blink |
| OLD | NEW |