Kristian Høgsberg | d7c1726 | 2012-09-05 21:54:15 -0400 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and |
| 5 | * its documentation for any purpose is hereby granted without fee, provided |
| 6 | * that the above copyright notice appear in all copies and that both that |
| 7 | * copyright notice and this permission notice appear in supporting |
| 8 | * documentation, and that the name of the copyright holders not be used in |
| 9 | * advertising or publicity pertaining to distribution of the software |
| 10 | * without specific, written prior permission. The copyright holders make |
| 11 | * no representations about the suitability of this software for any |
| 12 | * purpose. It is provided "as is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 15 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 16 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 17 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 18 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 19 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 20 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #include "compositor.h" |
| 24 | |
| 25 | static const char * |
| 26 | egl_error_string(EGLint code) |
| 27 | { |
| 28 | #define MYERRCODE(x) case x: return #x; |
| 29 | switch (code) { |
| 30 | MYERRCODE(EGL_SUCCESS) |
| 31 | MYERRCODE(EGL_NOT_INITIALIZED) |
| 32 | MYERRCODE(EGL_BAD_ACCESS) |
| 33 | MYERRCODE(EGL_BAD_ALLOC) |
| 34 | MYERRCODE(EGL_BAD_ATTRIBUTE) |
| 35 | MYERRCODE(EGL_BAD_CONTEXT) |
| 36 | MYERRCODE(EGL_BAD_CONFIG) |
| 37 | MYERRCODE(EGL_BAD_CURRENT_SURFACE) |
| 38 | MYERRCODE(EGL_BAD_DISPLAY) |
| 39 | MYERRCODE(EGL_BAD_SURFACE) |
| 40 | MYERRCODE(EGL_BAD_MATCH) |
| 41 | MYERRCODE(EGL_BAD_PARAMETER) |
| 42 | MYERRCODE(EGL_BAD_NATIVE_PIXMAP) |
| 43 | MYERRCODE(EGL_BAD_NATIVE_WINDOW) |
| 44 | MYERRCODE(EGL_CONTEXT_LOST) |
| 45 | default: |
| 46 | return "unknown"; |
| 47 | } |
| 48 | #undef MYERRCODE |
| 49 | } |
| 50 | |
| 51 | static void |
| 52 | print_egl_error_state(void) |
| 53 | { |
| 54 | EGLint code; |
| 55 | |
| 56 | code = eglGetError(); |
| 57 | weston_log("EGL error state: %s (0x%04lx)\n", |
| 58 | egl_error_string(code), (long)code); |
| 59 | } |
| 60 | |
| 61 | static void |
| 62 | repaint_surfaces(struct weston_output *output, pixman_region32_t *damage) |
| 63 | { |
| 64 | struct weston_compositor *compositor = output->compositor; |
| 65 | struct weston_surface *surface; |
| 66 | |
| 67 | wl_list_for_each_reverse(surface, &compositor->surface_list, link) |
| 68 | if (surface->plane == &compositor->primary_plane) |
| 69 | weston_surface_draw(surface, output, damage); |
| 70 | } |
| 71 | |
| 72 | WL_EXPORT void |
| 73 | gles2_renderer_repaint_output(struct weston_output *output, |
| 74 | pixman_region32_t *output_damage) |
| 75 | { |
| 76 | struct weston_compositor *compositor = output->compositor; |
| 77 | EGLBoolean ret; |
| 78 | static int errored; |
| 79 | int32_t width, height; |
| 80 | |
| 81 | width = output->current->width + |
| 82 | output->border.left + output->border.right; |
| 83 | height = output->current->height + |
| 84 | output->border.top + output->border.bottom; |
| 85 | |
| 86 | glViewport(0, 0, width, height); |
| 87 | |
| 88 | ret = eglMakeCurrent(compositor->egl_display, output->egl_surface, |
| 89 | output->egl_surface, compositor->egl_context); |
| 90 | if (ret == EGL_FALSE) { |
| 91 | if (errored) |
| 92 | return; |
| 93 | errored = 1; |
| 94 | weston_log("Failed to make EGL context current.\n"); |
| 95 | print_egl_error_state(); |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | /* if debugging, redraw everything outside the damage to clean up |
| 100 | * debug lines from the previous draw on this buffer: |
| 101 | */ |
| 102 | if (compositor->fan_debug) { |
| 103 | pixman_region32_t undamaged; |
| 104 | pixman_region32_init(&undamaged); |
| 105 | pixman_region32_subtract(&undamaged, &output->region, |
| 106 | output_damage); |
| 107 | compositor->fan_debug = 0; |
| 108 | repaint_surfaces(output, &undamaged); |
| 109 | compositor->fan_debug = 1; |
| 110 | pixman_region32_fini(&undamaged); |
| 111 | } |
| 112 | |
| 113 | repaint_surfaces(output, output_damage); |
| 114 | |
| 115 | wl_signal_emit(&output->frame_signal, output); |
| 116 | |
| 117 | ret = eglSwapBuffers(compositor->egl_display, output->egl_surface); |
| 118 | if (ret == EGL_FALSE && !errored) { |
| 119 | errored = 1; |
| 120 | weston_log("Failed in eglSwapBuffers.\n"); |
| 121 | print_egl_error_state(); |
| 122 | } |
| 123 | |
| 124 | } |