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

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

Issue 1963713002: Replace setMatrixClip() with BeginPlatformPaint() logic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 (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>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/mac/scoped_cftyperef.h" 13 #include "base/mac/scoped_cftyperef.h"
14 #include "base/mac/scoped_nsobject.h" 14 #include "base/mac/scoped_nsobject.h"
15 #include "skia/ext/bitmap_platform_device_mac.h" 15 #include "skia/ext/bitmap_platform_device_mac.h"
16 #include "skia/ext/platform_canvas.h" 16 #include "skia/ext/platform_canvas.h"
17 #include "third_party/skia/include/core/SkRegion.h"
18 #include "third_party/skia/include/utils/mac/SkCGUtils.h" 17 #include "third_party/skia/include/utils/mac/SkCGUtils.h"
19 18
20 namespace { 19 namespace {
21 20
22 // Draws an NSImage or an NSImageRep with a given size into a SkBitmap. 21 // Draws an NSImage or an NSImageRep with a given size into a SkBitmap.
23 SkBitmap NSImageOrNSImageRepToSkBitmapWithColorSpace( 22 SkBitmap NSImageOrNSImageRepToSkBitmapWithColorSpace(
24 NSImage* image, 23 NSImage* image,
25 NSImageRep* image_rep, 24 NSImageRep* image_rep,
26 NSSize size, 25 NSSize size,
27 bool is_opaque, 26 bool is_opaque,
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 count:4]; 184 count:4];
186 } 185 }
187 186
188 SkBitmap CGImageToSkBitmap(CGImageRef image) { 187 SkBitmap CGImageToSkBitmap(CGImageRef image) {
189 if (!image) 188 if (!image)
190 return SkBitmap(); 189 return SkBitmap();
191 190
192 int width = CGImageGetWidth(image); 191 int width = CGImageGetWidth(image);
193 int height = CGImageGetHeight(image); 192 int height = CGImageGetHeight(image);
194 193
195 std::unique_ptr<skia::BitmapPlatformDevice> device( 194 sk_sp<skia::BitmapPlatformDevice> device(
196 skia::BitmapPlatformDevice::Create(NULL, width, height, false)); 195 skia::BitmapPlatformDevice::Create(NULL, width, height, false));
197 196
198 CGContextRef context = device->GetBitmapContext(); 197 SkCanvas* canvas = skia::CreateCanvas(device, RETURN_NULL_ON_FAILURE);
f(malita) 2016/05/11 19:29:37 Ditto.
tomhudson 2016/05/19 12:24:12 Done.
198 ScopedPlatformPaint p(canvas);
199 CGContextRef context = p.GetPlatformSurface();
199 200
200 // We need to invert the y-axis of the canvas so that Core Graphics drawing 201 // We need to invert the y-axis of the canvas so that Core Graphics drawing
201 // happens right-side up. Skia has an upper-left origin and CG has a lower- 202 // happens right-side up. Skia has an upper-left origin and CG has a lower-
202 // left one. 203 // left one.
203 CGContextScaleCTM(context, 1.0, -1.0); 204 CGContextScaleCTM(context, 1.0, -1.0);
204 CGContextTranslateCTM(context, 0, -height); 205 CGContextTranslateCTM(context, 0, -height);
205 206
206 // We want to copy transparent pixels from |image|, instead of blending it 207 // We want to copy transparent pixels from |image|, instead of blending it
207 // onto uninitialized pixels. 208 // onto uninitialized pixels.
208 CGContextSetBlendMode(context, kCGBlendModeCopy); 209 CGContextSetBlendMode(context, kCGBlendModeCopy);
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 CGContextConcatCTM(cgContext_, SkMatrixToCGAffineTransform(matrix)); 463 CGContextConcatCTM(cgContext_, SkMatrixToCGAffineTransform(matrix));
463 464
464 return cgContext_; 465 return cgContext_;
465 } 466 }
466 467
467 bool SkiaBitLocker::hasEmptyClipRegion() const { 468 bool SkiaBitLocker::hasEmptyClipRegion() const {
468 return canvas_->isClipEmpty(); 469 return canvas_->isClipEmpty();
469 } 470 }
470 471
471 } // namespace skia 472 } // namespace skia
OLDNEW
« skia/ext/bitmap_platform_device_mac_unittest.cc ('K') | « skia/ext/platform_device_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698