OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 BASE_GFX_BITMAP_PLATFORM_DEVICE_MAC_H__ | 5 #ifndef BASE_GFX_BITMAP_PLATFORM_DEVICE_MAC_H__ |
6 #define BASE_GFX_BITMAP_PLATFORM_DEVICE_MAC_H__ | 6 #define BASE_GFX_BITMAP_PLATFORM_DEVICE_MAC_H__ |
7 | 7 |
8 #include "base/gfx/platform_device_mac.h" | 8 // TODO(brettw) this file should be removed and the includes changed to this |
9 #include "base/ref_counted.h" | 9 // new location. |
10 | 10 #include "webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceMac.h" |
11 namespace gfx { | |
12 | |
13 // A device is basically a wrapper around SkBitmap that provides a surface for | |
14 // SkCanvas to draw into. Our device provides a surface CoreGraphics can also | |
15 // write to. BitmapPlatformDeviceMac creates a bitmap using | |
16 // CGCreateBitmapContext() in a format that Skia supports and can then use this | |
17 // to draw text into, etc. This pixel data is provided to the bitmap that the | |
18 // device contains so that it can be shared. | |
19 // | |
20 // The device owns the pixel data, when the device goes away, the pixel data | |
21 // also becomes invalid. THIS IS DIFFERENT THAN NORMAL SKIA which uses | |
22 // reference counting for the pixel data. In normal Skia, you could assign | |
23 // another bitmap to this device's bitmap and everything will work properly. | |
24 // For us, that other bitmap will become invalid as soon as the device becomes | |
25 // invalid, which may lead to subtle bugs. Therefore, DO NOT ASSIGN THE | |
26 // DEVICE'S PIXEL DATA TO ANOTHER BITMAP, make sure you copy instead. | |
27 class BitmapPlatformDeviceMac : public PlatformDeviceMac { | |
28 public: | |
29 // Factory function. The screen DC is used to create the bitmap, and will not | |
30 // be stored beyond this function. is_opaque should be set if the caller | |
31 // knows the bitmap will be completely opaque and allows some optimizations. | |
32 // | |
33 // The shared_section parameter is optional (pass NULL for default behavior). | |
34 // If shared_section is non-null, then it must be a handle to a file-mapping | |
35 // object returned by CreateFileMapping. See CreateDIBSection for details. | |
36 static BitmapPlatformDeviceMac* Create(CGContextRef context, | |
37 int width, | |
38 int height, | |
39 bool is_opaque); | |
40 | |
41 // Copy constructor. When copied, devices duplicate their internal data, so | |
42 // stay linked. This is because their implementation is very heavyweight | |
43 // (lots of memory and CoreGraphics state). If a device has been copied, both | |
44 // clip rects and other state will stay in sync. | |
45 // | |
46 // This means it will NOT work to duplicate a device and assign it to a | |
47 // canvas, because the two canvases will each set their own clip rects, and | |
48 // the resulting CoreGraphics drawing state will be unpredictable. | |
49 // | |
50 // Copy constucting and "=" is designed for saving the device or passing it | |
51 // around to another routine willing to deal with the bitmap data directly. | |
52 BitmapPlatformDeviceMac(const BitmapPlatformDeviceMac& other); | |
53 virtual ~BitmapPlatformDeviceMac(); | |
54 | |
55 // See warning for copy constructor above. | |
56 BitmapPlatformDeviceMac& operator=(const BitmapPlatformDeviceMac& other); | |
57 | |
58 virtual CGContextRef GetBitmapContext(); | |
59 virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region); | |
60 | |
61 virtual void DrawToContext(CGContextRef context, int x, int y, | |
62 const CGRect* src_rect); | |
63 virtual bool IsVectorial() { return false; } | |
64 virtual void fixupAlphaBeforeCompositing() { }; | |
65 | |
66 // Returns the color value at the specified location. This does not | |
67 // consider any transforms that may be set on the device. | |
68 SkColor getColorAt(int x, int y); | |
69 | |
70 protected: | |
71 // Reference counted data that can be shared between multiple devices. This | |
72 // allows copy constructors and operator= for devices to work properly. The | |
73 // bitmaps used by the base device class are already refcounted and copyable. | |
74 class BitmapPlatformDeviceMacData; | |
75 | |
76 BitmapPlatformDeviceMac(BitmapPlatformDeviceMacData* data, | |
77 const SkBitmap& bitmap); | |
78 | |
79 // Flushes the CoreGraphics context so that the pixel data can be accessed | |
80 // directly by Skia. Overridden from SkDevice, this is called when Skia | |
81 // starts accessing pixel data. | |
82 virtual void onAccessBitmap(SkBitmap*); | |
83 | |
84 // Data associated with this device, guaranteed non-null. | |
85 scoped_refptr<BitmapPlatformDeviceMacData> data_; | |
86 | |
87 virtual void processPixels(int x, int y, | |
88 int width, int height, | |
89 adjustAlpha adjustor); | |
90 }; | |
91 | |
92 } // namespace gfx | |
93 | 11 |
94 #endif // BASE_GFX_BITMAP_PLATFORM_DEVICE_MAC_H__ | 12 #endif // BASE_GFX_BITMAP_PLATFORM_DEVICE_MAC_H__ |
95 | 13 |
OLD | NEW |