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

Side by Side Diff: ui/gfx/canvas_skia_mac.mm

Issue 8122013: Allow CanvasSkia to bind to an existing SkCanvas. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: 1 more fix Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "ui/gfx/canvas_skia.h" 7 #include "ui/gfx/canvas_skia.h"
8 8
9 #include "base/mac/mac_util.h" 9 #include "base/mac/mac_util.h"
10 #include "base/mac/scoped_cftyperef.h" 10 #include "base/mac/scoped_cftyperef.h"
11 #include "base/sys_string_conversions.h" 11 #include "base/sys_string_conversions.h"
12 #include "third_party/skia/include/core/SkShader.h" 12 #include "third_party/skia/include/core/SkShader.h"
13 #include "ui/gfx/font.h" 13 #include "ui/gfx/font.h"
14 #include "ui/gfx/rect.h" 14 #include "ui/gfx/rect.h"
15 15
16 namespace gfx { 16 namespace gfx {
17 17
18 CanvasSkia::CanvasSkia(int width, int height, bool is_opaque)
19 : skia::PlatformCanvas(width, height, is_opaque) {
20 }
21
22 CanvasSkia::CanvasSkia() : skia::PlatformCanvas() {
23 }
24
25 CanvasSkia::~CanvasSkia() {
26 }
27
28 // static 18 // static
29 void CanvasSkia::SizeStringInt(const string16& text, 19 void CanvasSkia::SizeStringInt(const string16& text,
30 const gfx::Font& font, 20 const gfx::Font& font,
31 int* width, int* height, 21 int* width, int* height,
32 int flags) { 22 int flags) {
33 NSFont* native_font = font.GetNativeFont(); 23 NSFont* native_font = font.GetNativeFont();
34 NSString* ns_string = base::SysUTF16ToNSString(text); 24 NSString* ns_string = base::SysUTF16ToNSString(text);
35 NSDictionary* attributes = 25 NSDictionary* attributes =
36 [NSDictionary dictionaryWithObject:native_font 26 [NSDictionary dictionaryWithObject:native_font
37 forKey:NSFontAttributeName]; 27 forKey:NSFontAttributeName];
38 NSSize string_size = [ns_string sizeWithAttributes:attributes]; 28 NSSize string_size = [ns_string sizeWithAttributes:attributes];
39 *width = string_size.width; 29 *width = string_size.width;
40 *height = font.GetHeight(); 30 *height = font.GetHeight();
41 } 31 }
42 32
43 void CanvasSkia::DrawStringInt(const string16& text, 33 void CanvasSkia::DrawStringInt(const string16& text,
44 const gfx::Font& font, 34 const gfx::Font& font,
45 const SkColor& color, 35 const SkColor& color,
46 int x, int y, int w, int h, 36 int x, int y, int w, int h,
47 int flags) { 37 int flags) {
48 if (!IntersectsClipRectInt(x, y, w, h)) 38 if (!IntersectsClipRectInt(x, y, w, h))
49 return; 39 return;
50 40
51 skia::ScopedPlatformPaint scoped_platform_paint(this); 41 skia::ScopedPlatformPaint scoped_platform_paint(canvas_);
52 CGContextRef context = scoped_platform_paint.GetPlatformSurface(); 42 CGContextRef context = scoped_platform_paint.GetPlatformSurface();
53 CGContextSaveGState(context); 43 CGContextSaveGState(context);
54 44
55 NSColor* ns_color = [NSColor colorWithDeviceRed:SkColorGetR(color) / 255.0 45 NSColor* ns_color = [NSColor colorWithDeviceRed:SkColorGetR(color) / 255.0
56 green:SkColorGetG(color) / 255.0 46 green:SkColorGetG(color) / 255.0
57 blue:SkColorGetB(color) / 255.0 47 blue:SkColorGetB(color) / 255.0
58 alpha:SkColorGetA(color) / 255.0]; 48 alpha:SkColorGetA(color) / 255.0];
59 NSMutableParagraphStyle *ns_style = 49 NSMutableParagraphStyle *ns_style =
60 [[[NSMutableParagraphStyle alloc] init] autorelease]; 50 [[[NSMutableParagraphStyle alloc] init] autorelease];
61 if (flags & TEXT_ALIGN_CENTER) 51 if (flags & TEXT_ALIGN_CENTER)
(...skipping 23 matching lines...) Expand all
85 CTFrameDraw(frame, context); 75 CTFrameDraw(frame, context);
86 CGContextRestoreGState(context); 76 CGContextRestoreGState(context);
87 } 77 }
88 78
89 ui::TextureID CanvasSkia::GetTextureID() { 79 ui::TextureID CanvasSkia::GetTextureID() {
90 // TODO(wjmaclean) 80 // TODO(wjmaclean)
91 return 0; 81 return 0;
92 } 82 }
93 83
94 } // namespace gfx 84 } // namespace gfx
OLDNEW
« ui/gfx/canvas.h ('K') | « ui/gfx/canvas_skia_linux.cc ('k') | ui/gfx/canvas_skia_paint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698