- Timestamp:
- Oct 26, 2010 9:58:18 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Graphics/DevVGA.cpp
r33263 r33455 2948 2948 } 2949 2949 #endif /* !VBOX */ 2950 2951 2952 #ifndef VBOX2953 /********************************************************/2954 /* vga screen dump */2955 2956 static int vga_save_w, vga_save_h;2957 2958 static void vga_save_dpy_update(DisplayState *s,2959 int x, int y, int w, int h)2960 {2961 }2962 2963 static void vga_save_dpy_resize(DisplayState *s, int w, int h)2964 {2965 s->linesize = w * 4;2966 #ifndef VBOX2967 s->data = qemu_malloc(h * s->linesize);2968 #else /* VBOX */2969 if (!s->data)2970 {2971 PPDMDEVINS pDevIns = VGASTATE2DEVINS((PVGASTATE)s->pvVgaState);2972 s->data = PDMDevHlpMMHeapAlloc(pDevIns, h * s->linesize);2973 }2974 else // (32-bpp buffer is allocated by the caller)2975 s->linesize = ((w * 32 + 31) / 32) * 4;2976 #endif /* VBOX */2977 vga_save_w = w;2978 vga_save_h = h;2979 }2980 2981 static void vga_save_dpy_refresh(DisplayState *s)2982 {2983 }2984 2985 static int ppm_save(const char *filename, uint8_t *data,2986 int w, int h, int linesize)2987 {2988 FILE *f;2989 uint8_t *d, *d1;2990 unsigned int v;2991 int y, x;2992 2993 f = fopen(filename, "wb");2994 if (!f)2995 return -1;2996 fprintf(f, "P6\n%d %d\n%d\n",2997 w, h, 255);2998 d1 = data;2999 for(y = 0; y < h; y++) {3000 d = d1;3001 for(x = 0; x < w; x++) {3002 v = *(uint32_t *)d;3003 fputc((v >> 16) & 0xff, f);3004 fputc((v >> 8) & 0xff, f);3005 fputc((v) & 0xff, f);3006 d += 4;3007 }3008 d1 += linesize;3009 }3010 fclose(f);3011 return 0;3012 }3013 3014 /* save the vga display in a PPM image even if no display is3015 available */3016 void vga_screen_dump(const char *filename)3017 {3018 VGAState *s = vga_state;3019 DisplayState *saved_ds, ds1, *ds = &ds1;3020 3021 /* XXX: this is a little hackish */3022 vga_invalidate_display();3023 saved_ds = s->ds;3024 3025 memset(ds, 0, sizeof(DisplayState));3026 ds->dpy_update = vga_save_dpy_update;3027 ds->dpy_resize = vga_save_dpy_resize;3028 ds->dpy_refresh = vga_save_dpy_refresh;3029 ds->depth = 32;3030 3031 s->ds = ds;3032 s->graphic_mode = -1;3033 vga_update_display();3034 3035 if (ds->data) {3036 ppm_save(filename, ds->data, vga_save_w, vga_save_h,3037 s->ds->linesize);3038 qemu_free(ds->data);3039 }3040 s->ds = saved_ds;3041 }3042 #endif /* !VBOX */3043 3044 3045 #if 0 //def VBOX3046 /* copy the vga display contents to the given buffer. the size of the buffer3047 must be sufficient to store the screen copy (see below). the width and height3048 parameters determine the required dimensions of the copy. If they differ3049 from the actual screen dimensions, then the returned copy is shrinked or3050 stretched accordingly. The copy is always a 32-bit image, so the size of3051 the buffer supplied must be at least (((width * 32 + 31) / 32) * 4) * height,3052 i.e. dword-aligned. returns zero if the operation was successfull and -13053 otherwise. */3054 3055 static int vga_copy_screen_to(PVGASTATE s, uint8_t *buf, int width, int height)3056 {3057 DisplayState *saved_ds, ds1, *ds = &ds1;3058 if (!buf || width <= 0 || height <= 0)3059 return -1;3060 3061 /* XXX: this is a little hackish */3062 vga_invalidate_display(s);3063 saved_ds = s->ds;3064 3065 memset(ds, 0, sizeof(DisplayState));3066 ds->dpy_update = vga_save_dpy_update;3067 ds->dpy_resize = vga_save_dpy_resize;3068 ds->dpy_refresh = vga_save_dpy_refresh;3069 ds->depth = 32;3070 ds->data = buf;3071 ds->pvVgaState = s;3072 3073 s->ds = ds;3074 s->graphic_mode = -1;3075 vga_update_display(s);3076 3077 //@@TODO (dmik): implement stretching/shrinking!3078 3079 s->ds = saved_ds;3080 return 0;3081 }3082 3083 /* copy the given buffer to the vga display. width and height define the3084 dimensions of the image in the buffer. x and y define the point on the3085 vga display to copy the image to. the buffer is assumed to contain a 32-bit3086 image, so the size of one scanline must be ((width * 32 + 31) / 32) * 4),3087 i.e. dword-aligned. returns zero if the operation was successfull and -13088 otherwise. */3089 static int vga_copy_screen_from(PVGASTATE s, uint8_t *buf, int x, int y, int width, int height)3090 {3091 int bpl = ((width * 32 + 31) / 32) * 4;3092 int linesize = s->ds->linesize;3093 uint8_t *dst;3094 uint8_t *src;3095 int bpp;3096 vga_draw_line_func *vga_draw_line;3097 3098 if (!buf || x < 0 || y < 0 || width <= 0 || height <= 03099 || x + width > s->ds->width || y + height > s->ds->height)3100 return -1;3101 3102 vga_draw_line = vga_draw_line_table[VGA_DRAW_LINE32 * 4 + get_depth_index(s->ds->depth)];3103 switch (s->ds->depth) {3104 case 8: bpp = 1; break;3105 case 15:3106 case 16: bpp = 2; break;3107 case 32: bpp = 4; break;3108 default: return -1;3109 }3110 3111 dst = s->ds->data + y * linesize + x * bpp;3112 src = buf;3113 for (y = 0; y < height; y ++)3114 {3115 vga_draw_line(s, dst, src, width);3116 dst += linesize;3117 src += bpl;3118 }3119 3120 return 0;3121 }3122 #endif3123 2950 3124 2951 #endif /* !VBOX || !IN_RC || !IN_RING0 */
Note:
See TracChangeset
for help on using the changeset viewer.