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

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

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

Powered by Google App Engine
This is Rietveld 408576698