Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: skia/ext/bitmap_platform_device_mac.h

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

Powered by Google App Engine
This is Rietveld 408576698