Add new direct2d platform plugin
This is an alternative plugin for the windows platform. It shares most code with the current windows plugin, but substitutes a direct2d-based paint engine for window backing stores and pixmaps. Change-Id: I78fafd9c5871fa090b49436f5b40ec80f8789f8b Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>bb10
parent
5a2fc4c367
commit
b9362903b3
|
|
@ -0,0 +1,57 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the config.tests of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <d3d11_1.h>
|
||||
#include <d2d1_1.h>
|
||||
#include <d2d1_1helper.h>
|
||||
#include <dxgi1_2.h>
|
||||
#include <wrl.h>
|
||||
#include <dwrite.h>
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
ComPtr<ID2D1Factory1> d2dFactory;
|
||||
D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, d2dFactory.ReleaseAndGetAddressOf());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
SOURCES = direct2d.cpp
|
||||
LIBS += -ld2d1 -ldwrite -ld3d11
|
||||
CONFIG -= qt
|
||||
CONFIG += console
|
||||
|
|
@ -69,7 +69,8 @@ public:
|
|||
};
|
||||
|
||||
enum ClassId { RasterClass, DirectFBClass,
|
||||
BlitterClass, CustomClass = 1024 };
|
||||
BlitterClass, Direct2DClass,
|
||||
CustomClass = 1024 };
|
||||
|
||||
QPlatformPixmap(PixelType pixelType, int classId);
|
||||
virtual ~QPlatformPixmap();
|
||||
|
|
|
|||
|
|
@ -387,6 +387,7 @@ void QPaintEngine::drawPolygon(const QPoint *points, int pointCount, PolygonDraw
|
|||
\value OpenGL2
|
||||
\value PaintBuffer
|
||||
\value Blitter
|
||||
\value Direct2D Windows only, Direct2D based engine
|
||||
*/
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -207,6 +207,7 @@ public:
|
|||
OpenGL2,
|
||||
PaintBuffer,
|
||||
Blitter,
|
||||
Direct2D,
|
||||
|
||||
User = 50, // first user type id
|
||||
MaxUser = 100 // last user type id
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"Keys": [ "direct2d" ]
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
TARGET = qdirect2d
|
||||
|
||||
PLUGIN_TYPE = platforms
|
||||
PLUGIN_CLASS_NAME = QWindowsDirect2DIntegrationPlugin
|
||||
load(qt_plugin)
|
||||
|
||||
QT *= core-private
|
||||
QT *= gui-private
|
||||
QT *= platformsupport-private
|
||||
|
||||
LIBS *= -ld2d1 -ld3d11 -ldwrite
|
||||
|
||||
include(../windows/windows.pri)
|
||||
|
||||
SOURCES += \
|
||||
qwindowsdirect2dpaintengine.cpp \
|
||||
qwindowsdirect2dpaintdevice.cpp \
|
||||
qwindowsdirect2dplatformpixmap.cpp \
|
||||
qwindowsdirect2dcontext.cpp \
|
||||
qwindowsdirect2dbitmap.cpp \
|
||||
qwindowsdirect2dbackingstore.cpp \
|
||||
qwindowsdirect2dintegration.cpp \
|
||||
qwindowsdirect2dplatformplugin.cpp \
|
||||
qwindowsdirect2ddevicecontext.cpp \
|
||||
qwindowsdirect2dnativeinterface.cpp
|
||||
|
||||
HEADERS += \
|
||||
qwindowsdirect2dpaintengine.h \
|
||||
qwindowsdirect2dpaintdevice.h \
|
||||
qwindowsdirect2dplatformpixmap.h \
|
||||
qwindowsdirect2dcontext.h \
|
||||
qwindowsdirect2dhelpers.h \
|
||||
qwindowsdirect2dbitmap.h \
|
||||
qwindowsdirect2dbackingstore.h \
|
||||
qwindowsdirect2dintegration.h \
|
||||
qwindowsdirect2ddevicecontext.h \
|
||||
qwindowsdirect2dnativeinterface.h
|
||||
|
||||
OTHER_FILES += direct2d.json
|
||||
|
|
@ -0,0 +1,239 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qwindowsdirect2dbackingstore.h"
|
||||
#include "qwindowsdirect2dintegration.h"
|
||||
#include "qwindowsdirect2dcontext.h"
|
||||
#include "qwindowsdirect2dpaintdevice.h"
|
||||
#include "qwindowsdirect2dbitmap.h"
|
||||
#include "qwindowsdirect2ddevicecontext.h"
|
||||
|
||||
#include "qwindowswindow.h"
|
||||
#include "qwindowscontext.h"
|
||||
|
||||
#include <QtGui/QWindow>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
#include <dxgi1_2.h>
|
||||
#include <d3d11.h>
|
||||
#include <wrl.h>
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowsDirect2DBackingStorePrivate
|
||||
{
|
||||
public:
|
||||
QWindowsDirect2DBackingStorePrivate() {}
|
||||
|
||||
ComPtr<IDXGISwapChain1> swapChain;
|
||||
QSharedPointer<QWindowsDirect2DBitmap> backingStore;
|
||||
QScopedPointer<QWindowsDirect2DPaintDevice> nativePaintDevice;
|
||||
|
||||
bool init(HWND hwnd)
|
||||
{
|
||||
DXGI_SWAP_CHAIN_DESC1 desc = {};
|
||||
|
||||
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
desc.BufferCount = 1;
|
||||
desc.SwapEffect = DXGI_SWAP_EFFECT_SEQUENTIAL;
|
||||
|
||||
HRESULT hr = QWindowsDirect2DContext::instance()->dxgiFactory()->CreateSwapChainForHwnd(
|
||||
QWindowsDirect2DContext::instance()->d3dDevice(), // [in] IUnknown *pDevice
|
||||
hwnd, // [in] HWND hWnd
|
||||
&desc, // [in] const DXGI_SWAP_CHAIN_DESC1 *pDesc
|
||||
NULL, // [in] const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *pFullscreenDesc
|
||||
NULL, // [in] IDXGIOutput *pRestrictToOutput
|
||||
swapChain.ReleaseAndGetAddressOf()); // [out] IDXGISwapChain1 **ppSwapChain
|
||||
|
||||
if (FAILED(hr))
|
||||
qWarning("%s: Could not create swap chain: %#x", __FUNCTION__, hr);
|
||||
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
bool setupPaintDevice()
|
||||
{
|
||||
if (!backingStore) {
|
||||
ComPtr<ID2D1DeviceContext> deviceContext;
|
||||
ComPtr<IDXGISurface1> backBufferSurface;
|
||||
ComPtr<ID2D1Bitmap1> backBufferBitmap;
|
||||
|
||||
HRESULT hr = QWindowsDirect2DContext::instance()->d2dDevice()->CreateDeviceContext(
|
||||
D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
|
||||
deviceContext.ReleaseAndGetAddressOf());
|
||||
if (FAILED(hr)) {
|
||||
qWarning("%s: Couldn't create Direct2D Device context: %#x", __FUNCTION__, hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = swapChain->GetBuffer(0, IID_PPV_ARGS(&backBufferSurface));
|
||||
if (FAILED(hr)) {
|
||||
qWarning("%s: Could not query backbuffer for DXGI Surface: %#x", __FUNCTION__, hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = deviceContext->CreateBitmapFromDxgiSurface(backBufferSurface.Get(), NULL, backBufferBitmap.ReleaseAndGetAddressOf());
|
||||
if (FAILED(hr)) {
|
||||
qWarning("%s: Could not create Direct2D Bitmap from DXGI Surface: %#x", __FUNCTION__, hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
backingStore.reset(new QWindowsDirect2DBitmap(backBufferBitmap.Get(), deviceContext.Get()));
|
||||
}
|
||||
|
||||
if (!nativePaintDevice)
|
||||
nativePaintDevice.reset(new QWindowsDirect2DPaintDevice(backingStore.data(), QInternal::Widget));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void releaseBackingStore()
|
||||
{
|
||||
nativePaintDevice.reset();
|
||||
backingStore.reset();
|
||||
}
|
||||
|
||||
QPaintDevice *paintDevice()
|
||||
{
|
||||
setupPaintDevice();
|
||||
return nativePaintDevice.data();
|
||||
}
|
||||
|
||||
void flush()
|
||||
{
|
||||
swapChain->Present(1, 0);
|
||||
}
|
||||
};
|
||||
|
||||
/*!
|
||||
\class QWindowsDirect2DBackingStore
|
||||
\brief Backing store for windows.
|
||||
\internal
|
||||
\ingroup qt-lighthouse-win
|
||||
*/
|
||||
|
||||
QWindowsDirect2DBackingStore::QWindowsDirect2DBackingStore(QWindow *window)
|
||||
: QPlatformBackingStore(window)
|
||||
, d_ptr(new QWindowsDirect2DBackingStorePrivate)
|
||||
{
|
||||
}
|
||||
|
||||
bool QWindowsDirect2DBackingStore::init()
|
||||
{
|
||||
if (window()->surfaceType() == QSurface::RasterSurface) {
|
||||
Q_D(QWindowsDirect2DBackingStore);
|
||||
return d->init(windowsWindow()->handle());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QWindowsDirect2DBackingStore *QWindowsDirect2DBackingStore::create(QWindow *window)
|
||||
{
|
||||
QWindowsDirect2DBackingStore *result = new QWindowsDirect2DBackingStore(window);
|
||||
|
||||
if (!result->init()) {
|
||||
delete result;
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QWindowsDirect2DBackingStore::~QWindowsDirect2DBackingStore()
|
||||
{
|
||||
Q_D(QWindowsDirect2DBackingStore);
|
||||
d->releaseBackingStore();
|
||||
d->swapChain.Reset();
|
||||
}
|
||||
|
||||
QPaintDevice *QWindowsDirect2DBackingStore::paintDevice()
|
||||
{
|
||||
QPaintDevice *result = 0;
|
||||
|
||||
if (window()->surfaceType() == QSurface::RasterSurface) {
|
||||
Q_D(QWindowsDirect2DBackingStore);
|
||||
result = d->paintDevice();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void QWindowsDirect2DBackingStore::flush(QWindow *, const QRegion &, const QPoint &)
|
||||
{
|
||||
if (window()->surfaceType() == QSurface::RasterSurface) {
|
||||
Q_D(QWindowsDirect2DBackingStore);
|
||||
d->flush();
|
||||
}
|
||||
}
|
||||
|
||||
void QWindowsDirect2DBackingStore::resize(const QSize &size, const QRegion ®ion)
|
||||
{
|
||||
Q_UNUSED(region);
|
||||
|
||||
if (window()->surfaceType() != QSurface::RasterSurface)
|
||||
return;
|
||||
|
||||
Q_D(QWindowsDirect2DBackingStore);
|
||||
d->releaseBackingStore();
|
||||
QWindowsDirect2DContext::instance()->d3dDeviceContext()->ClearState();
|
||||
|
||||
HRESULT hr = d->swapChain->ResizeBuffers(0,
|
||||
size.width(), size.height(),
|
||||
DXGI_FORMAT_UNKNOWN,
|
||||
0);
|
||||
if (FAILED(hr))
|
||||
qWarning("%s: Could not resize buffers: %#x", __FUNCTION__, hr);
|
||||
}
|
||||
|
||||
QWindowsWindow *QWindowsDirect2DBackingStore::windowsWindow() const
|
||||
{
|
||||
if (const QWindow *w = window())
|
||||
if (QPlatformWindow *pw = w->handle())
|
||||
return static_cast<QWindowsWindow *>(pw);
|
||||
return 0;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QWINDOWSDIRECT2DBACKINGSTORE_H
|
||||
#define QWINDOWSDIRECT2DBACKINGSTORE_H
|
||||
|
||||
#include <QtCore/QScopedPointer>
|
||||
#include <QtGui/qpa/qplatformbackingstore.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowsWindow;
|
||||
class QWindowsDirect2DBackingStorePrivate;
|
||||
|
||||
class QWindowsDirect2DBackingStore : public QPlatformBackingStore
|
||||
{
|
||||
Q_DECLARE_PRIVATE(QWindowsDirect2DBackingStore)
|
||||
Q_DISABLE_COPY(QWindowsDirect2DBackingStore)
|
||||
|
||||
public:
|
||||
static QWindowsDirect2DBackingStore *create(QWindow *window);
|
||||
~QWindowsDirect2DBackingStore();
|
||||
|
||||
QPaintDevice *paintDevice() Q_DECL_OVERRIDE;
|
||||
void flush(QWindow *, const QRegion ®ion, const QPoint &offset) Q_DECL_OVERRIDE;
|
||||
void resize(const QSize &size, const QRegion &staticContents) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
QWindowsDirect2DBackingStore(QWindow *window);
|
||||
bool init();
|
||||
|
||||
QWindowsWindow *windowsWindow() const;
|
||||
QScopedPointer<QWindowsDirect2DBackingStorePrivate> d_ptr;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWINDOWSDIRECT2DBACKINGSTORE_H
|
||||
|
|
@ -0,0 +1,205 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qwindowsdirect2dbitmap.h"
|
||||
#include "qwindowsdirect2dcontext.h"
|
||||
#include "qwindowsdirect2dhelpers.h"
|
||||
#include "qwindowsdirect2ddevicecontext.h"
|
||||
|
||||
#include <QtGui/QImage>
|
||||
#include <QtGui/QColor>
|
||||
|
||||
#include <wrl.h>
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowsDirect2DBitmapPrivate
|
||||
{
|
||||
public:
|
||||
QWindowsDirect2DBitmapPrivate(ID2D1DeviceContext *dc = 0, ID2D1Bitmap1 *bm = 0)
|
||||
: bitmap(bm)
|
||||
, deviceContext(new QWindowsDirect2DDeviceContext(dc))
|
||||
{
|
||||
deviceContext->get()->SetTarget(bm);
|
||||
}
|
||||
|
||||
D2D1_BITMAP_PROPERTIES1 bitmapProperties() const
|
||||
{
|
||||
FLOAT dpiX, dpiY;
|
||||
QWindowsDirect2DContext::instance()->d2dFactory()->GetDesktopDpi(&dpiX, &dpiY);
|
||||
|
||||
return D2D1::BitmapProperties1(
|
||||
D2D1_BITMAP_OPTIONS_TARGET,
|
||||
D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM,
|
||||
D2D1_ALPHA_MODE_PREMULTIPLIED),
|
||||
dpiX, dpiY);
|
||||
|
||||
}
|
||||
|
||||
bool resize(int width, int height, const void *data = 0, int pitch = 0)
|
||||
{
|
||||
deviceContext->get()->SetTarget(0);
|
||||
bitmap.Reset();
|
||||
|
||||
D2D1_SIZE_U size = {
|
||||
width, height
|
||||
};
|
||||
|
||||
HRESULT hr = deviceContext->get()->CreateBitmap(size, data, pitch,
|
||||
bitmapProperties(),
|
||||
bitmap.ReleaseAndGetAddressOf());
|
||||
if (SUCCEEDED(hr))
|
||||
deviceContext->get()->SetTarget(bitmap.Get());
|
||||
else
|
||||
qWarning("%s: Could not create bitmap: %#x", __FUNCTION__, hr);
|
||||
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
QImage toImage(const QRect &rect)
|
||||
{
|
||||
if (!bitmap)
|
||||
return QImage();
|
||||
|
||||
ComPtr<ID2D1Bitmap1> mappingCopy;
|
||||
|
||||
HRESULT hr = S_OK;
|
||||
D2D1_SIZE_U size = bitmap->GetPixelSize();
|
||||
|
||||
D2D1_BITMAP_PROPERTIES1 properties = bitmapProperties();
|
||||
properties.bitmapOptions = D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_CPU_READ;
|
||||
|
||||
hr = deviceContext->get()->CreateBitmap(size, NULL, NULL,
|
||||
properties, &mappingCopy);
|
||||
if (FAILED(hr)) {
|
||||
qWarning("%s: Could not create bitmap: %#x", __FUNCTION__, hr);
|
||||
return QImage();
|
||||
}
|
||||
|
||||
hr = mappingCopy->CopyFromBitmap(NULL, bitmap.Get(), NULL);
|
||||
if (FAILED(hr)) {
|
||||
qWarning("%s: Could not copy from bitmap: %#x", __FUNCTION__, hr);
|
||||
return QImage();
|
||||
}
|
||||
|
||||
D2D1_MAPPED_RECT mappedRect;
|
||||
hr = mappingCopy->Map(D2D1_MAP_OPTIONS_READ, &mappedRect);
|
||||
if (FAILED(hr)) {
|
||||
qWarning("%s: Could not map: %#x", __FUNCTION__, hr);
|
||||
return QImage();
|
||||
}
|
||||
|
||||
return QImage(static_cast<const uchar *>(mappedRect.bits),
|
||||
size.width, size.height, mappedRect.pitch,
|
||||
QImage::Format_ARGB32_Premultiplied).copy(rect);
|
||||
}
|
||||
|
||||
QScopedPointer<QWindowsDirect2DDeviceContext> deviceContext;
|
||||
ComPtr<ID2D1Bitmap1> bitmap;
|
||||
};
|
||||
|
||||
QWindowsDirect2DBitmap::QWindowsDirect2DBitmap()
|
||||
: d_ptr(new QWindowsDirect2DBitmapPrivate)
|
||||
{
|
||||
}
|
||||
|
||||
QWindowsDirect2DBitmap::QWindowsDirect2DBitmap(ID2D1Bitmap1 *bitmap, ID2D1DeviceContext *dc)
|
||||
: d_ptr(new QWindowsDirect2DBitmapPrivate(dc, bitmap))
|
||||
{
|
||||
}
|
||||
|
||||
QWindowsDirect2DBitmap::~QWindowsDirect2DBitmap()
|
||||
{
|
||||
}
|
||||
|
||||
bool QWindowsDirect2DBitmap::resize(int width, int height)
|
||||
{
|
||||
Q_D(QWindowsDirect2DBitmap);
|
||||
return d->resize(width, height);
|
||||
}
|
||||
|
||||
bool QWindowsDirect2DBitmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags)
|
||||
{
|
||||
Q_D(QWindowsDirect2DBitmap);
|
||||
|
||||
QImage converted = image.convertToFormat(QImage::Format_ARGB32_Premultiplied, flags);
|
||||
return d->resize(converted.width(), converted.height(),
|
||||
converted.constBits(), converted.bytesPerLine());
|
||||
}
|
||||
|
||||
ID2D1Bitmap1* QWindowsDirect2DBitmap::bitmap() const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DBitmap);
|
||||
return d->bitmap.Get();
|
||||
}
|
||||
|
||||
QWindowsDirect2DDeviceContext *QWindowsDirect2DBitmap::deviceContext() const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DBitmap);
|
||||
return d->deviceContext.data();
|
||||
}
|
||||
|
||||
void QWindowsDirect2DBitmap::fill(const QColor &color)
|
||||
{
|
||||
Q_D(QWindowsDirect2DBitmap);
|
||||
|
||||
d->deviceContext->begin();
|
||||
d->deviceContext->get()->Clear(to_d2d_color_f(color));
|
||||
d->deviceContext->end();
|
||||
}
|
||||
|
||||
QImage QWindowsDirect2DBitmap::toImage(const QRect &rect)
|
||||
{
|
||||
Q_D(QWindowsDirect2DBitmap);
|
||||
return d->toImage(rect);
|
||||
}
|
||||
|
||||
QSize QWindowsDirect2DBitmap::size() const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DBitmap);
|
||||
|
||||
D2D1_SIZE_U size = d->bitmap->GetPixelSize();
|
||||
return QSize(size.width, size.height);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QWINDOWSDIRECT2DBITMAP_H
|
||||
#define QWINDOWSDIRECT2DBITMAP_H
|
||||
|
||||
#include <QtCore/QScopedPointer>
|
||||
#include <QtGui/QImage>
|
||||
|
||||
struct ID2D1DeviceContext;
|
||||
struct ID2D1Bitmap1;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowsDirect2DDeviceContext;
|
||||
class QWindowsDirect2DBitmapPrivate;
|
||||
class QWindowsDirect2DBitmap
|
||||
{
|
||||
Q_DECLARE_PRIVATE(QWindowsDirect2DBitmap)
|
||||
Q_DISABLE_COPY(QWindowsDirect2DBitmap)
|
||||
public:
|
||||
QWindowsDirect2DBitmap();
|
||||
QWindowsDirect2DBitmap(ID2D1Bitmap1 *bitmap, ID2D1DeviceContext *dc);
|
||||
~QWindowsDirect2DBitmap();
|
||||
|
||||
bool resize(int width, int height);
|
||||
bool fromImage(const QImage &image, Qt::ImageConversionFlags flags);
|
||||
|
||||
ID2D1Bitmap1* bitmap() const;
|
||||
QWindowsDirect2DDeviceContext* deviceContext() const;
|
||||
|
||||
void fill(const QColor &color);
|
||||
QImage toImage(const QRect &rect = QRect());
|
||||
|
||||
QSize size() const;
|
||||
|
||||
private:
|
||||
QScopedPointer<QWindowsDirect2DBitmapPrivate> d_ptr;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWINDOWSDIRECT2DBITMAP_H
|
||||
|
|
@ -0,0 +1,218 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qwindowsdirect2dcontext.h"
|
||||
#include "qwindowsdirect2dhelpers.h"
|
||||
#include "qwindowsdirect2dintegration.h"
|
||||
|
||||
#include <d3d11_1.h>
|
||||
#include <d2d1_1.h>
|
||||
#include <d2d1_1helper.h>
|
||||
#include <dxgi1_2.h>
|
||||
#include <wrl.h>
|
||||
#include <dwrite.h>
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowsDirect2DContextPrivate
|
||||
{
|
||||
public:
|
||||
bool init()
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
D3D_FEATURE_LEVEL level;
|
||||
|
||||
D3D_DRIVER_TYPE typeAttempts[] = {
|
||||
D3D_DRIVER_TYPE_HARDWARE,
|
||||
D3D_DRIVER_TYPE_WARP
|
||||
};
|
||||
const int ntypes = int(sizeof(typeAttempts) / sizeof(typeAttempts[0]));
|
||||
|
||||
for (int i = 0; i < ntypes; i++) {
|
||||
hr = D3D11CreateDevice(NULL,
|
||||
typeAttempts[i],
|
||||
NULL,
|
||||
D3D11_CREATE_DEVICE_SINGLETHREADED | D3D11_CREATE_DEVICE_BGRA_SUPPORT,
|
||||
NULL,
|
||||
0,
|
||||
D3D11_SDK_VERSION,
|
||||
&d3dDevice,
|
||||
&level,
|
||||
&d3dDeviceContext);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
break;
|
||||
}
|
||||
|
||||
if (FAILED(hr)) {
|
||||
qWarning("%s: Could not create Direct3D Device: %#x", __FUNCTION__, hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
ComPtr<IDXGIDevice> dxgiDevice;
|
||||
ComPtr<IDXGIAdapter> dxgiAdapter;
|
||||
|
||||
hr = d3dDevice.As(&dxgiDevice);
|
||||
if (FAILED(hr)) {
|
||||
qWarning("%s: DXGI Device interface query failed on D3D Device: %#x", __FUNCTION__, hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = dxgiDevice->GetParent(IID_PPV_ARGS(&dxgiAdapter));
|
||||
if (FAILED(hr)) {
|
||||
qWarning("%s: Failed to probe DXGI Device for parent DXGI Adapter: %#x", __FUNCTION__, hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = dxgiAdapter->GetParent(IID_PPV_ARGS(&dxgiFactory));
|
||||
if (FAILED(hr)) {
|
||||
qWarning("%s: Failed to probe DXGI Adapter for parent DXGI Factory: %#x", __FUNCTION__, hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
D2D1_FACTORY_OPTIONS options = {};
|
||||
|
||||
#ifdef QT_D2D_DEBUG_OUTPUT
|
||||
qDebug("Turning on Direct2D debugging messages");
|
||||
options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
|
||||
#endif // QT_D2D_DEBUG_OUTPUT
|
||||
|
||||
hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, options, d2dFactory.GetAddressOf());
|
||||
if (FAILED(hr)) {
|
||||
qWarning("%s: Could not create Direct2D Factory: %#x", __FUNCTION__, hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = d2dFactory->CreateDevice(dxgiDevice.Get(), &d2dDevice);
|
||||
if (FAILED(hr)) {
|
||||
qWarning("%s: Could not create D2D Device: %#x", __FUNCTION__, hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory),
|
||||
static_cast<IUnknown **>(&directWriteFactory));
|
||||
if (FAILED(hr)) {
|
||||
qWarning("%s: Could not create DirectWrite factory: %#x", __FUNCTION__, hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = directWriteFactory->GetGdiInterop(&directWriteGdiInterop);
|
||||
if (FAILED(hr)) {
|
||||
qWarning("%s: Could not create DirectWrite GDI Interop: %#x", __FUNCTION__, hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ComPtr<ID3D11Device> d3dDevice;
|
||||
ComPtr<ID2D1Factory1> d2dFactory;
|
||||
ComPtr<ID2D1Device> d2dDevice;
|
||||
ComPtr<IDXGIFactory2> dxgiFactory;
|
||||
ComPtr<ID3D11DeviceContext> d3dDeviceContext;
|
||||
ComPtr<IDWriteFactory> directWriteFactory;
|
||||
ComPtr<IDWriteGdiInterop> directWriteGdiInterop;
|
||||
};
|
||||
|
||||
QWindowsDirect2DContext::QWindowsDirect2DContext()
|
||||
: d_ptr(new QWindowsDirect2DContextPrivate)
|
||||
{
|
||||
}
|
||||
|
||||
QWindowsDirect2DContext::~QWindowsDirect2DContext() {}
|
||||
|
||||
bool QWindowsDirect2DContext::init()
|
||||
{
|
||||
Q_D(QWindowsDirect2DContext);
|
||||
return d->init();
|
||||
}
|
||||
|
||||
QWindowsDirect2DContext *QWindowsDirect2DContext::instance()
|
||||
{
|
||||
return QWindowsDirect2DIntegration::instance()->direct2DContext();
|
||||
}
|
||||
|
||||
ID3D11Device *QWindowsDirect2DContext::d3dDevice() const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DContext);
|
||||
return d->d3dDevice.Get();
|
||||
}
|
||||
|
||||
ID2D1Device *QWindowsDirect2DContext::d2dDevice() const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DContext);
|
||||
return d->d2dDevice.Get();
|
||||
}
|
||||
|
||||
ID2D1Factory1 *QWindowsDirect2DContext::d2dFactory() const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DContext);
|
||||
return d->d2dFactory.Get();
|
||||
}
|
||||
|
||||
IDXGIFactory2 *QWindowsDirect2DContext::dxgiFactory() const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DContext);
|
||||
return d->dxgiFactory.Get();
|
||||
}
|
||||
|
||||
ID3D11DeviceContext *QWindowsDirect2DContext::d3dDeviceContext() const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DContext);
|
||||
return d->d3dDeviceContext.Get();
|
||||
}
|
||||
|
||||
IDWriteFactory *QWindowsDirect2DContext::dwriteFactory() const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DContext);
|
||||
return d->directWriteFactory.Get();
|
||||
}
|
||||
|
||||
IDWriteGdiInterop *QWindowsDirect2DContext::dwriteGdiInterop() const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DContext);
|
||||
return d->directWriteGdiInterop.Get();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QWINDOWSDIRECT2DCONTEXT_H
|
||||
#define QWINDOWSDIRECT2DCONTEXT_H
|
||||
|
||||
#include <QtCore/QScopedPointer>
|
||||
|
||||
struct ID3D11Device;
|
||||
struct ID2D1Device;
|
||||
struct ID2D1Factory1;
|
||||
struct IDXGIFactory2;
|
||||
struct ID3D11DeviceContext;
|
||||
struct IDWriteFactory;
|
||||
struct IDWriteGdiInterop;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowsDirect2DContextPrivate;
|
||||
class QWindowsDirect2DContext
|
||||
{
|
||||
Q_DECLARE_PRIVATE( QWindowsDirect2DContext )
|
||||
|
||||
public:
|
||||
QWindowsDirect2DContext();
|
||||
virtual ~QWindowsDirect2DContext();
|
||||
|
||||
bool init();
|
||||
|
||||
static QWindowsDirect2DContext *instance();
|
||||
|
||||
ID3D11Device *d3dDevice() const;
|
||||
ID2D1Device *d2dDevice() const;
|
||||
ID2D1Factory1 *d2dFactory() const;
|
||||
IDXGIFactory2 *dxgiFactory() const;
|
||||
ID3D11DeviceContext *d3dDeviceContext() const;
|
||||
IDWriteFactory *dwriteFactory() const;
|
||||
IDWriteGdiInterop *dwriteGdiInterop() const;
|
||||
|
||||
private:
|
||||
QScopedPointer<QWindowsDirect2DContextPrivate> d_ptr;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWINDOWSDIRECT2DCONTEXT_H
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qwindowsdirect2dcontext.h"
|
||||
#include "qwindowsdirect2dhelpers.h"
|
||||
#include "qwindowsdirect2ddevicecontext.h"
|
||||
|
||||
#include <wrl.h>
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowsDirect2DDeviceContextPrivate {
|
||||
public:
|
||||
QWindowsDirect2DDeviceContextPrivate(ID2D1DeviceContext *dc)
|
||||
: deviceContext(dc)
|
||||
, refCount(0)
|
||||
{
|
||||
if (!dc) {
|
||||
HRESULT hr = QWindowsDirect2DContext::instance()->d2dDevice()->CreateDeviceContext(
|
||||
D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
|
||||
&deviceContext);
|
||||
if (FAILED(hr))
|
||||
qFatal("%s: Couldn't create Direct2D Device Context: %#x", __FUNCTION__, hr);
|
||||
}
|
||||
|
||||
Q_ASSERT(deviceContext);
|
||||
}
|
||||
|
||||
void begin()
|
||||
{
|
||||
Q_ASSERT(deviceContext);
|
||||
Q_ASSERT(refCount >= 0);
|
||||
|
||||
if (refCount == 0)
|
||||
deviceContext->BeginDraw();
|
||||
|
||||
refCount++;
|
||||
}
|
||||
|
||||
bool end()
|
||||
{
|
||||
Q_ASSERT(deviceContext);
|
||||
Q_ASSERT(refCount >= 0);
|
||||
|
||||
bool success = true;
|
||||
refCount--;
|
||||
|
||||
if (refCount == 0) {
|
||||
D2D1_TAG tag1, tag2;
|
||||
HRESULT hr = deviceContext->EndDraw(&tag1, &tag2);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
success = false;
|
||||
qWarning("%s: EndDraw failed: %#x, tag1: %lld, tag2: %lld", __FUNCTION__, hr, tag1, tag2);
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
ComPtr<ID2D1DeviceContext> deviceContext;
|
||||
int refCount;
|
||||
};
|
||||
|
||||
QWindowsDirect2DDeviceContext::QWindowsDirect2DDeviceContext(ID2D1DeviceContext *dc)
|
||||
: d_ptr(new QWindowsDirect2DDeviceContextPrivate(dc))
|
||||
{
|
||||
}
|
||||
|
||||
QWindowsDirect2DDeviceContext::~QWindowsDirect2DDeviceContext()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ID2D1DeviceContext *QWindowsDirect2DDeviceContext::get() const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DDeviceContext);
|
||||
Q_ASSERT(d->deviceContext);
|
||||
|
||||
return d->deviceContext.Get();
|
||||
}
|
||||
|
||||
void QWindowsDirect2DDeviceContext::begin()
|
||||
{
|
||||
Q_D(QWindowsDirect2DDeviceContext);
|
||||
d->begin();
|
||||
}
|
||||
|
||||
bool QWindowsDirect2DDeviceContext::end()
|
||||
{
|
||||
Q_D(QWindowsDirect2DDeviceContext);
|
||||
return d->end();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QWINDOWSDIRECT2DDEVICECONTEXT_H
|
||||
#define QWINDOWSDIRECT2DDEVICECONTEXT_H
|
||||
|
||||
#include "qwindowsdirect2dhelpers.h"
|
||||
|
||||
#include <QtCore/QScopedPointer>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
/*
|
||||
* Convenience class for handling device contexts. We have to call BeginDraw
|
||||
* before anything can happen, and EndDraw once we're done, for every frame and
|
||||
* pretty much any kind of operation.
|
||||
*
|
||||
* Unfortunately, these calls cannot be interleaved, and there is no way to check
|
||||
* what state a device context is in.
|
||||
*
|
||||
* The end result is that the following throws an error if we don't track it:
|
||||
* QPixmap pmap;
|
||||
* QPainter painter(&pmap);
|
||||
* pmap.clear();
|
||||
*
|
||||
* Here BeginDraw would first be called through the paint device, then when we clear
|
||||
* the pixmap we would have to call it again. There is no way to know what state
|
||||
* the device context is in when performing the clear, and activating the dc is an
|
||||
* error. Bummer.
|
||||
*
|
||||
* Hence we keep a reference count here and only activate/deactivate the device
|
||||
* if the refcount is zero.
|
||||
*
|
||||
* In a nutshell: Do not call BeginDraw/EndDraw yourself on the device pointer, do
|
||||
* so through the begin/end members below.
|
||||
*/
|
||||
|
||||
class QWindowsDirect2DDeviceContextPrivate;
|
||||
class QWindowsDirect2DDeviceContext
|
||||
{
|
||||
Q_DECLARE_PRIVATE(QWindowsDirect2DDeviceContext)
|
||||
public:
|
||||
QWindowsDirect2DDeviceContext(ID2D1DeviceContext *dc);
|
||||
~QWindowsDirect2DDeviceContext();
|
||||
|
||||
ID2D1DeviceContext *get() const;
|
||||
|
||||
void begin();
|
||||
bool end();
|
||||
|
||||
private:
|
||||
QScopedPointer<QWindowsDirect2DDeviceContextPrivate> d_ptr;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWINDOWSDIRECT2DDEVICECONTEXT_H
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QWINDOWSDIRECT2DHELPERS_H
|
||||
#define QWINDOWSDIRECT2DHELPERS_H
|
||||
|
||||
#include <QtCore/QRectF>
|
||||
#include <QtCore/QSizeF>
|
||||
#include <QtCore/QPointF>
|
||||
#include <QtGui/QColor>
|
||||
#include <QtGui/QTransform>
|
||||
|
||||
#include <d2d1_1helper.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
Q_DECL_CONSTEXPR inline D2D1_RECT_U to_d2d_rect_u(const QRect &qrect)
|
||||
{
|
||||
return D2D1::RectU(qrect.left(), qrect.top(), qrect.right(), qrect.bottom());
|
||||
}
|
||||
|
||||
Q_DECL_CONSTEXPR inline D2D1_RECT_F to_d2d_rect_f(const QRectF &qrect)
|
||||
{
|
||||
return D2D1::RectF(qrect.left(), qrect.top(), qrect.right(), qrect.bottom());
|
||||
}
|
||||
|
||||
Q_DECL_CONSTEXPR inline D2D1_SIZE_U to_d2d_size_u(const QSizeF &qsize)
|
||||
{
|
||||
return D2D1::SizeU(qsize.width(), qsize.height());
|
||||
}
|
||||
|
||||
Q_DECL_CONSTEXPR inline D2D1_SIZE_U to_d2d_size_u(const QSize &qsize)
|
||||
{
|
||||
return D2D1::SizeU(qsize.width(), qsize.height());
|
||||
}
|
||||
|
||||
Q_DECL_CONSTEXPR inline D2D1_POINT_2F to_d2d_point_2f(const QPointF &qpoint)
|
||||
{
|
||||
return D2D1::Point2F(qpoint.x(), qpoint.y());
|
||||
}
|
||||
|
||||
Q_DECL_CONSTEXPR inline D2D1::ColorF to_d2d_color_f(const QColor &c)
|
||||
{
|
||||
return D2D1::ColorF(c.redF(), c.greenF(), c.blueF(), c.alphaF());
|
||||
}
|
||||
|
||||
Q_DECL_CONSTEXPR inline D2D1_MATRIX_3X2_F to_d2d_matrix_3x2_f(const QTransform &transform)
|
||||
{
|
||||
Q_ASSERT(transform.isAffine());
|
||||
|
||||
return D2D1::Matrix3x2F(transform.m11(), transform.m12(),
|
||||
transform.m21(), transform.m22(),
|
||||
transform.m31(), transform.m32());
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWINDOWSDIRECT2DHELPERS_H
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qwindowsdirect2dcontext.h"
|
||||
#include "qwindowsdirect2dintegration.h"
|
||||
#include "qwindowsdirect2dbackingstore.h"
|
||||
#include "qwindowsdirect2dplatformpixmap.h"
|
||||
#include "qwindowsdirect2dnativeinterface.h"
|
||||
|
||||
#include "qwindowscontext.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtGui/private/qpixmap_raster_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowsDirect2DIntegrationPrivate
|
||||
{
|
||||
public:
|
||||
QWindowsDirect2DNativeInterface m_nativeInterface;
|
||||
QWindowsDirect2DContext m_d2dContext;
|
||||
};
|
||||
|
||||
QWindowsDirect2DIntegration *QWindowsDirect2DIntegration::create(const QStringList ¶mList)
|
||||
{
|
||||
QWindowsDirect2DIntegration *integration = new QWindowsDirect2DIntegration(paramList);
|
||||
|
||||
if (!integration->init()) {
|
||||
delete integration;
|
||||
integration = 0;
|
||||
}
|
||||
|
||||
return integration;
|
||||
}
|
||||
|
||||
QWindowsDirect2DIntegration::~QWindowsDirect2DIntegration()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QWindowsDirect2DIntegration *QWindowsDirect2DIntegration::instance()
|
||||
{
|
||||
return static_cast<QWindowsDirect2DIntegration *>(QWindowsIntegration::instance());
|
||||
}
|
||||
|
||||
QPlatformNativeInterface *QWindowsDirect2DIntegration::nativeInterface() const
|
||||
{
|
||||
return &d->m_nativeInterface;
|
||||
}
|
||||
|
||||
QPlatformPixmap *QWindowsDirect2DIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
|
||||
{
|
||||
switch (type) {
|
||||
case QPlatformPixmap::BitmapType:
|
||||
return new QRasterPlatformPixmap(type);
|
||||
break;
|
||||
default:
|
||||
return new QWindowsDirect2DPlatformPixmap(type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QPlatformBackingStore *QWindowsDirect2DIntegration::createPlatformBackingStore(QWindow *window) const
|
||||
{
|
||||
return QWindowsDirect2DBackingStore::create(window);
|
||||
}
|
||||
|
||||
QWindowsDirect2DContext *QWindowsDirect2DIntegration::direct2DContext() const
|
||||
{
|
||||
return &d->m_d2dContext;
|
||||
}
|
||||
|
||||
QWindowsDirect2DIntegration::QWindowsDirect2DIntegration(const QStringList ¶mList)
|
||||
: QWindowsIntegration(paramList)
|
||||
, d(new QWindowsDirect2DIntegrationPrivate)
|
||||
{
|
||||
}
|
||||
|
||||
bool QWindowsDirect2DIntegration::init()
|
||||
{
|
||||
return d->m_d2dContext.init();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QWINDOWSDIRECT2DINTEGRATION_H
|
||||
#define QWINDOWSDIRECT2DINTEGRATION_H
|
||||
|
||||
#include "qwindowsintegration.h"
|
||||
|
||||
#include <QtCore/QScopedPointer>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowsDirect2DContext;
|
||||
class QWindowsDirect2DIntegrationPrivate;
|
||||
|
||||
class QWindowsDirect2DIntegration : public QWindowsIntegration
|
||||
{
|
||||
public:
|
||||
static QWindowsDirect2DIntegration *create(const QStringList ¶mList);
|
||||
|
||||
virtual ~QWindowsDirect2DIntegration();
|
||||
|
||||
static QWindowsDirect2DIntegration *instance();
|
||||
|
||||
QPlatformNativeInterface *nativeInterface() const Q_DECL_OVERRIDE;
|
||||
QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const Q_DECL_OVERRIDE;
|
||||
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const Q_DECL_OVERRIDE;
|
||||
|
||||
QWindowsDirect2DContext *direct2DContext() const;
|
||||
|
||||
private:
|
||||
explicit QWindowsDirect2DIntegration(const QStringList ¶mList);
|
||||
bool init();
|
||||
|
||||
QScopedPointer<QWindowsDirect2DIntegrationPrivate> d;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWINDOWSDIRECT2DINTEGRATION_H
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qwindowsdirect2dnativeinterface.h"
|
||||
|
||||
#include <QtGui/QBackingStore>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
void *QWindowsDirect2DNativeInterface::nativeResourceForBackingStore(const QByteArray &resource, QBackingStore *bs)
|
||||
{
|
||||
if (!bs || !bs->handle()) {
|
||||
qWarning("%s: '%s' requested for null backingstore or backingstore without handle.", __FUNCTION__, resource.constData());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// getDC is so common we don't want to print an "invalid key" line for it
|
||||
if (resource == "getDC")
|
||||
return 0;
|
||||
|
||||
qWarning("%s: Invalid key '%s' requested.", __FUNCTION__, resource.constData());
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QWINDOWSDIRECT2DNATIVEINTERFACE_H
|
||||
#define QWINDOWSDIRECT2DNATIVEINTERFACE_H
|
||||
|
||||
#include "qwindowsnativeinterface.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowsDirect2DNativeInterface : public QWindowsNativeInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
void *nativeResourceForBackingStore(const QByteArray &resource, QBackingStore *bs) Q_DECL_OVERRIDE;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWINDOWSDIRECT2DNATIVEINTERFACE_H
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qwindowsdirect2dpaintdevice.h"
|
||||
#include "qwindowsdirect2dpaintengine.h"
|
||||
#include "qwindowsdirect2dcontext.h"
|
||||
#include "qwindowsdirect2dhelpers.h"
|
||||
#include "qwindowsdirect2dbitmap.h"
|
||||
#include "qwindowsdirect2ddevicecontext.h"
|
||||
|
||||
#include "qwindowswindow.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowsDirect2DPaintDevicePrivate
|
||||
{
|
||||
public:
|
||||
QWindowsDirect2DPaintDevicePrivate(QWindowsDirect2DBitmap *bitmap, QInternal::PaintDeviceFlags f)
|
||||
: engine(new QWindowsDirect2DPaintEngine(bitmap))
|
||||
, bitmap(bitmap)
|
||||
, flags(f)
|
||||
{}
|
||||
|
||||
QScopedPointer<QWindowsDirect2DPaintEngine> engine;
|
||||
QWindowsDirect2DBitmap *bitmap;
|
||||
QInternal::PaintDeviceFlags flags;
|
||||
};
|
||||
|
||||
QWindowsDirect2DPaintDevice::QWindowsDirect2DPaintDevice(QWindowsDirect2DBitmap *bitmap, QInternal::PaintDeviceFlags flags)
|
||||
: d_ptr(new QWindowsDirect2DPaintDevicePrivate(bitmap, flags))
|
||||
{
|
||||
}
|
||||
|
||||
QPaintEngine *QWindowsDirect2DPaintDevice::paintEngine() const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DPaintDevice);
|
||||
|
||||
return d->engine.data();
|
||||
}
|
||||
|
||||
int QWindowsDirect2DPaintDevice::devType() const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DPaintDevice);
|
||||
|
||||
return d->flags;
|
||||
}
|
||||
|
||||
int QWindowsDirect2DPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DPaintDevice);
|
||||
|
||||
switch (metric) {
|
||||
case QPaintDevice::PdmWidth:
|
||||
return d->bitmap->bitmap()->GetPixelSize().width;
|
||||
break;
|
||||
case QPaintDevice::PdmHeight:
|
||||
return d->bitmap->bitmap()->GetPixelSize().height;
|
||||
break;
|
||||
case QPaintDevice::PdmNumColors:
|
||||
return INT_MAX;
|
||||
break;
|
||||
case QPaintDevice::PdmDepth:
|
||||
return 32;
|
||||
break;
|
||||
case QPaintDevice::PdmDpiX:
|
||||
case QPaintDevice::PdmPhysicalDpiX:
|
||||
{
|
||||
FLOAT x, y;
|
||||
QWindowsDirect2DContext::instance()->d2dFactory()->GetDesktopDpi(&x, &y);
|
||||
return x;
|
||||
}
|
||||
break;
|
||||
case QPaintDevice::PdmDpiY:
|
||||
case QPaintDevice::PdmPhysicalDpiY:
|
||||
{
|
||||
FLOAT x, y;
|
||||
QWindowsDirect2DContext::instance()->d2dFactory()->GetDesktopDpi(&x, &y);
|
||||
return y;
|
||||
}
|
||||
break;
|
||||
case QPaintDevice::PdmDevicePixelRatio:
|
||||
return 1;
|
||||
break;
|
||||
case QPaintDevice::PdmWidthMM:
|
||||
case QPaintDevice::PdmHeightMM:
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QWINDOWSDIRECT2DPAINTDEVICE_H
|
||||
#define QWINDOWSDIRECT2DPAINTDEVICE_H
|
||||
|
||||
#include <QtCore/QScopedPointer>
|
||||
#include <QtGui/QPaintDevice>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowsDirect2DBitmap;
|
||||
|
||||
class QWindowsDirect2DPaintDevicePrivate;
|
||||
class QWindowsDirect2DPaintDevice : public QPaintDevice
|
||||
{
|
||||
Q_DECLARE_PRIVATE(QWindowsDirect2DPaintDevice)
|
||||
|
||||
public:
|
||||
QWindowsDirect2DPaintDevice(QWindowsDirect2DBitmap *bitmap, QInternal::PaintDeviceFlags flags);
|
||||
QPaintEngine *paintEngine() const Q_DECL_OVERRIDE;
|
||||
int devType() const Q_DECL_OVERRIDE;
|
||||
|
||||
protected:
|
||||
int metric(PaintDeviceMetric metric) const Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
QScopedPointer<QWindowsDirect2DPaintDevicePrivate> d_ptr;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWINDOWSDIRECT2DPAINTDEVICE_H
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,87 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QWINDOWSDIRECT2DPAINTENGINE_H
|
||||
#define QWINDOWSDIRECT2DPAINTENGINE_H
|
||||
|
||||
#include <QtCore/QScopedPointer>
|
||||
#include <QtGui/QPaintEngine>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowsDirect2DPaintEnginePrivate;
|
||||
class QWindowsDirect2DBitmap;
|
||||
|
||||
class QWindowsDirect2DPaintEngine : public QPaintEngine
|
||||
{
|
||||
Q_DECLARE_PRIVATE(QWindowsDirect2DPaintEngine)
|
||||
|
||||
public:
|
||||
QWindowsDirect2DPaintEngine(QWindowsDirect2DBitmap *bitmap);
|
||||
|
||||
bool begin(QPaintDevice *pdev) Q_DECL_OVERRIDE;
|
||||
bool end() Q_DECL_OVERRIDE;
|
||||
|
||||
void updateState(const QPaintEngineState &state) Q_DECL_OVERRIDE;
|
||||
|
||||
Type type() const Q_DECL_OVERRIDE;
|
||||
|
||||
void drawEllipse(const QRectF &rect) Q_DECL_OVERRIDE;
|
||||
void drawEllipse(const QRect &rect) Q_DECL_OVERRIDE;
|
||||
void drawImage(const QRectF &rectangle, const QImage &image, const QRectF &sr, Qt::ImageConversionFlags flags = Qt::AutoColor) Q_DECL_OVERRIDE;
|
||||
void drawLines(const QLineF *lines, int lineCount) Q_DECL_OVERRIDE;
|
||||
void drawLines(const QLine *lines, int lineCount) Q_DECL_OVERRIDE;
|
||||
void drawPath(const QPainterPath &path) Q_DECL_OVERRIDE;
|
||||
void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) Q_DECL_OVERRIDE;
|
||||
void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) Q_DECL_OVERRIDE;
|
||||
void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode) Q_DECL_OVERRIDE;
|
||||
void drawRects(const QRectF *rects, int rectCount) Q_DECL_OVERRIDE;
|
||||
void drawRects(const QRect *rects, int rectCount) Q_DECL_OVERRIDE;
|
||||
void drawTextItem(const QPointF &p, const QTextItem &textItem) Q_DECL_OVERRIDE;
|
||||
void drawTiledPixmap(const QRectF &rect, const QPixmap &pixmap, const QPointF &p) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
QScopedPointer<QWindowsDirect2DPaintEnginePrivate> d_ptr;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWINDOWSDIRECT2DPAINTENGINE_H
|
||||
|
|
@ -0,0 +1,179 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qwindowsdirect2dcontext.h"
|
||||
#include "qwindowsdirect2dpaintdevice.h"
|
||||
#include "qwindowsdirect2dplatformpixmap.h"
|
||||
#include "qwindowsdirect2dbitmap.h"
|
||||
#include "qwindowsdirect2dhelpers.h"
|
||||
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QImage>
|
||||
#include <QtGui/QPaintDevice>
|
||||
#include <QtGui/QPaintEngine>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowsDirect2DPlatformPixmapPrivate
|
||||
{
|
||||
public:
|
||||
QWindowsDirect2DPlatformPixmapPrivate()
|
||||
: bitmap(new QWindowsDirect2DBitmap)
|
||||
, device(new QWindowsDirect2DPaintDevice(bitmap.data(), QInternal::Pixmap))
|
||||
, devicePixelRatio(1.0)
|
||||
{}
|
||||
|
||||
QScopedPointer<QWindowsDirect2DBitmap> bitmap;
|
||||
QScopedPointer<QWindowsDirect2DPaintDevice> device;
|
||||
qreal devicePixelRatio;
|
||||
};
|
||||
|
||||
static int qt_d2dpixmap_serno = 0;
|
||||
|
||||
QWindowsDirect2DPlatformPixmap::QWindowsDirect2DPlatformPixmap(PixelType pixelType)
|
||||
: QPlatformPixmap(pixelType, Direct2DClass)
|
||||
, d_ptr(new QWindowsDirect2DPlatformPixmapPrivate)
|
||||
{
|
||||
setSerialNumber(qt_d2dpixmap_serno++);
|
||||
}
|
||||
|
||||
QWindowsDirect2DPlatformPixmap::~QWindowsDirect2DPlatformPixmap()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void QWindowsDirect2DPlatformPixmap::resize(int width, int height)
|
||||
{
|
||||
Q_D(QWindowsDirect2DPlatformPixmap);
|
||||
|
||||
if (!d->bitmap->resize(width, height)) {
|
||||
qWarning("%s: Could not resize bitmap", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
is_null = false;
|
||||
w = width;
|
||||
h = height;
|
||||
this->d = 32;
|
||||
}
|
||||
|
||||
void QWindowsDirect2DPlatformPixmap::fromImage(const QImage &image,
|
||||
Qt::ImageConversionFlags flags)
|
||||
{
|
||||
Q_D(QWindowsDirect2DPlatformPixmap);
|
||||
|
||||
if (!d->bitmap->fromImage(image, flags)) {
|
||||
qWarning("%s: Could not init from image", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
is_null = false;
|
||||
w = image.width();
|
||||
h = image.height();
|
||||
this->d = 32;
|
||||
}
|
||||
|
||||
int QWindowsDirect2DPlatformPixmap::metric(QPaintDevice::PaintDeviceMetric metric) const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DPlatformPixmap);
|
||||
|
||||
Q_GUI_EXPORT int qt_paint_device_metric(const QPaintDevice *device, QPaintDevice::PaintDeviceMetric metric);
|
||||
return qt_paint_device_metric(d->device.data(), metric);
|
||||
}
|
||||
|
||||
void QWindowsDirect2DPlatformPixmap::fill(const QColor &color)
|
||||
{
|
||||
Q_D(QWindowsDirect2DPlatformPixmap);
|
||||
d->bitmap->fill(color);
|
||||
}
|
||||
|
||||
bool QWindowsDirect2DPlatformPixmap::hasAlphaChannel() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QImage QWindowsDirect2DPlatformPixmap::toImage() const
|
||||
{
|
||||
return toImage(QRect());
|
||||
}
|
||||
|
||||
QImage QWindowsDirect2DPlatformPixmap::toImage(const QRect &rect) const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DPlatformPixmap);
|
||||
|
||||
bool active = d->device->paintEngine()->isActive();
|
||||
|
||||
if (active)
|
||||
d->device->paintEngine()->end();
|
||||
|
||||
QImage result = d->bitmap->toImage(rect);
|
||||
|
||||
if (active)
|
||||
d->device->paintEngine()->begin(d->device.data());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QPaintEngine* QWindowsDirect2DPlatformPixmap::paintEngine() const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DPlatformPixmap);
|
||||
return d->device->paintEngine();
|
||||
}
|
||||
|
||||
qreal QWindowsDirect2DPlatformPixmap::devicePixelRatio() const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DPlatformPixmap);
|
||||
return d->devicePixelRatio;
|
||||
}
|
||||
|
||||
void QWindowsDirect2DPlatformPixmap::setDevicePixelRatio(qreal scaleFactor)
|
||||
{
|
||||
Q_D(QWindowsDirect2DPlatformPixmap);
|
||||
d->devicePixelRatio = scaleFactor;
|
||||
}
|
||||
|
||||
QWindowsDirect2DBitmap *QWindowsDirect2DPlatformPixmap::bitmap() const
|
||||
{
|
||||
Q_D(const QWindowsDirect2DPlatformPixmap);
|
||||
return d->bitmap.data();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QWINDOWSDIRECT2DPLATFORMPIXMAP_H
|
||||
#define QWINDOWSDIRECT2DPLATFORMPIXMAP_H
|
||||
|
||||
#include <QtGui/qpa/qplatformpixmap.h>
|
||||
#include <QtCore/QScopedPointer>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowsDirect2DPlatformPixmapPrivate;
|
||||
class QWindowsDirect2DBitmap;
|
||||
|
||||
class QWindowsDirect2DPlatformPixmap : public QPlatformPixmap
|
||||
{
|
||||
Q_DECLARE_PRIVATE(QWindowsDirect2DPlatformPixmap)
|
||||
public:
|
||||
QWindowsDirect2DPlatformPixmap(PixelType pixelType);
|
||||
~QWindowsDirect2DPlatformPixmap();
|
||||
|
||||
virtual void resize(int width, int height);
|
||||
virtual void fromImage(const QImage &image,
|
||||
Qt::ImageConversionFlags flags);
|
||||
|
||||
virtual int metric(QPaintDevice::PaintDeviceMetric metric) const;
|
||||
virtual void fill(const QColor &color);
|
||||
|
||||
virtual bool hasAlphaChannel() const;
|
||||
|
||||
virtual QImage toImage() const;
|
||||
virtual QImage toImage(const QRect &rect) const;
|
||||
|
||||
virtual QPaintEngine* paintEngine() const;
|
||||
|
||||
virtual qreal devicePixelRatio() const;
|
||||
virtual void setDevicePixelRatio(qreal scaleFactor);
|
||||
|
||||
QWindowsDirect2DBitmap *bitmap() const;
|
||||
|
||||
private:
|
||||
QScopedPointer<QWindowsDirect2DPlatformPixmapPrivate> d_ptr;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWINDOWSDIRECT2DPLATFORMPIXMAP_H
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the plugins of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qwindowsdirect2dintegration.h"
|
||||
|
||||
#include <QtGui/qpa/qplatformintegrationplugin.h>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWindowsDirect2DIntegrationPlugin : public QPlatformIntegrationPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.2" FILE "direct2d.json")
|
||||
public:
|
||||
QPlatformIntegration *create(const QString&, const QStringList&);
|
||||
};
|
||||
|
||||
QPlatformIntegration *QWindowsDirect2DIntegrationPlugin::create(const QString& system, const QStringList& paramList)
|
||||
{
|
||||
if (system.compare(system, QStringLiteral("direct2d"), Qt::CaseInsensitive) == 0)
|
||||
return QWindowsDirect2DIntegration::create(paramList);
|
||||
return 0;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "qwindowsdirect2dplatformplugin.moc"
|
||||
|
|
@ -18,6 +18,10 @@ mac {
|
|||
win32:!winrt: SUBDIRS += windows
|
||||
winrt: SUBDIRS += winrt
|
||||
|
||||
contains(QT_CONFIG, direct2d) {
|
||||
SUBDIRS += direct2d
|
||||
}
|
||||
|
||||
qnx {
|
||||
SUBDIRS += qnx
|
||||
}
|
||||
|
|
|
|||
|
|
@ -182,6 +182,7 @@ Configure::Configure(int& argc, char** argv)
|
|||
dictionary[ "QML_DEBUG" ] = "yes";
|
||||
dictionary[ "PLUGIN_MANIFESTS" ] = "no";
|
||||
dictionary[ "DIRECTWRITE" ] = "no";
|
||||
dictionary[ "DIRECT2D" ] = "no";
|
||||
dictionary[ "NIS" ] = "no";
|
||||
dictionary[ "NEON" ] = "auto";
|
||||
dictionary[ "LARGE_FILE" ] = "yes";
|
||||
|
|
@ -1218,6 +1219,12 @@ void Configure::parseCmdLine()
|
|||
dictionary["DIRECTWRITE"] = "no";
|
||||
}
|
||||
|
||||
else if (configCmdLine.at(i) == "-direct2d") {
|
||||
dictionary["DIRECT2D"] = "yes";
|
||||
} else if (configCmdLine.at(i) == "-no-direct2d") {
|
||||
dictionary["DIRECT2D"] = "no";
|
||||
}
|
||||
|
||||
else if (configCmdLine.at(i) == "-nis") {
|
||||
dictionary["NIS"] = "yes";
|
||||
} else if (configCmdLine.at(i) == "-no-nis") {
|
||||
|
|
@ -1939,6 +1946,11 @@ bool Configure::displayHelp()
|
|||
desc("DIRECTWRITE", "no", "-no-directwrite", "Do not build support for DirectWrite font rendering.");
|
||||
desc("DIRECTWRITE", "yes", "-directwrite", "Build support for DirectWrite font rendering (experimental, requires DirectWrite availability on target systems, e.g. Windows Vista with Platform Update, Windows 7, etc.)\n");
|
||||
|
||||
desc("DIRECT2D", "no", "-no-direct2d", "Do not build the Direct2D platform plugin.");
|
||||
desc("DIRECT2D", "yes", "-direct2d", "Build the Direct2D platform plugin (experimental,\n"
|
||||
"requires Direct2D availability on target systems,\n"
|
||||
"e.g. Windows 7 with Platform Update, Windows 8, etc.)\n");
|
||||
|
||||
desc( "-no-style-<style>", "Disable <style> entirely.");
|
||||
desc( "-qt-style-<style>", "Enable <style> in the Qt Library.\nAvailable styles: ");
|
||||
|
||||
|
|
@ -2206,6 +2218,8 @@ bool Configure::checkAvailability(const QString &part)
|
|||
available = findFile("mfapi.h") && findFile("mf.lib");
|
||||
} else if (part == "DIRECTWRITE") {
|
||||
available = findFile("dwrite.h") && findFile("d2d1.h") && findFile("dwrite.lib");
|
||||
} else if (part == "DIRECT2D") {
|
||||
available = tryCompileProject("qpa/direct2d");
|
||||
} else if (part == "ICONV") {
|
||||
available = tryCompileProject("unix/iconv") || tryCompileProject("unix/gnu-libiconv");
|
||||
} else if (part == "INOTIFY") {
|
||||
|
|
@ -2441,6 +2455,13 @@ bool Configure::verifyConfiguration()
|
|||
prompt = true;
|
||||
}
|
||||
|
||||
if (dictionary["DIRECT2D"] == "yes" && !checkAvailability("DIRECT2D")) {
|
||||
cout << "WARNING: To be able to build the Direct2D platform plugin you will" << endl
|
||||
<< "need the Microsoft DirectWrite and Microsoft Direct2D development" << endl
|
||||
<< "files such as headers and libraries." << endl;
|
||||
prompt = true;
|
||||
}
|
||||
|
||||
// -angle given on command line, but Direct X cannot be found.
|
||||
if (dictionary["ANGLE"] != "no") {
|
||||
QString errorMessage;
|
||||
|
|
@ -2730,6 +2751,9 @@ void Configure::generateOutputVars()
|
|||
if (dictionary["DIRECTWRITE"] == "yes")
|
||||
qtConfig += "directwrite";
|
||||
|
||||
if (dictionary["DIRECT2D"] == "yes")
|
||||
qtConfig += "direct2d";
|
||||
|
||||
if (dictionary[ "NATIVE_GESTURES" ] == "yes")
|
||||
qtConfig += "native-gestures";
|
||||
|
||||
|
|
@ -3574,6 +3598,11 @@ void Configure::displayConfig()
|
|||
sout << "Use system proxies.........." << dictionary[ "SYSTEM_PROXIES" ] << endl;
|
||||
sout << endl;
|
||||
|
||||
sout << "QPA Backends:" << endl;
|
||||
sout << " GDI....................." << "yes" << endl;
|
||||
sout << " Direct2D................" << dictionary[ "DIRECT2D" ] << endl;
|
||||
sout << endl;
|
||||
|
||||
sout << "Third Party Libraries:" << endl;
|
||||
sout << " ZLIB support............" << dictionary[ "ZLIB" ] << endl;
|
||||
sout << " GIF support............." << dictionary[ "GIF" ] << endl;
|
||||
|
|
|
|||
Loading…
Reference in New Issue