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

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

Issue 10701063: Cleanup gfx::Canvas now that 10562027 has landed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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
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 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 // Instructs DrawStringInt() to not use subpixel rendering. This is useful 94 // Instructs DrawStringInt() to not use subpixel rendering. This is useful
95 // when rendering text onto a fully- or partially-transparent background 95 // when rendering text onto a fully- or partially-transparent background
96 // that will later be blended with another image. 96 // that will later be blended with another image.
97 NO_SUBPIXEL_RENDERING = 1 << 13, 97 NO_SUBPIXEL_RENDERING = 1 << 13,
98 }; 98 };
99 99
100 // Creates an empty canvas with scale factor of 1x. 100 // Creates an empty canvas with scale factor of 1x.
101 Canvas(); 101 Canvas();
102 102
103 // Creates canvas with provided DIP |size| and a scale factor of 1x.
104 // If this canvas is not opaque, it's explicitly cleared to transparent before
105 // being returned.
106 // TODO(pkotwicz): Remove this constructor.
107 Canvas(const gfx::Size& size, bool is_opaque);
108
109 // Creates canvas with provided DIP |size| and |scale_factor|. 103 // Creates canvas with provided DIP |size| and |scale_factor|.
110 // If this canvas is not opaque, it's explicitly cleared to transparent before 104 // If this canvas is not opaque, it's explicitly cleared to transparent before
111 // being returned. 105 // being returned.
112 Canvas(const gfx::Size& size, 106 Canvas(const gfx::Size& size,
113 ui::ScaleFactor scale_factor, 107 ui::ScaleFactor scale_factor,
114 bool is_opaque); 108 bool is_opaque);
115 109
116 // Constructs a canvas with the size and the scale factor of the 110 // Constructs a canvas with the size and the scale factor of the
117 // provided |image_rep|, and draws the |image_rep| into it. 111 // provided |image_rep|, and draws the |image_rep| into it.
118 Canvas(const gfx::ImageSkiaRep& image_rep, bool is_opaque); 112 Canvas(const gfx::ImageSkiaRep& image_rep, bool is_opaque);
119 113
120 // Sets scale factor to |scale_factor|. 114 virtual ~Canvas();
121 // Only scales canvas if |scale_canvas| is true.
122 Canvas(SkCanvas* canvas,
123 ui::ScaleFactor scale_factor,
124 bool scale_canvas);
125 115
126 virtual ~Canvas(); 116 // Creates a gfx::Canvas backed by an |sk_canvas| with |scale_factor|.
117 // |sk_canvas| is assumed to be already scaled based on |scale_factor|
118 // so no additional scaling is applied.
119 static Canvas* CreateCanvasWithoutScaling(SkCanvas* sk_canvas,
120 ui::ScaleFactor scale_factor);
127 121
128 // Recreates the backing platform canvas with DIP |size| and |scale_factor|. 122 // Recreates the backing platform canvas with DIP |size| and |scale_factor|.
129 // If the canvas is not opaque, it is explicitly cleared. 123 // If the canvas is not opaque, it is explicitly cleared.
130 // This method is public so that canvas_skia_paint can recreate the platform 124 // This method is public so that canvas_skia_paint can recreate the platform
131 // canvas after having initialized the canvas. 125 // canvas after having initialized the canvas.
132 // TODO(pkotwicz): Push the scale factor into skia::PlatformCanvas such that 126 // TODO(pkotwicz): Push the scale factor into skia::PlatformCanvas such that
133 // this method can be private. 127 // this method can be private.
134 void RecreateBackingCanvas(const gfx::Size& size, 128 void RecreateBackingCanvas(const gfx::Size& size,
135 ui::ScaleFactor scale_factor, 129 ui::ScaleFactor scale_factor,
136 bool is_opaque); 130 bool is_opaque);
(...skipping 29 matching lines...) Expand all
166 // On Mac, NOTIMPLEMENTED. 160 // On Mac, NOTIMPLEMENTED.
167 // TODO(dhollowa): Skia-native implementation is underway. Cut over to 161 // TODO(dhollowa): Skia-native implementation is underway. Cut over to
168 // that when ready. http::/crbug.com/109946 162 // that when ready. http::/crbug.com/109946
169 void DrawStringWithHalo(const string16& text, 163 void DrawStringWithHalo(const string16& text,
170 const gfx::Font& font, 164 const gfx::Font& font,
171 SkColor text_color, 165 SkColor text_color,
172 SkColor halo_color, 166 SkColor halo_color,
173 int x, int y, int w, int h, 167 int x, int y, int w, int h,
174 int flags); 168 int flags);
175 169
176 // Extracts a bitmap from the contents of this canvas.
177 // TODO(pkotwicz): Remove ExtractBitmap once all callers use
178 // ExtractImageSkiaRep instead.
179 SkBitmap ExtractBitmap() const;
180
181 // Extracts an ImageSkiaRep from the contents of this canvas. 170 // Extracts an ImageSkiaRep from the contents of this canvas.
182 gfx::ImageSkiaRep ExtractImageSkiaRep() const; 171 gfx::ImageSkiaRep ExtractImageRep() const;
183 172
184 // Draws a dashed rectangle of the specified color. 173 // Draws a dashed rectangle of the specified color.
185 void DrawDashedRect(const gfx::Rect& rect, SkColor color); 174 void DrawDashedRect(const gfx::Rect& rect, SkColor color);
186 175
187 // Saves a copy of the drawing state onto a stack, operating on this copy 176 // Saves a copy of the drawing state onto a stack, operating on this copy
188 // until a balanced call to Restore() is made. 177 // until a balanced call to Restore() is made.
189 void Save(); 178 void Save();
190 179
191 // As with Save(), except draws to a layer that is blended with the canvas 180 // As with Save(), except draws to a layer that is blended with the canvas
192 // at the specified alpha once Restore() is called. 181 // at the specified alpha once Restore() is called.
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 size_t desired_characters_to_truncate_from_head, 371 size_t desired_characters_to_truncate_from_head,
383 const gfx::Font& font, 372 const gfx::Font& font,
384 SkColor color, 373 SkColor color,
385 const gfx::Rect& display_rect); 374 const gfx::Rect& display_rect);
386 375
387 skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); } 376 skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); }
388 SkCanvas* sk_canvas() const { return canvas_; } 377 SkCanvas* sk_canvas() const { return canvas_; }
389 ui::ScaleFactor scale_factor() const { return scale_factor_; } 378 ui::ScaleFactor scale_factor() const { return scale_factor_; }
390 379
391 private: 380 private:
381 Canvas(SkCanvas* canvas, ui::ScaleFactor scale_factor);
382
392 // Test whether the provided rectangle intersects the current clip rect. 383 // Test whether the provided rectangle intersects the current clip rect.
393 bool IntersectsClipRectInt(int x, int y, int w, int h); 384 bool IntersectsClipRectInt(int x, int y, int w, int h);
394 bool IntersectsClipRect(const gfx::Rect& rect); 385 bool IntersectsClipRect(const gfx::Rect& rect);
395 386
396 // Sets the canvas' scale factor to |scale_factor|. This affects
397 // the scale factor at which drawing bitmaps occurs and the scale factor of
398 // the image rep returned by Canvas::ExtractImageSkiaRep().
399 // If |scale_canvas| is true, scales the canvas by |scale_factor|.
400 void ApplyScaleFactor(ui::ScaleFactor scale_factor, bool scale_canvas);
401
402 // Returns the image rep which best matches the canvas |scale_factor_|. 387 // Returns the image rep which best matches the canvas |scale_factor_|.
403 // Returns a null image rep if |image| contains no image reps. 388 // Returns a null image rep if |image| contains no image reps.
404 // Builds mip map for returned image rep if necessary. 389 // Builds mip map for returned image rep if necessary.
405 // 390 //
406 // An optional additional user defined scale can be provided. 391 // An optional additional user defined scale can be provided.
407 const gfx::ImageSkiaRep& GetImageRepToPaint( 392 const gfx::ImageSkiaRep& GetImageRepToPaint(
408 const gfx::ImageSkia& image) const; 393 const gfx::ImageSkia& image) const;
409 const gfx::ImageSkiaRep& GetImageRepToPaint( 394 const gfx::ImageSkiaRep& GetImageRepToPaint(
410 const gfx::ImageSkia& image, 395 const gfx::ImageSkia& image,
411 float user_defined_scale_factor_x, 396 float user_defined_scale_factor_x,
412 float user_defined_scale_factor_y) const; 397 float user_defined_scale_factor_y) const;
413 398
414 scoped_ptr<skia::PlatformCanvas> owned_canvas_;
415 SkCanvas* canvas_;
416
417 // True if the scale factor scales the canvas and the inverse
418 // canvas scale should be applied when the destructor is called.
419 bool scale_factor_scales_canvas_;
420
421 // The device scale factor at which drawing on this canvas occurs. 399 // The device scale factor at which drawing on this canvas occurs.
422 // An additional scale can be applied via Canvas::Scale(). However, 400 // An additional scale can be applied via Canvas::Scale(). However,
423 // Canvas::Scale() does not affect |scale_factor_|. 401 // Canvas::Scale() does not affect |scale_factor_|.
424 ui::ScaleFactor scale_factor_; 402 ui::ScaleFactor scale_factor_;
425 403
404 scoped_ptr<skia::PlatformCanvas> owned_canvas_;
405 SkCanvas* canvas_;
406
426 DISALLOW_COPY_AND_ASSIGN(Canvas); 407 DISALLOW_COPY_AND_ASSIGN(Canvas);
427 }; 408 };
428 409
429 } // namespace gfx 410 } // namespace gfx
430 411
431 #endif // UI_GFX_CANVAS_H_ 412 #endif // UI_GFX_CANVAS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698