OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 5 #include <windows.h> |
6 | 6 |
7 #include "skia/ext/vector_platform_device_emf_win.h" | 7 #include "skia/ext/vector_platform_device_emf_win.h" |
8 | 8 |
9 #include "skia/ext/bitmap_platform_device.h" | 9 #include "skia/ext/bitmap_platform_device.h" |
10 #include "skia/ext/skia_utils_win.h" | 10 #include "skia/ext/skia_utils_win.h" |
11 #include "third_party/skia/include/core/SkTemplates.h" | 11 #include "third_party/skia/include/core/SkTemplates.h" |
12 #include "third_party/skia/include/core/SkUtils.h" | 12 #include "third_party/skia/include/core/SkUtils.h" |
13 #include "third_party/skia/include/ports/SkTypeface_win.h" | 13 #include "third_party/skia/include/ports/SkTypeface_win.h" |
14 | 14 |
15 namespace skia { | 15 namespace skia { |
16 | 16 |
17 //static | 17 //static |
18 PlatformDevice* VectorPlatformDeviceEmf::CreateDevice(int width, int height, | 18 SkDevice* VectorPlatformDeviceEmf::CreateDevice(int width, int height, |
19 bool is_opaque, | 19 bool is_opaque, |
20 HANDLE shared_section) { | 20 HANDLE shared_section) { |
21 if (!is_opaque) { | 21 if (!is_opaque) { |
22 // TODO(maruel): http://crbug.com/18382 When restoring a semi-transparent | 22 // TODO(maruel): http://crbug.com/18382 When restoring a semi-transparent |
23 // layer, i.e. merging it, we need to rasterize it because GDI doesn't | 23 // layer, i.e. merging it, we need to rasterize it because GDI doesn't |
24 // support transparency except for AlphaBlend(). Right now, a | 24 // support transparency except for AlphaBlend(). Right now, a |
25 // BitmapPlatformDevice is created when VectorCanvas think a saveLayers() | 25 // BitmapPlatformDevice is created when VectorCanvas think a saveLayers() |
26 // call is being done. The way to save a layer would be to create an | 26 // call is being done. The way to save a layer would be to create an |
27 // EMF-based VectorDevice and have this device registers the drawing. When | 27 // EMF-based VectorDevice and have this device registers the drawing. When |
28 // playing back the device into a bitmap, do it at the printer's dpi instead | 28 // playing back the device into a bitmap, do it at the printer's dpi instead |
29 // of the layout's dpi (which is much lower). | 29 // of the layout's dpi (which is much lower). |
30 return BitmapPlatformDevice::create(width, height, is_opaque, | 30 return BitmapPlatformDevice::create(width, height, is_opaque, |
31 shared_section); | 31 shared_section); |
32 } | 32 } |
33 | 33 |
34 // TODO(maruel): http://crbug.com/18383 Look if it would be worth to | 34 // TODO(maruel): http://crbug.com/18383 Look if it would be worth to |
35 // increase the resolution by ~10x (any worthy factor) to increase the | 35 // increase the resolution by ~10x (any worthy factor) to increase the |
36 // rendering precision (think about printing) while using a relatively | 36 // rendering precision (think about printing) while using a relatively |
37 // low dpi. This happens because we receive float as input but the GDI | 37 // low dpi. This happens because we receive float as input but the GDI |
38 // functions works with integers. The idea is to premultiply the matrix | 38 // functions works with integers. The idea is to premultiply the matrix |
39 // with this factor and multiply each SkScalar that are passed to | 39 // with this factor and multiply each SkScalar that are passed to |
40 // SkScalarRound(value) as SkScalarRound(value * 10). Safari is already | 40 // SkScalarRound(value) as SkScalarRound(value * 10). Safari is already |
41 // doing the same for text rendering. | 41 // doing the same for text rendering. |
42 SkASSERT(shared_section); | 42 SkASSERT(shared_section); |
43 PlatformDevice* device = VectorPlatformDeviceEmf::create( | 43 SkDevice* device = VectorPlatformDeviceEmf::create( |
44 reinterpret_cast<HDC>(shared_section), width, height); | 44 reinterpret_cast<HDC>(shared_section), width, height); |
45 return device; | 45 return device; |
46 } | 46 } |
47 | 47 |
48 static void FillBitmapInfoHeader(int width, int height, BITMAPINFOHEADER* hdr) { | 48 static void FillBitmapInfoHeader(int width, int height, BITMAPINFOHEADER* hdr) { |
49 hdr->biSize = sizeof(BITMAPINFOHEADER); | 49 hdr->biSize = sizeof(BITMAPINFOHEADER); |
50 hdr->biWidth = width; | 50 hdr->biWidth = width; |
51 hdr->biHeight = -height; // Minus means top-down bitmap. | 51 hdr->biHeight = -height; // Minus means top-down bitmap. |
52 hdr->biPlanes = 1; | 52 hdr->biPlanes = 1; |
53 hdr->biBitCount = 32; | 53 hdr->biBitCount = 32; |
54 hdr->biCompression = BI_RGB; // no compression | 54 hdr->biCompression = BI_RGB; // no compression |
55 hdr->biSizeImage = 0; | 55 hdr->biSizeImage = 0; |
56 hdr->biXPelsPerMeter = 1; | 56 hdr->biXPelsPerMeter = 1; |
57 hdr->biYPelsPerMeter = 1; | 57 hdr->biYPelsPerMeter = 1; |
58 hdr->biClrUsed = 0; | 58 hdr->biClrUsed = 0; |
59 hdr->biClrImportant = 0; | 59 hdr->biClrImportant = 0; |
60 } | 60 } |
61 | 61 |
62 VectorPlatformDeviceEmf* VectorPlatformDeviceEmf::create(HDC dc, | 62 SkDevice* VectorPlatformDeviceEmf::create(HDC dc, int width, int height) { |
63 int width, | |
64 int height) { | |
65 InitializeDC(dc); | 63 InitializeDC(dc); |
66 | 64 |
67 // Link the SkBitmap to the current selected bitmap in the device context. | 65 // Link the SkBitmap to the current selected bitmap in the device context. |
68 SkBitmap bitmap; | 66 SkBitmap bitmap; |
69 HGDIOBJ selected_bitmap = GetCurrentObject(dc, OBJ_BITMAP); | 67 HGDIOBJ selected_bitmap = GetCurrentObject(dc, OBJ_BITMAP); |
70 bool succeeded = false; | 68 bool succeeded = false; |
71 if (selected_bitmap != NULL) { | 69 if (selected_bitmap != NULL) { |
72 BITMAP bitmap_data; | 70 BITMAP bitmap_data; |
73 if (GetObject(selected_bitmap, sizeof(BITMAP), &bitmap_data) == | 71 if (GetObject(selected_bitmap, sizeof(BITMAP), &bitmap_data) == |
74 sizeof(BITMAP)) { | 72 sizeof(BITMAP)) { |
(...skipping 10 matching lines...) Expand all Loading... |
85 bitmap_data.bmWidthBytes); | 83 bitmap_data.bmWidthBytes); |
86 bitmap.setPixels(bitmap_data.bmBits); | 84 bitmap.setPixels(bitmap_data.bmBits); |
87 succeeded = true; | 85 succeeded = true; |
88 } | 86 } |
89 } | 87 } |
90 } | 88 } |
91 | 89 |
92 if (!succeeded) | 90 if (!succeeded) |
93 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 91 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
94 | 92 |
95 return new VectorPlatformDeviceEmf(dc, bitmap); | 93 VectorPlatformDeviceEmf* vector_device = new VectorPlatformDeviceEmf(dc, bitma
p); |
| 94 //return new VectorPlatformDeviceEmf(dc, bitmap); |
| 95 return vector_device->GetOwningDevice(); |
96 } | 96 } |
97 | 97 |
98 VectorPlatformDeviceEmf::VectorPlatformDeviceEmf(HDC dc, const SkBitmap& bitmap) | 98 VectorPlatformDeviceEmf::VectorPlatformDeviceEmf(HDC dc, const SkBitmap& bitmap) |
99 : PlatformDevice(bitmap), | 99 : SkDevice(bitmap), |
| 100 PlatformDevice(static_cast<SkDevice*>(this)), |
100 hdc_(dc), | 101 hdc_(dc), |
101 previous_brush_(NULL), | 102 previous_brush_(NULL), |
102 previous_pen_(NULL), | 103 previous_pen_(NULL), |
103 alpha_blend_used_(false) { | 104 alpha_blend_used_(false) { |
104 transform_.reset(); | 105 transform_.reset(); |
| 106 // Pass false, because VectorPlatformDeviceEmf inherits both SkDevice, and |
| 107 // PlatformDevice, so there is no need to explicitly bind the lifetime of the |
| 108 // two classes. |
| 109 SetPlatformDevice(device_, this, false); |
105 } | 110 } |
106 | 111 |
107 VectorPlatformDeviceEmf::~VectorPlatformDeviceEmf() { | 112 VectorPlatformDeviceEmf::~VectorPlatformDeviceEmf() { |
108 SkASSERT(previous_brush_ == NULL); | 113 SkASSERT(previous_brush_ == NULL); |
109 SkASSERT(previous_pen_ == NULL); | 114 SkASSERT(previous_pen_ == NULL); |
110 } | 115 } |
111 | 116 |
112 HDC VectorPlatformDeviceEmf::BeginPlatformPaint() { | 117 HDC VectorPlatformDeviceEmf::BeginPlatformPaint() { |
113 return hdc_; | 118 return hdc_; |
114 } | 119 } |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 reinterpret_cast<const BITMAPINFO*>(&hdr), | 864 reinterpret_cast<const BITMAPINFO*>(&hdr), |
860 DIB_RGB_COLORS, | 865 DIB_RGB_COLORS, |
861 SRCCOPY); | 866 SRCCOPY); |
862 } | 867 } |
863 EndPlatformPaint(); | 868 EndPlatformPaint(); |
864 Cleanup(); | 869 Cleanup(); |
865 } | 870 } |
866 | 871 |
867 } // namespace skia | 872 } // namespace skia |
868 | 873 |
OLD | NEW |