summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp')
-rw-r--r--src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp137
1 files changed, 135 insertions, 2 deletions
diff --git a/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp b/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp
index 1a26d7029e..9833d50e6c 100644
--- a/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp
+++ b/src/plugins/platforms/direct2d/qwindowsdirect2dintegration.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 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.
@@ -48,7 +48,8 @@
#include "qwindowscontext.h"
-#include <QtCore/QDebug>
+#include <qplatformdefs.h>
+#include <QtCore/QCoreApplication>
#include <QtGui/private/qpixmap_raster_p.h>
#include <QtGui/qpa/qwindowsysteminterface.h>
@@ -61,8 +62,140 @@ public:
QWindowsDirect2DContext m_d2dContext;
};
+class Direct2DVersion
+{
+private:
+ Direct2DVersion()
+ : partOne(0)
+ , partTwo(0)
+ , partThree(0)
+ , partFour(0)
+ {}
+
+ Direct2DVersion(int one, int two, int three, int four)
+ : partOne(one)
+ , partTwo(two)
+ , partThree(three)
+ , partFour(four)
+ {}
+
+public:
+ // 6.2.9200.16765 corresponds to Direct2D 1.1 on Windows 7 SP1 with Platform Update
+ enum {
+ D2DMinVersionPart1 = 6,
+ D2DMinVersionPart2 = 2,
+ D2DMinVersionPart3 = 9200,
+ D2DMinVersionPart4 = 16765
+ };
+
+ static Direct2DVersion systemVersion() {
+ static const int bufSize = 512;
+ TCHAR filename[bufSize];
+
+ UINT i = GetSystemDirectory(filename, bufSize);
+ if (i > 0 && i < MAX_PATH) {
+ if (_tcscat_s(filename, MAX_PATH, __TEXT("\\d2d1.dll")) == 0) {
+ DWORD versionInfoSize = GetFileVersionInfoSize(filename, NULL);
+ if (versionInfoSize) {
+ QVector<BYTE> info(versionInfoSize);
+ if (GetFileVersionInfo(filename, NULL, versionInfoSize, info.data())) {
+ UINT size;
+ DWORD *fi;
+
+ if (VerQueryValue(info.constData(), __TEXT("\\"), (LPVOID *) &fi, &size) && size) {
+ VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *) fi;
+ return Direct2DVersion(HIWORD(verInfo->dwFileVersionMS),
+ LOWORD(verInfo->dwFileVersionMS),
+ HIWORD(verInfo->dwFileVersionLS),
+ LOWORD(verInfo->dwFileVersionLS));
+ }
+ }
+ }
+ }
+ }
+
+ return Direct2DVersion();
+ }
+
+ static Direct2DVersion minimumVersion() {
+ return Direct2DVersion(D2DMinVersionPart1,
+ D2DMinVersionPart2,
+ D2DMinVersionPart3,
+ D2DMinVersionPart4);
+ }
+
+ bool isValid() const {
+ return partOne || partTwo || partThree || partFour;
+ }
+
+ bool operator<(const Direct2DVersion &other) {
+ int c = cmp(partOne, other.partOne);
+ if (c > 0)
+ return false;
+ if (c < 0)
+ return true;
+
+ c = cmp(partTwo, other.partTwo);
+ if (c > 0)
+ return false;
+ if (c < 0)
+ return true;
+
+ c = cmp(partThree, other.partThree);
+ if (c > 0)
+ return false;
+ if (c < 0)
+ return true;
+
+ c = cmp(partFour, other.partFour);
+ if (c > 0)
+ return false;
+ if (c < 0)
+ return true;
+
+ return false;
+ }
+
+ static Q_DECL_CONSTEXPR int cmp(int a, int b) {
+ return a - b;
+ }
+
+ int partOne, partTwo, partThree, partFour;
+};
+
QWindowsDirect2DIntegration *QWindowsDirect2DIntegration::create(const QStringList &paramList)
{
+ Direct2DVersion systemVersion = Direct2DVersion::systemVersion();
+
+ if (systemVersion.isValid() && systemVersion < Direct2DVersion::minimumVersion()) {
+ QString msg = QCoreApplication::translate("QWindowsDirect2DIntegration",
+ "Qt cannot load the direct2d platform plugin because " \
+ "the Direct2D version on this system is too old. The " \
+ "minimum system requirement for this platform plugin " \
+ "is Windows 7 SP1 with Platform Update.\n\n" \
+ "The minimum Direct2D version required is %1.%2.%3.%4. " \
+ "The Direct2D version on this system is %5.%6.%7.%8.");
+
+ msg = msg.arg(Direct2DVersion::D2DMinVersionPart1)
+ .arg(Direct2DVersion::D2DMinVersionPart2)
+ .arg(Direct2DVersion::D2DMinVersionPart3)
+ .arg(Direct2DVersion::D2DMinVersionPart4)
+ .arg(systemVersion.partOne)
+ .arg(systemVersion.partTwo)
+ .arg(systemVersion.partThree)
+ .arg(systemVersion.partFour);
+
+ QString caption = QCoreApplication::translate("QWindowsDirect2DIntegration",
+ "Cannot load direct2d platform plugin");
+
+ MessageBoxW(NULL,
+ msg.toStdWString().c_str(),
+ caption.toStdWString().c_str(),
+ MB_OK | MB_ICONERROR);
+
+ return Q_NULLPTR;
+ }
+
QWindowsDirect2DIntegration *integration = new QWindowsDirect2DIntegration(paramList);
if (!integration->init()) {