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 610e4d35c8f1a896a37f1c30a7ff80c781554e0e..f3d6ae204f7b49062ae15154bd3e521963056bf4 100644 |
--- a/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp |
+++ b/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp |
@@ -20,34 +20,6 @@ |
namespace blink { |
-namespace { |
- |
-mojo::ScopedSharedBufferHandle getSharedBufferOnData( |
- ScriptPromiseResolver* resolver, |
- uint8_t* data, |
- int size) { |
- DCHECK(data); |
- DCHECK(size); |
- ScriptPromise promise = resolver->promise(); |
- |
- mojo::ScopedSharedBufferHandle sharedBufferHandle = |
- mojo::SharedBufferHandle::Create(size); |
- if (!sharedBufferHandle->is_valid()) { |
- resolver->reject( |
- DOMException::create(InvalidStateError, "Internal allocation error")); |
- return sharedBufferHandle; |
- } |
- |
- const mojo::ScopedSharedBufferMapping mappedBuffer = |
- sharedBufferHandle->Map(size); |
- DCHECK(mappedBuffer.get()); |
- memcpy(mappedBuffer.get(), data, size); |
- |
- return sharedBufferHandle; |
-} |
- |
-} // anonymous namespace |
- |
ShapeDetector::ShapeDetector(LocalFrame& frame) { |
DCHECK(frame.interfaceProvider()); |
} |
@@ -140,13 +112,14 @@ ScriptPromise ShapeDetector::detect(ScriptState* scriptState, |
return promise; |
} |
- mojo::ScopedSharedBufferHandle sharedBufferHandle = getSharedBufferOnData( |
- resolver, pixelDataPtr, allocationSize.ValueOrDefault(0)); |
- if (!sharedBufferHandle->is_valid()) |
- return promise; |
+ skia::mojom::blink::BitmapPtr bitmap = skia::mojom::blink::Bitmap::New(); |
+ WTF::Vector<uint8_t> data; |
xianglu
2017/01/18 21:08:37
nit: Maybe we can call it something like "bitmapDa
|
+ data.append(pixelDataPtr, static_cast<int>(allocationSize.ValueOrDefault(0))); |
+ bitmap->width = image->width(); |
+ bitmap->height = image->height(); |
+ bitmap->pixel_data = std::move(data); |
- return doDetect(resolver, std::move(sharedBufferHandle), image->width(), |
- image->height()); |
+ return doDetect(resolver, std::move(bitmap)); |
} |
ScriptPromise ShapeDetector::detectShapesOnImageData( |
@@ -161,14 +134,14 @@ ScriptPromise ShapeDetector::detectShapesOnImageData( |
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()); |
+ skia::mojom::blink::BitmapPtr bitmap = skia::mojom::blink::Bitmap::New(); |
+ WTF::Vector<uint8_t> datas; |
+ datas.append(data, static_cast<int>(allocationSize.ValueOrDefault(0))); |
+ bitmap->width = imageData->width(); |
+ bitmap->height = imageData->height(); |
+ bitmap->pixel_data = std::move(datas); |
+ |
+ return doDetect(resolver, std::move(bitmap)); |
} |
ScriptPromise ShapeDetector::detectShapesOnImageElement( |
@@ -209,26 +182,10 @@ ScriptPromise ShapeDetector::detectShapesOnImageElement( |
const SkImageInfo skiaInfo = |
SkImageInfo::MakeN32(image->width(), image->height(), image->alphaType()); |
+ size_t rowBytes = skiaInfo.minRowBytes(); |
- const uint32_t allocationSize = skiaInfo.getSafeSize(skiaInfo.minRowBytes()); |
- |
- mojo::ScopedSharedBufferHandle sharedBufferHandle = |
- mojo::SharedBufferHandle::Create(allocationSize); |
- if (!sharedBufferHandle.is_valid()) { |
- DLOG(ERROR) << "Requested allocation : " << allocationSize |
- << "B, larger than |mojo::edk::kMaxSharedBufferSize| == 16MB "; |
- // TODO(xianglu): For now we reject the promise if the image is too large. |
- // But consider resizing the image to remove restriction on the user side. |
- // Also, add LayoutTests for this case later. |
- resolver->reject( |
- DOMException::create(InvalidStateError, "Image exceeds size limit.")); |
- return promise; |
- } |
- |
- const mojo::ScopedSharedBufferMapping mappedBuffer = |
- sharedBufferHandle->Map(allocationSize); |
- |
- const SkPixmap pixmap(skiaInfo, mappedBuffer.get(), skiaInfo.minRowBytes()); |
+ Vector<uint8_t> datas(skiaInfo.getSafeSize(rowBytes)); |
+ const SkPixmap pixmap(skiaInfo, datas.data(), rowBytes); |
if (!image->readPixels(pixmap, 0, 0)) { |
resolver->reject(DOMException::create( |
InvalidStateError, |
@@ -236,8 +193,12 @@ ScriptPromise ShapeDetector::detectShapesOnImageElement( |
return promise; |
} |
- return doDetect(resolver, std::move(sharedBufferHandle), img->naturalWidth(), |
- img->naturalHeight()); |
+ skia::mojom::blink::BitmapPtr bitmap = skia::mojom::blink::Bitmap::New(); |
+ bitmap->width = img->naturalWidth(); |
+ bitmap->height = img->naturalHeight(); |
+ bitmap->pixel_data = std::move(datas); |
+ |
+ return doDetect(resolver, std::move(bitmap)); |
} |
} // namespace blink |