graphicscomposition/openwfcompositionengine/adaptation/include/owfnativestream.h
changeset 0 5d03bc08d59c
child 99 ac1910f6e7cb
child 152 9f1c3fea0f87
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 /* Copyright (c) 2009 The Khronos Group Inc.
       
     2  *
       
     3  * Permission is hereby granted, free of charge, to any person obtaining a
       
     4  * copy of this software and/or associated documentation files (the
       
     5  * "Materials"), to deal in the Materials without restriction, including
       
     6  * without limitation the rights to use, copy, modify, merge, publish,
       
     7  * distribute, sublicense, and/or sell copies of the Materials, and to
       
     8  * permit persons to whom the Materials are furnished to do so, subject to
       
     9  * the following conditions:
       
    10  *
       
    11  * The above copyright notice and this permission notice shall be included
       
    12  * in all copies or substantial portions of the Materials.
       
    13  *
       
    14  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
       
    15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
       
    16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
       
    17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
       
    18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
       
    19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
       
    20  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
       
    21  */
       
    22 
       
    23 #ifndef OWFNATIVESTREAM_H_
       
    24 #define OWFNATIVESTREAM_H_
       
    25 
       
    26 /*!
       
    27  * \brief Image stream implementation for Linux.
       
    28  *
       
    29  * WF native stream is an abstraction of image stream or
       
    30  * a content pipe that can be used to deliver image data from
       
    31  * place to another. A stream has a producer (source) and a consumer
       
    32  * (sink) as its users.
       
    33  *
       
    34  * Streams operate on buffers, whose count is fixed at creation
       
    35  * time (minimum is 1, but for non-blocking behavior values
       
    36  * greater than 1 should be used.) Streams are meant to be used
       
    37  * strictly on "point-to-point" basis, i.e. there should be only
       
    38  * one producer and one consumer for each stream.
       
    39  *
       
    40  */
       
    41 
       
    42 #include "owfsemaphore.h"
       
    43 #include "owflinkedlist.h"
       
    44 #include "owfimage.h"
       
    45 #include "owftypes.h"
       
    46 
       
    47 #include <EGL/egl.h>
       
    48 #include <WF/wfcplatform.h>
       
    49 
       
    50 #ifdef __cplusplus
       
    51 extern "C" {
       
    52 #endif
       
    53 
       
    54 typedef enum
       
    55 {
       
    56     OWF_STREAM_ERROR_NONE               = 0,
       
    57     OWF_STREAM_ERROR_INVALID_STREAM     = -1,
       
    58     OWF_STREAM_ERROR_INVALID_OBSERVER   = -2,
       
    59     OWF_STREAM_ERROR_OUT_OF_MEMORY      = -3
       
    60 } OWF_STREAM_ERROR;
       
    61 
       
    62 typedef WFCHandle           WFCNativeStreamType;
       
    63 /*!---------------------------------------------------------------------------
       
    64  * Converts from external WFC native stream handle type to internal OWF native stream handle type.
       
    65  * The internal handle MUST be persistant. The external handle may already be persistant.
       
    66  * This method may fail, either due to memory, or due to the stream object not being supported by the compositor
       
    67  * @post if successful, internal stream object is returned with increased reference (@see owfNativeStreamDestroy) 
       
    68  * @param publicStream The publicly defined stream handle
       
    69  * @param error			Pointer to store error code - optionally can be NULL
       
    70  * @return OWFNativeStreamType an equivalent internal stream handle
       
    71  *----------------------------------------------------------------------------**/
       
    72  OWF_PUBLIC OWFNativeStreamType 
       
    73 owfNativeStreamFromWFC(WFCNativeStreamType publicStream,OWF_STREAM_ERROR* errorReturn);
       
    74 
       
    75 /*!---------------------------------------------------------------------------
       
    76  *  Create new off-screen image stream.
       
    77  *
       
    78  *  \param width            Stream image buffer width
       
    79  *  \param height           Stream image buffer height
       
    80  *  \param imageFormat      Stream image buffer format
       
    81  *  \param nbufs            Number of image buffers to allocate
       
    82  *
       
    83  *  \param Handle to newly created stream or OWF_INVALID_HANDLe if no
       
    84  *  stream could be created.
       
    85  *----------------------------------------------------------------------------*/
       
    86  OWF_PUBLIC OWFNativeStreamType
       
    87 owfNativeStreamCreateImageStream(OWFint width,
       
    88                                  OWFint height,
       
    89                                  const OWF_IMAGE_FORMAT* format,
       
    90                                  OWFint nbufs);
       
    91 
       
    92 /*!---------------------------------------------------------------------------
       
    93  *  Increase stream's reference count
       
    94  *
       
    95  *  \param stream           Stream handle
       
    96  *----------------------------------------------------------------------------*/
       
    97  OWF_API_CALL void
       
    98 owfNativeStreamAddReference(OWFNativeStreamType stream);
       
    99 
       
   100 /*!---------------------------------------------------------------------------
       
   101  *  Decrease stream's reference count
       
   102  *
       
   103  *  \param stream           Stream handle
       
   104  *----------------------------------------------------------------------------*/
       
   105  OWF_API_CALL void
       
   106 owfNativeStreamRemoveReference(OWFNativeStreamType stream);
       
   107 
       
   108 /*!----------------------------------------------------------------------------
       
   109  *  Destroy stream. The stream isn't necessarily immediately destroyed, but
       
   110  *  only when it's reference count reaches zero.
       
   111  *
       
   112  *  \param stream           Stream handle
       
   113  *----------------------------------------------------------------------------*/
       
   114  OWF_PUBLIC void
       
   115 owfNativeStreamDestroy(OWFNativeStreamType stream);
       
   116 
       
   117 
       
   118 /*!---------------------------------------------------------------------------
       
   119  * Get stream's image header
       
   120  *
       
   121  * \param stream            Stream handle
       
   122  * \param width             Stream width
       
   123  * \param height            Stream height
       
   124  * \param stride            Stream stride
       
   125  * \param format            Stream format
       
   126  * \param pixelSize         Stream pixelSize
       
   127  *
       
   128  * All the parameters above, except stream handle, are pointers to locations
       
   129  * where the particular value should be written to. Passing in a NULL
       
   130  * pointer means that the particular values is of no interest to the caller.
       
   131  *
       
   132  * E.g. to query only width & height one would call this function with
       
   133  * parameters (stream_handle, &width, &height, NULL, NULL, NULL);
       
   134  *
       
   135  *----------------------------------------------------------------------------*/
       
   136  OWF_PUBLIC void
       
   137 owfNativeStreamGetHeader(OWFNativeStreamType stream,
       
   138                            OWFint* width,
       
   139                            OWFint* height,
       
   140                            OWFint* stride,
       
   141                            OWF_IMAGE_FORMAT* format,
       
   142                            OWFint* pixelSize);
       
   143 
       
   144 /*!---------------------------------------------------------------------------
       
   145  *  Acquire read buffer from stream
       
   146  *
       
   147  *  \param stream           Stream handle
       
   148  *
       
   149  *  \return Handle to next readable (unread since last write)
       
   150  *  buffer from the stream or OWF_INVALID_HANDLE if no unread buffers
       
   151  *  are available.
       
   152  *----------------------------------------------------------------------------*/
       
   153  OWF_PUBLIC OWFNativeStreamBuffer
       
   154 owfNativeStreamAcquireReadBuffer(OWFNativeStreamType stream);
       
   155 
       
   156 /*!---------------------------------------------------------------------------
       
   157  *  Release read buffer.
       
   158  *
       
   159  *  \param stream           Stream handle
       
   160  *  \param buf              Buffer handle
       
   161  *----------------------------------------------------------------------------*/
       
   162  OWF_PUBLIC void
       
   163 owfNativeStreamReleaseReadBuffer(OWFNativeStreamType stream,
       
   164                                  OWFNativeStreamBuffer buf);
       
   165 
       
   166 /*!---------------------------------------------------------------------------
       
   167  *  Acquires writable buffer from a stream. The caller has exclusive access
       
   168  *  to returned buffer until the buffer is commited to stream by
       
   169  *  calling ReleaseWriteBuffer.
       
   170  *
       
   171  *  \param stream           Stream handle
       
   172  *
       
   173  *  \return Handle to next writable buffer or OWF_INVALID_HANDLE if no such
       
   174  *  buffer is available.
       
   175  *----------------------------------------------------------------------------*/
       
   176  OWF_PUBLIC OWFNativeStreamBuffer
       
   177 owfNativeStreamAcquireWriteBuffer(OWFNativeStreamType stream);
       
   178 
       
   179 /*!---------------------------------------------------------------------------
       
   180  *  \brief Commit write buffer to stream.
       
   181  *
       
   182  * If sync object is specified, the handle to sync object is
       
   183  * associated with the buffer. The sync object is signalled
       
   184  * when the image/buffer has been either:
       
   185  * - composed into the target stream
       
   186  * - dropped (ignored) due to it being superceded by a newer
       
   187  *   image/buffer before the compositor had a chance to read it
       
   188  *
       
   189  * Sync object is signalled exactly once. The caller is responsible
       
   190  * of destroying the object.
       
   191  *
       
   192  *  \param stream           Stream handle
       
   193  *  \param buf              Buffer handle
       
   194  *  \param dpy              Optional EGLDisplay
       
   195  *  \param sync             Optional EGLSync object which is signaled when
       
   196  *                          the buffer is consumed or dropped.
       
   197  *----------------------------------------------------------------------------*/
       
   198  OWF_PUBLIC void
       
   199 owfNativeStreamReleaseWriteBuffer(OWFNativeStreamType stream,
       
   200                                   OWFNativeStreamBuffer buf,
       
   201                                   EGLDisplay dpy,
       
   202                                   EGLSyncKHR sync);
       
   203 
       
   204 /*!---------------------------------------------------------------------------
       
   205  *  Register stream content observer (append to chain). The observer will
       
   206  *  receive buffer modification event from the stream whenever a buffer is
       
   207  *  committed.
       
   208  *
       
   209  *  \param stream           Stream handle
       
   210  *  \param observer         Stream observer
       
   211  *  \param data             Optional data to pass to observer callback
       
   212  *                          function when event is dispatched.
       
   213  *----------------------------------------------------------------------------*/
       
   214  OWF_PUBLIC OWF_STREAM_ERROR
       
   215 owfNativeStreamAddObserver(OWFNativeStreamType stream,
       
   216                            OWFStreamCallback observer,
       
   217                            void* data);
       
   218 
       
   219 /*!---------------------------------------------------------------------------
       
   220  *  Remove stream content observer.
       
   221  *
       
   222  *  \param stream           Stream handle
       
   223  *  \param observer         Observer to remove
       
   224  *
       
   225  *  \param Zero if the observer was removed successfully, otherwise non-zero
       
   226  *  (OWF_STREAM_ERROR_INVALID_STREAM if the stream is invalid;
       
   227  *   OWF_STREAM_ERROR_INVALID_OBSERVER if the observer is invalid.)
       
   228  *
       
   229  *   NOTE (khronos bugzilla #5188): "Because the parameter is the observer
       
   230  *   function, it is likely that the wrong context could be removed if
       
   231  *   two contexts sharing the same implementation code are observing the
       
   232  *   same stream, and then one removes its observer. Ideally, both the
       
   233  *   function and the client void* should be passed as parameters
       
   234  *   to uniquely identify the observer."
       
   235  *
       
   236  *   The issue can be fixed by adding sync object handle into the interface
       
   237  *   of this function. Sync object must be passed to the static comparison
       
   238  *   function (ObserversEqual). Implementator must take into account that
       
   239  *   when the stream is destroyed, all observers of that stream must be destroyed.
       
   240  *
       
   241  *----------------------------------------------------------------------------*/
       
   242  OWF_API_CALL OWF_STREAM_ERROR
       
   243 owfNativeStreamRemoveObserver(OWFNativeStreamType stream,
       
   244                               OWFStreamCallback observer,
       
   245                               void* data);
       
   246 
       
   247 /*!---------------------------------------------------------------------------
       
   248  *  Enable/disable stream content notifications.
       
   249  *
       
   250  *  \param stream           Stream handle
       
   251  *  \param send             Boolean value indicating whether the stream should
       
   252  *                          send content notifications to its observers.
       
   253  *----------------------------------------------------------------------------*/
       
   254  OWF_API_CALL void
       
   255 owfNativeStreamEnableUpdateNotifications(OWFNativeStreamType stream,
       
   256                                          OWFboolean send);
       
   257 
       
   258 
       
   259 /*!---------------------------------------------------------------------------
       
   260  *  Return pointer to stream buffer's pixel data. The buffer must be
       
   261  *  a valid read/write buffer.
       
   262  *
       
   263  *  \param stream           Stream handle
       
   264  *  \param buffer           Buffer handle
       
   265  *
       
   266  *  \return Pointer to buffers pixel data.
       
   267  *----------------------------------------------------------------------------*/
       
   268  OWF_PUBLIC void*
       
   269 owfNativeStreamGetBufferPtr(OWFNativeStreamType stream,
       
   270                             OWFNativeStreamBuffer buffer);
       
   271 
       
   272 /*!---------------------------------------------------------------------------
       
   273  *  Set/reset stream's protection flag. This flag is used for preventing the
       
   274  *  user from deleting a stream that s/he doesn't really own or should
       
   275  *  not twiddle with too much (on-screen context's target stream, for example)
       
   276  *
       
   277  *  \param stream           Stream handle
       
   278  *  \param flag             Protection status
       
   279  *----------------------------------------------------------------------------*/
       
   280  OWF_API_CALL void
       
   281 owfNativeStreamSetProtectionFlag(OWFNativeStreamType stream,
       
   282                                  OWFboolean flag);
       
   283  /*!---------------------------------------------------------------------------
       
   284   *  Sets (internal) target stream flip state
       
   285   *
       
   286   *  \param stream           Stream handle
       
   287   *
       
   288   *----------------------------------------------------------------------------*/
       
   289  OWF_API_CALL void
       
   290 owfSetStreamFlipState(OWFNativeStreamType stream, OWFboolean flip);
       
   291  
       
   292 
       
   293 #ifdef __cplusplus
       
   294 }
       
   295 #endif
       
   296 
       
   297 #endif