Chromium Code Reviews| 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/optional.h" | |
| 14 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 15 #include "cc/paint/paint_canvas.h" | 16 #include "cc/paint/paint_canvas.h" |
| 16 #include "cc/paint/paint_flags.h" | 17 #include "cc/paint/paint_flags.h" |
| 17 #include "cc/paint/paint_surface.h" | 18 #include "cc/paint/skia_paint_canvas.h" |
| 18 #include "ui/gfx/image/image_skia.h" | 19 #include "ui/gfx/image/image_skia.h" |
| 19 #include "ui/gfx/native_widget_types.h" | 20 #include "ui/gfx/native_widget_types.h" |
| 20 #include "ui/gfx/text_constants.h" | 21 #include "ui/gfx/text_constants.h" |
| 21 | 22 |
| 22 namespace gfx { | 23 namespace gfx { |
| 23 | 24 |
| 24 class Rect; | 25 class Rect; |
| 25 class RectF; | 26 class RectF; |
| 26 class FontList; | 27 class FontList; |
| 27 class Point; | 28 class Point; |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 // Apply transformation on the canvas. | 465 // Apply transformation on the canvas. |
| 465 void Transform(const Transform& transform); | 466 void Transform(const Transform& transform); |
| 466 | 467 |
| 467 // Draws the given string with a fade gradient at the end. | 468 // Draws the given string with a fade gradient at the end. |
| 468 void DrawFadedString(const base::string16& text, | 469 void DrawFadedString(const base::string16& text, |
| 469 const FontList& font_list, | 470 const FontList& font_list, |
| 470 SkColor color, | 471 SkColor color, |
| 471 const Rect& display_rect, | 472 const Rect& display_rect, |
| 472 int flags); | 473 int flags); |
| 473 | 474 |
| 474 SkBitmap ToBitmap(); | 475 SkBitmap ToBitmap(); |
|
danakj
2017/03/21 20:02:56
make a note that writing to this bitmap will chang
vmpstr
2017/03/21 22:34:54
Done. I also renamed it to AsBitmap to (hopefully)
danakj
2017/03/21 22:40:01
GetBitmap() does an even better job of this I thin
danakj
2017/03/21 22:42:48
In fact, why not return const SkBitmap&?
| |
| 475 | 476 |
| 476 // TODO(enne): rename sk_canvas members and interface. | 477 // TODO(enne): rename sk_canvas members and interface. |
| 477 cc::PaintCanvas* sk_canvas() { return canvas_; } | 478 cc::PaintCanvas* sk_canvas() { return canvas_; } |
| 478 float image_scale() const { return image_scale_; } | 479 float image_scale() const { return image_scale_; } |
| 479 | 480 |
| 480 private: | 481 private: |
| 481 // Tests whether the provided rectangle intersects the current clip rect. | 482 // Tests whether the provided rectangle intersects the current clip rect. |
| 482 bool IntersectsClipRect(const SkRect& rect); | 483 bool IntersectsClipRect(const SkRect& rect); |
| 483 | 484 |
| 484 // Helper for the DrawImageInt functions declared above. The | 485 // Helper for the DrawImageInt functions declared above. The |
| 485 // |remove_image_scale| parameter indicates if the scale of the |image_rep| | 486 // |remove_image_scale| parameter indicates if the scale of the |image_rep| |
| 486 // should be removed when drawing the image, to avoid double-scaling it. | 487 // should be removed when drawing the image, to avoid double-scaling it. |
| 487 void DrawImageIntHelper(const ImageSkiaRep& image_rep, | 488 void DrawImageIntHelper(const ImageSkiaRep& image_rep, |
| 488 int src_x, | 489 int src_x, |
| 489 int src_y, | 490 int src_y, |
| 490 int src_w, | 491 int src_w, |
| 491 int src_h, | 492 int src_h, |
| 492 int dest_x, | 493 int dest_x, |
| 493 int dest_y, | 494 int dest_y, |
| 494 int dest_w, | 495 int dest_w, |
| 495 int dest_h, | 496 int dest_h, |
| 496 bool filter, | 497 bool filter, |
| 497 const cc::PaintFlags& flags, | 498 const cc::PaintFlags& flags, |
| 498 bool remove_image_scale); | 499 bool remove_image_scale); |
| 500 cc::PaintCanvas* CreateOwnedCanvas(const Size& size, bool is_opaque); | |
| 499 | 501 |
| 500 // The device scale factor at which drawing on this canvas occurs. | 502 // The device scale factor at which drawing on this canvas occurs. |
| 501 // An additional scale can be applied via Canvas::Scale(). However, | 503 // An additional scale can be applied via Canvas::Scale(). However, |
| 502 // Canvas::Scale() does not affect |image_scale_|. | 504 // Canvas::Scale() does not affect |image_scale_|. |
| 503 float image_scale_; | 505 float image_scale_; |
| 504 | 506 |
| 505 // 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, |
| 506 // in which case surface_ will be set. Other times we are just | 508 // in which case bitmap_ and owned_canvas_ will be set. Other times we are |
| 507 // borrowing someone else's canvas, in which case canvas_ will point there | 509 // just borrowing someone else's canvas, in which case canvas_ will point |
| 508 // but surface_ will be null. | 510 // there but bitmap_ and owned_canvas_ will not exist. |
| 509 sk_sp<cc::PaintSurface> surface_; | 511 base::Optional<SkBitmap> bitmap_; |
| 512 base::Optional<cc::SkiaPaintCanvas> owned_canvas_; | |
| 510 cc::PaintCanvas* canvas_; | 513 cc::PaintCanvas* canvas_; |
| 511 | 514 |
| 512 DISALLOW_COPY_AND_ASSIGN(Canvas); | 515 DISALLOW_COPY_AND_ASSIGN(Canvas); |
| 513 }; | 516 }; |
| 514 | 517 |
| 515 } // namespace gfx | 518 } // namespace gfx |
| 516 | 519 |
| 517 #endif // UI_GFX_CANVAS_H_ | 520 #endif // UI_GFX_CANVAS_H_ |
| OLD | NEW |