Remove ref to non-existent tracing_controller_impl_data_sinks.h
[chromium-blink-merge.git] / skia / ext / bitmap_platform_device_mac.h
blob566924bb8d1b81a1839c242aa7c8360be94ded4f
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.
5 #ifndef SKIA_EXT_BITMAP_PLATFORM_DEVICE_MAC_H_
6 #define SKIA_EXT_BITMAP_PLATFORM_DEVICE_MAC_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "skia/ext/platform_device.h"
11 #include "skia/ext/refptr.h"
13 namespace skia {
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
17 // write to. BitmapPlatformDevice creates a bitmap using
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
20 // device contains so that it can be shared.
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
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.
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
28 // DEVICE'S PIXEL DATA TO ANOTHER BITMAP, make sure you copy instead.
29 class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice {
30 public:
31 // Creates a BitmapPlatformDevice instance. |is_opaque| should be set if the
32 // caller knows the bitmap will be completely opaque and allows some
33 // optimizations.
34 // |context| may be NULL. If |context| is NULL, then the bitmap backing store
35 // is not initialized.
36 static BitmapPlatformDevice* Create(CGContextRef context,
37 int width, int height,
38 bool is_opaque, bool do_clear = false);
40 // Creates a context for |data| and calls Create.
41 // If |data| is NULL, then the bitmap backing store is not initialized.
42 static BitmapPlatformDevice* CreateWithData(uint8_t* data,
43 int width, int height,
44 bool is_opaque);
46 ~BitmapPlatformDevice() override;
48 // PlatformDevice overrides
49 CGContextRef GetBitmapContext() override;
51 // SkBaseDevice overrides
52 void setMatrixClip(const SkMatrix& transform,
53 const SkRegion& region,
54 const SkClipStack&) override;
56 protected:
57 BitmapPlatformDevice(CGContextRef context,
58 const SkBitmap& bitmap);
60 SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override;
62 private:
63 void ReleaseBitmapContext();
65 // Sets the transform and clip operations. This will not update the CGContext,
66 // but will mark the config as dirty. The next call of LoadConfig will
67 // pick up these changes.
68 void SetMatrixClip(const SkMatrix& transform, const SkRegion& region);
70 // Loads the current transform and clip into the context. Can be called even
71 // when |bitmap_context_| is NULL (will be a NOP).
72 void LoadConfig();
74 // Lazily-created graphics context used to draw into the bitmap.
75 CGContextRef bitmap_context_;
77 // True when there is a transform or clip that has not been set to the
78 // context. The context is retrieved for every text operation, and the
79 // transform and clip do not change as much. We can save time by not loading
80 // the clip and transform for every one.
81 bool config_dirty_;
83 // Translation assigned to the context: we need to keep track of this
84 // separately so it can be updated even if the context isn't created yet.
85 SkMatrix transform_;
87 // The current clipping
88 SkRegion clip_region_;
89 DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice);
92 } // namespace skia
94 #endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_MAC_H_