Beispiel #1
0
//
// used the hash_table object receive from remote host 
// and send a hash stream to the remote host.
//
void hash_table::hash_it (file_reader & reader, hasher_stream & stream) const
{
	rs_mdfour_t ctx;
	rs_mdfour_begin(&ctx);
	uint64_t filsize = 0;
	try {
		int32_t f_blk_len = 0;
		if (reader.exist_file ()) {
			try {
				reader.open_file (); // sometimes this will throw.
				filsize = reader.get_file_size ();
				f_blk_len = get_xdelta_block_size (filsize);
			}
			catch (...) {
				stream.start_hash_stream (reader.get_fname (), 0);
				throw;
			}
			stream.start_hash_stream (reader.get_fname (), f_blk_len);
		}
		else {
			std::string mesg = fmt_string ("File %s not exists."
				, reader.get_fname ().c_str ());
			stream.start_hash_stream (reader.get_fname (), 0);
			stream.on_error (mesg, ENOENT);
			goto end;
		}
		read_and_hash (reader, stream, filsize, f_blk_len, 0, &ctx);
	}
	catch (xdelta_exception &e) {
		stream.on_error (e.what (), e.get_errno ());
	}

end:
	uchar_t file_hash[DIGEST_BYTES];
	memset (file_hash, 0, sizeof (file_hash));
	rs_mdfour_result (&ctx, file_hash);

	reader.close_file ();
	stream.end_hash_stream (file_hash, filsize);
	return;
}
Beispiel #2
0
void in_place_reconstructor::start_hash_stream (const std::string & fname
								, const int32_t blk_len)
{
	reader_ = foperator_.create_reader (fname);
	if (reader_->exist_file ()) {
		reader_->open_file ();
	}
	else {
		foperator_.release (reader_);
		reader_ = 0;
	}

	writer_ = foperator_.create_writer (fname);
	if (writer_ == 0) {
		std::string errmsg = fmt_string ("Can't create file %s.", fname.c_str ());
		THROW_XDELTA_EXCEPTION_NO_ERRNO (errmsg);
	}

	writer_->open_file ();
	fname_ = fname;
	ftmpname_.clear ();
}
Beispiel #3
0
static uint64_t get_file_size (const std::string & filename)
#endif
{
#ifdef _WIN32
	if (handle == INVALID_HANDLE_VALUE) {
		std::string errmsg ("File not open.");
		THROW_XDELTA_EXCEPTION_NO_ERRNO (errmsg);
	}
	uint64_t filsiz;
	DWORD high, low;
	low = GetFileSize (handle, &high);
	filsiz = high;
	filsiz <<= 32;
	return (filsiz + low) ;
#else
	struct stat st;
	int ret = stat(filename.c_str (), &st);
	if (ret < 0) {
		std::string errmsg = fmt_string ("Can't not stat file %s.", filename.c_str ());
		THROW_XDELTA_EXCEPTION (errmsg);
	}
	return st.st_size;
#endif
}
Beispiel #4
0
/**
 Create Entity-Tree from BSP-Tree of the map.
 There are 4 cases we have to deal with 
 (1) frontchild - NO  / backchild - NO	... Create a leaf node
 (2) frontchild - YES / backchild - YES	... Create a diverging node and recurse down for both sides
 (3) frontchild - YES / backchild - NO	... Just recurse down to frontchild
 (4) frontchild - NO  / backchild - YES ... This is an exception. In this case,
										    1) create a diverging node.
										    2) create a leaf node as a frontchild.
*/
short EntityManager::MakeEntityNode_r(short sNodeIndex, BSPTree* pSrcBSPTree,
					   vector<EntityNode>* pDestEntityTree)
{
//	SNode_f& rThisNode = pSrcBSPTree->m_paNode[ sNodeIndex ];
	const SNode_f& rThisNode = pSrcBSPTree->GetNode( sNodeIndex );
	short sFrontChild = rThisNode.sFrontChild;
	short sBackChild = rThisNode.sBackChild;

//	LOG_PRINTF(( "NODE: %d / FC: %d / BC: %d", sNodeIndex, sFrontChild, sBackChild ));

	if( 0 <= sFrontChild && sBackChild < 0 )	//case (1)
		return MakeEntityNode_r(sFrontChild, pSrcBSPTree, pDestEntityTree);  //recurse down to front

	EntityNode newnode;
	short sThisEntNodeIndex = (short)pDestEntityTree->size();
	pDestEntityTree->push_back( newnode );
	EntityNode& rNewNode = pDestEntityTree->at( sThisEntNodeIndex );

//	rNewNode.m_pLightEntity = NULL;

	if( sFrontChild < 0 && 0 <= sBackChild )  //This shouldn't really happen
	{
		//current node 'rThisNode' has no front child but it should be treated as a diverging node
		rNewNode.leaf = false;
		rNewNode.sFrontChild = (short)pDestEntityTree->size();

		//We have to add one leaf node as a front child to this diverging node
		pDestEntityTree->push_back( newnode );
		EntityNode& rFrontLeafNode = pDestEntityTree->back();
		rFrontLeafNode.sFrontChild = -1;
		rFrontLeafNode.sBackChild = -1;
		rFrontLeafNode.sParent = sThisEntNodeIndex;  //Index to 'rNewNode' in pDestEntityTree
		rFrontLeafNode.leaf = true;
		rFrontLeafNode.m_AABB = rThisNode.aabb;

		//Recurse down to the back side
		pDestEntityTree->at( sThisEntNodeIndex ).sBackChild
			= MakeEntityNode_r(sBackChild, pSrcBSPTree, pDestEntityTree);
		
		EntityNode& rNewNode = pDestEntityTree->at( sThisEntNodeIndex );
		rNewNode.m_Plane = pSrcBSPTree->GetPlane( rThisNode );
		rNewNode.m_AABB.Merge2AABBs( rThisNode.aabb,
			pDestEntityTree->at( rNewNode.sBackChild ).m_AABB );
		return sThisEntNodeIndex;  //Return the index to this diverging-node
	}

	else if( sFrontChild < 0 && sBackChild < 0 )  // complete leaf-node
	{	
		rNewNode.m_AABB = rThisNode.aabb;
		rNewNode.leaf = true;
		rNewNode.sFrontChild = -1;
		rNewNode.sBackChild = -1;
		rNewNode.m_sCellIndex = rThisNode.sCellIndex;
		if( rThisNode.sCellIndex < 0 )
			LOG_PRINT_ERROR( fmt_string( "invalid cell index found in a bsp-tree node (node index: %d)", sNodeIndex ) );
		return  sThisEntNodeIndex;	//returns the index of this node
	}

	else  //diverging-node
	{	
		rNewNode.m_AABB = rThisNode.aabb;
		rNewNode.leaf = false;

		//Recurse down to the both sides to make 2 sub-trees (front & back)
		pDestEntityTree->at( sThisEntNodeIndex ).sFrontChild
			= MakeEntityNode_r(sFrontChild, pSrcBSPTree, pDestEntityTree);
		pDestEntityTree->at( sThisEntNodeIndex ).sBackChild
			= MakeEntityNode_r(sBackChild, pSrcBSPTree, pDestEntityTree);

		//The internal memory allocation of 'pDestEntityTree' may have changed
		//during the above recursions.
		//In other words, the variable 'rNewNode' may be no longer valid
		//due to memory re-allocation, so we have to update the reference variable
		EntityNode& rNewNode = pDestEntityTree->at( sThisEntNodeIndex );
		rNewNode.m_Plane = pSrcBSPTree->GetPlane( rThisNode );  //Set 'binary partition plane'
		pDestEntityTree->at( rNewNode.sFrontChild ).sParent = sThisEntNodeIndex;
		pDestEntityTree->at( rNewNode.sBackChild ).sParent = sThisEntNodeIndex;
		return sThisEntNodeIndex;
	}

}
Result::Name EmbeddedGenericGLSLShader::Generate2DFragmentShader( const Generic2DShaderDesc& desc, std::string& shader )
{
//	shader = sg_2d_glsl_fs;

	string& fs = shader;

	fs =
	"#version 330\n"\
	"in vec4 dc;\n"\
	"in vec2 t0;\n"\
	"in vec2 t1;\n"\
	"in vec2 t2;\n"\
	"in vec2 t3;\n"\
	/*"layout(location = 0) out vec4 fc;\n"\*/
	"out vec4 fc;\n"\
	"uniform sampler2D T0;\n"\
	"uniform sampler2D T1;\n"\
	"uniform sampler2D T2;\n"\
	"uniform sampler2D T3;\n"\
	"void main(){";

	for( int i=0; i<numof(desc.textures); i++ )
	{
		const texture_sample_params& sample_params = desc.textures[i];

		if( !sample_params.is_valid() )
			break;

		fs += fmt_string( "vec4 tc%d = texture(T%d,t%d);\n", i, sample_params.sampler, sample_params.coord );
	}

	fs += "vec3 rgb=";
	AppendBlendCalculations(
		desc,
		"rgb",
		desc.diffuse_color_and_tex0_blend.rgb,
		desc.tex0_and_tex1_blend.rgb,
		desc.tex1_and_tex2_blend.rgb,
		desc.tex2_and_tex3_blend.rgb,
		fs
		);
	fs += ";\n";

	fs += "float a=";
	AppendBlendCalculations(
		desc,
		"a",
		desc.diffuse_color_and_tex0_blend.alpha,
		desc.tex0_and_tex1_blend.alpha,
		desc.tex1_and_tex2_blend.alpha,
		desc.tex2_and_tex3_blend.alpha,
		fs
		);
	fs += ";\n";

	fs += "fc = vec4(rgb,a);}\n";

	{
		static int s_counter = 0;
		FILE *fp = fopen(fmt_string(".debug/tl_fragment_shader_%02d.frag",s_counter).c_str(),"w");
		s_counter += 1;
		if(fp)
		{
			fprintf(fp,fs.c_str());
			fclose(fp);
		}
	}

	return Result::SUCCESS;
}
static Result::Name GenerateLightingFragmentShader( const GenericShaderDesc& desc, std::string& fragment_shader )
{
	static const char *fs_test =
	"#version 330\n"\
	"layout(location = 0) out vec4 fc;\n"\
	"void main(){fc = vec4(0,1,0,1);}\n";
	/*"out vec4 o_color;\n"\*/
	/*"void main(){o_color = vec4(1,1,1,1);}\n";*/

	// pos_vc: vertex position in view space
	// pos_vc: vertex position in projection space
	static const char *hs_lighting_fs_ins =
	"#version 330\n"\
	"in vec3 pos_vs;\n"\
	"in vec4 pos_ps;\n"\
	"in vec3 n_vs;\n"\
	"in vec4 dc;\n"\
	"in vec2 t0;\n";

	// fc: output fragment color
	static const char *hs_lighting_fs =
	"layout(location = 0) out vec4 fc;\n"\
	"uniform mat4 View;\n"\
	/*"uniform vec4 HSDL_UDC;\n"\*/
	/*"uniform vec4 HSDL_LDC;\n"\*/
	/*"uniform vec3 HSDL_Dir;\n"\*/
	"uniform sampler2D T0;\n"\
	"uniform sampler2D T1;\n"\
	"uniform sampler2D T2;\n"\
	"uniform sampler2D T3;\n";

	const char *fs_begin =
	"void main(){"\
	"	vec3 normal_vs = normalize(n_vs);"\
	"	vec4 br = vec4(0,0,0,1);\n";

	/*"	fc = vec4( normal_vs.x, normal_vs.y, normal_vs.z, 1 );"\*/

	const char *planar_reflection_fs_dec = "";
	const char *planar_reflection_fs_code = "";
	GeneratePlanarReflectionFragmentShader( desc, planar_reflection_fs_dec, planar_reflection_fs_code );

	fragment_shader += hs_lighting_fs_ins;

	fragment_shader += hs_lighting_fs;

	fragment_shader += planar_reflection_fs_dec;

	const char *hsdl_calc = "";
	const char *hspl_calc = "";
	const char *hssl_calc = "";

	if( desc.NumDirectionalLights != 0 )
	{
		int default_num_hsdls = 1;
		int num_hsdls = (0 < desc.NumPointLights) ? desc.NumPointLights : default_num_hsdls;
		fragment_shader += fmt_string( "#define NUM_HSDLS %d\n", num_hsdls );

		const char *hsdl_vars =
			"uniform vec4 HSDL_UDCs[NUM_HSDLS];\n"\
			"uniform vec4 HSDL_LDCs[NUM_HSDLS];\n"\
			/* directions in world space */
			"uniform vec3 HSDL_Dirs[NUM_HSDLS];\n"\
			"uniform int NumHSDLs;\n";
		fragment_shader += hsdl_vars;

		const char *non_specular_hsdl_calc =
			"for(int i=0;i<NumHSDLs;i++)"\
			"{"\
				"vec3 dir_to_light = -HSDL_Dirs[i];"\
				"float hsd = (dot(normal_vs,dir_to_light)+1)*0.5;"\
				"br += HSDL_UDCs[i] * hsd + HSDL_LDCs[i] * (1-hsd);"\
			"}\n";

		const char *specular_hsdl_calc =
		"	vec3 dir_to_viewer_vs = -normalize(pos_vs);"\
		"	for(int i=0;i<NumHSDLs;i++)"\
		"	{"\
		"		vec3 dir_to_light = -HSDL_Dirs[i];"\
		"		float cos_angle_incidence = dot(normal_vs,dir_to_light);"\
		"		cos_angle_incidence = clamp(cos_angle_incidence,0,1);"\
		"		vec3 half_angle = normalize(dir_to_viewer_vs+dir_to_light);"\
		/* Calculate the Blinn term */
		"		float bt = clamp(dot(half_angle,normal_vs),0,1);"\
		/* Clamp the Blinn term to 0 if the angle between the surface normal and the light direction is wider than 90 [deg] */
		"		bt = cos_angle_incidence != 0.0 ? bt : 0.0;"\
		/*"		bt = pow(bt,HSDL_Gs[i]);"\*/
		"		bt = pow(bt,25);"\
		"		float hsd = (dot(normal_vs,dir_to_light)+1)*0.5;"\
		"		br += ( HSDL_UDCs[i] * hsd + HSDL_LDCs[i] * (1-hsd) );"\
		/*"		br += HSPL_SCs[i] * bt;"\*/
		"		br += vec4(1,1,1,1) * bt;"\
		"	};\n";

		hsdl_calc = (desc.Specular == SpecularSource::NONE) ? non_specular_hsdl_calc : specular_hsdl_calc;
	}

	if( desc.NumPointLights != 0 )
//	if( false )
	{
		int default_num_hspls = 2;
		int num_hspls = (0 < desc.NumPointLights) ? desc.NumPointLights : default_num_hspls;
		fragment_shader += fmt_string( "#define NUM_HSPLS %d\n", num_hspls );

		const char *hspl_vars =
			"uniform vec4 HSPL_UDCs[NUM_HSPLS];\n"\
			"uniform vec4 HSPL_LDCs[NUM_HSPLS];\n"\
			"uniform vec4 HSPL_SCs[NUM_HSPLS];\n"\
			"uniform float HSPL_ShininessFactors[NUM_HSPLS];\n"\
			/* positions in world space */
			"uniform vec3 HSPL_Positions[NUM_HSPLS];\n"\
			"uniform vec3 HSPL_Atts[NUM_HSPLS];\n"\
			"uniform int NumHSPLs;\n";
		fragment_shader += hspl_vars;

		const char *non_specular_hspl_calc =
			"for(int i=0;i<NumHSPLs;i++)"\
			"{"\
				"vec3 to_light = HSPL_Positions[i] - pos_vs;"\
				"float dist = length(to_light);"\
				"vec3 dir_to_light = to_light / dist;"\
				"float att = 1.0f / (HSPL_Atts[i].x + HSPL_Atts[i].y*dist + HSPL_Atts[i].z*dist*dist);"\
				"float hsd = (dot(normal_vs,dir_to_light)+1)*0.5;"\
				"br += ( HSPL_UDCs[i] * hsd + HSPL_LDCs[i] * (1-hsd) ) * att;"\
			"}\n";

		const char *specular_hspl_calc =
		"	vec3 dir_vs = normalize(pos_vs);"\
		"	for(int i=0;i<NumHSPLs;i++)"\
		"	{"\
		"		vec3 to_light = HSPL_Positions[i] - pos_vs;"\
		"		float dist = length(to_light);"\
		"		vec3 dir_to_light = to_light / dist;"\
		"		float cos_angle_incidence = dot(normal_vs,dir_to_light);"\
		"		cos_angle_incidence = clamp(cos_angle_incidence,0,1);"\
		"		vec3 half_angle = normalize(dir_vs+dir_to_light);"\
		/* Calculate the Blinn term */
		"		float bt = clamp(dot(half_angle,normal_vs),0,1);"\
		/* Clamp the Blinn term to 0 if the angle between the surface normal and the light direction is wider than 90 [deg] */
		"		bt = cos_angle_incidence != 0.0 ? bt : 0.0;"\
		/*"		bt = pow(bt,HSPL_ShininessFactors[i]);"\*/
		"		bt = pow(bt,3);"\
		"		float att = 1.0f / (HSPL_Atts[i].x + HSPL_Atts[i].y*dist + HSPL_Atts[i].z*dist*dist);"\
		"		float hsd = (dot(normal_vs,dir_to_light)+1)*0.5;"\
		"		br += ( HSPL_UDCs[i] * hsd + HSPL_LDCs[i] * (1-hsd) ) * att;"\
		/*"		br += HSPL_SCs[i] * bt * att;"\*/
		"		br += vec4(1,1,1,1) * bt * att;"\
		"	}\n";

//		hspl_calc = specular_hspl_calc;
		hspl_calc = (desc.Specular == SpecularSource::NONE) ? non_specular_hspl_calc : specular_hspl_calc;
	}

//	if( desc.NumSpotLights != 0 )
	if( false )
	{
		int default_num_hssls = 1;
		int num_hssls = (0 < desc.NumPointLights) ? desc.NumPointLights : default_num_hssls;
		fragment_shader += fmt_string( "#define NUM_HSSLS %d\n", num_hssls );

		const char *hssl_vars =
			"uniform vec4 HSSL_UDCs[NUM_HSSLS];\n"\
			"uniform vec4 HSSL_LDCs[NUM_HSSLS];\n"\
			/* directions in world space */
			"uniform vec3 HSSL_Dirs[NUM_HSSLS];\n"\
			"uniform int NumHSSLs;\n";
		fragment_shader += hssl_vars;

		const char *non_specular_hssl_calc =
		"	for(int i=0;i<NumHSSLs;i++)"\
		"	{"\
		"		vec3 dir_vs = HSSL_Dirs[i];"\
		"		float hsd = (dot(normal_vs,-dir_vs)+1)*0.5;"\
		"		br += HSSL_UDCs[i] * hsd + HSSL_LDCs[i] * (1-hsd);"\
		"	}\n";
		hssl_calc = non_specular_hssl_calc;
	}

//	fragment_shader += hs_lighting_fs;

	fragment_shader += fs_begin;

	fragment_shader += hsdl_calc;
	fragment_shader += hspl_calc;
	fragment_shader += hssl_calc;

	const char *fs_fragment_color =
	"	vec4 tc = texture(T0,t0);"\
	"	fc = br * dc * tc;"\
	"	fc.a = dc.a * tc.a;\n";
	/*"	fc = br;"\*/
	/*"	fc = vec4(0,1,1,1);"\*/
	/*"	fc = vec4(normal_vs.x,normal_vs.y,normal_vs.z,1);"*/

	fragment_shader += fs_fragment_color;

	// Planar reflection shader (calculations)
	fragment_shader += planar_reflection_fs_code;

	const char *fs_end = "}\n";

	fragment_shader += fs_end;

	return Result::SUCCESS;
}
Beispiel #7
0
void read_and_delta (file_reader & reader
					, xdelta_stream & stream
					, const hash_table & hashes
					, std::set<hole_t> & hole_set
					, const int blk_len
					, bool need_split_hole)
{
	bool adddiff = !need_split_hole;
	char_buffer<uchar_t> buf (XDELTA_BUFFER_LEN);
	typedef std::set<hole_t>::iterator it_t;
	std::list<hole_t> holes2remove;

	for (it_t begin = hole_set.begin (); begin != hole_set.end (); ++begin) {
		const hole_t & hole = *begin;
		uint64_t offset = reader.seek_file (hole.offset, FILE_BEGIN);
		if (offset != hole.offset) {
			std::string errmsg = fmt_string ("Can't seek file %s(%s)."
				, reader.get_fname ().c_str (), error_msg ().c_str ());
			THROW_XDELTA_EXCEPTION (errmsg);
		}

		uint32_t buflen = XDELTA_BUFFER_LEN;
		uint32_t to_read_bytes = (uint32_t)hole.length;

		buflen = to_read_bytes > buflen ? buflen : to_read_bytes;
		uchar_t * rdbuf = buf.begin ();

		uint32_t size = reader.read_file (rdbuf, buflen);
		if (size != buflen) {
			std::string errmsg = fmt_string ("Can't read file %s(%s)."
				, reader.get_fname ().c_str (), error_msg ().c_str ());
			THROW_XDELTA_EXCEPTION (errmsg);
		}

		to_read_bytes -= size;
		const uchar_t * endbuf = rdbuf + size;
		rdbuf = buf.begin ();

		if ((int32_t)(endbuf - rdbuf) >= blk_len) {
			uchar_t * sentrybuf = rdbuf;
			rolling_hasher hasher;
			hasher.eat_hash (rdbuf, blk_len);

			while (true) {
				bool newhash = false;
				const slow_hash * bsh = hashes.find_block (hasher.hash_value (), rdbuf, blk_len);
				uchar_t outchar = 0;

				if (bsh) {
					// a match was found.
					uint32_t slipsize = (uint32_t)(rdbuf - sentrybuf);
					if (slipsize > 0 && adddiff)
						stream.add_block (sentrybuf, slipsize, offset);

					offset += slipsize;

					stream.add_block (bsh->tpos, blk_len, offset);
					if (need_split_hole) {
						hole_t newhole;
						newhole.offset = offset;
						newhole.length = blk_len;
						holes2remove.push_back (newhole);
					}

					rdbuf += blk_len;
					sentrybuf = rdbuf;
					newhash = true;
					offset += blk_len;
				}
				else {
					// slip the window by one bytes which size is blk_len.
					outchar = *rdbuf;
					++rdbuf;
				}

				//
				// beyond the buffer.
				int remain = (int)(endbuf - rdbuf);
				if (remain < blk_len) {
					if (to_read_bytes == 0) {
						// no more to read.
						uint32_t slipsize = (uint32_t)(endbuf - sentrybuf);
						if (slipsize > 0 && adddiff)
							stream.add_block (sentrybuf, slipsize, offset);
						goto end;
					}
					else {
						memmove (buf.begin (), rdbuf, remain);
						rdbuf = buf.begin ();
						sentrybuf = rdbuf;

						buflen = XDELTA_BUFFER_LEN - remain;
						buflen = to_read_bytes > buflen ? buflen : to_read_bytes;
						size = reader.read_file (rdbuf + remain, buflen);

						if (size != buflen) {
							std::string errmsg = fmt_string ("Can't read file %s(%s)."
								, reader.get_fname ().c_str (), error_msg ().c_str ());
							THROW_XDELTA_EXCEPTION (errmsg);
						}

						to_read_bytes -= size;
						endbuf = rdbuf + remain + size;
						remain += size;

						if (remain >= blk_len) {
							if (newhash)
								hasher.eat_hash (rdbuf, blk_len);
							else
								hasher.update (outchar, *(rdbuf + blk_len));
						}
						else {
							//
							// one read must complement data which length plus
							// remain must be more than one block length of @f_blk_len,
							// so if remain less than that, it must be reach the end of
							// file
							//
							if (adddiff)
								stream.add_block (rdbuf, remain, offset);
							offset += remain;
							goto end;
						}
					}
				}
				else {
					if (newhash)
						hasher.eat_hash (rdbuf, blk_len);
					else
						hasher.update (outchar, *(rdbuf + blk_len - 1));
				}
			}
		}
		else {
			if (adddiff)
				stream.add_block (rdbuf, size, offset);
		}
end:
		continue;
	}

	if (need_split_hole) {
		typedef std::list<hole_t>::iterator it_t;
		for (it_t begin = holes2remove.begin (); begin != holes2remove.end (); ++begin)
			split_hole (hole_set, *begin);
	}
	return;
}
static int wdma_config(DISP_MODULE_ENUM module,
               unsigned srcWidth, 
               unsigned srcHeight,
               unsigned clipX, 
               unsigned clipY, 
               unsigned clipWidth, 
               unsigned clipHeight,
               DpColorFormat  out_format, 
               unsigned long dstAddress, 
               unsigned dstPitch,               
               unsigned int useSpecifiedAlpha, 
               unsigned char alpha,
               DISP_BUFFER_TYPE sec,
               void * handle) 
{
    unsigned int idx                     = wdma_index(module);
    unsigned int output_swap             = fmt_swap(out_format);
    unsigned int output_color_space      = fmt_color_space(out_format);
    unsigned int out_fmt_reg             = fmt_hw_value(out_format); 
    unsigned int yuv444_to_yuv422        = 0;
    int color_matrix                     = 0x2; //0010 RGB_TO_BT601
    unsigned int idx_offst = idx*DISP_WDMA_INDEX_OFFSET;
	size_t size = dstPitch * clipHeight;

#if defined(CONFIG_TRUSTONIC_TEE_SUPPORT) && defined(CONFIG_MTK_SEC_VIDEO_PATH_SUPPORT)
    DDPMSG("module %s, src(w=%d,h=%d), clip(x=%d,y=%d,w=%d,h=%d),out_fmt=%s,dst_address=0x%lx,dst_p=%d,spific_alfa=%d,alpa=%d,handle=0x%p,sec%d\n",
        ddp_get_module_name(module),srcWidth,srcHeight,
        clipX,clipY,clipWidth,clipHeight,  
        fmt_string(out_format),dstAddress,dstPitch,  
        useSpecifiedAlpha,alpha,handle,sec);
#endif    
    // should use OVL alpha instead of sw config
    DISP_REG_SET(handle,idx_offst+DISP_REG_WDMA_SRC_SIZE, srcHeight<<16 | srcWidth);
    DISP_REG_SET(handle,idx_offst+DISP_REG_WDMA_CLIP_COORD, clipY<<16 | clipX);
    DISP_REG_SET(handle,idx_offst+DISP_REG_WDMA_CLIP_SIZE, clipHeight<<16 | clipWidth);
    DISP_REG_SET_FIELD(handle,CFG_FLD_OUT_FORMAT,idx_offst+DISP_REG_WDMA_CFG, out_fmt_reg);
    
    if(output_color_space == WDMA_COLOR_SPACE_YUV) {
        yuv444_to_yuv422 = fmt_is_yuv422(out_format);
        // set DNSP for UYVY and YUV_3P format for better quality
        DISP_REG_SET_FIELD(handle,CFG_FLD_DNSP_SEL, idx_offst+DISP_REG_WDMA_CFG, yuv444_to_yuv422);
        if(fmt_is_yuv420(out_format))
        {
            wdma_config_yuv420(module,out_format,dstPitch,clipHeight,dstAddress,sec,handle);
        }
        /*user internal matrix*/
        DISP_REG_SET_FIELD(handle,CFG_FLD_EXT_MTX_EN, idx_offst+DISP_REG_WDMA_CFG, 0);                         
        DISP_REG_SET_FIELD(handle,CFG_FLD_CT_EN, idx_offst+DISP_REG_WDMA_CFG, 1);
        DISP_REG_SET_FIELD(handle,CFG_FLD_INT_MTX_SEL, idx_offst+DISP_REG_WDMA_CFG, color_matrix);  
    }
    else
    {
        DISP_REG_SET_FIELD(handle,CFG_FLD_EXT_MTX_EN, idx_offst+DISP_REG_WDMA_CFG, 0);                         
        DISP_REG_SET_FIELD(handle,CFG_FLD_CT_EN, idx_offst+DISP_REG_WDMA_CFG, 0);  
    }
    DISP_REG_SET_FIELD(handle,CFG_FLD_SWAP, idx_offst+DISP_REG_WDMA_CFG, output_swap);
	if(sec != DISP_SECURE_BUFFER) {
    DISP_REG_SET(handle, idx_offst+DISP_REG_WDMA_DST_ADDR0, dstAddress);
	} else {
		int m4u_port;
		m4u_port = M4U_PORT_DISP_WDMA0;
	
		/* for sec layer, addr variable stores sec handle*/
		/* we need to pass this handle and offset to cmdq driver */
		/* cmdq sec driver will help to convert handle to correct address */
		cmdqRecWriteSecure(handle, disp_addr_convert(idx_offst+DISP_REG_WDMA_DST_ADDR0), 
				CMDQ_SAM_H_2_MVA, dstAddress, 0, size, m4u_port);
	}
    DISP_REG_SET(handle, idx_offst+DISP_REG_WDMA_DST_W_IN_BYTE, dstPitch);
    DISP_REG_SET_FIELD(handle,ALPHA_FLD_A_SEL, idx_offst+DISP_REG_WDMA_ALPHA, useSpecifiedAlpha);
    DISP_REG_SET_FIELD(handle,ALPHA_FLD_A_VALUE, idx_offst+DISP_REG_WDMA_ALPHA, alpha);
    
    wdma_calc_ultra(idx, srcWidth, srcHeight, 6, 60, handle);

    return 0;
}
Beispiel #9
0
/*
 * Command line argument parsing.
 * Sets nargc and nargv which corresponds to the argc/argv we'll use
 * for the command to be run (if we are running one).
 */
