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