Overte C++ Documentation
OffscreenQmlSurfaceCache.h
1 //
2 // Created by Bradley Austin Davis on 2017-01-11
3 // Copyright 2013-2017 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 #pragma once
9 #ifndef hifi_OffscreenQmlSurfaceCache_h
10 #define hifi_OffscreenQmlSurfaceCahce_h
11 
12 #include "DependencyManager.h"
13 
14 #include <QtCore/QSharedPointer>
15 
16 class QQmlContext;
17 class OffscreenQmlSurface;
18 
19 class OffscreenQmlSurfaceCache : public Dependency {
20  SINGLETON_DEPENDENCY
21 
22 public:
23  OffscreenQmlSurfaceCache();
24  virtual ~OffscreenQmlSurfaceCache();
25 
26  QSharedPointer<OffscreenQmlSurface> acquire(const QString& rootSource);
27  void release(const QString& rootSource, const QSharedPointer<OffscreenQmlSurface>& surface);
28  void reserve(const QString& rootSource, int count = 1);
29  void setOnRootContextCreated(const std::function<void(const QString& rootSource, QQmlContext* rootContext)> & onRootContextCreated);
30 
31 private:
32  QSharedPointer<OffscreenQmlSurface> buildSurface(const QString& rootSource);
33  QHash<QString, QList<QSharedPointer<OffscreenQmlSurface>>> _cache;
34  std::function<void(const QString& rootSource, QQmlContext* rootContext)> _onRootContextCreated;
35 };
36 
37 #endif