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

View File

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