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/SkUtils.h" | 11 #include "third_party/skia/include/core/SkUtils.h" |
12 | 12 |
13 namespace skia { | 13 namespace skia { |
14 | 14 |
| 15 SkDevice* VectorPlatformDeviceEmfFactory::newDevice(SkCanvas* unused, |
| 16 SkBitmap::Config config, |
| 17 int width, int height, |
| 18 bool isOpaque, |
| 19 bool isForLayer) { |
| 20 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
| 21 return CreateDevice(width, height, isOpaque, NULL); |
| 22 } |
| 23 |
15 //static | 24 //static |
16 PlatformDevice* VectorPlatformDeviceEmf::CreateDevice(int width, int height, | 25 PlatformDevice* VectorPlatformDeviceEmfFactory::CreateDevice( |
17 bool is_opaque, | 26 int width, int height, bool is_opaque, HANDLE shared_section) { |
18 HANDLE shared_section) { | |
19 if (!is_opaque) { | 27 if (!is_opaque) { |
20 // TODO(maruel): http://crbug.com/18382 When restoring a semi-transparent | 28 // TODO(maruel): http://crbug.com/18382 When restoring a semi-transparent |
21 // 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 |
22 // support transparency except for AlphaBlend(). Right now, a | 30 // support transparency except for AlphaBlend(). Right now, a |
23 // BitmapPlatformDevice is created when VectorCanvas think a saveLayers() | 31 // BitmapPlatformDevice is created when VectorCanvas think a saveLayers() |
24 // 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 |
25 // EMF-based VectorDevice and have this device registers the drawing. When | 33 // EMF-based VectorDevice and have this device registers the drawing. When |
26 // 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 |
27 // of the layout's dpi (which is much lower). | 35 // of the layout's dpi (which is much lower). |
28 return BitmapPlatformDevice::create(width, height, is_opaque, | 36 return BitmapPlatformDevice::create(width, height, is_opaque, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 previous_pen_(NULL), | 108 previous_pen_(NULL), |
101 alpha_blend_used_(false) { | 109 alpha_blend_used_(false) { |
102 transform_.reset(); | 110 transform_.reset(); |
103 } | 111 } |
104 | 112 |
105 VectorPlatformDeviceEmf::~VectorPlatformDeviceEmf() { | 113 VectorPlatformDeviceEmf::~VectorPlatformDeviceEmf() { |
106 SkASSERT(previous_brush_ == NULL); | 114 SkASSERT(previous_brush_ == NULL); |
107 SkASSERT(previous_pen_ == NULL); | 115 SkASSERT(previous_pen_ == NULL); |
108 } | 116 } |
109 | 117 |
| 118 SkDeviceFactory* VectorPlatformDeviceEmf::onNewDeviceFactory() { |
| 119 return SkNEW(VectorPlatformDeviceEmfFactory); |
| 120 } |
| 121 |
110 HDC VectorPlatformDeviceEmf::BeginPlatformPaint() { | 122 HDC VectorPlatformDeviceEmf::BeginPlatformPaint() { |
111 return hdc_; | 123 return hdc_; |
112 } | 124 } |
113 | 125 |
114 uint32_t VectorPlatformDeviceEmf::getDeviceCapabilities() { | 126 uint32_t VectorPlatformDeviceEmf::getDeviceCapabilities() { |
115 return SkDevice::getDeviceCapabilities() | kVector_Capability; | 127 return SkDevice::getDeviceCapabilities() | kVector_Capability; |
116 } | 128 } |
117 | 129 |
118 void VectorPlatformDeviceEmf::drawPaint(const SkDraw& draw, | 130 void VectorPlatformDeviceEmf::drawPaint(const SkDraw& draw, |
119 const SkPaint& paint) { | 131 const SkPaint& paint) { |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 const RECT* src_rect) { | 443 const RECT* src_rect) { |
432 SkASSERT(false); | 444 SkASSERT(false); |
433 } | 445 } |
434 | 446 |
435 void VectorPlatformDeviceEmf::LoadClipRegion() { | 447 void VectorPlatformDeviceEmf::LoadClipRegion() { |
436 SkMatrix t; | 448 SkMatrix t; |
437 t.reset(); | 449 t.reset(); |
438 LoadClippingRegionToDC(hdc_, clip_region_, t); | 450 LoadClippingRegionToDC(hdc_, clip_region_, t); |
439 } | 451 } |
440 | 452 |
441 SkDevice* VectorPlatformDeviceEmf::onCreateCompatibleDevice( | |
442 SkBitmap::Config config, int width, int height, bool isOpaque, | |
443 Usage /*usage*/) { | |
444 SkASSERT(config == SkBitmap::kARGB_8888_Config); | |
445 return VectorPlatformDeviceEmf::CreateDevice(width, height, isOpaque, NULL); | |
446 } | |
447 | |
448 bool VectorPlatformDeviceEmf::CreateBrush(bool use_brush, COLORREF color) { | 453 bool VectorPlatformDeviceEmf::CreateBrush(bool use_brush, COLORREF color) { |
449 SkASSERT(previous_brush_ == NULL); | 454 SkASSERT(previous_brush_ == NULL); |
450 // We can't use SetDCBrushColor() or DC_BRUSH when drawing to a EMF buffer. | 455 // We can't use SetDCBrushColor() or DC_BRUSH when drawing to a EMF buffer. |
451 // SetDCBrushColor() calls are not recorded at all and DC_BRUSH will use | 456 // SetDCBrushColor() calls are not recorded at all and DC_BRUSH will use |
452 // WHITE_BRUSH instead. | 457 // WHITE_BRUSH instead. |
453 | 458 |
454 if (!use_brush) { | 459 if (!use_brush) { |
455 // Set the transparency. | 460 // Set the transparency. |
456 if (0 == SetBkMode(hdc_, TRANSPARENT)) { | 461 if (0 == SetBkMode(hdc_, TRANSPARENT)) { |
457 SkASSERT(false); | 462 SkASSERT(false); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 DIB_RGB_COLORS, | 732 DIB_RGB_COLORS, |
728 SRCCOPY); | 733 SRCCOPY); |
729 SkASSERT(result); | 734 SkASSERT(result); |
730 } | 735 } |
731 EndPlatformPaint(); | 736 EndPlatformPaint(); |
732 Cleanup(); | 737 Cleanup(); |
733 } | 738 } |
734 | 739 |
735 } // namespace skia | 740 } // namespace skia |
736 | 741 |
OLD | NEW |