1bde3ed7517cc876cb2a6e174ea2a96a75938e787Kun Wang/*
2f91c8768670386683a281cc39141e21bdda9c97fKun Wang * Copyright (c) 2011 Intel Corporation. All Rights Reserved.
3f91c8768670386683a281cc39141e21bdda9c97fKun Wang *
4f91c8768670386683a281cc39141e21bdda9c97fKun Wang * Permission is hereby granted, free of charge, to any person obtaining a
5f91c8768670386683a281cc39141e21bdda9c97fKun Wang * copy of this software and associated documentation files (the
6f91c8768670386683a281cc39141e21bdda9c97fKun Wang * "Software"), to deal in the Software without restriction, including
7f91c8768670386683a281cc39141e21bdda9c97fKun Wang * without limitation the rights to use, copy, modify, merge, publish,
8f91c8768670386683a281cc39141e21bdda9c97fKun Wang * distribute, sub license, and/or sell copies of the Software, and to
9f91c8768670386683a281cc39141e21bdda9c97fKun Wang * permit persons to whom the Software is furnished to do so, subject to
10f91c8768670386683a281cc39141e21bdda9c97fKun Wang * the following conditions:
113f3d1e8746d2b793c982ac19a73061e006b1b178Kun Wang *
12f91c8768670386683a281cc39141e21bdda9c97fKun Wang * The above copyright notice and this permission notice (including the
13f91c8768670386683a281cc39141e21bdda9c97fKun Wang * next paragraph) shall be included in all copies or substantial portions
14f91c8768670386683a281cc39141e21bdda9c97fKun Wang * of the Software.
153f3d1e8746d2b793c982ac19a73061e006b1b178Kun Wang *
16f91c8768670386683a281cc39141e21bdda9c97fKun Wang * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17f91c8768670386683a281cc39141e21bdda9c97fKun Wang * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18f91c8768670386683a281cc39141e21bdda9c97fKun Wang * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19f91c8768670386683a281cc39141e21bdda9c97fKun Wang * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20f91c8768670386683a281cc39141e21bdda9c97fKun Wang * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21f91c8768670386683a281cc39141e21bdda9c97fKun Wang * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22f91c8768670386683a281cc39141e21bdda9c97fKun Wang * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23f91c8768670386683a281cc39141e21bdda9c97fKun Wang *
24bde3ed7517cc876cb2a6e174ea2a96a75938e787Kun Wang * Authors:
25bde3ed7517cc876cb2a6e174ea2a96a75938e787Kun Wang *    Jason Hu  <jason.hu@intel.com>
26bde3ed7517cc876cb2a6e174ea2a96a75938e787Kun Wang *    Zhaohan Ren  <zhaohan.ren@intel.com>
27bde3ed7517cc876cb2a6e174ea2a96a75938e787Kun Wang *
28bde3ed7517cc876cb2a6e174ea2a96a75938e787Kun Wang */
29bde3ed7517cc876cb2a6e174ea2a96a75938e787Kun Wang
30bde3ed7517cc876cb2a6e174ea2a96a75938e787Kun Wang
314b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo#ifndef _PSB_XRANDR_H_
324b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo#define _PSB_XRANDR_H_
334b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo#include <stdio.h>
344b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo#include <X11/Xlib.h>
354b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo#include <X11/Xlibint.h>
364b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo#include <X11/Xproto.h>
374b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo#include <X11/Xatom.h>
384b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo#include <X11/extensions/Xrandr.h>
39bde3ed7517cc876cb2a6e174ea2a96a75938e787Kun Wang#include <X11/extensions/Xrender.h>     /* we share subpixel information */
404b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo#include <pthread.h>
414b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo#include <string.h>
424b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo#include <stdlib.h>
434b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo#include <stdarg.h>
444b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo#include <math.h>
454b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo#include <va/va_backend.h>
464b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
474b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuotypedef enum _psb_output_device {
484b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    MIPI0,
494b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    MIPI1,
504b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    LVDS0,
514b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    HDMI,
524b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo} psb_output_device;
534b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
544b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuotypedef enum _psb_output_device_mode {
554b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    SINGLE_MIPI0,
564b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    SINGLE_MIPI1,
574b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    SINGLE_HDMI,
584b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    SINGLE_LVDS0,
594b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    MIPI0_MIPI1,
604b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    MIPI0_HDMI,
614b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    MIPI0_MIPI1_HDMI,
624b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    MIPI1_HDMI,
634b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo} psb_output_device_mode;
644b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
654b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuotypedef enum _psb_hdmi_mode {
66dc1209519284865899ca8d990b3a2c7dbca8ae08wangkun    CLONE,
674b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    EXTENDED,
68dc1209519284865899ca8d990b3a2c7dbca8ae08wangkun    EXTENDEDVIDEO,
694b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    SINGLE,
704b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    UNKNOWNVIDEOMODE,
714b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo} psb_hdmi_mode;
724b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
734b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuotypedef enum _psb_extvideo_center {
744b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    NOCENTER,
754b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    CENTER,
764b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    UNKNOWNCENTER,
774b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo} psb_extvideo_center;
784b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
794b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuotypedef enum _psb_extvideo_subtitle {
80dc1209519284865899ca8d990b3a2c7dbca8ae08wangkun    BOTH,
81dc1209519284865899ca8d990b3a2c7dbca8ae08wangkun    ONLY_HDMI,
824b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    NOSUBTITLE,
834b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo} psb_extvideo_subtitle;
844b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
85dc1209519284865899ca8d990b3a2c7dbca8ae08wangkuntypedef enum _psb_xrandr_location {
864b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    NORMAL, ABOVE, BELOW, LEFT_OF, RIGHT_OF,
874b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo} psb_xrandr_location;
884b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
894b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuotypedef struct _psb_extvideo_prop_s {
904b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    psb_hdmi_mode ExtVideoMode;
914b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    psb_hdmi_mode ExtDesktopMode;
924b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
934b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    unsigned int ExtVideoMode_XRes;
944b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    unsigned int ExtVideoMode_YRes;
954b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    unsigned int ExtVideoMode_X_Offset;
964b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    unsigned int ExtVideoMode_Y_Offset;
974b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    unsigned int OverscanMode;
984b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    unsigned int PANELFITTING;
994b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1004b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    psb_extvideo_center ExtVideoMode_Center;
1014b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    psb_extvideo_subtitle ExtVideoMode_SubTitle;
1024b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1034b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo} psb_extvideo_prop_s, *psb_extvideo_prop_p;
1044b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1054b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuotypedef struct _psb_xrandr_crtc_s {
1064b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    struct _psb_xrandr_crtc_s *next;
1074b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1084b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    RRCrtc crtc_id;
1094b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    RRMode crtc_mode;
1104b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1114b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    unsigned int width;
1124b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    unsigned int height;
1134b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    unsigned int x;
1144b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    unsigned int y;
1154b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1164b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    Rotation rotation;
1174b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    psb_xrandr_location location;
1184b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1194b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    int noutput;
1204b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1214b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo} psb_xrandr_crtc_s, *psb_xrandr_crtc_p;
1224b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
123dc1209519284865899ca8d990b3a2c7dbca8ae08wangkuntypedef struct _psb_xrandr_output_s {
1244b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    RROutput output_id;
1254b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    char name[10];
1264b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    struct _psb_xrandr_output_s *next;
1274b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1284b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    Connection connection;
1294b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1304b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    psb_xrandr_crtc_p crtc;
1314b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1324b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo} psb_xrandr_output_s, *psb_xrandr_output_p;
1334b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
134dc1209519284865899ca8d990b3a2c7dbca8ae08wangkuntypedef struct _psb_xrandr_info_s {
1354b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    psb_xrandr_crtc_p local_crtc[2];
1364b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    psb_xrandr_crtc_p extend_crtc;
1374b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1384b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    psb_xrandr_output_p local_output[2];
1394b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    psb_xrandr_output_p extend_output;
1404b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1414b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    unsigned int nconnected_output;
1424b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1434b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    psb_extvideo_prop_p hdmi_extvideo_prop;
1444b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1454b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    int lvds0_enabled;
1464b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    int mipi0_enabled;
1474b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    int mipi1_enabled;
1484b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    int hdmi_enabled;
1494b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1504b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    Rotation mipi0_rotation;
1514b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    Rotation mipi1_rotation;
1524b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    Rotation hdmi_rotation;
1534b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1544b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    int output_changed;
1554b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    psb_output_device_mode output_device_mode;
1564b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1574b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    psb_xrandr_crtc_p crtc_head, crtc_tail;
1584b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    psb_xrandr_output_p output_head, output_tail;
1594b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1604b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    pthread_mutex_t psb_extvideo_mutex;
1614b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    XRRScreenResources *res;
1624b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    Display *dpy;
1634b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    Window root;
1644b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo    Atom psb_exit_atom;
1654b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo} psb_xrandr_info_s, *psb_xrandr_info_p;
1664b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1674b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1684b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuoint psb_xrandr_hdmi_enabled();
1694b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuoint psb_xrandr_mipi1_enabled();
1704b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuoint psb_xrandr_single_mode();
1714b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuoint psb_xrandr_clone_mode();
1724b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuoint psb_xrandr_extend_mode();
1734b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuoint psb_xrandr_extvideo_mode();
1744b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuoint psb_xrandr_outputchanged();
1754b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1764b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, ShuoWindow psb_xrandr_create_full_screen_window(unsigned int destx, unsigned int desty, unsigned int destw, unsigned int desth);
177dc1209519284865899ca8d990b3a2c7dbca8ae08wangkunVAStatus psb_xrandr_extvideo_prop(unsigned int *xres, unsigned int *yres, unsigned int *xoffset,
178dc1209519284865899ca8d990b3a2c7dbca8ae08wangkun                                  unsigned int *yoffset, psb_extvideo_center *center, psb_extvideo_subtitle *subtitle,
179dc1209519284865899ca8d990b3a2c7dbca8ae08wangkun                                  unsigned int *overscanmode, unsigned int *pannelfitting);
1804b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, ShuoVAStatus psb_xrandr_local_crtc_coordinate(psb_output_device *local_device_enabled, int *x, int *y, int *width, int *height, Rotation *rotation);
1814b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, ShuoVAStatus psb_xrandr_extend_crtc_coordinate(psb_output_device *extend_device_enabled, int *x, int *y, int *width, int *height, psb_xrandr_location *location, Rotation *rotation);
1824b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1834b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuovoid psb_xrandr_refresh(VADriverContextP ctx);
1844b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuovoid psb_xrandr_thread();
1854b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, ShuoVAStatus psb_xrandr_thread_create(VADriverContextP ctx);
186dc1209519284865899ca8d990b3a2c7dbca8ae08wangkunVAStatus psb_xrandr_thread_exit();
187dc1209519284865899ca8d990b3a2c7dbca8ae08wangkunVAStatus psb_xrandr_init(VADriverContextP ctx);
1884b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, ShuoVAStatus psb_xrandr_deinit();
1894b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo
1904b5b72d7dd3fe944d75029ff0ca6db1e74600e59Liu, Shuo#endif /* _PSB_XRANDR_H_ */
191