Commit e159182e authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Add function to create image with size, color and scale.

Some tests needs to create an image with a given scale, so add
a function with a scale parameter.

Bug: 795669
Change-Id: Ibdc6863a247c2035cbbd5fed64c5b0954cbb2327
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Reviewed-on: https://chromium-review.googlesource.com/831514Reviewed-by: default avatarElodie Banel <lod@chromium.org>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524671}
parent 79cf4d47
...@@ -11,9 +11,17 @@ namespace ui { ...@@ -11,9 +11,17 @@ namespace ui {
namespace test { namespace test {
namespace uiimage_utils { namespace uiimage_utils {
// Returns a new UIImage of size |size| with a solid color of |color|. // Returns a new UIImage of size |size| with a solid color of |color|. This
// is the same as calling UIImageWithSizeAndSolidColorAndScale with a scale
// of 1.0.
UIImage* UIImageWithSizeAndSolidColor(CGSize const& size, UIColor* color); UIImage* UIImageWithSizeAndSolidColor(CGSize const& size, UIColor* color);
// Returns a new UIImage of size |size| with a solid color of |color|
// at scale |scale|.
UIImage* UIImageWithSizeAndSolidColorAndScale(CGSize const& size,
UIColor* color,
CGFloat scale);
// Disclaimer, this is a testing function with plenty of limitations: // Disclaimer, this is a testing function with plenty of limitations:
// Requires the UIImages to be backed by a CGImage, ignores colorspace, may // Requires the UIImages to be backed by a CGImage, ignores colorspace, may
// return false negatives, not efficient, and probably other things. // return false negatives, not efficient, and probably other things.
......
...@@ -11,7 +11,13 @@ namespace test { ...@@ -11,7 +11,13 @@ namespace test {
namespace uiimage_utils { namespace uiimage_utils {
UIImage* UIImageWithSizeAndSolidColor(CGSize const& size, UIColor* color) { UIImage* UIImageWithSizeAndSolidColor(CGSize const& size, UIColor* color) {
UIGraphicsBeginImageContext(size); return UIImageWithSizeAndSolidColorAndScale(size, color, /*scale=*/1.0);
}
UIImage* UIImageWithSizeAndSolidColorAndScale(CGSize const& size,
UIColor* color,
CGFloat scale) {
UIGraphicsBeginImageContextWithOptions(size, /*opaque=*/YES, scale);
CGContextRef context = UIGraphicsGetCurrentContext(); CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]); CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, CGRectMake(0, 0, size.width, size.height)); CGContextFillRect(context, CGRectMake(0, 0, size.width, size.height));
......
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