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

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

Issue 2522143002: ShapeDetection: split mojom into face and barcode interfaces (Closed)
Patch Set: Smart rebase to https://crrev.com/2527503003 (FaceDetectorOptions) 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"
(...skipping 26 matching lines...) Expand all
37 37
38 if (value.isHTMLVideoElement()) 38 if (value.isHTMLVideoElement())
39 return value.getAsHTMLVideoElement(); 39 return value.getAsHTMLVideoElement();
40 40
41 return nullptr; 41 return nullptr;
42 } 42 }
43 43
44 } // anonymous namespace 44 } // anonymous namespace
45 45
46 ShapeDetector::ShapeDetector(LocalFrame& frame) { 46 ShapeDetector::ShapeDetector(LocalFrame& frame) {
47 DCHECK(!m_service.is_bound()); 47 DCHECK(!m_faceService.is_bound());
48 DCHECK(!m_barcodeService.is_bound());
48 DCHECK(frame.interfaceProvider()); 49 DCHECK(frame.interfaceProvider());
49 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_service)); 50 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_faceService));
51 frame.interfaceProvider()->getInterface(mojo::GetProxy(&m_barcodeService));
50 } 52 }
51 53
52 ShapeDetector::ShapeDetector(LocalFrame& frame, 54 ShapeDetector::ShapeDetector(LocalFrame& frame,
53 const FaceDetectorOptions& options) 55 const FaceDetectorOptions& options)
54 : ShapeDetector(frame) { 56 : ShapeDetector(frame) {
55 m_options = mojom::blink::FaceDetectorOptions::New(); 57 m_faceDetectorOptions = mojom::blink::FaceDetectorOptions::New();
56 m_options->max_detected_faces = options.maxDetectedFaces(); 58 m_faceDetectorOptions->max_detected_faces = options.maxDetectedFaces();
57 m_options->fast_mode = options.fastMode(); 59 m_faceDetectorOptions->fast_mode = options.fastMode();
58 } 60 }
59 61
60 ScriptPromise ShapeDetector::detectShapes( 62 ScriptPromise ShapeDetector::detectShapes(
61 ScriptState* scriptState, 63 ScriptState* scriptState,
62 DetectorType detectorType, 64 DetectorType detectorType,
63 const CanvasImageSourceUnion& imageSource) { 65 const CanvasImageSourceUnion& imageSource) {
64 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); 66 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
65 67
66 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 68 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
67 ScriptPromise promise = resolver->promise(); 69 ScriptPromise promise = resolver->promise();
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 sharedBufferHandle->Map(allocationSize); 158 sharedBufferHandle->Map(allocationSize);
157 159
158 const SkPixmap pixmap(skiaInfo, mappedBuffer.get(), skiaInfo.minRowBytes()); 160 const SkPixmap pixmap(skiaInfo, mappedBuffer.get(), skiaInfo.minRowBytes());
159 if (!image->readPixels(pixmap, 0, 0)) { 161 if (!image->readPixels(pixmap, 0, 0)) {
160 resolver->reject(DOMException::create( 162 resolver->reject(DOMException::create(
161 InvalidStateError, 163 InvalidStateError,
162 "Failed to read pixels: Unable to decompress or unsupported format.")); 164 "Failed to read pixels: Unable to decompress or unsupported format."));
163 return promise; 165 return promise;
164 } 166 }
165 167
166 if (!m_service) {
167 resolver->reject(DOMException::create(
168 NotSupportedError, "Shape detection service unavailable."));
169 return promise;
170 }
171
172 m_serviceRequests.add(resolver); 168 m_serviceRequests.add(resolver);
173 DCHECK(m_service.is_bound());
174 if (detectorType == DetectorType::Face) { 169 if (detectorType == DetectorType::Face) {
175 m_service->DetectFaces( 170 if (!m_faceService) {
176 std::move(sharedBufferHandle), img->naturalWidth(), 171 resolver->reject(DOMException::create(
177 img->naturalHeight(), m_options.Clone(), 172 NotSupportedError, "Face detection service unavailable."));
178 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectFaces, 173 return promise;
179 wrapPersistent(this), 174 }
180 wrapPersistent(resolver)))); 175 m_faceService->Detect(std::move(sharedBufferHandle), img->naturalWidth(),
176 img->naturalHeight(), m_faceDetectorOptions.Clone(),
177 convertToBaseCallback(WTF::bind(
178 &ShapeDetector::onDetectFaces,
179 wrapPersistent(this), wrapPersistent(resolver))));
181 } else if (detectorType == DetectorType::Barcode) { 180 } else if (detectorType == DetectorType::Barcode) {
182 m_service->DetectBarcodes( 181 if (!m_barcodeService) {
182 resolver->reject(DOMException::create(
183 NotSupportedError, "Barcode detection service unavailable."));
184 return promise;
185 }
186 m_barcodeService->Detect(
183 std::move(sharedBufferHandle), img->naturalWidth(), 187 std::move(sharedBufferHandle), img->naturalWidth(),
184 img->naturalHeight(), 188 img->naturalHeight(),
185 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectBarcodes, 189 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectBarcodes,
186 wrapPersistent(this), 190 wrapPersistent(this),
187 wrapPersistent(resolver)))); 191 wrapPersistent(resolver))));
188 } else { 192 } else {
189 NOTREACHED() << "Unsupported detector type"; 193 NOTREACHED() << "Unsupported detector type";
190 } 194 }
191 195
192 return promise; 196 return promise;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 ScriptPromise promise = resolver->promise(); 295 ScriptPromise promise = resolver->promise();
292 296
293 mojo::ScopedSharedBufferHandle sharedBufferHandle = 297 mojo::ScopedSharedBufferHandle sharedBufferHandle =
294 mojo::SharedBufferHandle::Create(size); 298 mojo::SharedBufferHandle::Create(size);
295 if (!sharedBufferHandle->is_valid()) { 299 if (!sharedBufferHandle->is_valid()) {
296 resolver->reject( 300 resolver->reject(
297 DOMException::create(InvalidStateError, "Internal allocation error")); 301 DOMException::create(InvalidStateError, "Internal allocation error"));
298 return promise; 302 return promise;
299 } 303 }
300 304
301 if (!m_service) {
302 resolver->reject(DOMException::create(
303 NotSupportedError, "Shape detection service unavailable."));
304 return promise;
305 }
306
307 const mojo::ScopedSharedBufferMapping mappedBuffer = 305 const mojo::ScopedSharedBufferMapping mappedBuffer =
308 sharedBufferHandle->Map(size); 306 sharedBufferHandle->Map(size);
309 DCHECK(mappedBuffer.get()); 307 DCHECK(mappedBuffer.get());
310 308
311 memcpy(mappedBuffer.get(), data, size); 309 memcpy(mappedBuffer.get(), data, size);
312 310
313 m_serviceRequests.add(resolver); 311 m_serviceRequests.add(resolver);
314 DCHECK(m_service.is_bound());
315 if (detectorType == DetectorType::Face) { 312 if (detectorType == DetectorType::Face) {
316 m_service->DetectFaces( 313 if (!m_faceService) {
317 std::move(sharedBufferHandle), width, height, m_options.Clone(), 314 resolver->reject(DOMException::create(
318 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectFaces, 315 NotSupportedError, "Face detection service unavailable."));
319 wrapPersistent(this), 316 return promise;
320 wrapPersistent(resolver)))); 317 }
318 m_faceService->Detect(std::move(sharedBufferHandle), width, height,
319 m_faceDetectorOptions.Clone(),
320 convertToBaseCallback(WTF::bind(
321 &ShapeDetector::onDetectFaces,
322 wrapPersistent(this), wrapPersistent(resolver))));
321 } else if (detectorType == DetectorType::Barcode) { 323 } else if (detectorType == DetectorType::Barcode) {
322 m_service->DetectBarcodes( 324 if (!m_barcodeService) {
325 resolver->reject(DOMException::create(
326 NotSupportedError, "Barcode detection service unavailable."));
327 return promise;
328 }
329 m_barcodeService->Detect(
323 std::move(sharedBufferHandle), width, height, 330 std::move(sharedBufferHandle), width, height,
324 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectBarcodes, 331 convertToBaseCallback(WTF::bind(&ShapeDetector::onDetectBarcodes,
325 wrapPersistent(this), 332 wrapPersistent(this),
326 wrapPersistent(resolver)))); 333 wrapPersistent(resolver))));
327 } else { 334 } else {
328 NOTREACHED() << "Unsupported detector type"; 335 NOTREACHED() << "Unsupported detector type";
329 } 336 }
330 sharedBufferHandle.reset(); 337 sharedBufferHandle.reset();
331 return promise; 338 return promise;
332 } 339 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 } 372 }
366 373
367 resolver->resolve(detectedBarcodes); 374 resolver->resolve(detectedBarcodes);
368 } 375 }
369 376
370 DEFINE_TRACE(ShapeDetector) { 377 DEFINE_TRACE(ShapeDetector) {
371 visitor->trace(m_serviceRequests); 378 visitor->trace(m_serviceRequests);
372 } 379 }
373 380
374 } // namespace blink 381 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/shapedetection/ShapeDetector.h ('k') | third_party/WebKit/public/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698