ASPiK SDK
cgbitmap.h
1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #ifndef __cgbitmap__
6 #define __cgbitmap__
7 
8 #include "../iplatformbitmap.h"
9 
10 #if MAC
11 #include "../../cpoint.h"
12 
13 #if TARGET_OS_IPHONE
14  #include <CoreGraphics/CoreGraphics.h>
15  #include <ImageIO/ImageIO.h>
16 #else
17  #include <ApplicationServices/ApplicationServices.h>
18 #endif
19 
20 namespace VSTGUI {
21 
22 //-----------------------------------------------------------------------------
23 class CGBitmap : public IPlatformBitmap
24 {
25 public:
26  explicit CGBitmap (const CPoint& size);
27  explicit CGBitmap (CGImageRef image);
28  CGBitmap ();
29  ~CGBitmap () noexcept override;
30 
31  bool load (const CResourceDescription& desc) override;
32  const CPoint& getSize () const override { return size; }
33  SharedPointer<IPlatformBitmapPixelAccess> lockPixels (bool alphaPremultiplied) override;
34  void setScaleFactor (double factor) override { scaleFactor = factor; }
35  double getScaleFactor () const override { return scaleFactor; }
36 
37  CGImageRef getCGImage ();
38  CGContextRef createCGContext ();
39  bool loadFromImageSource (CGImageSourceRef source);
40 
41  void setDirty () { dirty = true; }
42  void* getBits () const { return bits; }
43  uint32_t getBytesPerRow () const { return bytesPerRow; }
44 
45  CGLayerRef createCGLayer (CGContextRef context);
46  CGLayerRef getCGLayer () const { return layer; }
47 //-----------------------------------------------------------------------------
48 protected:
49  void allocBits ();
50  void freeCGImage ();
51 
52  CPoint size;
53  CGImageRef image;
54  CGImageSourceRef imageSource;
55 
56  CGLayerRef layer;
57 
58  void* bits;
59  bool dirty;
60  uint32_t bytesPerRow;
61  double scaleFactor;
62 };
63 
64 } // namespace
65 
66 #endif // MAC
67 #endif // __cgbitmap__
Definition: customcontrols.cpp:8