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

Side by Side Diff: ui/gfx/image/image_unittest_util_ios.mm

Issue 2945213002: [ios] Snapshot for WebState (Closed)
Patch Set: Address comments. Created 3 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <CoreGraphics/CoreGraphics.h> 5 #import <CoreGraphics/CoreGraphics.h>
6 #import <UIKit/UIKit.h> 6 #import <UIKit/UIKit.h>
7 7
8 #include "base/mac/scoped_cftyperef.h" 8 #include "base/mac/scoped_cftyperef.h"
9 #include "skia/ext/skia_utils_ios.h" 9 #include "skia/ext/skia_utils_ios.h"
10 #include "ui/gfx/image/image_unittest_util.h" 10 #include "ui/gfx/image/image_unittest_util.h"
11 11
12 namespace gfx { 12 namespace gfx {
13 namespace test { 13 namespace test {
14 14
15 SkColor GetPlatformImageColor(PlatformImage image, int x, int y) { 15 SkColor GetPlatformImageColor(PlatformImage image, int x, int y) {
16 // Start by extracting the target pixel into a 1x1 CGImage. 16 // Start by extracting the target pixel into a 1x1 CGImage.
17 base::ScopedCFTypeRef<CGImageRef> pixel_image( 17
18 CGImageCreateWithImageInRect(image.CGImage, CGRectMake(x, y, 1, 1))); 18 base::ScopedCFTypeRef<CGImageRef> pixel_image(CGImageCreateWithImageInRect(
19 image.CGImage, CGRectMake(x * image.scale, y * image.scale, 1, 1)));
edchin 2017/06/23 19:03:10 I will pull this out into a separate CL and commen
19 20
20 // Draw that pixel into a 1x1 bitmap context. 21 // Draw that pixel into a 1x1 bitmap context.
21 base::ScopedCFTypeRef<CGColorSpaceRef> color_space( 22 base::ScopedCFTypeRef<CGColorSpaceRef> color_space(
22 CGColorSpaceCreateDeviceRGB()); 23 CGColorSpaceCreateDeviceRGB());
23 base::ScopedCFTypeRef<CGContextRef> bitmap_context(CGBitmapContextCreate( 24 base::ScopedCFTypeRef<CGContextRef> bitmap_context(CGBitmapContextCreate(
24 /*data=*/ NULL, 25 /*data=*/ NULL,
25 /*width=*/ 1, 26 /*width=*/ 1,
26 /*height=*/ 1, 27 /*height=*/ 1,
27 /*bitsPerComponent=*/ 8, 28 /*bitsPerComponent=*/ 8,
28 /*bytesPerRow=*/ 4, 29 /*bytesPerRow=*/ 4,
29 color_space, 30 color_space,
30 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host)); 31 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));
31 CGContextDrawImage(bitmap_context, CGRectMake(0, 0, 1, 1), pixel_image); 32 CGContextDrawImage(bitmap_context, CGRectMake(0, 0, 1, 1), pixel_image);
32 33
33 // The CGBitmapContext has the same memory layout as SkColor, so we can just 34 // The CGBitmapContext has the same memory layout as SkColor, so we can just
34 // read an SkColor straight out of the context. 35 // read an SkColor straight out of the context.
35 SkColor* data = 36 SkColor* data =
36 reinterpret_cast<SkColor*>(CGBitmapContextGetData(bitmap_context)); 37 reinterpret_cast<SkColor*>(CGBitmapContextGetData(bitmap_context));
37 return *data; 38 return *data;
38 } 39 }
39 40
40 } // namespace test 41 } // namespace test
41 } // namespace gfx 42 } // namespace gfx
OLDNEW
« ios/web/public/test/fakes/test_web_state.h ('K') | « ios/web/web_state/web_state_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698