os/graphics/graphicscomposition/openwfcompositionengine/adaptation/src/Platform/Graphics/owfnativestream.c
Update contrib.
1 /* Copyright (c) 2009 The Khronos Group Inc.
2 * Portions copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies)
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and/or associated documentation files (the
6 * "Materials"), to deal in the Materials without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Materials, and to
9 * permit persons to whom the Materials are furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Materials.
15 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
25 * Ring buffer based Image Stream implementation for Linux.
34 #define OWF_NATIVESTREAM_HANDLE 0xAB
39 #include "owfnativestream.h"
40 #include "owfscreen.h"
41 #include "owfmemory.h"
45 #include "owfhstore.h"
47 /*needed for owfNativeStreamFromWFC function */
48 #include "WF/wfcplatform.h"
50 /* macro for fetching stream object by handle */
51 #define GET_STREAM(ns, s) ns = owfNativeStreamGet(s)
53 /* stream null checks */
54 #define CHECK_STREAM(v) if (NULL == ns) { return v;}
55 #define CHECK_STREAM_NR() if (NULL == ns) { return; }
57 #define BUFFER_HANDLE_BASE 0x100
58 #define STREAM_HANDLE_BASE 10000
59 #define STREAM_HASHTABLE_SIZE 0x100
61 /* buffer handle sanity checks */
62 #define CHECK_BUFFER_NR(x) if ((x) < BUFFER_HANDLE_BASE || \
63 (x) >= BUFFER_HANDLE_BASE + ns->bufferCount) \
68 #define CHECK_BUFFER(x,v) if ((x) < BUFFER_HANDLE_BASE || \
69 (x) >= BUFFER_HANDLE_BASE + ns->bufferCount) \
74 #define BUFFER(x) ns->bufferList[(x)-BUFFER_HANDLE_BASE]
76 #define INDEX_TO_HANDLE(x) ((OWFNativeStreamBuffer) ((x)+BUFFER_HANDLE_BASE))
77 #define HANDLE_TO_INDEX(x) ((int) ((x)-BUFFER_HANDLE_BASE))
86 * Structure for image stream.
89 OWFNativeStreamType handle; /* stream handle */
95 OWFint width, /* frame width (pixels) */
96 height, /* frame height (pixels) */
97 stride; /* size of single row (bytes) */
98 OWF_IMAGE_FORMAT colorFormat;
99 OWFint referenceCount;
101 OWF_SEMAPHORE writer;
105 OWFboolean sendNotifications;
106 OWFboolean protected; /* protection flag to prevent the
107 user from destroying the stream
108 (for onscreen-context use) */
110 OWF_SYNC_DESC* bufferSyncs; /* sync object to be signalled when
111 buffer is 'consumed' */
115 static const OWF_IMAGE_FORMAT owfOnScreenColorFormat =
123 /*============================================================================
125 *============================================================================*/
127 /*!---------------------------------------------------------------------------
129 *----------------------------------------------------------------------------*/
133 /*!---------------------------------------------------------------------------
134 * Add stream to internal stream dictionary
136 * \param handle Stream handle
137 * \param stream Stream object associated with the handle
139 * \return Boolean value indicating whether the addition was succesful
140 *----------------------------------------------------------------------------*/
142 owfNativeStreamAddStream(OWF_NATIVE_STREAM* stream)
144 OWFHandle handle = OWF_INVALID_HANDLE;
146 handle = OWF_HStore_HandleCreate(OWF_NATIVESTREAM_HANDLE, stream);
151 /*----------------------------------------------------------------------------
152 * Returns the stream object associated to given handle
154 * \param handle Stream handle
156 * \return Stream object or NULL if the handle is invalid
157 *----------------------------------------------------------------------------*/
158 static OWF_NATIVE_STREAM*
159 owfNativeStreamGet(OWFNativeStreamType handle)
161 return (OWF_NATIVE_STREAM*) OWF_HStore_GetObj(handle, OWF_NATIVESTREAM_HANDLE);
164 /*----------------------------------------------------------------------------
165 * Remove stream from internal stream dictionary
167 * \param handle Stream handle
169 * \return Boolean value indicating success of the deletion
170 *----------------------------------------------------------------------------*/
172 owfNativeStreamRemove(OWFNativeStreamType handle)
174 OWF_HStore_HandleDelete(handle);
178 /*!---------------------------------------------------------------------------
179 * Notify stream's observers about an event
181 * \param stream Stream
182 * \param event Event to notify about
183 *----------------------------------------------------------------------------*/
184 static void owfNativeStreamNotifyObservers(OWFNativeStreamType stream,
185 OWFNativeStreamEvent event)
187 OWF_NODE* iter = NULL;
189 OWF_NATIVE_STREAM* ns;
191 DPRINT(("owfNativeStreamNotifyObservers(%p, %x)",
194 GET_STREAM(ns, stream);
197 if (ns->sendNotifications)
199 OWF_Mutex_Lock(&ns->mutex);
201 iter = ns->observers;
204 OWFStreamCallbackData* cbdata = (OWFStreamCallbackData*) iter->data;
206 DPRINT(("Stream callback: (%p)(%p, %x, %p)",
207 cbdata->callback, stream, event, cbdata->data));
209 if (cbdata->callback)
211 (cbdata->callback)(stream, event, cbdata->data);
215 OWF_Mutex_Unlock(&ns->mutex);
219 /*----------------------------------------------------------------------------
220 * Observer equality comparison
221 *----------------------------------------------------------------------------*/
223 ObserversEqual(void* arg1, void* arg2)
225 #define _CALLBACK(x) ((OWFStreamCallbackData*)(x))
228 return (OWFint)( _CALLBACK(arg1)->callback ==_CALLBACK(arg2)->callback
229 && _CALLBACK(arg1)->data ==_CALLBACK(arg2)->data
236 ObserverFuncsEqual(void* arg1, void* arg2)
238 #define _CALLBACK(x) ((OWFStreamCallbackData*)(x))
241 return (OWFint)(_CALLBACK(arg1)->callback ==_CALLBACK(arg2)->callback
248 ObserverDatasEqual(void* arg1, void* arg2)
250 #define _CALLBACK(x) ((OWFStreamCallbackData*)(x))
253 return (OWFint)(_CALLBACK(arg1)->data ==_CALLBACK(arg2)->data
259 /*----------------------------------------------------------------------------
260 * Destroy native stream (implementation)
262 * \param ns Native stream object
263 *----------------------------------------------------------------------------*/
265 owfNativeStreamDoDestroy(OWF_NATIVE_STREAM* ns)
271 /* bail out if the stream is protected (e.g. the user tries to
272 * free on-screen context's stream) */
273 OWF_Mutex_Lock(&ns->mutex);
276 OWF_Mutex_Unlock(&ns->mutex);
280 /* decrease reference count and check whether it is safe to
281 * actually destroy the stream */
282 ns->referenceCount--;
284 if (ns->referenceCount > 0) {
285 OWF_Mutex_Unlock(&ns->mutex);
289 /* remove from internal dictionary */
290 if (ns->handle != OWF_INVALID_HANDLE)
292 owfNativeStreamRemove(ns->handle);
295 OWF_ASSERT(0 == ns->lockCount);
297 /* release resources allocated by the stream. */
298 for (ii = 0; ii < ns->bufferCount; ii++)
300 OWF_Image_FreeData(&ns->bufferList[ii]);
302 xfree(ns->bufferList);
304 OWF_Semaphore_Destroy(&ns->writer);
305 OWF_Mutex_Unlock(&ns->mutex);
306 OWF_Mutex_Destroy(&ns->mutex);
310 while (ns->observers)
312 OWF_NODE* next = ns->observers->next;
313 xfree(ns->observers);
314 ns->observers = next;
317 xfree(ns->bufferSyncs);
318 xfree(ns->bufferRefs);
322 /*============================================================================
323 * PUBLIC API STARTS HERE
324 *============================================================================*/
326 /*!----------------------------------------------------------------------------
327 * Create new native stream.
329 * \param width Stream image buffer width
330 * \param height Stream image buffer height
331 * \param imageFormat Stream image buffer format
332 * \param nbufs Number of image buffers to allocate
334 * \param Handle to newly created stream or OWF_INVALID_HANDLe if no
335 * stream could be created.
336 *----------------------------------------------------------------------------*/
337 OWF_PUBLIC OWFNativeStreamType
338 owfNativeStreamCreateImageStream(OWFint width,
340 const OWF_IMAGE_FORMAT* imageFormat,
343 OWF_NATIVE_STREAM* ns = NULL;
344 OWFint multiFail = 0;
345 void** bufferList = NULL;
346 OWFint* bufferRefs = NULL;
347 OWF_SYNC_DESC* bufferSyncs = NULL;
352 OWF_ASSERT(nbufs >= 1);
354 /* stream must have at least 2 buffers (front & back) */
355 ns = NEW0(OWF_NATIVE_STREAM);
356 bufferList = xalloc(sizeof(void*), nbufs);
357 bufferRefs = xalloc(sizeof(int*), nbufs);
359 bufferSyncs = xalloc(sizeof(OWF_SYNC_DESC), nbufs);
362 /* initialize surface/buffer list */
365 for (ii = 0; ii < nbufs; ii++)
367 bufferList[ii] = OWF_Image_AllocData(width, height,
368 imageFormat->pixelFormat);
377 if (!ns || !bufferList || multiFail || !bufferRefs || !bufferSyncs)
382 for (j = 0; j < ii; j++)
384 OWF_Image_FreeData(&bufferList[j]);
391 return OWF_INVALID_HANDLE;
394 ns->bufferList = bufferList;
395 ns->bufferRefs = bufferRefs;
396 ns->bufferCount = nbufs;
403 memcpy(&ns->colorFormat, imageFormat, sizeof(ns->colorFormat));
404 ns->stride = OWF_Image_GetStride(width, imageFormat);
405 ns->referenceCount = 1;
406 ns->sendNotifications = OWF_TRUE;
407 ns->protected = OWF_FALSE;
409 ok = OWF_Semaphore_Init(&ns->writer, nbufs);
412 ok = OWF_Mutex_Init(&ns->mutex);
415 ns->bufferSyncs = bufferSyncs;
417 ns->handle = owfNativeStreamAddStream(ns);
418 if (ns->handle == OWF_INVALID_HANDLE || ok != 0)
420 owfNativeStreamDoDestroy(ns);
422 return OWF_INVALID_HANDLE;
427 /*!---------------------------------------------------------------------------
428 * Converts from external WFC native stream handle type to internal OWF native stream handle type.
429 * The internal handle MUST be persistant. The external handle nmay already be persistant.
430 * This method may fail, either due to memory, or due to the stream object not being supported by the compositor
431 * @param publicStream The publicly defined stream handle
432 * @param error Pointer to store error code - optionally can be NULL
433 * @return OWFNativeStreamType an equivalent internal stream handle
434 *----------------------------------------------------------------------------**/
435 OWF_PUBLIC OWFNativeStreamType owfNativeStreamFromWFC(WFCNativeStreamType publicStream,OWF_STREAM_ERROR* errorReturn)
437 OWFNativeStreamType rv=(OWFNativeStreamType)publicStream;
438 OWF_IMAGE_FORMAT format;
439 owfNativeStreamGetHeader(rv,NULL,NULL,NULL,&format,NULL);
440 if (format.pixelFormat==OWF_IMAGE_NOT_SUPPORTED)
444 *errorReturn=OWF_STREAM_ERROR_INVALID_STREAM;
446 return OWF_INVALID_HANDLE;
448 owfNativeStreamAddReference(rv);
451 *errorReturn=OWF_STREAM_ERROR_NONE;
456 /*!---------------------------------------------------------------------------
457 * Increase stream's reference count
459 * \param stream Stream handle
460 *----------------------------------------------------------------------------*/
462 owfNativeStreamAddReference(OWFNativeStreamType stream)
464 OWF_NATIVE_STREAM* ns;
466 GET_STREAM(ns, stream);
470 OWF_Mutex_Lock(&ns->mutex);
471 ++(ns->referenceCount);
472 OWF_Mutex_Unlock(&ns->mutex);
475 /*!---------------------------------------------------------------------------
476 * Decrease stream's reference count
478 * \param stream Stream handle
479 *----------------------------------------------------------------------------*/
481 owfNativeStreamRemoveReference(OWFNativeStreamType stream)
483 OWF_NATIVE_STREAM* ns;
485 GET_STREAM(ns, stream);
488 OWF_Mutex_Lock(&ns->mutex);
489 --(ns->referenceCount);
490 OWF_Mutex_Unlock(&ns->mutex);
493 /*!---------------------------------------------------------------------------
494 * Destroy stream. The stream isn't necessarily immediately destroyed, but
495 * only when it's reference count reaches zero.
497 * \param stream Stream handle
498 *----------------------------------------------------------------------------*/
500 owfNativeStreamDestroy(OWFNativeStreamType stream)
502 OWF_NATIVE_STREAM* ns;
504 GET_STREAM(ns, stream);
507 owfNativeStreamDoDestroy(ns);
510 /*!---------------------------------------------------------------------------
511 * Acquire read buffer from stream
513 * \param stream Stream handle
515 * \return Handle to next readable (unread since last write)
516 * buffer from the stream or OWF_INVALID_HANDLE if no unread buffers
518 *----------------------------------------------------------------------------*/
519 OWF_PUBLIC OWFNativeStreamBuffer
520 owfNativeStreamAcquireReadBuffer(OWFNativeStreamType stream)
522 OWF_NATIVE_STREAM* ns;
523 OWFNativeStreamBuffer buffer = OWF_INVALID_HANDLE;
525 GET_STREAM(ns, stream);
526 CHECK_STREAM(OWF_INVALID_HANDLE);
528 OWF_Mutex_Lock(&ns->mutex);
530 if (ns->bufferCount == 1)
532 /* Single buffered stream.
533 * A "Write lock" must not block reading */
534 buffer = INDEX_TO_HANDLE(0);
535 ++(ns->bufferRefs[0]); /* Increase buffer's reference count */
539 buffer = INDEX_TO_HANDLE(ns->idxFront);
540 /* Increase reference count of front buffer */
541 ++(ns->bufferRefs[ns->idxFront]);
543 OWF_Mutex_Unlock(&ns->mutex);
548 /*!---------------------------------------------------------------------------
549 * Release read buffer.
551 * \param stream Stream handle
552 * \param buf Buffer handle
553 *----------------------------------------------------------------------------*/
555 owfNativeStreamReleaseReadBuffer(OWFNativeStreamType stream,
556 OWFNativeStreamBuffer buf)
559 OWF_SYNC_DESC* syncDesc = NULL;
561 OWF_NATIVE_STREAM* ns;
563 GET_STREAM(ns, stream);
565 CHECK_BUFFER_NR(buf);
567 OWF_Mutex_Lock(&ns->mutex);
569 i = HANDLE_TO_INDEX(buf);
571 OWF_ASSERT(ns->bufferRefs[i] > 0);
573 --(ns->bufferRefs[i]);
575 syncDesc = &ns->bufferSyncs[i];
576 if (syncDesc->sync != NULL)
578 DPRINT(("signalling synched buffer(%p, %x)",
579 stream, syncDesc->sync));
581 eglSignalSyncKHR(syncDesc->dpy, syncDesc->sync, EGL_SIGNALED_KHR);
582 syncDesc->dpy = EGL_NO_DISPLAY;
583 syncDesc->sync = NULL;
585 OWF_Mutex_Unlock(&ns->mutex);
588 /*!---------------------------------------------------------------------------
589 * Acquires writable buffer from a stream. The caller has exclusive access
590 * to returned buffer until the buffer is commited to stream by
591 * calling ReleaseWriteBuffer.
593 * \param stream Stream handle
595 * \return Handle to next writable buffer or OWF_INVALID_HANDLE if no such
596 * buffer is available.
597 *----------------------------------------------------------------------------*/
598 OWF_PUBLIC OWFNativeStreamBuffer
599 owfNativeStreamAcquireWriteBuffer(OWFNativeStreamType stream)
601 OWFNativeStreamBuffer buffer = OWF_INVALID_HANDLE;
603 OWF_NATIVE_STREAM* ns;
605 GET_STREAM(ns, stream);
606 CHECK_STREAM(OWF_INVALID_HANDLE);
608 OWF_Mutex_Lock(&ns->mutex);
610 /* write always blocks */
611 OWF_Semaphore_Wait(&ns->writer);
613 if (ns->bufferCount == 1)
615 /* Single buffered stream */
616 buffer = INDEX_TO_HANDLE(0);
617 ++(ns->bufferRefs[0]); /* Increase buffer's reference count */
621 if (ns->idxFront == ns->idxNextFree)
623 buffer = OWF_INVALID_HANDLE;
627 buffer = INDEX_TO_HANDLE(ns->idxNextFree);
629 ++(ns->bufferRefs[ns->idxNextFree]); /* Increase buffer's
631 ++(ns->idxNextFree); /* Move pointer to next buffer */
632 if (ns->idxNextFree == ns->bufferCount)
639 if (buffer != OWF_INVALID_HANDLE)
641 /* Signal associated 'old' sync because
642 * buffer gets 'dropped', never consumed
646 OWF_SYNC_DESC* syncDesc;
648 bufferIndex = HANDLE_TO_INDEX(buffer);
649 syncDesc = &ns->bufferSyncs[bufferIndex];
651 if (syncDesc->sync != NULL)
653 DPRINT(("dropping synched buffer(%p, %x)",
654 stream, syncDesc->sync));
656 eglSignalSyncKHR(syncDesc->dpy, syncDesc->sync, EGL_SIGNALED_KHR);
657 syncDesc->dpy = EGL_NO_DISPLAY;
658 syncDesc->sync = NULL;
662 OWF_Mutex_Unlock(&ns->mutex);
667 /*!---------------------------------------------------------------------------
668 * Commit write buffer to stream.
670 * \param stream Stream handle
671 * \param buf Buffer handle
672 * \param sync EGLSync object which is signalled when
673 * release buffer gets consumed or dropped
674 *----------------------------------------------------------------------------*/
676 owfNativeStreamReleaseWriteBuffer(OWFNativeStreamType stream,
677 OWFNativeStreamBuffer buf,
681 OWFint bufferIndex = 0;
683 OWF_NATIVE_STREAM* ns;
685 GET_STREAM(ns, stream);
688 CHECK_BUFFER_NR(buf);
690 OWF_Mutex_Lock(&ns->mutex);
692 bufferIndex = HANDLE_TO_INDEX(buf);
693 OWF_ASSERT(ns->bufferRefs[bufferIndex] > 0);
695 /* Look up correct buffer (naive search) */
696 --(ns->bufferRefs[bufferIndex]); /* Decrease buffer's reference count */
697 ns->idxFront = bufferIndex; /* Update front buffer to point to new
700 OWF_Semaphore_Post(&ns->writer);
702 /* sync object bookkeeping */
703 ns->bufferSyncs[bufferIndex].dpy = dpy;
704 ns->bufferSyncs[bufferIndex].sync = sync;
706 OWF_Mutex_Unlock(&ns->mutex);
708 DPRINT(("Stream updated %p", stream ));
710 owfNativeStreamNotifyObservers(stream, OWF_STREAM_UPDATED);
713 /*!---------------------------------------------------------------------------
714 * Register stream content observer. The observer will receive buffer
715 * modification event from the stream whenever a buffer is committed.
717 * \param stream Stream handle
718 * \param observer Stream observer
719 * \param data Optional data to pass to observer callback
720 * function when event is dispatched.
721 *----------------------------------------------------------------------------*/
722 OWF_PUBLIC OWF_STREAM_ERROR
723 owfNativeStreamAddObserver(OWFNativeStreamType stream,
724 OWFStreamCallback observer,
727 OWF_NODE* node = NULL;
728 OWFStreamCallbackData* cbdata = NULL;
730 OWF_NATIVE_STREAM* ns;
732 GET_STREAM(ns, stream);
733 CHECK_STREAM(OWF_STREAM_ERROR_INVALID_STREAM);
735 /* exclusive access only for you my friend. */
736 OWF_Mutex_Lock(&ns->mutex);
740 /* new observer. allocate a slot with extra space needed
741 * to store the callback data. */
742 node = xalloc(sizeof(OWF_NODE) + sizeof(OWFStreamCallbackData), 1);
745 OWF_Mutex_Unlock(&ns->mutex);
746 return OWF_STREAM_ERROR_OUT_OF_MEMORY;
749 /* callback data is directly after node in the memory*/
750 cbdata = (OWFStreamCallbackData*) &node[1];
751 cbdata->callback = observer;
753 /* for convenience. */
754 node->data = (void*) cbdata;
759 /* append to callback-chain */
760 ns->observers = OWF_List_Append(ns->observers, node);
763 OWF_Mutex_Unlock(&ns->mutex);
765 return OWF_STREAM_ERROR_NONE;
768 /*!---------------------------------------------------------------------------
769 * Remove stream content observer.
770 * Observer or Data can be NULL indicating search only checks for other member.
771 * Both must not be NULL.
772 * \param stream Stream handle
773 * \param observer Observer to remove
774 * \param data Identifying client data
776 * \return Zero if the observer was removed successfully, otherwise non-zero
777 * (OWF_STREAM_ERROR_INVALID_STREAM if the stream is invalid;
778 * OWF_STREAM_ERROR_INVALID_OBSERVER if the observer is invalid.)
779 *----------------------------------------------------------------------------*/
781 owfNativeStreamRemoveObserver(OWFNativeStreamType stream,
782 OWFStreamCallback observer,
785 OWF_NODE* node = NULL;
786 OWFStreamCallbackData tmp;
788 NODECMPFUNC search=ObserversEqual;
790 OWF_NATIVE_STREAM* ns;
792 GET_STREAM(ns, stream);
793 CHECK_STREAM(OWF_STREAM_ERROR_INVALID_STREAM);
795 OWF_Mutex_Lock(&ns->mutex);
797 tmp.callback = observer;
803 return OWF_STREAM_ERROR_INVALID_OBSERVER;
807 search=ObserverDatasEqual;
814 search=ObserverFuncsEqual;
818 node = OWF_List_Find(ns->observers, search, &tmp);
822 /* taketh the observer away */
823 ns->observers = OWF_List_Remove(ns->observers, node);
828 OWF_Mutex_Unlock(&ns->mutex);
830 return node ? OWF_STREAM_ERROR_NONE :
831 OWF_STREAM_ERROR_INVALID_OBSERVER;
834 /*!---------------------------------------------------------------------------
835 * Enable/disable stream content notifications.
837 * \param stream Stream handle
838 * \param send Boolean value indicating whether the stream should
839 * send content notifications to its observers.
840 *----------------------------------------------------------------------------*/
842 owfNativeStreamEnableUpdateNotifications(OWFNativeStreamType stream,
845 OWF_NATIVE_STREAM* ns;
847 GET_STREAM(ns, stream);
850 OWF_Mutex_Lock(&ns->mutex);
852 ns->sendNotifications = send;
854 OWF_Mutex_Unlock(&ns->mutex);
857 /*!---------------------------------------------------------------------------
858 * Return pointer to stream buffer's pixel data. The buffer must be
859 * a valid read/write buffer.
861 * \param stream Stream handle
862 * \param buffer Buffer handle
864 * \return Pointer to buffers pixel data.
865 *----------------------------------------------------------------------------*/
867 owfNativeStreamGetBufferPtr(OWFNativeStreamType stream,
868 OWFNativeStreamBuffer buffer)
870 void* bufferPtr = NULL;
872 OWF_NATIVE_STREAM* ns;
874 GET_STREAM(ns, stream);
877 /* Check that buffer has been locked */
878 OWF_ASSERT(ns->bufferRefs[HANDLE_TO_INDEX(buffer)] > 0);
880 OWF_Mutex_Lock(&ns->mutex);
882 bufferPtr = ns->bufferList[HANDLE_TO_INDEX(buffer)];
884 OWF_Mutex_Unlock(&ns->mutex);
889 /*!---------------------------------------------------------------------------
890 * Set/reset stream's protection flag. This flag is used for preventing the
891 * user from deleting a stream that s/he doesn't really own or should
892 * not twiddle with too much (on-screen context's target stream, for example)
894 * \param stream Stream handle
895 * \param flag Protection status
896 *----------------------------------------------------------------------------*/
898 owfNativeStreamSetProtectionFlag(OWFNativeStreamType stream, OWFboolean flag)
900 OWF_NATIVE_STREAM* ns;
902 GET_STREAM(ns, stream);
905 OWF_Mutex_Lock(&ns->mutex);
906 ns->protected = flag;
907 OWF_Mutex_Unlock(&ns->mutex);
911 /*!---------------------------------------------------------------------------
912 * Get stream's image header
914 * \param stream Stream handle
915 * \param width Stream width
916 * \param height Stream height
917 * \param stride Stream stride
918 * \param format Stream format
919 * \param pixelSize Stream pixelSize
921 * All the parameters above, except stream handle, are pointers to locations
922 * where the particular value should be written to. Passing in a NULL
923 * pointer means that the particular values is of no interest to the caller.
925 * E.g. to query only width & height one would call this function with
926 * parameters (stream_handle, &width, &height, NULL, NULL, NULL);
928 *----------------------------------------------------------------------------*/
930 owfNativeStreamGetHeader(OWFNativeStreamType stream,
934 OWF_IMAGE_FORMAT* format,
937 OWF_NATIVE_STREAM* ns;
939 GET_STREAM(ns, stream);
949 *height = ns->height;
953 *stride = ns->stride;
957 memcpy(format, &ns->colorFormat, sizeof(*format));
962 *pixelSize = OWF_Image_GetFormatPixelSize(ns->colorFormat.pixelFormat);