blob: a05c8e0fcf069619461ac43c65acb5fe745bdfb8 [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 // Creates a Canvas backed by an |sk_canvas| with |image_scale_|.
87 // |sk_canvas| is assumed to be already scaled based on |image_scale|
[email protected]de13f352012-07-24 16:51:1688 // so no additional scaling is applied.
tomhudson399950b2016-05-11 11:00:1389 Canvas(sk_sp<SkCanvas> sk_canvas, float image_scale);
danakj8fa739b62015-05-12 02:10:0690
91 virtual ~Canvas();
[email protected]de13f352012-07-24 16:51:1692
[email protected]50b66262013-09-24 03:25:4893 // Recreates the backing platform canvas with DIP |size| and |image_scale_|.
[email protected]3b2591a2012-06-27 17:58:4194 // If the canvas is not opaque, it is explicitly cleared.
95 // This method is public so that canvas_skia_paint can recreate the platform
96 // canvas after having initialized the canvas.
[email protected]50b66262013-09-24 03:25:4897 // TODO(pkotwicz): Push the image_scale into skia::PlatformCanvas such that
[email protected]3b2591a2012-06-27 17:58:4198 // this method can be private.
[email protected]ad8d9d52013-08-22 07:20:0599 void RecreateBackingCanvas(const Size& size,
[email protected]50b66262013-09-24 03:25:48100 float image_scale,
[email protected]3b2591a2012-06-27 17:58:41101 bool is_opaque);
102
[email protected]ad8d9d52013-08-22 07:20:05103 // Compute the size required to draw some text with the provided fonts.
[email protected]3127f6632012-03-17 00:14:06104 // Attempts to fit the text with the provided width and height. Increases
105 // height and then width as needed to make the text fit. This method
[email protected]561f7482013-04-19 03:39:58106 // supports multiple lines. On Skia only a line_height can be specified and
107 // specifying a 0 value for it will cause the default height to be used.
[email protected]031ffed2013-06-09 03:32:36108 static void SizeStringInt(const base::string16& text,
[email protected]ad8d9d52013-08-22 07:20:05109 const FontList& font_list,
110 int* width,
111 int* height,
112 int line_height,
113 int flags);
[email protected]3127f6632012-03-17 00:14:06114
[email protected]8ad3c5a2013-10-10 09:57:19115 // This is same as SizeStringInt except that fractional size is returned.
116 // See comment in GetStringWidthF for its usage.
117 static void SizeStringFloat(const base::string16& text,
118 const FontList& font_list,
119 float* width,
120 float* height,
121 int line_height,
122 int flags);
123
[email protected]3127f6632012-03-17 00:14:06124 // Returns the number of horizontal pixels needed to display the specified
[email protected]ad8d9d52013-08-22 07:20:05125 // |text| with |font_list|.
126 static int GetStringWidth(const base::string16& text,
127 const FontList& font_list);
[email protected]3127f6632012-03-17 00:14:06128
[email protected]8ad3c5a2013-10-10 09:57:19129 // This is same as GetStringWidth except that fractional width is returned.
130 // Use this method for the scenario that multiple string widths need to be
131 // summed up. This is because GetStringWidth returns the ceiled width and
132 // adding multiple ceiled widths could cause more precision loss for certain
133 // platform like Mac where the fractioal width is used.
134 static float GetStringWidthF(const base::string16& text,
135 const FontList& font_list);
136
[email protected]3127f6632012-03-17 00:14:06137 // Returns the default text alignment to be used when drawing text on a
[email protected]ad8d9d52013-08-22 07:20:05138 // Canvas based on the directionality of the system locale language.
[email protected]399c4632014-01-30 17:42:42139 // This function is used by Canvas::DrawStringRect when the text alignment
[email protected]3127f6632012-03-17 00:14:06140 // is not specified.
141 //
[email protected]ad8d9d52013-08-22 07:20:05142 // This function returns either Canvas::TEXT_ALIGN_LEFT or
143 // Canvas::TEXT_ALIGN_RIGHT.
[email protected]3127f6632012-03-17 00:14:06144 static int DefaultCanvasTextAlignment();
145
146 // Draws text with a 1-pixel halo around it of the given color.
[email protected]ad8d9d52013-08-22 07:20:05147 // On Windows, it allows ClearType to be drawn to an otherwise transparent
[email protected]3127f6632012-03-17 00:14:06148 // bitmap for drag images. Drag images have only 1-bit of transparency, so
149 // we don't do any fancy blurring.
150 // On Linux, text with halo is created by stroking it with 2px |halo_color|
151 // then filling it with |text_color|.
152 // On Mac, NOTIMPLEMENTED.
153 // TODO(dhollowa): Skia-native implementation is underway. Cut over to
154 // that when ready. http::/crbug.com/109946
[email protected]ad8d9d52013-08-22 07:20:05155 void DrawStringRectWithHalo(const base::string16& text,
156 const FontList& font_list,
157 SkColor text_color,
158 SkColor halo_color,
159 const Rect& display_rect,
160 int flags);
[email protected]3127f6632012-03-17 00:14:06161
[email protected]3b2591a2012-06-27 17:58:41162 // Extracts an ImageSkiaRep from the contents of this canvas.
[email protected]ad8d9d52013-08-22 07:20:05163 ImageSkiaRep ExtractImageRep() const;
[email protected]3b2591a2012-06-27 17:58:41164
[email protected]3127f6632012-03-17 00:14:06165 // Draws a dashed rectangle of the specified color.
[email protected]ad8d9d52013-08-22 07:20:05166 void DrawDashedRect(const Rect& rect, SkColor color);
[email protected]3127f6632012-03-17 00:14:06167
danakjda764372015-10-30 19:25:16168 // Unscales by the image scale factor (aka device scale factor), and returns
169 // that factor. This is useful when callers want to draw directly in the
170 // native scale.
171 float UndoDeviceScaleFactor();
172
[email protected]3127f6632012-03-17 00:14:06173 // Saves a copy of the drawing state onto a stack, operating on this copy
174 // until a balanced call to Restore() is made.
175 void Save();
176
177 // As with Save(), except draws to a layer that is blended with the canvas
178 // at the specified alpha once Restore() is called.
179 // |layer_bounds| are the bounds of the layer relative to the current
180 // transform.
avic89eb8d42015-12-23 08:08:18181 void SaveLayerAlpha(uint8_t alpha);
182 void SaveLayerAlpha(uint8_t alpha, const Rect& layer_bounds);
[email protected]3127f6632012-03-17 00:14:06183
184 // Restores the drawing state after a call to Save*(). It is an error to
185 // call Restore() more times than Save*().
[email protected]964c429d2012-10-25 15:28:45186 void Restore();
[email protected]3127f6632012-03-17 00:14:06187
[email protected]a91031712014-03-03 15:41:16188 // Adds |rect| to the current clip.
189 void ClipRect(const Rect& rect);
[email protected]3127f6632012-03-17 00:14:06190
[email protected]d26b905c2014-05-26 16:43:44191 // Adds |path| to the current clip. |do_anti_alias| is true if the clip
192 // should be antialiased.
193 void ClipPath(const SkPath& path, bool do_anti_alias);
[email protected]a91031712014-03-03 15:41:16194
195 // Returns true if the current clip is empty.
196 bool IsClipEmpty() const;
[email protected]ffdd1fd2012-04-09 23:24:41197
198 // Returns the bounds of the current clip (in local coordinates) in the
199 // |bounds| parameter, and returns true if it is non empty.
[email protected]ad8d9d52013-08-22 07:20:05200 bool GetClipBounds(Rect* bounds);
[email protected]ffdd1fd2012-04-09 23:24:41201
[email protected]ad8d9d52013-08-22 07:20:05202 void Translate(const Vector2d& offset);
[email protected]3127f6632012-03-17 00:14:06203
204 void Scale(int x_scale, int y_scale);
205
[email protected]ffdd1fd2012-04-09 23:24:41206 // Fills the entire canvas' bitmap (restricted to current clip) with
207 // specified |color| using a transfer mode of SkXfermode::kSrcOver_Mode.
208 void DrawColor(SkColor color);
209
210 // Fills the entire canvas' bitmap (restricted to current clip) with
211 // specified |color| and |mode|.
212 void DrawColor(SkColor color, SkXfermode::Mode mode);
213
[email protected]3127f6632012-03-17 00:14:06214 // Fills |rect| with |color| using a transfer mode of
215 // SkXfermode::kSrcOver_Mode.
[email protected]ad8d9d52013-08-22 07:20:05216 void FillRect(const Rect& rect, SkColor color);
[email protected]3127f6632012-03-17 00:14:06217
218 // Fills |rect| with the specified |color| and |mode|.
[email protected]ad8d9d52013-08-22 07:20:05219 void FillRect(const Rect& rect, SkColor color, SkXfermode::Mode mode);
[email protected]3127f6632012-03-17 00:14:06220
[email protected]3127f6632012-03-17 00:14:06221 // Draws a single pixel rect in the specified region with the specified
222 // color, using a transfer mode of SkXfermode::kSrcOver_Mode.
223 //
224 // NOTE: if you need a single pixel line, use DrawLine.
[email protected]ad8d9d52013-08-22 07:20:05225 void DrawRect(const Rect& rect, SkColor color);
[email protected]3127f6632012-03-17 00:14:06226
227 // Draws a single pixel rect in the specified region with the specified
228 // color and transfer mode.
229 //
230 // NOTE: if you need a single pixel line, use DrawLine.
[email protected]ad8d9d52013-08-22 07:20:05231 void DrawRect(const Rect& rect, SkColor color, SkXfermode::Mode mode);
[email protected]3127f6632012-03-17 00:14:06232
[email protected]ffdd1fd2012-04-09 23:24:41233 // Draws the given rectangle with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05234 void DrawRect(const Rect& rect, const SkPaint& paint);
[email protected]3127f6632012-03-17 00:14:06235
[email protected]ffdd1fd2012-04-09 23:24:41236 // Draw the given point with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05237 void DrawPoint(const Point& p, const SkPaint& paint);
[email protected]ffdd1fd2012-04-09 23:24:41238
[email protected]3127f6632012-03-17 00:14:06239 // Draws a single pixel line with the specified color.
[email protected]ad8d9d52013-08-22 07:20:05240 void DrawLine(const Point& p1, const Point& p2, SkColor color);
estade397c9b92016-05-26 15:28:58241 void DrawLine(const PointF& p1, const PointF& 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);
estade397c9b92016-05-26 15:28:58245 void DrawLine(const PointF& p1, const PointF& p2, const SkPaint& paint);
[email protected]ffdd1fd2012-04-09 23:24:41246
247 // Draws a circle with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05248 void DrawCircle(const Point& center_point,
[email protected]ffdd1fd2012-04-09 23:24:41249 int radius,
250 const SkPaint& paint);
251
estade104196ec2016-06-02 01:37:53252 // Draws a circle with the given |paint| parameters.
253 void DrawCircle(const PointF& center_point,
254 float radius,
255 const SkPaint& paint);
256
[email protected]ffdd1fd2012-04-09 23:24:41257 // Draws the given rectangle with rounded corners of |radius| using the
mgiuca9a713fe12015-11-10 02:53:30258 // given |paint| parameters. DEPRECATED in favor of the RectF version below.
259 // TODO(mgiuca): Remove this (http://crbug.com/553726).
[email protected]ad8d9d52013-08-22 07:20:05260 void DrawRoundRect(const Rect& rect, int radius, const SkPaint& paint);
[email protected]ffdd1fd2012-04-09 23:24:41261
mgiuca9a713fe12015-11-10 02:53:30262 // Draws the given rectangle with rounded corners of |radius| using the
263 // given |paint| parameters.
264 void DrawRoundRect(const RectF& rect, float radius, const SkPaint& paint);
265
[email protected]ffdd1fd2012-04-09 23:24:41266 // 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).
avic89eb8d42015-12-23 08:08:18277 void DrawImageInt(const ImageSkia&, int x, int y, uint8_t 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]54bc2462014-05-06 05:10:58323 // Same as the DrawImageInt functions above. Difference being this does not
danakj4bfbb342015-10-29 23:38:25324 // do any scaling, i.e. it does not scale the output by the device scale
325 // factor (the internal image_scale_). It takes an ImageSkiaRep instead of
326 // an ImageSkia as the caller chooses the exact scale/pixel representation to
327 // use, which will not be scaled while drawing it into the canvas.
328 void DrawImageIntInPixel(const ImageSkiaRep& image_rep,
[email protected]54bc2462014-05-06 05:10:58329 int dest_x,
330 int dest_y,
331 int dest_w,
332 int dest_h,
333 bool filter,
334 const SkPaint& paint);
335
[email protected]8232da6b2012-07-02 19:41:15336 // Draws an |image| with the top left corner at |x| and |y|, clipped to
337 // |path|.
338 // Parameters are specified relative to current canvas scale not in pixels.
339 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05340 void DrawImageInPath(const ImageSkia& image,
[email protected]8232da6b2012-07-02 19:41:15341 int x,
342 int y,
343 const SkPath& path,
344 const SkPaint& paint);
345
[email protected]ad8d9d52013-08-22 07:20:05346 // Draws text with the specified color, fonts and location. The text is
[email protected]3127f6632012-03-17 00:14:06347 // aligned to the left, vertically centered, clipped to the region. If the
348 // text is too big, it is truncated and '...' is added to the end.
[email protected]ad8d9d52013-08-22 07:20:05349 void DrawStringRect(const base::string16& text,
350 const FontList& font_list,
351 SkColor color,
352 const Rect& display_rect);
[email protected]3127f6632012-03-17 00:14:06353
[email protected]ad8d9d52013-08-22 07:20:05354 // Draws text with the specified color, fonts and location. The last argument
[email protected]3127f6632012-03-17 00:14:06355 // specifies flags for how the text should be rendered. It can be one of
356 // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT.
[email protected]ad8d9d52013-08-22 07:20:05357 void DrawStringRectWithFlags(const base::string16& text,
358 const FontList& font_list,
359 SkColor color,
360 const Rect& display_rect,
361 int flags);
[email protected]3127f6632012-03-17 00:14:06362
[email protected]399c4632014-01-30 17:42:42363 // Similar to above DrawStringRect method but with text shadows support.
[email protected]561f7482013-04-19 03:39:58364 // Currently it's only implemented for canvas skia. Specifying a 0 line_height
365 // will cause the default height to be used.
[email protected]ad8d9d52013-08-22 07:20:05366 void DrawStringRectWithShadows(const base::string16& text,
367 const FontList& font_list,
368 SkColor color,
369 const Rect& text_bounds,
370 int line_height,
371 int flags,
372 const ShadowValues& shadows);
[email protected]0834e1b12012-04-11 02:23:56373
[email protected]3127f6632012-03-17 00:14:06374 // Draws a dotted gray rectangle used for focus purposes.
[email protected]ad8d9d52013-08-22 07:20:05375 void DrawFocusRect(const Rect& rect);
[email protected]3127f6632012-03-17 00:14:06376
[email protected]5db93a12013-12-02 21:07:31377 // Draws a |rect| in the specified region with the specified |color| with a
378 // with of one logical pixel which might be more device pixels.
379 void DrawSolidFocusRect(const Rect& rect, SkColor color);
380
[email protected]3127f6632012-03-17 00:14:06381 // Tiles the image in the specified region.
[email protected]35d53342012-05-16 21:30:12382 // Parameters are specified relative to current canvas scale not in pixels.
383 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05384 void TileImageInt(const ImageSkia& image,
385 int x,
386 int y,
387 int w,
388 int h);
389 void TileImageInt(const ImageSkia& image,
390 int src_x,
391 int src_y,
392 int dest_x,
393 int dest_y,
394 int w,
395 int h);
396 void TileImageInt(const ImageSkia& image,
397 int src_x,
398 int src_y,
399 float tile_scale_x,
400 float tile_scale_y,
401 int dest_x,
402 int dest_y,
403 int w,
404 int h);
[email protected]3127f6632012-03-17 00:14:06405
pkasting954f76a2016-02-25 01:11:00406 // Helper for TileImageInt(). Initializes |paint| for tiling |image| with the
407 // given parameters. Returns false if the provided image does not have a
408 // representation for the current scale.
409 bool InitSkPaintForTiling(const ImageSkia& image,
410 int src_x,
411 int src_y,
412 float tile_scale_x,
413 float tile_scale_y,
414 int dest_x,
415 int dest_y,
416 SkPaint* paint);
417
[email protected]3127f6632012-03-17 00:14:06418 // Apply transformation on the canvas.
[email protected]ad8d9d52013-08-22 07:20:05419 void Transform(const Transform& transform);
[email protected]3127f6632012-03-17 00:14:06420
[email protected]f3ce6212014-06-05 22:42:08421 // Draws the given string with a fade gradient at the end.
422 void DrawFadedString(const base::string16& text,
423 const FontList& font_list,
424 SkColor color,
425 const Rect& display_rect,
426 int flags);
[email protected]3127f6632012-03-17 00:14:06427
tomhudson748157f72016-02-04 18:49:56428 SkCanvas* sk_canvas() { return canvas_.get(); }
[email protected]50b66262013-09-24 03:25:48429 float image_scale() const { return image_scale_; }
[email protected]3127f6632012-03-17 00:14:06430
431 private:
pkasting954f76a2016-02-25 01:11:00432 // Tests whether the provided rectangle intersects the current clip rect.
433 bool IntersectsClipRect(const SkRect& rect);
[email protected]3127f6632012-03-17 00:14:06434
danakjf01075882016-01-06 19:39:32435 // Helper for the DrawImageInt functions declared above. The
436 // |remove_image_scale| parameter indicates if the scale of the |image_rep|
437 // should be removed when drawing the image, to avoid double-scaling it.
danakj4bfbb342015-10-29 23:38:25438 void DrawImageIntHelper(const ImageSkiaRep& image_rep,
[email protected]54bc2462014-05-06 05:10:58439 int src_x,
440 int src_y,
441 int src_w,
442 int src_h,
443 int dest_x,
444 int dest_y,
445 int dest_w,
446 int dest_h,
447 bool filter,
448 const SkPaint& paint,
danakjf01075882016-01-06 19:39:32449 bool remove_image_scale);
[email protected]54bc2462014-05-06 05:10:58450
[email protected]3b2591a2012-06-27 17:58:41451 // The device scale factor at which drawing on this canvas occurs.
452 // An additional scale can be applied via Canvas::Scale(). However,
[email protected]50b66262013-09-24 03:25:48453 // Canvas::Scale() does not affect |image_scale_|.
454 float image_scale_;
[email protected]3b2591a2012-06-27 17:58:41455
tomhudson399950b2016-05-11 11:00:13456 sk_sp<SkCanvas> canvas_;
[email protected]de13f352012-07-24 16:51:16457
[email protected]3127f6632012-03-17 00:14:06458 DISALLOW_COPY_AND_ASSIGN(Canvas);
[email protected]267c03d2011-02-02 23:03:07459};
460
[email protected]7fe28392011-10-27 00:16:05461} // namespace gfx
[email protected]267c03d2011-02-02 23:03:07462
463#endif // UI_GFX_CANVAS_H_