int
parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
    char ***env_addp)
{
    int mode = 0;		/* what mode is sudo to be run in? */
    int flags = 0;		/* mode flags */
    int valid_flags, ch;
    int i, j;
    char *cp, **env_add, **settings;
    int nenv = 0;
    int env_size = 32;

    env_add = emalloc2(env_size, sizeof(char *));

    /* Pass progname to plugin so it can call setprogname() */
    sudo_settings[ARG_PROGNAME].value = getprogname();

    /* First, check to see if we were invoked as "sudoedit". */
    if (strcmp(getprogname(), "sudoedit") == 0) {
	mode = MODE_EDIT;
	sudo_settings[ARG_SUDOEDIT].value = "true";
    }

    /* Load local IP addresses and masks. */
    if (get_net_ifs(&cp) > 0)
	sudo_settings[ARG_NET_ADDRS].value = cp;

    /* Returns true if the last option string was "--" */
#define got_end_of_args	(optind > 1 && argv[optind - 1][0] == '-' && \
	    argv[optind - 1][1] == '-' && argv[optind - 1][2] == '\0')

    /* Returns true if next option is an environment variable */
#define is_envar (optind < argc && argv[optind][0] != '/' && \
	    strchr(argv[optind], '=') != NULL)

    /* Flags allowed when running a command */
    valid_flags = MODE_BACKGROUND|MODE_PRESERVE_ENV|MODE_RESET_HOME|
		  MODE_LOGIN_SHELL|MODE_NONINTERACTIVE|MODE_SHELL;
    /* XXX - should fill in settings at the end to avoid dupes */
    for (;;) {
	/*
	 * We disable arg permutation for GNU getopt().
	 * Some trickiness is required to allow environment variables
	 * to be interspersed with command line options.
	 */
	if ((ch = getopt(argc, argv, "+Aa:bC:c:D:Eeg:HhiKklnPp:r:Sst:U:u:Vv")) != -1) {
	    switch (ch) {
		case 'A':
		    SET(tgetpass_flags, TGP_ASKPASS);
		    break;
#ifdef HAVE_BSD_AUTH_H
		case 'a':
		    sudo_settings[ARG_BSDAUTH_TYPE].value = optarg;
		    break;
#endif
		case 'b':
		    SET(flags, MODE_BACKGROUND);
		    break;
		case 'C':
		    if (atoi(optarg) < 3) {
			warningx(_("the argument to -C must be a number greater than or equal to 3"));
			usage(1);
		    }
		    sudo_settings[ARG_CLOSEFROM].value = optarg;
		    break;
#ifdef HAVE_LOGIN_CAP_H
		case 'c':
		    sudo_settings[ARG_LOGIN_CLASS].value = optarg;
		    break;
#endif
		case 'D':
		    if ((debug_level = atoi(optarg)) < 1 || debug_level > 9) {
			warningx(_("the argument to -D must be between 1 and 9 inclusive"));
			usage(1);
		    }
		    sudo_settings[ARG_DEBUG_LEVEL].value = optarg;
		    break;
		case 'E':
		    sudo_settings[ARG_PRESERVE_ENVIRONMENT].value = "true";
		    break;
		case 'e':
		    if (mode && mode != MODE_EDIT)
			usage_excl(1);
		    mode = MODE_EDIT;
		    sudo_settings[ARG_SUDOEDIT].value = "true";
		    valid_flags = MODE_NONINTERACTIVE;
		    break;
		case 'g':
		    runas_group = optarg;
		    sudo_settings[ARG_RUNAS_GROUP].value = optarg;
		    break;
		case 'H':
		    sudo_settings[ARG_SET_HOME].value = "true";
		    break;
		case 'h':
		    if (mode && mode != MODE_HELP) {
			if (strcmp(getprogname(), "sudoedit") != 0)
			    usage_excl(1);
		    }
		    mode = MODE_HELP;
		    valid_flags = 0;
		    break;
		case 'i':
		    sudo_settings[ARG_LOGIN_SHELL].value = "true";
		    SET(flags, MODE_LOGIN_SHELL);
		    break;
		case 'k':
		    sudo_settings[ARG_IGNORE_TICKET].value = "true";
		    break;
		case 'K':
		    sudo_settings[ARG_IGNORE_TICKET].value = "true";
		    if (mode && mode != MODE_KILL)
			usage_excl(1);
		    mode = MODE_KILL;
		    valid_flags = 0;
		    break;
		case 'l':
		    if (mode) {
			if (mode == MODE_LIST)
			    SET(flags, MODE_LONG_LIST);
			else
			    usage_excl(1);
		    }
		    mode = MODE_LIST;
		    valid_flags = MODE_NONINTERACTIVE|MODE_LONG_LIST;
		    break;
		case 'n':
		    SET(flags, MODE_NONINTERACTIVE);
		    sudo_settings[ARG_NONINTERACTIVE].value = "true";
		    break;
		case 'P':
		    sudo_settings[ARG_PRESERVE_GROUPS].value = "true";
		    break;
		case 'p':
		    sudo_settings[ARG_PROMPT].value = optarg;
		    break;
#ifdef HAVE_SELINUX
		case 'r':
		    sudo_settings[ARG_SELINUX_ROLE].value = optarg;
		    break;
		case 't':
		    sudo_settings[ARG_SELINUX_TYPE].value = optarg;
		    break;
#endif
		case 'S':
		    SET(tgetpass_flags, TGP_STDIN);
		    break;
		case 's':
		    sudo_settings[ARG_USER_SHELL].value = "true";
		    SET(flags, MODE_SHELL);
		    break;
		case 'U':
		    if ((getpwnam(optarg)) == NULL)
			errorx(1, _("unknown user: %s"), optarg);
		    list_user = optarg;
		    break;
		case 'u':
		    runas_user = optarg;
		    sudo_settings[ARG_RUNAS_USER].value = optarg;
		    break;
		case 'v':
		    if (mode && mode != MODE_VALIDATE)
			usage_excl(1);
		    mode = MODE_VALIDATE;
		    valid_flags = MODE_NONINTERACTIVE;
		    break;
		case 'V':
		    if (mode && mode != MODE_VERSION)
			usage_excl(1);
		    mode = MODE_VERSION;
		    valid_flags = 0;
		    break;
		default:
		    usage(1);
	    }
	} else if (!got_end_of_args && is_envar) {
	    if (nenv == env_size - 2) {
		env_size *= 2;
		env_add = erealloc3(env_add, env_size, sizeof(char *));
	    }
	    env_add[nenv++] = argv[optind];

	    /* Crank optind and resume getopt. */
	    optind++;
	} else {
	    /* Not an option or an environment variable -- we're done. */
	    break;
	}
    }
    env_add[nenv] = NULL;

    argc -= optind;
    argv += optind;

    if (!mode) {
	/* Defer -k mode setting until we know whether it is a flag or not */
	if (sudo_settings[ARG_IGNORE_TICKET].value != NULL) {
	    if (argc == 0) {
		mode = MODE_INVALIDATE;	/* -k by itself */
		sudo_settings[ARG_IGNORE_TICKET].value = NULL;
		valid_flags = 0;
	    }
	}
	if (!mode)
	    mode = MODE_RUN;		/* running a command */
    }

    if (argc > 0 && mode == MODE_LIST)
	mode = MODE_CHECK;

    if (ISSET(flags, MODE_LOGIN_SHELL)) {
	if (ISSET(flags, MODE_SHELL)) {
	    warningx(_("you may not specify both the `-i' and `-s' options"));
	    usage(1);
	}
	if (ISSET(flags, MODE_PRESERVE_ENV)) {
	    warningx(_("you may not specify both the `-i' and `-E' options"));
	    usage(1);
	}
	SET(flags, MODE_SHELL);
    }
    if ((flags & valid_flags) != flags)
	usage(1);
    if (mode == MODE_EDIT &&
       (ISSET(flags, MODE_PRESERVE_ENV) || env_add[0] != NULL)) {
	if (ISSET(mode, MODE_PRESERVE_ENV))
	    warningx(_("the `-E' option is not valid in edit mode"));
	if (env_add[0] != NULL)
	    warningx(_("you may not specify environment variables in edit mode"));
	usage(1);
    }
    if ((runas_user != NULL || runas_group != NULL) &&
	!ISSET(mode, MODE_EDIT | MODE_RUN | MODE_CHECK | MODE_VALIDATE)) {
	usage(1);
    }
    if (list_user != NULL && mode != MODE_LIST && mode != MODE_CHECK) {
	warningx(_("the `-U' option may only be used with the `-l' option"));
	usage(1);
    }
    if (ISSET(tgetpass_flags, TGP_STDIN) && ISSET(tgetpass_flags, TGP_ASKPASS)) {
	warningx(_("the `-A' and `-S' options may not be used together"));
	usage(1);
    }
    if ((argc == 0 && mode == MODE_EDIT) ||
	(argc > 0 && !ISSET(mode, MODE_RUN | MODE_EDIT | MODE_CHECK)))
	usage(1);
    if (argc == 0 && mode == MODE_RUN && !ISSET(flags, MODE_SHELL)) {
	SET(flags, (MODE_IMPLIED_SHELL | MODE_SHELL));
	sudo_settings[ARG_IMPLIED_SHELL].value = "true";
    }

    if (mode == MODE_HELP)
	help();

    /*
     * For shell mode we need to rewrite argv
     */
    if (ISSET(mode, MODE_RUN) && ISSET(flags, MODE_SHELL)) {
	char **av;
	int ac;

	if (argc == 0) {
	    /* just the shell */
	    ac = argc + 1;
	    av = emalloc2(ac + 1, sizeof(char *));
	    memcpy(av + 1, argv, argc * sizeof(char *));
	} else {
	    /* shell -c "command" */
	    char *cmnd, *src, *dst;
	    size_t cmnd_size = (size_t) (argv[argc - 1] - argv[0]) +
		strlen(argv[argc - 1]) + 1;

	    cmnd = dst = emalloc2(cmnd_size, 2);
	    for (av = argv; *av != NULL; av++) {
		for (src = *av; *src != '\0'; src++) {
		    /* quote potential meta characters */
		    if (!isalnum((unsigned char)*src) && *src != '_' && *src != '-')
			*dst++ = '\\';
		    *dst++ = *src;
		}
		*dst++ = ' ';
	    }
	    if (cmnd != dst)
		dst--;  /* replace last space with a NUL */
	    *dst = '\0';

	    ac = 3;
	    av = emalloc2(ac + 1, sizeof(char *));
	    av[1] = "-c";
	    av[2] = cmnd;
	}
	av[0] = (char *)user_details.shell; /* plugin may override shell */
	av[ac] = NULL;

	argv = av;
	argc = ac;
    }

    /*
     * Format setting_pairs into settings array.
     */
    settings = emalloc2(NUM_SETTINGS + 1, sizeof(char *));
    for (i = 0, j = 0; i < NUM_SETTINGS; i++) {
	if (sudo_settings[i].value) {
	    sudo_debug(9, "settings: %s=%s", sudo_settings[i].name,
		sudo_settings[i].value);
	    settings[j] = fmt_string(sudo_settings[i].name,
		sudo_settings[i].value);
	    if (settings[j] == NULL)
		errorx(1, _("unable to allocate memory"));
	    j++;
	}
    }
    settings[j] = NULL;

    if (mode == MODE_EDIT) {
#if defined(HAVE_SETRESUID) || defined(HAVE_SETREUID) || defined(HAVE_SETEUID)
	/* Must have the command in argv[0]. */
	argc++;
	argv--;
	argv[0] = "sudoedit";
#else
	errorx(1, _("sudoedit is not supported on this platform"));
#endif
    }

    *settingsp = settings;
    *env_addp = env_add;
    *nargc = argc;
    *nargv = argv;
    return mode | flags;
}
bool D3DCubeTextureRenderTarget::CreateTextures( uint texture_size, TextureFormat::Format texture_format )
{
	m_CubeTextureSize = texture_size;
	m_TextureFormat = texture_format;

	D3DFORMAT d3d_fmt;
	if( texture_format == TextureFormat::Invalid )
	/* || any ohter texture formats invalid for cube mapping ) */
	{
		LOG_PRINT_ERROR( fmt_string("An unsupported texture format: %d", texture_format) );
		return false;
	}

	d3d_fmt = ConvertTextureFormatToD3DFORMAT( texture_format );

	LPDIRECT3DDEVICE9 pd3dDevice = DIRECT3D9.GetDevice();
	HRESULT hr;

	m_NumCubes = 1; // always use the single cube texture

/*	if( d3d_fmt == D3DFMT_A16B16G16R16F )
	{
		// Create the cube textures
		ZeroMemory( m_apCubeMapFp, sizeof( m_apCubeMapFp ) );
		hr = pd3dDevice->CreateCubeTexture( m_CubeTextureSize,
											1,
											D3DUSAGE_RENDERTARGET,
											D3DFMT_A16B16G16R16F,
											D3DPOOL_DEFAULT,
											&m_apCubeMapFp[0],
											NULL );

		m_pCurrentCubeMap = m_apCubeMapFp[0];
	}
*/

	hr = pd3dDevice->CreateCubeTexture( m_CubeTextureSize,
										1,
										D3DUSAGE_RENDERTARGET,
										d3d_fmt,
										D3DPOOL_DEFAULT,
										&m_pCubeMap32,
										NULL );

	if( FAILED(hr) || !m_pCubeMap32 )
	{
		LOG_PRINT_WARNING( "CreateCubeTexture() failed. Cannot create cube texture." );
		return false;
	}

	m_pCurrentCubeMap =  m_pCubeMap32;

//	DXUTDeviceSettings d3dSettings = DXUTGetDeviceSettings();

	LPDIRECT3DSWAPCHAIN9 pSwapChain;
	pd3dDevice->GetSwapChain( 0, &pSwapChain );

	D3DPRESENT_PARAMETERS pp;
	pSwapChain->GetPresentParameters( &pp );

    hr = pd3dDevice->CreateDepthStencilSurface( m_CubeTextureSize,
                                                m_CubeTextureSize,
//                                              d3dSettings.d3d9.pp.AutoDepthStencilFormat,
                                                pp.AutoDepthStencilFormat,
                                                D3DMULTISAMPLE_NONE,
                                                0,
                                                TRUE,
                                                &m_pDepthCube,
                                                NULL );

	if( FAILED(hr) || !m_pCurrentCubeMap )
	{
		LOG_PRINT_WARNING( "CreateDepthStencilSurface() failed. Cannot create depth stencil surface." );
		return false;
	}

/*
	// Initialize the number of cube maps required when using floating point format
//	IDirect3D9* pD3D = DXUTGetD3D9Object(); 
//	D3DCAPS9 caps;
//	hr = pD3D->GetDeviceCaps( pDeviceSettings->d3d9.AdapterOrdinal, pDeviceSettings->d3d9.DeviceType, &caps );

//	if( FAILED( pD3D->CheckDeviceFormat( caps.AdapterOrdinal, caps.DeviceType,
//										 pDeviceSettings->d3d9.AdapterFormat, D3DUSAGE_RENDERTARGET, 
//										 D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F ) ) )

	if( FAILED( pD3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, DIRECT3D9.GetDeviceType(),
										 DIRECT3D9.GetAdapterFormat(), D3DUSAGE_RENDERTARGET, 
										 D3DRTYPE_CUBETEXTURE, D3DFMT_A16B16G16R16F ) ) )
	{
		m_NumCubes = m_NumFpCubeMap = 2;
	}
	else
	{
		m_NumCubes = m_NumFpCubeMap = 1;
	}

	// If device doesn't support HW T&L or doesn't support 1.1 vertex shaders in HW 
	// then switch to SWVP.
//	if( (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0 ||
//			caps.VertexShaderVersion < D3DVS_VERSION(1,1) )
//	{
//		pDeviceSettings->d3d9.BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
//	}*/

	return true;
}