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 "skia/ext/platform_device_win.h" |
11 | 11 |
12 namespace skia { | 12 namespace skia { |
13 | 13 |
14 // A device is basically a wrapper around SkBitmap that provides a surface for | 14 // 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 | 15 // SkCanvas to draw into. Our device provides a surface Windows can also write |
16 // to. BitmapPlatformDevice creates a bitmap using CreateDIBSection() in a | 16 // to. BitmapPlatformDevice creates a bitmap using CreateDIBSection() in a |
17 // format that Skia supports and can then use this to draw ClearType into, etc. | 17 // 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 | 18 // This pixel data is provided to the bitmap that the device contains so that it |
19 // can be shared. | 19 // can be shared. |
20 // | 20 // |
21 // The device owns the pixel data, when the device goes away, the pixel data | 21 // 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 | 22 // also becomes invalid. THIS IS DIFFERENT THAN NORMAL SKIA which uses |
23 // reference counting for the pixel data. In normal Skia, you could assign | 23 // 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. | 24 // 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 | 25 // 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 | 26 // 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. | 27 // DEVICE'S PIXEL DATA TO ANOTHER BITMAP, make sure you copy instead. |
28 class SK_API BitmapPlatformDevice : public PlatformDevice { | 28 class SK_API BitmapPlatformDevice : public PlatformDevice, |
| 29 public SkDevice::SkMatrixClipObserver { |
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 SkDevice* create(HDC screen_dc, |
38 int width, | 39 int width, |
39 int height, | 40 int height, |
40 bool is_opaque, | 41 bool is_opaque, |
41 HANDLE shared_section); | 42 HANDLE shared_section); |
42 | 43 |
43 // This version is the same as above but will get the screen DC itself. | 44 // This version is the same as above but will get the screen DC itself. |
44 static BitmapPlatformDevice* create(int width, | 45 static SkDevice* create(int width, |
45 int height, | 46 int height, |
46 bool is_opaque, | 47 bool is_opaque, |
47 HANDLE shared_section); | 48 HANDLE shared_section); |
48 | 49 |
49 virtual ~BitmapPlatformDevice(); | 50 virtual ~BitmapPlatformDevice(); |
50 | 51 |
51 // PlatformDevice overrides | 52 // PlatformDevice overrides |
52 // Retrieves the bitmap DC, which is the memory DC for our bitmap data. The | 53 // Retrieves the bitmap DC, which is the memory DC for our bitmap data. The |
53 // bitmap DC is lazy created. | 54 // bitmap DC is lazy created. |
54 virtual PlatformSurface BeginPlatformPaint(); | 55 virtual PlatformSurface BeginPlatformPaint(); |
55 virtual void EndPlatformPaint(); | 56 virtual void EndPlatformPaint(); |
56 | 57 |
57 virtual void DrawToNativeContext(HDC dc, int x, int y, const RECT* src_rect); | 58 virtual void DrawToNativeContext(HDC dc, int x, int y, const RECT* src_rect); |
58 virtual void MakeOpaque(int x, int y, int width, int height); | 59 virtual void MakeOpaque(int x, int y, int width, int height); |
59 | 60 |
| 61 virtual void matrixClipChanged(const SkMatrix& transform, |
| 62 const SkRegion& region, const SkClipStack&); |
| 63 #if 0 |
60 // Loads the given transform and clipping region into the HDC. This is | 64 // Loads the given transform and clipping region into the HDC. This is |
61 // overridden from SkDevice. | 65 // overridden from SkDevice. |
62 virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, | 66 virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, |
63 const SkClipStack&); | 67 const SkClipStack&); |
| 68 #endif |
64 | 69 |
65 protected: | 70 protected: |
| 71 #if 0 |
66 // Flushes the Windows device context so that the pixel data can be accessed | 72 // 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 | 73 // directly by Skia. Overridden from SkDevice, this is called when Skia |
68 // starts accessing pixel data. | 74 // starts accessing pixel data. |
69 virtual void onAccessBitmap(SkBitmap* bitmap); | 75 virtual void onAccessBitmap(SkBitmap* bitmap); |
| 76 #endif |
70 | 77 |
| 78 #if 0 |
71 virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, | 79 virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, |
72 int height, bool isOpaque, | 80 int height, bool isOpaque, |
73 Usage usage); | 81 Usage usage); |
| 82 #endif |
74 | 83 |
75 private: | 84 private: |
76 // Reference counted data that can be shared between multiple devices. This | 85 // Reference counted data that can be shared between multiple devices. This |
77 // allows copy constructors and operator= for devices to work properly. The | 86 // allows copy constructors and operator= for devices to work properly. The |
78 // bitmaps used by the base device class are already refcounted and copyable. | 87 // bitmaps used by the base device class are already refcounted and copyable. |
79 class BitmapPlatformDeviceData; | 88 class BitmapPlatformDeviceData; |
80 | 89 |
81 // Private constructor. The data should already be ref'ed for us. | 90 // Private constructor. The data should already be ref'ed for us. |
82 BitmapPlatformDevice(BitmapPlatformDeviceData* data, | 91 BitmapPlatformDevice(BitmapPlatformDeviceData* data, |
83 const SkBitmap& bitmap); | 92 /*const SkBitmap& bitmap*/ |
| 93 SkDevice* device); |
84 | 94 |
85 // Data associated with this device, guaranteed non-null. We hold a reference | 95 // Data associated with this device, guaranteed non-null. We hold a reference |
86 // to this object. | 96 // to this object. |
87 BitmapPlatformDeviceData* data_; | 97 BitmapPlatformDeviceData* data_; |
88 | 98 |
89 #ifdef SK_DEBUG | 99 #ifdef SK_DEBUG |
90 int begin_paint_count_; | 100 int begin_paint_count_; |
91 #endif | 101 #endif |
92 | 102 |
93 DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); | 103 DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); |
94 }; | 104 }; |
95 | 105 |
96 } // namespace skia | 106 } // namespace skia |
97 | 107 |
98 #endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_ | 108 #endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_ |
99 | 109 |
OLD | NEW |