OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "skia/ext/platform_device.h" | 10 #include "skia/ext/platform_device.h" |
11 #include "skia/ext/refptr.h" | 11 #include "skia/ext/refptr.h" |
12 | 12 |
13 namespace skia { | 13 namespace skia { |
14 | 14 |
15 // 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 |
16 // 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 |
17 // to. BitmapPlatformDevice creates a bitmap using CreateDIBSection() in a | 17 // to. BitmapPlatformDevice creates a bitmap using CreateDIBSection() in a |
18 // 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. |
19 // 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 |
20 // can be shared. | 20 // can be shared. |
21 // | 21 // |
22 // 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 |
23 // also becomes invalid. THIS IS DIFFERENT THAN NORMAL SKIA which uses | 23 // also becomes invalid. THIS IS DIFFERENT THAN NORMAL SKIA which uses |
24 // 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 |
25 // 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. |
26 // 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 |
27 // 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 |
28 // 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. |
29 class SK_API BitmapPlatformDevice : public SkDevice, public PlatformDevice { | 29 class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice
{ |
30 public: | 30 public: |
31 // Factory function. is_opaque should be set if the caller knows the bitmap | 31 // Factory function. is_opaque should be set if the caller knows the bitmap |
32 // will be completely opaque and allows some optimizations. | 32 // will be completely opaque and allows some optimizations. |
33 // | 33 // |
34 // The |shared_section| parameter is optional (pass NULL for default | 34 // The |shared_section| parameter is optional (pass NULL for default |
35 // behavior). If |shared_section| is non-null, then it must be a handle to a | 35 // behavior). If |shared_section| is non-null, then it must be a handle to a |
36 // file-mapping object returned by CreateFileMapping. See CreateDIBSection | 36 // file-mapping object returned by CreateFileMapping. See CreateDIBSection |
37 // for details. If |shared_section| is null, the bitmap backing store is not | 37 // for details. If |shared_section| is null, the bitmap backing store is not |
38 // initialized. | 38 // initialized. |
39 static BitmapPlatformDevice* Create(int width, int height, | 39 static BitmapPlatformDevice* Create(int width, int height, |
(...skipping 13 matching lines...) Expand all Loading... |
53 // PlatformDevice overrides | 53 // PlatformDevice overrides |
54 // Retrieves the bitmap DC, which is the memory DC for our bitmap data. The | 54 // Retrieves the bitmap DC, which is the memory DC for our bitmap data. The |
55 // bitmap DC is lazy created. | 55 // bitmap DC is lazy created. |
56 virtual PlatformSurface BeginPlatformPaint() OVERRIDE; | 56 virtual PlatformSurface BeginPlatformPaint() OVERRIDE; |
57 virtual void EndPlatformPaint() OVERRIDE; | 57 virtual void EndPlatformPaint() OVERRIDE; |
58 | 58 |
59 virtual void DrawToNativeContext(HDC dc, int x, int y, | 59 virtual void DrawToNativeContext(HDC dc, int x, int y, |
60 const RECT* src_rect) OVERRIDE; | 60 const RECT* src_rect) OVERRIDE; |
61 | 61 |
62 // Loads the given transform and clipping region into the HDC. This is | 62 // Loads the given transform and clipping region into the HDC. This is |
63 // overridden from SkDevice. | 63 // overridden from SkBaseDevice. |
64 virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, | 64 virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, |
65 const SkClipStack&) OVERRIDE; | 65 const SkClipStack&) OVERRIDE; |
66 | 66 |
67 protected: | 67 protected: |
68 // Flushes the Windows device context so that the pixel data can be accessed | 68 // Flushes the Windows device context so that the pixel data can be accessed |
69 // directly by Skia. Overridden from SkDevice, this is called when Skia | 69 // directly by Skia. Overridden from SkBaseDevice, this is called when Skia |
70 // starts accessing pixel data. | 70 // starts accessing pixel data. |
71 virtual const SkBitmap& onAccessBitmap(SkBitmap* bitmap) OVERRIDE; | 71 virtual const SkBitmap& onAccessBitmap(SkBitmap* bitmap) OVERRIDE; |
72 | 72 |
73 virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, | 73 virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config, int width, |
74 int height, bool isOpaque, | 74 int height, bool isOpaque, |
75 Usage usage) OVERRIDE; | 75 Usage usage) OVERRIDE; |
76 | 76 |
77 private: | 77 private: |
78 // Reference counted data that can be shared between multiple devices. This | 78 // Reference counted data that can be shared between multiple devices. This |
79 // allows copy constructors and operator= for devices to work properly. The | 79 // allows copy constructors and operator= for devices to work properly. The |
80 // bitmaps used by the base device class are already refcounted and copyable. | 80 // bitmaps used by the base device class are already refcounted and copyable. |
81 class BitmapPlatformDeviceData; | 81 class BitmapPlatformDeviceData; |
82 | 82 |
83 // Private constructor. | 83 // Private constructor. |
84 BitmapPlatformDevice(const skia::RefPtr<BitmapPlatformDeviceData>& data, | 84 BitmapPlatformDevice(const skia::RefPtr<BitmapPlatformDeviceData>& data, |
85 const SkBitmap& bitmap); | 85 const SkBitmap& bitmap); |
86 | 86 |
87 // Data associated with this device, guaranteed non-null. | 87 // Data associated with this device, guaranteed non-null. |
88 skia::RefPtr<BitmapPlatformDeviceData> data_; | 88 skia::RefPtr<BitmapPlatformDeviceData> data_; |
89 | 89 |
90 #ifdef SK_DEBUG | 90 #ifdef SK_DEBUG |
91 int begin_paint_count_; | 91 int begin_paint_count_; |
92 #endif | 92 #endif |
93 | 93 |
94 DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); | 94 DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); |
95 }; | 95 }; |
96 | 96 |
97 } // namespace skia | 97 } // namespace skia |
98 | 98 |
99 #endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_ | 99 #endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_ |
OLD | NEW |