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

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: RELAND2: ShapeDetection: use mojom::Bitmap for mojo interface. 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
deleted file mode 100644
index 9112e265a6b93175b4038a6efa9a69a569561f92..0000000000000000000000000000000000000000
--- a/services/shape_detection/android/java/src/org/chromium/shape_detection/SharedBufferUtils.java
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package org.chromium.shape_detection;
-
-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 java.nio.ByteBuffer;
-
-/**
- * Utility class to convert a SharedBufferHandle to a GMS core YUV Frame.
- */
-public class SharedBufferUtils {
- public static Frame convertToFrame(
- SharedBufferHandle frameData, final int width, final int 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)) {
- 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());
- 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.
- return new Frame.Builder().setBitmap(bitmap).build();
- } catch (IllegalArgumentException | IllegalStateException ex) {
- return null;
- }
- }
-}

Powered by Google App Engine
This is Rietveld 408576698