Telltales: Rendering Safety-Critical UI

/**************************************************************************** ** ** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Safe Renderer module ** ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ ** 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 The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3 as published by the Free Software ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT ** included in the packaging of this file. Please review the following ** information to ensure the GNU General Public License requirements will ** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/
#include <QtGui> #include <QImage> #include <QtSafeRenderer/qsaferenderer.h> #include <QtSafeRenderer/qsafelayout.h> #include <QtSafeRenderer/qsafewindow.h> using namespace SafeRenderer; QT_USE_NAMESPACE class ScreenBuffer : public AbstractFrameBuffer { public: ScreenBuffer(const QSafeSize& size) : m_image(static_cast<int>(size.width()), static_cast<int>(size.height()), QImage::Format_RGBA8888) { } uchar *bits() { return m_image.bits(); } SafeRenderer::quint32 bytesPerLine() { return static_cast<SafeRenderer::quint32>(m_image.bytesPerLine()); } QImage image() { return m_image; } uchar bitsPerPixel() { return m_image.pixelFormat().bitsPerPixel(); } PixelFormat format() const { return PixelFormat::RGBA8888; } private: QImage m_image; }; class RasterWindow : public QWindow, public AbstractWindow { Q_OBJECT public: explicit RasterWindow(const QSafeSize &size, QWindow *parent = nullptr); virtual void render(QPainter *painter); //Window virtual void render(const Rect &dirtyArea) override; virtual AbstractFrameBuffer *buffer() override { return &m_buffer; } public slots: void renderLater(); void renderNow(); protected: bool event(QEvent *event) override; void resizeEvent(QResizeEvent *event) override; void exposeEvent(QExposeEvent *event) override; private: QBackingStore *m_backingStore; ScreenBuffer m_buffer; };