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

Unified Diff: services/shape_detection/detection_utils_mac.mm

Issue 2755393002: Revert of RELAND: ShapeDetection: use mojom::Bitmap for mojo interface. (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « services/shape_detection/detection_utils_mac.h ('k') | services/shape_detection/face_detection_impl_mac.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/shape_detection/detection_utils_mac.mm
diff --git a/services/shape_detection/detection_utils_mac.mm b/services/shape_detection/detection_utils_mac.mm
index 554cd7e5c804f984ae22d38609e3149146a14d40..4e87812e99854b24dd7251094ea93cb405a134ac 100644
--- a/services/shape_detection/detection_utils_mac.mm
+++ b/services/shape_detection/detection_utils_mac.mm
@@ -9,31 +9,61 @@
#include "base/memory/shared_memory.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "services/shape_detection/barcode_detection_impl.h"
-#include "skia/ext/skia_utils_mac.h"
-#include "third_party/skia/include/utils/mac/SkCGUtils.h"
namespace shape_detection {
-base::scoped_nsobject<CIImage> CreateCIImageFromSkBitmap(
- const SkBitmap& bitmap) {
+// These formats are available but not public until Mac 10.11.
+#if !defined(MAC_OS_X_VERSION_10_11) || \
+ MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_11
+const int kCIFormatRGBA8 = 24;
+#else
+//static_assert(kCIFormatRGBA8 == 24, "RGBA8 format enum index.");
+#endif
+
+base::scoped_nsobject<CIImage> CreateCIImageFromSharedMemory(
+ mojo::ScopedSharedBufferHandle frame_data,
+ uint32_t width,
+ uint32_t height) {
base::CheckedNumeric<uint32_t> num_pixels =
- base::CheckedNumeric<uint32_t>(bitmap.width()) * bitmap.height();
+ base::CheckedNumeric<uint32_t>(width) * height;
base::CheckedNumeric<uint32_t> num_bytes = num_pixels * 4;
if (!num_bytes.IsValid()) {
DLOG(ERROR) << "Data overflow";
return base::scoped_nsobject<CIImage>();
}
- // First convert SkBitmap to CGImageRef.
- base::ScopedCFTypeRef<CGImageRef> cg_image(
- SkCreateCGImageRefWithColorspace(bitmap, NULL));
- if (!cg_image) {
- DLOG(ERROR) << "Failed to create CGImageRef";
+ base::SharedMemoryHandle memory_handle;
+ size_t memory_size = 0;
+ bool read_only_flag = false;
+ const MojoResult result = mojo::UnwrapSharedMemoryHandle(
+ std::move(frame_data), &memory_handle, &memory_size, &read_only_flag);
+ DCHECK_EQ(MOJO_RESULT_OK, result) << "Failed to unwrap SharedBufferHandle";
+ if (!memory_size || memory_size != num_bytes.ValueOrDie()) {
+ DLOG(ERROR) << "Invalid image size";
return base::scoped_nsobject<CIImage>();
}
- base::scoped_nsobject<CIImage> ci_image(
- [[CIImage alloc] initWithCGImage:cg_image]);
+ auto shared_memory =
+ base::MakeUnique<base::SharedMemory>(memory_handle, true /* read_only */);
+ if (!shared_memory->Map(memory_size)) {
+ DLOG(ERROR) << "Failed to map bytes from shared memory";
+ return base::scoped_nsobject<CIImage>();
+ }
+
+ NSData* byte_data = [NSData dataWithBytesNoCopy:shared_memory->memory()
+ length:num_bytes.ValueOrDie()
+ freeWhenDone:NO];
+
+ base::ScopedCFTypeRef<CGColorSpaceRef> colorspace(
+ CGColorSpaceCreateWithName(kCGColorSpaceSRGB));
+
+ // CIImage will return nil if RGBA8 is not supported in a certain version.
+ base::scoped_nsobject<CIImage> ci_image([[CIImage alloc]
+ initWithBitmapData:byte_data
+ bytesPerRow:width * 4
+ size:CGSizeMake(width, height)
+ format:kCIFormatRGBA8
+ colorSpace:colorspace]);
if (!ci_image) {
DLOG(ERROR) << "Failed to create CIImage";
return base::scoped_nsobject<CIImage>();
« no previous file with comments | « services/shape_detection/detection_utils_mac.h ('k') | services/shape_detection/face_detection_impl_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698