| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // Creates canvas with provided DIP |size| and |image_scale|. | 84 // Creates canvas with provided DIP |size| and |image_scale|. |
| 85 // If this canvas is not opaque, it's explicitly cleared to transparent before | 85 // If this canvas is not opaque, it's explicitly cleared to transparent before |
| 86 // being returned. | 86 // being returned. |
| 87 Canvas(const Size& size, float image_scale, bool is_opaque); | 87 Canvas(const Size& size, float image_scale, bool is_opaque); |
| 88 | 88 |
| 89 // Creates a Canvas backed by an |sk_canvas| with |image_scale_|. | 89 // Creates a Canvas backed by an |sk_canvas| with |image_scale_|. |
| 90 // |sk_canvas| is assumed to be already scaled based on |image_scale| | 90 // |sk_canvas| is assumed to be already scaled based on |image_scale| |
| 91 // so no additional scaling is applied. | 91 // so no additional scaling is applied. |
| 92 // Note: the caller must ensure that sk_canvas outlives this object, or until | 92 // Note: the caller must ensure that sk_canvas outlives this object, or until |
| 93 // RecreateBackingCanvas is called. | 93 // RecreateBackingCanvas is called. |
| 94 Canvas(SkCanvas* sk_canvas, float image_scale); | 94 // TODO(cdl): Update CdlCanvas to non ref-counted. |
| 95 Canvas(CdlCanvas* sk_canvas, float image_scale); |
| 95 | 96 |
| 96 virtual ~Canvas(); | 97 virtual ~Canvas(); |
| 97 | 98 |
| 98 // Recreates the backing platform canvas with DIP |size| and |image_scale_|. | 99 // Recreates the backing platform canvas with DIP |size| and |image_scale_|. |
| 99 // If the canvas is not opaque, it is explicitly cleared. | 100 // If the canvas is not opaque, it is explicitly cleared. |
| 100 // This method is public so that canvas_skia_paint can recreate the platform | 101 // This method is public so that canvas_skia_paint can recreate the platform |
| 101 // canvas after having initialized the canvas. | 102 // canvas after having initialized the canvas. |
| 102 // TODO(pkotwicz): Push the image_scale into skia::PlatformCanvas such that | 103 // TODO(pkotwicz): Push the image_scale into skia::PlatformCanvas such that |
| 103 // this method can be private. | 104 // this method can be private. |
| 104 void RecreateBackingCanvas(const Size& size, | 105 void RecreateBackingCanvas(const Size& size, |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 254 |
| 254 // 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 |
| 255 // color and transfer mode. | 256 // color and transfer mode. |
| 256 // | 257 // |
| 257 // NOTE: if you need a single pixel line, use DrawLine. | 258 // NOTE: if you need a single pixel line, use DrawLine. |
| 258 void DrawRect(const RectF& rect, SkColor color, SkBlendMode mode); | 259 void DrawRect(const RectF& rect, SkColor color, SkBlendMode mode); |
| 259 | 260 |
| 260 // Draws the given rectangle with the given |paint| parameters. | 261 // Draws the given rectangle with the given |paint| parameters. |
| 261 // DEPRECATED in favor of the RectF version below. | 262 // DEPRECATED in favor of the RectF version below. |
| 262 // TODO(funkysidd): Remove this (http://crbug.com/553726) | 263 // TODO(funkysidd): Remove this (http://crbug.com/553726) |
| 263 void DrawRect(const Rect& rect, const SkPaint& paint); | 264 void DrawRect(const Rect& rect, const CdlPaint& paint); |
| 264 | 265 |
| 265 // Draws the given rectangle with the given |paint| parameters. | 266 // Draws the given rectangle with the given |paint| parameters. |
| 266 void DrawRect(const RectF& rect, const SkPaint& paint); | 267 void DrawRect(const RectF& rect, const CdlPaint& paint); |
| 267 | 268 |
| 268 // Draw the given point with the given |paint| parameters. | 269 // Draw the given point with the given |paint| parameters. |
| 269 // DEPRECATED in favor of the RectF version below. | 270 // DEPRECATED in favor of the RectF version below. |
| 270 // TODO(funkysidd): Remove this (http://crbug.com/553726) | 271 // TODO(funkysidd): Remove this (http://crbug.com/553726) |
| 271 void DrawPoint(const Point& p, const SkPaint& paint); | 272 void DrawPoint(const Point& p, const CdlPaint& paint); |
| 272 | 273 |
| 273 // Draw the given point with the given |paint| parameters. | 274 // Draw the given point with the given |paint| parameters. |
| 274 void DrawPoint(const PointF& p, const SkPaint& paint); | 275 void DrawPoint(const PointF& p, const CdlPaint& paint); |
| 275 | 276 |
| 276 // Draws a single pixel line with the specified color. | 277 // Draws a single pixel line with the specified color. |
| 277 // DEPRECATED in favor of the RectF version below. | 278 // DEPRECATED in favor of the RectF version below. |
| 278 // TODO(funkysidd): Remove this (http://crbug.com/553726) | 279 // TODO(funkysidd): Remove this (http://crbug.com/553726) |
| 279 void DrawLine(const Point& p1, const Point& p2, SkColor color); | 280 void DrawLine(const Point& p1, const Point& p2, SkColor color); |
| 280 | 281 |
| 281 // Draws a single pixel line with the specified color. | 282 // Draws a single pixel line with the specified color. |
| 282 void DrawLine(const PointF& p1, const PointF& p2, SkColor color); | 283 void DrawLine(const PointF& p1, const PointF& p2, SkColor color); |
| 283 | 284 |
| 284 // Draws a line with the given |paint| parameters. | 285 // Draws a line with the given |paint| parameters. |
| 285 // DEPRECATED in favor of the RectF version below. | 286 // DEPRECATED in favor of the RectF version below. |
| 286 // TODO(funkysidd): Remove this (http://crbug.com/553726) | 287 // TODO(funkysidd): Remove this (http://crbug.com/553726) |
| 287 void DrawLine(const Point& p1, const Point& p2, const SkPaint& paint); | 288 void DrawLine(const Point& p1, const Point& p2, const CdlPaint& paint); |
| 288 | 289 |
| 289 // Draws a line with the given |paint| parameters. | 290 // Draws a line with the given |paint| parameters. |
| 290 void DrawLine(const PointF& p1, const PointF& p2, const SkPaint& paint); | 291 void DrawLine(const PointF& p1, const PointF& p2, const CdlPaint& paint); |
| 291 | 292 |
| 292 // Draws a circle with the given |paint| parameters. | 293 // Draws a circle with the given |paint| parameters. |
| 293 // DEPRECATED in favor of the RectF version below. | 294 // DEPRECATED in favor of the RectF version below. |
| 294 // TODO(funkysidd): Remove this (http://crbug.com/553726) | 295 // TODO(funkysidd): Remove this (http://crbug.com/553726) |
| 295 void DrawCircle(const Point& center_point, | 296 void DrawCircle(const Point& center_point, int radius, const CdlPaint& paint); |
| 296 int radius, | |
| 297 const SkPaint& paint); | |
| 298 | 297 |
| 299 // Draws a circle with the given |paint| parameters. | 298 // Draws a circle with the given |paint| parameters. |
| 300 void DrawCircle(const PointF& center_point, | 299 void DrawCircle(const PointF& center_point, |
| 301 float radius, | 300 float radius, |
| 302 const SkPaint& paint); | 301 const CdlPaint& paint); |
| 303 | 302 |
| 304 // Draws the given rectangle with rounded corners of |radius| using the | 303 // Draws the given rectangle with rounded corners of |radius| using the |
| 305 // given |paint| parameters. DEPRECATED in favor of the RectF version below. | 304 // given |paint| parameters. DEPRECATED in favor of the RectF version below. |
| 306 // TODO(mgiuca): Remove this (http://crbug.com/553726). | 305 // TODO(mgiuca): Remove this (http://crbug.com/553726). |
| 307 void DrawRoundRect(const Rect& rect, int radius, const SkPaint& paint); | 306 void DrawRoundRect(const Rect& rect, int radius, const CdlPaint& paint); |
| 308 | 307 |
| 309 // Draws the given rectangle with rounded corners of |radius| using the | 308 // Draws the given rectangle with rounded corners of |radius| using the |
| 310 // given |paint| parameters. | 309 // given |paint| parameters. |
| 311 void DrawRoundRect(const RectF& rect, float radius, const SkPaint& paint); | 310 void DrawRoundRect(const RectF& rect, float radius, const CdlPaint& paint); |
| 312 | 311 |
| 313 // Draws the given path using the given |paint| parameters. | 312 // Draws the given path using the given |paint| parameters. |
| 314 void DrawPath(const SkPath& path, const SkPaint& paint); | 313 void DrawPath(const SkPath& path, const CdlPaint& paint); |
| 315 | 314 |
| 316 // Draws an image with the origin at the specified location. The upper left | 315 // Draws an image with the origin at the specified location. The upper left |
| 317 // corner of the bitmap is rendered at the specified location. | 316 // corner of the bitmap is rendered at the specified location. |
| 318 // Parameters are specified relative to current canvas scale not in pixels. | 317 // Parameters are specified relative to current canvas scale not in pixels. |
| 319 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1. | 318 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1. |
| 320 void DrawImageInt(const ImageSkia&, int x, int y); | 319 void DrawImageInt(const ImageSkia&, int x, int y); |
| 321 | 320 |
| 322 // Helper for DrawImageInt(..., paint) that constructs a temporary paint and | 321 // Helper for DrawImageInt(..., paint) that constructs a temporary paint and |
| 323 // calls paint.setAlpha(alpha). | 322 // calls paint.setAlpha(alpha). |
| 324 void DrawImageInt(const ImageSkia&, int x, int y, uint8_t alpha); | 323 void DrawImageInt(const ImageSkia&, int x, int y, uint8_t alpha); |
| 325 | 324 |
| 326 // Draws an image with the origin at the specified location, using the | 325 // Draws an image with the origin at the specified location, using the |
| 327 // specified paint. The upper left corner of the bitmap is rendered at the | 326 // specified paint. The upper left corner of the bitmap is rendered at the |
| 328 // specified location. | 327 // specified location. |
| 329 // Parameters are specified relative to current canvas scale not in pixels. | 328 // Parameters are specified relative to current canvas scale not in pixels. |
| 330 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1. | 329 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1. |
| 331 void DrawImageInt(const ImageSkia& image, | 330 void DrawImageInt(const ImageSkia& image, |
| 332 int x, | 331 int x, |
| 333 int y, | 332 int y, |
| 334 const SkPaint& paint); | 333 const CdlPaint& paint); |
| 335 | 334 |
| 336 // Draws a portion of an image in the specified location. The src parameters | 335 // Draws a portion of an image in the specified location. The src parameters |
| 337 // correspond to the region of the bitmap to draw in the region defined | 336 // correspond to the region of the bitmap to draw in the region defined |
| 338 // by the dest coordinates. | 337 // by the dest coordinates. |
| 339 // | 338 // |
| 340 // If the width or height of the source differs from that of the destination, | 339 // If the width or height of the source differs from that of the destination, |
| 341 // the image will be scaled. When scaling down, a mipmap will be generated. | 340 // the image will be scaled. When scaling down, a mipmap will be generated. |
| 342 // Set |filter| to use filtering for images, otherwise the nearest-neighbor | 341 // Set |filter| to use filtering for images, otherwise the nearest-neighbor |
| 343 // algorithm is used for resampling. | 342 // algorithm is used for resampling. |
| 344 // | 343 // |
| (...skipping 13 matching lines...) Expand all Loading... |
| 358 void DrawImageInt(const ImageSkia& image, | 357 void DrawImageInt(const ImageSkia& image, |
| 359 int src_x, | 358 int src_x, |
| 360 int src_y, | 359 int src_y, |
| 361 int src_w, | 360 int src_w, |
| 362 int src_h, | 361 int src_h, |
| 363 int dest_x, | 362 int dest_x, |
| 364 int dest_y, | 363 int dest_y, |
| 365 int dest_w, | 364 int dest_w, |
| 366 int dest_h, | 365 int dest_h, |
| 367 bool filter, | 366 bool filter, |
| 368 const SkPaint& paint); | 367 const CdlPaint& paint); |
| 369 | 368 |
| 370 // Same as the DrawImageInt functions above. Difference being this does not | 369 // Same as the DrawImageInt functions above. Difference being this does not |
| 371 // do any scaling, i.e. it does not scale the output by the device scale | 370 // do any scaling, i.e. it does not scale the output by the device scale |
| 372 // factor (the internal image_scale_). It takes an ImageSkiaRep instead of | 371 // factor (the internal image_scale_). It takes an ImageSkiaRep instead of |
| 373 // an ImageSkia as the caller chooses the exact scale/pixel representation to | 372 // an ImageSkia as the caller chooses the exact scale/pixel representation to |
| 374 // use, which will not be scaled while drawing it into the canvas. | 373 // use, which will not be scaled while drawing it into the canvas. |
| 375 void DrawImageIntInPixel(const ImageSkiaRep& image_rep, | 374 void DrawImageIntInPixel(const ImageSkiaRep& image_rep, |
| 376 int dest_x, | 375 int dest_x, |
| 377 int dest_y, | 376 int dest_y, |
| 378 int dest_w, | 377 int dest_w, |
| 379 int dest_h, | 378 int dest_h, |
| 380 bool filter, | 379 bool filter, |
| 381 const SkPaint& paint); | 380 const CdlPaint& paint); |
| 382 | 381 |
| 383 // Draws an |image| with the top left corner at |x| and |y|, clipped to | 382 // Draws an |image| with the top left corner at |x| and |y|, clipped to |
| 384 // |path|. | 383 // |path|. |
| 385 // Parameters are specified relative to current canvas scale not in pixels. | 384 // Parameters are specified relative to current canvas scale not in pixels. |
| 386 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1. | 385 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1. |
| 387 void DrawImageInPath(const ImageSkia& image, | 386 void DrawImageInPath(const ImageSkia& image, |
| 388 int x, | 387 int x, |
| 389 int y, | 388 int y, |
| 390 const SkPath& path, | 389 const SkPath& path, |
| 391 const SkPaint& paint); | 390 const CdlPaint& paint); |
| 392 | 391 |
| 393 // Draws text with the specified color, fonts and location. The text is | 392 // Draws text with the specified color, fonts and location. The text is |
| 394 // aligned to the left, vertically centered, clipped to the region. If the | 393 // aligned to the left, vertically centered, clipped to the region. If the |
| 395 // text is too big, it is truncated and '...' is added to the end. | 394 // text is too big, it is truncated and '...' is added to the end. |
| 396 void DrawStringRect(const base::string16& text, | 395 void DrawStringRect(const base::string16& text, |
| 397 const FontList& font_list, | 396 const FontList& font_list, |
| 398 SkColor color, | 397 SkColor color, |
| 399 const Rect& display_rect); | 398 const Rect& display_rect); |
| 400 | 399 |
| 401 // Draws text with the specified color, fonts and location. The last argument | 400 // Draws text with the specified color, fonts and location. The last argument |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 // Helper for TileImageInt(). Initializes |paint| for tiling |image| with the | 457 // Helper for TileImageInt(). Initializes |paint| for tiling |image| with the |
| 459 // given parameters. Returns false if the provided image does not have a | 458 // given parameters. Returns false if the provided image does not have a |
| 460 // representation for the current scale. | 459 // representation for the current scale. |
| 461 bool InitSkPaintForTiling(const ImageSkia& image, | 460 bool InitSkPaintForTiling(const ImageSkia& image, |
| 462 int src_x, | 461 int src_x, |
| 463 int src_y, | 462 int src_y, |
| 464 float tile_scale_x, | 463 float tile_scale_x, |
| 465 float tile_scale_y, | 464 float tile_scale_y, |
| 466 int dest_x, | 465 int dest_x, |
| 467 int dest_y, | 466 int dest_y, |
| 468 SkPaint* paint); | 467 CdlPaint* paint); |
| 469 | 468 |
| 470 // Apply transformation on the canvas. | 469 // Apply transformation on the canvas. |
| 471 void Transform(const Transform& transform); | 470 void Transform(const Transform& transform); |
| 472 | 471 |
| 473 // Draws the given string with a fade gradient at the end. | 472 // Draws the given string with a fade gradient at the end. |
| 474 void DrawFadedString(const base::string16& text, | 473 void DrawFadedString(const base::string16& text, |
| 475 const FontList& font_list, | 474 const FontList& font_list, |
| 476 SkColor color, | 475 SkColor color, |
| 477 const Rect& display_rect, | 476 const Rect& display_rect, |
| 478 int flags); | 477 int flags); |
| 479 | 478 |
| 480 SkCanvas* sk_canvas() { return canvas_; } | 479 CdlCanvas* sk_canvas() { return canvas_; } |
| 481 float image_scale() const { return image_scale_; } | 480 float image_scale() const { return image_scale_; } |
| 482 | 481 |
| 483 private: | 482 private: |
| 484 // Tests whether the provided rectangle intersects the current clip rect. | 483 // Tests whether the provided rectangle intersects the current clip rect. |
| 485 bool IntersectsClipRect(const SkRect& rect); | 484 bool IntersectsClipRect(const SkRect& rect); |
| 486 | 485 |
| 487 // Helper for the DrawImageInt functions declared above. The | 486 // Helper for the DrawImageInt functions declared above. The |
| 488 // |remove_image_scale| parameter indicates if the scale of the |image_rep| | 487 // |remove_image_scale| parameter indicates if the scale of the |image_rep| |
| 489 // should be removed when drawing the image, to avoid double-scaling it. | 488 // should be removed when drawing the image, to avoid double-scaling it. |
| 490 void DrawImageIntHelper(const ImageSkiaRep& image_rep, | 489 void DrawImageIntHelper(const ImageSkiaRep& image_rep, |
| 491 int src_x, | 490 int src_x, |
| 492 int src_y, | 491 int src_y, |
| 493 int src_w, | 492 int src_w, |
| 494 int src_h, | 493 int src_h, |
| 495 int dest_x, | 494 int dest_x, |
| 496 int dest_y, | 495 int dest_y, |
| 497 int dest_w, | 496 int dest_w, |
| 498 int dest_h, | 497 int dest_h, |
| 499 bool filter, | 498 bool filter, |
| 500 const SkPaint& paint, | 499 const CdlPaint& paint, |
| 501 bool remove_image_scale); | 500 bool remove_image_scale); |
| 502 | 501 |
| 503 // The device scale factor at which drawing on this canvas occurs. | 502 // The device scale factor at which drawing on this canvas occurs. |
| 504 // An additional scale can be applied via Canvas::Scale(). However, | 503 // An additional scale can be applied via Canvas::Scale(). However, |
| 505 // Canvas::Scale() does not affect |image_scale_|. | 504 // Canvas::Scale() does not affect |image_scale_|. |
| 506 float image_scale_; | 505 float image_scale_; |
| 507 | 506 |
| 508 // canvas_ is our active canvas object. Sometimes we are also the owner, | 507 // canvas_ is our active canvas object. Sometimes we are also the owner, |
| 509 // in which case canvas_owner_ will be set. Other times we are just | 508 // in which case canvas_owner_ will be set. Other times we are just |
| 510 // borrowing someone else's canvas, in which case canvas_ will point there | 509 // borrowing someone else's canvas, in which case canvas_ will point there |
| 511 // but canvas_owner_ will be null. | 510 // but canvas_owner_ will be null. |
| 512 std::unique_ptr<SkCanvas> canvas_owner_; | 511 std::unique_ptr<CdlCanvas> canvas_owner_; |
| 513 SkCanvas* canvas_; | 512 CdlCanvas* canvas_; |
| 514 | 513 |
| 515 DISALLOW_COPY_AND_ASSIGN(Canvas); | 514 DISALLOW_COPY_AND_ASSIGN(Canvas); |
| 516 }; | 515 }; |
| 517 | 516 |
| 518 } // namespace gfx | 517 } // namespace gfx |
| 519 | 518 |
| 520 #endif // UI_GFX_CANVAS_H_ | 519 #endif // UI_GFX_CANVAS_H_ |
| OLD | NEW |