1ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul/************************************************************************** 2ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * 3ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * Copyright 2009 VMware, Inc. 4ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * All Rights Reserved. 5ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * 6ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * Permission is hereby granted, free of charge, to any person obtaining a 7ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * copy of this software and associated documentation files (the 8ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * "Software"), to deal in the Software without restriction, including 9ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * without limitation the rights to use, copy, modify, merge, publish, 10ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * distribute, sub license, and/or sell copies of the Software, and to 11ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * permit persons to whom the Software is furnished to do so, subject to 12ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * the following conditions: 13ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * 14ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * The above copyright notice and this permission notice (including the 15ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * next paragraph) shall be included in all copies or substantial portions 16ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * of the Software. 17ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * 18ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul * 26ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul **************************************************************************/ 27ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 28ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 29ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul/** 30663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell * Scene queue. We'll use two queues. One contains "full" scenes which 31663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell * are produced by the "setup" code. The other contains "empty" scenes 32663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell * which are produced by the "rast" code when it finishes rendering a scene. 33ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul */ 34ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 35591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell#include "util/u_ringbuffer.h" 369d0faea58cee28cf16bd31e6adbb2d93c391c556Brian Paul#include "util/u_memory.h" 37663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell#include "lp_scene_queue.h" 38ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 39ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 40ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 41663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell#define MAX_SCENE_QUEUE 4 42ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 43591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwellstruct scene_packet { 44591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell struct util_packet header; 45591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell struct lp_scene *scene; 46591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell}; 47ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 48ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul/** 49663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell * A queue of scenes 50ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul */ 51663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwellstruct lp_scene_queue 52ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul{ 53591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell struct util_ringbuffer *ring; 54ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul}; 55ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 56ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 57ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 58663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell/** Allocate a new scene queue */ 59663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwellstruct lp_scene_queue * 60663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwelllp_scene_queue_create(void) 61ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul{ 62663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell struct lp_scene_queue *queue = CALLOC_STRUCT(lp_scene_queue); 63591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell if (queue == NULL) 64591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell return NULL; 65591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell 66591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell queue->ring = util_ringbuffer_create( MAX_SCENE_QUEUE * 67591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell sizeof( struct scene_packet ) / 4); 68591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell if (queue->ring == NULL) 69591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell goto fail; 70591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell 71ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul return queue; 72591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell 73591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwellfail: 74591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell FREE(queue); 75591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell return NULL; 76ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul} 77ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 78ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 79663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell/** Delete a scene queue */ 80ea35993e7479793212529b1db081c84aa71ea4ccBrian Paulvoid 81663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwelllp_scene_queue_destroy(struct lp_scene_queue *queue) 82ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul{ 83591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell util_ringbuffer_destroy(queue->ring); 84591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell FREE(queue); 85ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul} 86ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 87ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 88663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell/** Remove first lp_scene from head of queue */ 89663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwellstruct lp_scene * 90591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwelllp_scene_dequeue(struct lp_scene_queue *queue, boolean wait) 91ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul{ 92591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell struct scene_packet packet; 93591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell enum pipe_error ret; 94ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 951462c1299c52c09a0fc5251067af75ae0192b9eaVinson Lee packet.scene = NULL; 961462c1299c52c09a0fc5251067af75ae0192b9eaVinson Lee 97591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell ret = util_ringbuffer_dequeue(queue->ring, 98591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell &packet.header, 99591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell sizeof packet / 4, 100591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell wait ); 101591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell if (ret != PIPE_OK) 102591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell return NULL; 103ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 104591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell return packet.scene; 105ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul} 106ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 107ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 108663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell/** Add an lp_scene to tail of queue */ 109ea35993e7479793212529b1db081c84aa71ea4ccBrian Paulvoid 110663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwelllp_scene_enqueue(struct lp_scene_queue *queue, struct lp_scene *scene) 111ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul{ 112591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell struct scene_packet packet; 113ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 114591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell packet.header.dwords = sizeof packet / 4; 115591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell packet.header.data24 = 0; 116591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell packet.scene = scene; 117721b5167dcb2558b4bd53e09fc33936feeb93744Brian Paul 118591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell util_ringbuffer_enqueue(queue->ring, &packet.header); 119ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul} 120ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 121ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 122ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 123ea35993e7479793212529b1db081c84aa71ea4ccBrian Paul 124591401ff05f878ff1607a1a34db1319103025d8fKeith Whitwell 125