| OLD | NEW |
| 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 BASE_GFX_BITMAP_PLATFORM_DEVICE_WIN_H_ | 5 #ifndef BASE_GFX_BITMAP_PLATFORM_DEVICE_WIN_H_ |
| 6 #define BASE_GFX_BITMAP_PLATFORM_DEVICE_WIN_H_ | 6 #define BASE_GFX_BITMAP_PLATFORM_DEVICE_WIN_H_ |
| 7 | 7 |
| 8 #include "base/gfx/platform_device_win.h" | 8 // TODO(brettw) this file should be removed and the includes changed to this |
| 9 #include "base/ref_counted.h" | 9 // new location. |
| 10 | 10 #include "webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceWin.h" |
| 11 namespace gfx { | |
| 12 | |
| 13 // A device is basically a wrapper around SkBitmap that provides a surface for | |
| 14 // SkCanvas to draw into. Our device provides a surface Windows can also write | |
| 15 // to. BitmapPlatformDeviceWin creates a bitmap using CreateDIBSection() in a | |
| 16 // format that Skia supports and can then use this to draw ClearType into, etc. | |
| 17 // This pixel data is provided to the bitmap that the device contains so that it | |
| 18 // can be shared. | |
| 19 // | |
| 20 // The device owns the pixel data, when the device goes away, the pixel data | |
| 21 // also becomes invalid. THIS IS DIFFERENT THAN NORMAL SKIA which uses | |
| 22 // reference counting for the pixel data. In normal Skia, you could assign | |
| 23 // another bitmap to this device's bitmap and everything will work properly. | |
| 24 // For us, that other bitmap will become invalid as soon as the device becomes | |
| 25 // invalid, which may lead to subtle bugs. Therefore, DO NOT ASSIGN THE | |
| 26 // DEVICE'S PIXEL DATA TO ANOTHER BITMAP, make sure you copy instead. | |
| 27 class BitmapPlatformDeviceWin : public PlatformDeviceWin { | |
| 28 public: | |
| 29 // Factory function. The screen DC is used to create the bitmap, and will not | |
| 30 // be stored beyond this function. is_opaque should be set if the caller | |
| 31 // knows the bitmap will be completely opaque and allows some optimizations. | |
| 32 // | |
| 33 // The shared_section parameter is optional (pass NULL for default behavior). | |
| 34 // If shared_section is non-null, then it must be a handle to a file-mapping | |
| 35 // object returned by CreateFileMapping. See CreateDIBSection for details. | |
| 36 static BitmapPlatformDeviceWin* create(HDC screen_dc, | |
| 37 int width, | |
| 38 int height, | |
| 39 bool is_opaque, | |
| 40 HANDLE shared_section); | |
| 41 | |
| 42 // Copy constructor. When copied, devices duplicate their internal data, so | |
| 43 // stay linked. This is because their implementation is very heavyweight | |
| 44 // (lots of memory and some GDI objects). If a device has been copied, both | |
| 45 // clip rects and other state will stay in sync. | |
| 46 // | |
| 47 // This means it will NOT work to duplicate a device and assign it to a | |
| 48 // canvas, because the two canvases will each set their own clip rects, and | |
| 49 // the resulting GDI clip rect will be random. | |
| 50 // | |
| 51 // Copy constucting and "=" is designed for saving the device or passing it | |
| 52 // around to another routine willing to deal with the bitmap data directly. | |
| 53 BitmapPlatformDeviceWin(const BitmapPlatformDeviceWin& other); | |
| 54 virtual ~BitmapPlatformDeviceWin(); | |
| 55 | |
| 56 // See warning for copy constructor above. | |
| 57 BitmapPlatformDeviceWin& operator=(const BitmapPlatformDeviceWin& other); | |
| 58 | |
| 59 // Retrieves the bitmap DC, which is the memory DC for our bitmap data. The | |
| 60 // bitmap DC is lazy created. | |
| 61 virtual HDC getBitmapDC(); | |
| 62 virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region); | |
| 63 | |
| 64 virtual void drawToHDC(HDC dc, int x, int y, const RECT* src_rect); | |
| 65 virtual void prepareForGDI(int x, int y, int width, int height); | |
| 66 virtual void postProcessGDI(int x, int y, int width, int height); | |
| 67 virtual void makeOpaque(int x, int y, int width, int height); | |
| 68 virtual void fixupAlphaBeforeCompositing(); | |
| 69 virtual bool IsVectorial() { return false; } | |
| 70 | |
| 71 // Returns the color value at the specified location. This does not | |
| 72 // consider any transforms that may be set on the device. | |
| 73 SkColor getColorAt(int x, int y); | |
| 74 | |
| 75 protected: | |
| 76 // Flushes the Windows device context so that the pixel data can be accessed | |
| 77 // directly by Skia. Overridden from SkDevice, this is called when Skia | |
| 78 // starts accessing pixel data. | |
| 79 virtual void onAccessBitmap(SkBitmap* bitmap); | |
| 80 | |
| 81 private: | |
| 82 // Function pointer used by the processPixels method for setting the alpha | |
| 83 // value of a particular pixel. | |
| 84 typedef void (*adjustAlpha)(uint32_t* pixel); | |
| 85 | |
| 86 // Reference counted data that can be shared between multiple devices. This | |
| 87 // allows copy constructors and operator= for devices to work properly. The | |
| 88 // bitmaps used by the base device class are already refcounted and copyable. | |
| 89 class BitmapPlatformDeviceWinData; | |
| 90 | |
| 91 // Private constructor. | |
| 92 BitmapPlatformDeviceWin(BitmapPlatformDeviceWinData* data, | |
| 93 const SkBitmap& bitmap); | |
| 94 | |
| 95 // Loops through each of the pixels in the specified range, invoking | |
| 96 // adjustor for the alpha value of each pixel. If |width| or |height| are -1, | |
| 97 // the available width/height is used. | |
| 98 template<adjustAlpha adjustor> | |
| 99 void processPixels(int x, | |
| 100 int y, | |
| 101 int width, | |
| 102 int height); | |
| 103 | |
| 104 // Data associated with this device, guaranteed non-null. | |
| 105 scoped_refptr<BitmapPlatformDeviceWinData> data_; | |
| 106 }; | |
| 107 | |
| 108 } // namespace gfx | |
| 109 | 11 |
| 110 #endif // BASE_GFX_BITMAP_PLATFORM_DEVICE_WIN_H_ | 12 #endif // BASE_GFX_BITMAP_PLATFORM_DEVICE_WIN_H_ |
| 111 | 13 |
| OLD | NEW |