Commit 32b38e9f authored by danakj's avatar danakj Committed by Chromium LUCI CQ

Rename skia.mojom.Bitmap to BitmapWithArbitraryBpp, introduce BitmapN32

Future mojoms should use BitmapN32, and we will convert existing users
of BitmapWithArbitraryBpp over to BitmapN32 wherever possible - the
difficulty of switching comes primarily due to the use of "Stable" on
the skia.mojom.Bitmap mojom and the gfx.mojom.Image mojom. We will
likely need to split off a non-stable Image type as well for non-
ChromeOS-API uses.

This suggests perhaps that all "Stable" mojoms should be independent
from the non-stable mojoms used throughout Chromium.

R=dcheng@chromium.org

Bug: 1144462
Change-Id: I110139960fc231e8ad2f6b0864fbc6200079cb29
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2560398
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: default avatarFlorin Malita <fmalita@chromium.org>
Reviewed-by: default avatarDarin Fisher <darin@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832584}
parent e2222449
...@@ -33,5 +33,5 @@ interface PdfThumbnailer { ...@@ -33,5 +33,5 @@ interface PdfThumbnailer {
[EnableIf=is_chromeos] [EnableIf=is_chromeos]
GetThumbnail(ThumbParams params, GetThumbnail(ThumbParams params,
mojo_base.mojom.ReadOnlySharedMemoryRegion pdf_region) mojo_base.mojom.ReadOnlySharedMemoryRegion pdf_region)
=> (skia.mojom.Bitmap? bitmap); => (skia.mojom.BitmapWithArbitraryBpp? bitmap);
}; };
...@@ -56,7 +56,7 @@ struct GenerateQRCodeResponse { ...@@ -56,7 +56,7 @@ struct GenerateQRCodeResponse {
// Image data for generated QR code. May be null on error, or if rendering // Image data for generated QR code. May be null on error, or if rendering
// was not requested. // was not requested.
skia.mojom.Bitmap? bitmap; skia.mojom.BitmapWithArbitraryBpp? bitmap;
// QR Code data. // QR Code data.
array<uint8> data; array<uint8> data;
......
...@@ -111,7 +111,7 @@ interface PaintPreviewCompositor { ...@@ -111,7 +111,7 @@ interface PaintPreviewCompositor {
BitmapForSeparatedFrame(mojo_base.mojom.UnguessableToken frame_guid, BitmapForSeparatedFrame(mojo_base.mojom.UnguessableToken frame_guid,
gfx.mojom.Rect clip_rect, gfx.mojom.Rect clip_rect,
float scale_factor) => float scale_factor) =>
(BitmapStatus status, skia.mojom.Bitmap? bitmap); (BitmapStatus status, skia.mojom.BitmapWithArbitraryBpp? bitmap);
// Starts the compositing process for |BitmapForMainFrame| calls using frame // Starts the compositing process for |BitmapForMainFrame| calls using frame
// data |request|. |status| will be negative on failure. If the root frame is // data |request|. |status| will be negative on failure. If the root frame is
...@@ -127,7 +127,7 @@ interface PaintPreviewCompositor { ...@@ -127,7 +127,7 @@ interface PaintPreviewCompositor {
// |status|. // |status|.
// |BeginMainFrameComposite| must be called before this method. // |BeginMainFrameComposite| must be called before this method.
BitmapForMainFrame(gfx.mojom.Rect clip_rect, float scale_factor) => BitmapForMainFrame(gfx.mojom.Rect clip_rect, float scale_factor) =>
(BitmapStatus status, skia.mojom.Bitmap? bitmap); (BitmapStatus status, skia.mojom.BitmapWithArbitraryBpp? bitmap);
// Sets the root frame of the compositor. Used for tracing and diagnostics. // Sets the root frame of the compositor. Used for tracing and diagnostics.
SetRootFrameUrl(url.mojom.Url url); SetRootFrameUrl(url.mojom.Url url);
......
...@@ -26,7 +26,7 @@ import org.chromium.mojo.bindings.MessageReceiver; ...@@ -26,7 +26,7 @@ import org.chromium.mojo.bindings.MessageReceiver;
import org.chromium.mojo.system.Core; import org.chromium.mojo.system.Core;
import org.chromium.mojo.system.Pair; import org.chromium.mojo.system.Pair;
import org.chromium.mojo_base.BigBufferUtil; import org.chromium.mojo_base.BigBufferUtil;
import org.chromium.skia.mojom.Bitmap; import org.chromium.skia.mojom.BitmapWithArbitraryBpp;
/** /**
* Represents the MessageChannel MessagePort object. Inspired from * Represents the MessageChannel MessagePort object. Inspired from
...@@ -299,7 +299,7 @@ public class AppWebMessagePort implements MessagePort { ...@@ -299,7 +299,7 @@ public class AppWebMessagePort implements MessagePort {
msg.message.nativeFileSystemTokens = new NativeFileSystemTransferToken[0]; msg.message.nativeFileSystemTokens = new NativeFileSystemTransferToken[0];
msg.message.senderOrigin = null; msg.message.senderOrigin = null;
msg.arrayBufferContentsArray = new SerializedArrayBufferContents[0]; msg.arrayBufferContentsArray = new SerializedArrayBufferContents[0];
msg.imageBitmapContentsArray = new Bitmap[0]; msg.imageBitmapContentsArray = new BitmapWithArbitraryBpp[0];
msg.ports = ports; msg.ports = ports;
msg.streamChannels = new MessagePortDescriptor[0]; msg.streamChannels = new MessagePortDescriptor[0];
mConnector.accept(msg.serializeWithHeader(mMojoCore, MESSAGE_HEADER)); mConnector.accept(msg.serializeWithHeader(mMojoCore, MESSAGE_HEADER));
......
...@@ -43,7 +43,7 @@ struct WebTestRendererDumpResult { ...@@ -43,7 +43,7 @@ struct WebTestRendererDumpResult {
string? layout; string? layout;
// Image dump. // Image dump.
skia.mojom.Bitmap? pixels; skia.mojom.BitmapWithArbitraryBpp? pixels;
string actual_pixel_hash; string actual_pixel_hash;
// Selection rect dump. // Selection rect dump.
......
...@@ -111,7 +111,7 @@ enum XRInteractionMode { ...@@ -111,7 +111,7 @@ enum XRInteractionMode {
}; };
struct XRTrackedImage { struct XRTrackedImage {
skia.mojom.Bitmap bitmap; skia.mojom.BitmapWithArbitraryBpp bitmap;
gfx.mojom.Size size_in_pixels; gfx.mojom.Size size_in_pixels;
float width_in_meters; float width_in_meters;
}; };
......
...@@ -28,11 +28,14 @@ int64_t kPadding = 64; ...@@ -28,11 +28,14 @@ int64_t kPadding = 64;
void ResizeImage(SkBitmap* decoded_image, void ResizeImage(SkBitmap* decoded_image,
bool shrink_to_fit, bool shrink_to_fit,
int64_t max_size_in_bytes) { int64_t max_size_in_bytes) {
// When serialized, the space taken up by a skia::mojom::Bitmap excluding // When serialized, the space taken up by a
// the pixel data payload should be: // skia::mojom::BitmapWithArbitraryBpp excluding the pixel data payload should
// sizeof(skia::mojom::Bitmap::Data_) + pixel data array header (8 bytes) // be:
// sizeof(skia::mojom::BitmapWithArbitraryBpp::Data_) +
// pixel data array header (8 bytes)
// Use a bigger number in case we need padding at the end. // Use a bigger number in case we need padding at the end.
int64_t struct_size = sizeof(skia::mojom::Bitmap::Data_) + kPadding; int64_t struct_size =
sizeof(skia::mojom::BitmapWithArbitraryBpp::Data_) + kPadding;
int64_t image_size = decoded_image->computeByteSize(); int64_t image_size = decoded_image->computeByteSize();
int halves = 0; int halves = 0;
while (struct_size + (image_size >> 2 * halves) > max_size_in_bytes) while (struct_size + (image_size >> 2 * halves) > max_size_in_bytes)
......
...@@ -87,7 +87,7 @@ class BlinkInitializer : public blink::Platform { ...@@ -87,7 +87,7 @@ class BlinkInitializer : public blink::Platform {
blink::CreateMainThreadAndInitialize(this, &binders); blink::CreateMainThreadAndInitialize(this, &binders);
} }
~BlinkInitializer() override {} ~BlinkInitializer() override = default;
private: private:
DISALLOW_COPY_AND_ASSIGN(BlinkInitializer); DISALLOW_COPY_AND_ASSIGN(BlinkInitializer);
...@@ -118,7 +118,7 @@ TEST_F(ImageDecoderImplTest, DecodeImageSizeLimit) { ...@@ -118,7 +118,7 @@ TEST_F(ImageDecoderImplTest, DecodeImageSizeLimit) {
// Approx max height for 3:2 image that will fit in the allotted space. // Approx max height for 3:2 image that will fit in the allotted space.
// 1.5 for width/height ratio, 4 for bytes/pixel. // 1.5 for width/height ratio, 4 for bytes/pixel.
int max_height_for_msg = sqrt(kTestMaxImageSize / (1.5 * 4)); int max_height_for_msg = sqrt(kTestMaxImageSize / (1.5 * 4));
int base_msg_size = sizeof(skia::mojom::Bitmap::Data_); int base_msg_size = sizeof(skia::mojom::BitmapWithArbitraryBpp::Data_);
// Sizes which should trigger dimension-halving 0, 1 and 2 times // Sizes which should trigger dimension-halving 0, 1 and 2 times
int heights[] = {max_height_for_msg - 10, max_height_for_msg + 10, int heights[] = {max_height_for_msg - 10, max_height_for_msg + 10,
......
...@@ -34,7 +34,7 @@ interface ImageDecoder { ...@@ -34,7 +34,7 @@ interface ImageDecoder {
DecodeImage(mojo_base.mojom.BigBuffer encoded_data, ImageCodec codec, DecodeImage(mojo_base.mojom.BigBuffer encoded_data, ImageCodec codec,
bool shrink_to_fit, int64 max_size_in_bytes, bool shrink_to_fit, int64 max_size_in_bytes,
gfx.mojom.Size desired_image_frame_size) gfx.mojom.Size desired_image_frame_size)
=> (skia.mojom.Bitmap? decoded_image); => (skia.mojom.BitmapWithArbitraryBpp? decoded_image);
// Decodes the image in |encoded_data|. This will return all frames in the // Decodes the image in |encoded_data|. This will return all frames in the
// image and assumes it is an animation (instead of say, a multi-sized image). // image and assumes it is an animation (instead of say, a multi-sized image).
......
...@@ -75,7 +75,8 @@ public class BarcodeDetectionImpl implements BarcodeDetection { ...@@ -75,7 +75,8 @@ public class BarcodeDetectionImpl implements BarcodeDetection {
} }
@Override @Override
public void detect(org.chromium.skia.mojom.Bitmap bitmapData, DetectResponse callback) { public void detect(
org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmapData, DetectResponse callback) {
// The vision library will be downloaded the first time the API is used // The vision library will be downloaded the first time the API is used
// on the device; this happens "fast", but it might have not completed, // on the device; this happens "fast", but it might have not completed,
// bail in this case. Also, the API was disabled between and v.9.0 and // bail in this case. Also, the API was disabled between and v.9.0 and
......
...@@ -17,7 +17,8 @@ import java.nio.ByteBuffer; ...@@ -17,7 +17,8 @@ import java.nio.ByteBuffer;
* Utility class to convert a Bitmap to a GMS core YUV Frame. * Utility class to convert a Bitmap to a GMS core YUV Frame.
*/ */
public class BitmapUtils { public class BitmapUtils {
public static Bitmap convertToBitmap(org.chromium.skia.mojom.Bitmap bitmapData) { public static Bitmap convertToBitmap(
org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmapData) {
if (bitmapData.imageInfo == null) return null; if (bitmapData.imageInfo == null) return null;
int width = bitmapData.imageInfo.width; int width = bitmapData.imageInfo.width;
int height = bitmapData.imageInfo.height; int height = bitmapData.imageInfo.height;
...@@ -45,7 +46,7 @@ public class BitmapUtils { ...@@ -45,7 +46,7 @@ public class BitmapUtils {
return bitmap; return bitmap;
} }
public static Frame convertToFrame(org.chromium.skia.mojom.Bitmap bitmapData) { public static Frame convertToFrame(org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmapData) {
Bitmap bitmap = convertToBitmap(bitmapData); Bitmap bitmap = convertToBitmap(bitmapData);
if (bitmap == null) { if (bitmap == null) {
return null; return null;
......
...@@ -36,7 +36,8 @@ public class FaceDetectionImpl implements FaceDetection { ...@@ -36,7 +36,8 @@ public class FaceDetectionImpl implements FaceDetection {
} }
@Override @Override
public void detect(org.chromium.skia.mojom.Bitmap bitmapData, final DetectResponse callback) { public void detect(org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmapData,
final DetectResponse callback) {
Bitmap bitmap = BitmapUtils.convertToBitmap(bitmapData); Bitmap bitmap = BitmapUtils.convertToBitmap(bitmapData);
if (bitmap == null) { if (bitmap == null) {
Log.e(TAG, "Error converting Mojom Bitmap to Android Bitmap"); Log.e(TAG, "Error converting Mojom Bitmap to Android Bitmap");
......
...@@ -59,7 +59,8 @@ public class FaceDetectionImplGmsCore implements FaceDetection { ...@@ -59,7 +59,8 @@ public class FaceDetectionImplGmsCore implements FaceDetection {
} }
@Override @Override
public void detect(org.chromium.skia.mojom.Bitmap bitmapData, DetectResponse callback) { public void detect(
org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmapData, DetectResponse callback) {
// The vision library will be downloaded the first time the API is used // The vision library will be downloaded the first time the API is used
// on the device; this happens "fast", but it might have not completed, // on the device; this happens "fast", but it might have not completed,
// bail in this case. // bail in this case.
......
...@@ -34,7 +34,8 @@ public class TextDetectionImpl implements TextDetection { ...@@ -34,7 +34,8 @@ public class TextDetectionImpl implements TextDetection {
} }
@Override @Override
public void detect(org.chromium.skia.mojom.Bitmap bitmapData, DetectResponse callback) { public void detect(
org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmapData, DetectResponse callback) {
// The vision library will be downloaded the first time the API is used // The vision library will be downloaded the first time the API is used
// on the device; this happens "fast", but it might have not completed, // on the device; this happens "fast", but it might have not completed,
// bail in this case. Also, the API was disabled between and v.9.0 and // bail in this case. Also, the API was disabled between and v.9.0 and
......
...@@ -36,7 +36,7 @@ import java.util.concurrent.TimeUnit; ...@@ -36,7 +36,7 @@ import java.util.concurrent.TimeUnit;
@Batch(Batch.UNIT_TESTS) @Batch(Batch.UNIT_TESTS)
@UseRunnerDelegate(BaseJUnit4RunnerDelegate.class) @UseRunnerDelegate(BaseJUnit4RunnerDelegate.class)
public class BarcodeDetectionImplTest { public class BarcodeDetectionImplTest {
private static final org.chromium.skia.mojom.Bitmap QR_CODE_BITMAP = private static final org.chromium.skia.mojom.BitmapWithArbitraryBpp QR_CODE_BITMAP =
TestUtils.mojoBitmapFromFile("qr_code.png"); TestUtils.mojoBitmapFromFile("qr_code.png");
private static final int[] SUPPORTED_FORMATS = {BarcodeFormat.AZTEC, BarcodeFormat.CODE_128, private static final int[] SUPPORTED_FORMATS = {BarcodeFormat.AZTEC, BarcodeFormat.CODE_128,
...@@ -65,13 +65,14 @@ public class BarcodeDetectionImplTest { ...@@ -65,13 +65,14 @@ public class BarcodeDetectionImplTest {
return toReturn; return toReturn;
} }
private static BarcodeDetectionResult[] detect(org.chromium.skia.mojom.Bitmap mojoBitmap) { private static BarcodeDetectionResult[] detect(
org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmap) {
BarcodeDetectorOptions options = new BarcodeDetectorOptions(); BarcodeDetectorOptions options = new BarcodeDetectorOptions();
return detectWithOptions(mojoBitmap, options); return detectWithOptions(mojoBitmap, options);
} }
private static BarcodeDetectionResult[] detectWithHint( private static BarcodeDetectionResult[] detectWithHint(
org.chromium.skia.mojom.Bitmap mojoBitmap, int format) { org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmap, int format) {
Assert.assertTrue(BarcodeFormat.isKnownValue(format)); Assert.assertTrue(BarcodeFormat.isKnownValue(format));
BarcodeDetectorOptions options = new BarcodeDetectorOptions(); BarcodeDetectorOptions options = new BarcodeDetectorOptions();
options.formats = new int[] {format}; options.formats = new int[] {format};
...@@ -79,7 +80,8 @@ public class BarcodeDetectionImplTest { ...@@ -79,7 +80,8 @@ public class BarcodeDetectionImplTest {
} }
private static BarcodeDetectionResult[] detectWithOptions( private static BarcodeDetectionResult[] detectWithOptions(
org.chromium.skia.mojom.Bitmap mojoBitmap, BarcodeDetectorOptions options) { org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmap,
BarcodeDetectorOptions options) {
BarcodeDetection detector = new BarcodeDetectionImpl(options); BarcodeDetection detector = new BarcodeDetectionImpl(options);
final ArrayBlockingQueue<BarcodeDetectionResult[]> queue = new ArrayBlockingQueue<>(1); final ArrayBlockingQueue<BarcodeDetectionResult[]> queue = new ArrayBlockingQueue<>(1);
...@@ -169,7 +171,8 @@ public class BarcodeDetectionImplTest { ...@@ -169,7 +171,8 @@ public class BarcodeDetectionImplTest {
if (!TestUtils.IS_GMS_CORE_SUPPORTED) { if (!TestUtils.IS_GMS_CORE_SUPPORTED) {
return; return;
} }
org.chromium.skia.mojom.Bitmap bitmap = TestUtils.mojoBitmapFromFile(inputFile); org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmap =
TestUtils.mojoBitmapFromFile(inputFile);
BarcodeDetectionResult[] results = detectWithHint(bitmap, format); BarcodeDetectionResult[] results = detectWithHint(bitmap, format);
Assert.assertEquals(1, results.length); Assert.assertEquals(1, results.length);
Assert.assertEquals(value, results[0].rawValue); Assert.assertEquals(value, results[0].rawValue);
...@@ -189,7 +192,8 @@ public class BarcodeDetectionImplTest { ...@@ -189,7 +192,8 @@ public class BarcodeDetectionImplTest {
if (!TestUtils.IS_GMS_CORE_SUPPORTED) { if (!TestUtils.IS_GMS_CORE_SUPPORTED) {
return; return;
} }
org.chromium.skia.mojom.Bitmap bitmap = TestUtils.mojoBitmapFromFile(inputFile); org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmap =
TestUtils.mojoBitmapFromFile(inputFile);
BarcodeDetectionResult[] results = detect(bitmap); BarcodeDetectionResult[] results = detect(bitmap);
Assert.assertEquals(1, results.length); Assert.assertEquals(1, results.length);
Assert.assertEquals(value, results[0].rawValue); Assert.assertEquals(value, results[0].rawValue);
......
...@@ -31,9 +31,9 @@ import java.util.concurrent.TimeUnit; ...@@ -31,9 +31,9 @@ import java.util.concurrent.TimeUnit;
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(BaseJUnit4ClassRunner.class)
@Batch(Batch.UNIT_TESTS) @Batch(Batch.UNIT_TESTS)
public class FaceDetectionImplTest { public class FaceDetectionImplTest {
private static final org.chromium.skia.mojom.Bitmap MONA_LISA_BITMAP = private static final org.chromium.skia.mojom.BitmapWithArbitraryBpp MONA_LISA_BITMAP =
TestUtils.mojoBitmapFromFile("mona_lisa.jpg"); TestUtils.mojoBitmapFromFile("mona_lisa.jpg");
private static final org.chromium.skia.mojom.Bitmap FACE_POSE_BITMAP = private static final org.chromium.skia.mojom.BitmapWithArbitraryBpp FACE_POSE_BITMAP =
TestUtils.mojoBitmapFromFile("face_pose.png"); TestUtils.mojoBitmapFromFile("face_pose.png");
// Different versions of Android have different implementations of FaceDetector.findFaces(), so // Different versions of Android have different implementations of FaceDetector.findFaces(), so
// we have to use a large error threshold. // we have to use a large error threshold.
...@@ -44,8 +44,9 @@ public class FaceDetectionImplTest { ...@@ -44,8 +44,9 @@ public class FaceDetectionImplTest {
public FaceDetectionImplTest() {} public FaceDetectionImplTest() {}
private static FaceDetectionResult[] detect(org.chromium.skia.mojom.Bitmap mojoBitmap, private static FaceDetectionResult[] detect(
boolean fastMode, DetectionProviderType api) { org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmap, boolean fastMode,
DetectionProviderType api) {
FaceDetectorOptions options = new FaceDetectorOptions(); FaceDetectorOptions options = new FaceDetectorOptions();
options.fastMode = fastMode; options.fastMode = fastMode;
options.maxDetectedFaces = 32; options.maxDetectedFaces = 32;
...@@ -112,7 +113,8 @@ public class FaceDetectionImplTest { ...@@ -112,7 +113,8 @@ public class FaceDetectionImplTest {
MONA_LISA_BITMAP.imageInfo.height, Bitmap.Config.ARGB_8888); MONA_LISA_BITMAP.imageInfo.height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(paddedBitmap); Canvas canvas = new Canvas(paddedBitmap);
canvas.drawBitmap(BitmapUtils.convertToBitmap(MONA_LISA_BITMAP), 0, 0, null); canvas.drawBitmap(BitmapUtils.convertToBitmap(MONA_LISA_BITMAP), 0, 0, null);
org.chromium.skia.mojom.Bitmap mojoBitmap = TestUtils.mojoBitmapFromBitmap(paddedBitmap); org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmap =
TestUtils.mojoBitmapFromBitmap(paddedBitmap);
Assert.assertEquals(1, mojoBitmap.imageInfo.width % 2); Assert.assertEquals(1, mojoBitmap.imageInfo.width % 2);
FaceDetectionResult[] results = detect(mojoBitmap, true, DetectionProviderType.ANDROID); FaceDetectionResult[] results = detect(mojoBitmap, true, DetectionProviderType.ANDROID);
......
...@@ -31,11 +31,13 @@ public class TestUtils { ...@@ -31,11 +31,13 @@ public class TestUtils {
ContextUtils.getApplicationContext()); ContextUtils.getApplicationContext());
} }
public static org.chromium.skia.mojom.Bitmap mojoBitmapFromBitmap(Bitmap bitmap) { public static org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmapFromBitmap(
Bitmap bitmap) {
ByteBuffer buffer = ByteBuffer.allocate(bitmap.getByteCount()); ByteBuffer buffer = ByteBuffer.allocate(bitmap.getByteCount());
bitmap.copyPixelsToBuffer(buffer); bitmap.copyPixelsToBuffer(buffer);
org.chromium.skia.mojom.Bitmap mojoBitmap = new org.chromium.skia.mojom.Bitmap(); org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmap =
new org.chromium.skia.mojom.BitmapWithArbitraryBpp();
mojoBitmap.imageInfo = new ImageInfo(); mojoBitmap.imageInfo = new ImageInfo();
mojoBitmap.imageInfo.width = bitmap.getWidth(); mojoBitmap.imageInfo.width = bitmap.getWidth();
mojoBitmap.imageInfo.height = bitmap.getHeight(); mojoBitmap.imageInfo.height = bitmap.getHeight();
...@@ -45,13 +47,15 @@ public class TestUtils { ...@@ -45,13 +47,15 @@ public class TestUtils {
return mojoBitmap; return mojoBitmap;
} }
public static org.chromium.skia.mojom.Bitmap mojoBitmapFromFile(String relPath) { public static org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmapFromFile(
String relPath) {
String path = UrlUtils.getIsolatedTestFilePath("services/test/data/" + relPath); String path = UrlUtils.getIsolatedTestFilePath("services/test/data/" + relPath);
Bitmap bitmap = BitmapFactory.decodeFile(path); Bitmap bitmap = BitmapFactory.decodeFile(path);
return mojoBitmapFromBitmap(bitmap); return mojoBitmapFromBitmap(bitmap);
} }
public static org.chromium.skia.mojom.Bitmap mojoBitmapFromText(String[] texts) { public static org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmapFromText(
String[] texts) {
final int x = 10; final int x = 10;
final int baseline = 100; final int baseline = 100;
......
...@@ -30,10 +30,11 @@ public class TextDetectionImplTest { ...@@ -30,10 +30,11 @@ public class TextDetectionImplTest {
"The quick brown fox jumped over the lazy dog.", "Helvetica Neue 36."}; "The quick brown fox jumped over the lazy dog.", "Helvetica Neue 36."};
private static final float[][] TEXT_BOUNDING_BOX = { private static final float[][] TEXT_BOUNDING_BOX = {
{0.0f, 71.0f, 753.0f, 36.0f}, {4.0f, 173.0f, 307.0f, 28.0f}}; {0.0f, 71.0f, 753.0f, 36.0f}, {4.0f, 173.0f, 307.0f, 28.0f}};
private static final org.chromium.skia.mojom.Bitmap TEXT_DETECTION_BITMAP = private static final org.chromium.skia.mojom.BitmapWithArbitraryBpp TEXT_DETECTION_BITMAP =
TestUtils.mojoBitmapFromText(DETECTION_EXPECTED_TEXT); TestUtils.mojoBitmapFromText(DETECTION_EXPECTED_TEXT);
private static TextDetectionResult[] detect(org.chromium.skia.mojom.Bitmap mojoBitmap) { private static TextDetectionResult[] detect(
org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmap) {
TextDetection detector = new TextDetectionImpl(); TextDetection detector = new TextDetectionImpl();
final ArrayBlockingQueue<TextDetectionResult[]> queue = new ArrayBlockingQueue<>(1); final ArrayBlockingQueue<TextDetectionResult[]> queue = new ArrayBlockingQueue<>(1);
......
...@@ -16,7 +16,7 @@ import org.robolectric.shadows.ShadowLog; ...@@ -16,7 +16,7 @@ import org.robolectric.shadows.ShadowLog;
import org.chromium.base.test.BaseRobolectricTestRunner; import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.mojo_base.BigBufferUtil; import org.chromium.mojo_base.BigBufferUtil;
import org.chromium.skia.mojom.Bitmap; import org.chromium.skia.mojom.BitmapWithArbitraryBpp;
import org.chromium.skia.mojom.ColorType; import org.chromium.skia.mojom.ColorType;
import org.chromium.skia.mojom.ImageInfo; import org.chromium.skia.mojom.ImageInfo;
...@@ -46,7 +46,7 @@ public class BitmapUtilsTest { ...@@ -46,7 +46,7 @@ public class BitmapUtilsTest {
@Test @Test
@Feature({"ShapeDetection"}) @Feature({"ShapeDetection"})
public void testConversionFailsWithInvalidBitmap() { public void testConversionFailsWithInvalidBitmap() {
Bitmap bitmap = new Bitmap(); BitmapWithArbitraryBpp bitmap = new BitmapWithArbitraryBpp();
bitmap.pixelData = null; bitmap.pixelData = null;
bitmap.imageInfo = new ImageInfo(); bitmap.imageInfo = new ImageInfo();
...@@ -59,7 +59,7 @@ public class BitmapUtilsTest { ...@@ -59,7 +59,7 @@ public class BitmapUtilsTest {
@Test @Test
@Feature({"ShapeDetection"}) @Feature({"ShapeDetection"})
public void testConversionFailsWithInvalidDimensions() { public void testConversionFailsWithInvalidDimensions() {
Bitmap bitmap = new Bitmap(); BitmapWithArbitraryBpp bitmap = new BitmapWithArbitraryBpp();
bitmap.imageInfo = new ImageInfo(); bitmap.imageInfo = new ImageInfo();
bitmap.pixelData = BigBufferUtil.createBigBufferFromBytes(EMPTY_DATA); bitmap.pixelData = BigBufferUtil.createBigBufferFromBytes(EMPTY_DATA);
bitmap.imageInfo.width = INVALID_WIDTH; bitmap.imageInfo.width = INVALID_WIDTH;
...@@ -74,7 +74,7 @@ public class BitmapUtilsTest { ...@@ -74,7 +74,7 @@ public class BitmapUtilsTest {
@Test @Test
@Feature({"ShapeDetection"}) @Feature({"ShapeDetection"})
public void testConversionFailsWithWronglyWrappedData() { public void testConversionFailsWithWronglyWrappedData() {
Bitmap bitmap = new Bitmap(); BitmapWithArbitraryBpp bitmap = new BitmapWithArbitraryBpp();
bitmap.imageInfo = new ImageInfo(); bitmap.imageInfo = new ImageInfo();
bitmap.pixelData = BigBufferUtil.createBigBufferFromBytes(EMPTY_DATA); bitmap.pixelData = BigBufferUtil.createBigBufferFromBytes(EMPTY_DATA);
bitmap.imageInfo.width = VALID_WIDTH; bitmap.imageInfo.width = VALID_WIDTH;
......
...@@ -38,6 +38,6 @@ struct BarcodeDetectionResult { ...@@ -38,6 +38,6 @@ struct BarcodeDetectionResult {
interface BarcodeDetection { interface BarcodeDetection {
// |bitmap_data| contains tightly packed image pixels in row-major order. // |bitmap_data| contains tightly packed image pixels in row-major order.
Detect(skia.mojom.Bitmap bitmap_data) Detect(skia.mojom.BitmapWithArbitraryBpp bitmap_data)
=> (array<BarcodeDetectionResult> results); => (array<BarcodeDetectionResult> results);
}; };
...@@ -33,6 +33,6 @@ struct FaceDetectorOptions { ...@@ -33,6 +33,6 @@ struct FaceDetectorOptions {
interface FaceDetection { interface FaceDetection {
// |bitmap_data| contains tightly packed image pixels in row-major order. // |bitmap_data| contains tightly packed image pixels in row-major order.
Detect(skia.mojom.Bitmap bitmap_data) Detect(skia.mojom.BitmapWithArbitraryBpp bitmap_data)
=> (array<FaceDetectionResult> results); => (array<FaceDetectionResult> results);
}; };
...@@ -17,6 +17,6 @@ struct TextDetectionResult { ...@@ -17,6 +17,6 @@ struct TextDetectionResult {
interface TextDetection { interface TextDetection {
// |bitmap_data| contains tightly packed image pixels in row-major order. // |bitmap_data| contains tightly packed image pixels in row-major order.
Detect(skia.mojom.Bitmap bitmap_data) Detect(skia.mojom.BitmapWithArbitraryBpp bitmap_data)
=> (array<TextDetectionResult> results); => (array<TextDetectionResult> results);
}; };
...@@ -153,7 +153,8 @@ interface FrameSinkVideoCaptureOverlay { ...@@ -153,7 +153,8 @@ interface FrameSinkVideoCaptureOverlay {
// content (e.g., 0.0 refers to the top or left edge; 1.0 to just after the // content (e.g., 0.0 refers to the top or left edge; 1.0 to just after the
// bottom or right edge). Pass empty |bounds| to temporarily hide the overlay // bottom or right edge). Pass empty |bounds| to temporarily hide the overlay
// until a later call to SetBounds(). // until a later call to SetBounds().
SetImageAndBounds(skia.mojom.Bitmap image, gfx.mojom.RectF bounds); SetImageAndBounds(skia.mojom.BitmapWithArbitraryBpp image,
gfx.mojom.RectF bounds);
// Changes the bounds of the previously-set image, showing the overlay if // Changes the bounds of the previously-set image, showing the overlay if
// non-empty bounds are provided, and hiding the overlay otherwise. |bounds| // non-empty bounds are provided, and hiding the overlay otherwise. |bounds|
......
...@@ -53,7 +53,17 @@ mojom("mojom") { ...@@ -53,7 +53,17 @@ mojom("mojom") {
{ {
types = [ types = [
{ {
mojom = "skia.mojom.Bitmap" mojom = "skia.mojom.BitmapN32"
cpp = "::SkBitmap"
nullable_is_same_type = true
},
{
mojom = "skia.mojom.BitmapWithArbitraryBpp"
cpp = "::SkBitmap"
nullable_is_same_type = true
},
{
mojom = "skia.mojom.BitmapWithArbitraryBpp"
cpp = "::SkBitmap" cpp = "::SkBitmap"
nullable_is_same_type = true nullable_is_same_type = true
}, },
......
...@@ -8,8 +8,21 @@ module skia.mojom; ...@@ -8,8 +8,21 @@ module skia.mojom;
import "mojo/public/mojom/base/big_buffer.mojom"; import "mojo/public/mojom/base/big_buffer.mojom";
import "skia/public/mojom/image_info.mojom"; import "skia/public/mojom/image_info.mojom";
[Stable] // The most common way to transfer an SkBitmap over IPC. This struct enforces
struct Bitmap { // that the bitmap is 32bpp to prevent buffer-overflow problems when reading/
// writing the pixel buffer.
struct BitmapN32 {
BitmapN32ImageInfo image_info;
mojo_base.mojom.BigBuffer pixel_data;
};
// Marked stable as this is used in the crosapi. This struct should be
// avoided whenever possible. If used, extreme care must be taken when
// manipulating the pixels in the bitmap, either only using SkBitmap methods to
// read and write to them, or taking care to not assume that there are 32 bits-
// per-pixel.
[Stable, RenamedFrom="skia.mojom.Bitmap"]
struct BitmapWithArbitraryBpp {
ImageInfo image_info; ImageInfo image_info;
uint64 UNUSED_row_bytes; uint64 UNUSED_row_bytes;
mojo_base.mojom.BigBuffer pixel_data; mojo_base.mojom.BigBuffer pixel_data;
......
...@@ -66,7 +66,7 @@ bool CreateSkBitmapForPixelData(SkBitmap* b, ...@@ -66,7 +66,7 @@ bool CreateSkBitmapForPixelData(SkBitmap* b,
} // namespace } // namespace
// static // static
mojo_base::BigBufferView StructTraits<skia::mojom::BitmapDataView, mojo_base::BigBufferView StructTraits<skia::mojom::BitmapN32DataView,
SkBitmap>::pixel_data(const SkBitmap& b) { SkBitmap>::pixel_data(const SkBitmap& b) {
CHECK_EQ(b.rowBytes(), b.info().minRowBytes()); CHECK_EQ(b.rowBytes(), b.info().minRowBytes());
return mojo_base::BigBufferView(base::make_span( return mojo_base::BigBufferView(base::make_span(
...@@ -74,8 +74,33 @@ mojo_base::BigBufferView StructTraits<skia::mojom::BitmapDataView, ...@@ -74,8 +74,33 @@ mojo_base::BigBufferView StructTraits<skia::mojom::BitmapDataView,
} }
// static // static
bool StructTraits<skia::mojom::BitmapDataView, SkBitmap>::Read( bool StructTraits<skia::mojom::BitmapN32DataView, SkBitmap>::Read(
skia::mojom::BitmapDataView data, skia::mojom::BitmapN32DataView data,
SkBitmap* b) {
SkImageInfo image_info;
if (!data.ReadImageInfo(&image_info))
return false;
mojo_base::BigBufferView pixel_data_view;
if (!data.ReadPixelData(&pixel_data_view))
return false;
return CreateSkBitmapForPixelData(b, std::move(image_info),
pixel_data_view.data());
}
// static
mojo_base::BigBufferView
StructTraits<skia::mojom::BitmapWithArbitraryBppDataView, SkBitmap>::pixel_data(
const SkBitmap& b) {
CHECK_EQ(b.rowBytes(), b.info().minRowBytes());
return mojo_base::BigBufferView(base::make_span(
static_cast<uint8_t*>(b.getPixels()), b.computeByteSize()));
}
// static
bool StructTraits<skia::mojom::BitmapWithArbitraryBppDataView, SkBitmap>::Read(
skia::mojom::BitmapWithArbitraryBppDataView data,
SkBitmap* b) { SkBitmap* b) {
SkImageInfo image_info; SkImageInfo image_info;
if (!data.ReadImageInfo(&image_info)) if (!data.ReadImageInfo(&image_info))
......
...@@ -16,10 +16,23 @@ ...@@ -16,10 +16,23 @@
namespace mojo { namespace mojo {
// Struct traits to use SkBitmap for skia::mojom::Bitmap in Chrome C++ code. // Struct traits to convert between SkBitmap and mojom types.
template <>
struct COMPONENT_EXPORT(SKIA_SHARED_TRAITS)
StructTraits<skia::mojom::BitmapN32DataView, SkBitmap> {
static bool IsNull(const SkBitmap& b) { return b.isNull(); }
static void SetToNull(SkBitmap* b) { b->reset(); }
static const SkImageInfo& image_info(const SkBitmap& b) { return b.info(); }
static mojo_base::BigBufferView pixel_data(const SkBitmap& b);
static bool Read(skia::mojom::BitmapN32DataView data, SkBitmap* b);
};
template <> template <>
struct COMPONENT_EXPORT(SKIA_SHARED_TRAITS) struct COMPONENT_EXPORT(SKIA_SHARED_TRAITS)
StructTraits<skia::mojom::BitmapDataView, SkBitmap> { StructTraits<skia::mojom::BitmapWithArbitraryBppDataView, SkBitmap> {
static bool IsNull(const SkBitmap& b) { return b.isNull(); } static bool IsNull(const SkBitmap& b) { return b.isNull(); }
static void SetToNull(SkBitmap* b) { b->reset(); } static void SetToNull(SkBitmap* b) { b->reset(); }
...@@ -27,7 +40,8 @@ struct COMPONENT_EXPORT(SKIA_SHARED_TRAITS) ...@@ -27,7 +40,8 @@ struct COMPONENT_EXPORT(SKIA_SHARED_TRAITS)
static uint64_t UNUSED_row_bytes(const SkBitmap& b) { return 0; } static uint64_t UNUSED_row_bytes(const SkBitmap& b) { return 0; }
static mojo_base::BigBufferView pixel_data(const SkBitmap& b); static mojo_base::BigBufferView pixel_data(const SkBitmap& b);
static bool Read(skia::mojom::BitmapDataView data, SkBitmap* b); static bool Read(skia::mojom::BitmapWithArbitraryBppDataView data,
SkBitmap* b);
}; };
template <> template <>
......
...@@ -22,13 +22,24 @@ ...@@ -22,13 +22,24 @@
namespace skia { namespace skia {
namespace { namespace {
// A helper to construct a skia.mojom.Bitmap without using StructTraits // A helper to construct a skia.mojom.BitmapN32 without using StructTraits
// to bypass checks on the sending/serialization side. // to bypass checks on the sending/serialization side.
mojo::StructPtr<skia::mojom::Bitmap> ConstructBitmap( mojo::StructPtr<skia::mojom::BitmapN32> ConstructBitmapN32(
SkImageInfo info, SkImageInfo info,
int row_bytes,
std::vector<unsigned char> pixels) { std::vector<unsigned char> pixels) {
auto mojom_bitmap = skia::mojom::Bitmap::New(); auto mojom_bitmap = skia::mojom::BitmapN32::New();
mojom_bitmap->image_info = std::move(info);
mojom_bitmap->pixel_data = std::move(pixels);
return mojom_bitmap;
}
// A helper to construct a skia.mojom.BitmapWithArbitraryBpp without using
// StructTraits to bypass checks on the sending/serialization side.
mojo::StructPtr<skia::mojom::BitmapWithArbitraryBpp>
ConstructBitmapWithArbitraryBpp(SkImageInfo info,
int row_bytes,
std::vector<unsigned char> pixels) {
auto mojom_bitmap = skia::mojom::BitmapWithArbitraryBpp::New();
mojom_bitmap->image_info = std::move(info); mojom_bitmap->image_info = std::move(info);
mojom_bitmap->UNUSED_row_bytes = row_bytes; mojom_bitmap->UNUSED_row_bytes = row_bytes;
mojom_bitmap->pixel_data = std::move(pixels); mojom_bitmap->pixel_data = std::move(pixels);
...@@ -127,10 +138,15 @@ TEST(StructTraitsTest, Bitmap) { ...@@ -127,10 +138,15 @@ TEST(StructTraitsTest, Bitmap) {
}; };
{ {
ASSERT_TRUE(mojo::test::SerializeAndDeserialize<skia::mojom::Bitmap>( ASSERT_TRUE(mojo::test::SerializeAndDeserialize<skia::mojom::BitmapN32>(
input, output)); input, output));
BitmapsEqual(input, output); BitmapsEqual(input, output);
} }
{
ASSERT_TRUE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapWithArbitraryBpp>(input, output));
BitmapsEqual(input, output);
}
{ {
ASSERT_TRUE(mojo::test::SerializeAndDeserialize< ASSERT_TRUE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapMappedFromTrustedProcess>(input, output)); skia::mojom::BitmapMappedFromTrustedProcess>(input, output));
...@@ -161,10 +177,15 @@ TEST(StructTraitsTest, BitmapNull) { ...@@ -161,10 +177,15 @@ TEST(StructTraitsTest, BitmapNull) {
SkBitmap output; SkBitmap output;
{ {
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<skia::mojom::Bitmap>( EXPECT_TRUE(mojo::test::SerializeAndDeserialize<skia::mojom::BitmapN32>(
input, output)); input, output));
IsDefaultInit(output); IsDefaultInit(output);
} }
{
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapWithArbitraryBpp>(input, output));
IsDefaultInit(output);
}
{ {
EXPECT_TRUE(mojo::test::SerializeAndDeserialize< EXPECT_TRUE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapMappedFromTrustedProcess>(input, output)); skia::mojom::BitmapMappedFromTrustedProcess>(input, output));
...@@ -199,11 +220,18 @@ TEST(StructTraitsTest, VerifyMojomConstruction) { ...@@ -199,11 +220,18 @@ TEST(StructTraitsTest, VerifyMojomConstruction) {
SkBitmap output; SkBitmap output;
{ {
mojo::StructPtr<skia::mojom::Bitmap> input = mojo::StructPtr<skia::mojom::BitmapN32> input =
ConstructBitmap(SkImageInfo::MakeN32Premul(1, 1), 0, {1, 2, 3, 4}); ConstructBitmapN32(SkImageInfo::MakeN32Premul(1, 1), {1, 2, 3, 4});
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<skia::mojom::Bitmap>( EXPECT_TRUE(mojo::test::SerializeAndDeserialize<skia::mojom::BitmapN32>(
input, output)); input, output));
} }
{
mojo::StructPtr<skia::mojom::BitmapWithArbitraryBpp> input =
ConstructBitmapWithArbitraryBpp(SkImageInfo::MakeN32Premul(1, 1), 0,
{1, 2, 3, 4});
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapWithArbitraryBpp>(input, output));
}
{ {
mojo::StructPtr<skia::mojom::BitmapMappedFromTrustedProcess> input = mojo::StructPtr<skia::mojom::BitmapMappedFromTrustedProcess> input =
ConstructBitmapMappedFromTrustedProcess( ConstructBitmapMappedFromTrustedProcess(
...@@ -228,9 +256,13 @@ TEST(StructTraitsTest, BitmapTooWideToSerialize) { ...@@ -228,9 +256,13 @@ TEST(StructTraitsTest, BitmapTooWideToSerialize) {
input.eraseColor(SK_ColorYELLOW); input.eraseColor(SK_ColorYELLOW);
SkBitmap output; SkBitmap output;
{ {
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<skia::mojom::Bitmap>( EXPECT_FALSE(mojo::test::SerializeAndDeserialize<skia::mojom::BitmapN32>(
input, output)); input, output));
} }
{
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapWithArbitraryBpp>(input, output));
}
{ {
EXPECT_FALSE(mojo::test::SerializeAndDeserialize< EXPECT_FALSE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapMappedFromTrustedProcess>(input, output)); skia::mojom::BitmapMappedFromTrustedProcess>(input, output));
...@@ -250,9 +282,13 @@ TEST(StructTraitsTest, BitmapTooTallToSerialize) { ...@@ -250,9 +282,13 @@ TEST(StructTraitsTest, BitmapTooTallToSerialize) {
input.eraseColor(SK_ColorYELLOW); input.eraseColor(SK_ColorYELLOW);
SkBitmap output; SkBitmap output;
{ {
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<skia::mojom::Bitmap>( EXPECT_FALSE(mojo::test::SerializeAndDeserialize<skia::mojom::BitmapN32>(
input, output)); input, output));
} }
{
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapWithArbitraryBpp>(input, output));
}
{ {
EXPECT_FALSE(mojo::test::SerializeAndDeserialize< EXPECT_FALSE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapMappedFromTrustedProcess>(input, output)); skia::mojom::BitmapMappedFromTrustedProcess>(input, output));
...@@ -275,8 +311,11 @@ static void BadRowBytes() { ...@@ -275,8 +311,11 @@ static void BadRowBytes() {
} }
// We do not allow sending rowBytes() other than the minRowBytes(). // We do not allow sending rowBytes() other than the minRowBytes().
TEST(StructTraitsTest, BitmapSerializeInvalidRowBytes_Bitmap) { TEST(StructTraitsTest, BitmapSerializeInvalidRowBytes_BitmapN32) {
BadRowBytes<skia::mojom::Bitmap>(); BadRowBytes<skia::mojom::BitmapN32>();
}
TEST(StructTraitsTest, BitmapSerializeInvalidRowBytes_BitmapWithArbitraryBpp) {
BadRowBytes<skia::mojom::BitmapWithArbitraryBpp>();
} }
TEST(StructTraitsTest, TEST(StructTraitsTest,
BitmapSerializeInvalidRowBytes_BitmapMappedFromTrustedProcess) { BitmapSerializeInvalidRowBytes_BitmapMappedFromTrustedProcess) {
...@@ -287,16 +326,31 @@ TEST(StructTraitsTest, BitmapSerializeInvalidRowBytes_InlineBitmap) { ...@@ -287,16 +326,31 @@ TEST(StructTraitsTest, BitmapSerializeInvalidRowBytes_InlineBitmap) {
} }
template <typename MojomType> template <typename MojomType>
static void BadColor() { static void BadColor(bool expect_crash) {
SkImageInfo info = SkImageInfo::MakeA8(10, 5); SkImageInfo info = SkImageInfo::MakeA8(10, 5);
SkBitmap input; SkBitmap input;
EXPECT_TRUE(input.tryAllocPixels(info)); EXPECT_TRUE(input.tryAllocPixels(info));
// This will crash. if (expect_crash) {
EXPECT_DEATH(MojomType::SerializeAsMessage(&input), ""); // This will crash.
EXPECT_DEATH(MojomType::SerializeAsMessage(&input), "");
} else {
// This won't as the mojom allows arbitrary color formats.
MojomType::SerializeAsMessage(&input);
}
} }
TEST(StructTraitsTest, InlineBitmapSerializeInvalidColorType_InlineBitmap) { TEST(StructTraitsTest, BitmapSerializeInvalidColorType_BitmapN32) {
BadColor<skia::mojom::InlineBitmap>(); BadColor<skia::mojom::BitmapN32>(/*expect_crash=*/true);
}
TEST(StructTraitsTest, BitmapSerializeInvalidColorType_BitmapWithArbitraryBpp) {
BadColor<skia::mojom::BitmapWithArbitraryBpp>(/*expect_crash=*/false);
}
TEST(StructTraitsTest,
BitmapSerializeInvalidColorType_BitmapMappedFromTrustedProcess) {
BadColor<skia::mojom::BitmapMappedFromTrustedProcess>(/*expect_crash=*/false);
}
TEST(StructTraitsTest, BitmapSerializeInvalidColorType_InlineBitmap) {
BadColor<skia::mojom::InlineBitmap>(/*expect_crash=*/true);
} }
// The row_bytes field is ignored, and the minRowBytes() is always used. // The row_bytes field is ignored, and the minRowBytes() is always used.
...@@ -306,10 +360,11 @@ TEST(StructTraitsTest, BitmapDeserializeIgnoresRowBytes) { ...@@ -306,10 +360,11 @@ TEST(StructTraitsTest, BitmapDeserializeIgnoresRowBytes) {
size_t ignored_row_bytes = 8; size_t ignored_row_bytes = 8;
size_t expected_row_bytes = 4; size_t expected_row_bytes = 4;
{ {
mojo::StructPtr<skia::mojom::Bitmap> input = ConstructBitmap( mojo::StructPtr<skia::mojom::BitmapWithArbitraryBpp> input =
SkImageInfo::MakeN32Premul(1, 1), ignored_row_bytes, {1, 2, 3, 4}); ConstructBitmapWithArbitraryBpp(SkImageInfo::MakeN32Premul(1, 1),
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<skia::mojom::Bitmap>( ignored_row_bytes, {1, 2, 3, 4});
input, output)); EXPECT_TRUE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapWithArbitraryBpp>(input, output));
EXPECT_EQ(expected_row_bytes, output.rowBytes()); EXPECT_EQ(expected_row_bytes, output.rowBytes());
} }
{ {
...@@ -321,7 +376,8 @@ TEST(StructTraitsTest, BitmapDeserializeIgnoresRowBytes) { ...@@ -321,7 +376,8 @@ TEST(StructTraitsTest, BitmapDeserializeIgnoresRowBytes) {
EXPECT_EQ(expected_row_bytes, output.rowBytes()); EXPECT_EQ(expected_row_bytes, output.rowBytes());
} }
{ {
// skia::mojom::InlineBitmap has no row_bytes field to test. // Neither skia::mojom::BitmapN32 nor skia::mojom::InlineBitmap have a
// row_bytes field to test.
} }
} }
...@@ -331,11 +387,17 @@ TEST(StructTraitsTest, InlineBitmapDeserializeTooFewBytes) { ...@@ -331,11 +387,17 @@ TEST(StructTraitsTest, InlineBitmapDeserializeTooFewBytes) {
std::vector<unsigned char> pixels = {1, 2, 3, 4}; std::vector<unsigned char> pixels = {1, 2, 3, 4};
SkBitmap output; SkBitmap output;
{ {
mojo::StructPtr<skia::mojom::Bitmap> input = mojo::StructPtr<skia::mojom::BitmapN32> input =
ConstructBitmap(info, 0, pixels); ConstructBitmapN32(info, pixels);
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<skia::mojom::Bitmap>( EXPECT_FALSE(mojo::test::SerializeAndDeserialize<skia::mojom::BitmapN32>(
input, output)); input, output));
} }
{
mojo::StructPtr<skia::mojom::BitmapWithArbitraryBpp> input =
ConstructBitmapWithArbitraryBpp(info, 0, pixels);
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapWithArbitraryBpp>(input, output));
}
{ {
mojo::StructPtr<skia::mojom::BitmapMappedFromTrustedProcess> input = mojo::StructPtr<skia::mojom::BitmapMappedFromTrustedProcess> input =
ConstructBitmapMappedFromTrustedProcess(info, 0, pixels); ConstructBitmapMappedFromTrustedProcess(info, 0, pixels);
...@@ -356,11 +418,17 @@ TEST(StructTraitsTest, InlineBitmapDeserializeTooManyBytes) { ...@@ -356,11 +418,17 @@ TEST(StructTraitsTest, InlineBitmapDeserializeTooManyBytes) {
std::vector<unsigned char> pixels = {1, 2, 3, 4, 5, 6, 7, 8}; std::vector<unsigned char> pixels = {1, 2, 3, 4, 5, 6, 7, 8};
SkBitmap output; SkBitmap output;
{ {
mojo::StructPtr<skia::mojom::Bitmap> input = mojo::StructPtr<skia::mojom::BitmapN32> input =
ConstructBitmap(info, 0, pixels); ConstructBitmapN32(info, pixels);
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<skia::mojom::Bitmap>( EXPECT_FALSE(mojo::test::SerializeAndDeserialize<skia::mojom::BitmapN32>(
input, output)); input, output));
} }
{
mojo::StructPtr<skia::mojom::BitmapWithArbitraryBpp> input =
ConstructBitmapWithArbitraryBpp(info, 0, pixels);
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapWithArbitraryBpp>(input, output));
}
{ {
mojo::StructPtr<skia::mojom::BitmapMappedFromTrustedProcess> input = mojo::StructPtr<skia::mojom::BitmapMappedFromTrustedProcess> input =
ConstructBitmapMappedFromTrustedProcess(info, 0, pixels); ConstructBitmapMappedFromTrustedProcess(info, 0, pixels);
......
...@@ -131,7 +131,7 @@ interface BackgroundFetchService { ...@@ -131,7 +131,7 @@ interface BackgroundFetchService {
string developer_id, string developer_id,
array<FetchAPIRequest> requests, array<FetchAPIRequest> requests,
BackgroundFetchOptions options, BackgroundFetchOptions options,
skia.mojom.Bitmap? icon, skia.mojom.BitmapWithArbitraryBpp? icon,
BackgroundFetchUkmData ukm_data) BackgroundFetchUkmData ukm_data)
=> (BackgroundFetchError error, => (BackgroundFetchError error,
BackgroundFetchRegistration? registration); BackgroundFetchRegistration? registration);
...@@ -157,7 +157,7 @@ interface BackgroundFetchService { ...@@ -157,7 +157,7 @@ interface BackgroundFetchService {
interface BackgroundFetchRegistrationService { interface BackgroundFetchRegistrationService {
// Updates the user interface for the Background Fetch registration. // Updates the user interface for the Background Fetch registration.
UpdateUI(string? title, UpdateUI(string? title,
skia.mojom.Bitmap? icon) skia.mojom.BitmapWithArbitraryBpp? icon)
=> (BackgroundFetchError error); => (BackgroundFetchError error);
// Aborts the Background Fetch registration. // Aborts the Background Fetch registration.
......
...@@ -59,7 +59,7 @@ interface ClipboardHost { ...@@ -59,7 +59,7 @@ interface ClipboardHost {
ReadRtf(ClipboardBuffer buffer) => (mojo_base.mojom.BigString result); ReadRtf(ClipboardBuffer buffer) => (mojo_base.mojom.BigString result);
[Sync] [Sync]
ReadImage(ClipboardBuffer buffer) => (skia.mojom.Bitmap? image); ReadImage(ClipboardBuffer buffer) => (skia.mojom.BitmapWithArbitraryBpp? image);
[Sync] [Sync]
ReadCustomData(ClipboardBuffer buffer, mojo_base.mojom.String16 type) => ReadCustomData(ClipboardBuffer buffer, mojo_base.mojom.String16 type) =>
...@@ -89,7 +89,7 @@ interface ClipboardHost { ...@@ -89,7 +89,7 @@ interface ClipboardHost {
WriteBookmark(string url, WriteBookmark(string url,
mojo_base.mojom.String16 title); mojo_base.mojom.String16 title);
WriteImage(skia.mojom.Bitmap image); WriteImage(skia.mojom.BitmapWithArbitraryBpp image);
CommitWrite(); CommitWrite();
......
...@@ -83,7 +83,7 @@ interface ContentIndexService { ...@@ -83,7 +83,7 @@ interface ContentIndexService {
Add(int64 service_worker_registration_id, Add(int64 service_worker_registration_id,
ContentDescription description, ContentDescription description,
array<skia.mojom.Bitmap> icon, array<skia.mojom.BitmapWithArbitraryBpp> icon,
url.mojom.Url launchUrl) url.mojom.Url launchUrl)
=> (ContentIndexError error); => (ContentIndexError error);
Delete(int64 service_worker_registration_id, string id) Delete(int64 service_worker_registration_id, string id)
......
...@@ -21,6 +21,6 @@ interface ImageDownloader { ...@@ -21,6 +21,6 @@ interface ImageDownloader {
uint32 max_bitmap_size, uint32 max_bitmap_size,
bool bypass_cache) bool bypass_cache)
=> (int32 http_status_code, => (int32 http_status_code,
array<skia.mojom.Bitmap> images, array<skia.mojom.BitmapWithArbitraryBpp> images,
array<gfx.mojom.Size> original_image_sizes); array<gfx.mojom.Size> original_image_sizes);
}; };
...@@ -30,7 +30,7 @@ struct TransferableMessage { ...@@ -30,7 +30,7 @@ struct TransferableMessage {
// Any ArrayBuffers being transferred as part of this message. // Any ArrayBuffers being transferred as part of this message.
array<SerializedArrayBufferContents> array_buffer_contents_array; array<SerializedArrayBufferContents> array_buffer_contents_array;
// Any ImageBitmaps being transferred as part of this message. // Any ImageBitmaps being transferred as part of this message.
array<skia.mojom.Bitmap> image_bitmap_contents_array; array<skia.mojom.BitmapWithArbitraryBpp> image_bitmap_contents_array;
// The user activation state, null if the frame isn't providing it. // The user activation state, null if the frame isn't providing it.
UserActivationSnapshot? user_activation; UserActivationSnapshot? user_activation;
}; };
...@@ -112,15 +112,15 @@ struct NotificationData { ...@@ -112,15 +112,15 @@ struct NotificationData {
// Structure representing the resources associated with a Web Notification. // Structure representing the resources associated with a Web Notification.
struct NotificationResources { struct NotificationResources {
// Image contents of the notification. May be empty if no image was specified. // Image contents of the notification. May be empty if no image was specified.
skia.mojom.Bitmap? image; skia.mojom.BitmapWithArbitraryBpp? image;
// Icon to be displayed with the notification. // Icon to be displayed with the notification.
skia.mojom.Bitmap? icon; skia.mojom.BitmapWithArbitraryBpp? icon;
// Badge representing the website displaying the notification. // Badge representing the website displaying the notification.
skia.mojom.Bitmap? badge; skia.mojom.BitmapWithArbitraryBpp? badge;
// Icons for the actions. The size of |action_icons| must match the size // Icons for the actions. The size of |action_icons| must match the size
// of |actions| in the corresponding NotificationData. // of |actions| in the corresponding NotificationData.
array<skia.mojom.Bitmap?>? action_icons; array<skia.mojom.BitmapWithArbitraryBpp?>? action_icons;
}; };
...@@ -190,7 +190,7 @@ interface FrameWidgetHost { ...@@ -190,7 +190,7 @@ interface FrameWidgetHost {
// session at the OS level. // session at the OS level.
StartDragging(DragData drag_data, StartDragging(DragData drag_data,
AllowedDragOperations operations_allowed, AllowedDragOperations operations_allowed,
skia.mojom.Bitmap? image, skia.mojom.BitmapWithArbitraryBpp? image,
gfx.mojom.Vector2d bitmap_offset_in_dip, gfx.mojom.Vector2d bitmap_offset_in_dip,
DragEventSourceInfo event_info); DragEventSourceInfo event_info);
}; };
......
...@@ -17,7 +17,7 @@ struct Cursor { ...@@ -17,7 +17,7 @@ struct Cursor {
gfx.mojom.Point hotspot; gfx.mojom.Point hotspot;
// The custom bitmap. Must be non-empty if |cursor_type| is kCustom. // The custom bitmap. Must be non-empty if |cursor_type| is kCustom.
skia.mojom.Bitmap? bitmap; skia.mojom.BitmapWithArbitraryBpp? bitmap;
// This is the image scale of this cursor. // This is the image scale of this cursor.
float image_scale_factor; float image_scale_factor;
......
...@@ -9,7 +9,7 @@ import "skia/public/mojom/bitmap.mojom"; ...@@ -9,7 +9,7 @@ import "skia/public/mojom/bitmap.mojom";
[Stable] [Stable]
struct ImageSkiaRep { struct ImageSkiaRep {
// Transport of the bitmap in this representation. // Transport of the bitmap in this representation.
skia.mojom.Bitmap bitmap; skia.mojom.BitmapWithArbitraryBpp bitmap;
// Corresponding scale of the bitmap or 0 if unscaled. // Corresponding scale of the bitmap or 0 if unscaled.
float scale; float scale;
......
...@@ -15,11 +15,10 @@ interface DeviceCursor { ...@@ -15,11 +15,10 @@ interface DeviceCursor {
// Sets the cursor |bitmaps| on |window| at |point| with // Sets the cursor |bitmaps| on |window| at |point| with
// |frame_delay_ms|. // |frame_delay_ms|.
SetCursor(gfx.mojom.AcceleratedWidget window, SetCursor(gfx.mojom.AcceleratedWidget window,
array<skia.mojom.Bitmap> bitmaps, array<skia.mojom.BitmapWithArbitraryBpp> bitmaps,
gfx.mojom.Point point, gfx.mojom.Point point,
int32 frame_delay_ms); int32 frame_delay_ms);
// Moves the cursor in |window| to |point|. // Moves the cursor in |window| to |point|.
MoveCursor(gfx.mojom.AcceleratedWidget window, gfx.mojom.Point point); MoveCursor(gfx.mojom.AcceleratedWidget window, gfx.mojom.Point point);
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment