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

Unified Diff: services/shape_detection/android/java/src/org/chromium/shape_detection/SharedBufferUtils.java

Issue 2875243002: RELAND: ShapeDetection: use mojom::Bitmap for mojo interface. (Closed)
Patch Set: Rebasing as all Java files were moved to //services Created 3 years, 7 months 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 side-by-side diff with in-line comments
Download patch
Index: services/shape_detection/android/java/src/org/chromium/shape_detection/SharedBufferUtils.java
diff --git a/services/shape_detection/android/java/src/org/chromium/shape_detection/SharedBufferUtils.java b/services/shape_detection/android/java/src/org/chromium/shape_detection/SharedBufferUtils.java
index 9112e265a6b93175b4038a6efa9a69a569561f92..2db63e75b3a88bb5416f3bd2085103383a86d71c 100644
--- a/services/shape_detection/android/java/src/org/chromium/shape_detection/SharedBufferUtils.java
+++ b/services/shape_detection/android/java/src/org/chromium/shape_detection/SharedBufferUtils.java
@@ -8,9 +8,7 @@ import android.graphics.Bitmap;
import com.google.android.gms.vision.Frame;
-import org.chromium.mojo.system.MojoException;
-import org.chromium.mojo.system.SharedBufferHandle;
-import org.chromium.mojo.system.SharedBufferHandle.MapFlags;
+import org.chromium.skia.mojom.ColorType;
import java.nio.ByteBuffer;
@@ -18,29 +16,29 @@ import java.nio.ByteBuffer;
* Utility class to convert a SharedBufferHandle to a GMS core YUV Frame.
*/
public class SharedBufferUtils {
mcasas 2017/05/16 18:12:53 Also this file/class should not be called SharedB
- public static Frame convertToFrame(
- SharedBufferHandle frameData, final int width, final int height) {
+ public static Frame convertToFrame(org.chromium.skia.mojom.Bitmap bitmapData) {
+ int width = bitmapData.width;
+ int height = bitmapData.height;
final long numPixels = (long) width * height;
// TODO(mcasas): https://crbug.com/670028 homogeneize overflow checking.
- if (!frameData.isValid() || width <= 0 || height <= 0 || numPixels > (Long.MAX_VALUE / 4)) {
+ if (bitmapData.pixelData == null || width <= 0 || height <= 0
+ || numPixels > (Long.MAX_VALUE / 4)) {
return null;
}
- // Mapping |frameData| will fail if the intended mapped size is larger
- // than its actual capacity, which is limited by the appropriate
- // mojo::edk::Configuration entry.
- ByteBuffer imageBuffer = frameData.map(0, numPixels * 4, MapFlags.none());
+ // TODO(junwei.fu): https://crbug.com/684921 support other bitmap pixel formats.
+ if (bitmapData.colorType != ColorType.RGBA_8888
+ && bitmapData.colorType != ColorType.BGRA_8888) {
+ return null;
+ }
+
+ ByteBuffer imageBuffer = ByteBuffer.wrap(bitmapData.pixelData);
if (imageBuffer.capacity() <= 0) {
return null;
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.copyPixelsFromBuffer(imageBuffer);
- try {
- frameData.unmap(imageBuffer);
- frameData.close();
- } catch (MojoException e) {
- }
try {
// This constructor implies a pixel format conversion to YUV.

Powered by Google App Engine
This is Rietveld 408576698