Region* RegionPagerBase::CreateRegion(int x, int y) {
	if (FindRegion(x, y)) {
		throw(std::logic_error("Cannot overwrite an existing region"));
	}
	regionList.emplace_front(x, y);
	return &regionList.front();
}
Example #2
0
//DOCS: since this method is the last ditch call from GetRegion, it must return a valid region object, even if the create function hasn't been set.
//return a new region, throwing an error on failure
Region* RegionPagerLua::CreateRegion(int x, int y) {
	if (FindRegion(x, y)) {
		throw(std::logic_error("Cannot overwrite an existing region"));
	}

	//get the pager's function from the registry
	lua_rawgeti(lua, LUA_REGISTRYINDEX, createRef);

	//check if this function is available
	if (lua_isnil(lua, -1)) {
		lua_pop(lua, 1);
		//return an empty region object
		regionList.emplace_front(x, y);
		return &regionList.front();
	}

	//something to work on
	Region tmpRegion(x, y);
	//TODO: add x & y as parameters
	lua_pushlightuserdata(lua, &tmpRegion);

	//call the function, 1 arg, 0 return
	if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
		throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
	}

	//return the new region
	regionList.push_front(tmpRegion);
	return &regionList.front();
}
Example #3
0
STDMETHODIMP CDVBSub::Render(SubPicDesc& spd, REFERENCE_TIME rt, double fps, RECT& bbox)
{
    CAutoLock cAutoLock(&m_csCritSec);

    rt -= m_rtCurrentSegmentStart; // Make sure the timing are relative to the current segment start
    RemoveOldPages(rt);

    if (POSITION posPage = FindPage(rt)) {
        const auto& pPage = m_pages.GetAt(posPage);
        bool BT709 = m_infoSourceTarget.sourceMatrix == BT_709 ? true : m_infoSourceTarget.sourceMatrix == NONE ? (m_displayInfo.width > 720) : false;

        pPage->rendered = true;
        TRACE_DVB(_T("DVB - Renderer - %s - %s\n"),
                  ReftimeToString(pPage->rtStart + m_rtCurrentSegmentStart), ReftimeToString(pPage->rtStop + m_rtCurrentSegmentStart));

        int nRegion = 1, nObject = 1;
        for (POSITION pos = pPage->regionsPos.GetHeadPosition(); pos; nRegion++) {
            DVB_REGION_POS regionPos = pPage->regionsPos.GetNext(pos);

            if (POSITION posRegion = FindRegion(pPage, regionPos.id)) {
                const auto& pRegion = pPage->regions.GetAt(posRegion);

                if (POSITION posCLUT = FindClut(pPage, pRegion->CLUT_id)) {
                    const auto& pCLUT = pPage->CLUTs.GetAt(posCLUT);

                    for (POSITION posO = pRegion->objects.GetHeadPosition(); posO; nObject++) {
                        DVB_OBJECT objectPos = pRegion->objects.GetNext(posO);

                        if (POSITION posObject = FindObject(pPage, objectPos.object_id)) {
                            const auto& pObject = pPage->objects.GetAt(posObject);

                            short nX = regionPos.horizAddr + objectPos.object_horizontal_position;
                            short nY = regionPos.vertAddr + objectPos.object_vertical_position;
                            pObject->m_width = pRegion->width;
                            pObject->m_height = pRegion->height;
                            pObject->SetPalette(pCLUT->size, pCLUT->palette, BT709,
                                                m_infoSourceTarget.sourceBlackLevel, m_infoSourceTarget.sourceWhiteLevel, m_infoSourceTarget.targetBlackLevel, m_infoSourceTarget.targetWhiteLevel);
                            pObject->RenderDvb(spd, nX, nY);

                            TRACE_DVB(_T(" --> %d/%d - %d/%d\n"), nRegion, pPage->regionsPos.GetCount(), nObject, pRegion->objects.GetCount());
                        }
                    }
                }
            }
        }

        bbox.left = 0;
        bbox.top = 0;
        bbox.right = m_displayInfo.width;
        bbox.bottom = m_displayInfo.height;
    }

    return S_OK;
}
Region* RegionPagerBase::GetRegion(int x, int y) {
	x = snapToBase(REGION_WIDTH, x);
	y = snapToBase(REGION_HEIGHT, y);

	//get the region by various means
	Region* ptr = nullptr;
	ptr = FindRegion(x, y);
	if (ptr) return ptr;
	ptr = LoadRegion(x, y);
	if (ptr) return ptr;
	return CreateRegion(x, y);
}
Example #5
0
HRESULT CDVBSub::ParseRegion(CGolombBuffer& gb, WORD wSegLength)
{
    HRESULT hr = E_POINTER;

    if (m_pCurrentPage) {
        size_t nExpectedSize = 10;
        size_t nEnd = gb.GetPos() + wSegLength;

        BYTE id = gb.ReadByte();
        POSITION posRegion = FindRegion(m_pCurrentPage, id);
        if (!posRegion) {
            posRegion = m_pCurrentPage->regions.AddTail(CAutoPtr<DVB_REGION>(DEBUG_NEW DVB_REGION()));
        }
        const auto& pRegion = m_pCurrentPage->regions.GetAt(posRegion);

        pRegion->id = id;
        pRegion->version_number = (BYTE)gb.BitRead(4);
        pRegion->fill_flag = (BYTE)gb.BitRead(1);
        gb.BitRead(3);  // Reserved
        pRegion->width = gb.ReadShort();
        pRegion->height = gb.ReadShort();
        pRegion->level_of_compatibility = (BYTE)gb.BitRead(3);
        pRegion->depth = (BYTE)gb.BitRead(3);
        gb.BitRead(2);  // Reserved
        pRegion->CLUT_id = gb.ReadByte();
        pRegion->_8_bit_pixel_code = gb.ReadByte();
        pRegion->_4_bit_pixel_code = (BYTE)gb.BitRead(4);
        pRegion->_2_bit_pixel_code = (BYTE)gb.BitRead(2);
        gb.BitRead(2);  // Reserved

        while (gb.GetPos() < nEnd) {
            nExpectedSize += 6;
            DVB_OBJECT object;
            object.object_id = gb.ReadShort();
            object.object_type = (BYTE)gb.BitRead(2);
            object.object_provider_flag = (BYTE)gb.BitRead(2);
            object.object_horizontal_position = (short)gb.BitRead(12);
            gb.BitRead(4);  // Reserved
            object.object_vertical_position = (short)gb.BitRead(12);
            if (object.object_type == 0x01 || object.object_type == 0x02) {
                nExpectedSize += 2;
                object.foreground_pixel_code = gb.ReadByte();
                object.background_pixel_code = gb.ReadByte();
            }
            pRegion->objects.AddTail(object);
        }

        hr = (wSegLength == nExpectedSize) ? S_OK : E_UNEXPECTED;
    }

    return hr;
}
Example #6
0
HRESULT CDVBSub::ParseRegion(CGolombBuffer& gb, WORD wSegLength)
{
	HRESULT					hr		= S_OK;
	WORD					wEnd	= (WORD)gb.GetPos() + wSegLength;
	CDVBSub::DVB_REGION*	pRegion;
	CDVBSub::DVB_REGION		DummyRegion;

	pRegion = FindRegion (m_pCurrentPage, gb.ReadByte());

	if (pRegion == NULL)
		pRegion = &DummyRegion;

	if (pRegion != NULL)
	{
		pRegion->version_number			= (BYTE)gb.BitRead(4);
		pRegion->fill_flag				= (BYTE)gb.BitRead(1);
		gb.BitRead(3);	// Reserved
		pRegion->width					= gb.ReadShort();
		pRegion->height					= gb.ReadShort();
		pRegion->level_of_compatibility	= (BYTE)gb.BitRead(3);
		pRegion->depth					= (BYTE)gb.BitRead(3);
		gb.BitRead(2);	// Reserved
		pRegion->CLUT_id				= gb.ReadByte();
		pRegion->_8_bit_pixel_code		= gb.ReadByte();
		pRegion->_4_bit_pixel_code		= (BYTE)gb.BitRead(4);
		pRegion->_2_bit_pixel_code		= (BYTE)gb.BitRead(2);
		gb.BitRead(2);	// Reserved

		pRegion->ObjectCount = 0;
		while (gb.GetPos() < wEnd)
		{
			DVB_OBJECT*		pObject = &pRegion->Objects[pRegion->ObjectCount];
			pObject->object_id					= gb.ReadShort();
			pObject->object_type				= (BYTE)gb.BitRead(2);
			pObject->object_provider_flag		= (BYTE)gb.BitRead(2);
			pObject->object_horizontal_position	= (SHORT)gb.BitRead(12);
			gb.BitRead(4);	// Reserved
			pObject->object_vertical_position	= (SHORT)gb.BitRead(12);
			if (pObject->object_type == 0x01 || pObject->object_type == 0x02)
			{
				pObject->foreground_pixel_code	= gb.ReadByte();
				pObject->background_pixel_code	= gb.ReadByte();
			}
			pRegion->ObjectCount++;
		}
	}
	else
		gb.SkipBytes (wSegLength-1);

	return S_OK;
}
Example #7
0
//NOTE: this return value seems strange; could replace it with a boolean
//return the saved region, or nullptr on failure
Region* RegionPagerLua::SaveRegion(int x, int y) {
	//get the pager's function from the registry
	lua_rawgeti(lua, LUA_REGISTRYINDEX, saveRef);

	//check if this function is available
	if (lua_isnil(lua, -1)) {
		lua_pop(lua, 1);
		//signal that the region wasn't saved
		return nullptr;
	}

	//find the specified region
	Region* ptr = FindRegion(x, y);
	if (!ptr) {
		lua_pop(lua, 1);
		//signal that there is no save function
		return nullptr;
	}
	lua_pushlightuserdata(lua, ptr);

	//call the function, 1 arg, 1 return
	if (lua_pcall(lua, 1, 1, 0) != LUA_OK) {
		throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
	}

	//check the return value, success or failure
	if (lua_isboolean(lua, -1) && lua_toboolean(lua, -1)) {
		lua_pop(lua, 1);
		//return the specified region that was saved
		return ptr;
	}
	else {
		lua_pop(lua, 1);
		//signal a failure
		return nullptr;
	}
}
Example #8
0
void KSnapShot::Shot(KListView * list)
{
    unsigned char * start = NULL;
    MEMORY_BASIC_INFORMATION info;

	KPEFile  module;
	void   * lastmodule = NULL;
	
	typedef enum { nMaxHeaps = 10 };
	HANDLE   ProcHeaps[nMaxHeaps];

	int heaps = GetProcessHeaps(nMaxHeaps, ProcHeaps);

    while ( VirtualQuery(start, & info, sizeof(info)) )
    {
		KRegion * pRegion = NULL;

		// compute CRC for committed region
	    if (info.State == MEM_COMMIT)
		{
			pRegion = FindRegion(start, info.RegionSize);		
            if (pRegion)
            {
        		pRegion->type    = info.Type;
				pRegion->lastcrc = pRegion->crc;
                pRegion->crc     = m_crc.Update(0, start, info.RegionSize);
				pRegion->count ++;
            }
		}
		
		if (list)
		{
			TCHAR temp[MAX_PATH];
			const TCHAR * p ;

			if ( pRegion && pRegion->count>=2 )
			{
				wsprintf(temp, "%04x", pRegion->lastcrc);
				list->AddItem(0, temp, ( pRegion->lastcrc != pRegion->crc ) + 1);
			}
			else
				list->AddItem(0, "     ", 0);

			if ( pRegion )
			{
				wsprintf(temp, "%04x", pRegion->crc);
				list->AddItem(1, temp);
			}
			
			wsprintf(temp, "%08lx", info.BaseAddress);	list->AddItem(2, temp);
			wsprintf(temp, "%08lx", info.RegionSize);   list->AddItem(3, temp);

			switch (info.State)
			{
				case MEM_FREE:    p = "F "; break;
				case MEM_RESERVE: p = "R "; break;
				case MEM_COMMIT:  p = "C "; break;
				default:          p = "? ";   
			}
			strcpy(temp, p);

			if ( info.State != MEM_FREE)
			{
				switch (info.Type)
				{
					case MEM_IMAGE:   p = "I "; break;
					case MEM_MAPPED:  p = "M "; break;
					case MEM_PRIVATE: p = "P "; break;
					default:          p = "? ";
				}
				strcat(temp, p);

				AddFlags(temp, info.AllocationProtect, Protections, sizeof(Protections)/sizeof(Protections[0]));
			}
			list->AddItem(4, temp);

/*
			char t[MAX_PATH];
			wsprintf(t, "%8lx ", info.AllocationBase);
			strcat(temp, t);

			if (info.State != MEM_RESERVE)
				AddFlags(temp, info.Protect, Protections, sizeof(Protections)/sizeof(Protections[0]));
*/

			if (info.State != MEM_FREE )
				if ( GetModuleFileName((HINSTANCE) info.BaseAddress, temp, sizeof(temp)) )
				{
					if (lastmodule)
					{
						module.Unload();
						lastmodule = NULL;
					}
				
					if ( module.Load(temp) )
						lastmodule = info.BaseAddress;

					// remove the directory path, keep only the filename
					if ( strchr(temp, '\\') )
					{
						for (char *p = strchr(temp, '\\') + 1;
									   strchr(p, '\\');
								   p = strchr(p, '\\') + 1);
						list->AddItem(5, p);
					}
					else 
						list->AddItem(5, temp);
				}
				else
				{
					const char * p = NULL;

					if (lastmodule != NULL)
						p = module.GetSectionName((unsigned) info.BaseAddress - (unsigned) lastmodule);

					if (p == NULL)
						for (int h=0; h<heaps; h++)
							if ( info.BaseAddress == ProcHeaps[h] )
							{
								wsprintf(temp, "Heap %d", h+1);
								p = temp;
								break;
							}

					if (p == NULL)
						if ( ( (unsigned) (& p) >= (unsigned) info.BaseAddress ) &&
						     ( (unsigned) (& p) <  (unsigned) info.BaseAddress + info.RegionSize ) )
							p = "Stack";

					if ( p )
						list->AddItem(5, p);
				}
							
		}

        start += info.RegionSize;

        if (start == 0)
            break;
    }

	if (lastmodule)
		module.Unload();
}
hsa_status_t LoaderContext::FindReadonlyRegion(hsa_region_t region, void *data) {
  return FindRegion(HSA_REGION_SEGMENT_READONLY, region, data);
}
hsa_status_t LoaderContext::FindGlobalRegion(hsa_region_t region, void *data) {
  return FindRegion(HSA_REGION_SEGMENT_GLOBAL, region, data);
}