Title: [248701] trunk/Tools
Revision
248701
Author
commit-qu...@webkit.org
Date
2019-08-14 18:17:30 -0700 (Wed, 14 Aug 2019)

Log Message

[iOS](REGRESSION: r200487): WebKit.RequestActivatedElementInfoForRotatedImage fails on iOS 13
https://bugs.webkit.org/show_bug.cgi?id=200726

Patch by Said Abou-Hallawa <sabouhall...@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):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (248700 => 248701)


--- trunk/Tools/ChangeLog	2019-08-15 00:54:50 UTC (rev 248700)
+++ trunk/Tools/ChangeLog	2019-08-15 01:17:30 UTC (rev 248701)
@@ -1,3 +1,17 @@
+2019-08-14  Said Abou-Hallawa  <sabouhall...@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  <ryanhad...@apple.com>
 
         Unreviewed, rolling out r248526.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm (248700 => 248701)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm	2019-08-15 00:54:50 UTC (rev 248700)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm	2019-08-15 01:17:30 UTC (rev 248701)
@@ -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 @@
 
     __block bool finished = false;
     [webView _requestActivatedElementAtPosition:CGPointMake(50, 50) completionBlock: ^(_WKActivatedElementInfo *elementInfo) {
-
-        auto image = elementInfo.image.CGImage;
-        auto data = ""
-        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 @@
         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;
     }];
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to