Ticket #368: osdsurface.diff

File osdsurface.diff, 3.0 KB (added by paulh, 18 years ago)

adds protection to the usedRegions to make it thread safe

  • libs/libmythtv/osdsurface.cpp

     
    8686    memset(u, 127, size / 4);
    8787    memset(v, 127, size / 4);
    8888    memset(alpha, 0, size);
     89    usedRegionsLock.lock();
    8990    usedRegions = QRegion();
     91    usedRegionsLock.unlock();
    9092}
    9193
    9294void OSDSurface::ClearUsed(void)
    9395{
     96    usedRegionsLock.lock();
    9497    QMemArray<QRect> rects = usedRegions.rects();
    9598    QMemArray<QRect>::Iterator it = rects.begin();
    9699    QRect drawRect;
     
    129132    }
    130133
    131134    usedRegions = QRegion();
     135    usedRegionsLock.unlock();
    132136}
    133137
    134138bool OSDSurface::IntersectsDrawn(QRect &newrect)
    135139{
     140    QMutexLocker lock(&usedRegionsLock);
    136141    QMemArray<QRect> rects = usedRegions.rects();
    137142    QMemArray<QRect>::Iterator it = rects.begin();
    138143    for (; it != rects.end(); ++it)
     
    143148
    144149void OSDSurface::AddRect(QRect &newrect)
    145150{
     151    usedRegionsLock.lock();
    146152    usedRegions = usedRegions.unite(newrect);
     153    usedRegionsLock.unlock();
    147154}
    148155
    149156///////////////////////////////////////////////////////////////////////////
     
    551558 */
    552559void OSDSurface::BlendToYV12(unsigned char *yuvptr) const
    553560{
     561    usedRegionsLock.lock();
    554562    const OSDSurface *surface = this;
    555563    blendtoyv12_8_fun blender = blendtoyv12_8_init(surface);
    556564
     
    649657            }
    650658        }
    651659    }
     660    usedRegionsLock.unlock();
    652661}
    653662
    654663static void BlendToBlack(unsigned char *argbptr, uint width, uint outheight)
     
    686695                             uint outheight, bool blend_to_black,
    687696                             uint threshold) const
    688697{
     698    usedRegionsLock.lock();
    689699    const OSDSurface *surface = this;
    690700    blendtoargb_8_fun blender = blendtoargb_8_init(surface);
    691701    const unsigned char *cm = surface->cm;
     
    756766    }
    757767    if (blend_to_black)
    758768        BlendToBlack(argbptr, stride>>2, outheight);
     769
     770    usedRegionsLock.unlock();
    759771}
    760772
    761773/** \fn OSDSurface::DitherToI44(unsigned char*,bool,uint,uint) const
     
    772784void OSDSurface::DitherToI44(unsigned char *outbuf, bool ifirst,
    773785                             uint stride, uint outheight) const
    774786{
     787    usedRegionsLock.lock();
    775788    const OSDSurface *surface = this;
    776789    int ashift = ifirst ? 0 : 4;
    777790    int amask = ifirst ? 0x0f : 0xf0;
     
    855868    }
    856869
    857870    delete_dithertoia44_8_context(dcontext);
     871    usedRegionsLock.unlock();
    858872}
    859873
    860874/** \fn OSDSurface::DitherToIA44(unsigned char*,uint,uint) const
  • libs/libmythtv/osdsurface.h

     
    22#define OSDSURFACE_H_
    33
    44#include <qregion.h>
     5#include <qmutex.h>
    56#include "blend.h"
    67
    78#define MAX_NEG_CROP 1024
     
    6162    int size;
    6263
    6364    QRegion usedRegions;
    64 
     65    mutable QMutex usedRegionsLock;
    6566#ifdef MMX
    6667    short int rec_lut[256];
    6768#else