| 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" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 resolver->reject(DOMException::create( | 159 resolver->reject(DOMException::create( |
| 160 NotSupportedError, "Shape detection service unavailable.")); | 160 NotSupportedError, "Shape detection service unavailable.")); |
| 161 return promise; | 161 return promise; |
| 162 } | 162 } |
| 163 | 163 |
| 164 m_serviceRequests.add(resolver); | 164 m_serviceRequests.add(resolver); |
| 165 DCHECK(m_service.is_bound()); | 165 DCHECK(m_service.is_bound()); |
| 166 if (detectorType == DetectorType::Face) { | 166 if (detectorType == DetectorType::Face) { |
| 167 m_service->DetectFaces( | 167 m_service->DetectFaces( |
| 168 std::move(sharedBufferHandle), img->naturalWidth(), | 168 std::move(sharedBufferHandle), img->naturalWidth(), |
| 169 img->naturalHeight(), | 169 img->naturalHeight(), m_options.Clone(), |
| 170 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectFaces, | 170 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectFaces, |
| 171 wrapPersistent(this), | 171 wrapPersistent(this), |
| 172 wrapPersistent(resolver)))); | 172 wrapPersistent(resolver)))); |
| 173 } else if (detectorType == DetectorType::Barcode) { | 173 } else if (detectorType == DetectorType::Barcode) { |
| 174 m_service->DetectBarcodes( | 174 m_service->DetectBarcodes( |
| 175 std::move(sharedBufferHandle), img->naturalWidth(), | 175 std::move(sharedBufferHandle), img->naturalWidth(), |
| 176 img->naturalHeight(), | 176 img->naturalHeight(), |
| 177 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectBarcodes, | 177 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectBarcodes, |
| 178 wrapPersistent(this), | 178 wrapPersistent(this), |
| 179 wrapPersistent(resolver)))); | 179 wrapPersistent(resolver)))); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 const mojo::ScopedSharedBufferMapping mappedBuffer = | 299 const mojo::ScopedSharedBufferMapping mappedBuffer = |
| 300 sharedBufferHandle->Map(size); | 300 sharedBufferHandle->Map(size); |
| 301 DCHECK(mappedBuffer.get()); | 301 DCHECK(mappedBuffer.get()); |
| 302 | 302 |
| 303 memcpy(mappedBuffer.get(), data, size); | 303 memcpy(mappedBuffer.get(), data, size); |
| 304 | 304 |
| 305 m_serviceRequests.add(resolver); | 305 m_serviceRequests.add(resolver); |
| 306 DCHECK(m_service.is_bound()); | 306 DCHECK(m_service.is_bound()); |
| 307 if (detectorType == DetectorType::Face) { | 307 if (detectorType == DetectorType::Face) { |
| 308 m_service->DetectFaces( | 308 m_service->DetectFaces( |
| 309 std::move(sharedBufferHandle), width, height, | 309 std::move(sharedBufferHandle), width, height, m_options.Clone(), |
| 310 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectFaces, | 310 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectFaces, |
| 311 wrapPersistent(this), | 311 wrapPersistent(this), |
| 312 wrapPersistent(resolver)))); | 312 wrapPersistent(resolver)))); |
| 313 } else if (detectorType == DetectorType::Barcode) { | 313 } else if (detectorType == DetectorType::Barcode) { |
| 314 m_service->DetectBarcodes( | 314 m_service->DetectBarcodes( |
| 315 std::move(sharedBufferHandle), width, height, | 315 std::move(sharedBufferHandle), width, height, |
| 316 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectBarcodes, | 316 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectBarcodes, |
| 317 wrapPersistent(this), | 317 wrapPersistent(this), |
| 318 wrapPersistent(resolver)))); | 318 wrapPersistent(resolver)))); |
| 319 } else { | 319 } else { |
| 320 NOTREACHED() << "Unsupported detector type"; | 320 NOTREACHED() << "Unsupported detector type"; |
| 321 } | 321 } |
| 322 sharedBufferHandle.reset(); | 322 sharedBufferHandle.reset(); |
| 323 return promise; | 323 return promise; |
| 324 } | 324 } |
| 325 | 325 |
| 326 void ShapeDetector::onDetectFaces( | 326 void ShapeDetector::onDetectFaces( |
| 327 ScriptPromiseResolver* resolver, | 327 ScriptPromiseResolver* resolver, |
| 328 mojom::blink::FaceDetectionResultPtr faceDetectionResult) { | 328 mojom::blink::FaceDetectionResultPtr faceDetectionResult) { |
| 329 if (!m_serviceRequests.contains(resolver)) | 329 if (!m_serviceRequests.contains(resolver)) |
| 330 return; | 330 return; |
| 331 | 331 |
| 332 HeapVector<Member<DOMRect>> detectedFaces; | 332 HeapVector<Member<DOMRect>> detectedFaces; |
| 333 for (const auto& boundingBox : faceDetectionResult->boundingBoxes) { | 333 for (const auto& boundingBox : faceDetectionResult->bounding_boxes) { |
| 334 detectedFaces.append(DOMRect::create(boundingBox->x, boundingBox->y, | 334 detectedFaces.append(DOMRect::create(boundingBox->x, boundingBox->y, |
| 335 boundingBox->width, | 335 boundingBox->width, |
| 336 boundingBox->height)); | 336 boundingBox->height)); |
| 337 } | 337 } |
| 338 | 338 |
| 339 resolver->resolve(detectedFaces); | 339 resolver->resolve(detectedFaces); |
| 340 m_serviceRequests.remove(resolver); | 340 m_serviceRequests.remove(resolver); |
| 341 } | 341 } |
| 342 | 342 |
| 343 void ShapeDetector::onDetectBarcodes( | 343 void ShapeDetector::onDetectBarcodes( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 357 } | 357 } |
| 358 | 358 |
| 359 resolver->resolve(detectedBarcodes); | 359 resolver->resolve(detectedBarcodes); |
| 360 } | 360 } |
| 361 | 361 |
| 362 DEFINE_TRACE(ShapeDetector) { | 362 DEFINE_TRACE(ShapeDetector) { |
| 363 visitor->trace(m_serviceRequests); | 363 visitor->trace(m_serviceRequests); |
| 364 } | 364 } |
| 365 | 365 |
| 366 } // namespace blink | 366 } // namespace blink |
| OLD | NEW |