os/graphics/graphicscomposition/openwfcompositionengine/composition/src/wfcdevice.c
Update contrib.
1 /* Copyright (c) 2009-2010 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.
26 * \brief SI Device handling
34 #include "wfcdevice.h"
35 #include "wfcelement.h"
36 #include "wfccontext.h"
37 #include "wfcimageprovider.h"
40 #include "owfmemory.h"
42 #include "owfscreen.h"
44 #include "owfobject.h"
45 #include "owfnativestream.h"
46 #include "owfnotifications.h"
53 #define MAX_ATTRIBUTES 32
55 #define FAIL_IF(c,e) if (c) { LEAVE(0); return e; }
57 #define FIRST_DEVICE_HANDLE 1000
59 PHYSICAL_DEVICE gPhyDevice;
62 /*-------------------------------------------------------------------------*//*!
65 * Initialize devices with default parameters.
66 *//*-------------------------------------------------------------------------*/
68 WFC_Devices_Initialize()
70 static WFCboolean initialised=WFC_FALSE;
73 OWF_Array_Initialize(&(gPhyDevice.iDeviceInstanceArray));
74 gPhyDevice.gDeviceHandleID = 0;
79 /*---------------------------------------------------------------------------
82 *----------------------------------------------------------------------------*/
84 WFC_Devices_GetIds(WFCint* idList,
86 const WFCint* filterList)
89 /* We assume there is only one physical device and
90 * all screens are supported by this device */
92 WFCint screenNumber = OWF_RESERVED_BAD_SCREEN_NUMBER,
97 hasFilter = (filterList && (*filterList != WFC_NONE)) ?
101 /* handle filter list, if given */
104 /* scan filter list (up to 32 attributes) */
105 while (n > 0 && WFC_NONE != filterList[0])
107 switch (filterList[0])
109 case WFC_DEVICE_FILTER_SCREEN_NUMBER:
110 if (screenNumber!=OWF_RESERVED_BAD_SCREEN_NUMBER && screenNumber!=filterList[1])
112 /* invalid repeated filter on screen number */
115 screenNumber = filterList[1];
116 if (!OWF_Screen_Valid(screenNumber))
118 /* invalid screen number */
128 /* EARLY EXIT - invalid attribute */
132 /* Move pointer to next key-value pair */
138 /* Return number of available devices */
139 if (NULL == idList && !hasFilter) {
143 for (i = 0, n = 0; i < 1 && listCapacity >= 0; i++) {
144 /* idList might be NULL when querying all devices w/
145 * screen number in filter list */
146 if (idList && n < listCapacity)
148 idList[n] = OWF_SUPPORTED_DEVICE_ID;
158 /*---------------------------------------------------------------------------
159 * Create instance of a device whose ID
162 * \param deviceId ID of the device to create. Must be WFC_DEFAULT_DEVICE_ID
163 * or some other valid device ID (returned by Devices_GetIds)
165 * \return Handle to created device or WFC_INVALID_HANDLE
167 *----------------------------------------------------------------------------*/
169 WFC_Device_Create(WFCint deviceId)
171 WFC_DEVICE *dev = NULL;
173 ENTER(WFC_Device_Create);
175 WFC_Devices_Initialize();
177 if (deviceId != WFC_DEFAULT_DEVICE_ID && deviceId != OWF_SUPPORTED_DEVICE_ID)
179 return WFC_INVALID_HANDLE;
182 dev = DEVICE(xalloc(1,sizeof(WFC_DEVICE)));
185 return WFC_INVALID_HANDLE;
188 dev->handle = FIRST_DEVICE_HANDLE + (gPhyDevice.gDeviceHandleID)++;
189 dev->deviceId = deviceId;
190 dev->latestUnreadError = WFC_ERROR_NONE;
192 OWF_Array_Initialize(&dev->contexts);
193 OWF_Array_Initialize(&dev->providers);
194 OWF_Array_Initialize(&dev->elements);
196 if (!OWF_Array_AppendItem(&(gPhyDevice.iDeviceInstanceArray), dev))
199 return WFC_INVALID_HANDLE;
202 LEAVE(WFC_Device_Create);
207 /*---------------------------------------------------------------------------
208 * Set error code for device. Obs! In case the previous
209 * error code hasn't been read from the device, this function
210 * does nothing; the new error is set only if "current" error
213 * \param dev Device object
214 * \param code Error to set
216 *----------------------------------------------------------------------------*/
217 OWF_API_CALL void OWF_APIENTRY
218 WFC_Device_SetError(WFCDevice dev,
222 static char* const errmsg[] =
225 "WFC_ERROR_OUT_OF_MEMORY",
226 "WFC_ERROR_ILLEGAL_ARGUMENT",
227 "WFC_ERROR_UNSUPPORTED",
228 "WFC_ERROR_BAD_ATTRIBUTE",
231 "WFC_ERROR_BAD_DEVICE",
232 "WFC_ERROR_BAD_HANDLE",
233 "WFC_ERROR_INCONSISTENCY",
237 WFC_DEVICE* device = WFC_Device_FindByHandle(dev);
238 if (WFC_INVALID_HANDLE == device)
240 /* Invalid device handle. Nothing we can do about it so return. */
246 OWF_Mutex_Init(&device->mutex);
249 OWF_Mutex_Lock(&device->mutex);
250 if (code == WFC_ERROR_IN_USE)
252 code=WFC_ERROR_IN_USE;
254 if (WFC_INVALID_HANDLE != device) {
255 if (WFC_ERROR_NONE == device->latestUnreadError &&
256 code != device->latestUnreadError)
259 char* const msg = errmsg[code > WFC_ERROR_NONE ?
260 code - WFC_ERROR_OUT_OF_MEMORY + 1 : 0];
261 (void)msg; //always reference to avoid warning
264 DPRINT(("setError(dev = %08x, err = %08x)", dev, code));
265 DPRINT((" error set to = %04x (%s)", (OWFuint16) code, msg));
267 device->latestUnreadError = code;
271 OWF_Mutex_Unlock(&device->mutex);
274 /*---------------------------------------------------------------------------
275 * Read and reset last error code from device.
277 * \param device Device object
279 * \return WFCErrorCode
280 *----------------------------------------------------------------------------*/
281 OWF_API_CALL WFCErrorCode
282 WFC_Device_GetError(WFC_DEVICE* device)
288 err = device->latestUnreadError;
289 device->latestUnreadError = WFC_ERROR_NONE;
293 /*---------------------------------------------------------------------------
294 * Find device object by handle
296 * \param dev Device handle
298 * \return Matching device object or NULL
299 *----------------------------------------------------------------------------*/
300 OWF_API_CALL WFC_DEVICE*
301 WFC_Device_FindByHandle(WFCDevice dev)
303 WFCint i = 0, length = 0;
304 WFC_DEVICE* pDevice = NULL;
306 if (dev == WFC_INVALID_HANDLE)
311 WFC_Devices_Initialize();
313 length = gPhyDevice.iDeviceInstanceArray.length;
314 for (i = 0; i < length; ++i)
316 pDevice = DEVICE(OWF_Array_GetItemAt(&(gPhyDevice.iDeviceInstanceArray), i));
317 if (pDevice->handle == dev)
325 /*---------------------------------------------------------------------------
326 * Get device attribute
328 * \param device Device
329 * \param attrib Attribute name
330 * \param value Pointer to where the value should be saved
332 * \return WFCErrorCode
333 *----------------------------------------------------------------------------*/
334 OWF_API_CALL WFCErrorCode
335 WFC_Device_GetAttribi(WFC_DEVICE* device,
336 WFCDeviceAttrib attrib,
339 WFCErrorCode result = WFC_ERROR_NONE;
345 case WFC_DEVICE_CLASS:
347 *value = WFC_DEVICE_CLASS_FULLY_CAPABLE;
352 *value = device->deviceId;
357 result = WFC_ERROR_BAD_ATTRIBUTE;
363 /*[][][][] CONTEXTS [][][][][][][][][][][][][][][][][][][][][][][][][][][][]*/
365 /*---------------------------------------------------------------------------
366 * Create context on device
368 * \param device Device
369 * \param stream Target stream for context
370 * \param type Context type
372 * \return New context
373 *----------------------------------------------------------------------------*/
374 OWF_API_CALL WFC_CONTEXT*
375 WFC_Device_CreateContext(WFC_DEVICE* device,
376 OWFNativeStreamType stream,
380 WFC_CONTEXT* context;
382 ENTER(WFC_Device_CreateContext);
386 context = WFC_Context_Create(device, stream, type, screenNum);
389 if (!OWF_Array_AppendItem(&device->contexts, context))
394 LEAVE(WFC_Device_CreateContext);
399 /*---------------------------------------------------------------------------
400 * Destroy context from device
401 *----------------------------------------------------------------------------*/
402 OWF_API_CALL WFCErrorCode
403 WFC_Device_DestroyContext(WFC_DEVICE* device,
407 WFCErrorCode result = WFC_ERROR_BAD_HANDLE;
408 ENTER(WFC_Device_DestroyContext);
412 DPRINT(("WFC_Device_DestroyContext(context = %d)", context));
414 for (i = 0; i < device->contexts.length; i++)
418 ctmp = (WFC_CONTEXT*) OWF_Array_GetItemAt(&device->contexts, i);
419 if (ctmp->handle == context)
421 WFC_CONTEXT* context;
423 context = CONTEXT(OWF_Array_RemoveItemAt(&device->contexts, i));
424 DPRINT((" Shutting down context %d", context->handle));
425 WFC_Context_Shutdown(context);
427 result = WFC_ERROR_NONE;
434 DPRINT(("-------------------------------------------------------"));
435 DPRINT(("Device statistics after context destruction:"));
436 DPRINT((" Contexts: %d", device->contexts.length));
437 DPRINT((" Elements: %d", device->elements.length));
438 DPRINT((" Image providers: %d", device->providers.length));
439 DPRINT(("-------------------------------------------------------"));
440 LEAVE(WFC_Device_DestroyContext);
445 /*---------------------------------------------------------------------------
446 * Destroy all device's contexts
448 * \param device Device object
449 *----------------------------------------------------------------------------*/
451 WFC_Device_DestroyContexts(WFC_DEVICE* device)
455 ENTER(WFC_Device_DestroyContexts);
457 for (i = 0; i < device->contexts.length; i++)
459 WFC_CONTEXT* context;
461 context = CONTEXT(OWF_Array_GetItemAt(&device->contexts, i));
462 WFC_Context_Shutdown(context);
466 OWF_Array_Destroy(&device->contexts);
468 LEAVE(WFC_Device_DestroyContexts);
471 /*---------------------------------------------------------------------------
472 * Find context context object by handle
474 * \param device Device
475 * \param context Context handle
477 * \return Corresponding context object or NULL
478 * if handle is invalid.
479 *----------------------------------------------------------------------------*/
480 OWF_API_CALL WFC_CONTEXT*
481 WFC_Device_FindContext(WFC_DEVICE* device,
485 WFC_CONTEXT* result = NULL;
487 ENTER(WFC_Device_FindContext);
489 FAIL_IF(NULL == device, NULL);
491 for (i = 0; i < device->contexts.length; i++)
495 ctmp = CONTEXT(OWF_Array_GetItemAt(&device->contexts, i));
496 if (ctmp->handle == context)
502 LEAVE(WFC_Device_FindContext);
506 /*[][][][] ELEMENTS [][][][][][][][][][][][][][][][][][][][][][][][][][][][]*/
508 /*---------------------------------------------------------------------------
514 * \return New element or NULL
515 *----------------------------------------------------------------------------*/
516 OWF_API_CALL WFC_ELEMENT*
517 WFC_Device_CreateElement(WFC_DEVICE* device, WFC_CONTEXT* context)
519 WFC_ELEMENT* element=NULL;
521 ENTER(WFC_Device_CreateElement);
523 FAIL_IF(NULL == device || NULL == context, NULL);
524 if (WFC_Context_IncreaseClientElementCount(context)>0)
526 element = WFC_Element_Create(context);
527 if (!element || !OWF_Array_AppendItem(&device->elements, element))
529 DPRINT(("WFC_Device_CreateElement: couldn't create element"));
530 WFC_Context_DecreaseClientElementCount(context);
533 WFC_Element_Destroy(element);
539 /* #4585: statement moved to else block */
540 DPRINT((" Created element; handle = %d", element->handle));
543 LEAVE(WFC_Device_CreateElement);
548 /*---------------------------------------------------------------------------
553 *----------------------------------------------------------------------------*/
554 OWF_API_CALL WFCErrorCode
555 WFC_Device_DestroyElement(WFC_DEVICE* device,
559 WFCErrorCode result = WFC_ERROR_BAD_HANDLE;
561 ENTER(WFC_Device_DestroyElement);
563 FAIL_IF(NULL == device, WFC_ERROR_BAD_HANDLE);
564 DPRINT(("destroying element %d", element));
566 for (i = 0; i < device->elements.length; i++)
570 object = ELEMENT(OWF_Array_GetItemAt(&device->elements, i));
571 DPRINT((" element %d = %d", i, object->handle));
572 if (object->handle == element)
574 WFC_Context_RemoveElement(CONTEXT(object->context), element);
576 WFC_Context_DecreaseClientElementCount(object->context);
577 OWF_Array_RemoveItemAt(&device->elements, i);
578 WFC_Element_Destroy(object);
579 result = WFC_ERROR_NONE;
583 LEAVE(WFC_Device_DestroyElement);
587 /*---------------------------------------------------------------------------
588 * Destroy all elements from device
590 * \param device Device
591 *----------------------------------------------------------------------------*/
593 WFC_Device_DestroyElements(WFC_DEVICE* device)
597 ENTER(WFC_Device_DestroyElements);
601 for (i = 0; i < device->elements.length; i++)
605 etemp = ELEMENT(OWF_Array_GetItemAt(&device->elements, i));
606 WFC_Element_Destroy(etemp);
608 OWF_Array_Destroy(&device->elements);
610 LEAVE(WFC_Device_DestroyElements);
613 /*---------------------------------------------------------------------------
614 * Find element by handle
616 * \param device Device
617 * \param el Element handle
619 * \return Element object
620 *----------------------------------------------------------------------------*/
621 OWF_API_CALL WFC_ELEMENT*
622 WFC_Device_FindElement(WFC_DEVICE* device,
625 WFC_ELEMENT* result = WFC_INVALID_HANDLE;
628 FAIL_IF(NULL == device, NULL);
630 for (i = 0; i < device->elements.length; i++)
632 WFC_ELEMENT* element;
633 element = ELEMENT(OWF_Array_GetItemAt(&device->elements, i));
635 if (element->handle == el)
645 /*---------------------------------------------------------------------------
646 * Set element integer vector attribute
648 * \param device Device
649 * \param element Element handle
650 * \param attrib Attribute name
651 * \param count Attribute value vector length (1 for scalar attribute)
652 * \param values Pointer to values
654 * \return WFCErrorCode: WFC_ERROR_BAD_ATTRIBUTE if attribute name is invalid;
655 * WFC_ERROR_INVALID_ARGUMENT if values is NULL or if the count doesn't match
656 * the attribute's size; WFC_ERROR_BAD_HANDLE if element handle is invalid.
657 *----------------------------------------------------------------------------*/
658 OWF_API_CALL WFCErrorCode
659 WFC_Device_SetElementAttribiv(WFC_DEVICE* device,
661 WFCElementAttrib attrib,
663 const WFCint* values)
669 object = WFC_Device_FindElement(device, element);
670 FAIL_IF(NULL == object, WFC_ERROR_BAD_HANDLE);
671 return WFC_Element_SetAttribiv(object, attrib, count, values);
674 /*---------------------------------------------------------------------------
677 *----------------------------------------------------------------------------*/
678 OWF_API_CALL WFCErrorCode
679 WFC_Device_SetElementAttribfv(WFC_DEVICE* device,
681 WFCElementAttrib attrib,
683 const WFCfloat* values)
689 object = WFC_Device_FindElement(device, element);
690 FAIL_IF(NULL == object, WFC_ERROR_BAD_HANDLE);
691 return WFC_Element_SetAttribfv(object, attrib, count, values);
694 /*---------------------------------------------------------------------------
697 *----------------------------------------------------------------------------*/
698 OWF_API_CALL WFCErrorCode
699 WFC_Device_GetElementAttribiv(WFC_DEVICE* device,
701 WFCElementAttrib attrib,
709 object = WFC_Device_FindElement(device, element);
710 FAIL_IF(NULL == object, WFC_ERROR_BAD_HANDLE);
711 return WFC_Element_GetAttribiv(object, attrib, count, values);
714 /*---------------------------------------------------------------------------
717 *----------------------------------------------------------------------------*/
718 OWF_API_CALL WFCErrorCode
719 WFC_Device_GetElementAttribfv(WFC_DEVICE* device,
721 WFCElementAttrib attrib,
729 object = WFC_Device_FindElement(device, element);
730 FAIL_IF(NULL == object, WFC_ERROR_BAD_HANDLE);
731 return WFC_Element_GetAttribfv(object, attrib, count, values);
735 /*[][][][] IMAGE PROVIDERS [][][][][][][][][][][][][][][][][][][][][][][][][]*/
737 /*---------------------------------------------------------------------------
739 *----------------------------------------------------------------------------*/
741 WFC_Device_EnableContentNotifications(WFC_DEVICE* device,
742 WFC_CONTEXT* context,
752 for (i = 0; i < device->providers.length; i++)
754 WFC_IMAGE_PROVIDER* prov;
756 prov = IMAGE_PROVIDER(OWF_Array_GetItemAt(&device->providers, i));
758 owfNativeStreamEnableUpdateNotifications(prov->streamHandle,
759 enable ? OWF_TRUE : OWF_FALSE);
763 /*---------------------------------------------------------------------------
765 *----------------------------------------------------------------------------*/
766 static WFC_IMAGE_PROVIDER*
767 WFC_Device_CreateImageProvider(WFC_DEVICE* device,
768 WFC_CONTEXT* context,
769 OWFNativeStreamType stream,
770 WFC_IMAGE_PROVIDER_TYPE type)
772 WFC_IMAGE_PROVIDER* provider;
778 /* create/fetch stream-wrapper for native stream. */
780 /* create new image provider object associated to
781 * native stream wrapper previously fetched */
782 provider = WFC_ImageProvider_Create(context, stream, type);
789 if (OWF_Array_AppendItem(&device->providers, provider) != OWF_TRUE)
794 if (!success || !owfSymDeviceInitialise(provider))
796 OWF_Array_RemoveItem(&device->providers, provider);
807 /*---------------------------------------------------------------------------
809 *----------------------------------------------------------------------------*/
811 WFC_Device_DestroyImageProvider(WFC_DEVICE* device,
815 WFCErrorCode result = WFC_ERROR_BAD_HANDLE;
817 ENTER(WFC_Device_DestroyImageProvider);
821 DPRINT((" number of providers = %d", device->providers.length));
823 for (i = 0; i < device->providers.length; i++)
825 WFC_IMAGE_PROVIDER* object;
827 object = (WFC_IMAGE_PROVIDER*)OWF_Array_GetItemAt(&device->providers, i);
829 if (object->handle == handle)
832 DPRINT((" Destroying image provider %d", handle));
834 owfSymDeviceDestroy(device, object, i);
835 OWF_Array_RemoveItemAt(&device->providers, i);
838 result = WFC_ERROR_NONE;
844 * Image provider's source content observer should be removed here,
845 * but on the other hand, it'll be removed when the image provider's
846 * source stream gets destroyed.
848 LEAVE(WFC_Device_DestroyImageProvider);
852 /*---------------------------------------------------------------------------
853 * Destroy all image providers from device
855 * \param device Device
856 *----------------------------------------------------------------------------*/
858 WFC_Device_DestroyImageProviders(WFC_DEVICE* device)
862 ENTER(WFC_Device_DestroyImageProviders);
866 DPRINT(("number of providers = %d", device->providers.length));
868 for (i = 0; i < device->providers.length; i++)
870 WFC_IMAGE_PROVIDER* itemp;
872 itemp = IMAGE_PROVIDER(OWF_Array_GetItemAt(&device->providers, i));
875 OWF_Array_Destroy(&device->providers);
877 LEAVE(WFC_Device_DestroyImageProviders);
880 /*---------------------------------------------------------------------------
882 *----------------------------------------------------------------------------*/
883 OWF_API_CALL WFC_IMAGE_PROVIDER*
884 WFC_Device_FindImageProvider(WFC_DEVICE* device,
886 WFC_IMAGE_PROVIDER_TYPE type)
889 WFC_IMAGE_PROVIDER* result = WFC_INVALID_HANDLE;
891 ENTER(WFC_Device_FindImageProvider);
894 DPRINT(("number of providers = %d", device->providers.length));
896 for (i = 0; i < device->providers.length; i++)
898 WFC_IMAGE_PROVIDER* object;
900 object = IMAGE_PROVIDER(OWF_Array_GetItemAt(&device->providers, i));
901 if (object->handle == handle && object->type == type)
908 LEAVE(WFC_Device_FindImageProvider);
913 /*---------------------------------------------------------------------------
915 *----------------------------------------------------------------------------*/
916 OWF_API_CALL WFC_IMAGE_PROVIDER*
917 WFC_Device_CreateSource(WFC_DEVICE* device,
918 WFC_CONTEXT* context,
919 WFCNativeStreamType stream)
923 return WFC_Device_CreateImageProvider(device,
924 context, stream, WFC_IMAGE_SOURCE);
927 /*---------------------------------------------------------------------------
929 *----------------------------------------------------------------------------*/
930 OWF_API_CALL WFC_IMAGE_PROVIDER*
931 WFC_Device_CreateMask(WFC_DEVICE* device,
932 WFC_CONTEXT* context,
933 WFCNativeStreamType stream)
937 return WFC_Device_CreateImageProvider(device,
938 context, stream, WFC_IMAGE_MASK);
941 /*---------------------------------------------------------------------------
943 *----------------------------------------------------------------------------*/
944 OWF_API_CALL WFCErrorCode
945 WFC_Device_DestroySource(WFC_DEVICE* device, WFCSource source)
948 return WFC_Device_DestroyImageProvider(device, source);
951 /*---------------------------------------------------------------------------
953 *----------------------------------------------------------------------------*/
954 OWF_API_CALL WFCErrorCode
955 WFC_Device_DestroyMask(WFC_DEVICE* device, WFCMask mask)
958 return WFC_Device_DestroyImageProvider(device, mask);
961 /*---------------------------------------------------------------------------
963 *----------------------------------------------------------------------------*/
964 OWF_API_CALL WFC_IMAGE_PROVIDER*
965 WFC_Device_FindSource(WFC_DEVICE* device, WFCSource source)
968 return WFC_Device_FindImageProvider(device, source, WFC_IMAGE_SOURCE);
971 /*---------------------------------------------------------------------------
973 *----------------------------------------------------------------------------*/
974 OWF_API_CALL WFC_IMAGE_PROVIDER*
975 WFC_Device_FindMask(WFC_DEVICE* device, WFCMask mask)
978 return WFC_Device_FindImageProvider(device, mask, WFC_IMAGE_MASK);
981 /*---------------------------------------------------------------------------
982 * Destroy device, or rather queue it for destruction.
984 * \param device Device
985 *----------------------------------------------------------------------------*/
987 WFC_Device_Destroy(WFC_DEVICE* device)
989 ENTER(WFC_Device_Destroy);
993 /* release resources */
994 WFC_Device_DestroyElements(device);
995 WFC_Device_DestroyImageProviders(device);
996 WFC_Device_DestroyContexts(device);
998 OWF_Mutex_Destroy(&device->mutex);
999 device->mutex = NULL;
1001 device->latestUnreadError = WFC_ERROR_NONE;
1002 device->handle = WFC_INVALID_HANDLE;
1004 OWF_Array_RemoveItem(&(gPhyDevice.iDeviceInstanceArray), device);
1006 if (gPhyDevice.iDeviceInstanceArray.length == 0)
1008 OWF_Array_Destroy(&(gPhyDevice.iDeviceInstanceArray));
1010 LEAVE(WFC_Device_Destroy);
1013 /*---------------------------------------------------------------------------
1015 *----------------------------------------------------------------------------*/
1016 OWF_API_CALL WFCboolean
1017 WFC_Device_StreamIsTarget(WFC_DEVICE* device,
1018 WFCNativeStreamType stream)
1021 WFCboolean result = WFC_FALSE;
1025 for (i = 0; i < device->contexts.length; i++)
1029 ctmp = CONTEXT(OWF_Array_GetItemAt(&device->contexts, i));
1030 if (ctmp->stream == stream)
1039 /*---------------------------------------------------------------------------
1041 *----------------------------------------------------------------------------*/
1042 OWF_API_CALL WFC_CONTEXT*
1043 WFC_Device_FindContextByScreen(WFC_DEVICE* device,
1044 WFCint screenNumber)
1047 WFC_CONTEXT* result = NULL;
1051 for (i = 0; i < device->contexts.length; i++)
1055 ctmp = CONTEXT(OWF_Array_GetItemAt(&device->contexts, i));
1056 if (ctmp->screenNumber == screenNumber)
1066 /*---------------------------------------------------------------------------
1067 * Called from context's destructor to clean up any elements that
1068 * weren't added to any scene at all i.e. they only reside in the
1069 * device's element list. These elements must not stay alive after
1070 * the context has been deleted.
1071 *----------------------------------------------------------------------------*/
1073 WFC_Device_DestroyContextElements(WFC_DEVICE* device,
1074 WFC_CONTEXT* context)
1078 DPRINT(("WFC_Device_DestroyContextElements(device=%d, context=%d",
1079 device ? device->handle : 0,
1080 context ? context->handle : 0));
1082 if (!device || !context)
1087 for (i = device->elements.length; i > 0; i--)
1089 WFC_ELEMENT* element;
1091 element = ELEMENT(OWF_Array_GetItemAt(&device->elements, i-1));
1092 if (element->context == context)
1094 DPRINT((" Destroying element %d (%p)", element->handle, element));
1096 /* Improvement idea: This code is partially same as in
1097 * WFC_Device_RemoveElement. Maybe the common part should
1098 * be isolated into some DoRemoveElement function which then
1099 * would be called from here and RemoveElement.
1101 WFC_Context_RemoveElement(CONTEXT(element->context), element->handle);
1102 OWF_Array_RemoveItemAt(&device->elements, i-1);
1103 WFC_Element_Destroy(element);
1108 /*---------------------------------------------------------------------------
1110 *----------------------------------------------------------------------------*/
1112 WFC_Device_DestroyContextImageProviders(WFC_DEVICE* device,
1113 WFC_CONTEXT* context)
1117 DPRINT(("WFC_Device_DestroyContextImageProviders(device=%d, context=%d",
1118 device ? device->handle : 0,
1119 context ? context->handle : 0));
1121 if (!device || !context)
1126 for (i = device->providers.length; i > 0; i--)
1128 WFC_IMAGE_PROVIDER* provider;
1130 provider = IMAGE_PROVIDER(OWF_Array_GetItemAt(&device->providers, i-1));
1131 if (provider->owner == context)
1133 DPRINT((" Destroying image provider %d (%p)",
1134 provider->handle, provider));
1136 WFC_Device_DestroyImageProvider(device, provider->handle);
1141 OWF_API_CALL WFCboolean
1142 WFC_Device_FindScreenNumber(WFCint screenNumber)
1144 WFCint i, j, deviceArrayLength, contextArrayLength;
1145 WFC_DEVICE* pDevice = NULL;
1146 ENTER(WFC_Device_DestroyContext);
1148 DPRINT(("WFC_Device_CheckScreenNumber(screenNumber = %d)", screenNumber));
1150 deviceArrayLength = gPhyDevice.iDeviceInstanceArray.length;
1151 for (i = 0; i < deviceArrayLength; ++i)
1153 pDevice = DEVICE(OWF_Array_GetItemAt(&(gPhyDevice.iDeviceInstanceArray), i));
1154 OWF_ASSERT(pDevice);
1157 contextArrayLength = pDevice->contexts.length;
1158 for (j = 0; j < contextArrayLength; j++)
1160 WFC_CONTEXT* pContext;
1161 pContext = CONTEXT(OWF_Array_GetItemAt(&pDevice->contexts, j));
1162 OWF_ASSERT(pContext);
1163 if (pContext && (pContext->screenNumber == screenNumber))