| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_GFX_CANVAS_H_ | 5 #ifndef UI_GFX_CANVAS_H_ |
| 6 #define UI_GFX_CANVAS_H_ | 6 #define UI_GFX_CANVAS_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 // DEPRECATED in favor of the RectF version below. | 251 // DEPRECATED in favor of the RectF version below. |
| 252 // TODO(funkysidd): Remove this (http://crbug.com/553726) | 252 // TODO(funkysidd): Remove this (http://crbug.com/553726) |
| 253 void DrawRect(const Rect& rect, SkColor color, SkBlendMode mode); | 253 void DrawRect(const Rect& rect, SkColor color, SkBlendMode mode); |
| 254 | 254 |
| 255 // Draws a single pixel rect in the specified region with the specified | 255 // Draws a single pixel rect in the specified region with the specified |
| 256 // color and transfer mode. | 256 // color and transfer mode. |
| 257 // | 257 // |
| 258 // NOTE: if you need a single pixel line, use DrawLine. | 258 // NOTE: if you need a single pixel line, use DrawLine. |
| 259 void DrawRect(const RectF& rect, SkColor color, SkBlendMode mode); | 259 void DrawRect(const RectF& rect, SkColor color, SkBlendMode mode); |
| 260 | 260 |
| 261 // Draws the given rectangle with the given |paint| parameters. | 261 // Draws the given rectangle with the given |flags| parameters. |
| 262 // DEPRECATED in favor of the RectF version below. | 262 // DEPRECATED in favor of the RectF version below. |
| 263 // TODO(funkysidd): Remove this (http://crbug.com/553726) | 263 // TODO(funkysidd): Remove this (http://crbug.com/553726) |
| 264 void DrawRect(const Rect& rect, const cc::PaintFlags& paint); | 264 void DrawRect(const Rect& rect, const cc::PaintFlags& flags); |
| 265 | 265 |
| 266 // Draws the given rectangle with the given |paint| parameters. | 266 // Draws the given rectangle with the given |flags| parameters. |
| 267 void DrawRect(const RectF& rect, const cc::PaintFlags& paint); | 267 void DrawRect(const RectF& rect, const cc::PaintFlags& flags); |
| 268 | 268 |
| 269 // Draw the given point with the given |paint| parameters. | 269 // Draw the given point with the given |flags| parameters. |
| 270 // DEPRECATED in favor of the RectF version below. | 270 // DEPRECATED in favor of the RectF version below. |
| 271 // TODO(funkysidd): Remove this (http://crbug.com/553726) | 271 // TODO(funkysidd): Remove this (http://crbug.com/553726) |
| 272 void DrawPoint(const Point& p, const cc::PaintFlags& paint); | 272 void DrawPoint(const Point& p, const cc::PaintFlags& flags); |
| 273 | 273 |
| 274 // Draw the given point with the given |paint| parameters. | 274 // Draw the given point with the given |flags| parameters. |
| 275 void DrawPoint(const PointF& p, const cc::PaintFlags& paint); | 275 void DrawPoint(const PointF& p, const cc::PaintFlags& flags); |
| 276 | 276 |
| 277 // Draws a single pixel line with the specified color. | 277 // Draws a single pixel line with the specified color. |
| 278 // DEPRECATED in favor of the RectF version below. | 278 // DEPRECATED in favor of the RectF version below. |
| 279 // TODO(funkysidd): Remove this (http://crbug.com/553726) | 279 // TODO(funkysidd): Remove this (http://crbug.com/553726) |
| 280 void DrawLine(const Point& p1, const Point& p2, SkColor color); | 280 void DrawLine(const Point& p1, const Point& p2, SkColor color); |
| 281 | 281 |
| 282 // Draws a single pixel line with the specified color. | 282 // Draws a single pixel line with the specified color. |
| 283 void DrawLine(const PointF& p1, const PointF& p2, SkColor color); | 283 void DrawLine(const PointF& p1, const PointF& p2, SkColor color); |
| 284 | 284 |
| 285 // Draws a line with the given |paint| parameters. | 285 // Draws a line with the given |flags| parameters. |
| 286 // DEPRECATED in favor of the RectF version below. | 286 // DEPRECATED in favor of the RectF version below. |
| 287 // TODO(funkysidd): Remove this (http://crbug.com/553726) | 287 // TODO(funkysidd): Remove this (http://crbug.com/553726) |
| 288 void DrawLine(const Point& p1, const Point& p2, const cc::PaintFlags& paint); | 288 void DrawLine(const Point& p1, const Point& p2, const cc::PaintFlags& flags); |
| 289 | 289 |
| 290 // Draws a line with the given |paint| parameters. | 290 // Draws a line with the given |flags| parameters. |
| 291 void DrawLine(const PointF& p1, | 291 void DrawLine(const PointF& p1, |
| 292 const PointF& p2, | 292 const PointF& p2, |
| 293 const cc::PaintFlags& paint); | 293 const cc::PaintFlags& flags); |
| 294 | 294 |
| 295 // Draws a circle with the given |paint| parameters. | 295 // Draws a circle with the given |flags| parameters. |
| 296 // DEPRECATED in favor of the RectF version below. | 296 // DEPRECATED in favor of the RectF version below. |
| 297 // TODO(funkysidd): Remove this (http://crbug.com/553726) | 297 // TODO(funkysidd): Remove this (http://crbug.com/553726) |
| 298 void DrawCircle(const Point& center_point, | 298 void DrawCircle(const Point& center_point, |
| 299 int radius, | 299 int radius, |
| 300 const cc::PaintFlags& paint); | 300 const cc::PaintFlags& flags); |
| 301 | 301 |
| 302 // Draws a circle with the given |paint| parameters. | 302 // Draws a circle with the given |flags| parameters. |
| 303 void DrawCircle(const PointF& center_point, | 303 void DrawCircle(const PointF& center_point, |
| 304 float radius, | 304 float radius, |
| 305 const cc::PaintFlags& paint); | 305 const cc::PaintFlags& flags); |
| 306 | 306 |
| 307 // Draws the given rectangle with rounded corners of |radius| using the | 307 // Draws the given rectangle with rounded corners of |radius| using the |
| 308 // given |paint| parameters. DEPRECATED in favor of the RectF version below. | 308 // given |flags| parameters. DEPRECATED in favor of the RectF version below. |
| 309 // TODO(mgiuca): Remove this (http://crbug.com/553726). | 309 // TODO(mgiuca): Remove this (http://crbug.com/553726). |
| 310 void DrawRoundRect(const Rect& rect, int radius, const cc::PaintFlags& paint); | 310 void DrawRoundRect(const Rect& rect, int radius, const cc::PaintFlags& flags); |
| 311 | 311 |
| 312 // Draws the given rectangle with rounded corners of |radius| using the | 312 // Draws the given rectangle with rounded corners of |radius| using the |
| 313 // given |paint| parameters. | 313 // given |flags| parameters. |
| 314 void DrawRoundRect(const RectF& rect, | 314 void DrawRoundRect(const RectF& rect, |
| 315 float radius, | 315 float radius, |
| 316 const cc::PaintFlags& paint); | 316 const cc::PaintFlags& flags); |
| 317 | 317 |
| 318 // Draws the given path using the given |paint| parameters. | 318 // Draws the given path using the given |flags| parameters. |
| 319 void DrawPath(const SkPath& path, const cc::PaintFlags& paint); | 319 void DrawPath(const SkPath& path, const cc::PaintFlags& flags); |
| 320 | 320 |
| 321 // Draws an image with the origin at the specified location. The upper left | 321 // Draws an image with the origin at the specified location. The upper left |
| 322 // corner of the bitmap is rendered at the specified location. | 322 // corner of the bitmap is rendered at the specified location. |
| 323 // Parameters are specified relative to current canvas scale not in pixels. | 323 // Parameters are specified relative to current canvas scale not in pixels. |
| 324 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1. | 324 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1. |
| 325 void DrawImageInt(const ImageSkia&, int x, int y); | 325 void DrawImageInt(const ImageSkia&, int x, int y); |
| 326 | 326 |
| 327 // Helper for DrawImageInt(..., paint) that constructs a temporary paint and | 327 // Helper for DrawImageInt(..., flags) that constructs a temporary flags and |
| 328 // calls paint.setAlpha(alpha). | 328 // calls flags.setAlpha(alpha). |
| 329 void DrawImageInt(const ImageSkia&, int x, int y, uint8_t alpha); | 329 void DrawImageInt(const ImageSkia&, int x, int y, uint8_t alpha); |
| 330 | 330 |
| 331 // Draws an image with the origin at the specified location, using the | 331 // Draws an image with the origin at the specified location, using the |
| 332 // specified paint. The upper left corner of the bitmap is rendered at the | 332 // specified flags. The upper left corner of the bitmap is rendered at the |
| 333 // specified location. | 333 // specified location. |
| 334 // Parameters are specified relative to current canvas scale not in pixels. | 334 // Parameters are specified relative to current canvas scale not in pixels. |
| 335 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1. | 335 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1. |
| 336 void DrawImageInt(const ImageSkia& image, | 336 void DrawImageInt(const ImageSkia& image, |
| 337 int x, | 337 int x, |
| 338 int y, | 338 int y, |
| 339 const cc::PaintFlags& paint); | 339 const cc::PaintFlags& flags); |
| 340 | 340 |
| 341 // Draws a portion of an image in the specified location. The src parameters | 341 // Draws a portion of an image in the specified location. The src parameters |
| 342 // correspond to the region of the bitmap to draw in the region defined | 342 // correspond to the region of the bitmap to draw in the region defined |
| 343 // by the dest coordinates. | 343 // by the dest coordinates. |
| 344 // | 344 // |
| 345 // If the width or height of the source differs from that of the destination, | 345 // If the width or height of the source differs from that of the destination, |
| 346 // the image will be scaled. When scaling down, a mipmap will be generated. | 346 // the image will be scaled. When scaling down, a mipmap will be generated. |
| 347 // Set |filter| to use filtering for images, otherwise the nearest-neighbor | 347 // Set |filter| to use filtering for images, otherwise the nearest-neighbor |
| 348 // algorithm is used for resampling. | 348 // algorithm is used for resampling. |
| 349 // | 349 // |
| (...skipping 13 matching lines...) Expand all Loading... |
| 363 void DrawImageInt(const ImageSkia& image, | 363 void DrawImageInt(const ImageSkia& image, |
| 364 int src_x, | 364 int src_x, |
| 365 int src_y, | 365 int src_y, |
| 366 int src_w, | 366 int src_w, |
| 367 int src_h, | 367 int src_h, |
| 368 int dest_x, | 368 int dest_x, |
| 369 int dest_y, | 369 int dest_y, |
| 370 int dest_w, | 370 int dest_w, |
| 371 int dest_h, | 371 int dest_h, |
| 372 bool filter, | 372 bool filter, |
| 373 const cc::PaintFlags& paint); | 373 const cc::PaintFlags& flags); |
| 374 | 374 |
| 375 // Same as the DrawImageInt functions above. Difference being this does not | 375 // Same as the DrawImageInt functions above. Difference being this does not |
| 376 // do any scaling, i.e. it does not scale the output by the device scale | 376 // do any scaling, i.e. it does not scale the output by the device scale |
| 377 // factor (the internal image_scale_). It takes an ImageSkiaRep instead of | 377 // factor (the internal image_scale_). It takes an ImageSkiaRep instead of |
| 378 // an ImageSkia as the caller chooses the exact scale/pixel representation to | 378 // an ImageSkia as the caller chooses the exact scale/pixel representation to |
| 379 // use, which will not be scaled while drawing it into the canvas. | 379 // use, which will not be scaled while drawing it into the canvas. |
| 380 void DrawImageIntInPixel(const ImageSkiaRep& image_rep, | 380 void DrawImageIntInPixel(const ImageSkiaRep& image_rep, |
| 381 int dest_x, | 381 int dest_x, |
| 382 int dest_y, | 382 int dest_y, |
| 383 int dest_w, | 383 int dest_w, |
| 384 int dest_h, | 384 int dest_h, |
| 385 bool filter, | 385 bool filter, |
| 386 const cc::PaintFlags& paint); | 386 const cc::PaintFlags& flags); |
| 387 | 387 |
| 388 // Draws an |image| with the top left corner at |x| and |y|, clipped to | 388 // Draws an |image| with the top left corner at |x| and |y|, clipped to |
| 389 // |path|. | 389 // |path|. |
| 390 // Parameters are specified relative to current canvas scale not in pixels. | 390 // Parameters are specified relative to current canvas scale not in pixels. |
| 391 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1. | 391 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1. |
| 392 void DrawImageInPath(const ImageSkia& image, | 392 void DrawImageInPath(const ImageSkia& image, |
| 393 int x, | 393 int x, |
| 394 int y, | 394 int y, |
| 395 const SkPath& path, | 395 const SkPath& path, |
| 396 const cc::PaintFlags& paint); | 396 const cc::PaintFlags& flags); |
| 397 | 397 |
| 398 // Draws text with the specified color, fonts and location. The text is | 398 // Draws text with the specified color, fonts and location. The text is |
| 399 // aligned to the left, vertically centered, clipped to the region. If the | 399 // aligned to the left, vertically centered, clipped to the region. If the |
| 400 // text is too big, it is truncated and '...' is added to the end. | 400 // text is too big, it is truncated and '...' is added to the end. |
| 401 void DrawStringRect(const base::string16& text, | 401 void DrawStringRect(const base::string16& text, |
| 402 const FontList& font_list, | 402 const FontList& font_list, |
| 403 SkColor color, | 403 SkColor color, |
| 404 const Rect& display_rect); | 404 const Rect& display_rect); |
| 405 | 405 |
| 406 // Draws text with the specified color, fonts and location. The last argument | 406 // Draws text with the specified color, fonts and location. The last argument |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 void TileImageInt(const ImageSkia& image, | 442 void TileImageInt(const ImageSkia& image, |
| 443 int src_x, | 443 int src_x, |
| 444 int src_y, | 444 int src_y, |
| 445 float tile_scale_x, | 445 float tile_scale_x, |
| 446 float tile_scale_y, | 446 float tile_scale_y, |
| 447 int dest_x, | 447 int dest_x, |
| 448 int dest_y, | 448 int dest_y, |
| 449 int w, | 449 int w, |
| 450 int h); | 450 int h); |
| 451 | 451 |
| 452 // Helper for TileImageInt(). Initializes |paint| for tiling |image| with the | 452 // Helper for TileImageInt(). Initializes |flags| for tiling |image| with the |
| 453 // given parameters. Returns false if the provided image does not have a | 453 // given parameters. Returns false if the provided image does not have a |
| 454 // representation for the current scale. | 454 // representation for the current scale. |
| 455 bool InitPaintFlagsForTiling(const ImageSkia& image, | 455 bool InitPaintFlagsForTiling(const ImageSkia& image, |
| 456 int src_x, | 456 int src_x, |
| 457 int src_y, | 457 int src_y, |
| 458 float tile_scale_x, | 458 float tile_scale_x, |
| 459 float tile_scale_y, | 459 float tile_scale_y, |
| 460 int dest_x, | 460 int dest_x, |
| 461 int dest_y, | 461 int dest_y, |
| 462 cc::PaintFlags* paint); | 462 cc::PaintFlags* flags); |
| 463 | 463 |
| 464 // Apply transformation on the canvas. | 464 // Apply transformation on the canvas. |
| 465 void Transform(const Transform& transform); | 465 void Transform(const Transform& transform); |
| 466 | 466 |
| 467 // Draws the given string with a fade gradient at the end. | 467 // Draws the given string with a fade gradient at the end. |
| 468 void DrawFadedString(const base::string16& text, | 468 void DrawFadedString(const base::string16& text, |
| 469 const FontList& font_list, | 469 const FontList& font_list, |
| 470 SkColor color, | 470 SkColor color, |
| 471 const Rect& display_rect, | 471 const Rect& display_rect, |
| 472 int flags); | 472 int flags); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 485 void DrawImageIntHelper(const ImageSkiaRep& image_rep, | 485 void DrawImageIntHelper(const ImageSkiaRep& image_rep, |
| 486 int src_x, | 486 int src_x, |
| 487 int src_y, | 487 int src_y, |
| 488 int src_w, | 488 int src_w, |
| 489 int src_h, | 489 int src_h, |
| 490 int dest_x, | 490 int dest_x, |
| 491 int dest_y, | 491 int dest_y, |
| 492 int dest_w, | 492 int dest_w, |
| 493 int dest_h, | 493 int dest_h, |
| 494 bool filter, | 494 bool filter, |
| 495 const cc::PaintFlags& paint, | 495 const cc::PaintFlags& flags, |
| 496 bool remove_image_scale); | 496 bool remove_image_scale); |
| 497 | 497 |
| 498 // The device scale factor at which drawing on this canvas occurs. | 498 // The device scale factor at which drawing on this canvas occurs. |
| 499 // An additional scale can be applied via Canvas::Scale(). However, | 499 // An additional scale can be applied via Canvas::Scale(). However, |
| 500 // Canvas::Scale() does not affect |image_scale_|. | 500 // Canvas::Scale() does not affect |image_scale_|. |
| 501 float image_scale_; | 501 float image_scale_; |
| 502 | 502 |
| 503 // canvas_ is our active canvas object. Sometimes we are also the owner, | 503 // canvas_ is our active canvas object. Sometimes we are also the owner, |
| 504 // in which case surface_ will be set. Other times we are just | 504 // in which case surface_ will be set. Other times we are just |
| 505 // borrowing someone else's canvas, in which case canvas_ will point there | 505 // borrowing someone else's canvas, in which case canvas_ will point there |
| 506 // but surface_ will be null. | 506 // but surface_ will be null. |
| 507 sk_sp<cc::PaintSurface> surface_; | 507 sk_sp<cc::PaintSurface> surface_; |
| 508 cc::PaintCanvas* canvas_; | 508 cc::PaintCanvas* canvas_; |
| 509 | 509 |
| 510 DISALLOW_COPY_AND_ASSIGN(Canvas); | 510 DISALLOW_COPY_AND_ASSIGN(Canvas); |
| 511 }; | 511 }; |
| 512 | 512 |
| 513 } // namespace gfx | 513 } // namespace gfx |
| 514 | 514 |
| 515 #endif // UI_GFX_CANVAS_H_ | 515 #endif // UI_GFX_CANVAS_H_ |
| OLD | NEW |