OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_win.h" | 7 #include "skia/ext/vector_platform_device_win.h" |
8 | 8 |
| 9 #include "skia/ext/bitmap_platform_device.h" |
9 #include "skia/ext/skia_utils_win.h" | 10 #include "skia/ext/skia_utils_win.h" |
10 #include "third_party/skia/include/core/SkUtils.h" | 11 #include "third_party/skia/include/core/SkUtils.h" |
11 | 12 |
12 namespace skia { | 13 namespace skia { |
13 | 14 |
| 15 SkDevice* SkVectorPlatformDeviceFactory::newDevice(SkBitmap::Config config, |
| 16 int width, int height, |
| 17 bool isOpaque, |
| 18 bool isForLayer) { |
| 19 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
| 20 return CreateDevice(width, height, isOpaque, NULL); |
| 21 } |
| 22 |
| 23 //static |
| 24 SkDevice* SkVectorPlatformDeviceFactory::CreateDevice(int width, int height, |
| 25 bool is_opaque, |
| 26 HANDLE shared_section) { |
| 27 if (!is_opaque) { |
| 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 |
| 30 // support transparency except for AlphaBlend(). Right now, a |
| 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 |
| 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 |
| 35 // of the layout's dpi (which is much lower). |
| 36 return BitmapPlatformDevice::create(width, height, |
| 37 is_opaque, shared_section); |
| 38 } |
| 39 |
| 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 |
| 42 // rendering precision (think about printing) while using a relatively |
| 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 |
| 45 // with this factor and multiply each SkScalar that are passed to |
| 46 // SkScalarRound(value) as SkScalarRound(value * 10). Safari is already |
| 47 // doing the same for text rendering. |
| 48 SkASSERT(shared_section); |
| 49 PlatformDevice* device = VectorPlatformDevice::create( |
| 50 reinterpret_cast<HDC>(shared_section), width, height); |
| 51 return device; |
| 52 } |
| 53 |
14 static void FillBitmapInfoHeader(int width, int height, BITMAPINFOHEADER* hdr) { | 54 static void FillBitmapInfoHeader(int width, int height, BITMAPINFOHEADER* hdr) { |
15 hdr->biSize = sizeof(BITMAPINFOHEADER); | 55 hdr->biSize = sizeof(BITMAPINFOHEADER); |
16 hdr->biWidth = width; | 56 hdr->biWidth = width; |
17 hdr->biHeight = -height; // Minus means top-down bitmap. | 57 hdr->biHeight = -height; // Minus means top-down bitmap. |
18 hdr->biPlanes = 1; | 58 hdr->biPlanes = 1; |
19 hdr->biBitCount = 32; | 59 hdr->biBitCount = 32; |
20 hdr->biCompression = BI_RGB; // no compression | 60 hdr->biCompression = BI_RGB; // no compression |
21 hdr->biSizeImage = 0; | 61 hdr->biSizeImage = 0; |
22 hdr->biXPelsPerMeter = 1; | 62 hdr->biXPelsPerMeter = 1; |
23 hdr->biYPelsPerMeter = 1; | 63 hdr->biYPelsPerMeter = 1; |
(...skipping 643 matching lines...) Loading... |
667 reinterpret_cast<const BITMAPINFO*>(&hdr), | 707 reinterpret_cast<const BITMAPINFO*>(&hdr), |
668 DIB_RGB_COLORS, | 708 DIB_RGB_COLORS, |
669 SRCCOPY); | 709 SRCCOPY); |
670 SkASSERT(result); | 710 SkASSERT(result); |
671 } | 711 } |
672 Cleanup(); | 712 Cleanup(); |
673 } | 713 } |
674 | 714 |
675 } // namespace skia | 715 } // namespace skia |
676 | 716 |
OLD | NEW |