[iOS](REGRESSION: r200487): WebKit.RequestActivatedElementInfoForRotatedImage fails...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Aug 2019 01:17:30 +0000 (01:17 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Aug 2019 01:17:30 +0000 (01:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200726

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2019-08-14
Reviewed by Simon Fraser.

To get the pixels as an array of colors, draw the image into a memory
context. The backing memory buffer can then be accessed to get the image
pixels' colors.

* TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm:
(TestWebKitAPI::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248701 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm

index c8bfba2..2a59a72 100644 (file)
@@ -1,3 +1,17 @@
+2019-08-14  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        [iOS](REGRESSION: r200487): WebKit.RequestActivatedElementInfoForRotatedImage fails on iOS 13
+        https://bugs.webkit.org/show_bug.cgi?id=200726
+
+        Reviewed by Simon Fraser.
+
+        To get the pixels as an array of colors, draw the image into a memory
+        context. The backing memory buffer can then be accessed to get the image
+        pixels' colors.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm:
+        (TestWebKitAPI::TEST):
+
 2019-08-14  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r248526.
index 556a5a9..a463a83 100644 (file)
@@ -33,6 +33,7 @@
 #import <WebKit/WKWebViewConfigurationPrivate.h>
 #import <WebKit/_WKActivatedElementInfo.h>
 #import <wtf/RetainPtr.h>
+#import <wtf/Vector.h>
 
 #if PLATFORM(IOS_FAMILY)
 
@@ -107,21 +108,34 @@ TEST(WebKit, RequestActivatedElementInfoForRotatedImage)
 
     __block bool finished = false;
     [webView _requestActivatedElementAtPosition:CGPointMake(50, 50) completionBlock: ^(_WKActivatedElementInfo *elementInfo) {
-
-        auto image = elementInfo.image.CGImage;
-        auto data = adoptCF(CGDataProviderCopyData(CGImageGetDataProvider(image)));
-        auto buffer = reinterpret_cast<const unsigned*>(CFDataGetBytePtr(data.get()));
-
-        auto pixelAt = [&](unsigned x, unsigned y) {
-            unsigned i = y * elementInfo.image.size.width + x;
-            return buffer[i];
-        };
-        
         static const unsigned yellow = 0xFFFFFF00;
         static const unsigned red = 0xFFF51900;
         static const unsigned green = 0xFF278000;
         static const unsigned blue = 0xFF0000FF;
 
+        auto imagePixels = [](CGImageRef image) -> Vector<unsigned> {
+            static const size_t bytesPerPixel = 4;
+            static const size_t bitsPerComponent = 8;
+            size_t width = CGImageGetWidth(image);
+            size_t height = CGImageGetHeight(image);
+            size_t bytesPerRow = bytesPerPixel * width;
+
+            static_assert(bytesPerPixel == sizeof(unsigned));
+            Vector<unsigned> pixels(height * width);
+
+            RetainPtr<CGColorSpaceRef> colorSpace = adoptCF(CGColorSpaceCreateDeviceRGB());
+            RetainPtr<CGContextRef> context = adoptCF(CGBitmapContextCreate(pixels.data(), width, height, bitsPerComponent, bytesPerRow, colorSpace.get(), kCGImageAlphaPremultipliedFirst | kCGImageByteOrder32Little));
+
+            CGContextDrawImage(context.get(), CGRectMake(0, 0, width, height), image);
+            return pixels;
+        };
+
+        auto indexOf = [&](unsigned x, unsigned y) -> unsigned {
+            return y * elementInfo.image.size.width + x;
+        };
+
+        auto pixels = imagePixels(elementInfo.image.CGImage);
+
         EXPECT_TRUE(elementInfo.type == _WKActivatedElementTypeImage);
         EXPECT_WK_STREQ(elementInfo.imageURL.lastPathComponent, "exif-orientation-8-llo.jpg");
         EXPECT_NOT_NULL(elementInfo.image);
@@ -130,10 +144,10 @@ TEST(WebKit, RequestActivatedElementInfoForRotatedImage)
         EXPECT_EQ(elementInfo.image.size.width, 50);
         EXPECT_EQ(elementInfo.image.size.height, 100);
 
-        EXPECT_EQ(pixelAt(0, 0), yellow);
-        EXPECT_EQ(pixelAt(elementInfo.image.size.width - 1, 0), red);
-        EXPECT_EQ(pixelAt(0, elementInfo.image.size.height - 1), green);
-        EXPECT_EQ(pixelAt(elementInfo.image.size.width - 1, elementInfo.image.size.height - 1), blue);
+        EXPECT_EQ(pixels[indexOf(0, 0)], yellow);
+        EXPECT_EQ(pixels[indexOf(elementInfo.image.size.width - 1, 0)], red);
+        EXPECT_EQ(pixels[indexOf(0, elementInfo.image.size.height - 1)], green);
+        EXPECT_EQ(pixels[indexOf(elementInfo.image.size.width - 1, elementInfo.image.size.height - 1)], blue);
 
         finished = true;
     }];