From c0660329a378b9b7e1ab7d4abb62b5b5cd11fe6f Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 17 Sep 2019 18:06:08 -0700 Subject: [PATCH] Exposing the REsource Caches through a bit of ui, adding MaterialCache to the family --- interface/src/Application.cpp | 6 +- .../src/RenderableModelEntityItem.cpp | 1 + .../MaterialCacheScriptingInterface.cpp | 17 +++ .../MaterialCacheScriptingInterface.h | 51 ++++++++ scripts/developer/utilities/cache/cash.js | 66 ++++++++++ scripts/developer/utilities/cache/cash.qml | 80 ++++++++++++ .../cache/cash/AnimationCacheInspector.qml | 20 +++ .../cache/cash/MaterialCacheInspector.qml | 20 +++ .../cache/cash/ModelCacheInspector.qml | 20 +++ .../developer/utilities/cache/cash/Page.js | 90 +++++++++++++ .../cache/cash/ResourceCacheInspector.qml | 122 ++++++++++++++++++ .../cache/cash/SoundCacheInspector.qml | 20 +++ .../cache/cash/TextureCacheInspector.qml | 20 +++ scripts/developer/utilities/cache/cash/qmldir | 6 + scripts/developer/utilities/lib/prop/qmldir | 1 + .../utilities/lib/prop/style/PiButton.qml | 32 +++++ 16 files changed, 571 insertions(+), 1 deletion(-) create mode 100644 libraries/material-networking/src/material-networking/MaterialCacheScriptingInterface.cpp create mode 100644 libraries/material-networking/src/material-networking/MaterialCacheScriptingInterface.h create mode 100644 scripts/developer/utilities/cache/cash.js create mode 100644 scripts/developer/utilities/cache/cash.qml create mode 100644 scripts/developer/utilities/cache/cash/AnimationCacheInspector.qml create mode 100644 scripts/developer/utilities/cache/cash/MaterialCacheInspector.qml create mode 100644 scripts/developer/utilities/cache/cash/ModelCacheInspector.qml create mode 100644 scripts/developer/utilities/cache/cash/Page.js create mode 100644 scripts/developer/utilities/cache/cash/ResourceCacheInspector.qml create mode 100644 scripts/developer/utilities/cache/cash/SoundCacheInspector.qml create mode 100644 scripts/developer/utilities/cache/cash/TextureCacheInspector.qml create mode 100644 scripts/developer/utilities/cache/cash/qmldir create mode 100644 scripts/developer/utilities/lib/prop/style/PiButton.qml diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b719f26c68..be2519e4ea 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -105,8 +105,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -885,6 +885,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); @@ -2908,6 +2909,7 @@ Application::~Application() { DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); + DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); @@ -3433,6 +3435,7 @@ void Application::onDesktopRootContextCreated(QQmlContext* surfaceContext) { // Caches surfaceContext->setContextProperty("AnimationCache", DependencyManager::get().data()); surfaceContext->setContextProperty("TextureCache", DependencyManager::get().data()); + surfaceContext->setContextProperty("MaterialCache", DependencyManager::get().data()); surfaceContext->setContextProperty("ModelCache", DependencyManager::get().data()); surfaceContext->setContextProperty("SoundCache", DependencyManager::get().data()); @@ -7563,6 +7566,7 @@ void Application::registerScriptEngineWithApplicationServices(const ScriptEngine // Caches scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get().data()); scriptEngine->registerGlobalObject("TextureCache", DependencyManager::get().data()); + scriptEngine->registerGlobalObject("MaterialCache", DependencyManager::get().data()); scriptEngine->registerGlobalObject("ModelCache", DependencyManager::get().data()); scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get().data()); diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index a6325c243d..a91d07947a 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -41,6 +41,7 @@ void ModelEntityWrapper::setModel(const ModelPointer& model) { if (_model) { _needsInitialSimulation = true; } + } }); } diff --git a/libraries/material-networking/src/material-networking/MaterialCacheScriptingInterface.cpp b/libraries/material-networking/src/material-networking/MaterialCacheScriptingInterface.cpp new file mode 100644 index 0000000000..193d9b96ee --- /dev/null +++ b/libraries/material-networking/src/material-networking/MaterialCacheScriptingInterface.cpp @@ -0,0 +1,17 @@ +// +// MaterialCacheScriptingInterface.cpp +// libraries/mmodel-networking/src/model-networking +// +// Created by Sam Gateau on 17 September 2019. +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "MaterialCacheScriptingInterface.h" + +MaterialCacheScriptingInterface::MaterialCacheScriptingInterface() : + ScriptableResourceCache::ScriptableResourceCache(DependencyManager::get()) +{ } + diff --git a/libraries/material-networking/src/material-networking/MaterialCacheScriptingInterface.h b/libraries/material-networking/src/material-networking/MaterialCacheScriptingInterface.h new file mode 100644 index 0000000000..c619966a2a --- /dev/null +++ b/libraries/material-networking/src/material-networking/MaterialCacheScriptingInterface.h @@ -0,0 +1,51 @@ +// +// MaterialCacheScriptingInterface.h +// libraries/material-networking/src/material-networking +// +// Created by Sam Gateau on 17 September 2019. +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#pragma once + +#ifndef hifi_MaterialCacheScriptingInterface_h +#define hifi_MaterialCacheScriptingInterface_h + +#include + +#include + +#include "MaterialCache.h" + +class MaterialCacheScriptingInterface : public ScriptableResourceCache, public Dependency { + Q_OBJECT + + // Properties are copied over from ResourceCache (see ResourceCache.h for reason). + + /**jsdoc + * The TextureCache API manages texture cache resources. + * + * @namespace TextureCache + * + * @hifi-interface + * @hifi-client-entity + * @hifi-avatar + * + * @property {number} numTotal - Total number of total resources. Read-only. + * @property {number} numCached - Total number of cached resource. Read-only. + * @property {number} sizeTotal - Size in bytes of all resources. Read-only. + * @property {number} sizeCached - Size in bytes of all cached resources. Read-only. + * + * @borrows ResourceCache.getResourceList as getResourceList + * @borrows ResourceCache.updateTotalSize as updateTotalSize + * @borrows ResourceCache.prefetch as prefetch + * @borrows ResourceCache.dirty as dirty + */ + +public: + MaterialCacheScriptingInterface(); +}; + +#endif // hifi_MaterialCacheScriptingInterface_h diff --git a/scripts/developer/utilities/cache/cash.js b/scripts/developer/utilities/cache/cash.js new file mode 100644 index 0000000000..078cd84218 --- /dev/null +++ b/scripts/developer/utilities/cache/cash.js @@ -0,0 +1,66 @@ +"use strict"; +var Page = Script.require('./cash/Page.js'); + +function openView() { + //window.closed.connect(function() { Script.stop(); }); + + + var pages = new Pages(); + function fromQml(message) { + console.log(JSON.stringify(message)) + if (pages.open(message.method)) { + return; + } + } + + var cashWindow + function openCashWindow(window) { + if (cashWindow !== undefined) { + activeWindow.fromQml.disconnect(fromQml); + } + if (window !== undefined) { + window.fromQml.connect(fromQml); + } + cashWindow = window; + + + var onMousePressEvent = function (e) { + }; + Controller.mousePressEvent.connect(onMousePressEvent); + + var onMouseReleaseEvent = function () { + }; + Controller.mouseReleaseEvent.connect(onMouseReleaseEvent); + + var onMouseMoveEvent = function (e) { + }; + Controller.mouseMoveEvent.connect(onMouseMoveEvent); + } + + function closeCashWindow() { + if (cashWindow !== undefined) { + activeWindow.fromQml.disconnect(fromQml); + } + cashWindow = {}; + + Controller.mousePressEvent.disconnect(onMousePressEvent); + Controller.mouseReleaseEvent.disconnect(onMouseReleaseEvent); + Controller.mouseMoveEvent.disconnect(onMouseMoveEvent); + pages.clear(); + } + + pages.addPage('Cash', 'Cash', "../cash.qml", 300, 420, openCashWindow, closeCashWindow); + pages.addPage('openModelCacheInspector', 'Model Cache Inspector', "./ModelCacheInspector.qml", 300, 500); + pages.addPage('openMaterialCacheInspector', 'Material Cache Inspector', "./MaterialCacheInspector.qml", 300, 500); + pages.addPage('openTextureCacheInspector', 'Texture Cache Inspector', "./TextureCacheInspector.qml", 300, 500); + pages.addPage('openAnimationCacheInspector', 'Animation Cache Inspector', "./AnimationCacheInspector.qml", 300, 500); + pages.addPage('openSoundCacheInspector', 'Sound Cache Inspector', "./SoundCacheInspector.qml", 300, 500); + + pages.open('Cash'); + + + return pages; +} + + +openView(); diff --git a/scripts/developer/utilities/cache/cash.qml b/scripts/developer/utilities/cache/cash.qml new file mode 100644 index 0000000000..a6551f117e --- /dev/null +++ b/scripts/developer/utilities/cache/cash.qml @@ -0,0 +1,80 @@ +// +// cash.qml +// +// Created by Sam Gateau on 17/9/2019 +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// +import QtQuick 2.7 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.3 + +import controlsUit 1.0 as HifiControls + +import "../lib/prop" as Prop +import "cash" + +Rectangle { + anchors.fill: parent + id: root; + + Prop.Global { id: global;} + color: global.color + + ScrollView { + id: scrollView + anchors.fill: parent + contentWidth: parent.width + clip: true + + Column { + id: column + width: parent.width + Prop.PropFolderPanel { + label: "Cache Inspectors" + isUnfold: true + panelFrameData: Component { + Column { + Prop.PropButton { + text: "Model" + onClicked: { + sendToScript({method: "openModelCacheInspector"}); + } + width:column.width + } + Prop.PropButton { + text: "Material" + onClicked: { + sendToScript({method: "openMaterialCacheInspector"}); + } + width:column.width + } + Prop.PropButton { + text: "Texture" + onClicked: { + sendToScript({method: "openTextureCacheInspector"}); + } + width:column.width + } + Prop.PropButton { + text: "Animation" + onClicked: { + sendToScript({method: "openAnimationCacheInspector"}); + } + width:column.width + } + Prop.PropButton { + text: "Sound" + onClicked: { + sendToScript({method: "openSoundCacheInspector"}); + } + width:column.width + } + } + } + } + } + } +} \ No newline at end of file diff --git a/scripts/developer/utilities/cache/cash/AnimationCacheInspector.qml b/scripts/developer/utilities/cache/cash/AnimationCacheInspector.qml new file mode 100644 index 0000000000..1a9fc822fa --- /dev/null +++ b/scripts/developer/utilities/cache/cash/AnimationCacheInspector.qml @@ -0,0 +1,20 @@ +// +// AnimationCacheInspector.qml +// +// Created by Sam Gateau on 2019-09-17 +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// +import QtQuick 2.7 +import QtQuick.Controls 2.5 +import QtQuick.Layouts 1.3 + +import "../../lib/prop" as Prop + +ResourceCacheInspector { + id: root; + anchors.fill: parent.fill + cache: AnimationCache +} diff --git a/scripts/developer/utilities/cache/cash/MaterialCacheInspector.qml b/scripts/developer/utilities/cache/cash/MaterialCacheInspector.qml new file mode 100644 index 0000000000..fcdd0cbed0 --- /dev/null +++ b/scripts/developer/utilities/cache/cash/MaterialCacheInspector.qml @@ -0,0 +1,20 @@ +// +// MaterialCacheInspector.qml +// +// Created by Sam Gateau on 2019-09-17 +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// +import QtQuick 2.7 +import QtQuick.Controls 2.5 +import QtQuick.Layouts 1.3 + +import "../../lib/prop" as Prop + +ResourceCacheInspector { + id: root; + anchors.fill: parent.fill + cache: MaterialCache +} diff --git a/scripts/developer/utilities/cache/cash/ModelCacheInspector.qml b/scripts/developer/utilities/cache/cash/ModelCacheInspector.qml new file mode 100644 index 0000000000..10615b2632 --- /dev/null +++ b/scripts/developer/utilities/cache/cash/ModelCacheInspector.qml @@ -0,0 +1,20 @@ +// +// ModelCacheInspector.qml +// +// Created by Sam Gateau on 2019-09-17 +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// +import QtQuick 2.7 +import QtQuick.Controls 2.5 +import QtQuick.Layouts 1.3 + +import "../../lib/prop" as Prop + +ResourceCacheInspector { + id: root; + anchors.fill: parent.fill + cache: ModelCache +} diff --git a/scripts/developer/utilities/cache/cash/Page.js b/scripts/developer/utilities/cache/cash/Page.js new file mode 100644 index 0000000000..06c9704abf --- /dev/null +++ b/scripts/developer/utilities/cache/cash/Page.js @@ -0,0 +1,90 @@ +// +// Page.js +// +// Sam Gateau, created on 4/19/2019 +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +"use strict"; + +(function() { +function Page(title, qmlurl, width, height, onViewCreated, onViewClosed) { + this.title = title; + this.qml = qmlurl; + this.width = width; + this.height = height; + this.onViewCreated = onViewCreated; + this.onViewClosed = onViewClosed; + + this.window; + + print("Page: New Page:" + JSON.stringify(this)); +} + +Page.prototype.killView = function () { + print("Page: Kill window for page:" + JSON.stringify(this)); + if (this.window) { + print("Page: Kill window for page:" + this.title); + //this.window.closed.disconnect(function () { + // this.killView(); + //}); + this.window.close(); + this.window = false; + } +}; + +Page.prototype.createView = function () { + var that = this; + if (!this.window) { + print("Page: New window for page:" + this.title); + this.window = Desktop.createWindow(Script.resolvePath(this.qml), { + title: this.title, + presentationMode: Desktop.PresentationMode.NATIVE, + size: {x: this.width, y: this.height} + }); + this.onViewCreated(this.window); + this.window.closed.connect(function () { + that.killView(); + that.onViewClosed(); + }); + } +}; + + +Pages = function () { + this._pages = {}; +}; + +Pages.prototype.addPage = function (command, title, qmlurl, width, height, onViewCreated, onViewClosed) { + if (onViewCreated === undefined) { + // Workaround for bad linter + onViewCreated = function(window) {}; + } + if (onViewClosed === undefined) { + // Workaround for bad linter + onViewClosed = function() {}; + } + this._pages[command] = new Page(title, qmlurl, width, height, onViewCreated, onViewClosed); +}; + +Pages.prototype.open = function (command) { + print("Pages: command = " + command); + if (!this._pages[command]) { + print("Pages: unknown command = " + command); + return; + } + this._pages[command].createView(); +}; + +Pages.prototype.clear = function () { + for (var p in this._pages) { + print("Pages: kill page: " + p); + this._pages[p].killView(); + delete this._pages[p]; + } + this._pages = {}; +}; + +}()); diff --git a/scripts/developer/utilities/cache/cash/ResourceCacheInspector.qml b/scripts/developer/utilities/cache/cash/ResourceCacheInspector.qml new file mode 100644 index 0000000000..a6b4c1df5d --- /dev/null +++ b/scripts/developer/utilities/cache/cash/ResourceCacheInspector.qml @@ -0,0 +1,122 @@ +// +// ResourceCacheInspector.qml +// +// Created by Sam Gateau on 2019-09-17 +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// +import QtQuick 2.7 +import QtQuick.Controls 2.5 +import QtQuick.Layouts 1.3 + +import "../../lib/prop" as Prop + +Item { + id: root; + anchors.fill: parent.fill + property var cache: {} + + function fromScript(message) { + switch (message.method) { + case "setJSON": + // jsonText.items = message.params.items; + break; + case "setItemList": + //console.log(message.params.items) + resouceItemsModel.resetItemList(message.params.items) + break; + case "resetItemList": + resetItemList() + break; + } + } + + Component.onCompleted: { + // if (cache !== undefined) { + resetItemList(); + // } + } + + function resetItemList() { + var theList = cache.getResourceList(); + resouceItemsModel.resetItemList(theList) + } + + ListModel { + id: resouceItemsModel + + function resetItemList(itemList) { + resouceItemsModel.clear() + for (var i in itemList) { + //resouceItemsModel.append({ "name": itemList[i]}) + resouceItemsModel.append({ "name": itemList[i].toString()}) + } + } + } + + Component { + id: resouceItemDelegate + Row { + id: itemRow + Prop.PropLabel { + text: model.name + } + } + } + + + Item { + id: header + + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + + + Prop.PropButton { + + anchors.left: parent.left + id: refresh + text: "Refresh" + onClicked: { + resetItemList() + } + } + + Prop.PropScalar { + id: totalCount + anchors.right: parent.right + label: "Count" + sourceValueVar: resouceItemsModel.count + integral: true + readOnly: true + } + + Prop.PropScalar { + id: totalCount + anchors.right: parent.right + label: "Count" + sourceValueVar: resouceItemsModel.count + integral: true + readOnly: true + } + + height: refresh.height + } + + + ScrollView { + anchors.top: header.bottom + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + clip: true + ListView { + id: listView + model: resouceItemsModel + delegate: resouceItemDelegate + } + } +} diff --git a/scripts/developer/utilities/cache/cash/SoundCacheInspector.qml b/scripts/developer/utilities/cache/cash/SoundCacheInspector.qml new file mode 100644 index 0000000000..2aef4efefd --- /dev/null +++ b/scripts/developer/utilities/cache/cash/SoundCacheInspector.qml @@ -0,0 +1,20 @@ +// +// SoundCacheInspector.qml +// +// Created by Sam Gateau on 2019-09-17 +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// +import QtQuick 2.7 +import QtQuick.Controls 2.5 +import QtQuick.Layouts 1.3 + +import "../../lib/prop" as Prop + +ResourceCacheInspector { + id: root; + anchors.fill: parent.fill + cache: SoundCache +} diff --git a/scripts/developer/utilities/cache/cash/TextureCacheInspector.qml b/scripts/developer/utilities/cache/cash/TextureCacheInspector.qml new file mode 100644 index 0000000000..a136ce6c47 --- /dev/null +++ b/scripts/developer/utilities/cache/cash/TextureCacheInspector.qml @@ -0,0 +1,20 @@ +// +// TextureCacheInspector.qml +// +// Created by Sam Gateau on 2019-09-17 +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// +import QtQuick 2.7 +import QtQuick.Controls 2.5 +import QtQuick.Layouts 1.3 + +import "../../lib/prop" as Prop + +ResourceCacheInspector { + id: root; + anchors.fill: parent.fill + cache: TextureCache +} diff --git a/scripts/developer/utilities/cache/cash/qmldir b/scripts/developer/utilities/cache/cash/qmldir new file mode 100644 index 0000000000..8793a6b8f5 --- /dev/null +++ b/scripts/developer/utilities/cache/cash/qmldir @@ -0,0 +1,6 @@ +ResourceCacheInspector 1.0 ResourceCacheInspector.qml +TextureCacheInspector 1.0 TextureCacheInspector.qml +MaterialCacheInspector 1.0 MaterialCacheInspector.qml +ModelCacheInspector 1.0 ModelCacheInspector.qml +AnimationCacheInspector 1.0 AnimationCacheInspector.qml +SoundCacheInspector 1.0 SoundCacheInspector.qml \ No newline at end of file diff --git a/scripts/developer/utilities/lib/prop/qmldir b/scripts/developer/utilities/lib/prop/qmldir index e09785846d..7d87c8a911 100644 --- a/scripts/developer/utilities/lib/prop/qmldir +++ b/scripts/developer/utilities/lib/prop/qmldir @@ -3,6 +3,7 @@ Global 1.0 style/Global.qml PropText 1.0 style/PiText.qml PropLabel 1.0 style/PiLabel.qml PropSplitter 1.0 style/PiSplitter.qml +PropButton 1.0 style/PiButton.qml PropComboBox 1.0 style/PiComboBox.qml PropCanvasIcon 1.0 style/PiCanvasIcon.qml PropCheckBox 1.0 style/PiCheckBox.qml diff --git a/scripts/developer/utilities/lib/prop/style/PiButton.qml b/scripts/developer/utilities/lib/prop/style/PiButton.qml new file mode 100644 index 0000000000..654d47e76d --- /dev/null +++ b/scripts/developer/utilities/lib/prop/style/PiButton.qml @@ -0,0 +1,32 @@ +// +// Prop/style/PiButton.qml +// +// Created by Sam Gateau on 17/09/2019 +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// + +import QtQuick 2.6 +import QtQuick.Controls 2.1 + +Button { + Global { id: global } + id: control + text: "" + spacing: 0 + + contentItem: PiText { + text: control.text + horizontalAlignment: Text.AlignHCenter + } + + background: Rectangle { + color: control.down ? global.colorBackHighlight : global.colorBackShadow + opacity: enabled ? 1 : 0.3 + border.color: control.down ? global.colorBorderHighight : (control.hovered ? global.colorBorderHighight : global.colorBorderLight) + border.width: global.valueBorderWidth + radius: global.valueBorderRadius + } +} \ No newline at end of file