コード例 #1
0
void * CompressionPoolThread::Entry()
{

#ifdef __MSVC__
    _set_se_translator(my_translate);

    //  On Windows, if anything in this thread produces a SEH exception (like access violation)
    //  we handle the exception locally, and simply alow the thread to exit smoothly with no results.
    //  Upstream will notice that nothing got done, and maybe try again later.
    
    try
#endif    
    {
    SetPriority( WXTHREAD_MIN_PRIORITY );

    if(!m_ticket->DoJob())
        m_ticket->b_isaborted = true;

    if( m_pMessageTarget ) {
        OCPN_CompressionThreadEvent Nevent(wxEVT_OCPN_COMPRESSIONTHREAD, 0);
        Nevent.SetTicket(m_ticket);
        Nevent.type = 0;
        m_pMessageTarget->QueueEvent(Nevent.Clone());
        // from here m_ticket is undefined (if deleted in event handler)
    }

    return 0;

    }           // try
    
#ifdef __MSVC__    
    catch (SE_Exception e)
    {
        if( m_pMessageTarget ) {
            OCPN_CompressionThreadEvent Nevent(wxEVT_OCPN_COMPRESSIONTHREAD, 0);
            m_ticket->b_isaborted = true;
            Nevent.SetTicket(m_ticket);
            Nevent.type = 0;
            m_pMessageTarget->QueueEvent(Nevent.Clone());
        }
        
        
        return 0;
    }
#endif    
    
}
コード例 #2
0
bool JobTicket::DoJob()
{
    if(!rect.IsEmpty())
        return DoJob(rect);

    // otherwise this ticket covers all the rects in the chart
    ChartBase *pchart = ChartData->OpenChartFromDB( m_ChartPath, FULL_INIT );
    if(!pchart)
        return false;

    ChartBaseBSB *pBSBChart = dynamic_cast<ChartBaseBSB*>( pchart );
    if(!pBSBChart)
        return false;

    int size_X = pBSBChart->GetSize_X();
    int size_Y = pBSBChart->GetSize_Y();

    int dim = g_GLOptions.m_iTextureDimension;
        
    int nx_tex = ceil( (float)size_X / dim );
    int ny_tex = ceil( (float)size_Y / dim );
        
    int nt = ny_tex * nx_tex;
        
    wxRect rect;
    rect.y = 0;
    rect.width = dim;
    rect.height = dim;
    for( int y = 0; y < ny_tex; y++ ) {
        
        if( pthread && pthread->m_pMessageTarget ) {
            OCPN_CompressionThreadEvent Nevent(wxEVT_OCPN_COMPRESSIONTHREAD, 0);
            Nevent.nstat = y;
            Nevent.nstat_max = ny_tex;
            Nevent.type = 1;
            Nevent.SetTicket(this);
            pthread->m_pMessageTarget->AddPendingEvent (Nevent);
        }
        
        rect.x = 0;
        for( int x = 0; x < nx_tex; x++ ) {
            if(!DoJob(rect))
                return false;
            
            pFact->UpdateCacheAllLevels(rect, global_color_scheme, compcomp_bits_array, compcomp_size_array);

            for(int i=0 ; i < g_mipmap_max_level+1 ; i++) {
                free(comp_bits_array[i]), comp_bits_array[i] = 0;
                free(compcomp_bits_array[i]), compcomp_bits_array[i] = 0;
            }

            
            rect.x += rect.width;
        }
        rect.y += rect.height;
    }
    
    return true;
}
コード例 #3
0
void OCP_DataStreamInput_Thread::Parse_And_Send_Posn(const char *buf)
{
    if( m_pMessageTarget ) {
        OCPN_DataStreamEvent Nevent(wxEVT_OCPN_DATASTREAM, 0);
        Nevent.SetNMEAString( buf );
        Nevent.SetStream( m_launcher );

        m_pMessageTarget->AddPendingEvent(Nevent);
    }

    return;
}
コード例 #4
0
void OCP_DataStreamInput_Thread::Parse_And_Send_Posn(wxString &str_temp_buf)
{
    OCPN_DataStreamEvent Nevent(wxEVT_OCPN_DATASTREAM, 0);
    std::string s = std::string(str_temp_buf.mb_str());
    Nevent.SetNMEAString(s);
    Nevent.SetStreamName(std::string( m_FullPortName.mb_str() ));
    Nevent.SetPriority(m_launcher->GetPriority());

    if( m_pMessageTarget )
        m_pMessageTarget->AddPendingEvent(Nevent);

    return;
}
コード例 #5
0
ファイル: androidUTIL.cpp プロジェクト: mark711/OpenCPN
    JNIEXPORT jint JNICALL Java_org_opencpn_OCPNNativeLib_processNMEA(JNIEnv *env, jobject obj, jstring nmea_string)
    {
        const char *string = env->GetStringUTFChars(nmea_string, NULL);
//        wxString wstring = wxString(string, wxConvUTF8);
        
//        qDebug() << "processNMEA" << string;
 
        char tstr[200];
        strncpy(tstr, string, 190);
        strcat(tstr, "\r\n");
        
        if( s_pAndroidNMEAMessageConsumer ) {
            OCPN_DataStreamEvent Nevent(wxEVT_OCPN_DATASTREAM, 0);
            Nevent.SetNMEAString( tstr );
            Nevent.SetStream( NULL );
                
            s_pAndroidNMEAMessageConsumer->AddPendingEvent(Nevent);
        }
        
        return 66;
    }
