Merge branch 'master' of https://github.com/highfidelity/hifi into commerce_zachsPunchlist2

This commit is contained in:
Zach Fox 2017-08-30 11:07:24 -07:00
commit e0878e7a3f
6 changed files with 44 additions and 20 deletions

View file

@ -183,7 +183,6 @@
#include "ui/UpdateDialog.h" #include "ui/UpdateDialog.h"
#include "ui/overlays/Overlays.h" #include "ui/overlays/Overlays.h"
#include "ui/DomainConnectionModel.h" #include "ui/DomainConnectionModel.h"
#include "ui/ImageProvider.h"
#include "Util.h" #include "Util.h"
#include "InterfaceParentFinder.h" #include "InterfaceParentFinder.h"
#include "ui/OctreeStatsProvider.h" #include "ui/OctreeStatsProvider.h"
@ -264,7 +263,7 @@ private:
switch ((int)event->type()) { switch ((int)event->type()) {
case ApplicationEvent::Render: case ApplicationEvent::Render:
render(); render();
// Ensure we never back up the render events. Each render should be triggered only in response // Ensure we never back up the render events. Each render should be triggered only in response
// to the NEXT render event after the last render occured // to the NEXT render event after the last render occured
QCoreApplication::removePostedEvents(this, ApplicationEvent::Render); QCoreApplication::removePostedEvents(this, ApplicationEvent::Render);
return true; return true;
@ -2246,8 +2245,6 @@ void Application::initializeUi() {
qApp->quit(); qApp->quit();
}); });
// register the pixmap image provider (used only for security image, for now)
engine->addImageProvider(ImageProvider::PROVIDER_NAME, new ImageProvider());
setupPreferences(); setupPreferences();
@ -5170,7 +5167,7 @@ void Application::update(float deltaTime) {
} }
} else { } else {
// update the rendering without any simulation // update the rendering without any simulation
getEntities()->update(false); getEntities()->update(false);
} }
// AvatarManager update // AvatarManager update

View file

