summaryrefslogtreecommitdiff
path: root/EGL/tizen/yagl_tizen_display.c
blob: b95ac924bf7e4babf1ac8cbf29d67841c5d94ff8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
 * YaGL
 *
 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact :
 * Stanislav Vorobiov <s.vorobiov@samsung.com>
 * Jinhyung Jo <jinhyung.jo@samsung.com>
 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
 *
 * 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 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.
 *
 * Contributors:
 * - S-Core Co., Ltd
 *
 */

#include "yagl_tizen_display.h"
#include "yagl_tizen_window.h"
#include "yagl_tizen_pbuffer.h"
#include <tbm_bufmgr_backend.h>
#include "yagl_log.h"
#include "yagl_malloc.h"
#include "vigs.h"
#include <sys/fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>



static int yagl_tizen_display_authenticate(struct yagl_native_display *dpy,
                                             uint32_t id)
{
    return 1;
}

static struct yagl_native_drawable
    *yagl_tizen_display_wrap_window(struct yagl_native_display *dpy,
                                      yagl_os_window os_window)
{
    return yagl_tizen_window_create(dpy, os_window);
}

static struct yagl_native_drawable
    *yagl_tizen_display_wrap_pixmap(struct yagl_native_display *dpy,
                                      yagl_os_pixmap os_pixmap)
{
    return NULL;
}

static struct yagl_native_drawable
    *yagl_tizen_display_create_pixmap(struct yagl_native_display *dpy,
                                        uint32_t width,
                                        uint32_t height,
                                        uint32_t depth)
{
    /*
     * Wayland actaully has no pixmap type. This is just for creating
     * a pbuffer and to make Tizen conformance tests happy.
     */
    return  yagl_tizen_pbuffer_create(dpy, width, height, depth);
}

static struct yagl_native_image
    *yagl_tizen_display_create_image(struct yagl_native_display *dpy,
                                       uint32_t width,
                                       uint32_t height,
                                       uint32_t depth)
{
    return NULL;
}

static int yagl_tizen_display_get_visual(struct yagl_native_display *dpy,
                                           int *visual_id,
                                           int *visual_type)
{
    tpl_display_t   *tpl_display = NULL;
    tpl_result_t    ret;

    YAGL_LOG_FUNC_SET(yagl_tizen_display_get_visual);

    tpl_display = tpl_display_get((tpl_handle_t)dpy->os_dpy);


    ret = tpl_display_query_config(tpl_display, TPL_SURFACE_TYPE_WINDOW,
                              8, 8, 8, 8, 32,
                              visual_id, NULL);
    if (ret != TPL_ERROR_NONE) {
        YAGL_LOG_ERROR("query error");
    }

    *visual_type = 0;

    return 1;
}

static void yagl_tizen_display_update_wl_server(struct yagl_native_display *dpy)
{
    return ;
}

static void yagl_tizen_display_destroy(struct yagl_native_display *dpy)
{
    struct yagl_tizen_display *tizen_dpy = (struct yagl_tizen_display *)dpy;
    if (tizen_dpy->tpl_display != NULL) {
        tpl_object_unreference((tpl_object_t *)tizen_dpy->tpl_display);
    }

    yagl_native_display_cleanup(dpy);

    yagl_free(dpy);
}

struct yagl_native_display
    *yagl_tizen_display_create(struct yagl_native_platform *platform,
                                 yagl_os_display os_dpy)
{
    struct yagl_tizen_display *dpy;
    tbm_bufmgr bufmgr;
    struct vigs_drm_device *drm_dev = NULL;

    YAGL_LOG_FUNC_ENTER(yagl_tizen_display_create, "os_dpy = %p", os_dpy);

    dpy = yagl_malloc0(sizeof(*dpy));

    dpy->drm_fd = -1;

    dpy->tpl_display = tpl_display_create(TPL_BACKEND_UNKNOWN, (tpl_handle_t)os_dpy);

    if (!dpy->tpl_display) {
        YAGL_LOG_ERROR("Failed to tpl_display");
        goto fail;
    }

    bufmgr = tbm_bufmgr_init(-1);
    drm_dev = (struct vigs_drm_device *)tbm_backend_get_priv_from_bufmgr(bufmgr);

    yagl_native_display_init(&dpy->base,
                            platform,
                            os_dpy,
                            drm_dev,
                            NULL);
    dpy->base.authenticate = &yagl_tizen_display_authenticate;
    dpy->base.wrap_window = &yagl_tizen_display_wrap_window;
    dpy->base.wrap_pixmap = &yagl_tizen_display_wrap_pixmap;
    dpy->base.create_pixmap = &yagl_tizen_display_create_pixmap;
    dpy->base.create_image = &yagl_tizen_display_create_image;
    dpy->base.get_visual = &yagl_tizen_display_get_visual;
    dpy->base.update_wl_server = &yagl_tizen_display_update_wl_server;
    dpy->base.destroy = &yagl_tizen_display_destroy;

    YAGL_LOG_FUNC_EXIT("display %p created", dpy);

    return &dpy->base;

fail:
    yagl_free(dpy);

    YAGL_LOG_FUNC_EXIT(NULL);

    return NULL;
}