Chromium Code Reviews| Index: third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp |
| diff --git a/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp b/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp |
| index a574933828cdd82b3196d42c231462206a67bff0..ed761c3ca159a16bdc4967929a9ba50eb575bad6 100644 |
| --- a/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp |
| +++ b/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp |
| @@ -11,7 +11,7 @@ |
| #include "core/frame/LocalFrame.h" |
| #include "core/html/HTMLImageElement.h" |
| #include "core/html/HTMLVideoElement.h" |
| -#include "core/html/canvas/CanvasImageSource.h" |
| +#include "core/html/ImageData.h" |
| #include "core/loader/resource/ImageResourceContent.h" |
| #include "platform/graphics/Image.h" |
| #include "third_party/skia/include/core/SkImage.h" |
| @@ -53,10 +53,13 @@ ShapeDetector::ShapeDetector(LocalFrame& frame) { |
| } |
| ScriptPromise ShapeDetector::detect(ScriptState* scriptState, |
| - const CanvasImageSourceUnion& imageSource) { |
| + const ImageBitmapSourceUnion& imageSource) { |
| ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| ScriptPromise promise = resolver->promise(); |
| + if (imageSource.isImageData()) |
| + return detectShapesOnImageData(resolver, imageSource.getAsImageData()); |
| + |
| CanvasImageSource* canvasImageSource; |
| if (imageSource.isHTMLImageElement()) { |
| canvasImageSource = imageSource.getAsHTMLImageElement(); |
| @@ -141,6 +144,23 @@ ScriptPromise ShapeDetector::detect(ScriptState* scriptState, |
| image->height()); |
| } |
| +ScriptPromise ShapeDetector::detectShapesOnImageData( |
| + ScriptPromiseResolver* resolver, |
| + ImageData* imageData) { |
| + ScriptPromise promise = resolver->promise(); |
|
xianglu
2016/12/14 22:32:28
Should we check origin for ImageData as well?
mcasas
2016/12/14 23:37:42
[1] tells us that ImageDatas can not be created fr
|
| + |
| + uint8_t* const data = imageData->data()->data(); |
| + WTF::CheckedNumeric<int> allocationSize = imageData->size().area() * 4; |
| + |
| + mojo::ScopedSharedBufferHandle sharedBufferHandle = |
| + getSharedBufferOnData(resolver, data, allocationSize.ValueOrDefault(0)); |
| + if (!sharedBufferHandle->is_valid()) |
| + return promise; |
| + |
| + return doDetect(resolver, std::move(sharedBufferHandle), imageData->width(), |
| + imageData->height()); |
| +} |
| + |
| ScriptPromise ShapeDetector::detectShapesOnImageElement( |
| ScriptPromiseResolver* resolver, |
| const HTMLImageElement* img) { |