コード例 #6
0
bool glTextureManager::ScheduleJob(glTexFactory* client, const wxRect &rect, int level,
                                   bool b_throttle_thread, bool b_nolimit, bool b_postZip, bool b_inplace)
{
    wxString chart_path = client->GetChartPath();
    if(!b_nolimit) {
        if(todo_list.GetCount() >= 50){
            // remove last job which is least important
            wxJobListNode *node = todo_list.GetLast();
            JobTicket *ticket = node->GetData();
            todo_list.DeleteNode(node);
            delete ticket;
        }

    //  Avoid adding duplicate jobs, i.e. the same chart_path, and the same rectangle
        wxJobListNode *node = todo_list.GetFirst();
        while(node){
            JobTicket *ticket = node->GetData();
            if( (ticket->m_ChartPath == chart_path) && (ticket->rect == rect)) {
                // bump to front
                todo_list.DeleteNode(node);
                todo_list.Insert(ticket);
                ticket->level_min_request = level;
                return false;
            }
        
            node = node->GetNext();
        }

        // avoid duplicate worker jobs
        wxJobListNode *tnode = running_list.GetFirst();
        while(tnode){
            JobTicket *ticket = tnode->GetData();
            if(ticket->rect == rect &&
               ticket->m_ChartPath == chart_path) {
                return false;
            }
            tnode = tnode->GetNext();
        }
    }
    
    JobTicket *pt = new JobTicket;
    pt->pFact = client;
    pt->rect = rect;
    pt->level_min_request = level;
    glTextureDescriptor *ptd = client->GetOrCreateTD( pt->rect );
    pt->ident = (ptd->tex_name << 16) + level;
    pt->b_throttle = b_throttle_thread;
    pt->m_ChartPath = chart_path;

    pt->level0_bits = NULL;
    pt->b_abort = false;
    pt->b_isaborted = false;
    pt->bpost_zip_compress = b_postZip;
    pt->binplace = b_inplace;

    /* do we compress in ram using builtin libraries, or do we
       upload to the gpu and use the driver to perform compression?
       we have builtin libraries for DXT1 (squish) and ETC1 (etcpak)
       FXT1 must use the driver, ETC1 cannot, and DXT1 can use the driver
       but the results are worse and don't compress well.

    additionally, if we use the driver we must stay single threaded in this thread
    (unless we created multiple opengl contexts), but with with our own libraries,
    we can use multiple threads to take advantage of multiple cores */

    if(g_raster_format != GL_COMPRESSED_RGB_FXT1_3DFX) {
        todo_list.Insert(pt); // push to front as a stack
        if(bthread_debug){
            int mem_used;
            GetMemoryStatus(0, &mem_used);
            printf( "Adding job: %08X  Job Count: %lu  mem_used %d\n", pt->ident, (unsigned long)todo_list.GetCount(), mem_used);
        }
 
        StartTopJob();
    }
    else {
        // give level 0 buffer to the ticket
        pt->level0_bits = ptd->map_array[0];
        ptd->map_array[0] = NULL;
        
        pt->DoJob();

        OCPN_CompressionThreadEvent Nevent(wxEVT_OCPN_COMPRESSIONTHREAD, 0);
        Nevent.type = 0;
        Nevent.SetTicket(pt);
        ProcessEventLocally(Nevent);
        // from here m_ticket is undefined (if deleted in event handler)
    }
    return true;
}