Skip to content

Commit f95d465

Browse files
committed
store a map of uniq image descriptions
1 parent 26fb063 commit f95d465

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

src/protocols/ColorManagement.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
using namespace NColorManagement;
1010

11-
static uint64_t lastImageID = 0; // FIXME use for deduplication
12-
1311
CColorManager::CColorManager(SP<CWpColorManagerV1> resource) : m_resource(resource) {
1412
if UNLIKELY (!good())
1513
return;
@@ -191,14 +189,13 @@ CColorManager::CColorManager(SP<CWpColorManagerV1> resource) : m_resource(resour
191189
}
192190

193191
RESOURCE->self = RESOURCE;
194-
RESOURCE->settings.id = ++lastImageID;
195192
RESOURCE->settings.windowsScRGB = true;
196193
RESOURCE->settings.primariesNamed = NColorManagement::CM_PRIMARIES_SRGB;
197194
RESOURCE->settings.primariesNameSet = true;
198195
RESOURCE->settings.primaries = NColorPrimaries::BT709;
199196
RESOURCE->settings.transferFunction = NColorManagement::CM_TRANSFER_FUNCTION_EXT_LINEAR;
200197
RESOURCE->settings.luminances.reference = 203;
201-
RESOURCE->resource()->sendReady(RESOURCE->settings.id);
198+
RESOURCE->resource()->sendReady(RESOURCE->settings.updateId());
202199
});
203200

204201
m_resource->setOnDestroy([this](CWpColorManagerV1* r) { PROTO::colorManagement->destroyResource(this); });
@@ -239,9 +236,7 @@ CColorManagementOutput::CColorManagementOutput(SP<CWpColorManagementOutputV1> re
239236
RESOURCE->m_resource->sendFailed(WP_IMAGE_DESCRIPTION_V1_CAUSE_NO_OUTPUT, "No output");
240237
else {
241238
RESOURCE->settings = m_monitor->imageDescription;
242-
if (RESOURCE->settings.id)
243-
RESOURCE->settings.id = ++lastImageID;
244-
RESOURCE->m_resource->sendReady(RESOURCE->settings.id); // FIXME: create correct id
239+
RESOURCE->m_resource->sendReady(RESOURCE->settings.updateId());
245240
}
246241
});
247242
}
@@ -383,10 +378,7 @@ CColorManagementFeedbackSurface::CColorManagementFeedbackSurface(SP<CWpColorMana
383378
m_currentPreferred = RESOURCE;
384379

385380
m_currentPreferred->settings = g_pCompositor->getPreferredImageDescription();
386-
if (!m_currentPreferred->settings.id)
387-
m_currentPreferred->settings.id = ++lastImageID;
388-
389-
RESOURCE->resource()->sendReady(++lastImageID); // FIXME: create correct id
381+
RESOURCE->resource()->sendReady(m_currentPreferred->settings.updateId());
390382
});
391383

392384
m_resource->setGetPreferredParametric([this](CWpColorManagementSurfaceFeedbackV1* r, uint32_t id) {
@@ -419,7 +411,7 @@ CColorManagementFeedbackSurface::CColorManagementFeedbackSurface(SP<CWpColorMana
419411
return;
420412
}
421413

422-
RESOURCE->resource()->sendReady(++lastImageID); // FIXME: create correct id
414+
RESOURCE->resource()->sendReady(m_currentPreferred->settings.updateId());
423415
});
424416
}
425417

@@ -467,8 +459,7 @@ CColorManagementIccCreator::CColorManagementIccCreator(SP<CWpImageDescriptionCre
467459

468460
RESOURCE->self = RESOURCE;
469461
RESOURCE->settings = settings;
470-
settings.id = ++lastImageID;
471-
RESOURCE->resource()->sendReady(settings.id); // FIXME: create correct id
462+
RESOURCE->resource()->sendReady(settings.updateId());
472463

473464
PROTO::colorManagement->destroyResource(this);
474465
});
@@ -522,8 +513,7 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CWpImage
522513

523514
RESOURCE->self = RESOURCE;
524515
RESOURCE->settings = settings;
525-
settings.id = ++lastImageID;
526-
RESOURCE->resource()->sendReady(settings.id); // FIXME: create correct id
516+
RESOURCE->resource()->sendReady(settings.updateId());
527517

528518
PROTO::colorManagement->destroyResource(this);
529519
});

src/protocols/types/ColorManagement.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#include "ColorManagement.hpp"
2+
#include <map>
23

34
namespace NColorManagement {
4-
const SPCPRimaries& getPrimaries(ePrimaries name) {
5+
static uint32_t lastImageID = 0;
6+
static std::map<SImageDescription, uint32_t> knownDescriptionIds; // expected to be small1
7+
8+
const SPCPRimaries& getPrimaries(ePrimaries name) {
59
switch (name) {
610
case CM_PRIMARIES_SRGB: return NColorPrimaries::BT709;
711
case CM_PRIMARIES_BT2020: return NColorPrimaries::BT2020;
@@ -17,4 +21,23 @@ namespace NColorManagement {
1721
}
1822
}
1923

24+
uint32_t SImageDescription::findId() const {
25+
const auto known = knownDescriptionIds.find(*this);
26+
if (known != knownDescriptionIds.end())
27+
return known->second;
28+
else {
29+
const auto newId = ++lastImageID;
30+
knownDescriptionIds.insert(std::make_pair(*this, newId));
31+
return newId;
32+
}
33+
}
34+
35+
uint32_t SImageDescription::getId() const {
36+
return id > 0 ? id : findId();
37+
}
38+
39+
uint32_t SImageDescription::updateId() {
40+
id = findId();
41+
return id;
42+
}
2043
}

src/protocols/types/ColorManagement.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,5 +217,9 @@ namespace NColorManagement {
217217
default: return SDR_MAX_LUMINANCE;
218218
}
219219
};
220+
221+
uint32_t findId() const;
222+
uint32_t getId() const;
223+
uint32_t updateId();
220224
};
221225
}

0 commit comments

Comments
 (0)