blob: d154962e7b5521b12a2c37c321a2bd3235084f9d [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]f3ce6212014-06-05 22:42:0818#include "ui/gfx/text_constants.h"
[email protected]3127f6632012-03-17 00:14:0619
[email protected]267c03d2011-02-02 23:03:0720namespace gfx {
21
[email protected]3127f6632012-03-17 00:14:0622class Rect;
mgiuca9a713fe12015-11-10 02:53:3023class RectF;
[email protected]ad8d9d52013-08-22 07:20:0524class FontList;
[email protected]3127f6632012-03-17 00:14:0625class Point;
26class Size;
[email protected]0f0453e2012-10-14 18:15:3527class Transform;
[email protected]3127f6632012-03-17 00:14:0628
29// Canvas is a SkCanvas wrapper that provides a number of methods for
30// common operations used throughout an application built using ui/gfx.
31//
32// All methods that take integer arguments (as is used throughout views)
33// end with Int. If you need to use methods provided by SkCanvas, you'll
34// need to do a conversion. In particular you'll need to use |SkIntToScalar()|,
35// or if converting from a scalar to an integer |SkScalarRound()|.
36//
37// A handful of methods in this class are overloaded providing an additional
38// argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the
39// source and destination colors are combined. Unless otherwise specified,
40// the variant that does not take a SkXfermode::Mode uses a transfer mode
41// of kSrcOver_Mode.
[email protected]4ffa7892013-09-27 16:56:0642class GFX_EXPORT Canvas {
[email protected]267c03d2011-02-02 23:03:0743 public:
[email protected]3127f6632012-03-17 00:14:0644 enum {
oshima7410ba72015-03-05 00:08:3845 // Specifies the alignment for text rendered with the DrawStringRect method.
[email protected]3127f6632012-03-17 00:14:0646 TEXT_ALIGN_LEFT = 1 << 0,
47 TEXT_ALIGN_CENTER = 1 << 1,
[email protected]ff1af582012-11-06 03:34:1248 TEXT_ALIGN_RIGHT = 1 << 2,
oshima7410ba72015-03-05 00:08:3849 TEXT_ALIGN_TO_HEAD = 1 << 3,
[email protected]3127f6632012-03-17 00:14:0650
51 // Specifies the text consists of multiple lines.
oshima7410ba72015-03-05 00:08:3852 MULTI_LINE = 1 << 4,
[email protected]3127f6632012-03-17 00:14:0653
[email protected]399c4632014-01-30 17:42:4254 // By default DrawStringRect does not process the prefix ('&') character
[email protected]3127f6632012-03-17 00:14:0655 // specially. That is, the string "&foo" is rendered as "&foo". When
56 // rendering text from a resource that uses the prefix character for
57 // mnemonics, the prefix should be processed and can be rendered as an
58 // underline (SHOW_PREFIX), or not rendered at all (HIDE_PREFIX).
oshima7410ba72015-03-05 00:08:3859 SHOW_PREFIX = 1 << 5,
60 HIDE_PREFIX = 1 << 6,
[email protected]3127f6632012-03-17 00:14:0661
62 // Prevent ellipsizing
oshima7410ba72015-03-05 00:08:3863 NO_ELLIPSIS = 1 << 7,
[email protected]3127f6632012-03-17 00:14:0664
65 // Specifies if words can be split by new lines.
66 // This only works with MULTI_LINE.
oshima7410ba72015-03-05 00:08:3867 CHARACTER_BREAK = 1 << 8,
[email protected]3127f6632012-03-17 00:14:0668
[email protected]399c4632014-01-30 17:42:4269 // Instructs DrawStringRect() to not use subpixel rendering. This is useful
[email protected]3127f6632012-03-17 00:14:0670 // when rendering text onto a fully- or partially-transparent background
71 // that will later be blended with another image.
oshima7410ba72015-03-05 00:08:3872 NO_SUBPIXEL_RENDERING = 1 << 9,
[email protected]3127f6632012-03-17 00:14:0673 };
74
[email protected]50b66262013-09-24 03:25:4875 // Creates an empty canvas with image_scale of 1x.
[email protected]94a0d2582012-03-09 00:30:5976 Canvas();
[email protected]267c03d2011-02-02 23:03:0777
[email protected]50b66262013-09-24 03:25:4878 // Creates canvas with provided DIP |size| and |image_scale|.
[email protected]3b2591a2012-06-27 17:58:4179 // If this canvas is not opaque, it's explicitly cleared to transparent before
80 // being returned.
[email protected]50b66262013-09-24 03:25:4881 Canvas(const Size& size, float image_scale, bool is_opaque);
[email protected]3127f6632012-03-17 00:14:0682
[email protected]50b66262013-09-24 03:25:4883 // Constructs a canvas with the size and the image_scale of the provided
84 // |image_rep|, and draws the |image_rep| into it.
[email protected]ad8d9d52013-08-22 07:20:0585 Canvas(const ImageSkiaRep& image_rep, bool is_opaque);
[email protected]3b2591a2012-06-27 17:58:4186
[email protected]50b66262013-09-24 03:25:4887 // Creates a Canvas backed by an |sk_canvas| with |image_scale_|.
88 // |sk_canvas| is assumed to be already scaled based on |image_scale|
[email protected]de13f352012-07-24 16:51:1689 // so no additional scaling is applied.
danakj8fa739b62015-05-12 02:10:0690 Canvas(SkCanvas* sk_canvas, float image_scale);
91
92 virtual ~Canvas();
[email protected]de13f352012-07-24 16:51:1693
[email protected]50b66262013-09-24 03:25:4894 // Recreates the backing platform canvas with DIP |size| and |image_scale_|.
[email protected]3b2591a2012-06-27 17:58:4195 // If the canvas is not opaque, it is explicitly cleared.
96 // This method is public so that canvas_skia_paint can recreate the platform
97 // canvas after having initialized the canvas.
[email protected]50b66262013-09-24 03:25:4898 // TODO(pkotwicz): Push the image_scale into skia::PlatformCanvas such that
[email protected]3b2591a2012-06-27 17:58:4199 // this method can be private.
[email protected]ad8d9d52013-08-22 07:20:05100 void RecreateBackingCanvas(const Size& size,
[email protected]50b66262013-09-24 03:25:48101 float image_scale,
[email protected]3b2591a2012-06-27 17:58:41102 bool is_opaque);
103
[email protected]ad8d9d52013-08-22 07:20:05104 // Compute the size required to draw some text with the provided fonts.
[email protected]3127f6632012-03-17 00:14:06105 // Attempts to fit the text with the provided width and height. Increases
106 // height and then width as needed to make the text fit. This method
[email protected]561f7482013-04-19 03:39:58107 // supports multiple lines. On Skia only a line_height can be specified and
108 // specifying a 0 value for it will cause the default height to be used.
[email protected]031ffed2013-06-09 03:32:36109 static void SizeStringInt(const base::string16& text,
[email protected]ad8d9d52013-08-22 07:20:05110 const FontList& font_list,
111 int* width,
112 int* height,
113 int line_height,
114 int flags);
[email protected]3127f6632012-03-17 00:14:06115
[email protected]8ad3c5a2013-10-10 09:57:19116 // This is same as SizeStringInt except that fractional size is returned.
117 // See comment in GetStringWidthF for its usage.
118 static void SizeStringFloat(const base::string16& text,
119 const FontList& font_list,
120 float* width,
121 float* height,
122 int line_height,
123 int flags);
124
[email protected]3127f6632012-03-17 00:14:06125 // Returns the number of horizontal pixels needed to display the specified
[email protected]ad8d9d52013-08-22 07:20:05126 // |text| with |font_list|.
127 static int GetStringWidth(const base::string16& text,
128 const FontList& font_list);
[email protected]3127f6632012-03-17 00:14:06129
[email protected]8ad3c5a2013-10-10 09:57:19130 // This is same as GetStringWidth except that fractional width is returned.
131 // Use this method for the scenario that multiple string widths need to be
132 // summed up. This is because GetStringWidth returns the ceiled width and
133 // adding multiple ceiled widths could cause more precision loss for certain
134 // platform like Mac where the fractioal width is used.
135 static float GetStringWidthF(const base::string16& text,
136 const FontList& font_list);
137
[email protected]3127f6632012-03-17 00:14:06138 // Returns the default text alignment to be used when drawing text on a
[email protected]ad8d9d52013-08-22 07:20:05139 // Canvas based on the directionality of the system locale language.
[email protected]399c4632014-01-30 17:42:42140 // This function is used by Canvas::DrawStringRect when the text alignment
[email protected]3127f6632012-03-17 00:14:06141 // is not specified.
142 //
[email protected]ad8d9d52013-08-22 07:20:05143 // This function returns either Canvas::TEXT_ALIGN_LEFT or
144 // Canvas::TEXT_ALIGN_RIGHT.
[email protected]3127f6632012-03-17 00:14:06145 static int DefaultCanvasTextAlignment();
146
147 // Draws text with a 1-pixel halo around it of the given color.
[email protected]ad8d9d52013-08-22 07:20:05148 // On Windows, it allows ClearType to be drawn to an otherwise transparent
[email protected]3127f6632012-03-17 00:14:06149 // bitmap for drag images. Drag images have only 1-bit of transparency, so
150 // we don't do any fancy blurring.
151 // On Linux, text with halo is created by stroking it with 2px |halo_color|
152 // then filling it with |text_color|.
153 // On Mac, NOTIMPLEMENTED.
154 // TODO(dhollowa): Skia-native implementation is underway. Cut over to
155 // that when ready. http::/crbug.com/109946
[email protected]ad8d9d52013-08-22 07:20:05156 void DrawStringRectWithHalo(const base::string16& text,
157 const FontList& font_list,
158 SkColor text_color,
159 SkColor halo_color,
160 const Rect& display_rect,
161 int flags);
[email protected]3127f6632012-03-17 00:14:06162
[email protected]3b2591a2012-06-27 17:58:41163 // Extracts an ImageSkiaRep from the contents of this canvas.
[email protected]ad8d9d52013-08-22 07:20:05164 ImageSkiaRep ExtractImageRep() const;
[email protected]3b2591a2012-06-27 17:58:41165
[email protected]3127f6632012-03-17 00:14:06166 // Draws a dashed rectangle of the specified color.
[email protected]ad8d9d52013-08-22 07:20:05167 void DrawDashedRect(const Rect& rect, SkColor color);
[email protected]3127f6632012-03-17 00:14:06168
danakjda764372015-10-30 19:25:16169 // Unscales by the image scale factor (aka device scale factor), and returns
170 // that factor. This is useful when callers want to draw directly in the
171 // native scale.
172 float UndoDeviceScaleFactor();
173
[email protected]3127f6632012-03-17 00:14:06174 // Saves a copy of the drawing state onto a stack, operating on this copy
175 // until a balanced call to Restore() is made.
176 void Save();
177
178 // As with Save(), except draws to a layer that is blended with the canvas
179 // at the specified alpha once Restore() is called.
180 // |layer_bounds| are the bounds of the layer relative to the current
181 // transform.
182 void SaveLayerAlpha(uint8 alpha);
[email protected]ad8d9d52013-08-22 07:20:05183 void SaveLayerAlpha(uint8 alpha, const Rect& layer_bounds);
[email protected]3127f6632012-03-17 00:14:06184
185 // Restores the drawing state after a call to Save*(). It is an error to
186 // call Restore() more times than Save*().
[email protected]964c429d2012-10-25 15:28:45187 void Restore();
[email protected]3127f6632012-03-17 00:14:06188
[email protected]a91031712014-03-03 15:41:16189 // Adds |rect| to the current clip.
190 void ClipRect(const Rect& rect);
[email protected]3127f6632012-03-17 00:14:06191
[email protected]d26b905c2014-05-26 16:43:44192 // Adds |path| to the current clip. |do_anti_alias| is true if the clip
193 // should be antialiased.
194 void ClipPath(const SkPath& path, bool do_anti_alias);
[email protected]a91031712014-03-03 15:41:16195
196 // Returns true if the current clip is empty.
197 bool IsClipEmpty() const;
[email protected]ffdd1fd2012-04-09 23:24:41198
199 // Returns the bounds of the current clip (in local coordinates) in the
200 // |bounds| parameter, and returns true if it is non empty.
[email protected]ad8d9d52013-08-22 07:20:05201 bool GetClipBounds(Rect* bounds);
[email protected]ffdd1fd2012-04-09 23:24:41202
[email protected]ad8d9d52013-08-22 07:20:05203 void Translate(const Vector2d& offset);
[email protected]3127f6632012-03-17 00:14:06204
205 void Scale(int x_scale, int y_scale);
206
[email protected]ffdd1fd2012-04-09 23:24:41207 // Fills the entire canvas' bitmap (restricted to current clip) with
208 // specified |color| using a transfer mode of SkXfermode::kSrcOver_Mode.
209 void DrawColor(SkColor color);
210
211 // Fills the entire canvas' bitmap (restricted to current clip) with
212 // specified |color| and |mode|.
213 void DrawColor(SkColor color, SkXfermode::Mode mode);
214
[email protected]3127f6632012-03-17 00:14:06215 // Fills |rect| with |color| using a transfer mode of
216 // SkXfermode::kSrcOver_Mode.
[email protected]ad8d9d52013-08-22 07:20:05217 void FillRect(const Rect& rect, SkColor color);
[email protected]3127f6632012-03-17 00:14:06218
219 // Fills |rect| with the specified |color| and |mode|.
[email protected]ad8d9d52013-08-22 07:20:05220 void FillRect(const Rect& rect, SkColor color, SkXfermode::Mode mode);
[email protected]3127f6632012-03-17 00:14:06221
[email protected]3127f6632012-03-17 00:14:06222 // Draws a single pixel rect in the specified region with the specified
223 // color, using a transfer mode of SkXfermode::kSrcOver_Mode.
224 //
225 // NOTE: if you need a single pixel line, use DrawLine.
[email protected]ad8d9d52013-08-22 07:20:05226 void DrawRect(const Rect& rect, SkColor color);
[email protected]3127f6632012-03-17 00:14:06227
228 // Draws a single pixel rect in the specified region with the specified
229 // color and transfer mode.
230 //
231 // NOTE: if you need a single pixel line, use DrawLine.
[email protected]ad8d9d52013-08-22 07:20:05232 void DrawRect(const Rect& rect, SkColor color, SkXfermode::Mode mode);
[email protected]3127f6632012-03-17 00:14:06233
[email protected]ffdd1fd2012-04-09 23:24:41234 // Draws the given rectangle with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05235 void DrawRect(const Rect& rect, const SkPaint& paint);
[email protected]3127f6632012-03-17 00:14:06236
[email protected]ffdd1fd2012-04-09 23:24:41237 // Draw the given point with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05238 void DrawPoint(const Point& p, const SkPaint& paint);
[email protected]ffdd1fd2012-04-09 23:24:41239
[email protected]3127f6632012-03-17 00:14:06240 // Draws a single pixel line with the specified color.
[email protected]ad8d9d52013-08-22 07:20:05241 void DrawLine(const Point& p1, const Point& p2, SkColor color);
[email protected]3127f6632012-03-17 00:14:06242
[email protected]ffdd1fd2012-04-09 23:24:41243 // Draws a line with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05244 void DrawLine(const Point& p1, const Point& p2, const SkPaint& paint);
[email protected]ffdd1fd2012-04-09 23:24:41245
246 // Draws a circle with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05247 void DrawCircle(const Point& center_point,
[email protected]ffdd1fd2012-04-09 23:24:41248 int radius,
249 const SkPaint& paint);
250
251 // Draws the given rectangle with rounded corners of |radius| using the
mgiuca9a713fe12015-11-10 02:53:30252 // given |paint| parameters. DEPRECATED in favor of the RectF version below.
253 // TODO(mgiuca): Remove this (http://crbug.com/553726).
[email protected]ad8d9d52013-08-22 07:20:05254 void DrawRoundRect(const Rect& rect, int radius, const SkPaint& paint);
[email protected]ffdd1fd2012-04-09 23:24:41255
mgiuca9a713fe12015-11-10 02:53:30256 // Draws the given rectangle with rounded corners of |radius| using the
257 // given |paint| parameters.
258 void DrawRoundRect(const RectF& rect, float radius, const SkPaint& paint);
259
[email protected]ffdd1fd2012-04-09 23:24:41260 // Draws the given path using the given |paint| parameters.
261 void DrawPath(const SkPath& path, const SkPaint& paint);
262
[email protected]35d53342012-05-16 21:30:12263 // Draws an image with the origin at the specified location. The upper left
[email protected]3127f6632012-03-17 00:14:06264 // corner of the bitmap is rendered at the specified location.
[email protected]35d53342012-05-16 21:30:12265 // Parameters are specified relative to current canvas scale not in pixels.
[email protected]8232da6b2012-07-02 19:41:15266 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05267 void DrawImageInt(const ImageSkia&, int x, int y);
[email protected]3127f6632012-03-17 00:14:06268
[email protected]2885cb32012-10-03 19:41:11269 // Helper for DrawImageInt(..., paint) that constructs a temporary paint and
270 // calls paint.setAlpha(alpha).
[email protected]ad8d9d52013-08-22 07:20:05271 void DrawImageInt(const ImageSkia&, int x, int y, uint8 alpha);
[email protected]2885cb32012-10-03 19:41:11272
[email protected]35d53342012-05-16 21:30:12273 // Draws an image with the origin at the specified location, using the
[email protected]3127f6632012-03-17 00:14:06274 // specified paint. The upper left corner of the bitmap is rendered at the
275 // specified location.
[email protected]35d53342012-05-16 21:30:12276 // Parameters are specified relative to current canvas scale not in pixels.
277 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05278 void DrawImageInt(const ImageSkia& image,
279 int x,
280 int y,
[email protected]243cac7d2012-06-07 13:29:20281 const SkPaint& paint);
[email protected]3127f6632012-03-17 00:14:06282
[email protected]35d53342012-05-16 21:30:12283 // Draws a portion of an image in the specified location. The src parameters
[email protected]3127f6632012-03-17 00:14:06284 // correspond to the region of the bitmap to draw in the region defined
285 // by the dest coordinates.
286 //
287 // If the width or height of the source differs from that of the destination,
[email protected]35d53342012-05-16 21:30:12288 // the image will be scaled. When scaling down, a mipmap will be generated.
289 // Set |filter| to use filtering for images, otherwise the nearest-neighbor
290 // algorithm is used for resampling.
[email protected]3127f6632012-03-17 00:14:06291 //
292 // An optional custom SkPaint can be provided.
[email protected]35d53342012-05-16 21:30:12293 // Parameters are specified relative to current canvas scale not in pixels.
294 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05295 void DrawImageInt(const ImageSkia& image,
296 int src_x,
297 int src_y,
298 int src_w,
299 int src_h,
300 int dest_x,
301 int dest_y,
302 int dest_w,
303 int dest_h,
[email protected]243cac7d2012-06-07 13:29:20304 bool filter);
[email protected]ad8d9d52013-08-22 07:20:05305 void DrawImageInt(const ImageSkia& image,
306 int src_x,
307 int src_y,
308 int src_w,
309 int src_h,
310 int dest_x,
311 int dest_y,
312 int dest_w,
313 int dest_h,
[email protected]243cac7d2012-06-07 13:29:20314 bool filter,
315 const SkPaint& paint);
[email protected]3127f6632012-03-17 00:14:06316
[email protected]54bc2462014-05-06 05:10:58317 // Same as the DrawImageInt functions above. Difference being this does not
danakj4bfbb342015-10-29 23:38:25318 // do any scaling, i.e. it does not scale the output by the device scale
319 // factor (the internal image_scale_). It takes an ImageSkiaRep instead of
320 // an ImageSkia as the caller chooses the exact scale/pixel representation to
321 // use, which will not be scaled while drawing it into the canvas.
322 void DrawImageIntInPixel(const ImageSkiaRep& image_rep,
[email protected]54bc2462014-05-06 05:10:58323 int dest_x,
324 int dest_y,
325 int dest_w,
326 int dest_h,
327 bool filter,
328 const SkPaint& paint);
329
[email protected]8232da6b2012-07-02 19:41:15330 // Draws an |image| with the top left corner at |x| and |y|, clipped to
331 // |path|.
332 // Parameters are specified relative to current canvas scale not in pixels.
333 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05334 void DrawImageInPath(const ImageSkia& image,
[email protected]8232da6b2012-07-02 19:41:15335 int x,
336 int y,
337 const SkPath& path,
338 const SkPaint& paint);
339
[email protected]ad8d9d52013-08-22 07:20:05340 // Draws text with the specified color, fonts and location. The text is
[email protected]3127f6632012-03-17 00:14:06341 // aligned to the left, vertically centered, clipped to the region. If the
342 // text is too big, it is truncated and '...' is added to the end.
[email protected]ad8d9d52013-08-22 07:20:05343 void DrawStringRect(const base::string16& text,
344 const FontList& font_list,
345 SkColor color,
346 const Rect& display_rect);
[email protected]3127f6632012-03-17 00:14:06347
[email protected]ad8d9d52013-08-22 07:20:05348 // Draws text with the specified color, fonts and location. The last argument
[email protected]3127f6632012-03-17 00:14:06349 // specifies flags for how the text should be rendered. It can be one of
350 // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT.
[email protected]ad8d9d52013-08-22 07:20:05351 void DrawStringRectWithFlags(const base::string16& text,
352 const FontList& font_list,
353 SkColor color,
354 const Rect& display_rect,
355 int flags);
[email protected]3127f6632012-03-17 00:14:06356
[email protected]399c4632014-01-30 17:42:42357 // Similar to above DrawStringRect method but with text shadows support.
[email protected]561f7482013-04-19 03:39:58358 // Currently it's only implemented for canvas skia. Specifying a 0 line_height
359 // will cause the default height to be used.
[email protected]ad8d9d52013-08-22 07:20:05360 void DrawStringRectWithShadows(const base::string16& text,
361 const FontList& font_list,
362 SkColor color,
363 const Rect& text_bounds,
364 int line_height,
365 int flags,
366 const ShadowValues& shadows);
[email protected]0834e1b12012-04-11 02:23:56367
[email protected]3127f6632012-03-17 00:14:06368 // Draws a dotted gray rectangle used for focus purposes.
[email protected]ad8d9d52013-08-22 07:20:05369 void DrawFocusRect(const Rect& rect);
[email protected]3127f6632012-03-17 00:14:06370
[email protected]5db93a12013-12-02 21:07:31371 // Draws a |rect| in the specified region with the specified |color| with a
372 // with of one logical pixel which might be more device pixels.
373 void DrawSolidFocusRect(const Rect& rect, SkColor color);
374
[email protected]3127f6632012-03-17 00:14:06375 // Tiles the image in the specified region.
[email protected]35d53342012-05-16 21:30:12376 // Parameters are specified relative to current canvas scale not in pixels.
377 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05378 void TileImageInt(const ImageSkia& image,
379 int x,
380 int y,
381 int w,
382 int h);
383 void TileImageInt(const ImageSkia& image,
384 int src_x,
385 int src_y,
386 int dest_x,
387 int dest_y,
388 int w,
389 int h);
390 void TileImageInt(const ImageSkia& image,
391 int src_x,
392 int src_y,
393 float tile_scale_x,
394 float tile_scale_y,
395 int dest_x,
396 int dest_y,
397 int w,
398 int h);
[email protected]3127f6632012-03-17 00:14:06399
[email protected]3127f6632012-03-17 00:14:06400 // Apply transformation on the canvas.
[email protected]ad8d9d52013-08-22 07:20:05401 void Transform(const Transform& transform);
[email protected]3127f6632012-03-17 00:14:06402
[email protected]f3ce6212014-06-05 22:42:08403 // Draws the given string with a fade gradient at the end.
404 void DrawFadedString(const base::string16& text,
405 const FontList& font_list,
406 SkColor color,
407 const Rect& display_rect,
408 int flags);
[email protected]3127f6632012-03-17 00:14:06409
hendrikw788debf2014-09-16 18:16:03410 skia::PlatformCanvas* platform_canvas() { return owned_canvas_.get(); }
411 SkCanvas* sk_canvas() { return canvas_; }
[email protected]50b66262013-09-24 03:25:48412 float image_scale() const { return image_scale_; }
[email protected]3127f6632012-03-17 00:14:06413
414 private:
415 // Test whether the provided rectangle intersects the current clip rect.
416 bool IntersectsClipRectInt(int x, int y, int w, int h);
[email protected]ad8d9d52013-08-22 07:20:05417 bool IntersectsClipRect(const Rect& rect);
[email protected]3127f6632012-03-17 00:14:06418
[email protected]54bc2462014-05-06 05:10:58419 // Helper for the DrawImageInt functions declared above. The |pixel|
420 // parameter if true indicates that the bounds and the image are to
421 // be assumed to be in pixels, i.e. no scaling needs to be performed.
danakj4bfbb342015-10-29 23:38:25422 void DrawImageIntHelper(const ImageSkiaRep& image_rep,
[email protected]54bc2462014-05-06 05:10:58423 int src_x,
424 int src_y,
425 int src_w,
426 int src_h,
427 int dest_x,
428 int dest_y,
429 int dest_w,
430 int dest_h,
431 bool filter,
432 const SkPaint& paint,
[email protected]54bc2462014-05-06 05:10:58433 bool pixel);
434
[email protected]3b2591a2012-06-27 17:58:41435 // The device scale factor at which drawing on this canvas occurs.
436 // An additional scale can be applied via Canvas::Scale(). However,
[email protected]50b66262013-09-24 03:25:48437 // Canvas::Scale() does not affect |image_scale_|.
438 float image_scale_;
[email protected]3b2591a2012-06-27 17:58:41439
[email protected]3699ae5a2012-12-05 01:00:54440 skia::RefPtr<skia::PlatformCanvas> owned_canvas_;
[email protected]de13f352012-07-24 16:51:16441 SkCanvas* canvas_;
442
[email protected]3127f6632012-03-17 00:14:06443 DISALLOW_COPY_AND_ASSIGN(Canvas);
[email protected]267c03d2011-02-02 23:03:07444};
445
[email protected]7fe28392011-10-27 00:16:05446} // namespace gfx
[email protected]267c03d2011-02-02 23:03:07447
448#endif // UI_GFX_CANVAS_H_