1 // Copyright 2018 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_REP_IOS_H_
6 #define UI_GFX_IMAGE_IMAGE_SKIA_REP_IOS_H_
7 
8 #include "build/build_config.h"
9 #include "third_party/skia/include/core/SkBitmap.h"
10 #include "ui/gfx/geometry/size.h"
11 #include "ui/gfx/gfx_export.h"
12 
13 namespace gfx {
14 
15 // An ImageSkiaRep represents an image and the scale factor it is intended for.
16 // 0.0f scale is used to indicate that this ImageSkiaRep is used for unscaled
17 // image (ImageSkia does not automatically scale the image).
18 // iOS does not support cc's PaintOpBuffer and instead uses cocoa frameworks
19 // image formats.
20 class GFX_EXPORT ImageSkiaRep {
21  public:
22   // Create null bitmap.
23   ImageSkiaRep();
24 
25   // Note: This is for testing purpose only.
26   // Creates a bitmap with kARGB_8888_Config config with given |size| in DIP.
27   // This allocates pixels in the bitmap. It is guaranteed that the data in the
28   // bitmap are initialized but the actual values are undefined.
29   // Specifying 0 scale means the image is for unscaled image. (unscaled()
30   // returns truen, and scale() returns 1.0f;)
31   ImageSkiaRep(const gfx::Size& size, float scale);
32 
33   // Creates a bitmap with given scale.
34   // Adds ref to |src|.
35   ImageSkiaRep(const SkBitmap& src, float scale);
36   ImageSkiaRep(const ImageSkiaRep& other);
37 
38   ~ImageSkiaRep();
39 
40   // Get width and height of the image in pixels.
pixel_width()41   int pixel_width() const { return bitmap_.width(); }
pixel_height()42   int pixel_height() const { return bitmap_.height(); }
pixel_size()43   Size pixel_size() const { return gfx::Size(pixel_width(), pixel_height()); }
44 
45   // Get width and height of the image in DIP.
46   int GetWidth() const;
47   int GetHeight() const;
48 
49   // Retrieves the scale for which this image is a representation of.
scale()50   float scale() const { return unscaled() ? 1.0f : scale_; }
unscaled()51   bool unscaled() const { return scale_ == 0.0f; }
52 
is_null()53   bool is_null() const { return bitmap_.isNull(); }
54 
55   // Returns the backing bitmap when the image representation is sourced from a
56   // bitmap.
57   const SkBitmap& GetBitmap() const;
58 
59  private:
60   Size pixel_size_;
61   SkBitmap bitmap_;
62   float scale_;
63 };
64 
65 }  // namespace gfx
66 
67 #endif  // UI_GFX_IMAGE_IMAGE_SKIA_REP_IOS_H_
68