Cache background quickly if no buttons pressed.

This commit is contained in:
John Preston 2021-08-13 19:31:55 +03:00
parent 2667bb3568
commit 2b46f87d7b
2 changed files with 13 additions and 4 deletions

View File

@ -64,13 +64,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_dialogs.h" #include "styles/style_dialogs.h"
#include "styles/style_layers.h" // st::boxLabel #include "styles/style_layers.h" // st::boxLabel
#include <QtGui/QGuiApplication>
namespace Window { namespace Window {
namespace { namespace {
constexpr auto kMaxChatEntryHistorySize = 50; constexpr auto kMaxChatEntryHistorySize = 50;
constexpr auto kCacheBackgroundTimeout = 3 * crl::time(1000);
// Cache background scaled image after 3s. constexpr auto kCacheBackgroundFastTimeout = crl::time(200);
constexpr auto kCacheBackgroundTimeout = 3000;
} // namespace } // namespace
@ -1324,7 +1325,8 @@ CachedBackground SessionController::cachedBackground(QRect area) {
} }
if (_willCacheForArea != area || !_cacheBackgroundTimer.isActive()) { if (_willCacheForArea != area || !_cacheBackgroundTimer.isActive()) {
_willCacheForArea = area; _willCacheForArea = area;
_cacheBackgroundTimer.callOnce(kCacheBackgroundTimeout); _lastAreaChangeTime = crl::now();
_cacheBackgroundTimer.callOnce(kCacheBackgroundFastTimeout);
} }
return {}; return {};
} }
@ -1334,6 +1336,12 @@ void SessionController::cacheBackground() {
if (background->colorForFill()) { if (background->colorForFill()) {
return; return;
} }
const auto now = crl::now();
if (now - _lastAreaChangeTime < kCacheBackgroundTimeout
&& QGuiApplication::mouseButtons() != 0) {
_cacheBackgroundTimer.callOnce(kCacheBackgroundFastTimeout);
return;
}
const auto gradient = background->gradientForFill(); const auto gradient = background->gradientForFill();
const auto patternOpacity = background->paper().patternOpacity(); const auto patternOpacity = background->paper().patternOpacity();
const auto &bg = background->pixmap(); const auto &bg = background->pixmap();

View File

@ -463,6 +463,7 @@ private:
CachedBackground _cachedBackground; CachedBackground _cachedBackground;
QRect _willCacheForArea; QRect _willCacheForArea;
crl::time _lastAreaChangeTime = 0;
base::Timer _cacheBackgroundTimer; base::Timer _cacheBackgroundTimer;
rpl::lifetime _lifetime; rpl::lifetime _lifetime;