From 176011eea776566ca73f98c48b0476db7f8b1e4d Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 15 Aug 2013 10:55:22 +0100 Subject: Add intel_framebuffer_dump A simple utility to capture the currently active framebuffers and record them as a png. --- tools/intel_framebuffer_dump.c | 111 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 tools/intel_framebuffer_dump.c (limited to 'tools/intel_framebuffer_dump.c') diff --git a/tools/intel_framebuffer_dump.c b/tools/intel_framebuffer_dump.c new file mode 100644 index 00000000..a254324c --- /dev/null +++ b/tools/intel_framebuffer_dump.c @@ -0,0 +1,111 @@ +/* + * Copyright © 2013 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ + +/* + * Read back all the KMS framebuffers attached to the CRTC and record as PNG. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + +#include "intel_gpu_tools.h" +#include "drmtest.h" + +int main(int argc, char **argv) +{ + drmModeResPtr res; + int fd, n; + + fd = drmOpen("i915", NULL); + if (fd < 0) + return ENOENT; + + res = drmModeGetResources(fd); + if (res == NULL) + return ENOMEM; + + for (n = 0; n < res->count_crtcs; n++) { + struct drm_gem_open open_arg; + struct drm_gem_flink flink; + drmModeCrtcPtr crtc; + drmModeFBPtr fb; + + crtc = drmModeGetCrtc(fd, res->crtcs[n]); + if (crtc == NULL) + continue; + + fb = drmModeGetFB(fd, crtc->buffer_id); + drmModeFreeCrtc(crtc); + if (fb == NULL) + continue; + + flink.handle = fb->handle; + if (drmIoctl(fd, DRM_IOCTL_GEM_FLINK, &flink)) { + drmModeFreeFB(fb); + continue; + } + + open_arg.name = flink.name; + if (drmIoctl(fd, DRM_IOCTL_GEM_OPEN, &open_arg) == 0) { + struct drm_i915_gem_mmap_gtt mmap_arg; + void *ptr; + + mmap_arg.handle = open_arg.handle; + if (drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg) == 0 && + (ptr = mmap(0, open_arg.size, PROT_READ, MAP_SHARED, fd, mmap_arg.offset)) != (void *)-1) { + cairo_surface_t *surface; + cairo_format_t format; + char name[80]; + + snprintf(name, sizeof(name), "fb-%d.png", fb->fb_id); + + switch (fb->depth) { + case 16: format = CAIRO_FORMAT_RGB16_565; break; + case 24: format = CAIRO_FORMAT_RGB24; break; + case 30: format = CAIRO_FORMAT_RGB30; break; + case 32: format = CAIRO_FORMAT_ARGB32; break; + default: format = CAIRO_FORMAT_INVALID; break; + } + + surface = cairo_image_surface_create_for_data(ptr, format, + fb->width, fb->height, fb->pitch); + cairo_surface_write_to_png(surface, name); + cairo_surface_destroy(surface); + + munmap(ptr, open_arg.size); + } + drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &open_arg.handle); + } + + drmModeFreeFB(fb); + } + + return 0; +} -- cgit v1.2.3