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 the same image at different densities, similar to NSImage. | |
| 19 // Smallest image is assumed to represent 1x density. | |
| 20 | |
| 21 // ImageSkia should be used for caching and drawing images of different | |
| 22 // densities. It should not be used as an SkBitmap wrapper. | |
| 23 class UI_EXPORT ImageSkia { | |
| 24 public: | |
| 25 explicit ImageSkia(const SkBitmap* bitmap); | |
| 26 explicit ImageSkia(const std::vector<const SkBitmap*>& bitmaps); | |
| 27 virtual ~ImageSkia(); | |
|
sky
2012/04/20 19:31:54
Do you really need this to be virtual?
| |
| 28 | |
| 29 // Build mipmap at time of next call to |DrawToCanvasInt|. | |
| 30 void BuildMipMap(); | |
| 31 | |
| 32 // Draws the image with the origin at the specified location. The upper left | |
| 33 // corner of the image is rendered at the specified location. | |
| 34 void DrawToCanvasInt(Canvas* canvas, int x, int y); | |
| 35 | |
| 36 // Draws the image with the origin at the specified location, using the | |
| 37 // specified paint. The upper left corner of the image is rendered at the | |
| 38 // specified location. | |
| 39 void DrawToCanvasInt(Canvas* canvas, | |
| 40 int x, int y, | |
| 41 const SkPaint& paint); | |
| 42 | |
| 43 // Draws a portion of the image in the specified location. The src parameters | |
| 44 // correspond to the region of the image to draw in the region defined | |
| 45 // by the dest coordinates. | |
| 46 // | |
| 47 // If the width or height of the source differs from that of the destination, | |
| 48 // the image will be scaled. When scaling down, it is highly recommended | |
| 49 // that you call BuildMipMap() on your image to ensure that it has | |
| 50 // a mipmap, which will result in much higher-quality output. Set |filter| to | |
| 51 // use filtering for bitmaps, otherwise the nearest-neighbor algorithm is used | |
| 52 // for resampling. | |
| 53 // | |
| 54 // An optional custom SkPaint can be provided. | |
| 55 void DrawToCanvasInt(Canvas* canvas, | |
| 56 int src_x, int src_y, int src_w, int src_h, | |
| 57 int dest_x, int dest_y, int dest_w, int dest_h, | |
| 58 bool filter); | |
| 59 void DrawToCanvasInt(Canvas* canvas, | |
| 60 int src_x, int src_y, int src_w, int src_h, | |
| 61 int dest_x, int dest_y, int dest_w, int dest_h, | |
| 62 bool filter, | |
| 63 const SkPaint& paint); | |
| 64 | |
| 65 // Returns true if the object contains no bitmaps. | |
| 66 bool IsEmpty() const; | |
|
sky
2012/04/20 19:31:54
Any reason you didn't inline this?
| |
| 67 | |
| 68 // Width and height of image in DIP coordinate system. | |
| 69 int width() const { return size_.width(); } | |
| 70 int height() const { return size_.height(); } | |
| 71 | |
| 72 // Returns a vector with the SkBitmaps contained in this object. | |
| 73 const std::vector<const SkBitmap*> bitmaps() const { return bitmaps_; } | |
|
sky
2012/04/20 19:31:54
const std::vector&
| |
| 74 | |
| 75 private: | |
|
sky
2012/04/20 19:31:54
nit: spacing
| |
| 76 // Returns the bitmap whose density best matches |x_scale_factor| and | |
| 77 // |y_scale_factor|. | |
| 78 const SkBitmap* GetBitmapForScale(float x_scale_factor, | |
| 79 float y_scale_factor) const; | |
| 80 | |
| 81 std::vector<const SkBitmap*> bitmaps_; | |
| 82 gfx::Size size_; | |
| 83 bool mip_map_build_pending_; | |
|
sky
2012/04/20 19:31:54
This is never initialized.
| |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(ImageSkia); | |
| 86 }; | |
| 87 | |
| 88 } // namespace gfx | |
| 89 | |
| 90 #endif // UI_GFX_IMAGE_IMAGE_SKIA_H_ | |
| OLD | NEW |