os/graphics/graphicscomposition/openwfcompositionengine/adaptation/src/Platform/Graphics/symbian/owfnotifications.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     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 // Description:
    23 // Display Channel adaptation for owfscreen
    24 // 
    25 //
    26 #include "WF/wfc.h"
    27 #include "wfcstructs.h"
    28 #include "wfcdevice.h"
    29 
    30 #include "wfcdevice.h"
    31 #include "wfcelement.h"
    32 #include "wfccontext.h"
    33 #include "wfcimageprovider.h"
    34 
    35 #include "owfarray.h"
    36 #include "owfmemory.h"
    37 #include "owfmutex.h"
    38 #include "owfscreen.h"
    39 #include "owftypes.h"
    40 #include "owfobject.h"
    41 
    42 #include "owfdebug.h"
    43 
    44 #include "owfnotifications.h"
    45 #include <graphics/symbianstream.h>
    46 
    47 #include "owfdisplaycontext.h"
    48 
    49 #ifdef __cplusplus
    50 extern "C" {
    51 #endif
    52 
    53 static void
    54 owfSymContextSourceStreamUpdated(SymbianStreamType stream,
    55                                  OWFint event,
    56                                  void* data,
    57                                  void* param);
    58 
    59 static void
    60 owfSymDeviceSetUpdateFlags(WFC_CONTEXT* context, OWFNativeStreamType stream, WFCint updateFlags);
    61 
    62 static WFCint
    63 owfSymDeviceProcessAllCallBacks(WFC_CONTEXT* context, WFCint events);
    64 
    65 static void
    66 owfSymDeviceSetVisibilityState(WFC_CONTEXT* context, OWFNativeStreamType stream, WFCint visibility);
    67 
    68 static OWFint owfGetScreenNumber(WFC_CONTEXT* context)
    69 {
    70     OWF_ASSERT(context);
    71     return context->type == WFC_CONTEXT_TYPE_ON_SCREEN ? context->screenNumber : -context->handle;
    72 }
    73 
    74 static void
    75 owfSymContextSourceStreamUpdated(SymbianStreamType stream,
    76                                  OWFint event,
    77                                  void* data,
    78                                  void* param)
    79 {
    80     OWF_ASSERT(data);
    81 
    82     (void) stream; /* suppress compiler warning */
    83  
    84     switch (event)
    85     {
    86     case ESOWF_ObserverReturnDefaultEvent:
    87         if (param)
    88         {
    89             SYMOWF_DEFAULT_EVENT_PARAM* parameter = (SYMOWF_DEFAULT_EVENT_PARAM*) param;
    90             if ((parameter->length) == sizeof(SYMOWF_DEFAULT_EVENT_PARAM))
    91             {
    92                 parameter->event = ESOWF_EventUpdated;
    93             }
    94         }
    95         return;
    96         
    97     case ESOWF_EventUpdated:
    98         {
    99             WFC_CONTEXT*            context = NULL;
   100             context = CONTEXT(data);
   101             OWF_ASSERT(context);
   102             OWF_ASSERT(context->device);
   103             
   104             OWFDisplayContext *pDispCtx = _OWF_DISPLAYCONTEXT(context->displayContext);
   105             
   106             if (param)
   107                 {
   108                 SYMOWF_CONTENT_UPDATED_PARAM* parameter = (SYMOWF_CONTENT_UPDATED_PARAM*) param;
   109                 OWFNativeStreamType owfStream = (OWFNativeStreamType) stream;
   110                 
   111                 if ((parameter->length) == sizeof(SYMOWF_CONTENT_UPDATED_PARAM))
   112                     {
   113                         switch (parameter->id)
   114                             {
   115                             case SYM_CONTENT_UPDATE_BEGIN:
   116                                 {
   117                                     OWF_Mutex_Lock(&context->updateFlagMutex);
   118                                     NFPRINT(("+++ BEGIN CONTENT UPDATE"));
   119                                     
   120                                     parameter->immediateAvailable = 0;
   121                                     parameter->immediateVisibility = SYM_CONTENT_VISIBLE_NOT_SET;
   122                                     if (pDispCtx->iCompositionOngoing &&
   123                                         context->device &&
   124                                         pDispCtx->iPreviousCommit == SYM_CONTENT_PREVIOUS_COMMIT_FALSE)
   125                                     {
   126                                         TInt i = 0;
   127                                         parameter->immediateAvailable = 1;
   128                                         parameter->serialNumber = pDispCtx->iSerialNumber;
   129                                         for (i = 0; i < context->device->providers.length; i++)
   130                                         {
   131                                             WFC_IMAGE_PROVIDER* provider;
   132     
   133                                             provider = IMAGE_PROVIDER(OWF_Array_GetItemAt(&context->device->providers, i));
   134                                             
   135                                             if (provider->type == WFC_IMAGE_SOURCE && 
   136                                                 provider->streamHandle == owfStream && 
   137                                                 context == provider->owner)
   138                                             {
   139                                                 parameter->immediateVisibility = provider->contentVisible;
   140                                                 break;
   141                                             }
   142                                         }
   143                                     }
   144                                     //the mutex is acquired!
   145                                 }
   146                                 return;
   147                                 
   148                             case SYM_CONTENT_UPDATE_END:
   149                                 ++context->sourceUpdateCount;
   150                                 pDispCtx->iEventServerUpdate |= parameter->par;
   151                                 owfSymDeviceSetUpdateFlags(context, owfStream, parameter->par);
   152                                 OWF_Mutex_Unlock(&context->updateFlagMutex);
   153                                 NFPRINT(("+++ END CONTENT UPDATE"));
   154                                 break;
   155                                 
   156                             case SYM_CONTENT_UPDATE:
   157                                 NFPRINT(("+++ CONTENT UPDATE"));
   158                                 OWF_Mutex_Lock(&context->updateFlagMutex);
   159                                 ++context->sourceUpdateCount;
   160                                 pDispCtx->iEventServerUpdate |= parameter->par;
   161                                 owfSymDeviceSetUpdateFlags(context, owfStream, parameter->par);
   162                                 OWF_Mutex_Unlock(&context->updateFlagMutex);
   163                                 break;
   164                             default:
   165                                 break;
   166                             }
   167                     }
   168                 else
   169                     {
   170                     NFPRINT(("+++ WFC_Context_SourceStreamUpdated parameter length error(%d)",
   171                             parameter->length));
   172                     
   173                     }
   174                 }
   175             else
   176                 {
   177                 // Old, legacy, behaviour, not sure if really needed
   178                 NFPRINT(("+++ LEGACY CONTENT UPDATE"));
   179                 OWF_Mutex_Lock(&context->updateFlagMutex);
   180                 ++context->sourceUpdateCount;
   181                 OWF_Mutex_Unlock(&context->updateFlagMutex);
   182                 }
   183         }
   184         return;
   185     default:
   186         return;
   187     }
   188 }
   189 
   190 static void
   191 owfSymDeviceSetUpdateFlags(WFC_CONTEXT* context, OWFNativeStreamType stream, WFCint updateFlags)
   192 {
   193     WFC_DEVICE* device = NULL;
   194     WFCint      i;
   195     
   196     OWF_ASSERT(context && (context->device));
   197 
   198     device = context->device;
   199     
   200     for (i = 0; i < device->providers.length; i++)
   201     {
   202         WFC_IMAGE_PROVIDER* provider = IMAGE_PROVIDER(OWF_Array_GetItemAt(&device->providers, i));
   203     
   204         if (provider->type == WFC_IMAGE_SOURCE && provider->streamHandle == stream && context == provider->owner)
   205         {
   206             NFPRINT(("+++ owfSymDeviceSetUpdateFlags set context updated stream(0x%x) provider(0x%x) flags(0x%x)", stream, provider, updateFlags));
   207             provider->contentUpdated |= updateFlags;
   208         }
   209     }
   210 }
   211 
   212 static void
   213 owfSymDeviceSetVisibilityState(WFC_CONTEXT* context, OWFNativeStreamType stream, WFCint visibility)
   214 {
   215     WFC_DEVICE* device = NULL;
   216     WFCint      i;
   217     
   218     OWF_ASSERT(context && (context->device));
   219 
   220     device = context->device;
   221     
   222     for (i = 0; i < device->providers.length; i++)
   223     {
   224         WFC_IMAGE_PROVIDER* provider = IMAGE_PROVIDER(OWF_Array_GetItemAt(&device->providers, i));
   225         
   226         if (provider->type == WFC_IMAGE_SOURCE && provider->streamHandle == stream && context == provider->owner)
   227         {
   228             provider->contentVisible = visibility;
   229         }
   230     }
   231 }
   232 
   233 static WFCint
   234 owfSymDeviceProcessAllCallBacks(WFC_CONTEXT* context, WFCint events)
   235 {
   236     WFC_DEVICE* device = NULL;
   237     WFCint      i;
   238     WFCint newMask = 0;
   239     NFPRINT(("+++ START owfSymDeviceProcessAllCallBacks events=0x%x", events));
   240     
   241     if (!context || !(context->device))
   242     {
   243         return newMask;
   244     }
   245     device = context->device;
   246     
   247     OWFDisplayContext *pDispCtx = _OWF_DISPLAYCONTEXT(context->displayContext);
   248 
   249     for (i = 0; i < device->providers.length; i++)
   250     {
   251         WFC_IMAGE_PROVIDER* source = IMAGE_PROVIDER(OWF_Array_GetItemAt(&device->providers, i));
   252         
   253         if (source->contentVisible == SYM_CONTENT_VISIBLE_NOT_SET)
   254         {
   255             source->contentVisible = SYM_CONTENT_NOT_VISIBLE;
   256         }
   257         
   258         NFPRINT(("+++ owfSymDeviceProcessAllCallBacks provider=0x%x v=%d t=%d o=%d u=0x%x c=0x%x ", 
   259                  source, 
   260                  source->contentVisible == SYM_CONTENT_VISIBLE, 
   261                  source->type == WFC_IMAGE_SOURCE, 
   262                  context == source->owner,
   263                  source->contentUpdated,
   264                  source->composed));
   265         
   266         if (source->contentVisible == SYM_CONTENT_VISIBLE && 
   267             source->type == WFC_IMAGE_SOURCE && 
   268             context == source->owner && 
   269             source->contentUpdated & events &&
   270             source->composed)
   271         {
   272             NFPRINT(("+++ START owfSymDeviceProcessAllCallBacks process all notifications handle=0x%x", 
   273                     source->streamHandle));
   274         
   275             SymbianStreamProcessNotifications((SymbianStreamType)source->streamHandle, 
   276                                               events & source->contentUpdated, 
   277                                               owfGetScreenNumber(context),
   278                                               pDispCtx->iSerialNumber,
   279                                               &newMask);
   280 
   281             source->visited |= events;
   282         
   283             source->contentUpdated &= ~events;
   284             source->contentUpdated |= newMask;
   285             source->composed = 0;
   286         }
   287     }
   288     
   289     for (i = 0; i < device->providers.length; i++)
   290     {
   291         WFC_IMAGE_PROVIDER* source = IMAGE_PROVIDER(OWF_Array_GetItemAt(&device->providers, i));
   292         
   293         if (!source->visited && 
   294             source->type == WFC_IMAGE_SOURCE && 
   295             context == source->owner && 
   296             (source->contentUpdated & events))
   297         {
   298             NFPRINT(("+++ START owfSymDeviceProcessAllCallBacks check visible handle=0x%x", 
   299                     source->streamHandle));
   300                 SymbianStreamCheckVisible((SymbianStreamType)source->streamHandle,
   301                                           events & source->contentUpdated,
   302                                           owfGetScreenNumber(context),
   303                                           pDispCtx->iSerialNumber);
   304                 
   305                 source->contentUpdated &= ~events;
   306             }
   307         source->visited = 0;
   308     }
   309     
   310     return newMask;
   311 }
   312 
   313 
   314 OWF_API_CALL OWFboolean
   315 owfSymDeviceInitialise(WFC_IMAGE_PROVIDER* source)
   316 {
   317     WFC_CONTEXT* context = NULL;
   318     WFC_DEVICE* device = NULL;
   319     WFCint i = 0;
   320     OWFNativeStreamType stream;
   321     
   322     if (!source || !(source->owner) || ! (((WFC_CONTEXT*)source->owner)->device))
   323     {
   324         return OWF_FALSE;
   325     }
   326    
   327     context = (WFC_CONTEXT*)source->owner;
   328     device = context->device;
   329     
   330     if (source->type == WFC_IMAGE_MASK)
   331     {
   332         return OWF_TRUE;
   333     }
   334     
   335     stream = source->streamHandle;
   336     
   337     source->contentVisible = SYM_CONTENT_VISIBLE_NOT_SET;
   338     source->visited = 0;
   339     source->composed = 0;
   340     
   341     // forward check to copy the visibility state
   342     for (i = 0; i < device->providers.length; i++)
   343     {
   344         WFC_IMAGE_PROVIDER* provider = IMAGE_PROVIDER(OWF_Array_GetItemAt(&device->providers, i));
   345         
   346         if (provider->type == WFC_IMAGE_SOURCE && provider->streamHandle == stream && context == provider->owner)
   347         {
   348             source->contentVisible = provider->contentVisible;
   349             break;
   350         }
   351     }
   352     
   353     SymbianStreamAddExtendedObserver((SymbianStreamType)source->streamHandle, 
   354                                   owfSymContextSourceStreamUpdated, 
   355                                   context, 
   356                                   owfGetScreenNumber(context),
   357                                   ESOWF_EventUpdated);
   358     return OWF_TRUE;
   359 
   360 }
   361 
   362 OWF_API_CALL void
   363 owfSymDeviceDestroy(WFC_DEVICE* device, WFC_IMAGE_PROVIDER* source, WFCint position)
   364 {
   365     WFCint i = 0;
   366     OWFboolean foundAnotherSource = OWF_FALSE;
   367 
   368     OWF_ASSERT(device);
   369     OWF_ASSERT(source);
   370 
   371     if (source->type == WFC_IMAGE_SOURCE)
   372     {
   373         OWFNativeStreamType  stream = source->streamHandle;
   374         WFC_CONTEXT* context = (WFC_CONTEXT*)source->owner;
   375         OWF_ASSERT(context);
   376         for (i = 0; i < device->providers.length; i++)
   377         {
   378             if (i != position)
   379             {
   380                 WFC_IMAGE_PROVIDER* newObject = (WFC_IMAGE_PROVIDER*)(OWF_Array_GetItemAt(&device->providers, i));
   381                 if ((stream == newObject->streamHandle) && 
   382                     (context == newObject->owner) && 
   383                     (newObject->type == WFC_IMAGE_SOURCE))
   384                 {
   385                     foundAnotherSource = OWF_TRUE;
   386                     break;
   387                 }
   388             }
   389         }
   390         
   391         if (!foundAnotherSource)
   392         {
   393         WFCint screenNumber = owfGetScreenNumber(context);
   394         SymbianStreamRemoveObserver((SymbianStreamType)stream,
   395                                             context,
   396                                             ESOWF_EventUpdated);
   397         }
   398     }
   399 }
   400 
   401 OWF_API_CALL OWFboolean
   402 owfSymElementNotifications(WFC_CONTEXT* context, WFC_ELEMENT* element)
   403 {
   404     WFC_IMAGE_PROVIDER* source = NULL;
   405     OWFNativeStreamType stream = OWF_INVALID_HANDLE;
   406     
   407     OWF_ASSERT(context && element && (context->device) && (element->source));
   408     
   409     source = IMAGE_PROVIDER(element->source);
   410     
   411     if (source->type != WFC_IMAGE_SOURCE)
   412     {
   413         return OWF_TRUE;
   414     }
   415     
   416     OWF_Mutex_Lock(&context->updateFlagMutex);
   417     source->composed = source->contentUpdated | ESOWF_EventComposed;
   418     NFPRINT(("+++ END owfSymElementNotifications composed s=0x%x u=0x%x", source, source->composed));
   419     
   420     if (source->contentVisible != SYM_CONTENT_VISIBLE_NOT_SET)
   421     {
   422         OWF_Mutex_Unlock(&context->updateFlagMutex);
   423         return OWF_TRUE;
   424     }
   425     
   426     stream = source->streamHandle;
   427     
   428     if (!element->skipCompose)
   429         {
   430         owfSymDeviceSetVisibilityState(context, stream, SYM_CONTENT_VISIBLE);
   431         }
   432     
   433     OWF_Mutex_Unlock(&context->updateFlagMutex);
   434     
   435     return OWF_TRUE;
   436 }
   437 
   438 OWF_API_CALL void
   439 owfSymDeviceResetVisibilityState(WFC_CONTEXT* context)
   440 {
   441     WFC_DEVICE* device = NULL;
   442     WFCint      i;
   443     
   444     OWF_ASSERT(context && (context->device));
   445 
   446     device = context->device;
   447     
   448     OWFDisplayContext *pDispCtx = _OWF_DISPLAYCONTEXT(context->displayContext);
   449     
   450     OWF_Mutex_Lock(&context->updateFlagMutex);
   451     pDispCtx->iPreviousCommit = SYM_CONTENT_PREVIOUS_COMMIT_TRUE;
   452     context->sourceUpdateCount++;
   453     for (i = 0; i < device->providers.length; i++)
   454     {
   455         WFC_IMAGE_PROVIDER* provider = IMAGE_PROVIDER(OWF_Array_GetItemAt(&device->providers, i));
   456         
   457         if (context == provider->owner)
   458         {
   459             provider->contentVisible = SYM_CONTENT_VISIBLE_NOT_SET;
   460         }
   461     }
   462     OWF_Mutex_Unlock(&context->updateFlagMutex);
   463 }
   464 
   465 OWF_API_CALL WFCint
   466 owfSymProcessAllNotifications(WFC_CONTEXT* context)
   467 {
   468     WFCint newContextUpdateEvents = 0;
   469     
   470     if (!context )
   471     {
   472         NFPRINT(("+++ END owfSymProcessAllNotifications (context = 0)"));
   473         return 0;
   474     }
   475     
   476     OWFDisplayContext *pDispCtx = _OWF_DISPLAYCONTEXT(context->displayContext);
   477     
   478     NFPRINT(("+++ START owfSymProcessAllNotifications events=0x%x", pDispCtx->iEventServerUpdate));
   479     OWF_Mutex_Lock(&context->updateFlagMutex);
   480     pDispCtx->iCompositionOngoing = WFC_FALSE;
   481     
   482     if (pDispCtx->iEventServerUpdate || pDispCtx->iPreviousCommit == SYM_CONTENT_PREVIOUS_COMMIT_TRUE)
   483     {
   484         newContextUpdateEvents |= owfSymDeviceProcessAllCallBacks(context, pDispCtx->iEventServerUpdate);
   485     
   486         pDispCtx->iEventServerUpdate = newContextUpdateEvents;
   487         
   488         if (newContextUpdateEvents)
   489         {
   490             context->sourceUpdateCount++;
   491         }
   492     }
   493     
   494     pDispCtx->iPreviousCommit = SYM_CONTENT_PREVIOUS_COMMIT_FALSE;
   495     OWF_Mutex_Unlock(&context->updateFlagMutex);
   496     
   497     NFPRINT(("+++ END owfSymProcessAllNotifications newEvents=0x%x", newContextUpdateEvents));
   498     return newContextUpdateEvents;
   499 }
   500 
   501 #ifdef __cplusplus
   502 }
   503 #endif
   504