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 610e4d35c8f1a896a37f1c30a7ff80c781554e0e..140360babdc26a5fc45980dd4ce9cfdc3f73e874 100644 |
| --- a/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp |
| +++ b/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp |
| @@ -22,28 +22,19 @@ 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; |
| +skia::mojom::blink::BitmapPtr getBitmapOnData(int width, |
| + int height, |
|
mcasas
2017/01/24 00:52:06
get is usually reserved for getters/accessors and
|
| + Vector<uint8_t> bitmapData) { |
| + skia::mojom::blink::BitmapPtr bitmap = skia::mojom::blink::Bitmap::New(); |
| + |
| + bitmap->color_type = (kN32_SkColorType == kRGBA_8888_SkColorType) |
| + ? skia::mojom::ColorType::RGBA_8888 |
| + : skia::mojom::ColorType::BGRA_8888; |
| + bitmap->width = width; |
| + bitmap->height = height; |
| + bitmap->pixel_data = std::move(bitmapData); |
| + |
| + return bitmap; |
| } |
| } // anonymous namespace |
| @@ -140,13 +131,12 @@ ScriptPromise ShapeDetector::detect(ScriptState* scriptState, |
| return promise; |
| } |
| - mojo::ScopedSharedBufferHandle sharedBufferHandle = getSharedBufferOnData( |
| - resolver, pixelDataPtr, allocationSize.ValueOrDefault(0)); |
| - if (!sharedBufferHandle->is_valid()) |
| - return promise; |
| + WTF::Vector<uint8_t> bitmapData; |
| + bitmapData.append(pixelDataPtr, |
| + static_cast<int>(allocationSize.ValueOrDefault(0))); |
| - return doDetect(resolver, std::move(sharedBufferHandle), image->width(), |
| - image->height()); |
| + return doDetect(resolver, getBitmapOnData(image->width(), image->height(), |
| + std::move(bitmapData))); |
| } |
| ScriptPromise ShapeDetector::detectShapesOnImageData( |
| @@ -161,14 +151,12 @@ ScriptPromise ShapeDetector::detectShapesOnImageData( |
| uint8_t* const data = imageData->data()->data(); |
| WTF::CheckedNumeric<int> allocationSize = imageData->size().area() * 4; |
| + WTF::Vector<uint8_t> bitmapData; |
| + bitmapData.append(data, static_cast<int>(allocationSize.ValueOrDefault(0))); |
| - 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()); |
| + return doDetect(resolver, |
| + getBitmapOnData(imageData->width(), imageData->height(), |
| + std::move(bitmapData))); |
| } |
| ScriptPromise ShapeDetector::detectShapesOnImageElement( |
| @@ -209,26 +197,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> bitmapData(skiaInfo.getSafeSize(rowBytes)); |
| + const SkPixmap pixmap(skiaInfo, bitmapData.data(), rowBytes); |
| if (!image->readPixels(pixmap, 0, 0)) { |
| resolver->reject(DOMException::create( |
| InvalidStateError, |
| @@ -236,8 +208,9 @@ ScriptPromise ShapeDetector::detectShapesOnImageElement( |
| return promise; |
| } |
| - return doDetect(resolver, std::move(sharedBufferHandle), img->naturalWidth(), |
| - img->naturalHeight()); |
| + return doDetect(resolver, |
| + getBitmapOnData(img->naturalWidth(), img->naturalHeight(), |
| + std::move(bitmapData))); |
| } |
| } // namespace blink |