summaryrefslogtreecommitdiff
path: root/EGL/tizen/yagl_tizen_pbuffer.c
blob: 266097626cb77ed4d7faea49b51e4deb4ade8840 (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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
 * YaGL
 *
 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact :
 * Vasiliy Ulyanov <v.ulyanov@samsung.com>
 * Jinhyung Jo <jinhyung.jo@samsung.com>
 * Sangho Park <sangho1206.park@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_pbuffer.h"
#include "yagl_native_display.h"
#include "yagl_native_drawable.h"
#include "yagl_log.h"
#include "yagl_malloc.h"
#include "yagl_gbm.h"
#include "vigs.h"
#include <assert.h>
#include <string.h>

/* This file is almost the same as wayland backend, not necessary to call tpl */

#define YAGL_TIZEN_PBUFFER(os_pbuffer) ((struct vigs_drm_surface *)(os_pbuffer))

static int yagl_tizen_pbuffer_get_buffer(struct yagl_native_drawable *drawable,
                                           yagl_native_attachment attachment,
                                           uint32_t *buffer_name,
                                           struct vigs_drm_surface **buffer_sfc)
{
    struct vigs_drm_surface *drm_sfc = YAGL_TIZEN_PBUFFER(drawable->os_drawable);

    YAGL_LOG_FUNC_SET(yagl_tizen_pbuffer_get_buffer);

    switch (attachment) {
    case yagl_native_attachment_front:
        break;
    case yagl_native_attachment_back:
    default:
        YAGL_LOG_ERROR("Bad attachment %u", attachment);
        return 0;
    }

    vigs_drm_gem_ref(&drm_sfc->gem);

    *buffer_sfc = drm_sfc;

    return 1;
}

static int yagl_tizen_pbuffer_validate(struct yagl_native_drawable *drawable)
{
    return 1;
}

static int yagl_tizen_pbuffer_get_buffer_age(struct yagl_native_drawable *drawable)
{
    return 0;
}

static void yagl_tizen_pbuffer_swap_buffers(struct yagl_native_drawable *drawable)
{
}

static void yagl_tizen_pbuffer_wait(struct yagl_native_drawable *drawable,
                                      uint32_t width,
                                      uint32_t height)
{
}

static void yagl_tizen_pbuffer_copy_to_pixmap(struct yagl_native_drawable *drawable,
                                                yagl_os_pixmap os_pixmap,
                                                uint32_t from_x,
                                                uint32_t from_y,
                                                uint32_t to_x,
                                                uint32_t to_y,
                                                uint32_t width,
                                                uint32_t height)
{
}

static void yagl_tizen_pbuffer_set_swap_interval(struct yagl_native_drawable *drawable,
                                                   int interval)
{
}

static void yagl_tizen_pbuffer_get_geometry(struct yagl_native_drawable *drawable,
                                              uint32_t *width,
                                              uint32_t *height,
                                              uint32_t *depth)
{
    struct vigs_drm_surface *drm_sfc = YAGL_TIZEN_PBUFFER(drawable->os_drawable);

    *width = drm_sfc->width;
    *height = drm_sfc->height;

    switch (drm_sfc->format) {
    case vigs_drm_surface_bgrx8888:
        *depth = 24;
        break;
    case vigs_drm_surface_bgra8888:
        *depth = 32;
        break;
    default: /* should never happen */
        assert(NULL);
        break;
    }
}

static struct yagl_native_image
    *yagl_tizen_pbuffer_get_image(struct yagl_native_drawable *drawable,
                                    uint32_t width,
                                    uint32_t height)
{
    return NULL;
}

static void yagl_tizen_pbuffer_destroy(struct yagl_native_drawable *drawable)
{
    struct vigs_drm_surface *drm_sfc = YAGL_TIZEN_PBUFFER(drawable->os_drawable);

    vigs_drm_gem_unref(&drm_sfc->gem);

    yagl_native_drawable_cleanup(drawable);

    yagl_free(drawable);
}

struct yagl_native_drawable
    *yagl_tizen_pbuffer_create(struct yagl_native_display *dpy,
                                 uint32_t width,
                                 uint32_t height,
                                 uint32_t depth)
{
    vigs_drm_surface_format format;
    struct vigs_drm_surface *drm_sfc;
    struct yagl_native_drawable *pbuffer;
    int ret;

    YAGL_LOG_FUNC_SET(yagl_tizen_pbuffer_create);

    switch (depth) {
    case 24:
        format = vigs_drm_surface_bgrx8888;
        break;
    case 32:
        format = vigs_drm_surface_bgra8888;
        break;
    default:
        YAGL_LOG_ERROR("Bad depth value: %u", depth);
        return NULL;
    }

    ret = vigs_drm_surface_create(dpy->drm_dev,
                                  width,
                                  height,
                                  width * 4, /* stride */
                                  format,
                                  0, /* scanout */
                                  &drm_sfc);

    if (ret) {
        YAGL_LOG_ERROR("vigs_drm_surface_create failed: %s", strerror(-ret));
        return NULL;
    }

    pbuffer = yagl_malloc0(sizeof(*pbuffer));

    yagl_native_drawable_init(pbuffer, dpy, (yagl_os_drawable)drm_sfc);

    pbuffer->get_buffer = &yagl_tizen_pbuffer_get_buffer;
    pbuffer->validate = &yagl_tizen_pbuffer_validate;
    pbuffer->get_buffer_age = &yagl_tizen_pbuffer_get_buffer_age;
    pbuffer->swap_buffers = &yagl_tizen_pbuffer_swap_buffers;
    pbuffer->wait = &yagl_tizen_pbuffer_wait;
    pbuffer->copy_to_pixmap = &yagl_tizen_pbuffer_copy_to_pixmap;
    pbuffer->set_swap_interval = &yagl_tizen_pbuffer_set_swap_interval;
    pbuffer->get_geometry = &yagl_tizen_pbuffer_get_geometry;
    pbuffer->get_image = &yagl_tizen_pbuffer_get_image;
    pbuffer->destroy = &yagl_tizen_pbuffer_destroy;

    return pbuffer;
}