Skip to content

Commit

Permalink
If Icon backgrounds are turned off, don't waste time/memory actually …
Browse files Browse the repository at this point in the history
…calculating the backgrounds during render
  • Loading branch information
dkulp committed Nov 26, 2024
1 parent f06a1d2 commit b24ca35
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 53 deletions.
6 changes: 6 additions & 0 deletions xLights/RenderBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,9 @@ void RenderBuffer::SetDisplayListVRect(Effect *eff, int idx, float x1, float y1,
void RenderBuffer::SetDisplayListRect(Effect *eff, int idx, float x1, float y1, float x2, float y2,
const xlColor &cx1y1, const xlColor &cx1y2,
const xlColor &cx2y1, const xlColor &cx2y2) {
if (!eff->IsBackgroundDisplayListEnabled()) {
return;
}

xlColor* colorMask = eff->GetColorMask();
xlColor maskcx1y1 = cx1y1;
Expand Down Expand Up @@ -1568,6 +1571,9 @@ void RenderBuffer::SetDisplayListRect(Effect *eff, int idx, float x1, float y1,
}

void RenderBuffer::CopyPixelsToDisplayListX(Effect *eff, int row, int sx, int ex, int inc) {
if (!eff->IsBackgroundDisplayListEnabled()) {
return;
}
std::lock_guard<std::recursive_mutex> lock(eff->GetBackgroundDisplayList().lock);
int count = curEffEndPer - curEffStartPer + 1;

Expand Down
34 changes: 18 additions & 16 deletions xLights/effects/ColorWashEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,23 @@ void ColorWashEffect::Render(Effect *effect, const SettingsMap &SettingsMap, Ren
} else {
orig = xlBLACK;
}
std::unique_lock<std::recursive_mutex> lock(effect->GetBackgroundDisplayList().lock);
if (VertFade || HorizFade) {
effect->GetBackgroundDisplayList().resize((buffer.curEffEndPer - buffer.curEffStartPer + 1) * 6 * 2);
int total = buffer.curEffEndPer - buffer.curEffStartPer + 1;
double x1 = double(buffer.curPeriod - buffer.curEffStartPer) / double(total);
double x2 = (buffer.curPeriod - buffer.curEffStartPer + 1.0) / double(total);
int idx = (buffer.curPeriod - buffer.curEffStartPer) * 12;
buffer.SetDisplayListVRect(effect, idx, x1, 0.0, x2, 0.5,
xlBLACK, orig);
buffer.SetDisplayListVRect(effect, idx + 6, x1, 0.5, x2, 1.0,
orig, xlBLACK);
} else {
effect->GetBackgroundDisplayList().resize((buffer.curEffEndPer - buffer.curEffStartPer + 1) * 6);
int midX = (StartX + endX) / 2;
int midY = (StartY + endY) / 2;
buffer.CopyPixelsToDisplayListX(effect, midY, midX, midX);
if (effect->IsBackgroundDisplayListEnabled()) {
std::unique_lock<std::recursive_mutex> lock(effect->GetBackgroundDisplayList().lock);
if (VertFade || HorizFade) {
effect->GetBackgroundDisplayList().resize((buffer.curEffEndPer - buffer.curEffStartPer + 1) * 6 * 2);
int total = buffer.curEffEndPer - buffer.curEffStartPer + 1;
double x1 = double(buffer.curPeriod - buffer.curEffStartPer) / double(total);
double x2 = (buffer.curPeriod - buffer.curEffStartPer + 1.0) / double(total);
int idx = (buffer.curPeriod - buffer.curEffStartPer) * 12;
buffer.SetDisplayListVRect(effect, idx, x1, 0.0, x2, 0.5,
xlBLACK, orig);
buffer.SetDisplayListVRect(effect, idx + 6, x1, 0.5, x2, 1.0,
orig, xlBLACK);
} else {
effect->GetBackgroundDisplayList().resize((buffer.curEffEndPer - buffer.curEffStartPer + 1) * 6);
int midX = (StartX + endX) / 2;
int midY = (StartY + endY) / 2;
buffer.CopyPixelsToDisplayListX(effect, midY, midX, midX);
}
}
}
38 changes: 21 additions & 17 deletions xLights/effects/OnEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,24 +264,28 @@ void OnEffect::Render(Effect *eff, const SettingsMap &SettingsMap, RenderBuffer
}

if (shimmer || cycles != 1.0) {
std::lock_guard<std::recursive_mutex> lock(eff->GetBackgroundDisplayList().lock);
eff->GetBackgroundDisplayList().resize((buffer.curEffEndPer - buffer.curEffStartPer + 1) * 6);
buffer.CopyPixelsToDisplayListX(eff, 0, 0, 0);
if (eff->IsBackgroundDisplayListEnabled()) {
std::lock_guard<std::recursive_mutex> lock(eff->GetBackgroundDisplayList().lock);
eff->GetBackgroundDisplayList().resize((buffer.curEffEndPer - buffer.curEffStartPer + 1) * 6);
buffer.CopyPixelsToDisplayListX(eff, 0, 0, 0);
}
} else if (buffer.needToInit) {
std::lock_guard<std::recursive_mutex> lock(eff->GetBackgroundDisplayList().lock);
eff->GetBackgroundDisplayList().resize(6);
if (start == 100 && end == 100) {
buffer.palette.GetColor(0, color);
buffer.SetDisplayListHRect(eff, 0, 0.0, 0.0, 1.0, 1.0, color, color);
} else {
HSVValue hsv;
buffer.palette.GetHSV(cidx,hsv);
hsv.value = hsv.value * start / 100.0;
color = hsv;

buffer.palette.GetHSV(cidx,hsv);
hsv.value = hsv.value * end / 100.0;
buffer.SetDisplayListHRect(eff, 0, 0.0, 0.0, 1.0, 1.0, color, xlColor(hsv));
if (eff->IsBackgroundDisplayListEnabled()) {
std::lock_guard<std::recursive_mutex> lock(eff->GetBackgroundDisplayList().lock);
eff->GetBackgroundDisplayList().resize(6);
if (start == 100 && end == 100) {
buffer.palette.GetColor(0, color);
buffer.SetDisplayListHRect(eff, 0, 0.0, 0.0, 1.0, 1.0, color, color);
} else {
HSVValue hsv;
buffer.palette.GetHSV(cidx,hsv);
hsv.value = hsv.value * start / 100.0;
color = hsv;

buffer.palette.GetHSV(cidx,hsv);
hsv.value = hsv.value * end / 100.0;
buffer.SetDisplayListHRect(eff, 0, 0.0, 0.0, 1.0, 1.0, color, xlColor(hsv));
}
}
buffer.needToInit = false;
}
Expand Down
18 changes: 10 additions & 8 deletions xLights/effects/ServoEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,16 @@ void ServoEffect::Render(Effect* effect, const SettingsMap& SettingsMap, RenderB
}
}
}
std::unique_lock<std::recursive_mutex> lock(effect->GetBackgroundDisplayList().lock);
effect->GetBackgroundDisplayList().resize((buffer.curEffEndPer - buffer.curEffStartPer + 1) * 6);
int total = buffer.curEffEndPer - buffer.curEffStartPer + 1;
double x1 = double(buffer.curPeriod - buffer.curEffStartPer) / double(total);
double x2 = (buffer.curPeriod - buffer.curEffStartPer + 1.0) / double(total);
int idx = (buffer.curPeriod - buffer.curEffStartPer) * 6;
float pos = 1.0 - (position / 100.0);
buffer.SetDisplayListVRect(effect, idx, x1, pos - 0.02, x2, pos + 0.02, xlWHITE, xlWHITE);
if (effect->IsBackgroundDisplayListEnabled()) {
std::unique_lock<std::recursive_mutex> lock(effect->GetBackgroundDisplayList().lock);
effect->GetBackgroundDisplayList().resize((buffer.curEffEndPer - buffer.curEffStartPer + 1) * 6);
int total = buffer.curEffEndPer - buffer.curEffStartPer + 1;
double x1 = double(buffer.curPeriod - buffer.curEffStartPer) / double(total);
double x2 = (buffer.curPeriod - buffer.curEffStartPer + 1.0) / double(total);
int idx = (buffer.curPeriod - buffer.curEffStartPer) * 6;
float pos = 1.0 - (position / 100.0);
buffer.SetDisplayListVRect(effect, idx, x1, pos - 0.02, x2, pos + 0.02, xlWHITE, xlWHITE);
}
}

void ServoEffect::SetPanelStatus(Model* cls) {
Expand Down
35 changes: 27 additions & 8 deletions xLights/effects/SingleStrandEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,11 @@ void SingleStrandEffect::RenderSingleStrandSkips(RenderBuffer &buffer, Effect *e

if (buffer.needToInit) {
buffer.needToInit = false;
std::lock_guard<std::recursive_mutex> lock(eff->GetBackgroundDisplayList().lock);
int rects = (Skips_SkipSize + Skips_BandSize) * (buffer.curEffEndPer - buffer.curEffStartPer + 1);
eff->GetBackgroundDisplayList().resize(rects * 6);
if (eff->IsBackgroundDisplayListEnabled()) {
std::lock_guard<std::recursive_mutex> lock(eff->GetBackgroundDisplayList().lock);
int rects = (Skips_SkipSize + Skips_BandSize) * (buffer.curEffEndPer - buffer.curEffStartPer + 1);
eff->GetBackgroundDisplayList().resize(rects * 6);
}
}

int firstX = x;
Expand Down Expand Up @@ -291,7 +293,9 @@ void SingleStrandEffect::RenderSingleStrandSkips(RenderBuffer &buffer, Effect *e
max = Skips_SkipSize + Skips_BandSize - 1;
if (max >= buffer.BufferWi) max = buffer.BufferWi - 1;

buffer.CopyPixelsToDisplayListX(eff, 0, 0, max);
if (eff->IsBackgroundDisplayListEnabled()) {
buffer.CopyPixelsToDisplayListX(eff, 0, 0, max);
}
}

class SingleStrandFXRenderCache : public EffectRenderCache
Expand Down Expand Up @@ -401,11 +405,24 @@ void SingleStrandEffect::RenderSingleStrandChase(RenderBuffer& buffer, Effect* e

//chasesize is a value curve item and can change throughout the effect and thus
//the number of rects could change
int rects = (chaseSize + 1) * (buffer.curEffEndPer - buffer.curEffStartPer + 1) * 6;
int numRects = chaseSize;
int rectInc = 1;
if (chaseSize > MaxNodes) {
numRects = MaxNodes;
}
if (numRects > 32) {
rectInc = numRects / 32;
}
int rects = (numRects + rectInc) * (buffer.curEffEndPer - buffer.curEffStartPer + 1) * 6 / rectInc;
if (!eff->IsBackgroundDisplayListEnabled()) {
rects = 0;
}
if (buffer.needToInit || rects >= eff->GetBackgroundDisplayList().size()) {
buffer.needToInit = false;
std::lock_guard<std::recursive_mutex> lock(eff->GetBackgroundDisplayList().lock);
eff->GetBackgroundDisplayList().resize(rects);
if (eff->IsBackgroundDisplayListEnabled()) {
std::lock_guard<std::recursive_mutex> lock(eff->GetBackgroundDisplayList().lock);
eff->GetBackgroundDisplayList().resize(rects);
}
}

bool Mirror = false;
Expand Down Expand Up @@ -534,7 +551,9 @@ void SingleStrandEffect::RenderSingleStrandChase(RenderBuffer& buffer, Effect* e
draw_chase(buffer, DoubleEnd ? x - 1 * scaledChaseWidth : x, Chase_Group_All, ColorScheme, Number_Chases, AutoReverse, width, chaseSize, Fade_Type, bool(ChaseDirection) == DoubleEnd, Mirror);
}
}
buffer.CopyPixelsToDisplayListX(eff, 0, 0, chaseSize);
if (eff->IsBackgroundDisplayListEnabled()) {
buffer.CopyPixelsToDisplayListX(eff, 0, 0, numRects, rectInc);
}
}

void SingleStrandEffect::draw_chase(RenderBuffer& buffer,
Expand Down
4 changes: 4 additions & 0 deletions xLights/sequencer/Effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ void Effect::ParseColorMap(const SettingsMap &mPaletteMap, xlColorVector &mColor

#pragma region Constructors and Destructors

bool Effect::backgroundDisplayListsEnabled = true;



// Used to create a temp copy of the effect in rendering only
Effect::Effect(const Effect& ef)
{
Expand Down
15 changes: 11 additions & 4 deletions xLights/sequencer/Effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ wxDECLARE_EVENT(EVT_SETTIMINGTRACKS, wxCommandEvent);
// An effect represents a generic effect
class Effect
{
static bool backgroundDisplayListsEnabled;
int mID = 0;
short mEffectIndex = -1;
std::string *mName = nullptr;
Expand Down Expand Up @@ -152,13 +153,15 @@ class Effect
xlDisplayList &GetBackgroundDisplayList() { return background; }
const xlDisplayList &GetBackgroundDisplayList() const { return background; }
bool HasBackgroundDisplayList() const {
std::lock_guard<std::recursive_mutex> lock(background.lock);
return !background.empty();
if (backgroundDisplayListsEnabled) {
std::lock_guard<std::recursive_mutex> lock(background.lock);
return !background.empty();
}
return false;
}

xlColor* GetColorMask() {
if (mColorMask.IsNilColor())
{
if (mColorMask.IsNilColor()) {
return nullptr;
}
return &mColorMask;
Expand All @@ -169,6 +172,10 @@ class Effect
bool GetFrame(RenderBuffer &buffer, RenderCache &renderCache);
void AddFrame(RenderBuffer &buffer, RenderCache &renderCache);
void PurgeCache(bool deleteCachefile = false);


static void EnableBackgroundDisplayLists(bool b) { backgroundDisplayListsEnabled = b; }
static bool IsBackgroundDisplayListEnabled() { return backgroundDisplayListsEnabled; }
};

bool operator<(const Effect &e1, const Effect &e2);
1 change: 1 addition & 0 deletions xLights/xLightsMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3530,6 +3530,7 @@ void xLightsFrame::SetFrequency(int frequency)
void xLightsFrame::SetGridIconBackgrounds(bool b)
{
mGridIconBackgrounds = b;
Effect::EnableBackgroundDisplayLists(b);
mainSequencer->PanelEffectGrid->SetEffectIconBackground(mGridIconBackgrounds);
mainSequencer->PanelEffectGrid->Refresh();
}
Expand Down

0 comments on commit b24ca35

Please sign in to comment.