/*
- Copyright 2012 Marten Richter
+ Copyright 2012 Marten Richter, 2020 Chris Tallon
This file is part of VOMP.
along with VOMP. If not, see <https://www.gnu.org/licenses/>.
*/
-#include "osdvector.h"
#include "surfacevector.h"
#include "vdr.h"
#include "vdrresponsepacket.h"
#include "control.h"
#include "message.h"
+#include "osdvector.h"
+
// The next section is activated, if the magick++ PictureReader is provided, it should be available for many POSIX platforms
#ifdef PICTURE_DECODER_MAGICK
#define MAGICKCORE_QUANTUM_DEPTH 16
{
byte_char_width[i] = 0.f;
}
-
- styles_lastit_valid = styles_ref_lastit_valid = false;
}
void OsdVector::screenShot(const char* fileName)
return new SurfaceVector(this);
}
-
void OsdVector::Blank()
{
// do nothing? remove this one?
// First clear the contents of all registered surfaces
surfaces_mutex.lock();
- //Now go through all surfaces and draw them
- std::list<SurfaceInfo>::iterator curdraw = surfaces.begin();
-
- while (curdraw != surfaces.end())
+ //Now go through all surfaces and clear them
+ for (auto& surface : surfaces)
{
- (*curdraw).commands.clear();
- (*curdraw).commands.reserve(2048);
- curdraw++;
+ surface.commands.clear();
+ surface.commands.reserve(2048);
}
//also clear all handles, they are now invalid, no need to release them
surfaces_mutex.unlock();
}
-void OsdVector::updateOrAddSurface(const SurfaceVector* surf, float x, float y, float height, float width,
- std::vector<SVGCommand>& commands)
+void OsdVector::updateOrAddSurface(const SurfaceVector* surf, float x, float y, float height, float width, std::vector<SVGCommand>& commands)
{
- surfaces_mutex.lock();
- //First determine it is already in our system
- std::list<SurfaceInfo>::iterator itty = surfaces.begin();
+ std::lock_guard<std::mutex> lg(surfaces_mutex);
+ SurfacesIterator si;
- while (itty != surfaces.end())
+ // First determine it is already in our system
+ for(si = surfaces.begin(); si != surfaces.end(); si++)
{
- if ((*itty).surf == surf)
+ if (si->surface == surf)
{
- //decrease the references
- decrementAllRefCounts((*itty).commands);
+ // If the surface given (surf) is already in our surfaces vector, reset our SurfaceInfo->commands vector
+ decrementAllRefCounts(si->commands);
+ si->commands.clear();
break;
}
-
- itty++;
}
- // if not insert it
- if (itty == surfaces.end())
+ // if not found, make a new SurfaceInfo
+ if (si == surfaces.end())
{
SurfaceInfo new_sc;
- new_sc.surf = surf;
+ new_sc.surface = surf;
new_sc.x = x;
new_sc.y = y;
new_sc.w = width;
new_sc.h = height;
- itty = surfaces.insert(itty, new_sc);
+ si = surfaces.insert(si, new_sc);
}
// update any images loaded in the mean time
- std::vector<SVGCommand>::iterator ilitty = commands.begin();
- while (ilitty != commands.end())
+ for (SVGCommand& command : commands)
{
- if ((*ilitty).instr == DrawImageLoading)
+ if (command.instr == DrawImageLoading)
{
- LoadIndex loadindex = (*ilitty).target.loadindex;
+ LoadIndex loadindex = command.target.loadindex;
if (tvmedias_loaded.find(loadindex) != tvmedias_loaded.end())
{
-
- (*ilitty).instr = DrawImage;
- (*ilitty).target.image = tvmedias_loaded[loadindex];
- incImageRef((*ilitty).target.image);
+ command.instr = DrawImage;
+ command.target.image = tvmedias_loaded[loadindex];
+ incImageRef(command.target.image);
removeLoadIndexRef(loadindex);
}
}
-
- ilitty++;
}
+ si->commands = commands; // Copy surf->commands to our SurfaceInfo->commands
+ incrementAllRefCounts(si->commands);
- // then clear and copy
- (*itty).commands.clear();
- (*itty).commands = commands;
- //increase the references
- incrementAllRefCounts((*itty).commands);
cleanupOrphanedRefs();
-
- surfaces_mutex.unlock();
}
void OsdVector::removeSurface(const SurfaceVector* surf)
{
- surfaces_mutex.lock();
- //First determine it is already in our system
- std::list<SurfaceInfo>::iterator itty = surfaces.begin();
-
- while (itty != surfaces.end())
+ std::lock_guard<std::mutex> lg(surfaces_mutex);
+ for (auto i = surfaces.begin(); i != surfaces.end(); i++)
{
- if ((*itty).surf == surf)
+ if (i->surface == surf)
{
- decrementAllRefCounts((*itty).commands);
- (*itty).commands.clear();
- surfaces.erase(itty);
- break;
+ decrementAllRefCounts(i->commands);
+ i->commands.clear();
+ surfaces.erase(i);
+ return;
}
-
- itty++;
}
-
- surfaces_mutex.unlock();
-
}
-void OsdVector::decrementAllRefCounts(std::vector<SVGCommand>& commands )
+void OsdVector::decrementAllRefCounts(std::vector<SVGCommand>& commands)
{
-
- std::vector<SVGCommand>::iterator sitty = commands.begin();
-
- while (sitty != commands.end())
+ for (SVGCommand& command : commands)
{
- removeStyleRef((*sitty).getRef());
- ImageIndex ii = (*sitty).getImageIndex();
+ decrementStyleRefCount(command.getRef());
+ ImageIndex ii = command.getImageIndex();
if (ii) removeImageRef(ii);
- LoadIndex li = (*sitty).getLoadIndex();
-
+ LoadIndex li = command.getLoadIndex();
if (li) removeLoadIndexRef(li);
-
- sitty++;
}
}
-void OsdVector::incrementAllRefCounts(std::vector<SVGCommand>& commands )
+void OsdVector::incrementAllRefCounts(std::vector<SVGCommand>& commands)
{
- std::vector<SVGCommand>::iterator sitty = commands.begin();
-
- while (sitty != commands.end())
+ for (SVGCommand& command : commands)
{
- incStyleRef((*sitty).getRef());
- ImageIndex ii = (*sitty).getImageIndex();
+ incrementStyleRefCount(command.getRef());
+ ImageIndex ii = command.getImageIndex();
if (ii) incImageRef(ii);
- LoadIndex li = (*sitty).getLoadIndex();
-
+ LoadIndex li = command.getLoadIndex();
if (li) incLoadIndexRef(li);
-
- sitty++;
}
}
-
void OsdVector::incImageRef(ImageIndex index)
{
if (images_ref.find(index) == images_ref.end())
tvmedias_load_inv.erase(ref);
reader.invalidateLoadIndex(ref);
-
-
}
}
-
-
void OsdVector::cleanupOrphanedRefs()
{
// Do some garbage collection
}
}
-
int OsdVector::getImageRef(ImageIndex index)
{
surfaces_mutex.lock();
surfaces_mutex.unlock();
}
-void OsdVector::incStyleRef(VectorHandle index)
+void OsdVector::incrementStyleRefCount(VectorHandle index)
{
- if (!styles_ref_lastit_valid || (*styles_ref_lastit).first != index)
+ if (!styles_ref_lastit_valid || (styles_ref_lastit->first != index))
{
- styles_ref_lastit_valid = false;
styles_ref_lastit = styles_ref.find(index);
+ if (styles_ref_lastit == styles_ref.end())
+ {
+ styles_ref_lastit = styles_ref.insert(std::pair<VectorHandle, int>(index, 0)).first;
+ }
}
- if (styles_ref_lastit == styles_ref.end())
- {
- styles_ref_lastit = styles_ref.insert(std::pair<VectorHandle, int>(index, 1)).first;
- }
- else
- {
- (*styles_ref_lastit).second++;
- }
-
+ styles_ref_lastit->second++;
styles_ref_lastit_valid = true;
}
-void OsdVector::removeStyleRef(VectorHandle index)
+void OsdVector::decrementStyleRefCount(VectorHandle index)
{
- if (!styles_ref_lastit_valid || (*styles_ref_lastit).first != index)
+ if (!styles_ref_lastit_valid || (styles_ref_lastit->first != index))
{
styles_ref_lastit_valid = false;
styles_ref_lastit = styles_ref.find(index);
if (styles_ref_lastit != styles_ref.end())
{
styles_ref_lastit_valid = true;
- (*styles_ref_lastit).second--;
+ styles_ref_lastit->second--;
}
}
surfaces_mutex.lock();
VectorHandle style_handle = 0;
- if (!styles_lastit_valid || (*styles_lastit).first != c)
+ if (!styles_lastit_valid || (styles_lastit->first != c))
{
styles_lastit_valid = false;
styles_lastit = styles.find(c);
}
else
{
-
- style_handle = (*styles_lastit).second;
+ style_handle = styles_lastit->second;
//Now check if the handle is valid
if (!styles_ref_lastit_valid || (*styles_ref_lastit).first != style_handle)
surfaces_mutex.unlock();
style_handle = createStyleRef(c);
surfaces_mutex.lock();
- (*styles_lastit).second = style_handle;
+ styles_lastit->second = style_handle;
}
else styles_ref_lastit_valid = true;
}
styles_lastit_valid = true;
- incStyleRef(style_handle);
+ incrementStyleRefCount(style_handle);
surfaces_mutex.unlock();
return style_handle;
}
return index;
}
-
-
void OsdVector::informPicture(LoadIndex index, ImageIndex imageIndex)
{
//Beware for thread safety
}
surfaces_mutex.unlock();
-
-
}
-
-
-
/*
ImageIndex OsdVector::getJpegRef(const char* fileName, int *width,int *height)
{
return image_handle;
}
-ImageIndex OsdVector::getImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data)
+ImageIndex OsdVector::getImagePalette(int width, int height, const unsigned char* image_data, const unsigned int* palette_data)
{
ImageIndex image_handle;
image_handle = createImagePalette(width, height, image_data, palette_data);
{
decoders_lock.lock();
- while ( decoders.size())
+ while (decoders.size())
{
PictureDecoder* dec = decoders.front();
decoders.pop_front();
void OsdVector::PictureReader::shutdown()
{
threadStop();
-
-
}
void OsdVector::PictureReader::addDecoder(PictureDecoder* decoder)
return true;
}
- // Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia Pictures arrived VDR %x %d %d",
- // vresp->getStreamID(),vresp->getUserDataLength(),vresp->getFlag());
+ // Log::getInstance()->log("OsdVector", Log::DEBUG, "TVMedia Pictures arrived VDR %x %d %d",
+ // vresp->getStreamID(),vresp->getUserDataLength(),vresp->getFlag());
bool decode = false;
bool freed = false;
UCHAR* userdata;
decode = true;
freed = false;
}
-
}
if (decode)
pict_lock_incoming.unlock();
}
-
if (pict_incoming.size() || pict_incoming_static.size()) return true;
return decoded;