[email protected] | fa8cfb0 | 2012-01-13 00:27:41 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef UI_GFX_CANVAS_H_ |
| 6 | #define UI_GFX_CANVAS_H_ |
| 7 | #pragma once |
| 8 | |
[email protected] | 0834e1b1 | 2012-04-11 02:23:56 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 11 | #include "base/basictypes.h" |
| 12 | #include "base/memory/scoped_ptr.h" |
| 13 | #include "base/string16.h" |
| 14 | #include "skia/ext/platform_canvas.h" |
[email protected] | 35d5334 | 2012-05-16 21:30:12 | [diff] [blame] | 15 | #include "ui/gfx/image/image_skia.h" |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 16 | #include "ui/gfx/native_widget_types.h" |
[email protected] | 2565068 | 2012-05-29 23:09:19 | [diff] [blame] | 17 | #include "ui/gfx/shadow_value.h" |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 18 | |
| 19 | class SkBitmap; |
| 20 | |
| 21 | namespace ui { |
| 22 | class Transform; |
| 23 | } |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 24 | |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 25 | namespace gfx { |
| 26 | |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 27 | class Brush; |
| 28 | class Rect; |
| 29 | class Font; |
| 30 | class Point; |
| 31 | class Size; |
| 32 | |
| 33 | // Canvas is a SkCanvas wrapper that provides a number of methods for |
| 34 | // common operations used throughout an application built using ui/gfx. |
| 35 | // |
| 36 | // All methods that take integer arguments (as is used throughout views) |
| 37 | // end with Int. If you need to use methods provided by SkCanvas, you'll |
| 38 | // need to do a conversion. In particular you'll need to use |SkIntToScalar()|, |
| 39 | // or if converting from a scalar to an integer |SkScalarRound()|. |
| 40 | // |
| 41 | // A handful of methods in this class are overloaded providing an additional |
| 42 | // argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the |
| 43 | // source and destination colors are combined. Unless otherwise specified, |
| 44 | // the variant that does not take a SkXfermode::Mode uses a transfer mode |
| 45 | // of kSrcOver_Mode. |
| 46 | class UI_EXPORT Canvas { |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 47 | public: |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 48 | enum TruncateFadeMode { |
| 49 | TruncateFadeTail, |
| 50 | TruncateFadeHead, |
| 51 | TruncateFadeHeadAndTail, |
| 52 | }; |
| 53 | |
| 54 | // Specifies the alignment for text rendered with the DrawStringInt method. |
| 55 | enum { |
| 56 | TEXT_ALIGN_LEFT = 1 << 0, |
| 57 | TEXT_ALIGN_CENTER = 1 << 1, |
| 58 | TEXT_ALIGN_RIGHT = 1 << 2 , |
| 59 | TEXT_VALIGN_TOP = 1 << 3, |
| 60 | TEXT_VALIGN_MIDDLE = 1 << 4, |
| 61 | TEXT_VALIGN_BOTTOM = 1 << 5, |
| 62 | |
| 63 | // Specifies the text consists of multiple lines. |
| 64 | MULTI_LINE = 1 << 6, |
| 65 | |
| 66 | // By default DrawStringInt does not process the prefix ('&') character |
| 67 | // specially. That is, the string "&foo" is rendered as "&foo". When |
| 68 | // rendering text from a resource that uses the prefix character for |
| 69 | // mnemonics, the prefix should be processed and can be rendered as an |
| 70 | // underline (SHOW_PREFIX), or not rendered at all (HIDE_PREFIX). |
| 71 | SHOW_PREFIX = 1 << 7, |
| 72 | HIDE_PREFIX = 1 << 8, |
| 73 | |
| 74 | // Prevent ellipsizing |
| 75 | NO_ELLIPSIS = 1 << 9, |
| 76 | |
| 77 | // Specifies if words can be split by new lines. |
| 78 | // This only works with MULTI_LINE. |
| 79 | CHARACTER_BREAK = 1 << 10, |
| 80 | |
| 81 | // Instructs DrawStringInt() to render the text using RTL directionality. |
| 82 | // In most cases, passing this flag is not necessary because information |
| 83 | // about the text directionality is going to be embedded within the string |
| 84 | // in the form of special Unicode characters. However, we don't insert |
| 85 | // directionality characters into strings if the locale is LTR because some |
| 86 | // platforms (for example, an English Windows XP with no RTL fonts |
| 87 | // installed) don't support these characters. Thus, this flag should be |
| 88 | // used to render text using RTL directionality when the locale is LTR. |
| 89 | FORCE_RTL_DIRECTIONALITY = 1 << 11, |
| 90 | |
| 91 | // Similar to FORCE_RTL_DIRECTIONALITY, but left-to-right. |
| 92 | // See FORCE_RTL_DIRECTIONALITY for details. |
| 93 | FORCE_LTR_DIRECTIONALITY = 1 << 12, |
| 94 | |
| 95 | // Instructs DrawStringInt() to not use subpixel rendering. This is useful |
| 96 | // when rendering text onto a fully- or partially-transparent background |
| 97 | // that will later be blended with another image. |
| 98 | NO_SUBPIXEL_RENDERING = 1 << 13, |
| 99 | }; |
| 100 | |
| 101 | // Creates an empty canvas. |
[email protected] | 94a0d258 | 2012-03-09 00:30:59 | [diff] [blame] | 102 | Canvas(); |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 103 | |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 104 | // If this canvas is not opaque, it's explicitly cleared to transparent before |
| 105 | // being returned. |
| 106 | Canvas(const gfx::Size& size, bool is_opaque); |
| 107 | |
| 108 | // Constructs a canvas the size of the provided |bitmap|, and draws the |
| 109 | // bitmap into it. |
| 110 | Canvas(const SkBitmap& bitmap, bool is_opaque); |
| 111 | |
[email protected] | 94a0d258 | 2012-03-09 00:30:59 | [diff] [blame] | 112 | explicit Canvas(SkCanvas* canvas); |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 113 | |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 114 | virtual ~Canvas(); |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 115 | |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 116 | // Compute the size required to draw some text with the provided font. |
| 117 | // Attempts to fit the text with the provided width and height. Increases |
| 118 | // height and then width as needed to make the text fit. This method |
| 119 | // supports multiple lines. |
| 120 | static void SizeStringInt(const string16& text, |
| 121 | const gfx::Font& font, |
| 122 | int* width, int* height, |
| 123 | int flags); |
| 124 | |
| 125 | // Returns the number of horizontal pixels needed to display the specified |
| 126 | // |text| with |font|. |
| 127 | static int GetStringWidth(const string16& text, const gfx::Font& font); |
| 128 | |
| 129 | // Returns the default text alignment to be used when drawing text on a |
| 130 | // gfx::Canvas based on the directionality of the system locale language. |
| 131 | // This function is used by gfx::Canvas::DrawStringInt when the text alignment |
| 132 | // is not specified. |
| 133 | // |
| 134 | // This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or |
| 135 | // gfx::Canvas::TEXT_ALIGN_RIGHT. |
| 136 | static int DefaultCanvasTextAlignment(); |
| 137 | |
| 138 | // Draws text with a 1-pixel halo around it of the given color. |
| 139 | // On Windows, it allows ClearType to be drawn to an otherwise transparenct |
| 140 | // bitmap for drag images. Drag images have only 1-bit of transparency, so |
| 141 | // we don't do any fancy blurring. |
| 142 | // On Linux, text with halo is created by stroking it with 2px |halo_color| |
| 143 | // then filling it with |text_color|. |
| 144 | // On Mac, NOTIMPLEMENTED. |
| 145 | // TODO(dhollowa): Skia-native implementation is underway. Cut over to |
| 146 | // that when ready. http::/crbug.com/109946 |
| 147 | void DrawStringWithHalo(const string16& text, |
| 148 | const gfx::Font& font, |
[email protected] | 1b81ff2 | 2012-03-24 22:04:42 | [diff] [blame] | 149 | SkColor text_color, |
| 150 | SkColor halo_color, |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 151 | int x, int y, int w, int h, |
| 152 | int flags); |
| 153 | |
| 154 | // Extracts a bitmap from the contents of this canvas. |
| 155 | SkBitmap ExtractBitmap() const; |
| 156 | |
| 157 | // Draws a dashed rectangle of the specified color. |
| 158 | void DrawDashedRect(const gfx::Rect& rect, SkColor color); |
| 159 | |
| 160 | // Saves a copy of the drawing state onto a stack, operating on this copy |
| 161 | // until a balanced call to Restore() is made. |
| 162 | void Save(); |
| 163 | |
| 164 | // As with Save(), except draws to a layer that is blended with the canvas |
| 165 | // at the specified alpha once Restore() is called. |
| 166 | // |layer_bounds| are the bounds of the layer relative to the current |
| 167 | // transform. |
| 168 | void SaveLayerAlpha(uint8 alpha); |
| 169 | void SaveLayerAlpha(uint8 alpha, const gfx::Rect& layer_bounds); |
| 170 | |
| 171 | // Restores the drawing state after a call to Save*(). It is an error to |
| 172 | // call Restore() more times than Save*(). |
| 173 | void Restore() ; |
| 174 | |
[email protected] | ffdd1fd | 2012-04-09 23:24:41 | [diff] [blame] | 175 | // Adds |rect| to the current clip. Returns true if the resulting clip is |
| 176 | // non-empty. |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 177 | bool ClipRect(const gfx::Rect& rect); |
| 178 | |
[email protected] | ffdd1fd | 2012-04-09 23:24:41 | [diff] [blame] | 179 | // Adds |path| to the current clip. Returns true if the resulting clip is |
| 180 | // non-empty. |
| 181 | bool ClipPath(const SkPath& path); |
| 182 | |
| 183 | // Returns the bounds of the current clip (in local coordinates) in the |
| 184 | // |bounds| parameter, and returns true if it is non empty. |
| 185 | bool GetClipBounds(gfx::Rect* bounds); |
| 186 | |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 187 | void Translate(const gfx::Point& point); |
| 188 | |
| 189 | void Scale(int x_scale, int y_scale); |
| 190 | |
[email protected] | ffdd1fd | 2012-04-09 23:24:41 | [diff] [blame] | 191 | // Fills the entire canvas' bitmap (restricted to current clip) with |
| 192 | // specified |color| using a transfer mode of SkXfermode::kSrcOver_Mode. |
| 193 | void DrawColor(SkColor color); |
| 194 | |
| 195 | // Fills the entire canvas' bitmap (restricted to current clip) with |
| 196 | // specified |color| and |mode|. |
| 197 | void DrawColor(SkColor color, SkXfermode::Mode mode); |
| 198 | |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 199 | // Fills |rect| with |color| using a transfer mode of |
| 200 | // SkXfermode::kSrcOver_Mode. |
[email protected] | 1b81ff2 | 2012-03-24 22:04:42 | [diff] [blame] | 201 | void FillRect(const gfx::Rect& rect, SkColor color); |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 202 | |
| 203 | // Fills |rect| with the specified |color| and |mode|. |
[email protected] | 1b81ff2 | 2012-03-24 22:04:42 | [diff] [blame] | 204 | void FillRect(const gfx::Rect& rect, SkColor color, SkXfermode::Mode mode); |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 205 | |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 206 | // Draws a single pixel rect in the specified region with the specified |
| 207 | // color, using a transfer mode of SkXfermode::kSrcOver_Mode. |
| 208 | // |
| 209 | // NOTE: if you need a single pixel line, use DrawLine. |
[email protected] | 1b81ff2 | 2012-03-24 22:04:42 | [diff] [blame] | 210 | void DrawRect(const gfx::Rect& rect, SkColor color); |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 211 | |
| 212 | // Draws a single pixel rect in the specified region with the specified |
| 213 | // color and transfer mode. |
| 214 | // |
| 215 | // NOTE: if you need a single pixel line, use DrawLine. |
[email protected] | 1b81ff2 | 2012-03-24 22:04:42 | [diff] [blame] | 216 | void DrawRect(const gfx::Rect& rect, SkColor color, SkXfermode::Mode mode); |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 217 | |
[email protected] | ffdd1fd | 2012-04-09 23:24:41 | [diff] [blame] | 218 | // Draws the given rectangle with the given |paint| parameters. |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 219 | void DrawRect(const gfx::Rect& rect, const SkPaint& paint); |
| 220 | |
[email protected] | ffdd1fd | 2012-04-09 23:24:41 | [diff] [blame] | 221 | // Draw the given point with the given |paint| parameters. |
| 222 | void DrawPoint(const gfx::Point& p, const SkPaint& paint); |
| 223 | |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 224 | // Draws a single pixel line with the specified color. |
[email protected] | 1b81ff2 | 2012-03-24 22:04:42 | [diff] [blame] | 225 | void DrawLine(const gfx::Point& p1, const gfx::Point& p2, SkColor color); |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 226 | |
[email protected] | ffdd1fd | 2012-04-09 23:24:41 | [diff] [blame] | 227 | // Draws a line with the given |paint| parameters. |
| 228 | void DrawLine(const gfx::Point& p1, |
| 229 | const gfx::Point& p2, |
| 230 | const SkPaint& paint); |
| 231 | |
| 232 | // Draws a circle with the given |paint| parameters. |
| 233 | void DrawCircle(const gfx::Point& center_point, |
| 234 | int radius, |
| 235 | const SkPaint& paint); |
| 236 | |
| 237 | // Draws the given rectangle with rounded corners of |radius| using the |
| 238 | // given |paint| parameters. |
| 239 | void DrawRoundRect(const gfx::Rect& rect, int radius, const SkPaint& paint); |
| 240 | |
| 241 | // Draws the given path using the given |paint| parameters. |
| 242 | void DrawPath(const SkPath& path, const SkPaint& paint); |
| 243 | |
[email protected] | 35d5334 | 2012-05-16 21:30:12 | [diff] [blame] | 244 | // Draws an image with the origin at the specified location. The upper left |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 245 | // corner of the bitmap is rendered at the specified location. |
[email protected] | 35d5334 | 2012-05-16 21:30:12 | [diff] [blame] | 246 | // Parameters are specified relative to current canvas scale not in pixels. |
| 247 | // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1. |
[email protected] | 243cac7d | 2012-06-07 13:29:20 | [diff] [blame^] | 248 | void DrawImageInt(const gfx::ImageSkia&, int x, int y); |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 249 | |
[email protected] | 35d5334 | 2012-05-16 21:30:12 | [diff] [blame] | 250 | // Draws an image with the origin at the specified location, using the |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 251 | // specified paint. The upper left corner of the bitmap is rendered at the |
| 252 | // specified location. |
[email protected] | 35d5334 | 2012-05-16 21:30:12 | [diff] [blame] | 253 | // Parameters are specified relative to current canvas scale not in pixels. |
| 254 | // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1. |
[email protected] | 243cac7d | 2012-06-07 13:29:20 | [diff] [blame^] | 255 | void DrawImageInt(const gfx::ImageSkia& image, |
| 256 | int x, int y, |
| 257 | const SkPaint& paint); |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 258 | |
[email protected] | 35d5334 | 2012-05-16 21:30:12 | [diff] [blame] | 259 | // Draws a portion of an image in the specified location. The src parameters |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 260 | // correspond to the region of the bitmap to draw in the region defined |
| 261 | // by the dest coordinates. |
| 262 | // |
| 263 | // If the width or height of the source differs from that of the destination, |
[email protected] | 35d5334 | 2012-05-16 21:30:12 | [diff] [blame] | 264 | // the image will be scaled. When scaling down, a mipmap will be generated. |
| 265 | // Set |filter| to use filtering for images, otherwise the nearest-neighbor |
| 266 | // algorithm is used for resampling. |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 267 | // |
| 268 | // An optional custom SkPaint can be provided. |
[email protected] | 35d5334 | 2012-05-16 21:30:12 | [diff] [blame] | 269 | // Parameters are specified relative to current canvas scale not in pixels. |
| 270 | // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1. |
[email protected] | 243cac7d | 2012-06-07 13:29:20 | [diff] [blame^] | 271 | void DrawImageInt(const gfx::ImageSkia& image, |
| 272 | int src_x, int src_y, int src_w, int src_h, |
| 273 | int dest_x, int dest_y, int dest_w, int dest_h, |
| 274 | bool filter); |
| 275 | void DrawImageInt(const gfx::ImageSkia& image, |
| 276 | int src_x, int src_y, int src_w, int src_h, |
| 277 | int dest_x, int dest_y, int dest_w, int dest_h, |
| 278 | bool filter, |
| 279 | const SkPaint& paint); |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 280 | |
| 281 | // Draws text with the specified color, font and location. The text is |
| 282 | // aligned to the left, vertically centered, clipped to the region. If the |
| 283 | // text is too big, it is truncated and '...' is added to the end. |
| 284 | void DrawStringInt(const string16& text, |
| 285 | const gfx::Font& font, |
[email protected] | 1b81ff2 | 2012-03-24 22:04:42 | [diff] [blame] | 286 | SkColor color, |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 287 | int x, int y, int w, int h); |
| 288 | void DrawStringInt(const string16& text, |
| 289 | const gfx::Font& font, |
[email protected] | 1b81ff2 | 2012-03-24 22:04:42 | [diff] [blame] | 290 | SkColor color, |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 291 | const gfx::Rect& display_rect); |
| 292 | |
| 293 | // Draws text with the specified color, font and location. The last argument |
| 294 | // specifies flags for how the text should be rendered. It can be one of |
| 295 | // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT. |
| 296 | void DrawStringInt(const string16& text, |
| 297 | const gfx::Font& font, |
[email protected] | 1b81ff2 | 2012-03-24 22:04:42 | [diff] [blame] | 298 | SkColor color, |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 299 | int x, int y, int w, int h, |
| 300 | int flags); |
| 301 | |
[email protected] | 0834e1b1 | 2012-04-11 02:23:56 | [diff] [blame] | 302 | // Similar to above DrawStringInt method but with text shadows support. |
| 303 | // Currently it's only implemented for canvas skia. |
| 304 | void DrawStringWithShadows(const string16& text, |
| 305 | const gfx::Font& font, |
| 306 | SkColor color, |
| 307 | const gfx::Rect& text_bounds, |
| 308 | int flags, |
[email protected] | 2565068 | 2012-05-29 23:09:19 | [diff] [blame] | 309 | const ShadowValues& shadows); |
[email protected] | 0834e1b1 | 2012-04-11 02:23:56 | [diff] [blame] | 310 | |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 311 | // Draws a dotted gray rectangle used for focus purposes. |
| 312 | void DrawFocusRect(const gfx::Rect& rect); |
| 313 | |
| 314 | // Tiles the image in the specified region. |
[email protected] | 35d5334 | 2012-05-16 21:30:12 | [diff] [blame] | 315 | // Parameters are specified relative to current canvas scale not in pixels. |
| 316 | // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1. |
| 317 | void TileImageInt(const gfx::ImageSkia& image, |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 318 | int x, int y, int w, int h); |
[email protected] | 35d5334 | 2012-05-16 21:30:12 | [diff] [blame] | 319 | void TileImageInt(const gfx::ImageSkia& image, |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 320 | int src_x, int src_y, |
| 321 | int dest_x, int dest_y, int w, int h); |
[email protected] | 2a3115e | 2012-05-25 23:27:04 | [diff] [blame] | 322 | void TileImageInt(const gfx::ImageSkia& image, |
| 323 | int src_x, int src_y, |
| 324 | float tile_scale_x, float tile_scale_y, |
| 325 | int dest_x, int dest_y, int w, int h); |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 326 | |
| 327 | // Returns a native drawing context for platform specific drawing routines to |
| 328 | // use. Must be balanced by a call to EndPlatformPaint(). |
| 329 | NativeDrawingContext BeginPlatformPaint(); |
| 330 | |
| 331 | // Signifies the end of platform drawing using the native drawing context |
| 332 | // returned by BeginPlatformPaint(). |
| 333 | void EndPlatformPaint(); |
| 334 | |
| 335 | // Apply transformation on the canvas. |
| 336 | void Transform(const ui::Transform& transform); |
| 337 | |
| 338 | #if defined(OS_WIN) |
| 339 | // Draws the given string with the beginning and/or the end using a fade |
| 340 | // gradient. When truncating the head |
| 341 | // |desired_characters_to_truncate_from_head| specifies the maximum number of |
| 342 | // characters that can be truncated. |
| 343 | void DrawFadeTruncatingString( |
| 344 | const string16& text, |
| 345 | TruncateFadeMode truncate_mode, |
| 346 | size_t desired_characters_to_truncate_from_head, |
| 347 | const gfx::Font& font, |
[email protected] | 1b81ff2 | 2012-03-24 22:04:42 | [diff] [blame] | 348 | SkColor color, |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 349 | const gfx::Rect& display_rect); |
| 350 | #endif |
| 351 | |
| 352 | skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); } |
| 353 | SkCanvas* sk_canvas() const { return canvas_; } |
| 354 | |
| 355 | private: |
| 356 | // Test whether the provided rectangle intersects the current clip rect. |
| 357 | bool IntersectsClipRectInt(int x, int y, int w, int h); |
[email protected] | 0834e1b1 | 2012-04-11 02:23:56 | [diff] [blame] | 358 | bool IntersectsClipRect(const gfx::Rect& rect); |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 359 | |
[email protected] | 35d5334 | 2012-05-16 21:30:12 | [diff] [blame] | 360 | // Returns the bitmap whose density best matches the current canvas scale. |
| 361 | // Returns a null bitmap if |image| contains no bitmaps. |
| 362 | // |bitmap_scale_factor| is set to the scale factor of the returned bitmap. |
| 363 | // Builds mip map for returned bitmap if necessary. |
| 364 | // |
| 365 | // An optional additional user defined scale can be provided. |
| 366 | const SkBitmap& GetBitmapToPaint(const gfx::ImageSkia& image, |
| 367 | float* bitmap_scale_factor) const; |
| 368 | const SkBitmap& GetBitmapToPaint(const gfx::ImageSkia& image, |
| 369 | float user_defined_scale_factor_x, |
| 370 | float user_defined_scale_factor_y, |
| 371 | float* bitmap_scale_factor) const; |
| 372 | |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 373 | #if defined(OS_WIN) |
| 374 | // Draws text with the specified color, font and location. The text is |
| 375 | // aligned to the left, vertically centered, clipped to the region. If the |
| 376 | // text is too big, it is truncated and '...' is added to the end. |
| 377 | void DrawStringInt(const string16& text, |
| 378 | HFONT font, |
[email protected] | 1b81ff2 | 2012-03-24 22:04:42 | [diff] [blame] | 379 | SkColor color, |
[email protected] | 0834e1b1 | 2012-04-11 02:23:56 | [diff] [blame] | 380 | const gfx::Rect& text_bounds, |
[email protected] | 3127f663 | 2012-03-17 00:14:06 | [diff] [blame] | 381 | int flags); |
| 382 | #endif |
| 383 | |
| 384 | scoped_ptr<skia::PlatformCanvas> owned_canvas_; |
| 385 | SkCanvas* canvas_; |
| 386 | |
| 387 | DISALLOW_COPY_AND_ASSIGN(Canvas); |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 388 | }; |
| 389 | |
[email protected] | 7fe2839 | 2011-10-27 00:16:05 | [diff] [blame] | 390 | } // namespace gfx |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 391 | |
| 392 | #endif // UI_GFX_CANVAS_H_ |