OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_WIN_H_ | 5 #ifndef SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_ |
6 #define SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_ | 6 #define SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "skia/ext/platform_device_win.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "skia/ext/platform_device.h" |
11 | 12 |
12 namespace skia { | 13 namespace skia { |
13 | 14 |
14 // A device is basically a wrapper around SkBitmap that provides a surface for | 15 // A device is basically a wrapper around SkBitmap that provides a surface for |
15 // SkCanvas to draw into. Our device provides a surface Windows can also write | 16 // SkCanvas to draw into. Our device provides a surface Windows can also write |
16 // to. BitmapPlatformDevice creates a bitmap using CreateDIBSection() in a | 17 // to. BitmapPlatformDevice creates a bitmap using CreateDIBSection() in a |
17 // format that Skia supports and can then use this to draw ClearType into, etc. | 18 // format that Skia supports and can then use this to draw ClearType into, etc. |
18 // This pixel data is provided to the bitmap that the device contains so that it | 19 // This pixel data is provided to the bitmap that the device contains so that it |
19 // can be shared. | 20 // can be shared. |
20 // | 21 // |
21 // The device owns the pixel data, when the device goes away, the pixel data | 22 // The device owns the pixel data, when the device goes away, the pixel data |
22 // also becomes invalid. THIS IS DIFFERENT THAN NORMAL SKIA which uses | 23 // also becomes invalid. THIS IS DIFFERENT THAN NORMAL SKIA which uses |
23 // reference counting for the pixel data. In normal Skia, you could assign | 24 // reference counting for the pixel data. In normal Skia, you could assign |
24 // another bitmap to this device's bitmap and everything will work properly. | 25 // another bitmap to this device's bitmap and everything will work properly. |
25 // For us, that other bitmap will become invalid as soon as the device becomes | 26 // For us, that other bitmap will become invalid as soon as the device becomes |
26 // invalid, which may lead to subtle bugs. Therefore, DO NOT ASSIGN THE | 27 // invalid, which may lead to subtle bugs. Therefore, DO NOT ASSIGN THE |
27 // DEVICE'S PIXEL DATA TO ANOTHER BITMAP, make sure you copy instead. | 28 // DEVICE'S PIXEL DATA TO ANOTHER BITMAP, make sure you copy instead. |
28 class SK_API BitmapPlatformDevice : public PlatformDevice { | 29 class SK_API BitmapPlatformDevice : public PlatformDevice, public SkDevice { |
29 public: | 30 public: |
30 // Factory function. The screen DC is used to create the bitmap, and will not | 31 // Factory function. The screen DC is used to create the bitmap, and will not |
31 // be stored beyond this function. is_opaque should be set if the caller | 32 // be stored beyond this function. is_opaque should be set if the caller |
32 // knows the bitmap will be completely opaque and allows some optimizations. | 33 // knows the bitmap will be completely opaque and allows some optimizations. |
33 // | 34 // |
34 // The shared_section parameter is optional (pass NULL for default behavior). | 35 // The shared_section parameter is optional (pass NULL for default behavior). |
35 // If shared_section is non-null, then it must be a handle to a file-mapping | 36 // If shared_section is non-null, then it must be a handle to a file-mapping |
36 // object returned by CreateFileMapping. See CreateDIBSection for details. | 37 // object returned by CreateFileMapping. See CreateDIBSection for details. |
37 static BitmapPlatformDevice* create(HDC screen_dc, | 38 static BitmapPlatformDevice* create(HDC screen_dc, int width, int height, |
38 int width, | 39 bool is_opaque, HANDLE shared_section); |
39 int height, | |
40 bool is_opaque, | |
41 HANDLE shared_section); | |
42 | 40 |
43 // This version is the same as above but will get the screen DC itself. | 41 // This version is the same as above but will get the screen DC itself. |
44 static BitmapPlatformDevice* create(int width, | 42 static BitmapPlatformDevice* create(int width, int height, bool is_opaque, |
45 int height, | |
46 bool is_opaque, | |
47 HANDLE shared_section); | 43 HANDLE shared_section); |
48 | 44 |
49 virtual ~BitmapPlatformDevice(); | 45 virtual ~BitmapPlatformDevice(); |
50 | 46 |
51 // PlatformDevice overrides | 47 // PlatformDevice overrides |
52 // Retrieves the bitmap DC, which is the memory DC for our bitmap data. The | 48 // Retrieves the bitmap DC, which is the memory DC for our bitmap data. The |
53 // bitmap DC is lazy created. | 49 // bitmap DC is lazy created. |
54 virtual PlatformSurface BeginPlatformPaint(); | 50 virtual PlatformSurface BeginPlatformPaint() OVERRIDE; |
55 virtual void EndPlatformPaint(); | 51 virtual void EndPlatformPaint() OVERRIDE; |
56 | 52 |
57 virtual void DrawToNativeContext(HDC dc, int x, int y, const RECT* src_rect); | 53 virtual void DrawToNativeContext(HDC dc, int x, int y, |
58 virtual void MakeOpaque(int x, int y, int width, int height); | 54 const RECT* src_rect) OVERRIDE; |
| 55 virtual void MakeOpaque(int x, int y, int width, int height) OVERRIDE; |
59 | 56 |
60 // Loads the given transform and clipping region into the HDC. This is | 57 // Loads the given transform and clipping region into the HDC. This is |
61 // overridden from SkDevice. | 58 // overridden from SkDevice. |
62 virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, | 59 virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, |
63 const SkClipStack&); | 60 const SkClipStack&) OVERRIDE; |
64 | 61 |
65 protected: | 62 protected: |
66 // Flushes the Windows device context so that the pixel data can be accessed | 63 // Flushes the Windows device context so that the pixel data can be accessed |
67 // directly by Skia. Overridden from SkDevice, this is called when Skia | 64 // directly by Skia. Overridden from SkDevice, this is called when Skia |
68 // starts accessing pixel data. | 65 // starts accessing pixel data. |
69 virtual void onAccessBitmap(SkBitmap* bitmap); | 66 virtual void onAccessBitmap(SkBitmap* bitmap) OVERRIDE; |
70 | 67 |
71 virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, | 68 virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, |
72 int height, bool isOpaque, | 69 int height, bool isOpaque, |
73 Usage usage); | 70 Usage usage) OVERRIDE; |
74 | 71 |
75 private: | 72 private: |
76 // Reference counted data that can be shared between multiple devices. This | 73 // Reference counted data that can be shared between multiple devices. This |
77 // allows copy constructors and operator= for devices to work properly. The | 74 // allows copy constructors and operator= for devices to work properly. The |
78 // bitmaps used by the base device class are already refcounted and copyable. | 75 // bitmaps used by the base device class are already refcounted and copyable. |
79 class BitmapPlatformDeviceData; | 76 class BitmapPlatformDeviceData; |
80 | 77 |
81 // Private constructor. The data should already be ref'ed for us. | 78 // Private constructor. The data should already be ref'ed for us. |
82 BitmapPlatformDevice(BitmapPlatformDeviceData* data, | 79 BitmapPlatformDevice(BitmapPlatformDeviceData* data, |
83 const SkBitmap& bitmap); | 80 const SkBitmap& bitmap); |
84 | 81 |
85 // Data associated with this device, guaranteed non-null. We hold a reference | 82 // Data associated with this device, guaranteed non-null. We hold a reference |
86 // to this object. | 83 // to this object. |
87 BitmapPlatformDeviceData* data_; | 84 BitmapPlatformDeviceData* data_; |
88 | 85 |
89 #ifdef SK_DEBUG | 86 #ifdef SK_DEBUG |
90 int begin_paint_count_; | 87 int begin_paint_count_; |
91 #endif | 88 #endif |
92 | 89 |
93 DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); | 90 DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); |
94 }; | 91 }; |
95 | 92 |
96 } // namespace skia | 93 } // namespace skia |
97 | 94 |
98 #endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_ | 95 #endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_ |
99 | |
OLD | NEW |