| 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/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.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 class ScopedPlatformPaint; |
| 16 |
| 15 // A device is basically a wrapper around SkBitmap that provides a surface for | 17 // 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 | 18 // SkCanvas to draw into. Our device provides a surface Windows can also write |
| 17 // to. BitmapPlatformDevice creates a bitmap using CreateDIBSection() in a | 19 // to. BitmapPlatformDevice creates a bitmap using CreateDIBSection() in a |
| 18 // format that Skia supports and can then use this to draw ClearType into, etc. | 20 // 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 | 21 // This pixel data is provided to the bitmap that the device contains so that it |
| 20 // can be shared. | 22 // can be shared. |
| 21 class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice
{ | 23 class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice
{ |
| 22 public: | 24 public: |
| 23 // Factory function. is_opaque should be set if the caller knows the bitmap | 25 // Factory function. is_opaque should be set if the caller knows the bitmap |
| 24 // will be completely opaque and allows some optimizations. | 26 // will be completely opaque and allows some optimizations. |
| 25 // | 27 // |
| 26 // The |shared_section| parameter is optional (pass NULL for default | 28 // The |shared_section| parameter is optional (pass NULL for default |
| 27 // behavior). If |shared_section| is non-null, then it must be a handle to a | 29 // behavior). If |shared_section| is non-null, then it must be a handle to a |
| 28 // file-mapping object returned by CreateFileMapping. See CreateDIBSection | 30 // file-mapping object returned by CreateFileMapping. See CreateDIBSection |
| 29 // for details. If |shared_section| is null, the bitmap backing store is not | 31 // for details. If |shared_section| is null, the bitmap backing store is not |
| 30 // initialized. | 32 // initialized. |
| 31 static BitmapPlatformDevice* Create(int width, int height, | 33 static BitmapPlatformDevice* Create(int width, int height, |
| 32 bool is_opaque, HANDLE shared_section, | 34 bool is_opaque, HANDLE shared_section, |
| 33 bool do_clear = false); | 35 bool do_clear = false); |
| 34 | 36 |
| 35 // Create a BitmapPlatformDevice with no shared section. The bitmap is not | 37 // Create a BitmapPlatformDevice with no shared section. The bitmap is not |
| 36 // initialized to 0. | 38 // initialized to 0. |
| 37 static BitmapPlatformDevice* Create(int width, int height, bool is_opaque); | 39 static BitmapPlatformDevice* Create(int width, int height, bool is_opaque); |
| 38 | 40 |
| 39 ~BitmapPlatformDevice() override; | 41 ~BitmapPlatformDevice() override; |
| 40 | 42 |
| 41 // PlatformDevice overrides | 43 // Loads (lazily) the given transform and clipping region into the HDC. This |
| 42 // Retrieves the bitmap DC, which is the memory DC for our bitmap data. The | 44 // is overridden from SkBaseDevice, where it is deprecated. |
| 43 // bitmap DC is lazy created. | |
| 44 PlatformSurface BeginPlatformPaint() override; | |
| 45 void EndPlatformPaint() override; | |
| 46 | |
| 47 // Loads the given transform and clipping region into the HDC. This is | |
| 48 // overridden from SkBaseDevice. | |
| 49 void setMatrixClip(const SkMatrix& transform, | 45 void setMatrixClip(const SkMatrix& transform, |
| 50 const SkRegion& region, | 46 const SkRegion& region, |
| 51 const SkClipStack&) override; | 47 const SkClipStack&) override; |
| 52 | 48 |
| 53 void DrawToHDC(HDC dc, int x, int y, const RECT* src_rect) override; | 49 void DrawToHDC(HDC dc, int x, int y, const RECT* src_rect) override; |
| 54 | 50 |
| 55 protected: | 51 protected: |
| 56 // Flushes the Windows device context so that the pixel data can be accessed | 52 // Flushes the Windows device context so that the pixel data can be accessed |
| 57 // directly by Skia. Overridden from SkBaseDevice, this is called when Skia | 53 // directly by Skia. Overridden from SkBaseDevice, this is called when Skia |
| 58 // starts accessing pixel data. | 54 // starts accessing pixel data. |
| 59 const SkBitmap& onAccessBitmap() override; | 55 const SkBitmap& onAccessBitmap() override; |
| 60 | 56 |
| 61 SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; | 57 SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; |
| 62 | 58 |
| 63 private: | 59 private: |
| 60 // PlatformDevice override |
| 61 // Retrieves the bitmap DC, which is the memory DC for our bitmap data. The |
| 62 // bitmap DC may be lazily created. |
| 63 PlatformSurface BeginPlatformPaint() override; |
| 64 |
| 64 // Private constructor. | 65 // Private constructor. |
| 65 BitmapPlatformDevice(HBITMAP hbitmap, const SkBitmap& bitmap); | 66 BitmapPlatformDevice(HBITMAP hbitmap, const SkBitmap& bitmap); |
| 66 | 67 |
| 67 // Bitmap into which the drawing will be done. This bitmap not owned by this | 68 // Bitmap into which the drawing will be done. This bitmap not owned by this |
| 68 // class, but by the BitmapPlatformPixelRef inside the device's SkBitmap. | 69 // class, but by the BitmapPlatformPixelRef inside the device's SkBitmap. |
| 69 // It's only stored here in order to lazy-create the DC (below). | 70 // It's only stored here in order to lazy-create the DC (below). |
| 70 HBITMAP hbitmap_; | 71 HBITMAP hbitmap_; |
| 71 | 72 |
| 72 // Previous bitmap held by the DC. This will be selected back before the | 73 // Previous bitmap held by the DC. This will be selected back before the |
| 73 // DC is destroyed. | 74 // DC is destroyed. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 96 | 97 |
| 97 // Sets the transform and clip operations. This will not update the DC, | 98 // Sets the transform and clip operations. This will not update the DC, |
| 98 // but will mark the config as dirty. The next call of LoadConfig will | 99 // but will mark the config as dirty. The next call of LoadConfig will |
| 99 // pick up these changes. | 100 // pick up these changes. |
| 100 void SetMatrixClip(const SkMatrix& transform, const SkRegion& region); | 101 void SetMatrixClip(const SkMatrix& transform, const SkRegion& region); |
| 101 | 102 |
| 102 // Loads the current transform and clip into the context. Can be called even | 103 // Loads the current transform and clip into the context. Can be called even |
| 103 // when |hbitmap_| is NULL (will be a NOP). | 104 // when |hbitmap_| is NULL (will be a NOP). |
| 104 void LoadConfig(); | 105 void LoadConfig(); |
| 105 | 106 |
| 106 #ifdef SK_DEBUG | |
| 107 int begin_paint_count_; | |
| 108 #endif | |
| 109 | |
| 110 DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); | 107 DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); |
| 108 friend class ScopedPlatformPaint; |
| 111 }; | 109 }; |
| 112 | 110 |
| 113 } // namespace skia | 111 } // namespace skia |
| 114 | 112 |
| 115 #endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_ | 113 #endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_ |
| OLD | NEW |