1/* 2 * Copyright © 2014 Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 */ 23 24#ifdef HAVE_DIX_CONFIG_H 25#include <dix-config.h> 26#endif 27 28#include "kdrive.h" 29#include "kxv.h" 30#include "ephyr.h" 31#include "glamor_priv.h" 32 33#include <X11/extensions/Xv.h> 34#include "fourcc.h" 35 36#define NUM_FORMATS 3 37 38static KdVideoFormatRec Formats[NUM_FORMATS] = { 39 {15, TrueColor}, {16, TrueColor}, {24, TrueColor} 40}; 41 42static void 43ephyr_glamor_xv_stop_video(KdScreenInfo *screen, void *data, Bool cleanup) 44{ 45 if (!cleanup) 46 return; 47 48 glamor_xv_stop_video(data); 49} 50 51static int 52ephyr_glamor_xv_set_port_attribute(KdScreenInfo *screen, 53 Atom attribute, int value, void *data) 54{ 55 return glamor_xv_set_port_attribute(data, attribute, (INT32)value); 56} 57 58static int 59ephyr_glamor_xv_get_port_attribute(KdScreenInfo *screen, 60 Atom attribute, int *value, void *data) 61{ 62 return glamor_xv_get_port_attribute(data, attribute, (INT32 *)value); 63} 64 65static void 66ephyr_glamor_xv_query_best_size(KdScreenInfo *screen, 67 Bool motion, 68 short vid_w, short vid_h, 69 short drw_w, short drw_h, 70 unsigned int *p_w, unsigned int *p_h, 71 void *data) 72{ 73 *p_w = drw_w; 74 *p_h = drw_h; 75} 76 77static int 78ephyr_glamor_xv_query_image_attributes(KdScreenInfo *screen, 79 int id, 80 unsigned short *w, unsigned short *h, 81 int *pitches, int *offsets) 82{ 83 return glamor_xv_query_image_attributes(id, w, h, pitches, offsets); 84} 85 86static int 87ephyr_glamor_xv_put_image(KdScreenInfo *screen, 88 DrawablePtr pDrawable, 89 short src_x, short src_y, 90 short drw_x, short drw_y, 91 short src_w, short src_h, 92 short drw_w, short drw_h, 93 int id, 94 unsigned char *buf, 95 short width, 96 short height, 97 Bool sync, 98 RegionPtr clipBoxes, void *data) 99{ 100 return glamor_xv_put_image(data, pDrawable, 101 src_x, src_y, 102 drw_x, drw_y, 103 src_w, src_h, 104 drw_w, drw_h, 105 id, buf, width, height, sync, clipBoxes); 106} 107 108void 109ephyr_glamor_xv_init(ScreenPtr screen) 110{ 111 KdVideoAdaptorRec *adaptor; 112 glamor_port_private *port_privates; 113 KdVideoEncodingRec encoding = { 114 0, 115 "XV_IMAGE", 116 /* These sizes should probably be GL_MAX_TEXTURE_SIZE instead 117 * of 2048, but our context isn't set up yet. 118 */ 119 2048, 2048, 120 {1, 1} 121 }; 122 int i; 123 124 glamor_xv_core_init(screen); 125 126 adaptor = xnfcalloc(1, sizeof(*adaptor)); 127 128 adaptor->name = "glamor textured video"; 129 adaptor->type = XvWindowMask | XvInputMask | XvImageMask; 130 adaptor->flags = 0; 131 adaptor->nEncodings = 1; 132 adaptor->pEncodings = &encoding; 133 134 adaptor->pFormats = Formats; 135 adaptor->nFormats = NUM_FORMATS; 136 137 adaptor->nPorts = 16; /* Some absurd number */ 138 port_privates = xnfcalloc(adaptor->nPorts, 139 sizeof(glamor_port_private)); 140 adaptor->pPortPrivates = xnfcalloc(adaptor->nPorts, 141 sizeof(glamor_port_private *)); 142 for (i = 0; i < adaptor->nPorts; i++) { 143 adaptor->pPortPrivates[i].ptr = &port_privates[i]; 144 glamor_xv_init_port(&port_privates[i]); 145 } 146 147 adaptor->pAttributes = glamor_xv_attributes; 148 adaptor->nAttributes = glamor_xv_num_attributes; 149 150 adaptor->pImages = glamor_xv_images; 151 adaptor->nImages = glamor_xv_num_images; 152 153 adaptor->StopVideo = ephyr_glamor_xv_stop_video; 154 adaptor->SetPortAttribute = ephyr_glamor_xv_set_port_attribute; 155 adaptor->GetPortAttribute = ephyr_glamor_xv_get_port_attribute; 156 adaptor->QueryBestSize = ephyr_glamor_xv_query_best_size; 157 adaptor->PutImage = ephyr_glamor_xv_put_image; 158 adaptor->QueryImageAttributes = ephyr_glamor_xv_query_image_attributes; 159 160 KdXVScreenInit(screen, adaptor, 1); 161} 162