summaryrefslogtreecommitdiffstats
path: root/ui/gfx/canvas.h
diff options
context:
space:
mode:
authorpkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-16 21:30:12 +0000
committerpkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-16 21:30:12 +0000
commit35d53343ae436c2190670b0686fdbbba240d7155 (patch)
tree7dc826260d6a6ab4080042575c4ba473a4307085 /ui/gfx/canvas.h
parent3d841611c4344e1026491602d21d024957cda690 (diff)
downloadchromium_src-35d53343ae436c2190670b0686fdbbba240d7155.zip
chromium_src-35d53343ae436c2190670b0686fdbbba240d7155.tar.gz
chromium_src-35d53343ae436c2190670b0686fdbbba240d7155.tar.bz2
This patch makes ImageSkia more like SkBitmap. The goal is to make swapping from SkBitmap to ImageSkia easier.
Notable changes: - ImageSkia can be cheaply copied - Added extractSubset, will remove after SkBitmaps have been converted to ImageSkia - Modified API to look more like SkBitmap Review URL: https://chromiumcodereview.appspot.com/10245003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137520 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/canvas.h')
-rw-r--r--ui/gfx/canvas.h56
1 files changed, 34 insertions, 22 deletions
diff --git a/ui/gfx/canvas.h b/ui/gfx/canvas.h
index 7653f39..69f402b 100644
--- a/ui/gfx/canvas.h
+++ b/ui/gfx/canvas.h
@@ -12,6 +12,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
#include "skia/ext/platform_canvas.h"
+#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/native_widget_types.h"
class SkBitmap;
@@ -240,47 +241,43 @@ class UI_EXPORT Canvas {
// Draws the given path using the given |paint| parameters.
void DrawPath(const SkPath& path, const SkPaint& paint);
- // Draws a bitmap with the origin at the specified location. The upper left
+ // Draws an image with the origin at the specified location. The upper left
// corner of the bitmap is rendered at the specified location.
- void DrawBitmapInt(const SkBitmap& bitmap, int x, int y);
+ // Parameters are specified relative to current canvas scale not in pixels.
+ // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
+ void DrawBitmapInt(const gfx::ImageSkia&, int x, int y);
- // Draws a bitmap with the origin at the specified location, using the
+ // Draws an image with the origin at the specified location, using the
// specified paint. The upper left corner of the bitmap is rendered at the
// specified location.
- void DrawBitmapInt(const SkBitmap& bitmap,
+ // Parameters are specified relative to current canvas scale not in pixels.
+ // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
+ void DrawBitmapInt(const gfx::ImageSkia& image,
int x, int y,
const SkPaint& paint);
- // Draws a portion of a bitmap in the specified location. The src parameters
+ // Draws a portion of an image in the specified location. The src parameters
// correspond to the region of the bitmap to draw in the region defined
// by the dest coordinates.
//
// If the width or height of the source differs from that of the destination,
- // the bitmap will be scaled. When scaling down, it is highly recommended
- // that you call buildMipMap(false) on your bitmap to ensure that it has
- // a mipmap, which will result in much higher-quality output. Set |filter|
- // to use filtering for bitmaps, otherwise the nearest-neighbor algorithm
- // is used for resampling.
+ // the image will be scaled. When scaling down, a mipmap will be generated.
+ // Set |filter| to use filtering for images, otherwise the nearest-neighbor
+ // algorithm is used for resampling.
//
// An optional custom SkPaint can be provided.
- void DrawBitmapInt(const SkBitmap& bitmap,
+ // Parameters are specified relative to current canvas scale not in pixels.
+ // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
+ void DrawBitmapInt(const gfx::ImageSkia& image,
int src_x, int src_y, int src_w, int src_h,
int dest_x, int dest_y, int dest_w, int dest_h,
bool filter);
- void DrawBitmapInt(const SkBitmap& bitmap,
+ void DrawBitmapInt(const gfx::ImageSkia& image,
int src_x, int src_y, int src_w, int src_h,
int dest_x, int dest_y, int dest_w, int dest_h,
bool filter,
const SkPaint& paint);
- // TODO(pkotwicz): make this function private once gfx::ImageSkia stops
- // calling this method.
- void DrawBitmapFloat(const SkBitmap& bitmap,
- float src_x, float src_y, float src_w, float src_h,
- float dest_x, float dest_y, float dest_w, float dest_h,
- bool filter,
- const SkPaint& paint);
-
// Draws text with the specified color, font and location. The text is
// aligned to the left, vertically centered, clipped to the region. If the
// text is too big, it is truncated and '...' is added to the end.
@@ -315,9 +312,11 @@ class UI_EXPORT Canvas {
void DrawFocusRect(const gfx::Rect& rect);
// Tiles the image in the specified region.
- void TileImageInt(const SkBitmap& bitmap,
+ // Parameters are specified relative to current canvas scale not in pixels.
+ // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
+ void TileImageInt(const gfx::ImageSkia& image,
int x, int y, int w, int h);
- void TileImageInt(const SkBitmap& bitmap,
+ void TileImageInt(const gfx::ImageSkia& image,
int src_x, int src_y,
int dest_x, int dest_y, int w, int h);
@@ -354,6 +353,19 @@ class UI_EXPORT Canvas {
bool IntersectsClipRectInt(int x, int y, int w, int h);
bool IntersectsClipRect(const gfx::Rect& rect);
+ // Returns the bitmap whose density best matches the current canvas scale.
+ // Returns a null bitmap if |image| contains no bitmaps.
+ // |bitmap_scale_factor| is set to the scale factor of the returned bitmap.
+ // Builds mip map for returned bitmap if necessary.
+ //
+ // An optional additional user defined scale can be provided.
+ const SkBitmap& GetBitmapToPaint(const gfx::ImageSkia& image,
+ float* bitmap_scale_factor) const;
+ const SkBitmap& GetBitmapToPaint(const gfx::ImageSkia& image,
+ float user_defined_scale_factor_x,
+ float user_defined_scale_factor_y,
+ float* bitmap_scale_factor) const;
+
#if defined(OS_WIN)
// Draws text with the specified color, font and location. The text is
// aligned to the left, vertically centered, clipped to the region. If the