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 #include "skia/ext/vector_platform_device_emf_win.h" | 5 #include "skia/ext/vector_platform_device_emf_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 bool succeeded = false; | 74 bool succeeded = false; |
75 if (selected_bitmap != NULL) { | 75 if (selected_bitmap != NULL) { |
76 BITMAP bitmap_data = {0}; | 76 BITMAP bitmap_data = {0}; |
77 if (GetObject(selected_bitmap, sizeof(BITMAP), &bitmap_data) == | 77 if (GetObject(selected_bitmap, sizeof(BITMAP), &bitmap_data) == |
78 sizeof(BITMAP)) { | 78 sizeof(BITMAP)) { |
79 // The context has a bitmap attached. Attach our SkBitmap to it. | 79 // The context has a bitmap attached. Attach our SkBitmap to it. |
80 // Warning: If the bitmap gets unselected from the HDC, | 80 // Warning: If the bitmap gets unselected from the HDC, |
81 // VectorPlatformDeviceEmf has no way to detect this, so the HBITMAP | 81 // VectorPlatformDeviceEmf has no way to detect this, so the HBITMAP |
82 // could be released while SkBitmap still has a reference to it. Be | 82 // could be released while SkBitmap still has a reference to it. Be |
83 // cautious. | 83 // cautious. |
84 if (width == bitmap_data.bmWidth && | 84 if (width == bitmap_data.bmWidth && height == bitmap_data.bmHeight) { |
85 height == bitmap_data.bmHeight) { | 85 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
86 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 86 succeeded = bitmap.installPixels(info, bitmap_data.bmBits, |
87 bitmap_data.bmWidth, | 87 bitmap_data.bmWidthBytes); |
88 bitmap_data.bmHeight, | |
89 bitmap_data.bmWidthBytes); | |
90 bitmap.setPixels(bitmap_data.bmBits); | |
91 succeeded = true; | |
92 } | 88 } |
93 } | 89 } |
94 } | 90 } |
95 | 91 |
96 if (!succeeded) | 92 if (!succeeded) |
97 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 93 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height)); |
98 | 94 |
99 return new VectorPlatformDeviceEmf(dc, bitmap); | 95 return new VectorPlatformDeviceEmf(dc, bitmap); |
100 } | 96 } |
101 | 97 |
102 VectorPlatformDeviceEmf::VectorPlatformDeviceEmf(HDC dc, const SkBitmap& bitmap) | 98 VectorPlatformDeviceEmf::VectorPlatformDeviceEmf(HDC dc, const SkBitmap& bitmap) |
103 : SkBitmapDevice(bitmap), | 99 : SkBitmapDevice(bitmap), |
104 hdc_(dc), | 100 hdc_(dc), |
105 previous_brush_(NULL), | 101 previous_brush_(NULL), |
106 previous_pen_(NULL) { | 102 previous_pen_(NULL) { |
107 transform_.reset(); | 103 transform_.reset(); |
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 pixels, | 986 pixels, |
991 reinterpret_cast<const BITMAPINFO*>(&hdr), | 987 reinterpret_cast<const BITMAPINFO*>(&hdr), |
992 DIB_RGB_COLORS, | 988 DIB_RGB_COLORS, |
993 SRCCOPY); | 989 SRCCOPY); |
994 } | 990 } |
995 EndPlatformPaint(); | 991 EndPlatformPaint(); |
996 Cleanup(); | 992 Cleanup(); |
997 } | 993 } |
998 | 994 |
999 } // namespace skia | 995 } // namespace skia |
OLD | NEW |