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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 Canvas(); | 82 Canvas(); |
83 | 83 |
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 Canvas(sk_sp<SkCanvas> sk_canvas, float image_scale); | 92 // Note: the caller must ensure that sk_canvas outlives this object, or until |
| 93 // RecreateBackingCanvas is called. |
| 94 Canvas(SkCanvas* sk_canvas, float image_scale); |
93 | 95 |
94 virtual ~Canvas(); | 96 virtual ~Canvas(); |
95 | 97 |
96 // Recreates the backing platform canvas with DIP |size| and |image_scale_|. | 98 // Recreates the backing platform canvas with DIP |size| and |image_scale_|. |
97 // If the canvas is not opaque, it is explicitly cleared. | 99 // If the canvas is not opaque, it is explicitly cleared. |
98 // This method is public so that canvas_skia_paint can recreate the platform | 100 // This method is public so that canvas_skia_paint can recreate the platform |
99 // canvas after having initialized the canvas. | 101 // canvas after having initialized the canvas. |
100 // TODO(pkotwicz): Push the image_scale into skia::PlatformCanvas such that | 102 // TODO(pkotwicz): Push the image_scale into skia::PlatformCanvas such that |
101 // this method can be private. | 103 // this method can be private. |
102 void RecreateBackingCanvas(const Size& size, | 104 void RecreateBackingCanvas(const Size& size, |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 // Apply transformation on the canvas. | 476 // Apply transformation on the canvas. |
475 void Transform(const Transform& transform); | 477 void Transform(const Transform& transform); |
476 | 478 |
477 // Draws the given string with a fade gradient at the end. | 479 // Draws the given string with a fade gradient at the end. |
478 void DrawFadedString(const base::string16& text, | 480 void DrawFadedString(const base::string16& text, |
479 const FontList& font_list, | 481 const FontList& font_list, |
480 SkColor color, | 482 SkColor color, |
481 const Rect& display_rect, | 483 const Rect& display_rect, |
482 int flags); | 484 int flags); |
483 | 485 |
484 SkCanvas* sk_canvas() { return canvas_.get(); } | 486 SkCanvas* sk_canvas() { return canvas_; } |
485 float image_scale() const { return image_scale_; } | 487 float image_scale() const { return image_scale_; } |
486 | 488 |
487 private: | 489 private: |
488 // Tests whether the provided rectangle intersects the current clip rect. | 490 // Tests whether the provided rectangle intersects the current clip rect. |
489 bool IntersectsClipRect(const SkRect& rect); | 491 bool IntersectsClipRect(const SkRect& rect); |
490 | 492 |
491 // Helper for the DrawImageInt functions declared above. The | 493 // Helper for the DrawImageInt functions declared above. The |
492 // |remove_image_scale| parameter indicates if the scale of the |image_rep| | 494 // |remove_image_scale| parameter indicates if the scale of the |image_rep| |
493 // should be removed when drawing the image, to avoid double-scaling it. | 495 // should be removed when drawing the image, to avoid double-scaling it. |
494 void DrawImageIntHelper(const ImageSkiaRep& image_rep, | 496 void DrawImageIntHelper(const ImageSkiaRep& image_rep, |
495 int src_x, | 497 int src_x, |
496 int src_y, | 498 int src_y, |
497 int src_w, | 499 int src_w, |
498 int src_h, | 500 int src_h, |
499 int dest_x, | 501 int dest_x, |
500 int dest_y, | 502 int dest_y, |
501 int dest_w, | 503 int dest_w, |
502 int dest_h, | 504 int dest_h, |
503 bool filter, | 505 bool filter, |
504 const SkPaint& paint, | 506 const SkPaint& paint, |
505 bool remove_image_scale); | 507 bool remove_image_scale); |
506 | 508 |
507 // The device scale factor at which drawing on this canvas occurs. | 509 // The device scale factor at which drawing on this canvas occurs. |
508 // An additional scale can be applied via Canvas::Scale(). However, | 510 // An additional scale can be applied via Canvas::Scale(). However, |
509 // Canvas::Scale() does not affect |image_scale_|. | 511 // Canvas::Scale() does not affect |image_scale_|. |
510 float image_scale_; | 512 float image_scale_; |
511 | 513 |
512 sk_sp<SkCanvas> canvas_; | 514 // canvas_ is our active canvas object. Sometimes we are also the owner, |
| 515 // in which case canvas_owner_ will be set. Other times we are just |
| 516 // borrowing someone else's canvas, in which case canvas_ will point there |
| 517 // but canvas_owner_ will be null. |
| 518 std::unique_ptr<SkCanvas> canvas_owner_; |
| 519 SkCanvas* canvas_; |
513 | 520 |
514 DISALLOW_COPY_AND_ASSIGN(Canvas); | 521 DISALLOW_COPY_AND_ASSIGN(Canvas); |
515 }; | 522 }; |
516 | 523 |
517 } // namespace gfx | 524 } // namespace gfx |
518 | 525 |
519 #endif // UI_GFX_CANVAS_H_ | 526 #endif // UI_GFX_CANVAS_H_ |
OLD | NEW |