2015-03-12 09:18:35 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
2020-04-18 03:39:50 -05:00
|
|
|
#pragma once
|
2015-03-12 09:18:35 -05:00
|
|
|
|
loolwsd: include cleanup and organization
A source file (.cpp) must include its own header first.
This insures that the header is self-contained and
doesn't depend on arbitrary (and accidental) includes
before it to compile.
Furthermore, system headers should go next, followed by
C then C++ headers, then libraries (Poco, etc) and, finally,
project headers come last.
This makes sure that headers and included in the same dependency
order to avoid side-effects. For example, Poco should never rely on
anything from our project in the same way that a C header should
never rely on anything in C++, Poco, or project headers.
Also, includes ought to be sorted where possible, to improve
readability and avoid accidental duplicates (of which there
were a few).
Change-Id: I62cc1343e4a091d69195e37ed659dba20cfcb1ef
Reviewed-on: https://gerrit.libreoffice.org/25262
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 09:23:07 -05:00
|
|
|
#include <iosfwd>
|
2015-03-12 09:18:35 -05:00
|
|
|
#include <memory>
|
2015-05-05 06:57:51 -05:00
|
|
|
#include <string>
|
2020-07-12 11:25:49 -05:00
|
|
|
#include <thread>
|
2019-02-15 14:55:47 -06:00
|
|
|
#include <unordered_map>
|
2022-03-25 13:32:01 -05:00
|
|
|
#include <unordered_set>
|
2015-03-12 09:18:35 -05:00
|
|
|
|
2018-05-31 13:20:09 -05:00
|
|
|
#include <Rectangle.hpp>
|
2016-05-15 16:50:32 -05:00
|
|
|
|
2022-03-25 13:32:01 -05:00
|
|
|
#include "Log.hpp"
|
|
|
|
#include "Common.hpp"
|
2016-05-21 08:41:23 -05:00
|
|
|
#include "TileDesc.hpp"
|
2016-04-15 10:24:00 -05:00
|
|
|
|
2016-05-16 19:49:36 -05:00
|
|
|
class ClientSession;
|
2016-04-15 10:24:00 -05:00
|
|
|
|
2020-07-12 11:25:49 -05:00
|
|
|
// The cache cares about only some properties.
|
|
|
|
struct TileDescCacheCompareEq final
|
2019-02-15 14:55:47 -06:00
|
|
|
{
|
2020-07-12 11:25:49 -05:00
|
|
|
inline bool operator()(const TileDesc& l, const TileDesc& r) const
|
2019-02-15 14:55:47 -06:00
|
|
|
{
|
2020-07-12 11:25:49 -05:00
|
|
|
return l.getPart() == r.getPart() &&
|
|
|
|
l.getWidth() == r.getWidth() &&
|
|
|
|
l.getHeight() == r.getHeight() &&
|
|
|
|
l.getTilePosX() == r.getTilePosX() &&
|
|
|
|
l.getTilePosY() == r.getTilePosY() &&
|
|
|
|
l.getTileWidth() == r.getTileWidth() &&
|
|
|
|
l.getTileHeight() == r.getTileHeight() &&
|
2022-08-30 00:27:44 -05:00
|
|
|
l.getNormalizedViewId() == r.getNormalizedViewId() &&
|
|
|
|
l.getEditMode() == r.getEditMode();
|
2019-02-15 14:55:47 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The cache cares about only some properties.
|
2020-07-12 11:25:49 -05:00
|
|
|
struct TileDescCacheHasher final
|
2019-02-15 14:55:47 -06:00
|
|
|
{
|
2020-07-12 11:25:49 -05:00
|
|
|
inline size_t operator()(const TileDesc& t) const
|
2019-02-15 14:55:47 -06:00
|
|
|
{
|
|
|
|
size_t hash = t.getPart();
|
|
|
|
|
2022-08-30 00:27:44 -05:00
|
|
|
hash = (hash << 5) + hash + t.getEditMode();
|
2019-02-15 14:55:47 -06:00
|
|
|
hash = (hash << 5) + hash + t.getWidth();
|
|
|
|
hash = (hash << 5) + hash + t.getHeight();
|
|
|
|
hash = (hash << 5) + hash + t.getTilePosX();
|
|
|
|
hash = (hash << 5) + hash + t.getTilePosY();
|
|
|
|
hash = (hash << 5) + hash + t.getTileWidth();
|
|
|
|
hash = (hash << 5) + hash + t.getTileHeight();
|
2019-11-09 23:09:00 -06:00
|
|
|
hash = (hash << 5) + hash + t.getNormalizedViewId();
|
2019-02-15 14:55:47 -06:00
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-11-13 05:49:35 -06:00
|
|
|
struct TileData
|
|
|
|
{
|
2022-03-25 13:32:01 -05:00
|
|
|
TileData(TileWireId start, const char *data, const size_t size)
|
2021-11-13 05:49:35 -06:00
|
|
|
{
|
2022-03-25 13:32:01 -05:00
|
|
|
appendBlob(start, data, size);
|
2021-11-13 05:49:35 -06:00
|
|
|
}
|
2022-03-25 13:32:01 -05:00
|
|
|
|
|
|
|
// Add a frame or delta and - return the size change
|
|
|
|
ssize_t appendBlob(TileWireId id, const char *data, const size_t dataSize)
|
|
|
|
{
|
2022-05-27 12:05:57 -05:00
|
|
|
size_t oldCacheSize = size();
|
2022-03-25 13:32:01 -05:00
|
|
|
|
|
|
|
assert (dataSize >= 1); // kit provides us a 'Z' or a 'D' or a png
|
|
|
|
if (isKeyframe(data, dataSize))
|
|
|
|
{
|
|
|
|
LOG_TRC("received key-frame - clearing tile");
|
|
|
|
_wids.clear();
|
2022-05-27 12:05:57 -05:00
|
|
|
_offsets.clear();
|
2022-03-25 13:32:01 -05:00
|
|
|
_deltas.clear();
|
|
|
|
}
|
|
|
|
else
|
2022-06-16 08:18:02 -05:00
|
|
|
{
|
2022-03-25 13:32:01 -05:00
|
|
|
LOG_TRC("received delta of size " << dataSize << " - appending to existing " << _wids.size());
|
2023-02-13 16:13:24 -06:00
|
|
|
// Issues #5532 and #5831 Replace assert with a log message
|
|
|
|
// Remove assert and allow delta messages to be handled even if
|
|
|
|
// there is no keyframe. Although it might make sense to skip
|
|
|
|
// delta messages if there is no keyframe, that causes some
|
|
|
|
// content, at least in Impress documents, to not render.
|
|
|
|
if (!_wids.size())
|
|
|
|
LOG_DBG("no underlying keyframe!");
|
2022-06-16 08:18:02 -05:00
|
|
|
}
|
2022-03-25 13:32:01 -05:00
|
|
|
|
2022-05-27 12:05:57 -05:00
|
|
|
size_t oldSize = size();
|
|
|
|
|
|
|
|
// FIXME: too many/large deltas means we should reset -
|
2022-03-25 13:32:01 -05:00
|
|
|
// but not here - when requesting the tiles.
|
|
|
|
_wids.push_back(id);
|
2022-05-27 12:05:57 -05:00
|
|
|
_offsets.push_back(_deltas.size());
|
|
|
|
_deltas.resize(oldSize + dataSize - 1);
|
|
|
|
std::memcpy(_deltas.data() + oldSize, data + 1, dataSize - 1);
|
2022-03-25 13:32:01 -05:00
|
|
|
|
|
|
|
// FIXME: possible race - should store a seq. from the invalidation(s) ?
|
|
|
|
_valid = true;
|
|
|
|
|
2022-05-27 12:05:57 -05:00
|
|
|
return size() - oldCacheSize;
|
2022-03-25 13:32:01 -05:00
|
|
|
}
|
|
|
|
|
2022-05-27 12:05:57 -05:00
|
|
|
bool isPng() const { return (_deltas.size() > 1 &&
|
|
|
|
_deltas[0] == (char)0x89); }
|
2022-03-25 13:32:01 -05:00
|
|
|
|
|
|
|
static bool isKeyframe(const char *data, size_t dataSize)
|
|
|
|
{
|
|
|
|
// keyframe or png
|
|
|
|
return dataSize > 0 && (data[0] == 'Z' || data[0] == (char)0x89);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isValid() const { return _valid; }
|
|
|
|
void invalidate() { _valid = false; }
|
|
|
|
|
|
|
|
bool _valid; // not true - waiting for a new tile if in view.
|
|
|
|
std::vector<TileWireId> _wids;
|
2022-05-27 12:05:57 -05:00
|
|
|
std::vector<size_t> _offsets; // offset of the start of data
|
|
|
|
BlobData _deltas; // first item is a key-frame, followed by deltas at _offsets
|
2022-03-25 13:32:01 -05:00
|
|
|
|
2021-11-13 05:49:35 -06:00
|
|
|
size_t size()
|
|
|
|
{
|
2022-05-27 12:05:57 -05:00
|
|
|
return _deltas.size();
|
2022-03-25 13:32:01 -05:00
|
|
|
}
|
|
|
|
|
2022-05-27 12:05:57 -05:00
|
|
|
const BlobData &data()
|
2022-03-25 13:32:01 -05:00
|
|
|
{
|
2022-05-27 12:05:57 -05:00
|
|
|
return _deltas;
|
2022-03-25 13:32:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// if we send changes since this seq - do we need to first send the keyframe ?
|
|
|
|
bool needsKeyframe(TileWireId since)
|
|
|
|
{
|
|
|
|
return since < _wids[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool appendChangesSince(std::vector<char> &output, TileWireId since)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; since != 0 && i < _wids.size() && _wids[i] <= since; ++i);
|
|
|
|
|
|
|
|
if (i >= _wids.size())
|
|
|
|
{
|
2022-06-28 05:49:21 -05:00
|
|
|
// We don't throttle delta sending - yet the code thinks we do still.
|
|
|
|
// We just send all the deltas we have on top of the keyframe.
|
|
|
|
// LOG_WRN("odd outcome - requested for a later id " << since <<
|
|
|
|
// " than the last known: " << ((_wids.size() > 0) ? _wids.back() : -1));
|
2022-03-25 13:32:01 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-05-27 12:05:57 -05:00
|
|
|
size_t offset = _offsets[i];
|
|
|
|
if (i != _offsets.size() - 1)
|
|
|
|
LOG_TRC("appending from " << i << " to " << (_offsets.size() - 1) <<
|
|
|
|
" from wid: " << _wids[i] << " to wid: " << since <<
|
|
|
|
" from offset: " << offset << " to " << _deltas.size());
|
|
|
|
|
|
|
|
size_t extra = _deltas.size() - offset;
|
|
|
|
size_t dest = output.size();
|
2022-03-25 13:32:01 -05:00
|
|
|
output.resize(output.size() + extra);
|
|
|
|
|
2022-05-27 12:05:57 -05:00
|
|
|
std::memcpy(output.data() + dest, _deltas.data() + offset, extra);
|
|
|
|
return true;
|
2022-03-25 13:32:01 -05:00
|
|
|
}
|
2021-11-13 05:49:35 -06:00
|
|
|
}
|
2022-03-25 13:32:01 -05:00
|
|
|
|
|
|
|
void dumpState(std::ostream& os)
|
2021-11-13 05:49:35 -06:00
|
|
|
{
|
2022-03-25 13:32:01 -05:00
|
|
|
if (_wids.size() < 2)
|
|
|
|
os << "keyframe";
|
|
|
|
else {
|
|
|
|
os << "deltas: ";
|
|
|
|
for (size_t i = 0; i < _wids.size(); ++i)
|
|
|
|
{
|
2022-05-27 12:05:57 -05:00
|
|
|
os << i << ": " << _wids[i] << " -> " << _offsets[i] << " ";
|
2022-03-25 13:32:01 -05:00
|
|
|
}
|
|
|
|
}
|
2021-11-13 05:49:35 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
using Tile = std::shared_ptr<TileData>;
|
|
|
|
|
2016-05-21 08:41:23 -05:00
|
|
|
/// Handles the caching of tiles of one document.
|
2015-03-12 18:34:42 -05:00
|
|
|
class TileCache
|
2015-03-12 09:18:35 -05:00
|
|
|
{
|
2016-04-25 04:04:25 -05:00
|
|
|
struct TileBeingRendered;
|
|
|
|
|
2016-05-15 17:47:08 -05:00
|
|
|
std::shared_ptr<TileBeingRendered> findTileBeingRendered(const TileDesc& tile);
|
2016-04-25 04:04:25 -05:00
|
|
|
|
2015-03-12 18:34:42 -05:00
|
|
|
public:
|
2022-08-30 00:27:44 -05:00
|
|
|
typedef std::pair<int, int> PartModePair;
|
|
|
|
|
2015-08-04 13:37:05 -05:00
|
|
|
/// When the docURL is a non-file:// url, the timestamp has to be provided by the caller.
|
|
|
|
/// For file:// url's, it's ignored.
|
|
|
|
/// When it is missing for non-file:// url, it is assumed the document must be read, and no cached value used.
|
2020-07-12 11:25:49 -05:00
|
|
|
TileCache(std::string docURL, const std::chrono::system_clock::time_point& modifiedTime,
|
|
|
|
bool dontCache = false);
|
2016-03-26 06:50:13 -05:00
|
|
|
~TileCache();
|
2015-03-12 18:34:42 -05:00
|
|
|
|
2019-02-14 15:40:33 -06:00
|
|
|
/// Completely clear the cache contents.
|
|
|
|
void clear();
|
2017-04-12 13:04:30 -05:00
|
|
|
|
2016-03-25 21:56:18 -05:00
|
|
|
TileCache(const TileCache&) = delete;
|
2019-10-28 08:26:15 -05:00
|
|
|
TileCache& operator=(const TileCache&) = delete;
|
2016-03-25 21:56:18 -05:00
|
|
|
|
2016-05-22 13:31:18 -05:00
|
|
|
/// Subscribes if no subscription exists and returns the version number.
|
|
|
|
/// Otherwise returns 0 to signify a subscription exists.
|
2020-08-07 11:36:56 -05:00
|
|
|
void subscribeToTileRendering(const TileDesc& tile, const std::shared_ptr<ClientSession>& subscriber,
|
|
|
|
const std::chrono::steady_clock::time_point& now);
|
2016-04-15 10:24:00 -05:00
|
|
|
|
2016-08-30 22:15:44 -05:00
|
|
|
/// Cancels all tile requests by the given subscriber.
|
2016-10-29 20:15:00 -05:00
|
|
|
std::string cancelTiles(const std::shared_ptr<ClientSession>& subscriber);
|
2016-08-30 22:15:44 -05:00
|
|
|
|
2019-02-14 13:01:43 -06:00
|
|
|
/// Find the tile with this description
|
|
|
|
Tile lookupTile(const TileDesc& tile);
|
2016-04-15 10:24:00 -05:00
|
|
|
|
2020-07-12 11:25:49 -05:00
|
|
|
void saveTileAndNotify(const TileDesc& tile, const char* data, size_t size);
|
2016-04-23 11:11:11 -05:00
|
|
|
|
2019-02-15 14:55:47 -06:00
|
|
|
enum StreamType {
|
|
|
|
Font,
|
|
|
|
Style,
|
|
|
|
CmdValues,
|
|
|
|
Last
|
|
|
|
};
|
|
|
|
|
2017-01-17 09:42:31 -06:00
|
|
|
/// Get the content of a cache file.
|
|
|
|
/// @param content Valid only when the call returns true.
|
|
|
|
/// @return true when the file actually exists
|
2019-02-15 14:55:47 -06:00
|
|
|
bool getTextStream(StreamType type, const std::string& fileName, std::string& content);
|
2015-06-24 15:05:49 -05:00
|
|
|
|
2016-04-22 06:00:11 -05:00
|
|
|
// Save some text into a file in the cache directory
|
2022-06-05 17:37:03 -05:00
|
|
|
void saveTextStream(StreamType type, const std::string& fileName, const std::vector<char>& data);
|
2015-03-12 18:34:42 -05:00
|
|
|
|
2015-11-27 08:12:44 -06:00
|
|
|
// Saves a font / style / etc rendering
|
2019-02-15 14:55:47 -06:00
|
|
|
void saveStream(StreamType type, const std::string& name, const char* data, size_t size);
|
2015-11-27 08:12:44 -06:00
|
|
|
|
2021-11-08 13:48:14 -06:00
|
|
|
/// Return the data if we have it, or nothing.
|
|
|
|
Blob lookupCachedStream(StreamType type, const std::string& name);
|
2015-11-27 08:12:44 -06:00
|
|
|
|
2015-05-28 10:39:05 -05:00
|
|
|
// The tiles parameter is an invalidatetiles: message as sent by the child process
|
2019-10-15 07:35:35 -05:00
|
|
|
void invalidateTiles(const std::string& tiles, int normalizedViewId);
|
2015-05-28 10:39:05 -05:00
|
|
|
|
2018-05-31 13:20:09 -05:00
|
|
|
/// Parse invalidateTiles message to a part number and a rectangle of the invalidated area
|
2022-08-30 00:27:44 -05:00
|
|
|
static std::pair<PartModePair, Util::Rectangle> parseInvalidateMsg(const std::string& tiles);
|
2018-05-31 13:20:09 -05:00
|
|
|
|
2022-06-16 10:31:37 -05:00
|
|
|
/// Forget the tile being rendered if it is the latest version we expect.
|
|
|
|
void forgetTileBeingRendered(const TileDesc& descForKitReply,
|
|
|
|
const std::shared_ptr<TileCache::TileBeingRendered>& tileBeingRendered);
|
2019-03-02 12:26:08 -06:00
|
|
|
|
2020-08-07 11:36:56 -05:00
|
|
|
size_t countTilesBeingRenderedForSession(const std::shared_ptr<ClientSession>& session,
|
|
|
|
const std::chrono::steady_clock::time_point& now);
|
|
|
|
bool hasTileBeingRendered(const TileDesc& tileDesc, const std::chrono::steady_clock::time_point *now = nullptr) const;
|
2020-07-12 11:25:49 -05:00
|
|
|
|
2020-08-07 11:36:56 -05:00
|
|
|
int getTileBeingRenderedVersion(const TileDesc& tileDesc);
|
2018-09-26 15:15:26 -05:00
|
|
|
|
2019-10-28 08:26:15 -05:00
|
|
|
/// Set the high watermark for tilecache size
|
|
|
|
void setMaxCacheSize(size_t cacheSize);
|
|
|
|
|
|
|
|
/// Get the current memory use.
|
|
|
|
size_t getMemorySize() const { return _cacheSize; }
|
|
|
|
|
2019-02-15 13:42:00 -06:00
|
|
|
// Debugging bits ...
|
|
|
|
void dumpState(std::ostream& os);
|
2017-06-22 07:58:50 -05:00
|
|
|
void setThreadOwner(const std::thread::id &id) { _owner = id; }
|
|
|
|
void assertCorrectThread();
|
2019-10-28 08:26:15 -05:00
|
|
|
void assertCacheSize();
|
2017-06-22 07:58:50 -05:00
|
|
|
|
2016-05-01 08:30:31 -05:00
|
|
|
private:
|
2019-10-28 08:26:15 -05:00
|
|
|
void ensureCacheSize();
|
|
|
|
static size_t itemCacheSize(const Tile &tile);
|
|
|
|
|
2022-08-30 00:27:44 -05:00
|
|
|
void invalidateTiles(int part, int mode, int x, int y, int width, int height, int normalizedViewId);
|
2015-05-28 10:39:05 -05:00
|
|
|
|
2019-02-14 15:40:33 -06:00
|
|
|
/// Lookup tile in our cache.
|
2021-11-08 13:48:14 -06:00
|
|
|
Tile findTile(const TileDesc &desc);
|
2019-02-15 14:55:47 -06:00
|
|
|
|
|
|
|
static std::string cacheFileName(const TileDesc& tileDesc);
|
2022-08-30 00:27:44 -05:00
|
|
|
static bool parseCacheFileName(const std::string& fileName, int& part, int& mode,
|
|
|
|
int& width, int& height, int& tilePosX, int& tilePosY,
|
|
|
|
int& tileWidth, int& tileHeight, int& nviewid);
|
2015-06-24 15:05:49 -05:00
|
|
|
|
|
|
|
/// Extract location from fileName, and check if it intersects with [x, y, width, height].
|
2022-08-30 00:27:44 -05:00
|
|
|
static bool intersectsTile(const TileDesc &tileDesc, int part, int mode, int x, int y,
|
|
|
|
int width, int height, int normalizedViewId);
|
2015-06-24 15:05:49 -05:00
|
|
|
|
2022-03-25 13:32:01 -05:00
|
|
|
Tile saveDataToCache(const TileDesc& desc, const char* data, size_t size);
|
2020-07-12 11:25:49 -05:00
|
|
|
void saveDataToStreamCache(StreamType type, const std::string& fileName, const char* data,
|
|
|
|
size_t size);
|
2015-08-04 13:37:05 -05:00
|
|
|
|
2016-03-26 06:50:13 -05:00
|
|
|
const std::string _docURL;
|
2015-06-24 15:05:49 -05:00
|
|
|
|
2017-06-22 07:58:50 -05:00
|
|
|
std::thread::id _owner;
|
2016-04-15 10:24:00 -05:00
|
|
|
|
2020-07-14 10:47:36 -05:00
|
|
|
const bool _dontCache;
|
2019-10-28 08:26:15 -05:00
|
|
|
|
|
|
|
/// Approximate size of tilecache in bytes
|
|
|
|
size_t _cacheSize;
|
|
|
|
|
|
|
|
/// Maximum (high watermark) size of the tilecache in bytes
|
|
|
|
size_t _maxCacheSize;
|
|
|
|
|
2019-02-15 14:55:47 -06:00
|
|
|
// FIXME: should we have a tile-desc to WID map instead and a simpler lookup ?
|
2020-07-12 11:25:49 -05:00
|
|
|
std::unordered_map<TileDesc, Tile,
|
|
|
|
TileDescCacheHasher,
|
|
|
|
TileDescCacheCompareEq> _cache;
|
2019-02-15 14:55:47 -06:00
|
|
|
// FIXME: TileBeingRendered contains TileDesc too ...
|
2020-07-12 11:25:49 -05:00
|
|
|
std::unordered_map<TileDesc, std::shared_ptr<TileBeingRendered>,
|
|
|
|
TileDescCacheHasher,
|
|
|
|
TileDescCacheCompareEq> _tilesBeingRendered;
|
2019-02-15 14:55:47 -06:00
|
|
|
|
|
|
|
// old-style file-name to data grab-bag.
|
2021-11-08 13:48:14 -06:00
|
|
|
std::map<std::string, Blob> _streamCache[static_cast<int>(StreamType::Last)];
|
2015-03-12 09:18:35 -05:00
|
|
|
};
|
|
|
|
|
2022-03-25 13:32:01 -05:00
|
|
|
/// Tracks view-port area tiles to track which we last
|
|
|
|
/// sent to avoid re-sending an existing delta causing grief
|
|
|
|
class ClientDeltaTracker final {
|
|
|
|
public:
|
|
|
|
// FIXME: could be a simple 2d TileWireId array for better packing.
|
|
|
|
std::unordered_set<TileDesc,
|
|
|
|
TileDescCacheHasher,
|
|
|
|
TileDescCacheCompareEq> _cache;
|
|
|
|
ClientDeltaTracker() {
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: only need to store this for the current viewports
|
|
|
|
void updateViewPort( /* ... */ )
|
|
|
|
{
|
|
|
|
// copy the set to another while filtering I guess.
|
|
|
|
}
|
|
|
|
|
|
|
|
/// return wire-id of last tile sent - or 0 if not present
|
|
|
|
/// update last-tile sent wire-id to curSeq if found.
|
|
|
|
TileWireId updateTileSeq(const TileDesc &desc)
|
|
|
|
{
|
|
|
|
auto it = _cache.find(desc);
|
|
|
|
if (it == _cache.end())
|
|
|
|
{
|
|
|
|
_cache.insert(desc);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const TileWireId curSeq = desc.getWireId();
|
|
|
|
TileWireId last = it->getWireId();
|
|
|
|
// id is not included in the hash.
|
|
|
|
auto pDesc = const_cast<TileDesc *>(&(*it));
|
|
|
|
pDesc->setWireId(curSeq);
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
|
|
|
void resetTileSeq(const TileDesc &desc)
|
|
|
|
{
|
|
|
|
auto it = _cache.find(desc);
|
|
|
|
if (it == _cache.end())
|
|
|
|
return;
|
|
|
|
// id is not included in the hash.
|
|
|
|
auto pDesc = const_cast<TileDesc *>(&(*it));
|
|
|
|
pDesc->setWireId(0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-11-13 05:49:35 -06:00
|
|
|
inline std::ostream& operator<< (std::ostream& os, const Tile& tile)
|
2021-11-08 13:48:14 -06:00
|
|
|
{
|
|
|
|
if (!tile)
|
|
|
|
os << "nullptr";
|
2022-03-25 13:32:01 -05:00
|
|
|
else
|
|
|
|
os << "keyframe id " << tile->_wids[0] <<
|
2022-05-27 12:05:57 -05:00
|
|
|
" size: " << tile->_deltas.size() <<
|
2022-03-25 13:32:01 -05:00
|
|
|
" deltas: " << (tile->_wids.size() - 1);
|
2021-11-08 13:48:14 -06:00
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2015-03-12 09:18:35 -05:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|