| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SKIA_EXT_BITMAP_PLATFORM_DEVICE_MAC_H_ | 5 #ifndef SKIA_EXT_BITMAP_PLATFORM_DEVICE_MAC_H_ |
| 6 #define SKIA_EXT_BITMAP_PLATFORM_DEVICE_MAC_H_ | 6 #define SKIA_EXT_BITMAP_PLATFORM_DEVICE_MAC_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "skia/ext/platform_device.h" | 10 #include "skia/ext/platform_device.h" |
| 11 #include "skia/ext/refptr.h" | 11 #include "skia/ext/refptr.h" |
| 12 | 12 |
| 13 namespace skia { | 13 namespace skia { |
| 14 | 14 |
| 15 // A device is basically a wrapper around SkBitmap that provides a surface for | 15 // A device is basically a wrapper around SkBitmap that provides a surface for |
| 16 // SkCanvas to draw into. Our device provides a surface CoreGraphics can also | 16 // SkCanvas to draw into. Our device provides a surface CoreGraphics can also |
| 17 // write to. BitmapPlatformDevice creates a bitmap using | 17 // write to. BitmapPlatformDevice creates a bitmap using |
| 18 // CGCreateBitmapContext() in a format that Skia supports and can then use this | 18 // CGCreateBitmapContext() in a format that Skia supports and can then use this |
| 19 // to draw text into, etc. This pixel data is provided to the bitmap that the | 19 // to draw text into, etc. This pixel data is provided to the bitmap that the |
| 20 // device contains so that it can be shared. | 20 // device contains so that it can be shared. |
| 21 // | 21 // |
| 22 // The device owns the pixel data, when the device goes away, the pixel data | 22 // The device owns the pixel data, when the device goes away, the pixel data |
| 23 // also becomes invalid. THIS IS DIFFERENT THAN NORMAL SKIA which uses | 23 // also becomes invalid. THIS IS DIFFERENT THAN NORMAL SKIA which uses |
| 24 // reference counting for the pixel data. In normal Skia, you could assign | 24 // reference counting for the pixel data. In normal Skia, you could assign |
| 25 // another bitmap to this device's bitmap and everything will work properly. | 25 // another bitmap to this device's bitmap and everything will work properly. |
| 26 // For us, that other bitmap will become invalid as soon as the device becomes | 26 // For us, that other bitmap will become invalid as soon as the device becomes |
| 27 // invalid, which may lead to subtle bugs. Therefore, DO NOT ASSIGN THE | 27 // invalid, which may lead to subtle bugs. Therefore, DO NOT ASSIGN THE |
| 28 // DEVICE'S PIXEL DATA TO ANOTHER BITMAP, make sure you copy instead. | 28 // DEVICE'S PIXEL DATA TO ANOTHER BITMAP, make sure you copy instead. |
| 29 class SK_API BitmapPlatformDevice : public SkDevice, public PlatformDevice { | 29 class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice
{ |
| 30 public: | 30 public: |
| 31 // Creates a BitmapPlatformDevice instance. |is_opaque| should be set if the | 31 // Creates a BitmapPlatformDevice instance. |is_opaque| should be set if the |
| 32 // caller knows the bitmap will be completely opaque and allows some | 32 // caller knows the bitmap will be completely opaque and allows some |
| 33 // optimizations. | 33 // optimizations. |
| 34 // |context| may be NULL. If |context| is NULL, then the bitmap backing store | 34 // |context| may be NULL. If |context| is NULL, then the bitmap backing store |
| 35 // is not initialized. | 35 // is not initialized. |
| 36 static BitmapPlatformDevice* Create(CGContextRef context, | 36 static BitmapPlatformDevice* Create(CGContextRef context, |
| 37 int width, int height, | 37 int width, int height, |
| 38 bool is_opaque); | 38 bool is_opaque); |
| 39 | 39 |
| 40 // Creates a BitmapPlatformDevice instance. If |is_opaque| is false, | 40 // Creates a BitmapPlatformDevice instance. If |is_opaque| is false, |
| 41 // then the bitmap is initialzed to 0. | 41 // then the bitmap is initialzed to 0. |
| 42 static BitmapPlatformDevice* CreateAndClear(int width, int height, | 42 static BitmapPlatformDevice* CreateAndClear(int width, int height, |
| 43 bool is_opaque); | 43 bool is_opaque); |
| 44 | 44 |
| 45 // Creates a context for |data| and calls Create. | 45 // Creates a context for |data| and calls Create. |
| 46 // If |data| is NULL, then the bitmap backing store is not initialized. | 46 // If |data| is NULL, then the bitmap backing store is not initialized. |
| 47 static BitmapPlatformDevice* CreateWithData(uint8_t* data, | 47 static BitmapPlatformDevice* CreateWithData(uint8_t* data, |
| 48 int width, int height, | 48 int width, int height, |
| 49 bool is_opaque); | 49 bool is_opaque); |
| 50 | 50 |
| 51 virtual ~BitmapPlatformDevice(); | 51 virtual ~BitmapPlatformDevice(); |
| 52 | 52 |
| 53 // PlatformDevice overrides | 53 // PlatformDevice overrides |
| 54 virtual CGContextRef GetBitmapContext() OVERRIDE; | 54 virtual CGContextRef GetBitmapContext() OVERRIDE; |
| 55 virtual void DrawToNativeContext(CGContextRef context, int x, int y, | 55 virtual void DrawToNativeContext(CGContextRef context, int x, int y, |
| 56 const CGRect* src_rect) OVERRIDE; | 56 const CGRect* src_rect) OVERRIDE; |
| 57 | 57 |
| 58 // SkDevice overrides | 58 // SkBaseDevice overrides |
| 59 virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, | 59 virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, |
| 60 const SkClipStack&) OVERRIDE; | 60 const SkClipStack&) OVERRIDE; |
| 61 | 61 |
| 62 protected: | 62 protected: |
| 63 // Reference counted data that can be shared between multiple devices. This | 63 // Reference counted data that can be shared between multiple devices. This |
| 64 // allows copy constructors and operator= for devices to work properly. The | 64 // allows copy constructors and operator= for devices to work properly. The |
| 65 // bitmaps used by the base device class are already refcounted and copyable. | 65 // bitmaps used by the base device class are already refcounted and copyable. |
| 66 class BitmapPlatformDeviceData; | 66 class BitmapPlatformDeviceData; |
| 67 | 67 |
| 68 BitmapPlatformDevice(const skia::RefPtr<BitmapPlatformDeviceData>& data, | 68 BitmapPlatformDevice(const skia::RefPtr<BitmapPlatformDeviceData>& data, |
| 69 const SkBitmap& bitmap); | 69 const SkBitmap& bitmap); |
| 70 | 70 |
| 71 // Flushes the CoreGraphics context so that the pixel data can be accessed | 71 // Flushes the CoreGraphics context so that the pixel data can be accessed |
| 72 // directly by Skia. Overridden from SkDevice, this is called when Skia | 72 // directly by Skia. Overridden from SkBaseDevice, this is called when Skia |
| 73 // starts accessing pixel data. | 73 // starts accessing pixel data. |
| 74 virtual const SkBitmap& onAccessBitmap(SkBitmap*) OVERRIDE; | 74 virtual const SkBitmap& onAccessBitmap(SkBitmap*) OVERRIDE; |
| 75 | 75 |
| 76 virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, | 76 virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, |
| 77 int height, bool isOpaque, | 77 int height, bool isOpaque, |
| 78 Usage usage) OVERRIDE; | 78 Usage usage) OVERRIDE; |
| 79 | 79 |
| 80 // Data associated with this device, guaranteed non-null. | 80 // Data associated with this device, guaranteed non-null. |
| 81 skia::RefPtr<BitmapPlatformDeviceData> data_; | 81 skia::RefPtr<BitmapPlatformDeviceData> data_; |
| 82 | 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); | 83 DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 } // namespace skia | 86 } // namespace skia |
| 87 | 87 |
| 88 #endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_MAC_H_ | 88 #endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_MAC_H_ |
| OLD | NEW |