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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 86 |
87 // Instructs DrawStringInt() to not use subpixel rendering. This is useful | 87 // Instructs DrawStringInt() to not use subpixel rendering. This is useful |
88 // when rendering text onto a fully- or partially-transparent background | 88 // when rendering text onto a fully- or partially-transparent background |
89 // that will later be blended with another image. | 89 // that will later be blended with another image. |
90 NO_SUBPIXEL_RENDERING = 1 << 10, | 90 NO_SUBPIXEL_RENDERING = 1 << 10, |
91 }; | 91 }; |
92 | 92 |
93 // Creates an empty canvas with scale factor of 1x. | 93 // Creates an empty canvas with scale factor of 1x. |
94 Canvas(); | 94 Canvas(); |
95 | 95 |
96 // Creates canvas with provided DIP |size| and |scale_factor|. | 96 // Creates canvas with provided DIP |size| and |scale|. |
97 // If this canvas is not opaque, it's explicitly cleared to transparent before | 97 // If this canvas is not opaque, it's explicitly cleared to transparent before |
98 // being returned. | 98 // being returned. |
99 Canvas(const Size& size, ui::ScaleFactor scale_factor, bool is_opaque); | 99 Canvas(const Size& size, float scale, bool is_opaque); |
100 | 100 |
101 // Constructs a canvas with the size and the scale factor of the | 101 // Constructs a canvas with the size and the scale factor of the |
102 // provided |image_rep|, and draws the |image_rep| into it. | 102 // provided |image_rep|, and draws the |image_rep| into it. |
103 Canvas(const ImageSkiaRep& image_rep, bool is_opaque); | 103 Canvas(const ImageSkiaRep& image_rep, bool is_opaque); |
104 | 104 |
105 virtual ~Canvas(); | 105 virtual ~Canvas(); |
106 | 106 |
107 // Creates a Canvas backed by an |sk_canvas| with |scale_factor|. | 107 // Creates a Canvas backed by an |sk_canvas| with |scale|. |
108 // |sk_canvas| is assumed to be already scaled based on |scale_factor| | 108 // |sk_canvas| is assumed to be already scaled based on |scale| |
109 // so no additional scaling is applied. | 109 // so no additional scaling is applied. |
110 static Canvas* CreateCanvasWithoutScaling(SkCanvas* sk_canvas, | 110 static Canvas* CreateCanvasWithoutScaling(SkCanvas* sk_canvas, float scale); |
111 ui::ScaleFactor scale_factor); | |
112 | 111 |
113 // Recreates the backing platform canvas with DIP |size| and |scale_factor|. | 112 // Recreates the backing platform canvas with DIP |size| and |scale|. |
114 // If the canvas is not opaque, it is explicitly cleared. | 113 // If the canvas is not opaque, it is explicitly cleared. |
115 // This method is public so that canvas_skia_paint can recreate the platform | 114 // This method is public so that canvas_skia_paint can recreate the platform |
116 // canvas after having initialized the canvas. | 115 // canvas after having initialized the canvas. |
117 // TODO(pkotwicz): Push the scale factor into skia::PlatformCanvas such that | 116 // TODO(pkotwicz): Push the scale factor into skia::PlatformCanvas such that |
118 // this method can be private. | 117 // this method can be private. |
119 void RecreateBackingCanvas(const Size& size, | 118 void RecreateBackingCanvas(const Size& size, float scale, bool is_opaque); |
120 ui::ScaleFactor scale_factor, | |
121 bool is_opaque); | |
122 | 119 |
123 // Compute the size required to draw some text with the provided fonts. | 120 // Compute the size required to draw some text with the provided fonts. |
124 // Attempts to fit the text with the provided width and height. Increases | 121 // Attempts to fit the text with the provided width and height. Increases |
125 // height and then width as needed to make the text fit. This method | 122 // height and then width as needed to make the text fit. This method |
126 // supports multiple lines. On Skia only a line_height can be specified and | 123 // supports multiple lines. On Skia only a line_height can be specified and |
127 // specifying a 0 value for it will cause the default height to be used. | 124 // specifying a 0 value for it will cause the default height to be used. |
128 static void SizeStringInt(const base::string16& text, | 125 static void SizeStringInt(const base::string16& text, |
129 const FontList& font_list, | 126 const FontList& font_list, |
130 int* width, | 127 int* width, |
131 int* height, | 128 int* height, |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 void DrawFadeTruncatingString( | 441 void DrawFadeTruncatingString( |
445 const base::string16& text, | 442 const base::string16& text, |
446 TruncateFadeMode truncate_mode, | 443 TruncateFadeMode truncate_mode, |
447 size_t desired_characters_to_truncate_from_head, | 444 size_t desired_characters_to_truncate_from_head, |
448 const Font& font, | 445 const Font& font, |
449 SkColor color, | 446 SkColor color, |
450 const Rect& display_rect); | 447 const Rect& display_rect); |
451 | 448 |
452 skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); } | 449 skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); } |
453 SkCanvas* sk_canvas() const { return canvas_; } | 450 SkCanvas* sk_canvas() const { return canvas_; } |
454 ui::ScaleFactor scale_factor() const { return scale_factor_; } | 451 float scale() const { return scale_; } |
455 | 452 |
456 private: | 453 private: |
457 Canvas(SkCanvas* canvas, ui::ScaleFactor scale_factor); | 454 Canvas(SkCanvas* canvas, float scale); |
458 | 455 |
459 // Test whether the provided rectangle intersects the current clip rect. | 456 // Test whether the provided rectangle intersects the current clip rect. |
460 bool IntersectsClipRectInt(int x, int y, int w, int h); | 457 bool IntersectsClipRectInt(int x, int y, int w, int h); |
461 bool IntersectsClipRect(const Rect& rect); | 458 bool IntersectsClipRect(const Rect& rect); |
462 | 459 |
463 // Returns the image rep which best matches the canvas |scale_factor_|. | 460 // Returns the image rep which best matches the canvas |scale_factor_|. |
464 // Returns a null image rep if |image| contains no image reps. | 461 // Returns a null image rep if |image| contains no image reps. |
465 // Builds mip map for returned image rep if necessary. | 462 // Builds mip map for returned image rep if necessary. |
466 // | 463 // |
467 // An optional additional user defined scale can be provided. | 464 // An optional additional user defined scale can be provided. |
468 const ImageSkiaRep& GetImageRepToPaint(const ImageSkia& image) const; | 465 const ImageSkiaRep& GetImageRepToPaint(const ImageSkia& image) const; |
469 const ImageSkiaRep& GetImageRepToPaint( | 466 const ImageSkiaRep& GetImageRepToPaint( |
470 const ImageSkia& image, | 467 const ImageSkia& image, |
471 float user_defined_scale_factor_x, | 468 float user_defined_scale_factor_x, |
472 float user_defined_scale_factor_y) const; | 469 float user_defined_scale_factor_y) const; |
473 | 470 |
474 // The device scale factor at which drawing on this canvas occurs. | 471 // The device scale factor at which drawing on this canvas occurs. |
475 // An additional scale can be applied via Canvas::Scale(). However, | 472 // An additional scale can be applied via Canvas::Scale(). However, |
476 // Canvas::Scale() does not affect |scale_factor_|. | 473 // Canvas::Scale() does not affect |scale_factor_|. |
477 ui::ScaleFactor scale_factor_; | 474 float scale_; |
478 | 475 |
479 skia::RefPtr<skia::PlatformCanvas> owned_canvas_; | 476 skia::RefPtr<skia::PlatformCanvas> owned_canvas_; |
480 SkCanvas* canvas_; | 477 SkCanvas* canvas_; |
481 | 478 |
482 DISALLOW_COPY_AND_ASSIGN(Canvas); | 479 DISALLOW_COPY_AND_ASSIGN(Canvas); |
483 }; | 480 }; |
484 | 481 |
485 } // namespace gfx | 482 } // namespace gfx |
486 | 483 |
487 #endif // UI_GFX_CANVAS_H_ | 484 #endif // UI_GFX_CANVAS_H_ |
OLD | NEW |