Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / gallium / drivers / llvmpipe / lp_scene_queue.c
1 /**************************************************************************
2  *
3  * Copyright 2009 VMware, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27
28
29 /**
30  * Scene queue.  We'll use two queues.  One contains "full" scenes which
31  * are produced by the "setup" code.  The other contains "empty" scenes
32  * which are produced by the "rast" code when it finishes rendering a scene.
33  */
34
35 #include "util/u_ringbuffer.h"
36 #include "util/u_memory.h"
37 #include "lp_scene_queue.h"
38
39
40
41 #define MAX_SCENE_QUEUE 4
42
43 struct scene_packet {
44    struct util_packet header;
45    struct lp_scene *scene;
46 };
47
48 /**
49  * A queue of scenes
50  */
51 struct lp_scene_queue
52 {
53    struct util_ringbuffer *ring;
54 };
55
56
57
58 /** Allocate a new scene queue */
59 struct lp_scene_queue *
60 lp_scene_queue_create(void)
61 {
62    struct lp_scene_queue *queue = CALLOC_STRUCT(lp_scene_queue);
63    if (queue == NULL)
64       return NULL;
65
66    queue->ring = util_ringbuffer_create( MAX_SCENE_QUEUE * 
67                                          sizeof( struct scene_packet ) / 4);
68    if (queue->ring == NULL)
69       goto fail;
70
71    return queue;
72
73 fail:
74    FREE(queue);
75    return NULL;
76 }
77
78
79 /** Delete a scene queue */
80 void
81 lp_scene_queue_destroy(struct lp_scene_queue *queue)
82 {
83    util_ringbuffer_destroy(queue->ring);
84    FREE(queue);
85 }
86
87
88 /** Remove first lp_scene from head of queue */
89 struct lp_scene *
90 lp_scene_dequeue(struct lp_scene_queue *queue, boolean wait)
91 {
92    struct scene_packet packet;
93    enum pipe_error ret;
94
95    packet.scene = NULL;
96
97    ret = util_ringbuffer_dequeue(queue->ring,
98                                  &packet.header,
99                                  sizeof packet / 4,
100                                  wait );
101    if (ret != PIPE_OK)
102       return NULL;
103
104    return packet.scene;
105 }
106
107
108 /** Add an lp_scene to tail of queue */
109 void
110 lp_scene_enqueue(struct lp_scene_queue *queue, struct lp_scene *scene)
111 {
112    struct scene_packet packet;
113
114    packet.header.dwords = sizeof packet / 4;
115    packet.header.data24 = 0;
116    packet.scene = scene;
117
118    util_ringbuffer_enqueue(queue->ring, &packet.header);
119 }
120
121
122
123
124