blob: c9165ebc4894dd4ba4191241c55662d6926ccc1d [file] [log] [blame]
license.botf003cfe2008-08-24 09:55:55 +09001// 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.commit3f4a7322008-07-27 06:49:38 +09004
5#include "base/gfx/vector_canvas.h"
6
7#include "base/gfx/vector_device.h"
8#include "base/logging.h"
9
10namespace gfx {
11
12VectorCanvas::VectorCanvas() {
13}
14
15VectorCanvas::VectorCanvas(HDC dc, int width, int height) {
16 initialize(dc, width, height);
17}
18
19VectorCanvas::~VectorCanvas() {
20}
21
22void 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
28SkBounder* VectorCanvas::setBounder(SkBounder* bounder) {
29 if (!IsTopDeviceVectorial())
awalker@google.combce88e12008-08-15 02:47:00 +090030 return PlatformCanvasWin::setBounder(bounder);
initial.commit3f4a7322008-07-27 06:49:38 +090031
32 // This function isn't used in the code. Verify this assumption.
33 NOTREACHED();
34 return NULL;
35}
36
37SkDevice* 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
44SkDrawFilter* VectorCanvas::setDrawFilter(SkDrawFilter* filter) {
45 // This function isn't used in the code. Verify this assumption.
46 NOTREACHED();
47 return NULL;
48}
49
50SkDevice* 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.combce88e12008-08-15 02:47:00 +090057 // BitmapPlatformDeviceWin is created when VectorCanvas think a saveLayers()
initial.commit3f4a7322008-07-27 06:49:38 +090058 // 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.combce88e12008-08-15 02:47:00 +090062 return PlatformCanvasWin::createPlatformDevice(width, height, is_opaque,
initial.commit3f4a7322008-07-27 06:49:38 +090063 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.combce88e12008-08-15 02:47:00 +090075 PlatformDeviceWin* device = VectorDevice::create(
initial.commit3f4a7322008-07-27 06:49:38 +090076 reinterpret_cast<HDC>(shared_section), width, height);
77 return device;
78}
79
80bool VectorCanvas::IsTopDeviceVectorial() const {
81 return getTopPlatformDevice().IsVectorial();
82}
83
84} // namespace gfx
license.botf003cfe2008-08-24 09:55:55 +090085