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

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

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 #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/memory/scoped_ptr.h"
10 #include "base/string16.h" 11 #include "base/string16.h"
11 #include "skia/ext/platform_canvas.h" 12 #include "skia/ext/platform_canvas.h"
12 #include "ui/gfx/canvas.h" 13 #include "ui/gfx/canvas.h"
13 14
14 #if defined(TOOLKIT_USES_GTK) 15 #if defined(TOOLKIT_USES_GTK)
15 typedef struct _GdkPixbuf GdkPixbuf; 16 typedef struct _GdkPixbuf GdkPixbuf;
16 #endif 17 #endif
17 18
18 namespace gfx { 19 namespace gfx {
19 20
20 class Canvas; 21 class Canvas;
21 22
22 // CanvasSkia is a SkCanvas subclass that provides a number of methods for 23 // CanvasSkia is a SkCanvas subclass that provides a number of methods for
23 // common operations used throughout an application built using base/gfx and 24 // common operations used throughout an application built using base/gfx and
24 // app/gfx. 25 // app/gfx.
25 // 26 //
26 // All methods that take integer arguments (as is used throughout views) 27 // 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 28 // 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 29 // 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 30 // macro SkIntToScalar(xxx), or if converting from a scalar to an integer
30 // SkScalarRound. 31 // SkScalarRound.
31 // 32 //
32 // A handful of methods in this class are overloaded providing an additional 33 // A handful of methods in this class are overloaded providing an additional
33 // argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the 34 // argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the
34 // source and destination colors are combined. Unless otherwise specified, 35 // source and destination colors are combined. Unless otherwise specified,
35 // the variant that does not take a SkXfermode::Mode uses a transfer mode 36 // the variant that does not take a SkXfermode::Mode uses a transfer mode
36 // of kSrcOver_Mode. 37 // of kSrcOver_Mode.
37 class UI_EXPORT CanvasSkia : public skia::PlatformCanvas, public Canvas { 38 class UI_EXPORT CanvasSkia : public Canvas {
38 public: 39 public:
39 enum TruncateFadeMode { 40 enum TruncateFadeMode {
40 TruncateFadeTail, 41 TruncateFadeTail,
41 TruncateFadeHead, 42 TruncateFadeHead,
42 TruncateFadeHeadAndTail, 43 TruncateFadeHeadAndTail,
43 }; 44 };
44 45
45 // Creates an empty Canvas. Callers must use initialize before using the 46 // Creates an empty Canvas. Callers must use initialize before using the
46 // canvas. 47 // canvas.
47 CanvasSkia(); 48 CanvasSkia();
48 49
49 CanvasSkia(int width, int height, bool is_opaque); 50 CanvasSkia(int width, int height, bool is_opaque);
51 explicit CanvasSkia(SkCanvas* canvas);
50 52
51 virtual ~CanvasSkia(); 53 virtual ~CanvasSkia();
52 54
53 // Compute the size required to draw some text with the provided font. 55 // Compute the size required to draw some text with the provided font.
54 // Attempts to fit the text with the provided width and height. Increases 56 // Attempts to fit the text with the provided width and height. Increases
55 // height and then width as needed to make the text fit. This method 57 // height and then width as needed to make the text fit. This method
56 // supports multiple lines. 58 // supports multiple lines.
57 static void SizeStringInt(const string16& text, 59 static void SizeStringInt(const string16& text,
58 const gfx::Font& font, 60 const gfx::Font& font,
59 int* width, int* height, 61 int* width, int* height,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 int src_x, int src_y, 158 int src_x, int src_y,
157 int dest_x, int dest_y, int w, int h); 159 int dest_x, int dest_y, int w, int h);
158 virtual gfx::NativeDrawingContext BeginPlatformPaint(); 160 virtual gfx::NativeDrawingContext BeginPlatformPaint();
159 virtual void EndPlatformPaint(); 161 virtual void EndPlatformPaint();
160 #if !defined(OS_MACOSX) 162 #if !defined(OS_MACOSX)
161 virtual void Transform(const ui::Transform& transform); 163 virtual void Transform(const ui::Transform& transform);
162 #endif 164 #endif
163 virtual ui::TextureID GetTextureID(); 165 virtual ui::TextureID GetTextureID();
164 virtual CanvasSkia* AsCanvasSkia(); 166 virtual CanvasSkia* AsCanvasSkia();
165 virtual const CanvasSkia* AsCanvasSkia() const; 167 virtual const CanvasSkia* AsCanvasSkia() const;
168 virtual SkCanvas* GetSkCanvas();
169 virtual const SkCanvas* GetSkCanvas() const;
170 SkCanvas* sk_canvas() const { return canvas_; }
171 skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); }
166 172
167 private: 173 private:
168 // Test whether the provided rectangle intersects the current clip rect. 174 // Test whether the provided rectangle intersects the current clip rect.
169 bool IntersectsClipRectInt(int x, int y, int w, int h); 175 bool IntersectsClipRectInt(int x, int y, int w, int h);
170 176
171 #if defined(OS_WIN) 177 #if defined(OS_WIN)
172 // Draws text with the specified color, font and location. The text is 178 // Draws text with the specified color, font and location. The text is
173 // aligned to the left, vertically centered, clipped to the region. If the 179 // aligned to the left, vertically centered, clipped to the region. If the
174 // text is too big, it is truncated and '...' is added to the end. 180 // text is too big, it is truncated and '...' is added to the end.
175 void DrawStringInt(const string16& text, 181 void DrawStringInt(const string16& text,
176 HFONT font, 182 HFONT font,
177 const SkColor& color, 183 const SkColor& color,
178 int x, int y, int w, int h, 184 int x, int y, int w, int h,
179 int flags); 185 int flags);
180 #endif 186 #endif
181 187
188 scoped_ptr<skia::PlatformCanvas> owned_canvas_;
189 SkCanvas* canvas_;
182 DISALLOW_COPY_AND_ASSIGN(CanvasSkia); 190 DISALLOW_COPY_AND_ASSIGN(CanvasSkia);
183 }; 191 };
184 192
185 } // namespace gfx; 193 } // namespace gfx;
186 194
187 #endif // UI_GFX_CANVAS_SKIA_H_ 195 #endif // UI_GFX_CANVAS_SKIA_H_
OLDNEW
« ui/gfx/canvas.h ('K') | « ui/gfx/canvas.cc ('k') | ui/gfx/canvas_skia.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698