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 SKIA_EXT_BITMAP_PLATFORM_DEVICE_MAC_H_ |
| 6 #define SKIA_EXT_BITMAP_PLATFORM_DEVICE_MAC_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" |
| 12 #include "skia/ext/platform_device.h" |
| 13 |
| 14 namespace skia { |
| 15 |
| 16 // A device is basically a wrapper around SkBitmap that provides a surface for |
| 17 // SkCanvas to draw into. Our device provides a surface CoreGraphics can also |
| 18 // write to. BitmapPlatformDevice creates a bitmap using |
| 19 // CGCreateBitmapContext() in a format that Skia supports and can then use this |
| 20 // to draw text into, etc. This pixel data is provided to the bitmap that the |
| 21 // device contains so that it can be shared. |
| 22 // |
| 23 // The device owns the pixel data, when the device goes away, the pixel data |
| 24 // also becomes invalid. THIS IS DIFFERENT THAN NORMAL SKIA which uses |
| 25 // reference counting for the pixel data. In normal Skia, you could assign |
| 26 // another bitmap to this device's bitmap and everything will work properly. |
| 27 // For us, that other bitmap will become invalid as soon as the device becomes |
| 28 // invalid, which may lead to subtle bugs. Therefore, DO NOT ASSIGN THE |
| 29 // DEVICE'S PIXEL DATA TO ANOTHER BITMAP, make sure you copy instead. |
| 30 class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice
{ |
| 31 public: |
| 32 // Creates a BitmapPlatformDevice instance. |is_opaque| should be set if the |
| 33 // caller knows the bitmap will be completely opaque and allows some |
| 34 // optimizations. |
| 35 // |context| may be NULL. If |context| is NULL, then the bitmap backing store |
| 36 // is not initialized. |
| 37 static BitmapPlatformDevice* Create(CGContextRef context, |
| 38 int width, int height, |
| 39 bool is_opaque, bool do_clear = false); |
| 40 |
| 41 // Creates a context for |data| and calls Create. |
| 42 // If |data| is NULL, then the bitmap backing store is not initialized. |
| 43 static BitmapPlatformDevice* CreateWithData(uint8_t* data, |
| 44 int width, int height, |
| 45 bool is_opaque); |
| 46 |
| 47 ~BitmapPlatformDevice() override; |
| 48 |
| 49 protected: |
| 50 BitmapPlatformDevice(CGContextRef context, |
| 51 const SkBitmap& bitmap); |
| 52 |
| 53 SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; |
| 54 |
| 55 private: |
| 56 NativeDrawingContext BeginPlatformPaint(const SkMatrix& transform, |
| 57 const SkIRect& clip_bounds) override; |
| 58 |
| 59 void ReleaseBitmapContext(); |
| 60 |
| 61 // Loads the current transform and clip into the context. Can be called even |
| 62 // when |bitmap_context_| is NULL (will be a NOP). |
| 63 void LoadConfig(const SkMatrix& transform, const SkIRect& clip_bounds); |
| 64 |
| 65 // Lazily-created graphics context used to draw into the bitmap. |
| 66 CGContextRef bitmap_context_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); |
| 69 }; |
| 70 |
| 71 } // namespace skia |
| 72 |
| 73 #endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_MAC_H_ |
OLD | NEW |