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

Side by Side Diff: skia/ext/skia_utils_mac.mm

Issue 2595113002: use skia cgimage->bitmap routine (Closed)
Patch Set: rebase Created 3 years, 12 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include "skia/ext/skia_utils_mac.h" 5 #include "skia/ext/skia_utils_mac.h"
6 6
7 #import <AppKit/AppKit.h> 7 #import <AppKit/AppKit.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 SkColorGetG(color) / 255.0, 177 SkColorGetG(color) / 255.0,
178 SkColorGetB(color) / 255.0, 178 SkColorGetB(color) / 255.0,
179 SkColorGetA(color) / 255.0 179 SkColorGetA(color) / 255.0
180 }; 180 };
181 return [NSColor colorWithColorSpace:[NSColorSpace sRGBColorSpace] 181 return [NSColor colorWithColorSpace:[NSColorSpace sRGBColorSpace]
182 components:components 182 components:components
183 count:4]; 183 count:4];
184 } 184 }
185 185
186 SkBitmap CGImageToSkBitmap(CGImageRef image) { 186 SkBitmap CGImageToSkBitmap(CGImageRef image) {
187 if (!image) 187 SkBitmap bitmap;
188 return SkBitmap(); 188 if (image && SkCreateBitmapFromCGImage(&bitmap, image))
189 189 return bitmap;
190 int width = CGImageGetWidth(image); 190 return SkBitmap();
191 int height = CGImageGetHeight(image);
192
193 std::unique_ptr<SkCanvas> canvas(
194 skia::TryCreateBitmapCanvas(width, height, false));
195 ScopedPlatformPaint p(canvas.get());
196 CGContextRef context = p.GetNativeDrawingContext();
197
198 // We need to invert the y-axis of the canvas so that Core Graphics drawing
199 // happens right-side up. Skia has an upper-left origin and CG has a lower-
200 // left one.
201 CGContextScaleCTM(context, 1.0, -1.0);
202 CGContextTranslateCTM(context, 0, -height);
203
204 // We want to copy transparent pixels from |image|, instead of blending it
205 // onto uninitialized pixels.
206 CGContextSetBlendMode(context, kCGBlendModeCopy);
207
208 CGRect rect = CGRectMake(0, 0, width, height);
209 CGContextDrawImage(context, rect, image);
210
211 return skia::ReadPixels(canvas.get());
212 } 191 }
213 192
214 SkBitmap NSImageToSkBitmapWithColorSpace( 193 SkBitmap NSImageToSkBitmapWithColorSpace(
215 NSImage* image, bool is_opaque, CGColorSpaceRef color_space) { 194 NSImage* image, bool is_opaque, CGColorSpaceRef color_space) {
216 return NSImageOrNSImageRepToSkBitmapWithColorSpace( 195 return NSImageOrNSImageRepToSkBitmapWithColorSpace(
217 image, nil, [image size], is_opaque, color_space); 196 image, nil, [image size], is_opaque, color_space);
218 } 197 }
219 198
220 SkBitmap NSImageRepToSkBitmapWithColorSpace(NSImageRep* image_rep, 199 SkBitmap NSImageRepToSkBitmapWithColorSpace(NSImageRep* image_rep,
221 NSSize size, 200 NSSize size,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 CGContextConcatCTM(cgContext_, SkMatrixToCGAffineTransform(matrix)); 357 CGContextConcatCTM(cgContext_, SkMatrixToCGAffineTransform(matrix));
379 358
380 return cgContext_; 359 return cgContext_;
381 } 360 }
382 361
383 bool SkiaBitLocker::hasEmptyClipRegion() const { 362 bool SkiaBitLocker::hasEmptyClipRegion() const {
384 return canvas_->isClipEmpty(); 363 return canvas_->isClipEmpty();
385 } 364 }
386 365
387 } // namespace skia 366 } // namespace skia
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698