Commit a94dd8da authored by Robert Sesek's avatar Robert Sesek Committed by Chromium LUCI CQ

mac: Remove code to support OS X 10.10 in //services/shape_detection

Bug: 1153883
Change-Id: Ic1e2dc39b96c2c5ed1e80c4732e1a2dcee02b675
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2571801Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Robert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833422}
parent 08e07eab
......@@ -18,7 +18,7 @@
namespace shape_detection {
class API_AVAILABLE(macosx(10.10)) BarcodeDetectionImplMac
class BarcodeDetectionImplMac
: public shape_detection::mojom::BarcodeDetection {
public:
BarcodeDetectionImplMac();
......
......@@ -120,11 +120,6 @@ TEST_P(BarcodeDetectionImplMacTest, ScanOneBarcode) {
}
impl_ = GetParam().factory.Run(mojom::BarcodeDetectorOptions::New());
if (!impl_) {
LOG(WARNING) << "Barcode Detection is not supported before Mac OSX 10.10."
<< "Skipping test.";
return;
}
// Generate a barcode image as a CIImage by using |qr_code_generator|.
NSData* const qr_code_data =
......
......@@ -4,7 +4,6 @@
#include "services/shape_detection/text_detection_impl_mac.h"
#include "base/mac/mac_util.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/strings/sys_string_conversions.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
......@@ -17,11 +16,8 @@ namespace shape_detection {
// static
void TextDetectionImpl::Create(
mojo::PendingReceiver<mojom::TextDetection> receiver) {
// Text detection needs at least MAC OS X 10.11.
if (@available(macOS 10.11, *)) {
mojo::MakeSelfOwnedReceiver(std::make_unique<TextDetectionImplMac>(),
std::move(receiver));
}
mojo::MakeSelfOwnedReceiver(std::make_unique<TextDetectionImplMac>(),
std::move(receiver));
}
TextDetectionImplMac::TextDetectionImplMac() {
......@@ -35,8 +31,6 @@ TextDetectionImplMac::~TextDetectionImplMac() {}
void TextDetectionImplMac::Detect(const SkBitmap& bitmap,
DetectCallback callback) {
DCHECK(base::mac::IsAtLeastOS10_11());
base::scoped_nsobject<CIImage> ci_image = CreateCIImageFromSkBitmap(bitmap);
if (!ci_image) {
std::move(callback).Run({});
......
......@@ -41,64 +41,61 @@ TEST_F(TextDetectionImplMacTest, CreateAndDestroy) {}
// This test generates an image with a single text line and scans it back.
TEST_F(TextDetectionImplMacTest, ScanOnce) {
// Text detection needs at least MAC OS X 10.11, and GPU infrastructure.
// Text detection needs GPU infrastructure.
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kUseGpuInTests) ||
!base::mac::IsAtLeastOS10_11()) {
switches::kUseGpuInTests)) {
return;
}
if (@available(macOS 10.11, *)) {
impl_.reset(new TextDetectionImplMac);
base::ScopedCFTypeRef<CGColorSpaceRef> rgb_colorspace(
CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB));
const int width = 200;
const int height = 50;
base::ScopedCFTypeRef<CGContextRef> context(CGBitmapContextCreate(
nullptr, width, height, 8 /* bitsPerComponent */,
width * 4 /* rowBytes */, rgb_colorspace,
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));
// Draw a white background.
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextFillRect(context, CGRectMake(0.0, 0.0, width, height));
// Create a line of Helvetica 16 text, and draw it in the |context|.
base::scoped_nsobject<NSFont> helvetica(
[NSFont fontWithName:@"Helvetica" size:16]);
NSDictionary* attributes = [NSDictionary
dictionaryWithObjectsAndKeys:helvetica, kCTFontAttributeName, nil];
base::scoped_nsobject<NSAttributedString> info([[NSAttributedString alloc]
initWithString:@"https://www.chromium.org"
attributes:attributes]);
base::ScopedCFTypeRef<CTLineRef> line(
CTLineCreateWithAttributedString((CFAttributedStringRef)info.get()));
CGContextSetTextPosition(context, 10.0, height / 2.0);
CTLineDraw(line, context);
// Extract a CGImage and its raw pixels from |context|.
base::ScopedCFTypeRef<CGImageRef> cg_image(
CGBitmapContextCreateImage(context));
EXPECT_EQ(static_cast<size_t>(width), CGImageGetWidth(cg_image));
EXPECT_EQ(static_cast<size_t>(height), CGImageGetHeight(cg_image));
SkBitmap bitmap;
ASSERT_TRUE(SkCreateBitmapFromCGImage(&bitmap, cg_image));
base::RunLoop run_loop;
// Send the image to Detect() and expect the response in callback.
EXPECT_CALL(*this, Detection(1))
.WillOnce(RunOnceClosure(run_loop.QuitClosure()));
impl_->Detect(bitmap,
base::BindOnce(&TextDetectionImplMacTest::DetectCallback,
base::Unretained(this)));
run_loop.Run();
}
impl_.reset(new TextDetectionImplMac);
base::ScopedCFTypeRef<CGColorSpaceRef> rgb_colorspace(
CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB));
const int width = 200;
const int height = 50;
base::ScopedCFTypeRef<CGContextRef> context(CGBitmapContextCreate(
nullptr, width, height, 8 /* bitsPerComponent */,
width * 4 /* rowBytes */, rgb_colorspace,
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));
// Draw a white background.
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextFillRect(context, CGRectMake(0.0, 0.0, width, height));
// Create a line of Helvetica 16 text, and draw it in the |context|.
base::scoped_nsobject<NSFont> helvetica([NSFont fontWithName:@"Helvetica"
size:16]);
NSDictionary* attributes = [NSDictionary
dictionaryWithObjectsAndKeys:helvetica, kCTFontAttributeName, nil];
base::scoped_nsobject<NSAttributedString> info([[NSAttributedString alloc]
initWithString:@"https://www.chromium.org"
attributes:attributes]);
base::ScopedCFTypeRef<CTLineRef> line(
CTLineCreateWithAttributedString((CFAttributedStringRef)info.get()));
CGContextSetTextPosition(context, 10.0, height / 2.0);
CTLineDraw(line, context);
// Extract a CGImage and its raw pixels from |context|.
base::ScopedCFTypeRef<CGImageRef> cg_image(
CGBitmapContextCreateImage(context));
EXPECT_EQ(static_cast<size_t>(width), CGImageGetWidth(cg_image));
EXPECT_EQ(static_cast<size_t>(height), CGImageGetHeight(cg_image));
SkBitmap bitmap;
ASSERT_TRUE(SkCreateBitmapFromCGImage(&bitmap, cg_image));
base::RunLoop run_loop;
// Send the image to Detect() and expect the response in callback.
EXPECT_CALL(*this, Detection(1))
.WillOnce(RunOnceClosure(run_loop.QuitClosure()));
impl_->Detect(bitmap,
base::BindOnce(&TextDetectionImplMacTest::DetectCallback,
base::Unretained(this)));
run_loop.Run();
}
} // shape_detection namespace
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