@ -224,6 +224,12 @@ void initializeAESKeys(unsigned char* ivec, unsigned char* ckey, const QByteArra
memcpy(ckey, hash.data(), 32); memcpy(ckey, hash.data(), 32);
} }
Wallet::~Wallet() {
if (_securityImage) {
delete _securityImage;
}
}
void Wallet::setPassphrase(const QString& passphrase) { void Wallet::setPassphrase(const QString& passphrase) {
if (_passphrase) { if (_passphrase) {
delete _passphrase; delete _passphrase;
@ -411,6 +417,13 @@ QString Wallet::signWithKey(const QByteArray& text, const QString& key) {
return QString(); return QString();
} }
void Wallet::updateImageProvider() {
// inform the image provider. Note it doesn't matter which one you inform, as the
// images are statics
auto engine = DependencyManager::get<OffscreenUi>()->getSurfaceContext()->engine();
auto imageProvider = reinterpret_cast<ImageProvider*>(engine->imageProvider(ImageProvider::PROVIDER_NAME));
imageProvider->setSecurityImage(_securityImage);
}
void Wallet::chooseSecurityImage(const QString& filename) { void Wallet::chooseSecurityImage(const QString& filename) {
@ -431,10 +444,7 @@ void Wallet::chooseSecurityImage(const QString& filename) {
if (encryptFile(path, imageFilePath())) { if (encryptFile(path, imageFilePath())) {
qCDebug(commerce) << "emitting pixmap"; qCDebug(commerce) << "emitting pixmap";
// inform the image provider updateImageProvider();
auto engine = DependencyManager::get<OffscreenUi>()->getSurfaceContext()->engine();
auto imageProvider = reinterpret_cast<ImageProvider*>(engine->imageProvider(ImageProvider::PROVIDER_NAME));
imageProvider->setSecurityImage(_securityImage);
emit securityImageResult(true); emit securityImageResult(true);
} else { } else {
@ -460,10 +470,7 @@ void Wallet::getSecurityImage() {
_securityImage->loadFromData(data, dataLen, "jpg"); _securityImage->loadFromData(data, dataLen, "jpg");
qCDebug(commerce) << "created pixmap from encrypted file"; qCDebug(commerce) << "created pixmap from encrypted file";
// inform the image provider updateImageProvider();
auto engine = DependencyManager::get<OffscreenUi>()->getSurfaceContext()->engine();
auto imageProvider = reinterpret_cast<ImageProvider*>(engine->imageProvider(ImageProvider::PROVIDER_NAME));
imageProvider->setSecurityImage(_securityImage);
delete[] data; delete[] data;
emit securityImageResult(true); emit securityImageResult(true);

View file

@ -23,6 +23,8 @@ class Wallet : public QObject, public Dependency {
SINGLETON_DEPENDENCY SINGLETON_DEPENDENCY
public: public:
~Wallet();
// These are currently blocking calls, although they might take a moment. // These are currently blocking calls, although they might take a moment.
bool createIfNeeded(); bool createIfNeeded();
bool generateKeyPair(); bool generateKeyPair();
@ -48,6 +50,7 @@ private:
QByteArray _salt {"iamsalt!"}; QByteArray _salt {"iamsalt!"};
QString* _passphrase { new QString("pwd") }; QString* _passphrase { new QString("pwd") };
void updateImageProvider();
bool encryptFile(const QString& inputFilePath, const QString& outputFilePath); bool encryptFile(const QString& inputFilePath, const QString& outputFilePath);
bool decryptFile(const QString& inputFilePath, unsigned char** outputBufferPtr, int* outputBufferLen); bool decryptFile(const QString& inputFilePath, unsigned char** outputBufferPtr, int* outputBufferLen);
}; };

View file

@ -10,13 +10,24 @@
// //
#include "ImageProvider.h" #include "ImageProvider.h"
#include <QDebug>
#include <QReadLocker>
#include <QWriteLocker>
const QString ImageProvider::PROVIDER_NAME = "security"; const QString ImageProvider::PROVIDER_NAME = "security";
QReadWriteLock ImageProvider::_rwLock;
QPixmap* ImageProvider::_securityImage = nullptr;
void ImageProvider::setSecurityImage(QPixmap* pixmap) {
// no need to delete old one, that is managed by the wallet
QWriteLocker lock(&_rwLock);
_securityImage = pixmap;
}
QPixmap ImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) { QPixmap ImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) {
// adjust the internal pixmap to have the requested size // adjust the internal pixmap to have the requested size
QReadLocker lock(&_rwLock);
if (id == "securityImage" && _securityImage) { if (id == "securityImage" && _securityImage) {
*size = _securityImage->size(); *size = _securityImage->size();
if (requestedSize.width() > 0 && requestedSize.height() > 0) { if (requestedSize.width() > 0 && requestedSize.height() > 0) {

View file

@ -13,6 +13,7 @@
#define hifi_ImageProvider_h #define hifi_ImageProvider_h
#include <QQuickImageProvider> #include <QQuickImageProvider>
#include <QReadWriteLock>
class ImageProvider: public QQuickImageProvider { class ImageProvider: public QQuickImageProvider {
public: public:
@ -22,10 +23,10 @@ public:
QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override; QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override;
void setSecurityImage(QPixmap* pixmap) { _securityImage = pixmap; } void setSecurityImage(QPixmap* pixmap);
protected: protected:
QPixmap* _securityImage { nullptr }; static QReadWriteLock _rwLock;
static QPixmap* _securityImage;
}; };

View file

@ -6,6 +6,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "OffscreenQmlSurface.h" #include "OffscreenQmlSurface.h"
#include "ImageProvider.h"
// Has to come before Qt GL includes // Has to come before Qt GL includes
#include <gl/Config.h> #include <gl/Config.h>
@ -184,7 +185,7 @@ private:
GLuint texture = textureAndFence.first; GLuint texture = textureAndFence.first;
uvec2 size = _textureSizes[texture]; uvec2 size = _textureSizes[texture];
auto sizeKey = uvec2ToUint64(size); auto sizeKey = uvec2ToUint64(size);
// Textures can be returned after all surfaces of the given size have been destroyed, // Textures can be returned after all surfaces of the given size have been destroyed,
// in which case we just destroy the texture // in which case we just destroy the texture
if (!_textures.count(sizeKey)) { if (!_textures.count(sizeKey)) {
destroy(textureAndFence); destroy(textureAndFence);
@ -305,6 +306,9 @@ static size_t globalEngineRefCount{ 0 };
#endif #endif
void initializeQmlEngine(QQmlEngine* engine, QQuickWindow* window) { void initializeQmlEngine(QQmlEngine* engine, QQuickWindow* window) {
// register the pixmap image provider (used only for security image, for now)
engine->addImageProvider(ImageProvider::PROVIDER_NAME, new ImageProvider());
engine->setNetworkAccessManagerFactory(new QmlNetworkAccessManagerFactory); engine->setNetworkAccessManagerFactory(new QmlNetworkAccessManagerFactory);
auto importList = engine->importPathList(); auto importList = engine->importPathList();
importList.insert(importList.begin(), PathUtils::resourcesPath()); importList.insert(importList.begin(), PathUtils::resourcesPath());
@ -464,8 +468,8 @@ std::function<void(uint32_t, void*)> OffscreenQmlSurface::getDiscardLambda() {
} }
bool OffscreenQmlSurface::allowNewFrame(uint8_t fps) { bool OffscreenQmlSurface::allowNewFrame(uint8_t fps) {
// If we already have a pending texture, don't render another one // If we already have a pending texture, don't render another one
// i.e. don't render faster than the consumer context, since it wastes // i.e. don't render faster than the consumer context, since it wastes
// GPU cycles on producing output that will never be seen // GPU cycles on producing output that will never be seen
if (0 != _latestTextureAndFence.first) { if (0 != _latestTextureAndFence.first) {
return false; return false;
@ -526,6 +530,7 @@ void OffscreenQmlSurface::create() {
// Create a QML engine. // Create a QML engine.
auto qmlEngine = acquireEngine(_quickWindow); auto qmlEngine = acquireEngine(_quickWindow);
_qmlContext = new QQmlContext(qmlEngine->rootContext()); _qmlContext = new QQmlContext(qmlEngine->rootContext());
_qmlContext->setContextProperty("offscreenWindow", QVariant::fromValue(getWindow())); _qmlContext->setContextProperty("offscreenWindow", QVariant::fromValue(getWindow()));