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

Side by Side Diff: ui/gfx/canvas_skia.h

Issue 6879013: skia::PlatformCanvas is being deprecated. Going forward we will use gfx::Canvas wherever we need ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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
« no previous file with comments | « ui/base/clipboard/clipboard_win.cc ('k') | ui/gfx/canvas_skia.cc » ('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) 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 #ifndef UI_GFX_CANVAS_SKIA_H_ 5 #ifndef UI_GFX_CANVAS_SKIA_H_
6 #define UI_GFX_CANVAS_SKIA_H_ 6 #define UI_GFX_CANVAS_SKIA_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/scoped_ptr.h"
10 #include "base/string16.h" 11 #include "base/string16.h"
11 #include "skia/ext/platform_canvas.h"
12 #include "ui/gfx/canvas.h" 12 #include "ui/gfx/canvas.h"
13 13
14 #if defined(OS_POSIX) && !defined(OS_MACOSX) 14 #if defined(OS_POSIX) && !defined(OS_MACOSX)
15 typedef struct _GdkPixbuf GdkPixbuf; 15 typedef struct _GdkPixbuf GdkPixbuf;
16 #endif 16 #endif
17 17
18 namespace gfx { 18 namespace gfx {
19 19
20 class Canvas; 20 class Canvas;
21 21
22 // CanvasSkia is a SkCanvas subclass that provides a number of methods for 22 // CanvasSkia is a Canvas subclass implemented using skia canvas.
23 // common operations used throughout an application built using base/gfx and 23 // It provides a number of methods for common operations used throughout an
24 // app/gfx. 24 // application built using base/gfx and app/gfx.
25 // 25 //
26 // All methods that take integer arguments (as is used throughout views) 26 // All methods that take integer arguments (as is used throughout views)
27 // end with Int. If you need to use methods provided by the superclass 27 // end with Int. If you need to use methods provided by the superclass
28 // you'll need to do a conversion. In particular you'll need to use 28 // you'll need to do a conversion. In particular you'll need to use
29 // macro SkIntToScalar(xxx), or if converting from a scalar to an integer 29 // macro SkIntToScalar(xxx), or if converting from a scalar to an integer
30 // SkScalarRound. 30 // SkScalarRound.
31 // 31 //
32 // A handful of methods in this class are overloaded providing an additional 32 // A handful of methods in this class are overloaded providing an additional
33 // argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the 33 // argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the
34 // source and destination colors are combined. Unless otherwise specified, 34 // source and destination colors are combined. Unless otherwise specified,
35 // the variant that does not take a SkXfermode::Mode uses a transfer mode 35 // the variant that does not take a SkXfermode::Mode uses a transfer mode
36 // of kSrcOver_Mode. 36 // of kSrcOver_Mode.
37 class CanvasSkia : public skia::PlatformCanvas, 37 class CanvasSkia : public Canvas {
38 public Canvas {
39 public: 38 public:
40 enum TruncateFadeMode { 39 enum TruncateFadeMode {
41 TruncateFadeTail, 40 TruncateFadeTail,
42 TruncateFadeHead, 41 TruncateFadeHead,
43 TruncateFadeHeadAndTail, 42 TruncateFadeHeadAndTail,
44 }; 43 };
45 44
46 // Creates an empty Canvas. Callers must use initialize before using the 45 // Creates an empty Canvas.
47 // canvas. 46 // Callers must use Init before using the canvas.
48 CanvasSkia(); 47 CanvasSkia();
49
50 CanvasSkia(int width, int height, bool is_opaque);
51
52 virtual ~CanvasSkia(); 48 virtual ~CanvasSkia();
53 49
54 // Compute the size required to draw some text with the provided font. 50 // Compute the size required to draw some text with the provided font.
55 // Attempts to fit the text with the provided width and height. Increases 51 // Attempts to fit the text with the provided width and height. Increases
56 // height and then width as needed to make the text fit. This method 52 // height and then width as needed to make the text fit. This method
57 // supports multiple lines. 53 // supports multiple lines.
58 static void SizeStringInt(const string16& text, 54 static void SizeStringInt(const string16& text,
59 const gfx::Font& font, 55 const gfx::Font& font,
60 int* width, int* height, 56 int* width, int* height,
61 int flags); 57 int flags);
62 58
63 // Returns the default text alignment to be used when drawing text on a 59 // Returns the default text alignment to be used when drawing text on a
64 // gfx::CanvasSkia based on the directionality of the system locale language. 60 // gfx::CanvasSkia based on the directionality of the system locale language.
65 // This function is used by gfx::Canvas::DrawStringInt when the text alignment 61 // This function is used by gfx::Canvas::DrawStringInt when the text alignment
66 // is not specified. 62 // is not specified.
67 // 63 //
68 // This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or 64 // This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or
69 // gfx::Canvas::TEXT_ALIGN_RIGHT. 65 // gfx::Canvas::TEXT_ALIGN_RIGHT.
70 static int DefaultCanvasTextAlignment(); 66 static int DefaultCanvasTextAlignment();
71 67
68 bool Init(int width, int height, bool is_opaque);
69
70 // Returns the underlying skia canvas.
71 SkCanvas* skia_canvas() { return skia_canvas_.get(); }
72
72 #if defined(OS_POSIX) && !defined(OS_MACOSX) 73 #if defined(OS_POSIX) && !defined(OS_MACOSX)
73 // Draw the pixbuf in its natural size at (x, y). 74 // Draw the pixbuf in its natural size at (x, y).
74 void DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y); 75 void DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y);
75 #endif 76 #endif
76 77
77 #if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX)) 78 #if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX))
78 // Draws text with a 1-pixel halo around it of the given color. 79 // Draws text with a 1-pixel halo around it of the given color.
79 // On Windows, it allows ClearType to be drawn to an otherwise transparenct 80 // On Windows, it allows ClearType to be drawn to an otherwise transparenct
80 // bitmap for drag images. Drag images have only 1-bit of transparency, so 81 // bitmap for drag images. Drag images have only 1-bit of transparency, so
81 // we don't do any fancy blurring. 82 // we don't do any fancy blurring.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 virtual void TileImageInt(const SkBitmap& bitmap, 157 virtual void TileImageInt(const SkBitmap& bitmap,
157 int src_x, int src_y, 158 int src_x, int src_y,
158 int dest_x, int dest_y, int w, int h); 159 int dest_x, int dest_y, int w, int h);
159 virtual gfx::NativeDrawingContext BeginPlatformPaint(); 160 virtual gfx::NativeDrawingContext BeginPlatformPaint();
160 virtual void EndPlatformPaint(); 161 virtual void EndPlatformPaint();
161 virtual void Transform(const ui::Transform& transform); 162 virtual void Transform(const ui::Transform& transform);
162 virtual ui::TextureID GetTextureID(); 163 virtual ui::TextureID GetTextureID();
163 virtual CanvasSkia* AsCanvasSkia(); 164 virtual CanvasSkia* AsCanvasSkia();
164 virtual const CanvasSkia* AsCanvasSkia() const; 165 virtual const CanvasSkia* AsCanvasSkia() const;
165 166
167 // Blits a rectangle from this canvas into the destination context.
168 // This function uses two blit modes to achieve the final color:
169 // 1. Copy: If the source canvas is opaque the color data in the source
170 // rectangle is simply copied to the destination rectangle.
171 // 2. Blend: If the source canvas is translucent, the color data in the
172 // source rectangle is blended with that in the destination
173 // rectangle.
174 void BlitToNativeContext(const Rect& src_rect,
175 const Point& dst_origin,
176 NativeDrawingContext dst_context);
177
166 private: 178 private:
167 // Test whether the provided rectangle intersects the current clip rect. 179 // Test whether the provided rectangle intersects the current clip rect.
168 bool IntersectsClipRectInt(int x, int y, int w, int h); 180 bool IntersectsClipRectInt(int x, int y, int w, int h);
169 181
170 #if defined(OS_WIN) 182 #if defined(OS_WIN)
171 // Draws text with the specified color, font and location. The text is 183 // Draws text with the specified color, font and location. The text is
172 // aligned to the left, vertically centered, clipped to the region. If the 184 // aligned to the left, vertically centered, clipped to the region. If the
173 // text is too big, it is truncated and '...' is added to the end. 185 // text is too big, it is truncated and '...' is added to the end.
174 void DrawStringInt(const string16& text, 186 void DrawStringInt(const string16& text,
175 HFONT font, 187 HFONT font,
176 const SkColor& color, 188 const SkColor& color,
177 int x, int y, int w, int h, 189 int x, int y, int w, int h,
178 int flags); 190 int flags);
179 #endif 191 #endif
180 192
193 scoped_ptr<SkCanvas> skia_canvas_;
181 DISALLOW_COPY_AND_ASSIGN(CanvasSkia); 194 DISALLOW_COPY_AND_ASSIGN(CanvasSkia);
182 }; 195 };
183 196
184 } // namespace gfx; 197 } // namespace gfx;
185 198
186 #endif // UI_GFX_CANVAS_SKIA_H_ 199 #endif // UI_GFX_CANVAS_SKIA_H_
OLDNEW
« no previous file with comments | « ui/base/clipboard/clipboard_win.cc ('k') | ui/gfx/canvas_skia.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698