Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: trunk/src/ui/gfx/canvas.h

Issue 24262008: Revert 224473 "Remove dependency on ui::ScaleFactor from ui/gfx" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « trunk/src/ui/compositor/layer.cc ('k') | trunk/src/ui/gfx/canvas.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // Similar to FORCE_RTL_DIRECTIONALITY, but left-to-right. 83 // Similar to FORCE_RTL_DIRECTIONALITY, but left-to-right.
84 // See FORCE_RTL_DIRECTIONALITY for details. 84 // See FORCE_RTL_DIRECTIONALITY for details.
85 FORCE_LTR_DIRECTIONALITY = 1 << 9, 85 FORCE_LTR_DIRECTIONALITY = 1 << 9,
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 image_scale 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 |image_scale|. 96 // Creates canvas with provided DIP |size| and |scale_factor|.
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, float image_scale, bool is_opaque); 99 Canvas(const Size& size, ui::ScaleFactor scale_factor, bool is_opaque);
100 100
101 // Constructs a canvas with the size and the image_scale of the provided 101 // Constructs a canvas with the size and the scale factor of the
102 // |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 |image_scale_|. 107 // Creates a Canvas backed by an |sk_canvas| with |scale_factor|.
108 // |sk_canvas| is assumed to be already scaled based on |image_scale| 108 // |sk_canvas| is assumed to be already scaled based on |scale_factor|
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,
111 float image_scale); 111 ui::ScaleFactor scale_factor);
112 112
113 // Recreates the backing platform canvas with DIP |size| and |image_scale_|. 113 // Recreates the backing platform canvas with DIP |size| and |scale_factor|.
114 // If the canvas is not opaque, it is explicitly cleared. 114 // If the canvas is not opaque, it is explicitly cleared.
115 // This method is public so that canvas_skia_paint can recreate the platform 115 // This method is public so that canvas_skia_paint can recreate the platform
116 // canvas after having initialized the canvas. 116 // canvas after having initialized the canvas.
117 // TODO(pkotwicz): Push the image_scale into skia::PlatformCanvas such that 117 // TODO(pkotwicz): Push the scale factor into skia::PlatformCanvas such that
118 // this method can be private. 118 // this method can be private.
119 void RecreateBackingCanvas(const Size& size, 119 void RecreateBackingCanvas(const Size& size,
120 float image_scale, 120 ui::ScaleFactor scale_factor,
121 bool is_opaque); 121 bool is_opaque);
122 122
123 // Compute the size required to draw some text with the provided fonts. 123 // 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 124 // 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 125 // 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 126 // 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. 127 // specifying a 0 value for it will cause the default height to be used.
128 static void SizeStringInt(const base::string16& text, 128 static void SizeStringInt(const base::string16& text,
129 const FontList& font_list, 129 const FontList& font_list,
130 int* width, 130 int* width,
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 void DrawFadeTruncatingString( 444 void DrawFadeTruncatingString(
445 const base::string16& text, 445 const base::string16& text,
446 TruncateFadeMode truncate_mode, 446 TruncateFadeMode truncate_mode,
447 size_t desired_characters_to_truncate_from_head, 447 size_t desired_characters_to_truncate_from_head,
448 const Font& font, 448 const Font& font,
449 SkColor color, 449 SkColor color,
450 const Rect& display_rect); 450 const Rect& display_rect);
451 451
452 skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); } 452 skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); }
453 SkCanvas* sk_canvas() const { return canvas_; } 453 SkCanvas* sk_canvas() const { return canvas_; }
454 float image_scale() const { return image_scale_; } 454 ui::ScaleFactor scale_factor() const { return scale_factor_; }
455 455
456 private: 456 private:
457 Canvas(SkCanvas* canvas, float image_scale); 457 Canvas(SkCanvas* canvas, ui::ScaleFactor scale_factor);
458 458
459 // Test whether the provided rectangle intersects the current clip rect. 459 // Test whether the provided rectangle intersects the current clip rect.
460 bool IntersectsClipRectInt(int x, int y, int w, int h); 460 bool IntersectsClipRectInt(int x, int y, int w, int h);
461 bool IntersectsClipRect(const Rect& rect); 461 bool IntersectsClipRect(const Rect& rect);
462 462
463 // Returns the image rep which best matches the canvas |image_scale_|. 463 // Returns the image rep which best matches the canvas |scale_factor_|.
464 // Returns a null image rep if |image| contains no image reps. 464 // Returns a null image rep if |image| contains no image reps.
465 // Builds mip map for returned image rep if necessary. 465 // Builds mip map for returned image rep if necessary.
466 // 466 //
467 // An optional additional user defined scale can be provided. 467 // An optional additional user defined scale can be provided.
468 const ImageSkiaRep& GetImageRepToPaint(const ImageSkia& image) const; 468 const ImageSkiaRep& GetImageRepToPaint(const ImageSkia& image) const;
469 const ImageSkiaRep& GetImageRepToPaint( 469 const ImageSkiaRep& GetImageRepToPaint(
470 const ImageSkia& image, 470 const ImageSkia& image,
471 float user_defined_scale_factor_x, 471 float user_defined_scale_factor_x,
472 float user_defined_scale_factor_y) const; 472 float user_defined_scale_factor_y) const;
473 473
474 // The device scale factor at which drawing on this canvas occurs. 474 // The device scale factor at which drawing on this canvas occurs.
475 // An additional scale can be applied via Canvas::Scale(). However, 475 // An additional scale can be applied via Canvas::Scale(). However,
476 // Canvas::Scale() does not affect |image_scale_|. 476 // Canvas::Scale() does not affect |scale_factor_|.
477 float image_scale_; 477 ui::ScaleFactor scale_factor_;
478 478
479 skia::RefPtr<skia::PlatformCanvas> owned_canvas_; 479 skia::RefPtr<skia::PlatformCanvas> owned_canvas_;
480 SkCanvas* canvas_; 480 SkCanvas* canvas_;
481 481
482 DISALLOW_COPY_AND_ASSIGN(Canvas); 482 DISALLOW_COPY_AND_ASSIGN(Canvas);
483 }; 483 };
484 484
485 } // namespace gfx 485 } // namespace gfx
486 486
487 #endif // UI_GFX_CANVAS_H_ 487 #endif // UI_GFX_CANVAS_H_
OLDNEW
« no previous file with comments | « trunk/src/ui/compositor/layer.cc ('k') | trunk/src/ui/gfx/canvas.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698