summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>2017-11-07 16:47:51 +0900
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>2017-11-07 18:11:43 +0900
commitb4f138383f10562b7cdd5585a8e0cc12265dff2c (patch)
treec896e58d1f36011cc8f2483aefb42af3b44b8759
parent6144ad632808c3a6cfbaf2a4e241fb2bc631def0 (diff)
Adopt window manager feature to get rendering right
Change-Id: I6170cf0b8b351e5ce07531319de51f7c62eeb82d Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
-rw-r--r--app/app.pro6
-rw-r--r--app/main.cpp37
-rw-r--r--app/qlibwindowmanager.cpp71
-rw-r--r--app/qlibwindowmanager.h71
-rw-r--r--package/config.xml1
5 files changed, 173 insertions, 13 deletions
diff --git a/app/app.pro b/app/app.pro
index 52bd496..a2fdf14 100644
--- a/app/app.pro
+++ b/app/app.pro
@@ -1,7 +1,11 @@
TARGET = mediaplayer
QT = quickcontrols2
-SOURCES = main.cpp
+HEADERS = qlibwindowmanager.h
+SOURCES = main.cpp qlibwindowmanager.cpp
+
+CONFIG += link_pkgconfig
+PKGCONFIG += libwindowmanager
RESOURCES += \
mediaplayer.qrc \
diff --git a/app/main.cpp b/app/main.cpp
index c3e0fb0..4b966d5 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 The Qt Company Ltd.
+ * Copyright (C) 2016, 2017 Toyota Motor Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,21 +26,14 @@
#include <QtQml/qqml.h>
#include <QtQuickControls2/QQuickStyle>
-#ifdef HAVE_LIBHOMESCREEN
-#include <libhomescreen.hpp>
-#endif
+#include <QQuickWindow>
+#include "qlibwindowmanager.h"
+
+static QLibWindowmanager* qwm;
+static std::string myname = std::string("MediaPlayer");
int main(int argc, char *argv[])
{
-#ifdef HAVE_LIBHOMESCREEN
- LibHomeScreen libHomeScreen;
-
- if (!libHomeScreen.renderAppToAreaAllowed(0, 1)) {
- qWarning() << "renderAppToAreaAllowed is denied";
- return -1;
- }
-#endif
-
QGuiApplication app(argc, argv);
QQuickStyle::setStyle("AGL");
@@ -67,9 +61,28 @@ int main(int argc, char *argv[])
query.addQueryItem(QStringLiteral("token"), secret);
bindingAddress.setQuery(query);
context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
+ qwm = new QLibWindowmanager();
+ // WindowManager
+ if(qwm->init(port,secret) != 0){
+ exit(EXIT_FAILURE);
+ }
+ if (qwm->requestSurface(myname.c_str()) != 0) {
+ exit(EXIT_FAILURE);
+ }
+ qwm->set_event_handler(QLibWindowmanager::Event_SyncDraw, [qwm](json_object *object) {
+ fprintf(stderr, "Surface got syncDraw!\n");
+ qwm->endDraw(myname.c_str());
+ });
+ qwm->set_event_handler(QLibWindowmanager::Event_FlushDraw, [](json_object *object) {
+ fprintf(stderr, "Surface got flushDraw!\n");;
+ });
}
engine.load(QUrl(QStringLiteral("qrc:/MediaPlayer.qml")));
+ QObject *root = engine.rootObjects().first();
+ QQuickWindow *window = qobject_cast<QQuickWindow *>(root);
+ QObject::connect(window, SIGNAL(frameSwapped()),
+ qwm, SLOT(slotActivateSurface())); // This should be disconnected, but when...
return app.exec();
}
diff --git a/app/qlibwindowmanager.cpp b/app/qlibwindowmanager.cpp
new file mode 100644
index 0000000..7380bc8
--- /dev/null
+++ b/app/qlibwindowmanager.cpp
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "qlibwindowmanager.h"
+#include <unistd.h>
+
+int QLibWindowmanager::init(int port, const QString &token) {
+ std::string ctoken = token.toStdString();
+ return this->wm->init(port, ctoken.c_str());
+}
+
+int QLibWindowmanager::requestSurface(const char *label) {
+ applabel = label;
+ json_object *obj = json_object_new_object();
+ json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(label));
+ return this->wm->requestSurface(obj);
+}
+
+int QLibWindowmanager::activateSurface(const char *label) {
+ json_object *obj = json_object_new_object();
+ json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(label));
+ json_object_object_add(obj, wm->kKeyDrawingArea, json_object_new_string("normal.full"));
+ return this->wm->activateSurface(obj);
+}
+
+int QLibWindowmanager::deactivateSurface(const char *label) {
+ json_object *obj = json_object_new_object();
+ json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(label));
+ return this->wm->deactivateSurface(obj);
+}
+
+int QLibWindowmanager::endDraw(const char *label) {
+ json_object *obj = json_object_new_object();
+ json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(label));
+ return this->wm->endDraw(obj);
+ }
+
+void QLibWindowmanager::set_event_handler(enum QEventType et,
+ handler_fun f) {
+ LibWindowmanager::EventType wet = (LibWindowmanager::EventType)et;
+ return this->wm->set_event_handler(wet, std::move(f));
+}
+
+void QLibWindowmanager::slotActivateSurface(){
+ if(!isActive){
+ qDebug("Let's show radio");
+ isActive = true;
+ this->activateSurface(applabel.c_str());
+ }
+}
+
+QLibWindowmanager::QLibWindowmanager(QObject *parent)
+ :QObject(parent), isActive(false)
+{
+ wm = new LibWindowmanager();
+}
+
+QLibWindowmanager::~QLibWindowmanager() { }
diff --git a/app/qlibwindowmanager.h b/app/qlibwindowmanager.h
new file mode 100644
index 0000000..dd0694e
--- /dev/null
+++ b/app/qlibwindowmanager.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef QLIBWINDOWMANAGER_H
+#define QLIBWINDOWMANAGER_H
+#include <libwindowmanager.h>
+#include <functional>
+ #include <QObject>
+ #include <QUrl>
+ #include <QVariant>
+ #include <string>
+ #include <vector>
+
+class QLibWindowmanager : public QObject{
+Q_OBJECT
+public:
+ explicit QLibWindowmanager(QObject *parent = nullptr);
+ ~QLibWindowmanager();
+
+ QLibWindowmanager(const QLibWindowmanager &) = delete;
+ QLibWindowmanager &operator=(const QLibWindowmanager &) = delete;
+
+public:
+ using handler_fun = std::function<void(json_object *object)>;
+
+ enum QEventType {
+ Event_Active = 0,
+ Event_Inactive,
+
+ Event_Visible,
+ Event_Invisible,
+
+ Event_SyncDraw,
+ Event_FlushDraw,
+ };
+
+ static QLibWindowmanager &instance();
+
+ int init(int port, const QString &token);
+
+ // WM API
+ int requestSurface(const char *label);
+ int activateSurface(const char *label);
+ int deactivateSurface(const char *label);
+ int endDraw(const char *label);
+ void set_event_handler(enum QEventType et, handler_fun f);
+
+public slots:
+ void slotActivateSurface();
+
+private:
+ LibWindowmanager* wm;
+ std::string applabel;
+ std::vector<int> surfaceIDs;
+ bool isActive;
+
+};
+#endif // LIBWINDOWMANAGER_H
diff --git a/package/config.xml b/package/config.xml
index e8567c9..31e686a 100644
--- a/package/config.xml
+++ b/package/config.xml
@@ -8,6 +8,7 @@
<license>APL 2.0</license>
<feature name="urn:AGL:widget:required-api">
<param name="mediaplayer" value="ws" />
+ <param name="windowmanager" value="ws" />
<param name="Bluetooth-Manager" value="ws" />
</feature>
<feature name="urn:AGL:widget:required-permission">