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