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