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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 76 |
77 // Creates canvas with provided DIP |size| and |image_scale|. | 77 // Creates canvas with provided DIP |size| and |image_scale|. |
78 // If this canvas is not opaque, it's explicitly cleared to transparent before | 78 // If this canvas is not opaque, it's explicitly cleared to transparent before |
79 // being returned. | 79 // being returned. |
80 Canvas(const Size& size, float image_scale, bool is_opaque); | 80 Canvas(const Size& size, float image_scale, bool is_opaque); |
81 | 81 |
82 // Constructs a canvas with the size and the image_scale of the provided | 82 // Constructs a canvas with the size and the image_scale of the provided |
83 // |image_rep|, and draws the |image_rep| into it. | 83 // |image_rep|, and draws the |image_rep| into it. |
84 Canvas(const ImageSkiaRep& image_rep, bool is_opaque); | 84 Canvas(const ImageSkiaRep& image_rep, bool is_opaque); |
85 | 85 |
86 virtual ~Canvas(); | |
87 | |
88 // Creates a Canvas backed by an |sk_canvas| with |image_scale_|. | 86 // Creates a Canvas backed by an |sk_canvas| with |image_scale_|. |
89 // |sk_canvas| is assumed to be already scaled based on |image_scale| | 87 // |sk_canvas| is assumed to be already scaled based on |image_scale| |
90 // so no additional scaling is applied. | 88 // so no additional scaling is applied. |
91 static Canvas* CreateCanvasWithoutScaling(SkCanvas* sk_canvas, | 89 Canvas(SkCanvas* sk_canvas, float image_scale); |
92 float image_scale); | 90 |
| 91 virtual ~Canvas(); |
93 | 92 |
94 // Recreates the backing platform canvas with DIP |size| and |image_scale_|. | 93 // Recreates the backing platform canvas with DIP |size| and |image_scale_|. |
95 // If the canvas is not opaque, it is explicitly cleared. | 94 // If the canvas is not opaque, it is explicitly cleared. |
96 // This method is public so that canvas_skia_paint can recreate the platform | 95 // This method is public so that canvas_skia_paint can recreate the platform |
97 // canvas after having initialized the canvas. | 96 // canvas after having initialized the canvas. |
98 // TODO(pkotwicz): Push the image_scale into skia::PlatformCanvas such that | 97 // TODO(pkotwicz): Push the image_scale into skia::PlatformCanvas such that |
99 // this method can be private. | 98 // this method can be private. |
100 void RecreateBackingCanvas(const Size& size, | 99 void RecreateBackingCanvas(const Size& size, |
101 float image_scale, | 100 float image_scale, |
102 bool is_opaque); | 101 bool is_opaque); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 const FontList& font_list, | 405 const FontList& font_list, |
407 SkColor color, | 406 SkColor color, |
408 const Rect& display_rect, | 407 const Rect& display_rect, |
409 int flags); | 408 int flags); |
410 | 409 |
411 skia::PlatformCanvas* platform_canvas() { return owned_canvas_.get(); } | 410 skia::PlatformCanvas* platform_canvas() { return owned_canvas_.get(); } |
412 SkCanvas* sk_canvas() { return canvas_; } | 411 SkCanvas* sk_canvas() { return canvas_; } |
413 float image_scale() const { return image_scale_; } | 412 float image_scale() const { return image_scale_; } |
414 | 413 |
415 private: | 414 private: |
416 Canvas(SkCanvas* canvas, float image_scale); | |
417 | |
418 // Test whether the provided rectangle intersects the current clip rect. | 415 // Test whether the provided rectangle intersects the current clip rect. |
419 bool IntersectsClipRectInt(int x, int y, int w, int h); | 416 bool IntersectsClipRectInt(int x, int y, int w, int h); |
420 bool IntersectsClipRect(const Rect& rect); | 417 bool IntersectsClipRect(const Rect& rect); |
421 | 418 |
422 // Helper for the DrawImageInt functions declared above. The |pixel| | 419 // Helper for the DrawImageInt functions declared above. The |pixel| |
423 // parameter if true indicates that the bounds and the image are to | 420 // parameter if true indicates that the bounds and the image are to |
424 // be assumed to be in pixels, i.e. no scaling needs to be performed. | 421 // be assumed to be in pixels, i.e. no scaling needs to be performed. |
425 void DrawImageIntHelper(const ImageSkia& image, | 422 void DrawImageIntHelper(const ImageSkia& image, |
426 int src_x, | 423 int src_x, |
427 int src_y, | 424 int src_y, |
(...skipping 15 matching lines...) Expand all Loading... |
443 | 440 |
444 skia::RefPtr<skia::PlatformCanvas> owned_canvas_; | 441 skia::RefPtr<skia::PlatformCanvas> owned_canvas_; |
445 SkCanvas* canvas_; | 442 SkCanvas* canvas_; |
446 | 443 |
447 DISALLOW_COPY_AND_ASSIGN(Canvas); | 444 DISALLOW_COPY_AND_ASSIGN(Canvas); |
448 }; | 445 }; |
449 | 446 |
450 } // namespace gfx | 447 } // namespace gfx |
451 | 448 |
452 #endif // UI_GFX_CANVAS_H_ | 449 #endif // UI_GFX_CANVAS_H_ |
OLD | NEW |