summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Janes <mark.a.janes@intel.com>2015-09-19 18:28:11 -0400
committerMark Janes <mark.a.janes@intel.com>2017-06-19 14:04:44 -0700
commit7e8c2ec4cbc9558aabf3f7729a5f14a73d45ce80 (patch)
tree33d63518eba1ddd1d5e0c2189d04f19b276e8322
parenta8dd28e281bcc59c5528ee109de45e8b453bb92b (diff)
add some first steps at executing bar graph
This commit provides a minimal QML application that displays a simple bar graph with 2 bars. The intention is to expand it as: - an interactive utility for testing features as they are added - a base to drive automated unit tests
-rw-r--r--retrace/daemon/bargraph/CMakeLists.txt20
-rw-r--r--retrace/daemon/bargraph/glframe_bargraph.cpp10
-rw-r--r--retrace/daemon/bargraph/glframe_bargraph.hpp8
-rw-r--r--retrace/daemon/bargraph/glframe_qbargraph.cpp17
-rw-r--r--retrace/daemon/bargraph/glframe_qbargraph.hpp4
-rw-r--r--retrace/daemon/bargraph/test/test_bargraph.cpp6
-rw-r--r--retrace/daemon/bargraph/ui/CMakeLists.txt54
-rw-r--r--retrace/daemon/bargraph/ui/main.cpp49
-rw-r--r--retrace/daemon/bargraph/ui/qml/mainwin.qml43
-rw-r--r--retrace/daemon/bargraph/ui/resources.qrc32
10 files changed, 235 insertions, 8 deletions
diff --git a/retrace/daemon/bargraph/CMakeLists.txt b/retrace/daemon/bargraph/CMakeLists.txt
index ae9a2560..5f0fd413 100644
--- a/retrace/daemon/bargraph/CMakeLists.txt
+++ b/retrace/daemon/bargraph/CMakeLists.txt
@@ -1,3 +1,22 @@
+# Copyright (c) 2015 Intel Corporation
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
include(../Lint.cmake)
include_directories (
@@ -37,3 +56,4 @@ add_library(retrace_bargraph STATIC
qt5_use_modules(retrace_bargraph Core Gui OpenGL Quick)
add_subdirectory(test)
+add_subdirectory(ui)
diff --git a/retrace/daemon/bargraph/glframe_bargraph.cpp b/retrace/daemon/bargraph/glframe_bargraph.cpp
index db0bc873..6e5652d4 100644
--- a/retrace/daemon/bargraph/glframe_bargraph.cpp
+++ b/retrace/daemon/bargraph/glframe_bargraph.cpp
@@ -41,13 +41,14 @@ BarGraphRenderer::vshader =
"attribute vec2 coord; \n"
"uniform float max_x; \n"
"uniform float max_y; \n"
+ "uniform float invert_y; \n"
"void main(void) { \n"
" /* normalize y */ \n"
" /* normalize x */ \n"
" mat2 normalize = mat2(2.0 / max_x , 0.0, 0.0, 2.0 / max_y); \n"
" vec2 translate = vec2(-1.0, -1.0); \n"
" vec2 pos = translate + normalize * coord; \n"
- " gl_Position = vec4(pos.x, pos.y, 0.0, 1.0); \n"
+ " gl_Position = vec4(pos.x, invert_y * pos.y, 0.0, 1.0); \n"
"}";
const char *
@@ -57,7 +58,8 @@ BarGraphRenderer::fshader =
" gl_FragColor = bar_color;"
"}";
-BarGraphRenderer::BarGraphRenderer() {
+BarGraphRenderer::BarGraphRenderer(bool invert)
+ : invert_y(invert ? -1 : 1) {
// generate vbo
GL::GenBuffers(1, &vbo);
GL_CHECK();
@@ -97,6 +99,8 @@ BarGraphRenderer::BarGraphRenderer() {
GL_CHECK();
uni_max_y = GL::GetUniformLocation(prog, "max_y");
GL_CHECK();
+ uni_invert_y = GL::GetUniformLocation(prog, "invert_y");
+ GL_CHECK();
uni_bar_color = GL::GetUniformLocation(prog, "bar_color");
GL_CHECK();
}
@@ -167,6 +171,8 @@ BarGraphRenderer::render() {
GL_CHECK();
GL::Uniform1f(uni_max_x, total_x);
GL_CHECK();
+ GL::Uniform1f(uni_invert_y, invert_y);
+ GL_CHECK();
const float color[4] = { .5, .5, .5, 1.0 };
GL::Uniform4f(uni_bar_color, color[0], color[1], color[2], color[3]);
GL_CHECK();
diff --git a/retrace/daemon/bargraph/glframe_bargraph.hpp b/retrace/daemon/bargraph/glframe_bargraph.hpp
index 57fd0e6d..2a089cec 100644
--- a/retrace/daemon/bargraph/glframe_bargraph.hpp
+++ b/retrace/daemon/bargraph/glframe_bargraph.hpp
@@ -1,4 +1,4 @@
-// Copyright (C) Intel Corp. 2014. All Rights Reserved.
+// Copyright (C) Intel Corp. 2015. All Rights Reserved.
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -53,7 +53,7 @@ class BarMetrics {
// - Independent of Qt
class BarGraphRenderer {
public:
- BarGraphRenderer();
+ explicit BarGraphRenderer(bool invert = false); // Qt draws top-to-bottom
void setBars(const std::vector<BarMetrics> &bars);
void setMouseArea(float x1, float y1, float x2, float y2);
void render();
@@ -61,14 +61,14 @@ class BarGraphRenderer {
private:
static const char *vshader, *fshader;
GLuint vbo;
- GLint att_coord, uni_max_x, uni_max_y, uni_bar_color, prog;
+ GLint att_coord, uni_max_x, uni_max_y, uni_invert_y, uni_bar_color, prog;
struct Vertex {
float x;
float y;
};
std::vector<Vertex> vertices;
- float max_y, total_x;
+ float max_y, total_x, invert_y;
};
} // namespace glretrace
diff --git a/retrace/daemon/bargraph/glframe_qbargraph.cpp b/retrace/daemon/bargraph/glframe_qbargraph.cpp
index fc6d4fd6..5fd04091 100644
--- a/retrace/daemon/bargraph/glframe_qbargraph.cpp
+++ b/retrace/daemon/bargraph/glframe_qbargraph.cpp
@@ -28,11 +28,24 @@
#include <QtOpenGL>
+#include <vector>
+
using glretrace::QBarGraphRenderer;
using glretrace::BarGraphView;
+using glretrace::BarMetrics;
+
+QBarGraphRenderer::QBarGraphRenderer() : m_graph(true) {
+ std::vector<BarMetrics> metrics(2);
+ metrics[0].metric1 = 1;
+ metrics[0].metric2 = 1;
+ metrics[1].metric1 = 2;
+ metrics[1].metric2 = 2;
+ m_graph.setBars(metrics);
+}
void
QBarGraphRenderer::render() {
+ m_graph.render();
}
void
@@ -51,3 +64,7 @@ QQuickFramebufferObject::Renderer *
BarGraphView::createRenderer() const {
return new QBarGraphRenderer();
}
+
+BarGraphView::BarGraphView() {
+}
+
diff --git a/retrace/daemon/bargraph/glframe_qbargraph.hpp b/retrace/daemon/bargraph/glframe_qbargraph.hpp
index 9224ff34..a55ed5f7 100644
--- a/retrace/daemon/bargraph/glframe_qbargraph.hpp
+++ b/retrace/daemon/bargraph/glframe_qbargraph.hpp
@@ -1,4 +1,4 @@
-// Copyright (C) Intel Corp. 2014. All Rights Reserved.
+// Copyright (C) Intel Corp. 2015. All Rights Reserved.
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -39,6 +39,7 @@ class QBarGraphRenderer : public QObject,
public QQuickFramebufferObject::Renderer,
NoCopy, NoAssign, NoMove {
public:
+ QBarGraphRenderer();
void render();
void synchronize(QQuickFramebufferObject * item);
// to ensure that we get a multisample fbo
@@ -53,6 +54,7 @@ class QBarGraphRenderer : public QObject,
class BarGraphView : public QQuickFramebufferObject,
NoCopy, NoAssign, NoMove {
public:
+ BarGraphView();
QQuickFramebufferObject::Renderer *createRenderer() const;
};
diff --git a/retrace/daemon/bargraph/test/test_bargraph.cpp b/retrace/daemon/bargraph/test/test_bargraph.cpp
index 0752272f..1c0e058c 100644
--- a/retrace/daemon/bargraph/test/test_bargraph.cpp
+++ b/retrace/daemon/bargraph/test/test_bargraph.cpp
@@ -62,9 +62,13 @@ TEST(BarGraph, MultiBar) {
GlFunctions::Init();
TestContext c;
BarGraphRenderer r;
- std::vector<BarMetrics> bars(2);
+ std::vector<BarMetrics> bars(3);
bars[0].metric1 = 25;
+ bars[0].metric2 = 5;
bars[1].metric1 = 37;
+ bars[1].metric2 = 10;
+ bars[2].metric1 = 7;
+ bars[2].metric2 = 2;
r.setBars(bars);
r.render();
diff --git a/retrace/daemon/bargraph/ui/CMakeLists.txt b/retrace/daemon/bargraph/ui/CMakeLists.txt
new file mode 100644
index 00000000..05799571
--- /dev/null
+++ b/retrace/daemon/bargraph/ui/CMakeLists.txt
@@ -0,0 +1,54 @@
+# Copyright (c) 2015 Intel Corporation
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+cmake_minimum_required(VERSION 2.8)
+
+include_directories (
+ ${CMAKE_SOURCE_DIR}/retrace/daemon/bargraph
+ )
+
+find_package(Qt5Widgets REQUIRED)
+find_package(Qt5Core REQUIRED)
+find_package(Qt5Gui REQUIRED)
+
+# Instruct CMake to run moc automatically when needed.
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_definitions(${Qt5Widgets_DEFINITIONS})
+
+qt5_add_resources(RESOURCE_ADDED_BG resources.qrc)
+
+add_executable(bargraph
+ main.cpp
+ ${UIS_HDRS}
+ ${RESOURCE_ADDED_BG}
+)
+
+qt5_use_modules(bargraph Core Gui Concurrent Quick)
+
+target_link_libraries(bargraph
+ retrace_bargraph
+ GL
+ ${X11_X11_LIB}
+ pthread
+ dl
+)
+
diff --git a/retrace/daemon/bargraph/ui/main.cpp b/retrace/daemon/bargraph/ui/main.cpp
new file mode 100644
index 00000000..de71e3ac
--- /dev/null
+++ b/retrace/daemon/bargraph/ui/main.cpp
@@ -0,0 +1,49 @@
+// Copyright (C) Intel Corp. 2015. All Rights Reserved.
+
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+
+// The above copyright notice and this permission notice (including the
+// next paragraph) shall be included in all copies or substantial
+// portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+// **********************************************************************/
+// * Authors:
+// * Mark Janes <mark.a.janes@intel.com>
+// **********************************************************************/
+
+#include <QGuiApplication>
+#include <QQmlApplicationEngine>
+#include <QtQml>
+
+#include "glframe_qbargraph.hpp"
+#include "glframe_glhelper.hpp"
+
+using glretrace::BarGraphView;
+using glretrace::GlFunctions;
+
+int main(int argc, char *argv[]) {
+ GlFunctions::Init();
+
+ QGuiApplication app(argc, argv);
+
+ qmlRegisterType<glretrace::BarGraphView>("ApiTrace", 1, 0, "BarGraph");
+
+ QQmlApplicationEngine engine(QUrl("qrc:///qml/mainwin.qml"));
+
+ int ret = app.exec();
+ return ret;
+}
diff --git a/retrace/daemon/bargraph/ui/qml/mainwin.qml b/retrace/daemon/bargraph/ui/qml/mainwin.qml
new file mode 100644
index 00000000..a3d85fea
--- /dev/null
+++ b/retrace/daemon/bargraph/ui/qml/mainwin.qml
@@ -0,0 +1,43 @@
+// Copyright (C) Intel Corp. 2015. All Rights Reserved.
+
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+
+// The above copyright notice and this permission notice (including the
+// next paragraph) shall be included in all copies or substantial
+// portions of the Software.
+
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+// **********************************************************************/
+// * Authors:
+// * Mark Janes <mark.a.janes@intel.com>
+// **********************************************************************/
+
+import QtQuick 2.2
+import QtQuick.Controls 1.1
+import QtQuick.Layouts 1.1
+import QtQuick.Dialogs 1.1
+import ApiTrace 1.0
+
+ApplicationWindow {
+ width: 600
+ height: 500
+ visible: true
+ id: mainWindow
+ BarGraph {
+ visible: true
+ anchors.fill: parent
+ }
+}
diff --git a/retrace/daemon/bargraph/ui/resources.qrc b/retrace/daemon/bargraph/ui/resources.qrc
new file mode 100644
index 00000000..59778ceb
--- /dev/null
+++ b/retrace/daemon/bargraph/ui/resources.qrc
@@ -0,0 +1,32 @@
+<!-- Copyright (C) Intel Corp. 2015. All Rights Reserved. -->
+
+<!-- Permission is hereby granted, free of charge, to any person obtaining -->
+<!-- a copy of this software and associated documentation files (the -->
+<!-- "Software"), to deal in the Software without restriction, including -->
+<!-- without limitation the rights to use, copy, modify, merge, publish, -->
+<!-- distribute, sublicense, and/or sell copies of the Software, and to -->
+<!-- permit persons to whom the Software is furnished to do so, subject to -->
+<!-- the following conditions: -->
+
+<!-- The above copyright notice and this permission notice (including the -->
+<!-- next paragraph) shall be included in all copies or substantial -->
+<!-- portions of the Software. -->
+
+<!-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -->
+<!-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -->
+<!-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -->
+<!-- IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE -->
+<!-- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -->
+<!-- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -->
+<!-- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -->
+
+<!-- **********************************************************************/ -->
+<!-- * Authors: -->
+<!-- * Mark Janes <mark.a.janes@intel.com> -->
+<!-- **********************************************************************/ -->
+
+<RCC>
+ <qresource prefix="/">
+ <file>qml/mainwin.qml</file>
+ </qresource>
+</RCC>