src/hbcore/ovgeffects/hbvgmaskeffect.cpp
changeset 5 627c4a0fd0e7
parent 0 16d8024aca5e
child 7 923ff622b8b9
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
   139  * previously set mask pixmap or rectangle will not be effective anymore.
   139  * previously set mask pixmap or rectangle will not be effective anymore.
   140  */
   140  */
   141 void HbVgMaskEffect::setMaskCallback(MaskCallback callback, void *param)
   141 void HbVgMaskEffect::setMaskCallback(MaskCallback callback, void *param)
   142 {
   142 {
   143     Q_D(HbVgMaskEffect);
   143     Q_D(HbVgMaskEffect);
   144     if (d->maskCallback == callback)
   144     if (d->maskCallback == callback) {
   145         return;
   145         return;
       
   146     }
   146     clear();
   147     clear();
   147     d->maskCallback = callback;
   148     d->maskCallback = callback;
   148     d->maskCallbackParam = param;
   149     d->maskCallbackParam = param;
   149     updateEffect();
   150     updateEffect();
   150     emit maskCallbackChanged(callback);
   151     emit maskCallbackChanged(callback);
   174  * rectangle will not be effective anymore.
   175  * rectangle will not be effective anymore.
   175  */
   176  */
   176 void HbVgMaskEffect::setMaskRect(const QRectF &rect)
   177 void HbVgMaskEffect::setMaskRect(const QRectF &rect)
   177 {
   178 {
   178     Q_D(HbVgMaskEffect);
   179     Q_D(HbVgMaskEffect);
   179     if (rect == d->maskRect && !d->maskRectIsInDeviceCoords)
   180     if (rect == d->maskRect && !d->maskRectIsInDeviceCoords) {
   180         return;
   181         return;
       
   182     }
   181     clear();
   183     clear();
   182     d->maskRect = rect;
   184     d->maskRect = rect;
   183     d->maskRectIsInDeviceCoords = false;
   185     d->maskRectIsInDeviceCoords = false;
   184     updateEffect();
   186     updateEffect();
   185     emit maskRectChanged(rect);
   187     emit maskRectChanged(rect);
   191  * the source item will be clipped where it intersects with \a rect.
   193  * the source item will be clipped where it intersects with \a rect.
   192  */
   194  */
   193 void HbVgMaskEffect::setMaskDeviceRect(const QRectF &rect)
   195 void HbVgMaskEffect::setMaskDeviceRect(const QRectF &rect)
   194 {
   196 {
   195     Q_D(HbVgMaskEffect);
   197     Q_D(HbVgMaskEffect);
   196     if (rect == d->maskRect && d->maskRectIsInDeviceCoords)
   198     if (rect == d->maskRect && d->maskRectIsInDeviceCoords) {
   197         return;
   199         return;
       
   200     }
   198     clear();
   201     clear();
   199     d->maskRect = rect;
   202     d->maskRect = rect;
   200     d->maskRectIsInDeviceCoords = true;
   203     d->maskRectIsInDeviceCoords = true;
   201     updateEffect();
   204     updateEffect();
   202     emit maskRectChanged(rect);
   205     emit maskRectChanged(rect);
   231 {
   234 {
   232 #ifdef HB_EFFECTS_OPENVG
   235 #ifdef HB_EFFECTS_OPENVG
   233     Q_UNUSED(vgImage);
   236     Q_UNUSED(vgImage);
   234     Q_D(HbVgMaskEffect);
   237     Q_D(HbVgMaskEffect);
   235 
   238 
       
   239     if (!painter->paintEngine()) {
       
   240         return;
       
   241     }
       
   242 
   236     // Initialize scaledMask if the mask has changed or the size of the source
   243     // Initialize scaledMask if the mask has changed or the size of the source
   237     // is different than before.
   244     // is different than before.
   238     if (!d->mask.isNull()) {
   245     if (!d->mask.isNull()) {
   239         if (d->scaledMask.isNull())
   246         if (d->scaledMask.isNull()) {
   240             d->scaledMask = d->mask;
   247             d->scaledMask = d->mask;
       
   248         }
   241         // Scale only when really needed, i.e. when the size is different than
   249         // Scale only when really needed, i.e. when the size is different than
   242         // before (or there is a new mask).
   250         // before (or there is a new mask).
   243         if (d->scaledMask.size() != vgImageSize)
   251         if (d->scaledMask.size() != vgImageSize) {
   244             d->scaledMask = d->mask.scaled(vgImageSize);
   252             d->scaledMask = d->mask.scaled(vgImageSize);
       
   253         }
   245     }
   254     }
   246 
   255 
   247     vgSeti(VG_MASKING, VG_TRUE);
   256     vgSeti(VG_MASKING, VG_TRUE);
   248     QPaintDevice *pdev = painter->paintEngine()->paintDevice();
   257     QPaintDevice *pdev = painter->paintEngine()->paintDevice();
   249     // Set the mask for the entire surface to 1 (i.e. nothing is transparent).
   258     // Set the mask for the entire surface to 1 (i.e. nothing is transparent).
   274     } else if (!d->scaledMask.isNull()) {
   283     } else if (!d->scaledMask.isNull()) {
   275         maskPtr = &d->scaledMask;
   284         maskPtr = &d->scaledMask;
   276     } else if (d->maskCallback) {
   285     } else if (d->maskCallback) {
   277         // Invoke the callback but only if it has just been set or the size of
   286         // Invoke the callback but only if it has just been set or the size of
   278         // the source is different than before.
   287         // the source is different than before.
   279         if (d->callbackResult.isNull() || d->callbackResult.size() != vgImageSize)
   288         if (d->callbackResult.isNull() || d->callbackResult.size() != vgImageSize) {
   280             d->callbackResult = d->maskCallback(vgImageSize, d->maskCallbackParam);
   289             d->callbackResult = d->maskCallback(vgImageSize, d->maskCallbackParam);
       
   290         }
   281         maskPtr = &d->callbackResult;
   291         maskPtr = &d->callbackResult;
   282     }
   292     }
   283 
   293 
   284     if (maskPtr) {
   294     if (maskPtr) {
   285         int w = vgImageSize.width();
   295         int w = vgImageSize.width();