display.c (3717B)
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20#include "config.h" 21#include "cursor.h" 22#include "display.h" 23#include "video.h" 24 25#include <cairo/cairo.h> 26#include <guacamole/mem.h> 27 28#include <stdlib.h> 29 30cairo_operator_t guacenc_display_cairo_operator(guac_composite_mode mask) { 31 32 /* Translate Guacamole channel mask into Cairo operator */ 33 switch (mask) { 34 35 /* Source */ 36 case GUAC_COMP_SRC: 37 return CAIRO_OPERATOR_SOURCE; 38 39 /* Over */ 40 case GUAC_COMP_OVER: 41 return CAIRO_OPERATOR_OVER; 42 43 /* In */ 44 case GUAC_COMP_IN: 45 return CAIRO_OPERATOR_IN; 46 47 /* Out */ 48 case GUAC_COMP_OUT: 49 return CAIRO_OPERATOR_OUT; 50 51 /* Atop */ 52 case GUAC_COMP_ATOP: 53 return CAIRO_OPERATOR_ATOP; 54 55 /* Over (source/destination reversed) */ 56 case GUAC_COMP_ROVER: 57 return CAIRO_OPERATOR_DEST_OVER; 58 59 /* In (source/destination reversed) */ 60 case GUAC_COMP_RIN: 61 return CAIRO_OPERATOR_DEST_IN; 62 63 /* Out (source/destination reversed) */ 64 case GUAC_COMP_ROUT: 65 return CAIRO_OPERATOR_DEST_OUT; 66 67 /* Atop (source/destination reversed) */ 68 case GUAC_COMP_RATOP: 69 return CAIRO_OPERATOR_DEST_ATOP; 70 71 /* XOR */ 72 case GUAC_COMP_XOR: 73 return CAIRO_OPERATOR_XOR; 74 75 /* Additive */ 76 case GUAC_COMP_PLUS: 77 return CAIRO_OPERATOR_ADD; 78 79 /* If unrecognized, just default to CAIRO_OPERATOR_OVER */ 80 default: 81 return CAIRO_OPERATOR_OVER; 82 83 } 84 85} 86 87guacenc_display* guacenc_display_alloc(const char* path, const char* codec, 88 int width, int height, int bitrate) { 89 90 /* Prepare video encoding */ 91 guacenc_video* video = guacenc_video_alloc(path, codec, width, height, bitrate); 92 if (video == NULL) 93 return NULL; 94 95 /* Allocate display */ 96 guacenc_display* display = 97 (guacenc_display*) guac_mem_zalloc(sizeof(guacenc_display)); 98 99 /* Associate display with video output */ 100 display->output = video; 101 102 /* Allocate special-purpose cursor layer */ 103 display->cursor = guacenc_cursor_alloc(); 104 105 return display; 106 107} 108 109int guacenc_display_free(guacenc_display* display) { 110 111 int i; 112 113 /* Ignore NULL display */ 114 if (display == NULL) 115 return 0; 116 117 /* Finalize video */ 118 int retval = guacenc_video_free(display->output); 119 120 /* Free all buffers */ 121 for (i = 0; i < GUACENC_DISPLAY_MAX_BUFFERS; i++) 122 guacenc_buffer_free(display->buffers[i]); 123 124 /* Free all layers */ 125 for (i = 0; i < GUACENC_DISPLAY_MAX_LAYERS; i++) 126 guacenc_layer_free(display->layers[i]); 127 128 /* Free all streams */ 129 for (i = 0; i < GUACENC_DISPLAY_MAX_STREAMS; i++) 130 guacenc_image_stream_free(display->image_streams[i]); 131 132 /* Free cursor */ 133 guacenc_cursor_free(display->cursor); 134 135 guac_mem_free(display); 136 return retval; 137 138} 139