Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef UI_GFX_IMAGE_IMAGE_SKIA_H_ | |
| 6 #define UI_GFX_IMAGE_IMAGE_SKIA_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | |
| 13 #include "ui/gfx/canvas.h" | |
| 14 #include "ui/gfx/size.h" | |
| 15 | |
| 16 namespace gfx { | |
| 17 | |
| 18 // Container for images at various densities. | |
|
Robert Sesek
2012/04/19 19:12:48
Didn't address the class comment. This needs to ta
| |
| 19 // Smallest image is assumed to represent 1x density. | |
| 20 class UI_EXPORT ImageSkia { | |
| 21 public: | |
| 22 explicit ImageSkia(const SkBitmap* bitmap); | |
| 23 ImageSkia(const std::vector<const SkBitmap*>& bitmaps); | |
|
Robert Sesek
2012/04/19 19:12:48
explicit?
| |
| 24 virtual ~ImageSkia(); | |
| 25 | |
| 26 // Build mipmap at time of next call to |DrawToCanvasInt|. | |
| 27 void BuildMipMap(); | |
| 28 | |
| 29 // Draws the image with the origin at the specified location. The upper left | |
| 30 // corner of the image is rendered at the specified location. | |
| 31 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
| |
| 32 | |
| 33 // Draws the image with the origin at the specified location, using the | |
| 34 // specified paint. The upper left corner of the image is rendered at the | |
| 35 // specified location. | |
| 36 void DrawToCanvasInt(Canvas* canvas, | |
| 37 int x, int y, | |
| 38 const SkPaint& paint); | |
| 39 | |
| 40 // Draws a portion of the image in the specified location. The src parameters | |
| 41 // correspond to the region of the image to draw in the region defined | |
| 42 // by the dest coordinates. | |
| 43 // | |
| 44 // If the width or height of the source differs from that of the destination, | |
| 45 // the image will be scaled. When scaling down, it is highly recommended | |
| 46 // that you call BuildMipMap() on your image to ensure that it has | |
| 47 // a mipmap, which will result in much higher-quality output. Set |filter| to | |
| 48 // use filtering for bitmaps, otherwise the nearest-neighbor algorithm is used | |
| 49 // for resampling. | |
| 50 // | |
| 51 // An optional custom SkPaint can be provided. | |
| 52 void DrawToCanvasInt(Canvas* canvas, | |
| 53 int src_x, int src_y, int src_w, int src_h, | |
|
Robert Sesek
2012/04/19 19:12:48
And gfx::Rect here?
| |
| 54 int dest_x, int dest_y, int dest_w, int dest_h, | |
| 55 bool filter); | |
| 56 void DrawToCanvasInt(Canvas* canvas, | |
| 57 int src_x, int src_y, int src_w, int src_h, | |
| 58 int dest_x, int dest_y, int dest_w, int dest_h, | |
| 59 bool filter, | |
| 60 const SkPaint& paint); | |
| 61 | |
| 62 // Gets the number of bitmaps in this image. | |
| 63 size_t GetNumberOfBitmaps() const; | |
| 64 | |
| 65 // Gets the bitmap at the given index. | |
| 66 const SkBitmap* GetBitmapAtIndex(size_t index) const; | |
| 67 | |
| 68 // Returns true if the object contains no bitmaps. | |
| 69 bool IsEmpty() const; | |
| 70 | |
| 71 // Width and height of image in DIP coordinate system. | |
| 72 int width() const { return size_.width(); } | |
| 73 int height() const { return size_.height(); } | |
| 74 | |
| 75 // Returns an SkBitmap which is contained by this object. | |
| 76 // TODO(pkotwicz): Remove this method once gfx::Image::ToSkBitmap() is | |
| 77 // removed. | |
| 78 const SkBitmap* bitmap() { return bitmaps_[0]; } | |
| 79 | |
| 80 private: | |
| 81 // Returns the bitmap whose density best matches |x_scale_factor| and | |
| 82 // |y_scale_factor|. | |
| 83 const SkBitmap* GetBitmapForScale(float x_scale_factor, | |
| 84 float y_scale_factor) const; | |
| 85 | |
| 86 std::vector<const SkBitmap*> bitmaps_; | |
| 87 gfx::Size size_; | |
| 88 bool mip_map_build_pending_; | |
| 89 | |
| 90 DISALLOW_COPY_AND_ASSIGN(ImageSkia); | |
| 91 }; | |
| 92 | |
| 93 } // namespace gfx | |
| 94 | |
| 95 #endif // UI_GFX_IMAGE_IMAGE_SKIA_H_ | |
| OLD | NEW |