Exemple #1
0
SkOpSegment* SkOpContour::addCurve(SkPath::Verb verb, const SkPoint pts[4],
        SkChunkAlloc* allocator) {
    switch (verb) {
        case SkPath::kLine_Verb: {
            SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocator, 2);
            memcpy(ptStorage, pts, sizeof(SkPoint) * 2);
            return appendSegment(allocator).addLine(ptStorage, this);
        } break;
        case SkPath::kQuad_Verb: {
            SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocator, 3);
            memcpy(ptStorage, pts, sizeof(SkPoint) * 3);
            return appendSegment(allocator).addQuad(ptStorage, this);
        } break;
        case SkPath::kConic_Verb: {
            SkASSERT(0);  // the original curve is a cubic, which will never reduce to a conic
        } break;
        case SkPath::kCubic_Verb: {
            SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocator, 4);
            memcpy(ptStorage, pts, sizeof(SkPoint) * 4);
            return appendSegment(allocator).addCubic(ptStorage, this);
        } break;
        default:
            SkASSERT(0);
    }
    return nullptr;
}
Region::Shape::Shape(const IntRect& rect)
{
    appendSpan(rect.y());
    appendSegment(rect.x());
    appendSegment(rect.maxX());
    appendSpan(rect.maxY());
}
Exemple #3
0
void SkOpContour::addCurve(SkPath::Verb verb, const SkPoint pts[4], SkChunkAlloc* allocator) {
    switch (verb) {
        case SkPath::kLine_Verb: {
            SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocator, 2);
            memcpy(ptStorage, pts, sizeof(SkPoint) * 2);
            appendSegment(allocator).addLine(ptStorage, this);
        } break;
        case SkPath::kQuad_Verb: {
            SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocator, 3);
            memcpy(ptStorage, pts, sizeof(SkPoint) * 3);
            appendSegment(allocator).addQuad(ptStorage, this);
        } break;
        case SkPath::kCubic_Verb: {
            SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocator, 4);
            memcpy(ptStorage, pts, sizeof(SkPoint) * 4);
            appendSegment(allocator).addCubic(ptStorage, this);
        } break;
        default:
            SkASSERT(0);
    }
}
Exemple #4
0
/*-----------------------------------
            Main for testing
-----------------------------------*/
int main()
{
	//some values/const needed for testing
	int test_port_num = 12345;
	const char* test_ip_addr = "localhost";
	char test_tracker_filename[] = "name.track";
	
	//test file handle
	FILE* test_file_h;
	
	test_file_h = fopen( test_tracker_filename, "a+" );
	
	for( int n=0; n<10; n++ )
	{
		srand(time(NULL));
		fprintf( test_file_h, "\r\n%s:%d:%d:%d:%d",
					test_ip_addr,
					test_port_num,
					rand(),
					rand(),
					rand()
					);
	}
	fclose( test_file_h );

	//run tracker_file_parser()
	tracker_file_parser( 	test_tracker_filename,
							tracked_file_info.filename,
							tracked_file_info.filesize,
							tracked_file_info.description,
							tracked_file_info.md5
							);

	if( TEST_MODE == 1 )
	{
		long test_start = rand();
		long test_end = rand();
		long test_time_stamp = 1999999999;

	
		printf( "\n\r[TEST] Testing commitPendingChunks() & findNextChunk() with start_byte = %ld, end_byte = %ld ...\n",
				test_start,
				test_end
				);
	
		//construct test_chunk struct, could use appendChunk() instead
		for( int n=0; n<2; n++ )
		{
			pending_chunks.push_back( chunks_struct() );
			strcpy( pending_chunks[n].ip_addr, test_ip_addr );
			pending_chunks[n].port_num = test_port_num;
			pending_chunks[n].start_byte = test_start;
			pending_chunks[n].end_byte = test_end;
			pending_chunks[n].time_stamp = test_time_stamp;
			test_port_num++;
			test_time_stamp++;
		}
	
		//test commitPendingChunks()
		commitPendingChunks( test_tracker_filename );
	
		int next_chunk_i = findNextChunk( test_start, test_end );
		if( next_chunk_i >= 0 )
		{
			printf( "[TEST] Chunk[%d] is the next chunk, ip = %s, port = %d, time_stamp = %ld\n",
				next_chunk_i,
				live_chunks[ next_chunk_i ].ip_addr,
				live_chunks[ next_chunk_i ].port_num,
				live_chunks[ next_chunk_i ].time_stamp
				);
		}
		else printf( "[TEST] No next chunk found\n" );
	
		//test isLiveChunk()
		printf( "[TEST] Testing isLiveChunk() ... \n\r" );
		int test_rtn;
		test_rtn = isLiveChunk( live_chunks[1] );
		if( test_rtn != NOT_LIVE_CHUNK ) printf( "[TEST] test_chunk is live @ live_chunks[%d]!\n\r", test_rtn );
		else printf( "[TEST] test_chunk is offline!\n\r" );
		
		printf( "[TEST] Testing createNewTracker() ... \n\r" );
		char dog_file[] = "dog.jpg";
		char dog_track[] = "dog.jpg.track";
		
		test_file_h = fopen( dog_file, "r" );
		fseek( test_file_h, 0, SEEK_END ); 				// seek to end of file
		long dog_size = ftell( test_file_h ); 			// get current file pointer
		fseek( test_file_h, 0, SEEK_SET ); 				// seek back to beginning of file
		fclose( test_file_h );
		
		printf( "[TEST] Testing file: \"%s\" with filesize = %ld ... \n", dog_file, dog_size );
		
		initSegments( dog_size );
		printf( "[TEST] Segment vector initialized\n" );
		
		int client_i = 4;
		
		for(int n=client_i*4; n<(client_i+1)*4; n++ )
		{
			appendSegment( dog_track, dog_size, n, test_port_num );
			printf( "[TEST] Segment[%d] appended\n", n );
		}
		
		char myfile_path[40];
		myFilePath( 1, myfile_path );
		printf( "\r[TEST] Testing myFile() : %s\n", myfile_path );
		
		printf( "\r[TEST] Testing fileSperator() and fileCat() ... \n" );
		fileSperator( dog_file );
		fileCat( dog_file );
		printf( "\r[TEST] Testing fileSperator() and fileCat() ... \n" );
		
		printf( "\n[TEST] Testing DONE!\n\n" );
	}

	return 0;
}