Exemplo n.º 1
0
Arquivo: mac.c Projeto: Mettbrot/vlc
block_t *screen_Capture( demux_t *p_demux )
{
    demux_sys_t *p_sys = p_demux->p_sys;
    screen_data_t *p_data = ( screen_data_t * )p_sys->p_data;
    block_t *p_block;
    int i_size;

    i_size = p_sys->fmt.video.i_height * p_sys->fmt.video.i_width * 4;

    if( !( p_block = block_Alloc( i_size ) ) )
    {
        msg_Warn( p_demux, "cannot get block" );
        return NULL;
    }

    CGPoint cursor_pos;
    CGError cursor_result;

    cursor_pos.x = 0;
    cursor_pos.y = 0;

    cursor_result =
        CGSGetCurrentCursorLocation( p_data->connection, &cursor_pos );

    cursor_pos.x -= p_data->screen_left;
    cursor_pos.y -= p_data->screen_top;

    if( p_sys->b_follow_mouse
        && cursor_result == kCGErrorSuccess )
    {
        FollowMouse( p_sys, cursor_pos.x, cursor_pos.y );
    }

    screen_CaptureScreen( p_sys );

    CGLSetCurrentContext( p_data->clipped );

    glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
    glClear( GL_COLOR_BUFFER_BIT );

    glDrawPixels( p_data->width,
                  p_data->height,
                  GL_RGBA, GL_UNSIGNED_BYTE, p_data->screen_image );

    if( cursor_result == kCGErrorSuccess )
    {
        screen_DrawCursor( p_sys, &cursor_pos );
    }

    glReadPixels( 0, 0,
                  p_data->width,
                  p_data->height,
                  GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
                  p_block->p_buffer );

    return p_block;
}
Exemplo n.º 2
0
void GetCursorInfo() {
	CGSConnectionRef connection = getConnection();
    CGError err = noErr;
    int cursorDataSize, depth, components, bitsPerComponent, cursorRowSize;
    unsigned char*		cursorData;
    CGPoint				location, hotspot;
    CGRect				cursorRect;
    int i, j;

    err = CGSGetCurrentCursorLocation(connection, &location);
    printf("location (err %d) = %d, %d\n", err, (int)location.x, (int)location.y);

    err = CGSGetGlobalCursorDataSize(connection, &cursorDataSize);
    printf("data size (err %d) = %d\n", err, cursorDataSize);

    cursorData = (unsigned char*)calloc(cursorDataSize, sizeof(unsigned char));

    err = CGSGetGlobalCursorData(connection,
                                 cursorData,
                                 &cursorDataSize,
                                 &cursorRowSize,
                                 &cursorRect,
                                 &hotspot,
                                 &depth,
                                 &components,
                                 &bitsPerComponent);

    printf("rect origin (%g, %g), dimensions (%g, %g)\n", cursorRect.origin.x, cursorRect.origin.y, cursorRect.size.width, cursorRect.size.height);

    printf("hotspot (%g, %g)\n", hotspot.x, hotspot.y);

    printf("depth: %d\n", depth);

    printf("components: %d\n", components);

    printf("bits per component: %d\n", bitsPerComponent);

    printf("Bytes Per Row: %d\n", cursorRowSize);


    printf("Components (err %d):\n", err);

    // Print Colors
    for (j=0; j < components; j++) {
        printf("\n");
        for (i=0; i < cursorDataSize; i++) {
            if (i % cursorRowSize == 0)
                printf("\n");
            if (i % components == j)
                printf("%02x", (int)cursorData[i]);
        }
    }

    printf("released connection (err %d)\n", CGSReleaseConnection(connection));
}
Exemplo n.º 3
0
CGPoint currentCursorLoc() {
    CGPoint cursorLoc={0.0, 0.0};
	CGSConnectionRef connection = getConnection();

    if (connection) {
		if (CGSGetCurrentCursorLocation(connection, &cursorLoc) != kCGErrorSuccess)
			rfbLog("Error obtaining cursor location\n");
    }
	
    return cursorLoc;
}
Exemplo n.º 4
0
Arquivo: mac.c Projeto: CSRedRat/vlc
block_t *screen_Capture( demux_t *p_demux )
{
    demux_sys_t *p_sys = p_demux->p_sys;
    screen_data_t *p_data = ( screen_data_t * )p_sys->p_data;
    block_t *p_block;
    int i_size;

    i_size = p_sys->fmt.video.i_height * p_sys->fmt.video.i_width * 4; 

    if( !( p_block = block_New( p_demux, i_size ) ) )
    {
        msg_Warn( p_demux, "cannot get block" );
        return NULL;
    }

    CGPoint cursor_pos;
    CGError cursor_result;

    cursor_pos.x = 0;
    cursor_pos.y = 0;

    cursor_result
      = CGSGetCurrentCursorLocation( p_data->connection, &cursor_pos );

    if( p_sys->b_follow_mouse
        && cursor_result == kCGErrorSuccess )
    {
        FollowMouse( p_sys, cursor_pos.x, cursor_pos.y );
        p_data->left = p_sys->i_left;
        p_data->top = p_sys->i_top;
    }

    CGLSetCurrentContext( p_data->screen );
    glReadPixels( p_data->left,
                  p_data->screen_height - p_data->top - p_data->src_height,
                  p_data->src_width,
                  p_data->src_height,
                  GL_RGBA, GL_UNSIGNED_BYTE,
                  p_data->texture_image );

    CGLSetCurrentContext( p_data->scaled );
    glEnable( GL_TEXTURE_2D );
    glBindTexture( GL_TEXTURE_2D, p_data->texture );
    glTexImage2D( GL_TEXTURE_2D, 0,
                  GL_RGBA8, p_data->src_width, p_data->src_height, 0,
                  GL_RGBA, GL_UNSIGNED_BYTE, p_data->texture_image );

    glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
    glClear( GL_COLOR_BUFFER_BIT );
    glColor3f( 1.0f, 1.0f, 1.0f );
    glEnable( GL_TEXTURE_2D );
    glBindTexture( GL_TEXTURE_2D, p_data->texture );
    glBegin( GL_POLYGON );
    glTexCoord2f( 0.0, 1.0 ); glVertex2f( -1.0, -1.0 );
    glTexCoord2f( 1.0, 1.0 ); glVertex2f( 1.0, -1.0 );
    glTexCoord2f( 1.0, 0.0 ); glVertex2f( 1.0, 1.0 );
    glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, 1.0 );
    glEnd();
    glDisable( GL_TEXTURE_2D );

    int size;
    int tmp1, tmp2, tmp3, tmp4;
    unsigned char *cursor_image;
    CGRect cursor_rect;
    CGPoint cursor_hot;

    if( cursor_result == kCGErrorSuccess
        && CGSGetGlobalCursorDataSize( p_data->connection, &size )
        == kCGErrorSuccess )
    {
        cursor_image = ( unsigned char* )malloc( size );
        if( CGSGetGlobalCursorData( p_data->connection,
                                    cursor_image, &size,
                                    &tmp1,
                                    &cursor_rect, &cursor_hot,
                                    &tmp2, &tmp3, &tmp4 )
            == kCGErrorSuccess )
        {
            glEnable( GL_TEXTURE_2D );
            glBindTexture( GL_TEXTURE_2D, p_data->cursor_texture );
            glTexImage2D( GL_TEXTURE_2D, 0,
                          GL_RGBA8,
                          ( int )( cursor_rect.size.width ),
                          ( int )( cursor_rect.size.height ), 0,
                          GL_RGBA, GL_UNSIGNED_BYTE,
                          ( char * )cursor_image );

            cursor_rect.origin.x = cursor_pos.x - p_data->left - cursor_hot.x;
            cursor_rect.origin.y = cursor_pos.y - p_data->top - cursor_hot.y;

            cursor_rect.origin.x
              = 2.0 * cursor_rect.origin.x / p_data->src_width - 1.0;
            cursor_rect.origin.y
              = 2.0 * cursor_rect.origin.y / p_data->src_height - 1.0;
            cursor_rect.size.width
              = 2.0 * cursor_rect.size.width / p_data->src_width;
            cursor_rect.size.height
              = 2.0 * cursor_rect.size.height / p_data->src_height;

            glColor3f( 1.0f, 1.0f, 1.0f );
            glEnable( GL_TEXTURE_2D );
            glEnable( GL_BLEND );
            glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
            glBindTexture( GL_TEXTURE_2D, p_data->cursor_texture );
            glBegin( GL_POLYGON );
            glTexCoord2f( 0.0, 0.0 ); glVertex2f( cursor_rect.origin.x,
                                                  cursor_rect.origin.y );
            glTexCoord2f( 1.0, 0.0 ); glVertex2f( cursor_rect.origin.x
                                                  + cursor_rect.size.width,
                                                  cursor_rect.origin.y );
            glTexCoord2f( 1.0, 1.0 ); glVertex2f( cursor_rect.origin.x
                                                  + cursor_rect.size.width,
                                                  cursor_rect.origin.y
                                                  + cursor_rect.size.height );
            glTexCoord2f( 0.0, 1.0 ); glVertex2f( cursor_rect.origin.x,
                                                  cursor_rect.origin.y
                                                  + cursor_rect.size.height );
            glEnd();
            glDisable( GL_BLEND );
            glDisable( GL_TEXTURE_2D );
        }
        free( cursor_image );
    }

    glReadPixels( 0, 0, 
                  p_data->dest_width,
                  p_data->dest_height,
                  GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
                  p_block->p_buffer );

    return p_block;
}