Chromium Code Reviews| Index: ui/gfx/image/image_skia.h |
| diff --git a/ui/gfx/image/image_skia.h b/ui/gfx/image/image_skia.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..267dc73a3d77e686c5f84f406dc375b8b06777c8 |
| --- /dev/null |
| +++ b/ui/gfx/image/image_skia.h |
| @@ -0,0 +1,95 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef UI_GFX_IMAGE_IMAGE_SKIA_H_ |
| +#define UI_GFX_IMAGE_IMAGE_SKIA_H_ |
| +#pragma once |
| + |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "third_party/skia/include/core/SkBitmap.h" |
| +#include "ui/gfx/canvas.h" |
| +#include "ui/gfx/size.h" |
| + |
| +namespace gfx { |
| + |
| +// Container for images at various densities. |
|
Robert Sesek
2012/04/19 19:12:48
Didn't address the class comment. This needs to ta
|
| +// Smallest image is assumed to represent 1x density. |
| +class UI_EXPORT ImageSkia { |
| + public: |
| + explicit ImageSkia(const SkBitmap* bitmap); |
| + ImageSkia(const std::vector<const SkBitmap*>& bitmaps); |
|
Robert Sesek
2012/04/19 19:12:48
explicit?
|
| + virtual ~ImageSkia(); |
| + |
| + // Build mipmap at time of next call to |DrawToCanvasInt|. |
| + void BuildMipMap(); |
| + |
| + // Draws the image with the origin at the specified location. The upper left |
| + // corner of the image is rendered at the specified location. |
| + void DrawToCanvasInt(Canvas* canvas, int x, int y); |
|
Robert Sesek
2012/04/19 19:12:48
Would it make sense to use gfx::Point here?
pkotwicz
2012/04/19 21:21:26
Perhaps. However, the goal is to keep the API as s
|
| + |
| + // Draws the image with the origin at the specified location, using the |
| + // specified paint. The upper left corner of the image is rendered at the |
| + // specified location. |
| + void DrawToCanvasInt(Canvas* canvas, |
| + int x, int y, |
| + const SkPaint& paint); |
| + |
| + // Draws a portion of the image in the specified location. The src parameters |
| + // correspond to the region of the image 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 image will be scaled. When scaling down, it is highly recommended |
| + // that you call BuildMipMap() on your image 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. |
| + // |
| + // An optional custom SkPaint can be provided. |
| + void DrawToCanvasInt(Canvas* canvas, |
| + int src_x, int src_y, int src_w, int src_h, |
|
Robert Sesek
2012/04/19 19:12:48
And gfx::Rect here?
|
| + int dest_x, int dest_y, int dest_w, int dest_h, |
| + bool filter); |
| + void DrawToCanvasInt(Canvas* canvas, |
| + 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); |
| + |
| + // Gets the number of bitmaps in this image. |
| + size_t GetNumberOfBitmaps() const; |
| + |
| + // Gets the bitmap at the given index. |
| + const SkBitmap* GetBitmapAtIndex(size_t index) const; |
| + |
| + // Returns true if the object contains no bitmaps. |
| + bool IsEmpty() const; |
| + |
| + // Width and height of image in DIP coordinate system. |
| + int width() const { return size_.width(); } |
| + int height() const { return size_.height(); } |
| + |
| + // Returns an SkBitmap which is contained by this object. |
| + // TODO(pkotwicz): Remove this method once gfx::Image::ToSkBitmap() is |
| + // removed. |
| + const SkBitmap* bitmap() { return bitmaps_[0]; } |
| + |
| +private: |
| + // Returns the bitmap whose density best matches |x_scale_factor| and |
| + // |y_scale_factor|. |
| + const SkBitmap* GetBitmapForScale(float x_scale_factor, |
| + float y_scale_factor) const; |
| + |
| + std::vector<const SkBitmap*> bitmaps_; |
| + gfx::Size size_; |
| + bool mip_map_build_pending_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ImageSkia); |
| +}; |
| + |
| +} // namespace gfx |
| + |
| +#endif // UI_GFX_IMAGE_IMAGE_SKIA_H_ |