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

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

Issue 2523673004: [NOT FOR COMMIT] Fully replace SkCanvas uses.
Patch Set: Support Android build. Created 4 years 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 | « skia/ext/skia_utils_mac.h ('k') | third_party/WebKit/Source/core/frame/ImageBitmap.cpp » ('j') | 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 count:4]; 183 count:4];
184 } 184 }
185 185
186 SkBitmap CGImageToSkBitmap(CGImageRef image) { 186 SkBitmap CGImageToSkBitmap(CGImageRef image) {
187 if (!image) 187 if (!image)
188 return SkBitmap(); 188 return SkBitmap();
189 189
190 int width = CGImageGetWidth(image); 190 int width = CGImageGetWidth(image);
191 int height = CGImageGetHeight(image); 191 int height = CGImageGetHeight(image);
192 192
193 std::unique_ptr<SkCanvas> canvas(skia::CreatePlatformCanvas( 193 std::unique_ptr<CdlCanvas> canvas(skia::CreatePlatformCanvas(
194 nullptr, width, height, false, RETURN_NULL_ON_FAILURE)); 194 nullptr, width, height, false, RETURN_NULL_ON_FAILURE));
195 ScopedPlatformPaint p(canvas.get()); 195 ScopedPlatformPaint p(canvas.get());
196 CGContextRef context = p.GetNativeDrawingContext(); 196 CGContextRef context = p.GetNativeDrawingContext();
197 197
198 // We need to invert the y-axis of the canvas so that Core Graphics drawing 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- 199 // happens right-side up. Skia has an upper-left origin and CG has a lower-
200 // left one. 200 // left one.
201 CGContextScaleCTM(context, 1.0, -1.0); 201 CGContextScaleCTM(context, 1.0, -1.0);
202 CGContextTranslateCTM(context, 0, -height); 202 CGContextTranslateCTM(context, 0, -height);
203 203
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 [image setSize:NSMakeSize(skiaBitmap.width(), skiaBitmap.height())]; 255 [image setSize:NSMakeSize(skiaBitmap.width(), skiaBitmap.height())];
256 return [image.release() autorelease]; 256 return [image.release() autorelease];
257 } 257 }
258 258
259 NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) { 259 NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) {
260 base::ScopedCFTypeRef<CGColorSpaceRef> colorSpace( 260 base::ScopedCFTypeRef<CGColorSpaceRef> colorSpace(
261 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); 261 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB));
262 return SkBitmapToNSImageWithColorSpace(skiaBitmap, colorSpace.get()); 262 return SkBitmapToNSImageWithColorSpace(skiaBitmap, colorSpace.get());
263 } 263 }
264 264
265 SkiaBitLocker::SkiaBitLocker(SkCanvas* canvas, 265 SkiaBitLocker::SkiaBitLocker(CdlCanvas* canvas,
266 const SkIRect& userClipRect, 266 const SkIRect& userClipRect,
267 SkScalar bitmapScaleFactor) 267 SkScalar bitmapScaleFactor)
268 : canvas_(canvas), 268 : canvas_(canvas),
269 cgContext_(0), 269 cgContext_(0),
270 bitmapScaleFactor_(bitmapScaleFactor), 270 bitmapScaleFactor_(bitmapScaleFactor),
271 useDeviceBits_(false), 271 useDeviceBits_(false),
272 bitmapIsDummy_(false) { 272 bitmapIsDummy_(false) {
273 canvas_->save(); 273 canvas_->save();
274 canvas_->clipRect(SkRect::MakeFromIRect(userClipRect)); 274 canvas_->clipRect(SkRect::MakeFromIRect(userClipRect));
275 } 275 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 // non-NULL CGContext to use. 321 // non-NULL CGContext to use.
322 bitmapIsDummy_ = true; 322 bitmapIsDummy_ = true;
323 clip_bounds = SkIRect::MakeXYWH(0, 0, 1, 1); 323 clip_bounds = SkIRect::MakeXYWH(0, 0, 1, 1);
324 } 324 }
325 325
326 // remember the top/left, in case we need to compose this later 326 // remember the top/left, in case we need to compose this later
327 bitmapOffset_.set(clip_bounds.x(), clip_bounds.y()); 327 bitmapOffset_.set(clip_bounds.x(), clip_bounds.y());
328 328
329 // Now make clip_bounds be relative to the current layer/device 329 // Now make clip_bounds be relative to the current layer/device
330 if (!bitmapIsDummy_) { 330 if (!bitmapIsDummy_) {
331 canvas_->temporary_internal_describeTopLayer(nullptr, &clip_bounds); 331 GetSkCanvas(canvas_)->temporary_internal_describeTopLayer(nullptr,
332 &clip_bounds);
332 } 333 }
333 334
334 SkPixmap devicePixels; 335 SkPixmap devicePixels;
335 skia::GetWritablePixels(canvas_, &devicePixels); 336 skia::GetWritablePixels(canvas_, &devicePixels);
336 337
337 // Only draw directly if we have pixels, and we're only rect-clipped. 338 // Only draw directly if we have pixels, and we're only rect-clipped.
338 // If not, we allocate an offscreen and draw into that, relying on the 339 // If not, we allocate an offscreen and draw into that, relying on the
339 // compositing step to apply skia's clip. 340 // compositing step to apply skia's clip.
340 useDeviceBits_ = devicePixels.addr() && 341 useDeviceBits_ = devicePixels.addr() &&
341 canvas_->isClipRect() && 342 canvas_->isClipRect() &&
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 CGContextConcatCTM(cgContext_, SkMatrixToCGAffineTransform(matrix)); 379 CGContextConcatCTM(cgContext_, SkMatrixToCGAffineTransform(matrix));
379 380
380 return cgContext_; 381 return cgContext_;
381 } 382 }
382 383
383 bool SkiaBitLocker::hasEmptyClipRegion() const { 384 bool SkiaBitLocker::hasEmptyClipRegion() const {
384 return canvas_->isClipEmpty(); 385 return canvas_->isClipEmpty();
385 } 386 }
386 387
387 } // namespace skia 388 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/skia_utils_mac.h ('k') | third_party/WebKit/Source/core/frame/ImageBitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698