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 {
[EnableIf=is_chromeos]
GetThumbnail(ThumbParams params,
mojo_base.mojom.ReadOnlySharedMemoryRegion pdf_region)
=> (skia.mojom.Bitmap? bitmap);
=> (skia.mojom.BitmapWithArbitraryBpp? bitmap);
};
......@@ -56,7 +56,7 @@ struct GenerateQRCodeResponse {
// Image data for generated QR code. May be null on error, or if rendering
// was not requested.
skia.mojom.Bitmap? bitmap;
skia.mojom.BitmapWithArbitraryBpp? bitmap;
// QR Code data.
array<uint8> data;
......
......@@ -111,7 +111,7 @@ interface PaintPreviewCompositor {
BitmapForSeparatedFrame(mojo_base.mojom.UnguessableToken frame_guid,
gfx.mojom.Rect clip_rect,
float scale_factor) =>
(BitmapStatus status, skia.mojom.Bitmap? bitmap);
(BitmapStatus status, skia.mojom.BitmapWithArbitraryBpp? bitmap);
// Starts the compositing process for |BitmapForMainFrame| calls using frame
// data |request|. |status| will be negative on failure. If the root frame is
......@@ -127,7 +127,7 @@ interface PaintPreviewCompositor {
// |status|.
// |BeginMainFrameComposite| must be called before this method.
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.
SetRootFrameUrl(url.mojom.Url url);
......
......@@ -26,7 +26,7 @@ import org.chromium.mojo.bindings.MessageReceiver;
import org.chromium.mojo.system.Core;
import org.chromium.mojo.system.Pair;
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
......@@ -299,7 +299,7 @@ public class AppWebMessagePort implements MessagePort {
msg.message.nativeFileSystemTokens = new NativeFileSystemTransferToken[0];
msg.message.senderOrigin = null;
msg.arrayBufferContentsArray = new SerializedArrayBufferContents[0];
msg.imageBitmapContentsArray = new Bitmap[0];
msg.imageBitmapContentsArray = new BitmapWithArbitraryBpp[0];
msg.ports = ports;
msg.streamChannels = new MessagePortDescriptor[0];
mConnector.accept(msg.serializeWithHeader(mMojoCore, MESSAGE_HEADER));
......
......@@ -43,7 +43,7 @@ struct WebTestRendererDumpResult {
string? layout;
// Image dump.
skia.mojom.Bitmap? pixels;
skia.mojom.BitmapWithArbitraryBpp? pixels;
string actual_pixel_hash;
// Selection rect dump.
......
......@@ -111,7 +111,7 @@ enum XRInteractionMode {
};
struct XRTrackedImage {
skia.mojom.Bitmap bitmap;
skia.mojom.BitmapWithArbitraryBpp bitmap;
gfx.mojom.Size size_in_pixels;
float width_in_meters;
};
......
......@@ -28,11 +28,14 @@ int64_t kPadding = 64;
void ResizeImage(SkBitmap* decoded_image,
bool shrink_to_fit,
int64_t max_size_in_bytes) {
// When serialized, the space taken up by a skia::mojom::Bitmap excluding
// the pixel data payload should be:
// sizeof(skia::mojom::Bitmap::Data_) + pixel data array header (8 bytes)
// When serialized, the space taken up by a
// skia::mojom::BitmapWithArbitraryBpp excluding the pixel data payload should
// be:
// sizeof(skia::mojom::BitmapWithArbitraryBpp::Data_) +
// pixel data array header (8 bytes)
// 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();
int halves = 0;
while (struct_size + (image_size >> 2 * halves) > max_size_in_bytes)
......
......@@ -87,7 +87,7 @@ class BlinkInitializer : public blink::Platform {
blink::CreateMainThreadAndInitialize(this, &binders);
}
~BlinkInitializer() override {}
~BlinkInitializer() override = default;
private:
DISALLOW_COPY_AND_ASSIGN(BlinkInitializer);
......@@ -118,7 +118,7 @@ TEST_F(ImageDecoderImplTest, DecodeImageSizeLimit) {
// Approx max height for 3:2 image that will fit in the allotted space.
// 1.5 for width/height ratio, 4 for bytes/pixel.
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
int heights[] = {max_height_for_msg - 10, max_height_for_msg + 10,
......
......@@ -34,7 +34,7 @@ interface ImageDecoder {
DecodeImage(mojo_base.mojom.BigBuffer encoded_data, ImageCodec codec,
bool shrink_to_fit, int64 max_size_in_bytes,
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
// image and assumes it is an animation (instead of say, a multi-sized image).
......
......@@ -75,7 +75,8 @@ public class BarcodeDetectionImpl implements BarcodeDetection {
}
@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
// 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
......
......@@ -17,7 +17,8 @@ import java.nio.ByteBuffer;
* Utility class to convert a Bitmap to a GMS core YUV Frame.
*/
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;
int width = bitmapData.imageInfo.width;
int height = bitmapData.imageInfo.height;
......@@ -45,7 +46,7 @@ public class BitmapUtils {
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);
if (bitmap == null) {
return null;
......
......@@ -36,7 +36,8 @@ public class FaceDetectionImpl implements FaceDetection {
}
@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);
if (bitmap == null) {
Log.e(TAG, "Error converting Mojom Bitmap to Android Bitmap");
......
......@@ -59,7 +59,8 @@ public class FaceDetectionImplGmsCore implements FaceDetection {
}
@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
// on the device; this happens "fast", but it might have not completed,
// bail in this case.
......
......@@ -34,7 +34,8 @@ public class TextDetectionImpl implements TextDetection {
}
@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
// 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
......
......@@ -36,7 +36,7 @@ import java.util.concurrent.TimeUnit;
@Batch(Batch.UNIT_TESTS)
@UseRunnerDelegate(BaseJUnit4RunnerDelegate.class)
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");
private static final int[] SUPPORTED_FORMATS = {BarcodeFormat.AZTEC, BarcodeFormat.CODE_128,
......@@ -65,13 +65,14 @@ public class BarcodeDetectionImplTest {
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();
return detectWithOptions(mojoBitmap, options);
}
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));
BarcodeDetectorOptions options = new BarcodeDetectorOptions();
options.formats = new int[] {format};
......@@ -79,7 +80,8 @@ public class BarcodeDetectionImplTest {
}
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);
final ArrayBlockingQueue<BarcodeDetectionResult[]> queue = new ArrayBlockingQueue<>(1);
......@@ -169,7 +171,8 @@ public class BarcodeDetectionImplTest {
if (!TestUtils.IS_GMS_CORE_SUPPORTED) {
return;
}
org.chromium.skia.mojom.Bitmap bitmap = TestUtils.mojoBitmapFromFile(inputFile);
org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmap =
TestUtils.mojoBitmapFromFile(inputFile);
BarcodeDetectionResult[] results = detectWithHint(bitmap, format);
Assert.assertEquals(1, results.length);
Assert.assertEquals(value, results[0].rawValue);
......@@ -189,7 +192,8 @@ public class BarcodeDetectionImplTest {
if (!TestUtils.IS_GMS_CORE_SUPPORTED) {
return;
}
org.chromium.skia.mojom.Bitmap bitmap = TestUtils.mojoBitmapFromFile(inputFile);
org.chromium.skia.mojom.BitmapWithArbitraryBpp bitmap =
TestUtils.mojoBitmapFromFile(inputFile);
BarcodeDetectionResult[] results = detect(bitmap);
Assert.assertEquals(1, results.length);
Assert.assertEquals(value, results[0].rawValue);
......
......@@ -31,9 +31,9 @@ import java.util.concurrent.TimeUnit;
@RunWith(BaseJUnit4ClassRunner.class)
@Batch(Batch.UNIT_TESTS)
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");
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");
// Different versions of Android have different implementations of FaceDetector.findFaces(), so
// we have to use a large error threshold.
......@@ -44,8 +44,9 @@ public class FaceDetectionImplTest {
public FaceDetectionImplTest() {}
private static FaceDetectionResult[] detect(org.chromium.skia.mojom.Bitmap mojoBitmap,
boolean fastMode, DetectionProviderType api) {
private static FaceDetectionResult[] detect(
org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmap, boolean fastMode,
DetectionProviderType api) {
FaceDetectorOptions options = new FaceDetectorOptions();
options.fastMode = fastMode;
options.maxDetectedFaces = 32;
......@@ -112,7 +113,8 @@ public class FaceDetectionImplTest {
MONA_LISA_BITMAP.imageInfo.height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(paddedBitmap);
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);
FaceDetectionResult[] results = detect(mojoBitmap, true, DetectionProviderType.ANDROID);
......
......@@ -31,11 +31,13 @@ public class TestUtils {
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());
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.width = bitmap.getWidth();
mojoBitmap.imageInfo.height = bitmap.getHeight();
......@@ -45,13 +47,15 @@ public class TestUtils {
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);
Bitmap bitmap = BitmapFactory.decodeFile(path);
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 baseline = 100;
......
......@@ -30,10 +30,11 @@ public class TextDetectionImplTest {
"The quick brown fox jumped over the lazy dog.", "Helvetica Neue 36."};
private static final float[][] TEXT_BOUNDING_BOX = {
{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);
private static TextDetectionResult[] detect(org.chromium.skia.mojom.Bitmap mojoBitmap) {
private static TextDetectionResult[] detect(
org.chromium.skia.mojom.BitmapWithArbitraryBpp mojoBitmap) {
TextDetection detector = new TextDetectionImpl();
final ArrayBlockingQueue<TextDetectionResult[]> queue = new ArrayBlockingQueue<>(1);
......
......@@ -16,7 +16,7 @@ import org.robolectric.shadows.ShadowLog;
import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.base.test.util.Feature;
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.ImageInfo;
......@@ -46,7 +46,7 @@ public class BitmapUtilsTest {
@Test
@Feature({"ShapeDetection"})
public void testConversionFailsWithInvalidBitmap() {
Bitmap bitmap = new Bitmap();
BitmapWithArbitraryBpp bitmap = new BitmapWithArbitraryBpp();
bitmap.pixelData = null;
bitmap.imageInfo = new ImageInfo();
......@@ -59,7 +59,7 @@ public class BitmapUtilsTest {
@Test
@Feature({"ShapeDetection"})
public void testConversionFailsWithInvalidDimensions() {
Bitmap bitmap = new Bitmap();
BitmapWithArbitraryBpp bitmap = new BitmapWithArbitraryBpp();
bitmap.imageInfo = new ImageInfo();
bitmap.pixelData = BigBufferUtil.createBigBufferFromBytes(EMPTY_DATA);
bitmap.imageInfo.width = INVALID_WIDTH;
......@@ -74,7 +74,7 @@ public class BitmapUtilsTest {
@Test
@Feature({"ShapeDetection"})
public void testConversionFailsWithWronglyWrappedData() {
Bitmap bitmap = new Bitmap();
BitmapWithArbitraryBpp bitmap = new BitmapWithArbitraryBpp();
bitmap.imageInfo = new ImageInfo();
bitmap.pixelData = BigBufferUtil.createBigBufferFromBytes(EMPTY_DATA);
bitmap.imageInfo.width = VALID_WIDTH;
......
......@@ -38,6 +38,6 @@ struct BarcodeDetectionResult {
interface BarcodeDetection {
// |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);
};
......@@ -33,6 +33,6 @@ struct FaceDetectorOptions {
interface FaceDetection {
// |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);
};
......@@ -17,6 +17,6 @@ struct TextDetectionResult {
interface TextDetection {
// |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);
};
......@@ -153,7 +153,8 @@ interface FrameSinkVideoCaptureOverlay {
// 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
// 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
// non-empty bounds are provided, and hiding the overlay otherwise. |bounds|
......
......@@ -53,7 +53,17 @@ mojom("mojom") {
{
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"
nullable_is_same_type = true
},
......
......@@ -8,8 +8,21 @@ module skia.mojom;
import "mojo/public/mojom/base/big_buffer.mojom";
import "skia/public/mojom/image_info.mojom";
[Stable]
struct Bitmap {
// The most common way to transfer an SkBitmap over IPC. This struct enforces
// 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;
uint64 UNUSED_row_bytes;
mojo_base.mojom.BigBuffer pixel_data;
......
......@@ -66,7 +66,7 @@ bool CreateSkBitmapForPixelData(SkBitmap* b,
} // namespace
// static
mojo_base::BigBufferView StructTraits<skia::mojom::BitmapDataView,
mojo_base::BigBufferView StructTraits<skia::mojom::BitmapN32DataView,
SkBitmap>::pixel_data(const SkBitmap& b) {
CHECK_EQ(b.rowBytes(), b.info().minRowBytes());
return mojo_base::BigBufferView(base::make_span(
......@@ -74,8 +74,33 @@ mojo_base::BigBufferView StructTraits<skia::mojom::BitmapDataView,
}
// static
bool StructTraits<skia::mojom::BitmapDataView, SkBitmap>::Read(
skia::mojom::BitmapDataView data,
bool StructTraits<skia::mojom::BitmapN32DataView, SkBitmap>::Read(
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) {
SkImageInfo image_info;
if (!data.ReadImageInfo(&image_info))
......
......@@ -16,10 +16,23 @@
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 <>
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 void SetToNull(SkBitmap* b) { b->reset(); }
......@@ -27,7 +40,8 @@ struct COMPONENT_EXPORT(SKIA_SHARED_TRAITS)
static uint64_t UNUSED_row_bytes(const SkBitmap& b) { return 0; }
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 <>
......
......@@ -22,13 +22,24 @@
namespace skia {
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.
mojo::StructPtr<skia::mojom::Bitmap> ConstructBitmap(
mojo::StructPtr<skia::mojom::BitmapN32> ConstructBitmapN32(
SkImageInfo info,
int row_bytes,
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->UNUSED_row_bytes = row_bytes;
mojom_bitmap->pixel_data = std::move(pixels);
......@@ -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));
BitmapsEqual(input, output);
}
{
ASSERT_TRUE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapWithArbitraryBpp>(input, output));
BitmapsEqual(input, output);
}
{
ASSERT_TRUE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapMappedFromTrustedProcess>(input, output));
......@@ -161,10 +177,15 @@ TEST(StructTraitsTest, BitmapNull) {
SkBitmap output;
{
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<skia::mojom::Bitmap>(
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<skia::mojom::BitmapN32>(
input, output));
IsDefaultInit(output);
}
{
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapWithArbitraryBpp>(input, output));
IsDefaultInit(output);
}
{
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapMappedFromTrustedProcess>(input, output));
......@@ -199,11 +220,18 @@ TEST(StructTraitsTest, VerifyMojomConstruction) {
SkBitmap output;
{
mojo::StructPtr<skia::mojom::Bitmap> input =
ConstructBitmap(SkImageInfo::MakeN32Premul(1, 1), 0, {1, 2, 3, 4});
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<skia::mojom::Bitmap>(
mojo::StructPtr<skia::mojom::BitmapN32> input =
ConstructBitmapN32(SkImageInfo::MakeN32Premul(1, 1), {1, 2, 3, 4});
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<skia::mojom::BitmapN32>(
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 =
ConstructBitmapMappedFromTrustedProcess(
......@@ -228,9 +256,13 @@ TEST(StructTraitsTest, BitmapTooWideToSerialize) {
input.eraseColor(SK_ColorYELLOW);
SkBitmap output;
{
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<skia::mojom::Bitmap>(
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<skia::mojom::BitmapN32>(
input, output));
}
{
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapWithArbitraryBpp>(input, output));
}
{
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapMappedFromTrustedProcess>(input, output));
......@@ -250,9 +282,13 @@ TEST(StructTraitsTest, BitmapTooTallToSerialize) {
input.eraseColor(SK_ColorYELLOW);
SkBitmap output;
{
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<skia::mojom::Bitmap>(
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<skia::mojom::BitmapN32>(
input, output));
}
{
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapWithArbitraryBpp>(input, output));
}
{
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapMappedFromTrustedProcess>(input, output));
......@@ -275,8 +311,11 @@ static void BadRowBytes() {
}
// We do not allow sending rowBytes() other than the minRowBytes().
TEST(StructTraitsTest, BitmapSerializeInvalidRowBytes_Bitmap) {
BadRowBytes<skia::mojom::Bitmap>();
TEST(StructTraitsTest, BitmapSerializeInvalidRowBytes_BitmapN32) {
BadRowBytes<skia::mojom::BitmapN32>();
}
TEST(StructTraitsTest, BitmapSerializeInvalidRowBytes_BitmapWithArbitraryBpp) {
BadRowBytes<skia::mojom::BitmapWithArbitraryBpp>();
}
TEST(StructTraitsTest,
BitmapSerializeInvalidRowBytes_BitmapMappedFromTrustedProcess) {
......@@ -287,16 +326,31 @@ TEST(StructTraitsTest, BitmapSerializeInvalidRowBytes_InlineBitmap) {
}
template <typename MojomType>
static void BadColor() {
static void BadColor(bool expect_crash) {
SkImageInfo info = SkImageInfo::MakeA8(10, 5);
SkBitmap input;
EXPECT_TRUE(input.tryAllocPixels(info));
// This will crash.
EXPECT_DEATH(MojomType::SerializeAsMessage(&input), "");
if (expect_crash) {
// 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) {
BadColor<skia::mojom::InlineBitmap>();
TEST(StructTraitsTest, BitmapSerializeInvalidColorType_BitmapN32) {
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.
......@@ -306,10 +360,11 @@ TEST(StructTraitsTest, BitmapDeserializeIgnoresRowBytes) {
size_t ignored_row_bytes = 8;
size_t expected_row_bytes = 4;
{
mojo::StructPtr<skia::mojom::Bitmap> input = ConstructBitmap(
SkImageInfo::MakeN32Premul(1, 1), ignored_row_bytes, {1, 2, 3, 4});
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<skia::mojom::Bitmap>(
input, output));
mojo::StructPtr<skia::mojom::BitmapWithArbitraryBpp> input =
ConstructBitmapWithArbitraryBpp(SkImageInfo::MakeN32Premul(1, 1),
ignored_row_bytes, {1, 2, 3, 4});
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<
skia::mojom::BitmapWithArbitraryBpp>(input, output));
EXPECT_EQ(expected_row_bytes, output.rowBytes());
}
{
......@@ -321,7 +376,8 @@ TEST(StructTraitsTest, BitmapDeserializeIgnoresRowBytes) {
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) {
std::vector<unsigned char> pixels = {1, 2, 3, 4};
SkBitmap output;
{
mojo::StructPtr<skia::mojom::Bitmap> input =
ConstructBitmap(info, 0, pixels);
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<skia::mojom::Bitmap>(
mojo::StructPtr<skia::mojom::BitmapN32> input =
ConstructBitmapN32(info, pixels);
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<skia::mojom::BitmapN32>(
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 =
ConstructBitmapMappedFromTrustedProcess(info, 0, pixels);
......@@ -356,11 +418,17 @@ TEST(StructTraitsTest, InlineBitmapDeserializeTooManyBytes) {
std::vector<unsigned char> pixels = {1, 2, 3, 4, 5, 6, 7, 8};
SkBitmap output;
{
mojo::StructPtr<skia::mojom::Bitmap> input =
ConstructBitmap(info, 0, pixels);
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<skia::mojom::Bitmap>(
mojo::StructPtr<skia::mojom::BitmapN32> input =
ConstructBitmapN32(info, pixels);
EXPECT_FALSE(mojo::test::SerializeAndDeserialize<skia::mojom::BitmapN32>(
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 =
ConstructBitmapMappedFromTrustedProcess(info, 0, pixels);
......
......@@ -131,7 +131,7 @@ interface BackgroundFetchService {
string developer_id,
array<FetchAPIRequest> requests,
BackgroundFetchOptions options,
skia.mojom.Bitmap? icon,
skia.mojom.BitmapWithArbitraryBpp? icon,
BackgroundFetchUkmData ukm_data)
=> (BackgroundFetchError error,
BackgroundFetchRegistration? registration);
......@@ -157,7 +157,7 @@ interface BackgroundFetchService {
interface BackgroundFetchRegistrationService {
// Updates the user interface for the Background Fetch registration.
UpdateUI(string? title,
skia.mojom.Bitmap? icon)
skia.mojom.BitmapWithArbitraryBpp? icon)
=> (BackgroundFetchError error);
// Aborts the Background Fetch registration.
......
......@@ -59,7 +59,7 @@ interface ClipboardHost {
ReadRtf(ClipboardBuffer buffer) => (mojo_base.mojom.BigString result);
[Sync]
ReadImage(ClipboardBuffer buffer) => (skia.mojom.Bitmap? image);
ReadImage(ClipboardBuffer buffer) => (skia.mojom.BitmapWithArbitraryBpp? image);
[Sync]
ReadCustomData(ClipboardBuffer buffer, mojo_base.mojom.String16 type) =>
......@@ -89,7 +89,7 @@ interface ClipboardHost {
WriteBookmark(string url,
mojo_base.mojom.String16 title);
WriteImage(skia.mojom.Bitmap image);
WriteImage(skia.mojom.BitmapWithArbitraryBpp image);
CommitWrite();
......
......@@ -83,7 +83,7 @@ interface ContentIndexService {
Add(int64 service_worker_registration_id,
ContentDescription description,
array<skia.mojom.Bitmap> icon,
array<skia.mojom.BitmapWithArbitraryBpp> icon,
url.mojom.Url launchUrl)
=> (ContentIndexError error);
Delete(int64 service_worker_registration_id, string id)
......
......@@ -21,6 +21,6 @@ interface ImageDownloader {
uint32 max_bitmap_size,
bool bypass_cache)
=> (int32 http_status_code,
array<skia.mojom.Bitmap> images,
array<skia.mojom.BitmapWithArbitraryBpp> images,
array<gfx.mojom.Size> original_image_sizes);
};
......@@ -30,7 +30,7 @@ struct TransferableMessage {
// Any ArrayBuffers being transferred as part of this message.
array<SerializedArrayBufferContents> array_buffer_contents_array;
// 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.
UserActivationSnapshot? user_activation;
};
......@@ -112,15 +112,15 @@ struct NotificationData {
// Structure representing the resources associated with a Web Notification.
struct NotificationResources {
// 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.
skia.mojom.Bitmap? icon;
skia.mojom.BitmapWithArbitraryBpp? icon;
// 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
// of |actions| in the corresponding NotificationData.
array<skia.mojom.Bitmap?>? action_icons;
array<skia.mojom.BitmapWithArbitraryBpp?>? action_icons;
};
......@@ -190,7 +190,7 @@ interface FrameWidgetHost {
// session at the OS level.
StartDragging(DragData drag_data,
AllowedDragOperations operations_allowed,
skia.mojom.Bitmap? image,
skia.mojom.BitmapWithArbitraryBpp? image,
gfx.mojom.Vector2d bitmap_offset_in_dip,
DragEventSourceInfo event_info);
};
......
......@@ -17,7 +17,7 @@ struct Cursor {
gfx.mojom.Point hotspot;
// 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.
float image_scale_factor;
......
......@@ -9,7 +9,7 @@ import "skia/public/mojom/bitmap.mojom";
[Stable]
struct ImageSkiaRep {
// Transport of the bitmap in this representation.
skia.mojom.Bitmap bitmap;
skia.mojom.BitmapWithArbitraryBpp bitmap;
// Corresponding scale of the bitmap or 0 if unscaled.
float scale;
......
......@@ -15,11 +15,10 @@ interface DeviceCursor {
// Sets the cursor |bitmaps| on |window| at |point| with
// |frame_delay_ms|.
SetCursor(gfx.mojom.AcceleratedWidget window,
array<skia.mojom.Bitmap> bitmaps,
array<skia.mojom.BitmapWithArbitraryBpp> bitmaps,
gfx.mojom.Point point,
int32 frame_delay_ms);
// Moves the cursor in |window| to |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