blob: cb937d0139d87e5cf555289e15a6affb63643683 [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
avic89eb8d42015-12-23 08:08:188#include <stdint.h>
9
danakj25c52c32016-04-12 21:51:0810#include <memory>
[email protected]0834e1b12012-04-11 02:23:5611#include <vector>
12
avic89eb8d42015-12-23 08:08:1813#include "base/macros.h"
[email protected]f3652ff92013-06-11 13:54:3114#include "base/strings/string16.h"
[email protected]3127f6632012-03-17 00:14:0615#include "skia/ext/platform_canvas.h"
tomhudson399950b2016-05-11 11:00:1316#include "third_party/skia/include/core/SkRefCnt.h"
[email protected]35d53342012-05-16 21:30:1217#include "ui/gfx/image/image_skia.h"
[email protected]3127f6632012-03-17 00:14:0618#include "ui/gfx/native_widget_types.h"
[email protected]25650682012-05-29 23:09:1919#include "ui/gfx/shadow_value.h"
[email protected]f3ce6212014-06-05 22:42:0820#include "ui/gfx/text_constants.h"
[email protected]3127f6632012-03-17 00:14:0621
[email protected]267c03d2011-02-02 23:03:0722namespace gfx {
23
[email protected]3127f6632012-03-17 00:14:0624class Rect;
mgiuca9a713fe12015-11-10 02:53:3025class RectF;
[email protected]ad8d9d52013-08-22 07:20:0526class FontList;
[email protected]3127f6632012-03-17 00:14:0627class Point;
estade397c9b92016-05-26 15:28:5828class PointF;
[email protected]3127f6632012-03-17 00:14:0629class Size;
[email protected]0f0453e2012-10-14 18:15:3530class Transform;
[email protected]3127f6632012-03-17 00:14:0631
32// Canvas is a SkCanvas wrapper that provides a number of methods for
33// common operations used throughout an application built using ui/gfx.
34//
35// All methods that take integer arguments (as is used throughout views)
36// end with Int. If you need to use methods provided by SkCanvas, you'll
37// need to do a conversion. In particular you'll need to use |SkIntToScalar()|,
38// or if converting from a scalar to an integer |SkScalarRound()|.
39//
40// A handful of methods in this class are overloaded providing an additional
41// argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the
42// source and destination colors are combined. Unless otherwise specified,
43// the variant that does not take a SkXfermode::Mode uses a transfer mode
44// of kSrcOver_Mode.
[email protected]4ffa7892013-09-27 16:56:0645class GFX_EXPORT Canvas {
[email protected]267c03d2011-02-02 23:03:0746 public:
[email protected]3127f6632012-03-17 00:14:0647 enum {
oshima7410ba72015-03-05 00:08:3848 // Specifies the alignment for text rendered with the DrawStringRect method.
[email protected]3127f6632012-03-17 00:14:0649 TEXT_ALIGN_LEFT = 1 << 0,
50 TEXT_ALIGN_CENTER = 1 << 1,
[email protected]ff1af582012-11-06 03:34:1251 TEXT_ALIGN_RIGHT = 1 << 2,
oshima7410ba72015-03-05 00:08:3852 TEXT_ALIGN_TO_HEAD = 1 << 3,
[email protected]3127f6632012-03-17 00:14:0653
54 // Specifies the text consists of multiple lines.
oshima7410ba72015-03-05 00:08:3855 MULTI_LINE = 1 << 4,
[email protected]3127f6632012-03-17 00:14:0656
[email protected]399c4632014-01-30 17:42:4257 // By default DrawStringRect does not process the prefix ('&') character
[email protected]3127f6632012-03-17 00:14:0658 // specially. That is, the string "&foo" is rendered as "&foo". When
59 // rendering text from a resource that uses the prefix character for
60 // mnemonics, the prefix should be processed and can be rendered as an
61 // underline (SHOW_PREFIX), or not rendered at all (HIDE_PREFIX).
oshima7410ba72015-03-05 00:08:3862 SHOW_PREFIX = 1 << 5,
63 HIDE_PREFIX = 1 << 6,
[email protected]3127f6632012-03-17 00:14:0664
65 // Prevent ellipsizing
oshima7410ba72015-03-05 00:08:3866 NO_ELLIPSIS = 1 << 7,
[email protected]3127f6632012-03-17 00:14:0667
68 // Specifies if words can be split by new lines.
69 // This only works with MULTI_LINE.
oshima7410ba72015-03-05 00:08:3870 CHARACTER_BREAK = 1 << 8,
[email protected]3127f6632012-03-17 00:14:0671
[email protected]399c4632014-01-30 17:42:4272 // Instructs DrawStringRect() to not use subpixel rendering. This is useful
[email protected]3127f6632012-03-17 00:14:0673 // when rendering text onto a fully- or partially-transparent background
74 // that will later be blended with another image.
oshima7410ba72015-03-05 00:08:3875 NO_SUBPIXEL_RENDERING = 1 << 9,
[email protected]3127f6632012-03-17 00:14:0676 };
77
[email protected]50b66262013-09-24 03:25:4878 // Creates an empty canvas with image_scale of 1x.
[email protected]94a0d2582012-03-09 00:30:5979 Canvas();
[email protected]267c03d2011-02-02 23:03:0780
[email protected]50b66262013-09-24 03:25:4881 // Creates canvas with provided DIP |size| and |image_scale|.
[email protected]3b2591a2012-06-27 17:58:4182 // If this canvas is not opaque, it's explicitly cleared to transparent before
83 // being returned.
[email protected]50b66262013-09-24 03:25:4884 Canvas(const Size& size, float image_scale, bool is_opaque);
[email protected]3127f6632012-03-17 00:14:0685
[email protected]50b66262013-09-24 03:25:4886 // Constructs a canvas with the size and the image_scale of the provided
87 // |image_rep|, and draws the |image_rep| into it.
[email protected]ad8d9d52013-08-22 07:20:0588 Canvas(const ImageSkiaRep& image_rep, bool is_opaque);
[email protected]3b2591a2012-06-27 17:58:4189
[email protected]50b66262013-09-24 03:25:4890 // Creates a Canvas backed by an |sk_canvas| with |image_scale_|.
91 // |sk_canvas| is assumed to be already scaled based on |image_scale|
[email protected]de13f352012-07-24 16:51:1692 // so no additional scaling is applied.
tomhudson399950b2016-05-11 11:00:1393 Canvas(sk_sp<SkCanvas> sk_canvas, float image_scale);
danakj8fa739b62015-05-12 02:10:0694
95 virtual ~Canvas();
[email protected]de13f352012-07-24 16:51:1696
[email protected]50b66262013-09-24 03:25:4897 // Recreates the backing platform canvas with DIP |size| and |image_scale_|.
[email protected]3b2591a2012-06-27 17:58:4198 // If the canvas is not opaque, it is explicitly cleared.
99 // This method is public so that canvas_skia_paint can recreate the platform
100 // canvas after having initialized the canvas.
[email protected]50b66262013-09-24 03:25:48101 // TODO(pkotwicz): Push the image_scale into skia::PlatformCanvas such that
[email protected]3b2591a2012-06-27 17:58:41102 // this method can be private.
[email protected]ad8d9d52013-08-22 07:20:05103 void RecreateBackingCanvas(const Size& size,
[email protected]50b66262013-09-24 03:25:48104 float image_scale,
[email protected]3b2591a2012-06-27 17:58:41105 bool is_opaque);
106
[email protected]ad8d9d52013-08-22 07:20:05107 // Compute the size required to draw some text with the provided fonts.
[email protected]3127f6632012-03-17 00:14:06108 // Attempts to fit the text with the provided width and height. Increases
109 // height and then width as needed to make the text fit. This method
[email protected]561f7482013-04-19 03:39:58110 // supports multiple lines. On Skia only a line_height can be specified and
111 // specifying a 0 value for it will cause the default height to be used.
[email protected]031ffed2013-06-09 03:32:36112 static void SizeStringInt(const base::string16& text,
[email protected]ad8d9d52013-08-22 07:20:05113 const FontList& font_list,
114 int* width,
115 int* height,
116 int line_height,
117 int flags);
[email protected]3127f6632012-03-17 00:14:06118
[email protected]8ad3c5a2013-10-10 09:57:19119 // This is same as SizeStringInt except that fractional size is returned.
120 // See comment in GetStringWidthF for its usage.
121 static void SizeStringFloat(const base::string16& text,
122 const FontList& font_list,
123 float* width,
124 float* height,
125 int line_height,
126 int flags);
127
[email protected]3127f6632012-03-17 00:14:06128 // Returns the number of horizontal pixels needed to display the specified
[email protected]ad8d9d52013-08-22 07:20:05129 // |text| with |font_list|.
130 static int GetStringWidth(const base::string16& text,
131 const FontList& font_list);
[email protected]3127f6632012-03-17 00:14:06132
[email protected]8ad3c5a2013-10-10 09:57:19133 // This is same as GetStringWidth except that fractional width is returned.
134 // Use this method for the scenario that multiple string widths need to be
135 // summed up. This is because GetStringWidth returns the ceiled width and
136 // adding multiple ceiled widths could cause more precision loss for certain
137 // platform like Mac where the fractioal width is used.
138 static float GetStringWidthF(const base::string16& text,
139 const FontList& font_list);
140
[email protected]3127f6632012-03-17 00:14:06141 // Returns the default text alignment to be used when drawing text on a
[email protected]ad8d9d52013-08-22 07:20:05142 // Canvas based on the directionality of the system locale language.
[email protected]399c4632014-01-30 17:42:42143 // This function is used by Canvas::DrawStringRect when the text alignment
[email protected]3127f6632012-03-17 00:14:06144 // is not specified.
145 //
[email protected]ad8d9d52013-08-22 07:20:05146 // This function returns either Canvas::TEXT_ALIGN_LEFT or
147 // Canvas::TEXT_ALIGN_RIGHT.
[email protected]3127f6632012-03-17 00:14:06148 static int DefaultCanvasTextAlignment();
149
150 // Draws text with a 1-pixel halo around it of the given color.
[email protected]ad8d9d52013-08-22 07:20:05151 // On Windows, it allows ClearType to be drawn to an otherwise transparent
[email protected]3127f6632012-03-17 00:14:06152 // bitmap for drag images. Drag images have only 1-bit of transparency, so
153 // we don't do any fancy blurring.
154 // On Linux, text with halo is created by stroking it with 2px |halo_color|
155 // then filling it with |text_color|.
156 // On Mac, NOTIMPLEMENTED.
157 // TODO(dhollowa): Skia-native implementation is underway. Cut over to
158 // that when ready. http::/crbug.com/109946
[email protected]ad8d9d52013-08-22 07:20:05159 void DrawStringRectWithHalo(const base::string16& text,
160 const FontList& font_list,
161 SkColor text_color,
162 SkColor halo_color,
163 const Rect& display_rect,
164 int flags);
[email protected]3127f6632012-03-17 00:14:06165
[email protected]3b2591a2012-06-27 17:58:41166 // Extracts an ImageSkiaRep from the contents of this canvas.
[email protected]ad8d9d52013-08-22 07:20:05167 ImageSkiaRep ExtractImageRep() const;
[email protected]3b2591a2012-06-27 17:58:41168
[email protected]3127f6632012-03-17 00:14:06169 // Draws a dashed rectangle of the specified color.
[email protected]ad8d9d52013-08-22 07:20:05170 void DrawDashedRect(const Rect& rect, SkColor color);
[email protected]3127f6632012-03-17 00:14:06171
danakjda764372015-10-30 19:25:16172 // Unscales by the image scale factor (aka device scale factor), and returns
173 // that factor. This is useful when callers want to draw directly in the
174 // native scale.
175 float UndoDeviceScaleFactor();
176
[email protected]3127f6632012-03-17 00:14:06177 // Saves a copy of the drawing state onto a stack, operating on this copy
178 // until a balanced call to Restore() is made.
179 void Save();
180
181 // As with Save(), except draws to a layer that is blended with the canvas
182 // at the specified alpha once Restore() is called.
183 // |layer_bounds| are the bounds of the layer relative to the current
184 // transform.
avic89eb8d42015-12-23 08:08:18185 void SaveLayerAlpha(uint8_t alpha);
186 void SaveLayerAlpha(uint8_t alpha, const Rect& layer_bounds);
[email protected]3127f6632012-03-17 00:14:06187
188 // Restores the drawing state after a call to Save*(). It is an error to
189 // call Restore() more times than Save*().
[email protected]964c429d2012-10-25 15:28:45190 void Restore();
[email protected]3127f6632012-03-17 00:14:06191
[email protected]a91031712014-03-03 15:41:16192 // Adds |rect| to the current clip.
193 void ClipRect(const Rect& rect);
[email protected]3127f6632012-03-17 00:14:06194
[email protected]d26b905c2014-05-26 16:43:44195 // Adds |path| to the current clip. |do_anti_alias| is true if the clip
196 // should be antialiased.
197 void ClipPath(const SkPath& path, bool do_anti_alias);
[email protected]a91031712014-03-03 15:41:16198
199 // Returns true if the current clip is empty.
200 bool IsClipEmpty() const;
[email protected]ffdd1fd2012-04-09 23:24:41201
202 // Returns the bounds of the current clip (in local coordinates) in the
203 // |bounds| parameter, and returns true if it is non empty.
[email protected]ad8d9d52013-08-22 07:20:05204 bool GetClipBounds(Rect* bounds);
[email protected]ffdd1fd2012-04-09 23:24:41205
[email protected]ad8d9d52013-08-22 07:20:05206 void Translate(const Vector2d& offset);
[email protected]3127f6632012-03-17 00:14:06207
208 void Scale(int x_scale, int y_scale);
209
[email protected]ffdd1fd2012-04-09 23:24:41210 // Fills the entire canvas' bitmap (restricted to current clip) with
211 // specified |color| using a transfer mode of SkXfermode::kSrcOver_Mode.
212 void DrawColor(SkColor color);
213
214 // Fills the entire canvas' bitmap (restricted to current clip) with
215 // specified |color| and |mode|.
216 void DrawColor(SkColor color, SkXfermode::Mode mode);
217
[email protected]3127f6632012-03-17 00:14:06218 // Fills |rect| with |color| using a transfer mode of
219 // SkXfermode::kSrcOver_Mode.
[email protected]ad8d9d52013-08-22 07:20:05220 void FillRect(const Rect& rect, SkColor color);
[email protected]3127f6632012-03-17 00:14:06221
222 // Fills |rect| with the specified |color| and |mode|.
[email protected]ad8d9d52013-08-22 07:20:05223 void FillRect(const Rect& rect, SkColor color, SkXfermode::Mode mode);
[email protected]3127f6632012-03-17 00:14:06224
[email protected]3127f6632012-03-17 00:14:06225 // Draws a single pixel rect in the specified region with the specified
226 // color, using a transfer mode of SkXfermode::kSrcOver_Mode.
227 //
228 // NOTE: if you need a single pixel line, use DrawLine.
[email protected]ad8d9d52013-08-22 07:20:05229 void DrawRect(const Rect& rect, SkColor color);
[email protected]3127f6632012-03-17 00:14:06230
231 // Draws a single pixel rect in the specified region with the specified
232 // color and transfer mode.
233 //
234 // NOTE: if you need a single pixel line, use DrawLine.
[email protected]ad8d9d52013-08-22 07:20:05235 void DrawRect(const Rect& rect, SkColor color, SkXfermode::Mode mode);
[email protected]3127f6632012-03-17 00:14:06236
[email protected]ffdd1fd2012-04-09 23:24:41237 // Draws the given rectangle with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05238 void DrawRect(const Rect& rect, const SkPaint& paint);
[email protected]3127f6632012-03-17 00:14:06239
[email protected]ffdd1fd2012-04-09 23:24:41240 // Draw the given point with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05241 void DrawPoint(const Point& p, const SkPaint& paint);
[email protected]ffdd1fd2012-04-09 23:24:41242
[email protected]3127f6632012-03-17 00:14:06243 // Draws a single pixel line with the specified color.
[email protected]ad8d9d52013-08-22 07:20:05244 void DrawLine(const Point& p1, const Point& p2, SkColor color);
estade397c9b92016-05-26 15:28:58245 void DrawLine(const PointF& p1, const PointF& p2, SkColor color);
[email protected]3127f6632012-03-17 00:14:06246
[email protected]ffdd1fd2012-04-09 23:24:41247 // Draws a line with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05248 void DrawLine(const Point& p1, const Point& p2, const SkPaint& paint);
estade397c9b92016-05-26 15:28:58249 void DrawLine(const PointF& p1, const PointF& p2, const SkPaint& paint);
[email protected]ffdd1fd2012-04-09 23:24:41250
251 // Draws a circle with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05252 void DrawCircle(const Point& center_point,
[email protected]ffdd1fd2012-04-09 23:24:41253 int radius,
254 const SkPaint& paint);
255
256 // Draws the given rectangle with rounded corners of |radius| using the
mgiuca9a713fe12015-11-10 02:53:30257 // given |paint| parameters. DEPRECATED in favor of the RectF version below.
258 // TODO(mgiuca): Remove this (http://crbug.com/553726).
[email protected]ad8d9d52013-08-22 07:20:05259 void DrawRoundRect(const Rect& rect, int radius, const SkPaint& paint);
[email protected]ffdd1fd2012-04-09 23:24:41260
mgiuca9a713fe12015-11-10 02:53:30261 // Draws the given rectangle with rounded corners of |radius| using the
262 // given |paint| parameters.
263 void DrawRoundRect(const RectF& rect, float radius, const SkPaint& paint);
264
[email protected]ffdd1fd2012-04-09 23:24:41265 // Draws the given path using the given |paint| parameters.
266 void DrawPath(const SkPath& path, const SkPaint& paint);
267
[email protected]35d53342012-05-16 21:30:12268 // Draws an image with the origin at the specified location. The upper left
[email protected]3127f6632012-03-17 00:14:06269 // corner of the bitmap is rendered at the specified location.
[email protected]35d53342012-05-16 21:30:12270 // Parameters are specified relative to current canvas scale not in pixels.
[email protected]8232da6b2012-07-02 19:41:15271 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05272 void DrawImageInt(const ImageSkia&, int x, int y);
[email protected]3127f6632012-03-17 00:14:06273
[email protected]2885cb32012-10-03 19:41:11274 // Helper for DrawImageInt(..., paint) that constructs a temporary paint and
275 // calls paint.setAlpha(alpha).
avic89eb8d42015-12-23 08:08:18276 void DrawImageInt(const ImageSkia&, int x, int y, uint8_t alpha);
[email protected]2885cb32012-10-03 19:41:11277
[email protected]35d53342012-05-16 21:30:12278 // Draws an image with the origin at the specified location, using the
[email protected]3127f6632012-03-17 00:14:06279 // specified paint. The upper left corner of the bitmap is rendered at the
280 // specified location.
[email protected]35d53342012-05-16 21:30:12281 // Parameters are specified relative to current canvas scale not in pixels.
282 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05283 void DrawImageInt(const ImageSkia& image,
284 int x,
285 int y,
[email protected]243cac7d2012-06-07 13:29:20286 const SkPaint& paint);
[email protected]3127f6632012-03-17 00:14:06287
[email protected]35d53342012-05-16 21:30:12288 // Draws a portion of an image in the specified location. The src parameters
[email protected]3127f6632012-03-17 00:14:06289 // correspond to the region of the bitmap to draw in the region defined
290 // by the dest coordinates.
291 //
292 // If the width or height of the source differs from that of the destination,
[email protected]35d53342012-05-16 21:30:12293 // the image will be scaled. When scaling down, a mipmap will be generated.
294 // Set |filter| to use filtering for images, otherwise the nearest-neighbor
295 // algorithm is used for resampling.
[email protected]3127f6632012-03-17 00:14:06296 //
297 // An optional custom SkPaint can be provided.
[email protected]35d53342012-05-16 21:30:12298 // Parameters are specified relative to current canvas scale not in pixels.
299 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05300 void DrawImageInt(const ImageSkia& image,
301 int src_x,
302 int src_y,
303 int src_w,
304 int src_h,
305 int dest_x,
306 int dest_y,
307 int dest_w,
308 int dest_h,
[email protected]243cac7d2012-06-07 13:29:20309 bool filter);
[email protected]ad8d9d52013-08-22 07:20:05310 void DrawImageInt(const ImageSkia& image,
311 int src_x,
312 int src_y,
313 int src_w,
314 int src_h,
315 int dest_x,
316 int dest_y,
317 int dest_w,
318 int dest_h,
[email protected]243cac7d2012-06-07 13:29:20319 bool filter,
320 const SkPaint& paint);
[email protected]3127f6632012-03-17 00:14:06321
[email protected]54bc2462014-05-06 05:10:58322 // Same as the DrawImageInt functions above. Difference being this does not
danakj4bfbb342015-10-29 23:38:25323 // do any scaling, i.e. it does not scale the output by the device scale
324 // factor (the internal image_scale_). It takes an ImageSkiaRep instead of
325 // an ImageSkia as the caller chooses the exact scale/pixel representation to
326 // use, which will not be scaled while drawing it into the canvas.
327 void DrawImageIntInPixel(const ImageSkiaRep& image_rep,
[email protected]54bc2462014-05-06 05:10:58328 int dest_x,
329 int dest_y,
330 int dest_w,
331 int dest_h,
332 bool filter,
333 const SkPaint& paint);
334
[email protected]8232da6b2012-07-02 19:41:15335 // Draws an |image| with the top left corner at |x| and |y|, clipped to
336 // |path|.
337 // Parameters are specified relative to current canvas scale not in pixels.
338 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05339 void DrawImageInPath(const ImageSkia& image,
[email protected]8232da6b2012-07-02 19:41:15340 int x,
341 int y,
342 const SkPath& path,
343 const SkPaint& paint);
344
[email protected]ad8d9d52013-08-22 07:20:05345 // Draws text with the specified color, fonts and location. The text is
[email protected]3127f6632012-03-17 00:14:06346 // aligned to the left, vertically centered, clipped to the region. If the
347 // text is too big, it is truncated and '...' is added to the end.
[email protected]ad8d9d52013-08-22 07:20:05348 void DrawStringRect(const base::string16& text,
349 const FontList& font_list,
350 SkColor color,
351 const Rect& display_rect);
[email protected]3127f6632012-03-17 00:14:06352
[email protected]ad8d9d52013-08-22 07:20:05353 // Draws text with the specified color, fonts and location. The last argument
[email protected]3127f6632012-03-17 00:14:06354 // specifies flags for how the text should be rendered. It can be one of
355 // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT.
[email protected]ad8d9d52013-08-22 07:20:05356 void DrawStringRectWithFlags(const base::string16& text,
357 const FontList& font_list,
358 SkColor color,
359 const Rect& display_rect,
360 int flags);
[email protected]3127f6632012-03-17 00:14:06361
[email protected]399c4632014-01-30 17:42:42362 // Similar to above DrawStringRect method but with text shadows support.
[email protected]561f7482013-04-19 03:39:58363 // Currently it's only implemented for canvas skia. Specifying a 0 line_height
364 // will cause the default height to be used.
[email protected]ad8d9d52013-08-22 07:20:05365 void DrawStringRectWithShadows(const base::string16& text,
366 const FontList& font_list,
367 SkColor color,
368 const Rect& text_bounds,
369 int line_height,
370 int flags,
371 const ShadowValues& shadows);
[email protected]0834e1b12012-04-11 02:23:56372
[email protected]3127f6632012-03-17 00:14:06373 // Draws a dotted gray rectangle used for focus purposes.
[email protected]ad8d9d52013-08-22 07:20:05374 void DrawFocusRect(const Rect& rect);
[email protected]3127f6632012-03-17 00:14:06375
[email protected]5db93a12013-12-02 21:07:31376 // Draws a |rect| in the specified region with the specified |color| with a
377 // with of one logical pixel which might be more device pixels.
378 void DrawSolidFocusRect(const Rect& rect, SkColor color);
379
[email protected]3127f6632012-03-17 00:14:06380 // Tiles the image in the specified region.
[email protected]35d53342012-05-16 21:30:12381 // Parameters are specified relative to current canvas scale not in pixels.
382 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05383 void TileImageInt(const ImageSkia& image,
384 int x,
385 int y,
386 int w,
387 int h);
388 void TileImageInt(const ImageSkia& image,
389 int src_x,
390 int src_y,
391 int dest_x,
392 int dest_y,
393 int w,
394 int h);
395 void TileImageInt(const ImageSkia& image,
396 int src_x,
397 int src_y,
398 float tile_scale_x,
399 float tile_scale_y,
400 int dest_x,
401 int dest_y,
402 int w,
403 int h);
[email protected]3127f6632012-03-17 00:14:06404
pkasting954f76a2016-02-25 01:11:00405 // Helper for TileImageInt(). Initializes |paint| for tiling |image| with the
406 // given parameters. Returns false if the provided image does not have a
407 // representation for the current scale.
408 bool InitSkPaintForTiling(const ImageSkia& image,
409 int src_x,
410 int src_y,
411 float tile_scale_x,
412 float tile_scale_y,
413 int dest_x,
414 int dest_y,
415 SkPaint* paint);
416
[email protected]3127f6632012-03-17 00:14:06417 // Apply transformation on the canvas.
[email protected]ad8d9d52013-08-22 07:20:05418 void Transform(const Transform& transform);
[email protected]3127f6632012-03-17 00:14:06419
[email protected]f3ce6212014-06-05 22:42:08420 // Draws the given string with a fade gradient at the end.
421 void DrawFadedString(const base::string16& text,
422 const FontList& font_list,
423 SkColor color,
424 const Rect& display_rect,
425 int flags);
[email protected]3127f6632012-03-17 00:14:06426
tomhudson748157f72016-02-04 18:49:56427 SkCanvas* sk_canvas() { return canvas_.get(); }
[email protected]50b66262013-09-24 03:25:48428 float image_scale() const { return image_scale_; }
[email protected]3127f6632012-03-17 00:14:06429
430 private:
pkasting954f76a2016-02-25 01:11:00431 // Tests whether the provided rectangle intersects the current clip rect.
432 bool IntersectsClipRect(const SkRect& rect);
[email protected]3127f6632012-03-17 00:14:06433
danakjf01075882016-01-06 19:39:32434 // Helper for the DrawImageInt functions declared above. The
435 // |remove_image_scale| parameter indicates if the scale of the |image_rep|
436 // should be removed when drawing the image, to avoid double-scaling it.
danakj4bfbb342015-10-29 23:38:25437 void DrawImageIntHelper(const ImageSkiaRep& image_rep,
[email protected]54bc2462014-05-06 05:10:58438 int src_x,
439 int src_y,
440 int src_w,
441 int src_h,
442 int dest_x,
443 int dest_y,
444 int dest_w,
445 int dest_h,
446 bool filter,
447 const SkPaint& paint,
danakjf01075882016-01-06 19:39:32448 bool remove_image_scale);
[email protected]54bc2462014-05-06 05:10:58449
[email protected]3b2591a2012-06-27 17:58:41450 // The device scale factor at which drawing on this canvas occurs.
451 // An additional scale can be applied via Canvas::Scale(). However,
[email protected]50b66262013-09-24 03:25:48452 // Canvas::Scale() does not affect |image_scale_|.
453 float image_scale_;
[email protected]3b2591a2012-06-27 17:58:41454
tomhudson399950b2016-05-11 11:00:13455 sk_sp<SkCanvas> canvas_;
[email protected]de13f352012-07-24 16:51:16456
[email protected]3127f6632012-03-17 00:14:06457 DISALLOW_COPY_AND_ASSIGN(Canvas);
[email protected]267c03d2011-02-02 23:03:07458};
459
[email protected]7fe28392011-10-27 00:16:05460} // namespace gfx
[email protected]267c03d2011-02-02 23:03:07461
462#endif // UI_GFX_CANVAS_H_