os/graphics/graphicscomposition/openwfcompositionengine/composition/src/wfcelement.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 Element handling
35 #include "wfcelement.h"
36 #include "wfccontext.h"
37 #include "wfcdevice.h"
38 #include "wfcstructs.h"
39 #include "wfcimageprovider.h"
40 #include "owfnativestream.h"
41 #include "owfattributes.h"
42 #include "owfmemory.h"
43 #include "owfobject.h"
51 #define FIRST_ELEMENT_HANDLE 3000
53 #define FAIL_IF(c,e) if (c) { return e; }
56 static const WFCbitfield validTransparencyModes[] = {
57 WFC_TRANSPARENCY_NONE,
58 WFC_TRANSPARENCY_ELEMENT_GLOBAL_ALPHA,
59 WFC_TRANSPARENCY_SOURCE,
60 WFC_TRANSPARENCY_MASK,
61 WFC_TRANSPARENCY_ELEMENT_GLOBAL_ALPHA |
62 WFC_TRANSPARENCY_SOURCE,
63 WFC_TRANSPARENCY_ELEMENT_GLOBAL_ALPHA |
67 /*---------------------------------------------------------------------------
69 *----------------------------------------------------------------------------*/
71 WFC_Element_Initialize(WFC_ELEMENT* element)
73 element->dstRect[0] = 0;
74 element->dstRect[1] = 0;
75 element->dstRect[2] = 0;
76 element->dstRect[3] = 0;
77 element->srcRect[0] = 0;
78 element->srcRect[1] = 0;
79 element->srcRect[2] = 0;
80 element->srcRect[3] = 0;
82 element->source = WFC_INVALID_HANDLE;
83 element->sourceFlip = WFC_FALSE;
84 element->sourceRotation = WFC_ROTATION_0;
85 element->sourceScaleFilter = WFC_SCALE_FILTER_NONE;
86 element->transparencyTypes = 0;
87 element->globalAlpha = OWF_ALPHA_MAX_VALUE;
88 element->maskHandle = WFC_INVALID_HANDLE;
89 element->sourceHandle = WFC_INVALID_HANDLE;
92 /*---------------------------------------------------------------------------
94 *----------------------------------------------------------------------------*/
96 WFC_Element_Destroy(WFC_ELEMENT* element)
100 DPRINT(("WFC_Element_Destroy"));
102 DPRINT((" element = %p (%d)", element, element->handle));
104 DESTROY(element->cachedSource);
105 DESTROY(element->cachedMask);
107 DPRINT((" cachedSource = %p (%d)", element->cachedSource,
108 element->cachedSource ?
109 element->cachedSource->handle :
111 DPRINT((" cachedMask = %p (%d)", element->cachedMask,
112 element->cachedMask ?
113 element->cachedMask->handle :
116 DESTROY(element->source);
117 DESTROY(element->mask);
119 DPRINT((" source = %p (%d)", element->source,
121 element->source->handle :
123 DPRINT((" mask = %p (%d)", element->mask,
125 element->mask->handle :
127 DESTROY(element->context);
129 OWF_Pool_PutObject(element);
133 /*---------------------------------------------------------------------------
134 * Create new element into context
136 * \param context Context into which to create the element
138 * \return New element object or NULL
139 *----------------------------------------------------------------------------*/
140 OWF_API_CALL WFC_ELEMENT*
141 WFC_Element_Create(WFC_CONTEXT* context)
143 static WFCint nextElementHandle = FIRST_ELEMENT_HANDLE;
144 WFC_ELEMENT* element;
148 element = (WFC_ELEMENT*)OWF_Pool_GetObject(context->elementPool);
152 WFC_Element_Initialize(element);
154 element->handle = nextElementHandle++;
156 ADDREF(element->context, context);
157 element->device = context->device;
162 /*---------------------------------------------------------------------------
164 *----------------------------------------------------------------------------*/
165 OWF_API_CALL WFC_ELEMENT*
166 WFC_Element_Clone(WFC_ELEMENT* element)
169 WFC_CONTEXT* context;
173 DPRINT(("WFC_Element_Clone: element = %d, context = %d", element->handle,
174 element->context->handle));
176 context = CONTEXT(element->context);
177 clone = (WFC_ELEMENT*)OWF_Pool_GetObject(context->elementPool);
181 WFC_Element_Initialize(clone);
183 clone->handle = element->handle;
185 clone->sourceFlip = element->sourceFlip;
186 clone->sourceRotation = element->sourceRotation;
187 clone->sourceScaleFilter= element->sourceScaleFilter;
188 clone->transparencyTypes= element->transparencyTypes;
189 clone->globalAlpha = element->globalAlpha;
190 clone->maskHandle = element->maskHandle;
191 clone->sourceHandle = element->sourceHandle;
193 ADDREF(clone->cachedMask, element->cachedMask);
194 ADDREF(clone->cachedSource, element->cachedSource);
196 ADDREF(clone->mask, element->mask);
197 ADDREF(clone->source, element->source);
198 clone->device = element->device;
200 ADDREF(clone->context, element->context);
202 memcpy(clone->srcRect, element->srcRect, 4 * sizeof(WFCfloat));
203 memcpy(clone->dstRect, element->dstRect, 4 * sizeof(WFCfloat));
210 /*---------------------------------------------------------------------------
212 *----------------------------------------------------------------------------*/
213 static WFCboolean WFC_Element_ClampRectangle(const char* rtype,
217 * int -> float conversion:
218 * ------------------------
220 * above 2^24 we start to lose precision when performing
221 * conversions between floats & ints, thus we must clamp
222 * values above in order to avoid nasty sign-change effects
223 * and other weird side-effects.
227 const WFCfloat LIMIT = 1.6777216E7f;
229 WFCboolean clamped = WFC_FALSE;
231 /* Prevent compiler warning when DPRINT is disabled */
234 for (i = 0; i < 4; i++)
236 if (fabs(rect[i]) > LIMIT)
239 static const char* coord[4] = {"x", "y", "width", "height"};
243 DPRINT((" Warning: Precision loss in element's %s rectangle's "
247 rect[i] = rect[i] < 0 ? -LIMIT : LIMIT;
254 /*===========================================================================
256 * Attribute set-time checking functions. These are used for checking
257 * the attributes before saving them into elements. Attributes are validated
258 * for 2nd time during commit, where e.g. destination rectangle size vs.
259 * mask size dependency is checked.
261 *============================================================================*/
263 /*---------------------------------------------------------------------------
265 *----------------------------------------------------------------------------*/
267 WFC_Element_ValidateSourceRectangle(WFC_ELEMENT* element,
270 WFCErrorCode result = WFC_ERROR_NONE;
279 if (rect[0] < 0.0f || rect[1] < 0.0f || rect[2] < 0.0f || rect[3] < 0.0f)
281 result = WFC_ERROR_ILLEGAL_ARGUMENT;
283 else if (WFC_Element_ClampRectangle("source", rect))
285 result = WFC_ERROR_NONE;
290 /*---------------------------------------------------------------------------
292 *----------------------------------------------------------------------------*/
294 WFC_Element_ValidateDestinationRectangle(WFC_ELEMENT* element,
297 WFCErrorCode result = WFC_ERROR_NONE;
306 DPRINT(("WFC_Element_ValidateDestinationRectangle(element = %d)",
309 if (rect[2] < 0.0f || rect[3] < 0.0f)
311 result = WFC_ERROR_ILLEGAL_ARGUMENT;
313 else if (WFC_Element_ClampRectangle("destination", rect))
315 /* ... return error or something here? */
316 result = WFC_ERROR_NONE;
319 /* Hmm.. let's clamp the rectangle even more! To 16k*16k at max;
320 * in OWF_Image_Create we calculate the byte size of the image buffer
321 * required, and if we have 4bpp, we get overflow for pixelcounts
323 rect[2] = CLAMP(rect[2], 0, 16384);
324 rect[3] = CLAMP(rect[3], 0, 16384);
329 #define BOOLEAN_TO_ERROR(x) ((x) ? WFC_ERROR_NONE : WFC_ERROR_ILLEGAL_ARGUMENT)
331 /*---------------------------------------------------------------------------
333 *----------------------------------------------------------------------------*/
335 WFC_Element_ValidateScalarAttributei(WFC_ELEMENT* element,
336 WFCElementAttrib attrib,
339 WFCErrorCode result = WFC_ERROR_NONE;
345 case WFC_ELEMENT_SOURCE:
347 WFC_IMAGE_PROVIDER* source;
349 source = WFC_Device_FindImageProvider(element->device,
353 result = BOOLEAN_TO_ERROR((WFC_INVALID_HANDLE == value) ||
354 ((WFC_INVALID_HANDLE != value) &&
359 case WFC_ELEMENT_MASK:
361 WFC_IMAGE_PROVIDER* mask;
363 mask = WFC_Device_FindImageProvider(element->device,
367 result = BOOLEAN_TO_ERROR((WFC_INVALID_HANDLE == value) ||
368 ((WFC_INVALID_HANDLE != value) &&
373 case WFC_ELEMENT_SOURCE_ROTATION:
375 WFCRotation rotation = (WFCRotation) value;
377 result = BOOLEAN_TO_ERROR((WFC_ROTATION_0 == rotation ||
378 WFC_ROTATION_90 == rotation ||
379 WFC_ROTATION_180 == rotation ||
380 WFC_ROTATION_270 == rotation));
384 case WFC_ELEMENT_SOURCE_SCALE_FILTER:
386 WFCScaleFilter filter = (WFCScaleFilter) value;
388 result = BOOLEAN_TO_ERROR((WFC_SCALE_FILTER_NONE == filter ||
389 WFC_SCALE_FILTER_FASTER == filter ||
390 WFC_SCALE_FILTER_BETTER == filter));
394 case WFC_ELEMENT_SOURCE_FLIP:
396 result = WFC_ERROR_NONE;
400 case WFC_ELEMENT_TRANSPARENCY_TYPES:
403 WFCint count = sizeof(validTransparencyModes) /
405 WFCbitfield types = (WFCbitfield) value;
407 result = WFC_ERROR_ILLEGAL_ARGUMENT;
408 for (ii = 0; ii < count; ii++) {
409 if (types == validTransparencyModes[ii])
411 result = WFC_ERROR_NONE;
420 result = WFC_ERROR_BAD_ATTRIBUTE;
427 /*---------------------------------------------------------------------------
429 *----------------------------------------------------------------------------*/
431 WFC_Element_ValidateScalarAttributef(WFC_ELEMENT* element,
432 WFCElementAttrib attrib,
435 WFCErrorCode result = WFC_ERROR_NONE;
445 case WFC_ELEMENT_GLOBAL_ALPHA:
447 result = BOOLEAN_TO_ERROR(value >= OWF_ALPHA_MIN_VALUE &&
448 value <= OWF_ALPHA_MAX_VALUE);
453 case WFC_ELEMENT_SOURCE_FLIP:
454 case WFC_ELEMENT_SOURCE_ROTATION:
455 case WFC_ELEMENT_SOURCE_SCALE_FILTER:
456 case WFC_ELEMENT_TRANSPARENCY_TYPES:
457 case WFC_ELEMENT_SOURCE:
458 case WFC_ELEMENT_MASK:
460 /* NOTE! special early out here. */
461 result = WFC_ERROR_BAD_ATTRIBUTE;
467 result = WFC_ERROR_ILLEGAL_ARGUMENT;
475 /*---------------------------------------------------------------------------
477 *----------------------------------------------------------------------------*/
479 WFC_Element_SetElementImageProvider(WFC_ELEMENT* element,
480 WFC_IMAGE_PROVIDER_TYPE type,
483 WFC_IMAGE_PROVIDER* provider;
487 provider = WFC_Device_FindImageProvider(element->device, handle, type);
491 case WFC_IMAGE_SOURCE:
493 DESTROY(element->cachedSource);
494 ADDREF(element->cachedSource, provider);
495 element->sourceHandle = handle;
500 DESTROY(element->cachedMask);
501 ADDREF(element->cachedMask, provider);
502 element->maskHandle = handle;
508 /*---------------------------------------------------------------------------
509 * \brief Set vector integer attribute for an element
511 * \param element Element
512 * \param attrib Attribute name
513 * \param count Attribute size
514 * \param values Attribute vector value
516 *----------------------------------------------------------------------------*/
517 OWF_API_CALL WFCErrorCode
518 WFC_Element_SetAttribiv(WFC_ELEMENT* element,
519 WFCElementAttrib attrib,
521 const WFCint* values)
523 WFCErrorCode result = WFC_ERROR_NONE;
526 FAIL_IF(NULL == values, WFC_ERROR_ILLEGAL_ARGUMENT);
530 /* Vector attributes */
531 case WFC_ELEMENT_SOURCE_RECTANGLE:
532 case WFC_ELEMENT_DESTINATION_RECTANGLE:
541 result = WFC_Element_SetAttribfv(element, attrib, count, rect);
545 case WFC_ELEMENT_GLOBAL_ALPHA:
547 WFCfloat fvalue = values[0] /
548 (WFCfloat) OWF_BYTE_MAX_VALUE;
550 result = WFC_Element_SetAttribfv(element,
557 /* Scalar attributes */
562 FAIL_IF(1 != count, WFC_ERROR_ILLEGAL_ARGUMENT);
566 /* Validate the value thus ensuring it is safe to change it */
567 result = WFC_Element_ValidateScalarAttributei(element,
570 if (WFC_ERROR_NONE != result)
577 case WFC_ELEMENT_SOURCE:
579 WFC_Element_SetElementImageProvider(element,
584 case WFC_ELEMENT_MASK:
586 WFC_Element_SetElementImageProvider(element,
591 case WFC_ELEMENT_SOURCE_FLIP:
593 element->sourceFlip = (WFCboolean)value;
596 case WFC_ELEMENT_SOURCE_ROTATION:
598 element->sourceRotation = (WFCRotation)value;
601 case WFC_ELEMENT_SOURCE_SCALE_FILTER:
603 element->sourceScaleFilter = (WFCScaleFilter)value;
606 case WFC_ELEMENT_TRANSPARENCY_TYPES:
608 element->transparencyTypes = value;
613 result = WFC_ERROR_BAD_ATTRIBUTE;
624 /*---------------------------------------------------------------------------
626 *----------------------------------------------------------------------------*/
627 OWF_API_CALL WFCErrorCode
628 WFC_Element_SetAttribfv(WFC_ELEMENT* element,
629 WFCElementAttrib attrib,
631 const WFCfloat* values)
633 WFCErrorCode result = WFC_ERROR_NONE;
635 FAIL_IF(NULL == values, WFC_ERROR_ILLEGAL_ARGUMENT);
639 /* Vector attributes */
640 case WFC_ELEMENT_SOURCE_RECTANGLE:
641 case WFC_ELEMENT_DESTINATION_RECTANGLE:
645 FAIL_IF(4 != count, WFC_ERROR_ILLEGAL_ARGUMENT);
647 memcpy(clamped, values, 4 * sizeof(WFCfloat));
649 if (WFC_ELEMENT_SOURCE_RECTANGLE == attrib)
651 /* this clamps the rectangle, in case it has values that
652 * cause precision loss or other fuzzy behaviour. */
653 result = WFC_Element_ValidateSourceRectangle(element, clamped);
655 if (WFC_ERROR_NONE == result)
657 memcpy(element->srcRect, clamped, 4 * sizeof(WFCfloat));
659 DPRINT((" Source rectangle set to (%.2f,%.2f,%.2f,%.2f)",
660 clamped[0], clamped[1], clamped[2], clamped[3]));
664 DPRINT((" Source rectangle (%.2f,%.2f,%.2f,%.2f) is " \
666 values[0], values[1], values[2], values[3]));
671 result = WFC_Element_ValidateDestinationRectangle(element,
673 if (WFC_ERROR_NONE == result)
675 memcpy(element->dstRect, clamped, 4 * sizeof(WFCfloat));
677 DPRINT((" Destination rectangle set to " \
678 "(%.2f,%.2f,%.2f,%.2f)",
679 clamped[0], clamped[1], clamped[2], clamped[3]));
683 DPRINT((" Destination rectangle (%.2f,%.2f,%.2f,%.2f) is "
685 values[0], values[1], values[2], values[3]));
691 /* scalar attributes */
692 case WFC_ELEMENT_GLOBAL_ALPHA:
694 /* values[0] must be [0, 1] */
695 WFCfloat value = values[0];
697 /* value is [0, 1] map to [0, OWF_ALPHA_MAX] */
698 value = value * OWF_ALPHA_MAX_VALUE;
700 /* validate the value */
701 result = WFC_Element_ValidateScalarAttributef(element,
705 if (WFC_ERROR_NONE != result)
707 /* invalid value for attribute, out we go */
711 element->globalAlpha = value;
717 result = WFC_ERROR_BAD_ATTRIBUTE;
725 /*---------------------------------------------------------------------------
727 *----------------------------------------------------------------------------*/
728 OWF_API_CALL WFCErrorCode
729 WFC_Element_GetAttribiv(WFC_ELEMENT* element,
730 WFCElementAttrib attrib,
734 WFCErrorCode result = WFC_ERROR_NONE;
737 FAIL_IF(NULL == values, WFC_ERROR_ILLEGAL_ARGUMENT);
741 /* Vector attributes */
742 case WFC_ELEMENT_SOURCE_RECTANGLE:
743 case WFC_ELEMENT_DESTINATION_RECTANGLE:
745 WFCfloat rect[4] = {0.0, 0.0, 0.0, 0.0};
747 result = WFC_Element_GetAttribfv(element, attrib, count, rect);
749 if (WFC_ERROR_NONE == result)
751 values[0] = floor(rect[0]);
752 values[1] = floor(rect[1]);
753 values[2] = floor(rect[2]);
754 values[3] = floor(rect[3]);
759 /* Scalar attributes */
762 FAIL_IF(1 != count, WFC_ERROR_ILLEGAL_ARGUMENT);
766 /* pure int attributes */
767 case WFC_ELEMENT_SOURCE:
769 *values = element->sourceHandle;
772 case WFC_ELEMENT_MASK:
774 *values = element->maskHandle;
777 case WFC_ELEMENT_SOURCE_FLIP:
779 *values = element->sourceFlip;
782 case WFC_ELEMENT_SOURCE_ROTATION:
784 *values = element->sourceRotation;
787 case WFC_ELEMENT_SOURCE_SCALE_FILTER:
789 *values = element->sourceScaleFilter;
792 case WFC_ELEMENT_TRANSPARENCY_TYPES:
794 *values = element->transparencyTypes;
797 case WFC_ELEMENT_GLOBAL_ALPHA:
801 WFC_Element_GetAttribfv(element, attrib, 1, &fvalue);
802 *values = floor(OWF_BYTE_MAX_VALUE * fvalue /
803 OWF_ALPHA_MAX_VALUE);
808 result = WFC_ERROR_BAD_ATTRIBUTE;
819 /*---------------------------------------------------------------------------
821 *----------------------------------------------------------------------------*/
822 OWF_API_CALL WFCErrorCode
823 WFC_Element_GetAttribfv(WFC_ELEMENT* element,
824 WFCElementAttrib attrib,
828 WFCErrorCode result = WFC_ERROR_NONE;
830 FAIL_IF(NULL == values, WFC_ERROR_ILLEGAL_ARGUMENT);
834 /* Vector attributes */
835 case WFC_ELEMENT_SOURCE_RECTANGLE:
836 case WFC_ELEMENT_DESTINATION_RECTANGLE:
838 FAIL_IF(4 != count, WFC_ERROR_ILLEGAL_ARGUMENT);
840 if (WFC_ELEMENT_SOURCE_RECTANGLE == attrib)
842 values[0] = element->srcRect[0];
843 values[1] = element->srcRect[1];
844 values[2] = element->srcRect[2];
845 values[3] = element->srcRect[3];
849 values[0] = element->dstRect[0];
850 values[1] = element->dstRect[1];
851 values[2] = element->dstRect[2];
852 values[3] = element->dstRect[3];
857 /* Scalar attributes */
862 case WFC_ELEMENT_GLOBAL_ALPHA:
864 *values = element->globalAlpha;
869 result = WFC_ERROR_BAD_ATTRIBUTE;
880 /*---------------------------------------------------------------------------
881 * Attribute checkers to use during commit to check element
882 * for inconsistencies.
883 *----------------------------------------------------------------------------*/
885 WFC_Element_CheckAttribute(WFC_ELEMENT* element,
886 WFCElementAttrib attrib)
888 #define VALIDATE_SCALAR_I(v) \
889 (WFC_Element_ValidateScalarAttributei(element, attrib, v) == \
890 WFC_ERROR_NONE ? WFC_TRUE : WFC_FALSE)
891 #define VALIDATE_SCALAR_F(v) \
892 (WFC_Element_ValidateScalarAttributef(element, attrib, v) == \
893 WFC_ERROR_NONE ? WFC_TRUE : WFC_FALSE)
895 WFCboolean result = WFC_TRUE;
897 DPRINT(("WFC_Element_CheckAttribute(%08x,%0x)",
905 case WFC_ELEMENT_SOURCE:
907 /* Validated when the attribute was modified */
911 case WFC_ELEMENT_MASK:
913 /* Validated when the attribute was modified */
917 case WFC_ELEMENT_SOURCE_FLIP:
919 result = VALIDATE_SCALAR_I(element->sourceFlip) ? WFC_TRUE: WFC_FALSE;
922 DPRINT((" Element source flipping is invalid (%d)",
923 element->sourceFlip));
928 case WFC_ELEMENT_SOURCE_ROTATION:
930 result = VALIDATE_SCALAR_I(element->sourceRotation) ? WFC_TRUE: WFC_FALSE;
934 DPRINT((" Element source rotation is invalid (%d)",
935 element->sourceRotation));
940 case WFC_ELEMENT_SOURCE_SCALE_FILTER:
942 result = VALIDATE_SCALAR_I(element->sourceScaleFilter) ? WFC_TRUE: WFC_FALSE;
946 DPRINT((" Element source scale filter is invalid (%d)",
947 element->sourceScaleFilter));
952 case WFC_ELEMENT_TRANSPARENCY_TYPES:
954 result = VALIDATE_SCALAR_I(element->transparencyTypes) ? WFC_TRUE: WFC_FALSE;
958 DPRINT((" Element transparency type is invalid (%x)",
959 element->transparencyTypes));
964 case WFC_ELEMENT_GLOBAL_ALPHA:
966 result = VALIDATE_SCALAR_F(element->globalAlpha) ? WFC_TRUE: WFC_FALSE;
969 DPRINT((" Element global alpha is invalid (%d)",
970 element->globalAlpha));
975 case WFC_ELEMENT_DESTINATION_RECTANGLE:
977 WFC_IMAGE_PROVIDER* mask;
979 /* The <0 test is repeated in SetAttribfv ValidateDestinationRectangle */
980 if (element->dstRect[2] < 0 || element->dstRect[3] < 0)
982 DPRINT((" Element destination rectangle has negative "
987 if (element->maskHandle!=WFC_INVALID_HANDLE)
989 result = WFC_Element_CheckAttribute(element, WFC_ELEMENT_MASK);
993 mask = WFC_Device_FindMask(element->device,
994 element->maskHandle);
997 DPRINT((" Mask handle is valid, but mask object now destroyed"));
998 mask=element->cachedMask;
1006 WFCint maskWidth, maskHeight;
1008 DPRINT((" Element has a mask"));
1009 /* if the element has a mask, then width & height must match
1010 the dimensions of that mask */
1011 owfNativeStreamGetHeader(mask->streamHandle,&maskWidth, &maskHeight,NULL,NULL,NULL);
1013 if (element->dstRect[2] != maskWidth ||
1014 element->dstRect[3] != maskHeight)
1016 DPRINT((" Mask size (%dx%d) != element size (%d,%d)",
1017 maskWidth, maskHeight,
1018 (int)element->dstRect[2],
1019 (int)element->dstRect[3]));
1026 DPRINT((" No mask pointers could be opened! Scene not safe!"));
1034 case WFC_ELEMENT_SOURCE_RECTANGLE:
1036 WFC_IMAGE_PROVIDER* source;
1038 result = WFC_Element_CheckAttribute(element, WFC_ELEMENT_SOURCE);
1040 if (result && element->sourceHandle!=WFC_INVALID_HANDLE)
1041 { /* no source is valid - the element "will not affect composition results" */
1042 source = WFC_Device_FindImageProvider(element->device,
1043 element->sourceHandle,
1049 DPRINT((" Source handle is valid, but source object now destroyed"));
1050 source=element->cachedSource;
1053 source=element->source;
1059 WFCint sourceWidth, sourceHeight;
1061 owfNativeStreamGetHeader(source->streamHandle,&sourceWidth, &sourceHeight,NULL,NULL,NULL);
1062 /* The <0 test is repeated in SetAttribfv ValidateSourceRectangle */
1063 if ((element->srcRect[0] < 0) ||
1064 (element->srcRect[1] < 0) ||
1065 (element->srcRect[2] < 0) ||
1066 (element->srcRect[3] < 0) ||
1067 (element->srcRect[0] + element->srcRect[2]) > sourceWidth ||
1068 (element->srcRect[1] + element->srcRect[3]) > sourceHeight)
1070 DPRINT((" Source rectangle out of bounds"));
1071 DPRINT((" (%f,%f,%f,%f), source size %dx%d",
1072 element->srcRect[0], element->srcRect[1],
1073 element->srcRect[2], element->srcRect[3],
1074 sourceWidth, sourceHeight));
1081 DPRINT((" No source pointers could be opened! Scene not safe!"));
1088 case WFC_ELEMENT_FORCE_32BIT:
1090 /* to keep compiler happy */
1098 #undef VALIDATE_SCALAR_F
1099 #undef VALIDATE_SCALAR_I
1102 /*---------------------------------------------------------------------------
1104 *----------------------------------------------------------------------------*/
1105 OWF_API_CALL WFCboolean
1106 WFC_Element_HasConflicts(WFC_ELEMENT* element)
1109 if (!WFC_Element_CheckAttribute(element, x)) \
1111 DPRINT(("Element %d: Conflict in attribute %08x", element->handle, x));\
1115 CHECK(WFC_ELEMENT_SOURCE);
1116 CHECK(WFC_ELEMENT_MASK);
1117 CHECK(WFC_ELEMENT_SOURCE_RECTANGLE);
1118 CHECK(WFC_ELEMENT_DESTINATION_RECTANGLE);
1119 CHECK(WFC_ELEMENT_SOURCE_FLIP);
1120 CHECK(WFC_ELEMENT_SOURCE_ROTATION);
1121 CHECK(WFC_ELEMENT_SOURCE_SCALE_FILTER);
1122 CHECK(WFC_ELEMENT_TRANSPARENCY_TYPES);
1123 CHECK(WFC_ELEMENT_GLOBAL_ALPHA);
1127 /* all ok, no conflicts */
1131 /*---------------------------------------------------------------------------
1133 *----------------------------------------------------------------------------*/
1134 OWF_API_CALL WFCboolean
1135 WFC_Element_AffectsCompositionResults(WFC_ELEMENT* element)
1137 if ( (element->transparencyTypes&WFC_TRANSPARENCY_ELEMENT_GLOBAL_ALPHA)
1138 && element->globalAlpha==OWF_FULLY_TRANSPARENT )
1142 if (element->sourceHandle==WFC_INVALID_HANDLE)
1146 if (element->dstRect[2]==0.0f || element->dstRect[3]==0.0f)
1150 if (element->srcRect[2]==0.0f || element->srcRect[3]==0.0f)
1157 /*---------------------------------------------------------------------------
1159 *----------------------------------------------------------------------------*/
1161 WFC_Element_Commit(WFC_ELEMENT* element)
1163 OWF_ASSERT(element);
1165 DPRINT(("WFC_Element_Commit(element = %d)\n", element->handle));
1167 /* replace source/mask ONLY if it has changed. without these checks,
1168 * both source and mask would be overwritten whenever one of them
1172 if (element->cachedSource != element->source)
1174 element->source = element->cachedSource;
1177 if (element->cachedMask != element->mask)
1179 element->mask = element->cachedMask;
1182 /* these must be reset now that the element is committed -- the only purpose
1183 * of these cached ones is to have source/mask object pointers in the
1184 * element so that source/mask can be safely deleted from the device even
1185 * if that particular image provider is set as source/mask for some element
1186 * that is not yet committed.
1189 DPRINT((" Prior to destroying cached objects:"));
1190 DPRINT((" R(cachedMask) = %d", REFCOUNT(element->cachedMask)));
1191 DPRINT((" R(cachedSource) = %d", REFCOUNT(element->cachedSource)));
1193 element->cachedSource = NULL;
1194 element->cachedMask = NULL;
1196 DPRINT((" new source = %d\n", element->source ?
1197 element->source->handle : 0));
1198 DPRINT((" new mask = %d\n", element->mask ?
1199 element->mask->handle : 0));