1 /* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
2 /* Cairo - a vector graphics library with display and print output
4 * Copyright © 2005 Red Hat, Inc.
5 * Copyright © 2012 Intel Corporation
7 * This library is free software; you can redistribute it and/or
8 * modify it either under the terms of the GNU Lesser General Public
9 * License version 2.1 as published by the Free Software Foundation
10 * (the "LGPL") or, at your option, under the terms of the Mozilla
11 * Public License Version 1.1 (the "MPL"). If you do not alter this
12 * notice, a recipient may use your version of this file under either
13 * the MPL or the LGPL.
15 * You should have received a copy of the LGPL along with this library
16 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
18 * You should have received a copy of the MPL along with this library
19 * in the file COPYING-MPL-1.1
21 * The contents of this file are subject to the Mozilla Public License
22 * Version 1.1 (the "License"); you may not use this file except in
23 * compliance with the License. You may obtain a copy of the License at
24 * http://www.mozilla.org/MPL/
26 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
27 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
28 * the specific language governing rights and limitations.
30 * The Original Code is the cairo graphics library.
32 * The Initial Developer of the Original Code is Red Hat, Inc.
35 * Owen Taylor <otaylor@redhat.com>
36 * Stuart Parmenter <stuart@mozilla.com>
37 * Vladimir Vukicevic <vladimir@pobox.com>
40 #define WIN32_LEAN_AND_MEAN
41 /* We require Windows 2000 features such as ETO_PDY */
42 #if !defined(WINVER) || (WINVER < 0x0500)
43 # define WINVER 0x0500
45 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
46 # define _WIN32_WINNT 0x0500
51 #include "cairo-atomic-private.h"
52 #include "cairo-device-private.h"
53 #include "cairo-win32-private.h"
58 static cairo_device_t *__cairo_win32_device;
61 _cairo_win32_device_flush (void *device)
64 return CAIRO_STATUS_SUCCESS;
68 _cairo_win32_device_finish (void *device)
73 _cairo_win32_device_destroy (void *device)
78 static const cairo_device_backend_t _cairo_win32_device_backend = {
79 CAIRO_DEVICE_TYPE_WIN32,
81 NULL, NULL, /* lock, unlock */
83 _cairo_win32_device_flush,
84 _cairo_win32_device_finish,
85 _cairo_win32_device_destroy,
89 D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(D2D1_RENDER_TARGET_TYPE_DEFAULT,
91 DXGI_FORMAT_B8G8R8A8_UNORM,
92 D2D1_ALPHA_MODE_IGNORE),
95 D2D1_RENDER_TARGET_USAGE_NONE,
96 D2D1_FEATURE_LEVEL_DEFAULT
99 hr = m_pD2DFactory->CreateDCRenderTarget(&props, &device->d2d);
102 static cairo_bool_t is_win98 (void)
106 os.dwOSVersionInfoSize = sizeof (os);
109 return (VER_PLATFORM_WIN32_WINDOWS != os.dwPlatformId &&
110 os.dwMajorVersion != 4 &&
111 os.dwMinorVersion != 10);
115 _cairo_win32_device_get_alpha_blend (cairo_win32_device_t *device)
122 device->msimg32_dll = LoadLibraryW (L"msimg32");
123 if (device->msimg32_dll)
124 func = GetProcAddress (device->msimg32_dll, "AlphaBlend");
130 _cairo_win32_device_get (void)
132 cairo_win32_device_t *device;
134 if (__cairo_win32_device)
135 return cairo_device_reference (__cairo_win32_device);
137 device = malloc (sizeof (*device));
139 _cairo_device_init (&device->base, &_cairo_win32_device_backend);
141 device->compositor = _cairo_win32_gdi_compositor_get ();
143 device->msimg32_dll = NULL;
144 device->alpha_blend = _cairo_win32_device_get_alpha_blend (device);
146 if (_cairo_atomic_ptr_cmpxchg ((void **)&__cairo_win32_device, NULL, device))
147 return cairo_device_reference(&device->base);
149 _cairo_win32_device_destroy (device);
150 return cairo_device_reference (__cairo_win32_device);
154 _cairo_win32_flags_for_dc (HDC dc)
159 cap = GetDeviceCaps(dc, RASTERCAPS);
161 flags |= CAIRO_WIN32_SURFACE_CAN_BITBLT;
162 if (cap & RC_STRETCHBLT)
163 flags |= CAIRO_WIN32_SURFACE_CAN_STRETCHBLT;
164 if (cap & RC_STRETCHDIB)
165 flags |= CAIRO_WIN32_SURFACE_CAN_STRETCHDIB;
167 if (GetDeviceCaps(dc, TECHNOLOGY) == DT_RASDISPLAY) {
168 flags |= CAIRO_WIN32_SURFACE_IS_DISPLAY;
170 /* These will always be possible, but the actual GetDeviceCaps
171 * calls will return whether they're accelerated or not.
172 * We may want to use our own (pixman) routines sometimes
173 * if they're eventually faster, but for now have GDI do
177 flags |= CAIRO_WIN32_SURFACE_CAN_BITBLT;
178 flags |= CAIRO_WIN32_SURFACE_CAN_ALPHABLEND;
179 flags |= CAIRO_WIN32_SURFACE_CAN_STRETCHBLT;
180 flags |= CAIRO_WIN32_SURFACE_CAN_STRETCHDIB;
183 cap = GetDeviceCaps(dc, SHADEBLENDCAPS);
185 flags |= CAIRO_WIN32_SURFACE_CAN_ALPHABLEND;