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