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" |
11 #include "skia/ext/bitmap_platform_device.h" | 11 #include "skia/ext/bitmap_platform_device.h" |
12 #include "skia/ext/skia_utils_win.h" | 12 #include "skia/ext/skia_utils_win.h" |
13 #include "third_party/skia/include/core/SkFontHost.h" | 13 #include "third_party/skia/include/core/SkFontHost.h" |
14 #include "third_party/skia/include/core/SkPathEffect.h" | 14 #include "third_party/skia/include/core/SkPathEffect.h" |
15 #include "third_party/skia/include/core/SkTemplates.h" | 15 #include "third_party/skia/include/core/SkTemplates.h" |
16 #include "third_party/skia/include/core/SkUtils.h" | 16 #include "third_party/skia/include/core/SkUtils.h" |
17 #include "third_party/skia/include/ports/SkTypeface_win.h" | 17 #include "third_party/skia/include/ports/SkTypeface_win.h" |
18 | 18 |
19 namespace skia { | 19 namespace skia { |
20 | 20 |
21 #define CHECK_FOR_NODRAW_ANNOTATION(paint) \ | 21 #define CHECK_FOR_NODRAW_ANNOTATION(paint) \ |
22 do { if (paint.isNoDrawAnnotation()) { return; } } while (0) | 22 do { if (paint.isNoDrawAnnotation()) { return; } } while (0) |
23 | 23 |
24 // static | 24 // static |
25 SkDevice* VectorPlatformDeviceEmf::CreateDevice( | 25 SkBaseDevice* VectorPlatformDeviceEmf::CreateDevice( |
26 int width, int height, bool is_opaque, HANDLE shared_section) { | 26 int width, int height, bool is_opaque, HANDLE shared_section) { |
27 if (!is_opaque) { | 27 if (!is_opaque) { |
28 // TODO(maruel): http://crbug.com/18382 When restoring a semi-transparent | 28 // TODO(maruel): http://crbug.com/18382 When restoring a semi-transparent |
29 // layer, i.e. merging it, we need to rasterize it because GDI doesn't | 29 // layer, i.e. merging it, we need to rasterize it because GDI doesn't |
30 // support transparency except for AlphaBlend(). Right now, a | 30 // support transparency except for AlphaBlend(). Right now, a |
31 // BitmapPlatformDevice is created when VectorCanvas think a saveLayers() | 31 // BitmapPlatformDevice is created when VectorCanvas think a saveLayers() |
32 // call is being done. The way to save a layer would be to create an | 32 // call is being done. The way to save a layer would be to create an |
33 // EMF-based VectorDevice and have this device registers the drawing. When | 33 // EMF-based VectorDevice and have this device registers the drawing. When |
34 // playing back the device into a bitmap, do it at the printer's dpi instead | 34 // playing back the device into a bitmap, do it at the printer's dpi instead |
35 // of the layout's dpi (which is much lower). | 35 // of the layout's dpi (which is much lower). |
36 return BitmapPlatformDevice::Create(width, height, is_opaque, | 36 return BitmapPlatformDevice::Create(width, height, is_opaque, |
37 shared_section); | 37 shared_section); |
38 } | 38 } |
39 | 39 |
40 // TODO(maruel): http://crbug.com/18383 Look if it would be worth to | 40 // TODO(maruel): http://crbug.com/18383 Look if it would be worth to |
41 // increase the resolution by ~10x (any worthy factor) to increase the | 41 // increase the resolution by ~10x (any worthy factor) to increase the |
42 // rendering precision (think about printing) while using a relatively | 42 // rendering precision (think about printing) while using a relatively |
43 // low dpi. This happens because we receive float as input but the GDI | 43 // low dpi. This happens because we receive float as input but the GDI |
44 // functions works with integers. The idea is to premultiply the matrix | 44 // functions works with integers. The idea is to premultiply the matrix |
45 // with this factor and multiply each SkScalar that are passed to | 45 // with this factor and multiply each SkScalar that are passed to |
46 // SkScalarRound(value) as SkScalarRound(value * 10). Safari is already | 46 // SkScalarRound(value) as SkScalarRound(value * 10). Safari is already |
47 // doing the same for text rendering. | 47 // doing the same for text rendering. |
48 SkASSERT(shared_section); | 48 SkASSERT(shared_section); |
49 SkDevice* device = VectorPlatformDeviceEmf::create( | 49 SkBaseDevice* device = VectorPlatformDeviceEmf::create( |
50 reinterpret_cast<HDC>(shared_section), width, height); | 50 reinterpret_cast<HDC>(shared_section), width, height); |
51 return device; | 51 return device; |
52 } | 52 } |
53 | 53 |
54 static void FillBitmapInfoHeader(int width, int height, BITMAPINFOHEADER* hdr) { | 54 static void FillBitmapInfoHeader(int width, int height, BITMAPINFOHEADER* hdr) { |
55 hdr->biSize = sizeof(BITMAPINFOHEADER); | 55 hdr->biSize = sizeof(BITMAPINFOHEADER); |
56 hdr->biWidth = width; | 56 hdr->biWidth = width; |
57 hdr->biHeight = -height; // Minus means top-down bitmap. | 57 hdr->biHeight = -height; // Minus means top-down bitmap. |
58 hdr->biPlanes = 1; | 58 hdr->biPlanes = 1; |
59 hdr->biBitCount = 32; | 59 hdr->biBitCount = 32; |
60 hdr->biCompression = BI_RGB; // no compression | 60 hdr->biCompression = BI_RGB; // no compression |
61 hdr->biSizeImage = 0; | 61 hdr->biSizeImage = 0; |
62 hdr->biXPelsPerMeter = 1; | 62 hdr->biXPelsPerMeter = 1; |
63 hdr->biYPelsPerMeter = 1; | 63 hdr->biYPelsPerMeter = 1; |
64 hdr->biClrUsed = 0; | 64 hdr->biClrUsed = 0; |
65 hdr->biClrImportant = 0; | 65 hdr->biClrImportant = 0; |
66 } | 66 } |
67 | 67 |
68 SkDevice* VectorPlatformDeviceEmf::create(HDC dc, int width, int height) { | 68 SkBaseDevice* VectorPlatformDeviceEmf::create(HDC dc, int width, int height) { |
69 InitializeDC(dc); | 69 InitializeDC(dc); |
70 | 70 |
71 // Link the SkBitmap to the current selected bitmap in the device context. | 71 // Link the SkBitmap to the current selected bitmap in the device context. |
72 SkBitmap bitmap; | 72 SkBitmap bitmap; |
73 HGDIOBJ selected_bitmap = GetCurrentObject(dc, OBJ_BITMAP); | 73 HGDIOBJ selected_bitmap = GetCurrentObject(dc, OBJ_BITMAP); |
74 bool succeeded = false; | 74 bool succeeded = false; |
75 if (selected_bitmap != NULL) { | 75 if (selected_bitmap != NULL) { |
76 BITMAP bitmap_data; | 76 BITMAP bitmap_data; |
77 if (GetObject(selected_bitmap, sizeof(BITMAP), &bitmap_data) == | 77 if (GetObject(selected_bitmap, sizeof(BITMAP), &bitmap_data) == |
78 sizeof(BITMAP)) { | 78 sizeof(BITMAP)) { |
(...skipping 14 matching lines...) Expand all Loading... |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 if (!succeeded) | 96 if (!succeeded) |
97 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 97 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
98 | 98 |
99 return new VectorPlatformDeviceEmf(dc, bitmap); | 99 return new VectorPlatformDeviceEmf(dc, bitmap); |
100 } | 100 } |
101 | 101 |
102 VectorPlatformDeviceEmf::VectorPlatformDeviceEmf(HDC dc, const SkBitmap& bitmap) | 102 VectorPlatformDeviceEmf::VectorPlatformDeviceEmf(HDC dc, const SkBitmap& bitmap) |
103 : SkDevice(bitmap), | 103 : SkBitmapDevice(bitmap), |
104 hdc_(dc), | 104 hdc_(dc), |
105 previous_brush_(NULL), | 105 previous_brush_(NULL), |
106 previous_pen_(NULL) { | 106 previous_pen_(NULL) { |
107 transform_.reset(); | 107 transform_.reset(); |
108 SetPlatformDevice(this, this); | 108 SetPlatformDevice(this, this); |
109 } | 109 } |
110 | 110 |
111 VectorPlatformDeviceEmf::~VectorPlatformDeviceEmf() { | 111 VectorPlatformDeviceEmf::~VectorPlatformDeviceEmf() { |
112 SkASSERT(previous_brush_ == NULL); | 112 SkASSERT(previous_brush_ == NULL); |
113 SkASSERT(previous_pen_ == NULL); | 113 SkASSERT(previous_pen_ == NULL); |
114 } | 114 } |
115 | 115 |
116 HDC VectorPlatformDeviceEmf::BeginPlatformPaint() { | 116 HDC VectorPlatformDeviceEmf::BeginPlatformPaint() { |
117 return hdc_; | 117 return hdc_; |
118 } | 118 } |
119 | 119 |
120 uint32_t VectorPlatformDeviceEmf::getDeviceCapabilities() { | 120 uint32_t VectorPlatformDeviceEmf::getDeviceCapabilities() { |
121 return SkDevice::getDeviceCapabilities() | kVector_Capability; | 121 return SkBitmapDevice::getDeviceCapabilities() | kVector_Capability; |
122 } | 122 } |
123 | 123 |
124 void VectorPlatformDeviceEmf::drawPaint(const SkDraw& draw, | 124 void VectorPlatformDeviceEmf::drawPaint(const SkDraw& draw, |
125 const SkPaint& paint) { | 125 const SkPaint& paint) { |
126 // TODO(maruel): Bypass the current transformation matrix. | 126 // TODO(maruel): Bypass the current transformation matrix. |
127 SkRect rect; | 127 SkRect rect; |
128 rect.fLeft = 0; | 128 rect.fLeft = 0; |
129 rect.fTop = 0; | 129 rect.fTop = 0; |
130 rect.fRight = SkIntToScalar(width() + 1); | 130 rect.fRight = SkIntToScalar(width() + 1); |
131 rect.fBottom = SkIntToScalar(height() + 1); | 131 rect.fBottom = SkIntToScalar(height() + 1); |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 const SkColor colors[], | 579 const SkColor colors[], |
580 SkXfermode* xmode, | 580 SkXfermode* xmode, |
581 const uint16_t indices[], | 581 const uint16_t indices[], |
582 int indexCount, | 582 int indexCount, |
583 const SkPaint& paint) { | 583 const SkPaint& paint) { |
584 // This function isn't used in the code. Verify this assumption. | 584 // This function isn't used in the code. Verify this assumption. |
585 SkASSERT(false); | 585 SkASSERT(false); |
586 } | 586 } |
587 | 587 |
588 void VectorPlatformDeviceEmf::drawDevice(const SkDraw& draw, | 588 void VectorPlatformDeviceEmf::drawDevice(const SkDraw& draw, |
589 SkDevice* device, | 589 SkBaseDevice* device, |
590 int x, | 590 int x, |
591 int y, | 591 int y, |
592 const SkPaint& paint) { | 592 const SkPaint& paint) { |
593 // TODO(maruel): http://b/1183870 Playback the EMF buffer at printer's dpi if | 593 // TODO(maruel): http://b/1183870 Playback the EMF buffer at printer's dpi if |
594 // it is a vectorial device. | 594 // it is a vectorial device. |
595 drawSprite(draw, device->accessBitmap(false), x, y, paint); | 595 drawSprite(draw, device->accessBitmap(false), x, y, paint); |
596 } | 596 } |
597 | 597 |
598 bool VectorPlatformDeviceEmf::ApplyPaint(const SkPaint& paint) { | 598 bool VectorPlatformDeviceEmf::ApplyPaint(const SkPaint& paint) { |
599 // Note: The goal here is to transfert the SkPaint's state to the HDC's state. | 599 // Note: The goal here is to transfert the SkPaint's state to the HDC's state. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 const RECT* src_rect) { | 686 const RECT* src_rect) { |
687 SkASSERT(false); | 687 SkASSERT(false); |
688 } | 688 } |
689 | 689 |
690 void VectorPlatformDeviceEmf::LoadClipRegion() { | 690 void VectorPlatformDeviceEmf::LoadClipRegion() { |
691 SkMatrix t; | 691 SkMatrix t; |
692 t.reset(); | 692 t.reset(); |
693 LoadClippingRegionToDC(hdc_, clip_region_, t); | 693 LoadClippingRegionToDC(hdc_, clip_region_, t); |
694 } | 694 } |
695 | 695 |
696 SkDevice* VectorPlatformDeviceEmf::onCreateCompatibleDevice( | 696 SkBaseDevice* VectorPlatformDeviceEmf::onCreateCompatibleDevice( |
697 SkBitmap::Config config, int width, int height, bool isOpaque, | 697 SkBitmap::Config config, int width, int height, bool isOpaque, |
698 Usage /*usage*/) { | 698 Usage /*usage*/) { |
699 SkASSERT(config == SkBitmap::kARGB_8888_Config); | 699 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
700 return VectorPlatformDeviceEmf::CreateDevice(width, height, isOpaque, NULL); | 700 return VectorPlatformDeviceEmf::CreateDevice(width, height, isOpaque, NULL); |
701 } | 701 } |
702 | 702 |
703 bool VectorPlatformDeviceEmf::CreateBrush(bool use_brush, COLORREF color) { | 703 bool VectorPlatformDeviceEmf::CreateBrush(bool use_brush, COLORREF color) { |
704 SkASSERT(previous_brush_ == NULL); | 704 SkASSERT(previous_brush_ == NULL); |
705 // We can't use SetDCBrushColor() or DC_BRUSH when drawing to a EMF buffer. | 705 // We can't use SetDCBrushColor() or DC_BRUSH when drawing to a EMF buffer. |
706 // SetDCBrushColor() calls are not recorded at all and DC_BRUSH will use | 706 // SetDCBrushColor() calls are not recorded at all and DC_BRUSH will use |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 pixels, | 978 pixels, |
979 reinterpret_cast<const BITMAPINFO*>(&hdr), | 979 reinterpret_cast<const BITMAPINFO*>(&hdr), |
980 DIB_RGB_COLORS, | 980 DIB_RGB_COLORS, |
981 SRCCOPY); | 981 SRCCOPY); |
982 } | 982 } |
983 EndPlatformPaint(); | 983 EndPlatformPaint(); |
984 Cleanup(); | 984 Cleanup(); |
985 } | 985 } |
986 | 986 |
987 } // namespace skia | 987 } // namespace skia |
OLD | NEW |