blob: b3be76a839c98f7e53904074eda509127331a929 [file] [log] [blame]
[email protected]fa8cfb02012-01-13 00:27:411// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]267c03d2011-02-02 23:03:072// 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_
[email protected]267c03d2011-02-02 23:03:077
[email protected]0834e1b12012-04-11 02:23:568#include <vector>
9
[email protected]3127f6632012-03-17 00:14:0610#include "base/basictypes.h"
11#include "base/memory/scoped_ptr.h"
[email protected]f3652ff92013-06-11 13:54:3112#include "base/strings/string16.h"
[email protected]3127f6632012-03-17 00:14:0613#include "skia/ext/platform_canvas.h"
[email protected]3699ae5a2012-12-05 01:00:5414#include "skia/ext/refptr.h"
[email protected]35d53342012-05-16 21:30:1215#include "ui/gfx/image/image_skia.h"
[email protected]3127f6632012-03-17 00:14:0616#include "ui/gfx/native_widget_types.h"
[email protected]25650682012-05-29 23:09:1917#include "ui/gfx/shadow_value.h"
[email protected]3127f6632012-03-17 00:14:0618
[email protected]267c03d2011-02-02 23:03:0719namespace gfx {
20
[email protected]3127f6632012-03-17 00:14:0621class Rect;
[email protected]ad8d9d52013-08-22 07:20:0522class FontList;
[email protected]3127f6632012-03-17 00:14:0623class Point;
24class Size;
[email protected]0f0453e2012-10-14 18:15:3525class Transform;
[email protected]3127f6632012-03-17 00:14:0626
27// Canvas is a SkCanvas wrapper that provides a number of methods for
28// common operations used throughout an application built using ui/gfx.
29//
30// All methods that take integer arguments (as is used throughout views)
31// end with Int. If you need to use methods provided by SkCanvas, you'll
32// need to do a conversion. In particular you'll need to use |SkIntToScalar()|,
33// or if converting from a scalar to an integer |SkScalarRound()|.
34//
35// A handful of methods in this class are overloaded providing an additional
36// argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the
37// source and destination colors are combined. Unless otherwise specified,
38// the variant that does not take a SkXfermode::Mode uses a transfer mode
39// of kSrcOver_Mode.
[email protected]4ffa7892013-09-27 16:56:0640class GFX_EXPORT Canvas {
[email protected]267c03d2011-02-02 23:03:0741 public:
[email protected]3127f6632012-03-17 00:14:0642 enum TruncateFadeMode {
43 TruncateFadeTail,
44 TruncateFadeHead,
[email protected]3127f6632012-03-17 00:14:0645 };
46
[email protected]399c4632014-01-30 17:42:4247 // Specifies the alignment for text rendered with the DrawStringRect method.
[email protected]3127f6632012-03-17 00:14:0648 enum {
49 TEXT_ALIGN_LEFT = 1 << 0,
50 TEXT_ALIGN_CENTER = 1 << 1,
[email protected]ff1af582012-11-06 03:34:1251 TEXT_ALIGN_RIGHT = 1 << 2,
[email protected]3127f6632012-03-17 00:14:0652
53 // Specifies the text consists of multiple lines.
[email protected]ff1af582012-11-06 03:34:1254 MULTI_LINE = 1 << 3,
[email protected]3127f6632012-03-17 00:14:0655
[email protected]399c4632014-01-30 17:42:4256 // By default DrawStringRect does not process the prefix ('&') character
[email protected]3127f6632012-03-17 00:14:0657 // specially. That is, the string "&foo" is rendered as "&foo". When
58 // rendering text from a resource that uses the prefix character for
59 // mnemonics, the prefix should be processed and can be rendered as an
60 // underline (SHOW_PREFIX), or not rendered at all (HIDE_PREFIX).
[email protected]ff1af582012-11-06 03:34:1261 SHOW_PREFIX = 1 << 4,
62 HIDE_PREFIX = 1 << 5,
[email protected]3127f6632012-03-17 00:14:0663
64 // Prevent ellipsizing
[email protected]ff1af582012-11-06 03:34:1265 NO_ELLIPSIS = 1 << 6,
[email protected]3127f6632012-03-17 00:14:0666
67 // Specifies if words can be split by new lines.
68 // This only works with MULTI_LINE.
[email protected]ff1af582012-11-06 03:34:1269 CHARACTER_BREAK = 1 << 7,
[email protected]3127f6632012-03-17 00:14:0670
[email protected]399c4632014-01-30 17:42:4271 // Instructs DrawStringRect() to render the text using RTL directionality.
[email protected]3127f6632012-03-17 00:14:0672 // In most cases, passing this flag is not necessary because information
73 // about the text directionality is going to be embedded within the string
74 // in the form of special Unicode characters. However, we don't insert
75 // directionality characters into strings if the locale is LTR because some
76 // platforms (for example, an English Windows XP with no RTL fonts
77 // installed) don't support these characters. Thus, this flag should be
78 // used to render text using RTL directionality when the locale is LTR.
[email protected]ff1af582012-11-06 03:34:1279 FORCE_RTL_DIRECTIONALITY = 1 << 8,
[email protected]3127f6632012-03-17 00:14:0680
81 // Similar to FORCE_RTL_DIRECTIONALITY, but left-to-right.
82 // See FORCE_RTL_DIRECTIONALITY for details.
[email protected]ff1af582012-11-06 03:34:1283 FORCE_LTR_DIRECTIONALITY = 1 << 9,
[email protected]3127f6632012-03-17 00:14:0684
[email protected]399c4632014-01-30 17:42:4285 // Instructs DrawStringRect() to not use subpixel rendering. This is useful
[email protected]3127f6632012-03-17 00:14:0686 // when rendering text onto a fully- or partially-transparent background
87 // that will later be blended with another image.
[email protected]ff1af582012-11-06 03:34:1288 NO_SUBPIXEL_RENDERING = 1 << 10,
[email protected]3127f6632012-03-17 00:14:0689 };
90
[email protected]50b66262013-09-24 03:25:4891 // Creates an empty canvas with image_scale of 1x.
[email protected]94a0d2582012-03-09 00:30:5992 Canvas();
[email protected]267c03d2011-02-02 23:03:0793
[email protected]50b66262013-09-24 03:25:4894 // Creates canvas with provided DIP |size| and |image_scale|.
[email protected]3b2591a2012-06-27 17:58:4195 // If this canvas is not opaque, it's explicitly cleared to transparent before
96 // being returned.
[email protected]50b66262013-09-24 03:25:4897 Canvas(const Size& size, float image_scale, bool is_opaque);
[email protected]3127f6632012-03-17 00:14:0698
[email protected]50b66262013-09-24 03:25:4899 // Constructs a canvas with the size and the image_scale of the provided
100 // |image_rep|, and draws the |image_rep| into it.
[email protected]ad8d9d52013-08-22 07:20:05101 Canvas(const ImageSkiaRep& image_rep, bool is_opaque);
[email protected]3b2591a2012-06-27 17:58:41102
[email protected]57047da2012-07-23 20:55:08103 virtual ~Canvas();
[email protected]f7fc60212012-07-23 20:27:08104
[email protected]50b66262013-09-24 03:25:48105 // Creates a Canvas backed by an |sk_canvas| with |image_scale_|.
106 // |sk_canvas| is assumed to be already scaled based on |image_scale|
[email protected]de13f352012-07-24 16:51:16107 // so no additional scaling is applied.
108 static Canvas* CreateCanvasWithoutScaling(SkCanvas* sk_canvas,
[email protected]50b66262013-09-24 03:25:48109 float image_scale);
[email protected]de13f352012-07-24 16:51:16110
[email protected]50b66262013-09-24 03:25:48111 // Recreates the backing platform canvas with DIP |size| and |image_scale_|.
[email protected]3b2591a2012-06-27 17:58:41112 // If the canvas is not opaque, it is explicitly cleared.
113 // This method is public so that canvas_skia_paint can recreate the platform
114 // canvas after having initialized the canvas.
[email protected]50b66262013-09-24 03:25:48115 // TODO(pkotwicz): Push the image_scale into skia::PlatformCanvas such that
[email protected]3b2591a2012-06-27 17:58:41116 // this method can be private.
[email protected]ad8d9d52013-08-22 07:20:05117 void RecreateBackingCanvas(const Size& size,
[email protected]50b66262013-09-24 03:25:48118 float image_scale,
[email protected]3b2591a2012-06-27 17:58:41119 bool is_opaque);
120
[email protected]ad8d9d52013-08-22 07:20:05121 // Compute the size required to draw some text with the provided fonts.
[email protected]3127f6632012-03-17 00:14:06122 // Attempts to fit the text with the provided width and height. Increases
123 // height and then width as needed to make the text fit. This method
[email protected]561f7482013-04-19 03:39:58124 // supports multiple lines. On Skia only a line_height can be specified and
125 // specifying a 0 value for it will cause the default height to be used.
[email protected]031ffed2013-06-09 03:32:36126 static void SizeStringInt(const base::string16& text,
[email protected]ad8d9d52013-08-22 07:20:05127 const FontList& font_list,
128 int* width,
129 int* height,
130 int line_height,
131 int flags);
[email protected]3127f6632012-03-17 00:14:06132
[email protected]8ad3c5a2013-10-10 09:57:19133 // This is same as SizeStringInt except that fractional size is returned.
134 // See comment in GetStringWidthF for its usage.
135 static void SizeStringFloat(const base::string16& text,
136 const FontList& font_list,
137 float* width,
138 float* height,
139 int line_height,
140 int flags);
141
[email protected]3127f6632012-03-17 00:14:06142 // Returns the number of horizontal pixels needed to display the specified
[email protected]ad8d9d52013-08-22 07:20:05143 // |text| with |font_list|.
144 static int GetStringWidth(const base::string16& text,
145 const FontList& font_list);
[email protected]3127f6632012-03-17 00:14:06146
[email protected]8ad3c5a2013-10-10 09:57:19147 // This is same as GetStringWidth except that fractional width is returned.
148 // Use this method for the scenario that multiple string widths need to be
149 // summed up. This is because GetStringWidth returns the ceiled width and
150 // adding multiple ceiled widths could cause more precision loss for certain
151 // platform like Mac where the fractioal width is used.
152 static float GetStringWidthF(const base::string16& text,
153 const FontList& font_list);
154
[email protected]3127f6632012-03-17 00:14:06155 // Returns the default text alignment to be used when drawing text on a
[email protected]ad8d9d52013-08-22 07:20:05156 // Canvas based on the directionality of the system locale language.
[email protected]399c4632014-01-30 17:42:42157 // This function is used by Canvas::DrawStringRect when the text alignment
[email protected]3127f6632012-03-17 00:14:06158 // is not specified.
159 //
[email protected]ad8d9d52013-08-22 07:20:05160 // This function returns either Canvas::TEXT_ALIGN_LEFT or
161 // Canvas::TEXT_ALIGN_RIGHT.
[email protected]3127f6632012-03-17 00:14:06162 static int DefaultCanvasTextAlignment();
163
164 // Draws text with a 1-pixel halo around it of the given color.
[email protected]ad8d9d52013-08-22 07:20:05165 // On Windows, it allows ClearType to be drawn to an otherwise transparent
[email protected]3127f6632012-03-17 00:14:06166 // bitmap for drag images. Drag images have only 1-bit of transparency, so
167 // we don't do any fancy blurring.
168 // On Linux, text with halo is created by stroking it with 2px |halo_color|
169 // then filling it with |text_color|.
170 // On Mac, NOTIMPLEMENTED.
171 // TODO(dhollowa): Skia-native implementation is underway. Cut over to
172 // that when ready. http::/crbug.com/109946
[email protected]ad8d9d52013-08-22 07:20:05173 void DrawStringRectWithHalo(const base::string16& text,
174 const FontList& font_list,
175 SkColor text_color,
176 SkColor halo_color,
177 const Rect& display_rect,
178 int flags);
[email protected]3127f6632012-03-17 00:14:06179
[email protected]3b2591a2012-06-27 17:58:41180 // Extracts an ImageSkiaRep from the contents of this canvas.
[email protected]ad8d9d52013-08-22 07:20:05181 ImageSkiaRep ExtractImageRep() const;
[email protected]3b2591a2012-06-27 17:58:41182
[email protected]3127f6632012-03-17 00:14:06183 // Draws a dashed rectangle of the specified color.
[email protected]ad8d9d52013-08-22 07:20:05184 void DrawDashedRect(const Rect& rect, SkColor color);
[email protected]3127f6632012-03-17 00:14:06185
186 // Saves a copy of the drawing state onto a stack, operating on this copy
187 // until a balanced call to Restore() is made.
188 void Save();
189
190 // As with Save(), except draws to a layer that is blended with the canvas
191 // at the specified alpha once Restore() is called.
192 // |layer_bounds| are the bounds of the layer relative to the current
193 // transform.
194 void SaveLayerAlpha(uint8 alpha);
[email protected]ad8d9d52013-08-22 07:20:05195 void SaveLayerAlpha(uint8 alpha, const Rect& layer_bounds);
[email protected]3127f6632012-03-17 00:14:06196
197 // Restores the drawing state after a call to Save*(). It is an error to
198 // call Restore() more times than Save*().
[email protected]964c429d2012-10-25 15:28:45199 void Restore();
[email protected]3127f6632012-03-17 00:14:06200
[email protected]a91031712014-03-03 15:41:16201 // Adds |rect| to the current clip.
202 void ClipRect(const Rect& rect);
[email protected]3127f6632012-03-17 00:14:06203
[email protected]a91031712014-03-03 15:41:16204 // Adds |path| to the current clip.
205 void ClipPath(const SkPath& path);
206
207 // Returns true if the current clip is empty.
208 bool IsClipEmpty() const;
[email protected]ffdd1fd2012-04-09 23:24:41209
210 // Returns the bounds of the current clip (in local coordinates) in the
211 // |bounds| parameter, and returns true if it is non empty.
[email protected]ad8d9d52013-08-22 07:20:05212 bool GetClipBounds(Rect* bounds);
[email protected]ffdd1fd2012-04-09 23:24:41213
[email protected]ad8d9d52013-08-22 07:20:05214 void Translate(const Vector2d& offset);
[email protected]3127f6632012-03-17 00:14:06215
216 void Scale(int x_scale, int y_scale);
217
[email protected]ffdd1fd2012-04-09 23:24:41218 // Fills the entire canvas' bitmap (restricted to current clip) with
219 // specified |color| using a transfer mode of SkXfermode::kSrcOver_Mode.
220 void DrawColor(SkColor color);
221
222 // Fills the entire canvas' bitmap (restricted to current clip) with
223 // specified |color| and |mode|.
224 void DrawColor(SkColor color, SkXfermode::Mode mode);
225
[email protected]3127f6632012-03-17 00:14:06226 // Fills |rect| with |color| using a transfer mode of
227 // SkXfermode::kSrcOver_Mode.
[email protected]ad8d9d52013-08-22 07:20:05228 void FillRect(const Rect& rect, SkColor color);
[email protected]3127f6632012-03-17 00:14:06229
230 // Fills |rect| with the specified |color| and |mode|.
[email protected]ad8d9d52013-08-22 07:20:05231 void FillRect(const Rect& rect, SkColor color, SkXfermode::Mode mode);
[email protected]3127f6632012-03-17 00:14:06232
[email protected]3127f6632012-03-17 00:14:06233 // Draws a single pixel rect in the specified region with the specified
234 // color, using a transfer mode of SkXfermode::kSrcOver_Mode.
235 //
236 // NOTE: if you need a single pixel line, use DrawLine.
[email protected]ad8d9d52013-08-22 07:20:05237 void DrawRect(const Rect& rect, SkColor color);
[email protected]3127f6632012-03-17 00:14:06238
239 // Draws a single pixel rect in the specified region with the specified
240 // color and transfer mode.
241 //
242 // NOTE: if you need a single pixel line, use DrawLine.
[email protected]ad8d9d52013-08-22 07:20:05243 void DrawRect(const Rect& rect, SkColor color, SkXfermode::Mode mode);
[email protected]3127f6632012-03-17 00:14:06244
[email protected]ffdd1fd2012-04-09 23:24:41245 // Draws the given rectangle with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05246 void DrawRect(const Rect& rect, const SkPaint& paint);
[email protected]3127f6632012-03-17 00:14:06247
[email protected]ffdd1fd2012-04-09 23:24:41248 // Draw the given point with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05249 void DrawPoint(const Point& p, const SkPaint& paint);
[email protected]ffdd1fd2012-04-09 23:24:41250
[email protected]3127f6632012-03-17 00:14:06251 // Draws a single pixel line with the specified color.
[email protected]ad8d9d52013-08-22 07:20:05252 void DrawLine(const Point& p1, const Point& p2, SkColor color);
[email protected]3127f6632012-03-17 00:14:06253
[email protected]ffdd1fd2012-04-09 23:24:41254 // Draws a line with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05255 void DrawLine(const Point& p1, const Point& p2, const SkPaint& paint);
[email protected]ffdd1fd2012-04-09 23:24:41256
257 // Draws a circle with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05258 void DrawCircle(const Point& center_point,
[email protected]ffdd1fd2012-04-09 23:24:41259 int radius,
260 const SkPaint& paint);
261
262 // Draws the given rectangle with rounded corners of |radius| using the
263 // given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05264 void DrawRoundRect(const Rect& rect, int radius, const SkPaint& paint);
[email protected]ffdd1fd2012-04-09 23:24:41265
266 // Draws the given path using the given |paint| parameters.
267 void DrawPath(const SkPath& path, const SkPaint& paint);
268
[email protected]35d53342012-05-16 21:30:12269 // Draws an image with the origin at the specified location. The upper left
[email protected]3127f6632012-03-17 00:14:06270 // corner of the bitmap is rendered at the specified location.
[email protected]35d53342012-05-16 21:30:12271 // Parameters are specified relative to current canvas scale not in pixels.
[email protected]8232da6b2012-07-02 19:41:15272 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05273 void DrawImageInt(const ImageSkia&, int x, int y);
[email protected]3127f6632012-03-17 00:14:06274
[email protected]2885cb32012-10-03 19:41:11275 // Helper for DrawImageInt(..., paint) that constructs a temporary paint and
276 // calls paint.setAlpha(alpha).
[email protected]ad8d9d52013-08-22 07:20:05277 void DrawImageInt(const ImageSkia&, int x, int y, uint8 alpha);
[email protected]2885cb32012-10-03 19:41:11278
[email protected]35d53342012-05-16 21:30:12279 // Draws an image with the origin at the specified location, using the
[email protected]3127f6632012-03-17 00:14:06280 // specified paint. The upper left corner of the bitmap is rendered at the
281 // specified location.
[email protected]35d53342012-05-16 21:30:12282 // Parameters are specified relative to current canvas scale not in pixels.
283 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05284 void DrawImageInt(const ImageSkia& image,
285 int x,
286 int y,
[email protected]243cac7d2012-06-07 13:29:20287 const SkPaint& paint);
[email protected]3127f6632012-03-17 00:14:06288
[email protected]35d53342012-05-16 21:30:12289 // Draws a portion of an image in the specified location. The src parameters
[email protected]3127f6632012-03-17 00:14:06290 // correspond to the region of the bitmap to draw in the region defined
291 // by the dest coordinates.
292 //
293 // If the width or height of the source differs from that of the destination,
[email protected]35d53342012-05-16 21:30:12294 // the image will be scaled. When scaling down, a mipmap will be generated.
295 // Set |filter| to use filtering for images, otherwise the nearest-neighbor
296 // algorithm is used for resampling.
[email protected]3127f6632012-03-17 00:14:06297 //
298 // An optional custom SkPaint can be provided.
[email protected]35d53342012-05-16 21:30:12299 // Parameters are specified relative to current canvas scale not in pixels.
300 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05301 void DrawImageInt(const ImageSkia& image,
302 int src_x,
303 int src_y,
304 int src_w,
305 int src_h,
306 int dest_x,
307 int dest_y,
308 int dest_w,
309 int dest_h,
[email protected]243cac7d2012-06-07 13:29:20310 bool filter);
[email protected]ad8d9d52013-08-22 07:20:05311 void DrawImageInt(const ImageSkia& image,
312 int src_x,
313 int src_y,
314 int src_w,
315 int src_h,
316 int dest_x,
317 int dest_y,
318 int dest_w,
319 int dest_h,
[email protected]243cac7d2012-06-07 13:29:20320 bool filter,
321 const SkPaint& paint);
[email protected]3127f6632012-03-17 00:14:06322
[email protected]8232da6b2012-07-02 19:41:15323 // Draws an |image| with the top left corner at |x| and |y|, clipped to
324 // |path|.
325 // Parameters are specified relative to current canvas scale not in pixels.
326 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05327 void DrawImageInPath(const ImageSkia& image,
[email protected]8232da6b2012-07-02 19:41:15328 int x,
329 int y,
330 const SkPath& path,
331 const SkPaint& paint);
332
[email protected]ad8d9d52013-08-22 07:20:05333 // Draws text with the specified color, fonts and location. The text is
[email protected]3127f6632012-03-17 00:14:06334 // aligned to the left, vertically centered, clipped to the region. If the
335 // text is too big, it is truncated and '...' is added to the end.
[email protected]ad8d9d52013-08-22 07:20:05336 void DrawStringRect(const base::string16& text,
337 const FontList& font_list,
338 SkColor color,
339 const Rect& display_rect);
[email protected]3127f6632012-03-17 00:14:06340
[email protected]ad8d9d52013-08-22 07:20:05341 // Draws text with the specified color, fonts and location. The last argument
[email protected]3127f6632012-03-17 00:14:06342 // specifies flags for how the text should be rendered. It can be one of
343 // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT.
[email protected]ad8d9d52013-08-22 07:20:05344 void DrawStringRectWithFlags(const base::string16& text,
345 const FontList& font_list,
346 SkColor color,
347 const Rect& display_rect,
348 int flags);
[email protected]3127f6632012-03-17 00:14:06349
[email protected]399c4632014-01-30 17:42:42350 // Similar to above DrawStringRect method but with text shadows support.
[email protected]561f7482013-04-19 03:39:58351 // Currently it's only implemented for canvas skia. Specifying a 0 line_height
352 // will cause the default height to be used.
[email protected]ad8d9d52013-08-22 07:20:05353 void DrawStringRectWithShadows(const base::string16& text,
354 const FontList& font_list,
355 SkColor color,
356 const Rect& text_bounds,
357 int line_height,
358 int flags,
359 const ShadowValues& shadows);
[email protected]0834e1b12012-04-11 02:23:56360
[email protected]3127f6632012-03-17 00:14:06361 // Draws a dotted gray rectangle used for focus purposes.
[email protected]ad8d9d52013-08-22 07:20:05362 void DrawFocusRect(const Rect& rect);
[email protected]3127f6632012-03-17 00:14:06363
[email protected]5db93a12013-12-02 21:07:31364 // Draws a |rect| in the specified region with the specified |color| with a
365 // with of one logical pixel which might be more device pixels.
366 void DrawSolidFocusRect(const Rect& rect, SkColor color);
367
[email protected]3127f6632012-03-17 00:14:06368 // Tiles the image in the specified region.
[email protected]35d53342012-05-16 21:30:12369 // Parameters are specified relative to current canvas scale not in pixels.
370 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05371 void TileImageInt(const ImageSkia& image,
372 int x,
373 int y,
374 int w,
375 int h);
376 void TileImageInt(const ImageSkia& image,
377 int src_x,
378 int src_y,
379 int dest_x,
380 int dest_y,
381 int w,
382 int h);
383 void TileImageInt(const ImageSkia& image,
384 int src_x,
385 int src_y,
386 float tile_scale_x,
387 float tile_scale_y,
388 int dest_x,
389 int dest_y,
390 int w,
391 int h);
[email protected]3127f6632012-03-17 00:14:06392
393 // Returns a native drawing context for platform specific drawing routines to
394 // use. Must be balanced by a call to EndPlatformPaint().
395 NativeDrawingContext BeginPlatformPaint();
396
397 // Signifies the end of platform drawing using the native drawing context
398 // returned by BeginPlatformPaint().
399 void EndPlatformPaint();
400
401 // Apply transformation on the canvas.
[email protected]ad8d9d52013-08-22 07:20:05402 void Transform(const Transform& transform);
[email protected]3127f6632012-03-17 00:14:06403
[email protected]657d679b2013-10-30 03:56:22404 // Draws the given string with the beginning or the end using a fade gradient.
[email protected]ad8d9d52013-08-22 07:20:05405 void DrawFadeTruncatingStringRect(
406 const base::string16& text,
407 TruncateFadeMode truncate_mode,
[email protected]ad8d9d52013-08-22 07:20:05408 const FontList& font_list,
409 SkColor color,
410 const Rect& display_rect);
[email protected]ebb1fedb2013-10-31 04:11:21411 void DrawFadeTruncatingStringRectWithFlags(
412 const base::string16& text,
413 TruncateFadeMode truncate_mode,
414 const FontList& font_list,
415 SkColor color,
416 const Rect& display_rect,
417 int flags);
[email protected]3127f6632012-03-17 00:14:06418
419 skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); }
420 SkCanvas* sk_canvas() const { return canvas_; }
[email protected]50b66262013-09-24 03:25:48421 float image_scale() const { return image_scale_; }
[email protected]3127f6632012-03-17 00:14:06422
423 private:
[email protected]50b66262013-09-24 03:25:48424 Canvas(SkCanvas* canvas, float image_scale);
[email protected]de13f352012-07-24 16:51:16425
[email protected]3127f6632012-03-17 00:14:06426 // Test whether the provided rectangle intersects the current clip rect.
427 bool IntersectsClipRectInt(int x, int y, int w, int h);
[email protected]ad8d9d52013-08-22 07:20:05428 bool IntersectsClipRect(const Rect& rect);
[email protected]3127f6632012-03-17 00:14:06429
[email protected]50b66262013-09-24 03:25:48430 // Returns the image rep which best matches the canvas |image_scale_|.
[email protected]8232da6b2012-07-02 19:41:15431 // Returns a null image rep if |image| contains no image reps.
432 // Builds mip map for returned image rep if necessary.
[email protected]35d53342012-05-16 21:30:12433 //
434 // An optional additional user defined scale can be provided.
[email protected]ad8d9d52013-08-22 07:20:05435 const ImageSkiaRep& GetImageRepToPaint(const ImageSkia& image) const;
436 const ImageSkiaRep& GetImageRepToPaint(
437 const ImageSkia& image,
[email protected]8232da6b2012-07-02 19:41:15438 float user_defined_scale_factor_x,
[email protected]ad8d9d52013-08-22 07:20:05439 float user_defined_scale_factor_y) const;
[email protected]35d53342012-05-16 21:30:12440
[email protected]3b2591a2012-06-27 17:58:41441 // The device scale factor at which drawing on this canvas occurs.
442 // An additional scale can be applied via Canvas::Scale(). However,
[email protected]50b66262013-09-24 03:25:48443 // Canvas::Scale() does not affect |image_scale_|.
444 float image_scale_;
[email protected]3b2591a2012-06-27 17:58:41445
[email protected]3699ae5a2012-12-05 01:00:54446 skia::RefPtr<skia::PlatformCanvas> owned_canvas_;
[email protected]de13f352012-07-24 16:51:16447 SkCanvas* canvas_;
448
[email protected]3127f6632012-03-17 00:14:06449 DISALLOW_COPY_AND_ASSIGN(Canvas);
[email protected]267c03d2011-02-02 23:03:07450};
451
[email protected]7fe28392011-10-27 00:16:05452} // namespace gfx
[email protected]267c03d2011-02-02 23:03:07453
454#endif // UI_GFX_CANVAS_H_