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

Side by Side Diff: skia/ext/bitmap_platform_device_win.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_mac.cc ('k') | skia/ext/bitmap_platform_device_win.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_BITMAP_PLATFORM_DEVICE_WIN_H_ 5 #ifndef SKIA_BITMAP_PLATFORM_DEVICE_WIN_H_
6 #define SKIA_BITMAP_PLATFORM_DEVICE_WIN_H_ 6 #define SKIA_BITMAP_PLATFORM_DEVICE_WIN_H_
7 7
8 #include "skia/ext/platform_device_win.h" 8 #include "skia/ext/platform_device_win.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 Windows can also write 13 // SkCanvas to draw into. Our device provides a surface Windows can also write
14 // to. BitmapPlatformDeviceWin creates a bitmap using CreateDIBSection() in a 14 // to. BitmapPlatformDevice creates a bitmap using CreateDIBSection() in a
15 // format that Skia supports and can then use this to draw ClearType into, etc. 15 // format that Skia supports and can then use this to draw ClearType into, etc.
16 // This pixel data is provided to the bitmap that the device contains so that it 16 // This pixel data is provided to the bitmap that the device contains so that it
17 // can be shared. 17 // 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 BitmapPlatformDeviceWin : public PlatformDeviceWin { 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 BitmapPlatformDeviceWin* create(HDC screen_dc, 35 static BitmapPlatformDevice* create(HDC screen_dc,
36 int width, 36 int width,
37 int height, 37 int height,
38 bool is_opaque, 38 bool is_opaque,
39 HANDLE shared_section); 39 HANDLE shared_section);
40
41 // This version is the same as above but will get the screen DC itself.
42 static BitmapPlatformDevice* create(int width,
43 int height,
44 bool is_opaque,
45 HANDLE shared_section);
40 46
41 // Copy constructor. When copied, devices duplicate their internal data, so 47 // Copy constructor. When copied, devices duplicate their internal data, so
42 // stay linked. This is because their implementation is very heavyweight 48 // stay linked. This is because their implementation is very heavyweight
43 // (lots of memory and some GDI objects). If a device has been copied, both 49 // (lots of memory and some GDI objects). If a device has been copied, both
44 // clip rects and other state will stay in sync. 50 // clip rects and other state will stay in sync.
45 // 51 //
46 // This means it will NOT work to duplicate a device and assign it to a 52 // 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 53 // canvas, because the two canvases will each set their own clip rects, and
48 // the resulting GDI clip rect will be random. 54 // the resulting GDI clip rect will be random.
49 // 55 //
50 // Copy constucting and "=" is designed for saving the device or passing it 56 // 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. 57 // around to another routine willing to deal with the bitmap data directly.
52 BitmapPlatformDeviceWin(const BitmapPlatformDeviceWin& other); 58 BitmapPlatformDevice(const BitmapPlatformDevice& other);
53 virtual ~BitmapPlatformDeviceWin(); 59 virtual ~BitmapPlatformDevice();
54 60
55 // See warning for copy constructor above. 61 // See warning for copy constructor above.
56 BitmapPlatformDeviceWin& operator=(const BitmapPlatformDeviceWin& other); 62 BitmapPlatformDevice& operator=(const BitmapPlatformDevice& other);
57 63
58 // Retrieves the bitmap DC, which is the memory DC for our bitmap data. The 64 // Retrieves the bitmap DC, which is the memory DC for our bitmap data. The
59 // bitmap DC is lazy created. 65 // bitmap DC is lazy created.
60 virtual HDC getBitmapDC(); 66 virtual HDC getBitmapDC();
61 virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region); 67 virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region);
62 68
63 virtual void drawToHDC(HDC dc, int x, int y, const RECT* src_rect); 69 virtual void drawToHDC(HDC dc, int x, int y, const RECT* src_rect);
64 virtual void makeOpaque(int x, int y, int width, int height); 70 virtual void makeOpaque(int x, int y, int width, int height);
65 virtual bool IsVectorial() { return false; } 71 virtual bool IsVectorial() { return false; }
66 72
67 // Returns the color value at the specified location. This does not 73 // Returns the color value at the specified location. This does not
68 // consider any transforms that may be set on the device. 74 // consider any transforms that may be set on the device.
69 SkColor getColorAt(int x, int y); 75 SkColor getColorAt(int x, int y);
70 76
71 protected: 77 protected:
72 // Flushes the Windows device context so that the pixel data can be accessed 78 // Flushes the Windows device context so that the pixel data can be accessed
73 // directly by Skia. Overridden from SkDevice, this is called when Skia 79 // directly by Skia. Overridden from SkDevice, this is called when Skia
74 // starts accessing pixel data. 80 // starts accessing pixel data.
75 virtual void onAccessBitmap(SkBitmap* bitmap); 81 virtual void onAccessBitmap(SkBitmap* bitmap);
76 82
77 private: 83 private:
78 // Reference counted data that can be shared between multiple devices. This 84 // Reference counted data that can be shared between multiple devices. This
79 // allows copy constructors and operator= for devices to work properly. The 85 // allows copy constructors and operator= for devices to work properly. The
80 // bitmaps used by the base device class are already refcounted and copyable. 86 // bitmaps used by the base device class are already refcounted and copyable.
81 class BitmapPlatformDeviceWinData; 87 class BitmapPlatformDeviceData;
82 88
83 // Private constructor. The data should already be ref'ed for us. 89 // Private constructor. The data should already be ref'ed for us.
84 BitmapPlatformDeviceWin(BitmapPlatformDeviceWinData* data, 90 BitmapPlatformDevice(BitmapPlatformDeviceData* data,
85 const SkBitmap& bitmap); 91 const SkBitmap& bitmap);
86 92
87 // Data associated with this device, guaranteed non-null. We hold a reference 93 // Data associated with this device, guaranteed non-null. We hold a reference
88 // to this object. 94 // to this object.
89 BitmapPlatformDeviceWinData* data_; 95 BitmapPlatformDeviceData* data_;
90 }; 96 };
91 97
92 } // namespace skia 98 } // namespace skia
93 99
94 #endif // SKIA_BITMAP_PLATFORM_DEVICE_WIN_H_ 100 #endif // SKIA_BITMAP_PLATFORM_DEVICE_WIN_H_
95 101
OLDNEW
« no previous file with comments | « skia/ext/bitmap_platform_device_mac.cc ('k') | skia/ext/bitmap_platform_device_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698