| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 static BitmapPlatformDevice* Create(int width, int height, | 32 static BitmapPlatformDevice* Create(int width, int height, |
| 33 bool is_opaque, HANDLE shared_section, | 33 bool is_opaque, HANDLE shared_section, |
| 34 bool do_clear = false); | 34 bool do_clear = false); |
| 35 | 35 |
| 36 // Create a BitmapPlatformDevice with no shared section. The bitmap is not | 36 // Create a BitmapPlatformDevice with no shared section. The bitmap is not |
| 37 // initialized to 0. | 37 // initialized to 0. |
| 38 static BitmapPlatformDevice* Create(int width, int height, bool is_opaque); | 38 static BitmapPlatformDevice* Create(int width, int height, bool is_opaque); |
| 39 | 39 |
| 40 ~BitmapPlatformDevice() override; | 40 ~BitmapPlatformDevice() override; |
| 41 | 41 |
| 42 // Loads (lazily) the given transform and clipping region into the HDC. This | 42 void DrawToHDC(HDC source_dc, HDC destination_dc, int x, int y, |
| 43 // is overridden from SkBaseDevice, where it is deprecated. | 43 const RECT* src_rect, const SkMatrix& transform) override; |
| 44 void setMatrixClip(const SkMatrix& transform, | |
| 45 const SkRegion& region, | |
| 46 const SkClipStack&) override; | |
| 47 | |
| 48 void DrawToHDC(HDC dc, int x, int y, const RECT* src_rect) override; | |
| 49 | 44 |
| 50 protected: | 45 protected: |
| 51 // Flushes the Windows device context so that the pixel data can be accessed | 46 // Flushes the Windows device context so that the pixel data can be accessed |
| 52 // directly by Skia. Overridden from SkBaseDevice, this is called when Skia | 47 // directly by Skia. Overridden from SkBaseDevice, this is called when Skia |
| 53 // starts accessing pixel data. | 48 // starts accessing pixel data. |
| 54 const SkBitmap& onAccessBitmap() override; | 49 const SkBitmap& onAccessBitmap() override; |
| 55 | 50 |
| 56 SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; | 51 SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; |
| 57 | 52 |
| 58 private: | 53 private: |
| 59 // PlatformDevice override | 54 // PlatformDevice override |
| 60 // Retrieves the bitmap DC, which is the memory DC for our bitmap data. The | 55 // Retrieves the bitmap DC, which is the memory DC for our bitmap data. The |
| 61 // bitmap DC may be lazily created. | 56 // bitmap DC may be lazily created. |
| 62 PlatformSurface BeginPlatformPaint() override; | 57 PlatformSurface BeginPlatformPaint(const SkMatrix& transform, |
| 58 const SkIRect& clip_bounds) override; |
| 63 | 59 |
| 64 // Private constructor. | 60 // Private constructor. |
| 65 BitmapPlatformDevice(HBITMAP hbitmap, const SkBitmap& bitmap); | 61 BitmapPlatformDevice(HBITMAP hbitmap, const SkBitmap& bitmap); |
| 66 | 62 |
| 67 // Bitmap into which the drawing will be done. This bitmap not owned by this | 63 // 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. | 64 // class, but by the BitmapPlatformPixelRef inside the device's SkBitmap. |
| 69 // It's only stored here in order to lazy-create the DC (below). | 65 // It's only stored here in order to lazy-create the DC (below). |
| 70 HBITMAP hbitmap_; | 66 HBITMAP hbitmap_; |
| 71 | 67 |
| 72 // Previous bitmap held by the DC. This will be selected back before the | 68 // Previous bitmap held by the DC. This will be selected back before the |
| 73 // DC is destroyed. | 69 // DC is destroyed. |
| 74 HBITMAP old_hbitmap_; | 70 HBITMAP old_hbitmap_; |
| 75 | 71 |
| 76 // Lazily-created DC used to draw into the bitmap; see GetBitmapDC(). | 72 // Lazily-created DC used to draw into the bitmap; see GetBitmapDC(). |
| 77 HDC hdc_; | 73 HDC hdc_; |
| 78 | 74 |
| 79 // True when there is a transform or clip that has not been set to the | |
| 80 // context. The context is retrieved for every text operation, and the | |
| 81 // transform and clip do not change as much. We can save time by not loading | |
| 82 // the clip and transform for every one. | |
| 83 bool config_dirty_; | |
| 84 | |
| 85 // Translation assigned to the context: we need to keep track of this | |
| 86 // separately so it can be updated even if the context isn't created yet. | |
| 87 SkMatrix transform_; | |
| 88 | |
| 89 // The current clipping region. | |
| 90 SkRegion clip_region_; | |
| 91 | |
| 92 // Create/destroy hdc_, which is the memory DC for our bitmap data. | 75 // Create/destroy hdc_, which is the memory DC for our bitmap data. |
| 93 HDC GetBitmapDC(); | 76 HDC GetBitmapDC(const SkMatrix& transform, const SkIRect& clip_bounds); |
| 94 void ReleaseBitmapDC(); | 77 void ReleaseBitmapDC(); |
| 95 bool IsBitmapDCCreated() const; | 78 bool IsBitmapDCCreated() const; |
| 96 | 79 |
| 97 // 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 // pick up these changes. | |
| 100 void SetMatrixClip(const SkMatrix& transform, const SkRegion& region); | |
| 101 | |
| 102 // Loads the current transform and clip into the context. Can be called even | 80 // Loads the current transform and clip into the context. Can be called even |
| 103 // when |hbitmap_| is NULL (will be a NOP). | 81 // when |hbitmap_| is NULL (will be a NOP). |
| 104 void LoadConfig(); | 82 void LoadConfig(const SkMatrix& transform, const SkIRect& clip_bounds); |
| 105 | 83 |
| 106 DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); | 84 DISALLOW_COPY_AND_ASSIGN(BitmapPlatformDevice); |
| 107 friend class ScopedPlatformPaint; | 85 friend class ScopedPlatformPaint; |
| 108 }; | 86 }; |
| 109 | 87 |
| 110 } // namespace skia | 88 } // namespace skia |
| 111 | 89 |
| 112 #endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_ | 90 #endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_ |
| OLD | NEW |