os/graphics/graphicscomposition/openwfcompositionengine/composition/src/wfcimageprovider.c
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicscomposition/openwfcompositionengine/composition/src/wfcimageprovider.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,227 @@
1.4 +/* Copyright (c) 2009 The Khronos Group Inc.
1.5 + * Portions copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies)
1.6 + *
1.7 + * Permission is hereby granted, free of charge, to any person obtaining a
1.8 + * copy of this software and/or associated documentation files (the
1.9 + * "Materials"), to deal in the Materials without restriction, including
1.10 + * without limitation the rights to use, copy, modify, merge, publish,
1.11 + * distribute, sublicense, and/or sell copies of the Materials, and to
1.12 + * permit persons to whom the Materials are furnished to do so, subject to
1.13 + * the following conditions:
1.14 + *
1.15 + * The above copyright notice and this permission notice shall be included
1.16 + * in all copies or substantial portions of the Materials.
1.17 + *
1.18 + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1.19 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1.20 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
1.21 + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
1.22 + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
1.23 + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
1.24 + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
1.25 + */
1.26 +/*! \ingroup wfc
1.27 + * \file wfcimageprovider.c
1.28 + *
1.29 + * \brief SI image providers
1.30 + */
1.31 +
1.32 +#include <stdio.h>
1.33 +#include <stdlib.h>
1.34 +
1.35 +#include "wfcimageprovider.h"
1.36 +#include "wfcdevice.h"
1.37 +#include "wfccontext.h"
1.38 +#include "wfcstructs.h"
1.39 +
1.40 +#include "owfimage.h"
1.41 +#include "owfarray.h"
1.42 +#include "owfmemory.h"
1.43 +#include "owfobject.h"
1.44 +#include "owfnativestream.h"
1.45 +#include "owfdebug.h"
1.46 +
1.47 +#ifdef __cplusplus
1.48 +extern "C"
1.49 +{
1.50 +#endif
1.51 +
1.52 +#define FIRST_IMAGEPROVIDER_HANDLE 4000
1.53 +
1.54 +static WFCint nextImageProviderHandle =
1.55 + FIRST_IMAGEPROVIDER_HANDLE;
1.56 +
1.57 +OWF_API_CALL void
1.58 +WFC_IMAGE_PROVIDER_Ctor(void* self)
1.59 +{
1.60 + WFC_IMAGE_PROVIDER* ip;
1.61 +
1.62 + ENTER(WFC_IMAGE_PROVIDER_Ctor);
1.63 +
1.64 + ip = IMAGE_PROVIDER(self);
1.65 +
1.66 + ip->lockedStream.image=NULL;
1.67 + ip->lockedStream.lockCount=0;
1.68 +
1.69 + LEAVE(WFC_IMAGE_PROVIDER_Dtor);
1.70 +}
1.71 +
1.72 +OWF_API_CALL void
1.73 +WFC_IMAGE_PROVIDER_Dtor(void* self)
1.74 +{
1.75 +
1.76 + WFC_IMAGE_PROVIDER* ip;
1.77 +
1.78 + ENTER(WFC_IMAGE_PROVIDER_Dtor);
1.79 +
1.80 + ip = IMAGE_PROVIDER(self);
1.81 +
1.82 + DPRINT(("ptr=%p, handle=%d", ip, ip->handle));
1.83 + owfNativeStreamDestroy(ip->streamHandle);
1.84 + DESTROY(ip->owner);
1.85 + if (ip->lockedStream.image)
1.86 + {
1.87 + if (ip->lockedStream.lockCount)
1.88 + { /* belts and braces: unlock the read buffer when image provider is destroyed */
1.89 + DPRINT(("Native stream buffer still locked when Image Provider destroyed ptr=%p, handle=%d", ip, ip->handle));
1.90 + owfNativeStreamReleaseReadBuffer(ip->streamHandle, ip->lockedStream.buffer);
1.91 + }
1.92 + OWF_Image_Destroy(ip->lockedStream.image);
1.93 + }
1.94 + LEAVE(WFC_IMAGE_PROVIDER_Dtor);
1.95 +}
1.96 +
1.97 +static WFC_IMAGE_PROVIDER*
1.98 +WFC_ImageProvider_DoCreate(void* owner, /*WFC_CONTEXT* context,*/
1.99 + OWFNativeStreamType stream,
1.100 + WFC_IMAGE_PROVIDER_TYPE type)
1.101 +{
1.102 + WFC_IMAGE_PROVIDER* object;
1.103 +
1.104 + ENTER(WFC_ImageProvider_DoCreate);
1.105 +
1.106 + if (!stream)
1.107 + {
1.108 + return NULL;
1.109 + }
1.110 + object = CREATE(WFC_IMAGE_PROVIDER);
1.111 +
1.112 + if (!object)
1.113 + {
1.114 + return NULL;
1.115 + }
1.116 +
1.117 + owfNativeStreamAddReference(stream);
1.118 + object->streamHandle = stream;
1.119 + object->type = type;
1.120 + object->contentUpdated = WFC_FALSE;
1.121 +
1.122 + WFC_ImageProvider_LockForReading(object);
1.123 + if (object->lockedStream.image==NULL || object->lockedStream.image->data==NULL)
1.124 + {
1.125 + owfNativeStreamDestroy(stream);
1.126 + DESTROY(object);
1.127 + return NULL;
1.128 + }
1.129 + WFC_ImageProvider_Unlock(object);
1.130 + ADDREF(object->owner, owner);
1.131 +
1.132 + LEAVE(WFC_ImageProvider_DoCreate);
1.133 + return object;
1.134 +}
1.135 +
1.136 +OWF_API_CALL WFC_IMAGE_PROVIDER*
1.137 +WFC_ImageProvider_Create(void* owner, /*WFC_CONTEXT* context,*/
1.138 + OWFNativeStreamType stream,
1.139 + WFC_IMAGE_PROVIDER_TYPE type)
1.140 +{
1.141 + WFC_IMAGE_PROVIDER* object;
1.142 +
1.143 + ENTER(WFC_ImageProvider_Create);
1.144 +
1.145 + object = WFC_ImageProvider_DoCreate(owner/*context*/, stream, type);
1.146 +
1.147 + if (object)
1.148 + {
1.149 + object->handle = nextImageProviderHandle++;
1.150 + DPRINT(("WFC_ImageProvider_Create: attaching image provider %d to "
1.151 + "stream %p",
1.152 + object->handle, object->streamHandle));
1.153 + }
1.154 +
1.155 + LEAVE(WFC_ImageProvider_Create);
1.156 + return object;
1.157 +}
1.158 +
1.159 +OWF_API_CALL void
1.160 +WFC_ImageProvider_LockForReading(WFC_IMAGE_PROVIDER* provider)
1.161 +{
1.162 + void* pixels;
1.163 + OWFint width, height, pixelSize = 0;
1.164 + OWF_IMAGE_FORMAT imgf;
1.165 + OWFint stride;
1.166 +
1.167 + if (!provider) {
1.168 + DPRINT(("WFC_ImageProvider_LockForReading: provider = NULL"));
1.169 + return;
1.170 + }
1.171 + OWF_ASSERT(provider->streamHandle);
1.172 +
1.173 + DPRINT(("stream = %p", provider->streamHandle));
1.174 +
1.175 + if (!provider->lockedStream.lockCount)
1.176 + {
1.177 + DPRINT(("About to acquire & lock a read buffer"));
1.178 + /* acquire buffer */
1.179 + provider->lockedStream.buffer = owfNativeStreamAcquireReadBuffer(provider->streamHandle);
1.180 + DPRINT((" Acquired read buffer stream=%p, buffer=%d",
1.181 + provider->streamHandle, provider->lockedStream.buffer));
1.182 +
1.183 + /* Bind source image to pixel buffer */
1.184 + pixels = owfNativeStreamGetBufferPtr(provider->streamHandle, provider->lockedStream.buffer);
1.185 + if (provider->lockedStream.image)
1.186 + {
1.187 + OWF_Image_SetPixelBuffer(provider->lockedStream.image,pixels);
1.188 + }
1.189 + else
1.190 + {
1.191 + owfNativeStreamGetHeader(provider->streamHandle,
1.192 + &width, &height,
1.193 + &stride, &imgf, &pixelSize);
1.194 + provider->lockedStream.image = OWF_Image_Create(width, height, &imgf, pixels, stride);
1.195 + }
1.196 + }
1.197 +
1.198 + ++provider->lockedStream.lockCount;
1.199 + DPRINT(("lock count = %d", provider->lockedStream.lockCount));
1.200 +
1.201 +}
1.202 +
1.203 +OWF_API_CALL void
1.204 +WFC_ImageProvider_Unlock(WFC_IMAGE_PROVIDER* provider)
1.205 +{
1.206 + if (!provider) {
1.207 + DPRINT(("WFC_ImageProvider_Unlock: provider = NULL"));
1.208 + return;
1.209 + }
1.210 +
1.211 + if (provider->lockedStream.lockCount > 0)
1.212 + {
1.213 + --provider->lockedStream.lockCount;
1.214 + DPRINT(("lock count = %d", provider->lockedStream.lockCount));
1.215 +
1.216 + if (!provider->lockedStream.lockCount)
1.217 + {
1.218 + DPRINT((" Releasing read buffer provider=%p, buffer=%d",
1.219 + provider->handle, provider->lockedStream.buffer));
1.220 + owfNativeStreamReleaseReadBuffer(provider->streamHandle, provider->lockedStream.buffer);
1.221 + }
1.222 + }
1.223 +}
1.224 +
1.225 +
1.226 +
1.227 +#ifdef __cplusplus
1.228 +}
1.229 +#endif
1.230 +