OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/gfx/vector_canvas.h" | |
6 | |
7 #include "base/gfx/vector_device.h" | |
8 #include "base/logging.h" | |
9 | |
10 namespace gfx { | |
11 | |
12 VectorCanvas::VectorCanvas() { | |
13 } | |
14 | |
15 VectorCanvas::VectorCanvas(HDC dc, int width, int height) { | |
16 bool initialized = initialize(dc, width, height); | |
17 CHECK(initialized); | |
18 } | |
19 | |
20 VectorCanvas::~VectorCanvas() { | |
21 } | |
22 | |
23 bool VectorCanvas::initialize(HDC context, int width, int height) { | |
24 SkDevice* device = createPlatformDevice(width, height, true, context); | |
25 if (!device) | |
26 return false; | |
27 | |
28 setDevice(device); | |
29 device->unref(); // was created with refcount 1, and setDevice also refs | |
30 return true; | |
31 } | |
32 | |
33 SkBounder* VectorCanvas::setBounder(SkBounder* bounder) { | |
34 if (!IsTopDeviceVectorial()) | |
35 return PlatformCanvasWin::setBounder(bounder); | |
36 | |
37 // This function isn't used in the code. Verify this assumption. | |
38 NOTREACHED(); | |
39 return NULL; | |
40 } | |
41 | |
42 SkDevice* VectorCanvas::createDevice(SkBitmap::Config config, | |
43 int width, int height, | |
44 bool is_opaque, bool isForLayer) { | |
45 DCHECK(config == SkBitmap::kARGB_8888_Config); | |
46 return createPlatformDevice(width, height, is_opaque, NULL); | |
47 } | |
48 | |
49 SkDrawFilter* VectorCanvas::setDrawFilter(SkDrawFilter* filter) { | |
50 // This function isn't used in the code. Verify this assumption. | |
51 NOTREACHED(); | |
52 return NULL; | |
53 } | |
54 | |
55 SkDevice* VectorCanvas::createPlatformDevice(int width, | |
56 int height, bool is_opaque, | |
57 HANDLE shared_section) { | |
58 if (!is_opaque) { | |
59 // TODO(maruel): http://b/1184002 1184002 When restoring a semi-transparent | |
60 // layer, i.e. merging it, we need to rasterize it because GDI doesn't | |
61 // support transparency except for AlphaBlend(). Right now, a | |
62 // BitmapPlatformDeviceWin is created when VectorCanvas think a saveLayers() | |
63 // call is being done. The way to save a layer would be to create an | |
64 // EMF-based VectorDevice and have this device registers the drawing. When | |
65 // playing back the device into a bitmap, do it at the printer's dpi instead | |
66 // of the layout's dpi (which is much lower). | |
67 return PlatformCanvasWin::createPlatformDevice(width, height, is_opaque, | |
68 shared_section); | |
69 } | |
70 | |
71 // TODO(maruel): http://b/1183870 Look if it would be worth to increase the | |
72 // resolution by ~10x (any worthy factor) to increase the rendering precision | |
73 // (think about printing) while using a relatively low dpi. This happens | |
74 // because we receive float as input but the GDI functions works with | |
75 // integers. The idea is to premultiply the matrix with this factor and | |
76 // multiply each SkScalar that are passed to SkScalarRound(value) as | |
77 // SkScalarRound(value * 10). Safari is already doing the same for text | |
78 // rendering. | |
79 DCHECK(shared_section); | |
80 PlatformDeviceWin* device = VectorDevice::create( | |
81 reinterpret_cast<HDC>(shared_section), width, height); | |
82 return device; | |
83 } | |
84 | |
85 bool VectorCanvas::IsTopDeviceVectorial() const { | |
86 return getTopPlatformDevice().IsVectorial(); | |
87 } | |
88 | |
89 } // namespace gfx | |
90 | |
OLD | NEW |