os/graphics/graphicscomposition/openwfcompositionengine/adaptation/src/Platform/Graphics/symbian/owfnativestreamstub.cpp
First public contribution.
1 // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
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:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Materials.
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.
23 // Native Stream Stubs
28 #include <graphics/symbianstream.h>
29 #include <graphics/surfacemanager.h>
30 #include <graphics/streammap.h>
31 #include "owfnativestream.h"
38 static khronos_int32_t max(khronos_int32_t aLhs, khronos_int32_t aRhs)
46 static TSurfaceId createSurface(RSurfaceManager& surface_manager, khronos_int32_t width,
47 khronos_int32_t height,
48 const OWF_IMAGE_FORMAT* format,
49 khronos_int32_t nbufs)
51 TSurfaceId surface = TSurfaceId::CreateNullId();
52 RSurfaceManager::TSurfaceCreationAttributesBuf bf;
53 RSurfaceManager::TSurfaceCreationAttributes& b = bf();
55 TBool premultiplied = format->premultiplied;
56 OWF_PIXEL_FORMAT pixelFormat = format->pixelFormat;
57 khronos_int32_t bytesPerPixel = 0;
58 // we don't support linear mode
65 case OWF_IMAGE_RGB565:
66 b.iPixelFormat = EUidPixelFormatRGB_565;
68 b.iAlignment = max(format->rowPadding, 4);
70 case OWF_IMAGE_ARGB8888:
74 b.iPixelFormat = EUidPixelFormatARGB_8888_PRE;
78 b.iPixelFormat = EUidPixelFormatARGB_8888;
81 b.iAlignment = format->rowPadding;
84 case OWF_IMAGE_XRGB8888 :
85 b.iPixelFormat = EUidPixelFormatXRGB_8888;
87 b.iAlignment = max(format->rowPadding,4);
93 b.iSize.iWidth = width;
94 b.iSize.iHeight = height;
95 b.iBuffers = nbufs; // number of buffers in the surface
96 b.iOffsetToFirstBuffer = 0; // way of reserving space before the surface pixel data
97 if (bytesPerPixel >= 0)
99 b.iStride = bytesPerPixel * width; // number of bytes between start of one line and start of next
103 b.iStride = (width-(bytesPerPixel+1)) / (-bytesPerPixel);
105 b.iContiguous = OWF_TRUE;
106 b.iMappable = OWF_TRUE;
108 TInt err=surface_manager.CreateSurface(bf, surface);
111 surface=TSurfaceId::CreateNullId();
116 static void WipeWriteBuffer(SymbianStreamType ns)
118 khronos_int32_t height,stride;
119 SymbianStreamGetHeader(ns,NULL,&height,&stride,NULL,NULL);
120 SymbianStreamBuffer buffer;
121 if( KErrNone != SymbianStreamAcquireWriteBuffer(ns, &buffer))
126 // If we fail to get buffer pointer, we proceed without initial wipe
127 if( KErrNone != SymbianStreamGetBufferPointer(ns,buffer,&pixels))
131 memset(pixels,0,height*stride);
132 SymbianStreamReleaseWriteBuffer(ns,buffer);
135 /*!---------------------------------------------------------------------------
136 * Create new off-screen image stream.
138 * \param width Stream image buffer width
139 * \param height Stream image buffer height
140 * \param imageFormat Stream image buffer format
141 * \param nbufs Number of image buffers to allocate
143 * \param Handle to newly created stream or OWF_INVALID_HANDLe if no
144 * stream could be created.
145 *----------------------------------------------------------------------------*/
146 OWF_API_CALL OWFNativeStreamType
147 owfNativeStreamCreateImageStream(OWFint width,
149 const OWF_IMAGE_FORMAT* format,
152 RSurfaceManager surface_manager;
153 TInt err=surface_manager.Open();
156 return WFC_INVALID_HANDLE;
160 surface = createSurface(surface_manager, width, height, format, nbufs);
161 if (surface.IsNull())
163 return WFC_INVALID_HANDLE;
165 SymbianStreamType ns=WFC_INVALID_HANDLE; //No more error checking required...
166 SymbianStreamAcquire(&surface,&ns);
168 surface_manager.CloseSurface(surface);
173 surface_manager.Close();
174 return (OWFNativeStreamType)ns;
176 /*!---------------------------------------------------------------------------
177 * Converts from external WFC native stream handle type to internal OWF native stream handle type.
178 * The internal handle MUST be persistant. The external handle may already be persistant.
179 * This method may fail, either due to memory, or due to the stream object not being supported by the compositor
180 * @param publicStream The publicly defined stream handle
181 * @param error Pointer to store error code - optionally can be NULL
182 * @return OWFNativeStreamType an equivalent internal stream handle
183 *----------------------------------------------------------------------------**/
184 OWF_API_CALL OWFNativeStreamType owfNativeStreamFromWFC(WFCNativeStreamType publicStream,OWF_STREAM_ERROR* errorReturn)
186 SymbianStreamType rvss;
187 TInt err = SymbianStreamAcquire(reinterpret_cast<SymbianStreamType>(publicStream),&rvss);
192 *errorReturn = (err == KErrNoMemory) ? OWF_STREAM_ERROR_OUT_OF_MEMORY : OWF_STREAM_ERROR_INVALID_STREAM;
194 return OWF_INVALID_HANDLE;
196 OWF_IMAGE_FORMAT format;
197 OWFNativeStreamType rvowf=reinterpret_cast<OWFNativeStreamType>(rvss);
198 owfNativeStreamGetHeader(rvowf,NULL,NULL,NULL,&format,NULL);
199 if (format.pixelFormat==OWF_IMAGE_NOT_SUPPORTED)
201 SymbianStreamRemoveReference(rvss);
204 *errorReturn=OWF_STREAM_ERROR_INVALID_STREAM;
206 return OWF_INVALID_HANDLE;
210 *errorReturn=OWF_STREAM_ERROR_NONE;
217 /*!---------------------------------------------------------------------------
218 * Increase stream's reference count
220 * \param stream Stream handle
221 *----------------------------------------------------------------------------*/
223 owfNativeStreamAddReference(OWFNativeStreamType stream)
225 SymbianStreamAddReference((SymbianStreamType)stream);
228 /*!---------------------------------------------------------------------------
229 * Decrease stream's reference count
231 * \param stream Stream handle
232 *----------------------------------------------------------------------------*/
234 owfNativeStreamRemoveReference(OWFNativeStreamType stream)
236 SymbianStreamRemoveReference((SymbianStreamType)stream);
239 /*!----------------------------------------------------------------------------
240 * Destroy stream. The stream isn't necessarily immediately destroyed, but
241 * only when it's reference count reaches zero.
243 * \param stream Stream handle
244 *----------------------------------------------------------------------------*/
246 owfNativeStreamDestroy(OWFNativeStreamType stream)
248 SymbianStreamRemoveReference((SymbianStreamType)stream);
251 static TInt PixelFormatConversion(TUidPixelFormat aBaseFormat, OWF_IMAGE_FORMAT& aFormat)
253 // Non-alpha formats have the premultiplied flag set because the
254 // code handles them more quickly that way.
257 case EUidPixelFormatRGB_565:
258 aFormat.linear = OWF_FALSE;
259 aFormat.premultiplied = OWF_TRUE;
260 aFormat.rowPadding = 2;
261 aFormat.pixelFormat = OWF_IMAGE_RGB565;
263 case EUidPixelFormatARGB_8888_PRE:
264 aFormat.linear = OWF_FALSE;
265 aFormat.premultiplied = OWF_TRUE;
266 aFormat.rowPadding = 4;
267 aFormat.pixelFormat = OWF_IMAGE_ARGB8888;
269 case EUidPixelFormatARGB_8888:
270 aFormat.linear = OWF_FALSE;
271 aFormat.premultiplied = OWF_FALSE;
272 aFormat.rowPadding = 4;
273 aFormat.pixelFormat = OWF_IMAGE_ARGB8888;
275 case EUidPixelFormatXRGB_8888 :
276 aFormat.linear = OWF_FALSE;
277 aFormat.premultiplied = OWF_TRUE;
278 aFormat.rowPadding = 4;
279 aFormat.pixelFormat = OWF_IMAGE_XRGB8888;
281 case EUidPixelFormatA_8 :
282 aFormat.linear = OWF_FALSE;
283 aFormat.premultiplied = OWF_FALSE;
284 aFormat.rowPadding = 4;
285 aFormat.pixelFormat = OWF_IMAGE_L8;
287 case EUidPixelFormatL_1 :
288 aFormat.linear = OWF_FALSE;
289 aFormat.premultiplied = OWF_FALSE;
290 aFormat.rowPadding = 4;
291 aFormat.pixelFormat = OWF_IMAGE_L1;
294 aFormat.linear = OWF_FALSE;
295 aFormat.premultiplied = OWF_FALSE;
296 aFormat.rowPadding = 0;
297 aFormat.pixelFormat = OWF_IMAGE_NOT_SUPPORTED;
298 return KErrNotSupported;
303 /*!---------------------------------------------------------------------------
304 * Get stream's image header
306 * \param stream Stream handle
307 * \param width Stream width
308 * \param height Stream height
309 * \param stride Stream stride
310 * \param format Stream format
311 * \param pixelSize Stream pixelSize
313 * All the parameters above, except stream handle, are pointers to locations
314 * where the particular value should be written to. Passing in a NULL
315 * pointer means that the particular values is of no interest to the caller.
317 * E.g. to query only width & height one would call this function with
318 * parameters (stream_handle, &width, &height, NULL, NULL, NULL);
320 *----------------------------------------------------------------------------*/
322 owfNativeStreamGetHeader(OWFNativeStreamType stream,
326 OWF_IMAGE_FORMAT* format,
329 SymOwfPixelFormat symFormat;
330 SymbianStreamGetHeader((SymbianStreamType)stream,
334 format?&symFormat:(SymOwfPixelFormat*)NULL,
337 { //translate format. If error then OWF_IMAGE_NOT_SUPPORTED is set.
338 PixelFormatConversion(static_cast<TUidPixelFormat>(symFormat),*format);
342 /*!---------------------------------------------------------------------------
343 * Acquire read buffer from stream
345 * \param stream Stream handle
347 * \return Handle to next readable (unread since last write)
348 * buffer from the stream or OWF_INVALID_HANDLE if no unread buffers
350 *----------------------------------------------------------------------------*/
351 OWF_API_CALL OWFNativeStreamBuffer
352 owfNativeStreamAcquireReadBuffer(OWFNativeStreamType stream)
354 OWFNativeStreamBuffer returnBuffer;
355 SymbianStreamAcquireReadBuffer((SymbianStreamType)stream,(SymbianStreamBuffer*)&returnBuffer);
359 /*!---------------------------------------------------------------------------
360 * Release read buffer.
362 * \param stream Stream handle
363 * \param buf Buffer handle
364 *----------------------------------------------------------------------------*/
366 owfNativeStreamReleaseReadBuffer(OWFNativeStreamType stream,
367 OWFNativeStreamBuffer buf)
369 SymbianStreamReleaseReadBuffer((SymbianStreamType)stream,(SymbianStreamBuffer)buf);
372 /*!---------------------------------------------------------------------------
373 * Acquires writable buffer from a stream. The caller has exclusive access
374 * to returned buffer until the buffer is commited to stream by
375 * calling ReleaseWriteBuffer.
377 * \param stream Stream handle
379 * \return Handle to next writable buffer or OWF_INVALID_HANDLE if no such
380 * buffer is available.
381 *----------------------------------------------------------------------------*/
382 OWF_API_CALL OWFNativeStreamBuffer
383 owfNativeStreamAcquireWriteBuffer(OWFNativeStreamType stream)
385 OWFNativeStreamBuffer returnBuffer;
386 SymbianStreamAcquireWriteBuffer((SymbianStreamType)stream,(SymbianStreamBuffer*)&returnBuffer);
390 /*!---------------------------------------------------------------------------
391 * Commit write buffer to stream.
393 * \param stream Stream handle
394 * \param buf Buffer handle
395 *----------------------------------------------------------------------------*/
397 owfNativeStreamReleaseWriteBuffer(OWFNativeStreamType stream,
398 OWFNativeStreamBuffer buf,
402 //We do not use the sync object mechanism to indicate that content has been consumed.
403 //See the SUS notification support
406 SymbianStreamReleaseWriteBuffer((SymbianStreamType)stream,(SymbianStreamBuffer)buf);
409 /*!---------------------------------------------------------------------------
410 * Enable/disable stream content notifications.
412 * \param stream Stream handle
413 * \param send Boolean value indicating whether the stream should
414 * send content notifications to its observers.
415 *----------------------------------------------------------------------------*/
417 owfNativeStreamEnableUpdateNotifications(OWFNativeStreamType /*stream*/,
420 //SymbianStream always enables update notifications.
421 //It can deal efficiently with the situation where there are no registered observers.
426 /*!---------------------------------------------------------------------------
427 * Return pointer to stream buffer's pixel data. The buffer must be
428 * a valid read/write buffer.
430 * \param stream Stream handle
431 * \param buffer Buffer handle
433 * \return Pointer to buffers pixel data.
434 *----------------------------------------------------------------------------*/
436 owfNativeStreamGetBufferPtr(OWFNativeStreamType stream,
437 OWFNativeStreamBuffer buffer)
439 void* returnPointer = NULL;
440 SymbianStreamGetBufferPointer((SymbianStreamType)stream,buffer,&returnPointer);
441 return returnPointer;
444 /*!---------------------------------------------------------------------------
445 * Set/reset stream's protection flag. This flag is used for preventing the
446 * user from deleting a stream that s/he doesn't really own or should
447 * not twiddle with too much (on-screen context's target stream, for example)
449 * \param stream Stream handle
450 * \param flag Protection status
451 *----------------------------------------------------------------------------*/
453 owfNativeStreamSetProtectionFlag(OWFNativeStreamType stream,
456 SymbianStreamSetProtectionFlag((SymbianStreamType)stream,flag);
459 /*!---------------------------------------------------------------------------
460 * Set/reset stream's flip state. When the flip state is OWF_TRUE, the stream
461 * attributes returned by owfNativeStreamGetHeader are affected as follows:
462 * -# The width and height attributes are swapped.
463 * -# The stride attribute is derived from the height value instead of the
466 * Note: the attributes of the underlying surface as retrieved using Surface
467 * Manager are not affected by this flag.
469 * \param stream Stream handle
470 * \param flip New flip state
471 *----------------------------------------------------------------------------*/
473 owfSetStreamFlipState(OWFNativeStreamType stream, OWFboolean flip)
475 SymbianStreamSetFlipState((SymbianStreamType)stream, flip);