license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 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. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 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 | initialize(dc, width, height); |
| 17 | } |
| 18 | |
| 19 | VectorCanvas::~VectorCanvas() { |
| 20 | } |
| 21 | |
| 22 | void VectorCanvas::initialize(HDC context, int width, int height) { |
| 23 | SkDevice* device = createPlatformDevice(width, height, true, context); |
| 24 | setDevice(device); |
| 25 | device->unref(); // was created with refcount 1, and setDevice also refs |
| 26 | } |
| 27 | |
| 28 | SkBounder* VectorCanvas::setBounder(SkBounder* bounder) { |
| 29 | if (!IsTopDeviceVectorial()) |
awalker@google.com | bce88e1 | 2008-08-15 02:47:00 +0900 | [diff] [blame] | 30 | return PlatformCanvasWin::setBounder(bounder); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 31 | |
| 32 | // This function isn't used in the code. Verify this assumption. |
| 33 | NOTREACHED(); |
| 34 | return NULL; |
| 35 | } |
| 36 | |
| 37 | SkDevice* VectorCanvas::createDevice(SkBitmap::Config config, |
| 38 | int width, int height, |
| 39 | bool is_opaque, bool isForLayer) { |
| 40 | DCHECK(config == SkBitmap::kARGB_8888_Config); |
| 41 | return createPlatformDevice(width, height, is_opaque, NULL); |
| 42 | } |
| 43 | |
| 44 | SkDrawFilter* VectorCanvas::setDrawFilter(SkDrawFilter* filter) { |
| 45 | // This function isn't used in the code. Verify this assumption. |
| 46 | NOTREACHED(); |
| 47 | return NULL; |
| 48 | } |
| 49 | |
| 50 | SkDevice* VectorCanvas::createPlatformDevice(int width, |
| 51 | int height, bool is_opaque, |
| 52 | HANDLE shared_section) { |
| 53 | if (!is_opaque) { |
| 54 | // TODO(maruel): http://b/1184002 1184002 When restoring a semi-transparent |
| 55 | // layer, i.e. merging it, we need to rasterize it because GDI doesn't |
| 56 | // support transparency except for AlphaBlend(). Right now, a |
awalker@google.com | bce88e1 | 2008-08-15 02:47:00 +0900 | [diff] [blame] | 57 | // BitmapPlatformDeviceWin is created when VectorCanvas think a saveLayers() |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 58 | // call is being done. The way to save a layer would be to create an |
| 59 | // EMF-based VectorDevice and have this device registers the drawing. When |
| 60 | // playing back the device into a bitmap, do it at the printer's dpi instead |
| 61 | // of the layout's dpi (which is much lower). |
awalker@google.com | bce88e1 | 2008-08-15 02:47:00 +0900 | [diff] [blame] | 62 | return PlatformCanvasWin::createPlatformDevice(width, height, is_opaque, |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 63 | shared_section); |
| 64 | } |
| 65 | |
| 66 | // TODO(maruel): http://b/1183870 Look if it would be worth to increase the |
| 67 | // resolution by ~10x (any worthy factor) to increase the rendering precision |
| 68 | // (think about printing) while using a relatively low dpi. This happens |
| 69 | // because we receive float as input but the GDI functions works with |
| 70 | // integers. The idea is to premultiply the matrix with this factor and |
| 71 | // multiply each SkScalar that are passed to SkScalarRound(value) as |
| 72 | // SkScalarRound(value * 10). Safari is already doing the same for text |
| 73 | // rendering. |
| 74 | DCHECK(shared_section); |
awalker@google.com | bce88e1 | 2008-08-15 02:47:00 +0900 | [diff] [blame] | 75 | PlatformDeviceWin* device = VectorDevice::create( |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 76 | reinterpret_cast<HDC>(shared_section), width, height); |
| 77 | return device; |
| 78 | } |
| 79 | |
| 80 | bool VectorCanvas::IsTopDeviceVectorial() const { |
| 81 | return getTopPlatformDevice().IsVectorial(); |
| 82 | } |
| 83 | |
| 84 | } // namespace gfx |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 85 | |