Merging r48545 through r48574 from trunk into soc-2011-tomato
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 4 Jul 2012 07:33:34 +0000 (07:33 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 4 Jul 2012 07:33:34 +0000 (07:33 +0000)
1  2 
source/blender/blenkernel/BKE_mask.h
source/blender/blenkernel/intern/mask.c
source/blender/compositor/operations/COM_MaskOperation.cpp
source/blender/editors/space_node/space_node.c
source/blender/makesdna/DNA_windowmanager_types.h
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_userdef.c
source/blender/render/intern/source/render_result.c
source/blender/windowmanager/intern/wm_window.c

index 0682b16536cf9d0860b37538afd88e2b62d2345f,ee7c13ba7cb4888682118fa47727e986434c98af..0eaa3b046ec57a6c30b146213842ea2c58440e81
@@@ -170,6 -175,11 +175,11 @@@ void BKE_mask_layer_shape_changed_remov
  
  /* rasterization */
  int BKE_mask_get_duration(struct Mask *mask);
 -void BKE_mask_rasterize_layers(struct ListBase *masklayers, int width, int height, float *buffer,
++void BKE_mask_rasterize_layers(struct Mask *mask, struct ListBase *masklayers, int width, int height, float *buffer,
+                                const short do_aspect_correct, const short do_mask_aa,
+                                const short do_feather);
  void BKE_mask_rasterize(struct Mask *mask, int width, int height, float *buffer,
                          const short do_aspect_correct, const short do_mask_aa,
                          const short do_feather);
index 611c0eb06be5e32f8465909d0839c09cd288418c,b400332db81c3fde41ba94e11cd016fe42c759bd..97977ca33208b83cc50bd1aa31f055eed7c2ac4e
@@@ -1080,50 -1116,23 +1128,57 @@@ void BKE_mask_layer_free(MaskLayer *mas
        MEM_freeN(masklay);
  }
  
++
+ void BKE_mask_layer_free_list(ListBase *masklayers)
+ {
+       MaskLayer *masklay = masklayers->first;
+       while (masklay) {
+               MaskLayer *masklay_next = masklay->next;
+               BLI_remlink(masklayers, masklay);
+               BKE_mask_layer_free(masklay);
+               masklay = masklay_next;
+       }
++
+ }
 +#ifdef USE_MANGO_MASK_CACHE_HACK
 +void BKE_mask_raster_cache_free(Mask *mask)
 +{
 +      MaskRasterCache *cache = mask->raster_cache;
 +
 +      if (cache) {
 +              MaskLayer *layer;
 +
 +              layer = cache->layers.first;
 +              while (layer) {
 +                      MaskLayer *layer_next = layer->next;
 +
 +                      BKE_mask_layer_free(layer);
 +                      layer = layer_next;
 +              }
 +
 +              MEM_freeN(cache->buffer);
 +              MEM_freeN(cache);
 +
 +              mask->raster_cache = NULL;
 +      }
 +}
 +#endif
 +
  void BKE_mask_free(Mask *mask)
  {
-       MaskLayer *masklay = mask->masklayers.first;
-       while (masklay) {
-               MaskLayer *next_masklay = masklay->next;
-               BLI_remlink(&mask->masklayers, masklay);
-               BKE_mask_layer_free(masklay);
-               masklay = next_masklay;
-       }
+       BKE_mask_layer_free_list(&mask->masklayers);
 +
 +#ifdef USE_MANGO_MASK_CACHE_HACK
 +      if (mask->raster_cache) {
 +              BKE_mask_raster_cache_free(mask);
 +
 +              mask->raster_cache = NULL;
 +      }
 +#endif
  }
  
  void BKE_mask_unlink(Main *bmain, Mask *mask)
@@@ -2136,211 -2145,18 +2191,149 @@@ int BKE_mask_get_duration(Mask *mask
        return MAX2(1, mask->efra - mask->sfra);
  }
  
- static void mask_splines_duplicate(ListBase *base_new, ListBase *base)
- {
-       MaskSpline *spline;
-       for (spline = base->first; spline; spline = spline->next) {
-               MaskSpline *spline_new = BKE_mask_spline_copy(spline);
-               int i;
-               if (spline->points_deform) {
-                       spline_new->points_deform = MEM_dupallocN(spline->points_deform);
-                       for (i = 0; i < spline->tot_point; i++) {
-                               MaskSplinePoint *point_deform = &spline_new->points_deform[i];
-                               if (point_deform->uw)
-                                       point_deform->uw = MEM_dupallocN(point_deform->uw);
-                       }
-               }
-               BLI_addtail(base_new, spline_new);
-       }
- }
- static MaskLayer *mask_layer_duplicate(MaskLayer *layer)
- {
-       MaskLayer *layer_new;
-       layer_new = MEM_callocN(sizeof(MaskLayer), "new mask layer");
-       BLI_strncpy(layer_new->name, layer->name, sizeof(layer_new->name));
-       layer_new->alpha = layer->alpha;
-       layer_new->blend = layer->blend;
-       layer_new->blend_flag = layer->blend_flag;
-       layer_new->flag = layer->flag;
-       layer_new->restrictflag = layer->restrictflag;
-       mask_splines_duplicate(&layer_new->splines, &layer->splines);
-       return layer_new;
- }
- static void mask_layers_duplicate(ListBase *base_new, ListBase *base)
- {
-       MaskLayer *layer;
-       for (layer = base->first; layer; layer = layer->next) {
-               MaskLayer *layer_new = mask_layer_duplicate(layer);
-               BLI_addtail(base_new, layer_new);
-       }
- }
 +#ifdef USE_MANGO_MASK_CACHE_HACK
 +static int mask_point_compare(MaskSplinePoint *point_a, MaskSplinePoint *point_b)
 +{
 +      if (point_a->tot_uw != point_b->tot_uw) {
 +              return FALSE;
 +      }
 +
 +      if (memcmp(&point_a->bezt, &point_b->bezt, sizeof(BezTriple))) {
 +              return FALSE;
 +      }
 +
 +      if (memcmp(&point_a->uw, &point_b->uw, 2 * point_a->tot_uw * sizeof(float))) {
 +              return FALSE;
 +      }
 +
 +      return TRUE;
 +}
 +
 +static int mask_points_compare(MaskSplinePoint *points_a, MaskSplinePoint *points_b, int tot_point)
 +{
 +      MaskSplinePoint *point_a = points_a;
 +      MaskSplinePoint *point_b = points_b;
 +      int a = tot_point;
 +
 +      while (a--) {
 +              if (!mask_point_compare(point_a, point_b)) {
 +                      return FALSE;
 +              }
 +
 +              point_a++;
 +              point_b++;
 +      }
 +
 +      return TRUE;
 +}
 +
 +static int mask_spline_compare(MaskSpline *spline_a, MaskSpline *spline_b)
 +{
 +      if (spline_a->flag != spline_b->flag ||
 +          spline_a->tot_point != spline_b->tot_point ||
 +          spline_a->weight_interp != spline_b->weight_interp)
 +      {
 +              return FALSE;
 +      }
 +
 +      if (!mask_points_compare(spline_a->points, spline_b->points, spline_a->tot_point)) {
 +              return FALSE;
 +      }
 +
 +      return mask_points_compare(spline_a->points_deform, spline_b->points_deform, spline_a->tot_point);
 +}
 +
 +static int mask_splines_compare(ListBase *base_a, ListBase *base_b)
 +{
 +      MaskSpline *spline_a, *spline_b;
 +
 +      for (spline_a = base_a->first, spline_b = base_b->first;
 +           spline_a && spline_b;
 +           spline_a = spline_a->next, spline_b = spline_b->next)
 +      {
 +              if (!mask_spline_compare(spline_a, spline_b)) {
 +                      return FALSE;
 +              }
 +      }
 +
 +      if (spline_a || spline_b)
 +              return FALSE;
 +
 +      return TRUE;
 +}
 +
 +static int mask_layer_compare(MaskLayer *layer_a, MaskLayer *layer_b)
 +{
 +      if (layer_a->alpha != layer_b->alpha ||
 +          layer_a->blend != layer_b->blend ||
 +          layer_a->blend_flag != layer_b->blend_flag ||
 +          layer_a->flag != layer_b->flag ||
 +          layer_a->restrictflag != layer_b->restrictflag)
 +      {
 +              return FALSE;
 +      }
 +
 +      if (strcmp(layer_a->name, layer_b->name))
 +              return FALSE;
 +
 +      return mask_splines_compare(&layer_a->splines, &layer_b->splines);
 +}
 +
 +static int mask_layers_compare(ListBase *base_a, ListBase *base_b)
 +{
 +      MaskLayer *layer_a, *layer_b;
 +
 +      for (layer_a = base_a->first, layer_b = base_b->first;
 +           layer_a && layer_b;
 +           layer_a = layer_a->next, layer_b = layer_b->next)
 +      {
 +              if (!mask_layer_compare(layer_a, layer_b)) {
 +                      return FALSE;
 +              }
 +      }
 +
 +      if (layer_a || layer_b)
 +              return FALSE;
 +
 +      return TRUE;
 +}
 +#endif
 +
  /* rasterization */
- void BKE_mask_rasterize(Mask *mask, int width, int height, float *buffer,
-                         const short do_aspect_correct, const short do_mask_aa,
-                         const short do_feather)
 -void BKE_mask_rasterize_layers(ListBase *masklayers, int width, int height, float *buffer,
++
++/* XXX: mask is only passed here to access rasterization cache
++ *      this MUST be removed as soon as tile-based rasterization would be here
++ */
++void BKE_mask_rasterize_layers(Mask *mask, ListBase *masklayers, int width, int height, float *buffer,
+                                const short do_aspect_correct, const short do_mask_aa,
+                                const short do_feather)
  {
 +      MaskRasterCache *cache = mask->raster_cache;
        MaskLayer *masklay;
  
        /* temp blending buffer */
        const int buffer_size = width * height;
 -      float *buffer_tmp = MEM_mallocN(sizeof(float) * buffer_size, __func__);
 +      float *buffer_tmp;
 +
 +#ifdef USE_MANGO_MASK_CACHE_HACK
 +      if (cache &&
 +          cache->width == width &&
 +          cache->height == height &&
 +          cache->do_aspect_correct == do_aspect_correct &&
 +          cache->do_mask_aa == do_mask_aa &&
 +          cache->do_feather == do_feather &&
 +          mask_layers_compare(&cache->layers, &mask->masklayers))
 +      {
 +              memcpy(buffer, cache->buffer, sizeof(float) * buffer_size);
 +              return;
 +      }
 +
 +      BKE_mask_raster_cache_free(mask);
-       cache = MEM_callocN(sizeof(MaskRasterCache), "mask raster cache");
-       /* duplicate first to be sure rasterization happens with the same
-        * configuration as is being cached, otherwise could be threading issues
-        * with transformation code -- in some circumstances deformation could
-        * happen at the same time as deformating spline is rasterizing
-        */
-       mask_layers_duplicate(&cache->layers, &mask->masklayers);
 +#endif
 +
 +      buffer_tmp = MEM_mallocN(sizeof(float) * buffer_size, __func__);
  
- #ifdef USE_MANGO_MASK_CACHE_HACK
-       for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
- #else
-       for (masklay = cache->layers.first; masklay; masklay = masklay->next) {
- #endif
+       for (masklay = masklayers->first; masklay; masklay = masklay->next) {
                MaskSpline *spline;
                float alpha;
  
        }
  
        MEM_freeN(buffer_tmp);
 +
 +#ifdef USE_MANGO_MASK_CACHE_HACK
++      cache = MEM_callocN(sizeof(MaskRasterCache), "mask raster cache");
++
 +      cache->buffer = MEM_mallocN(sizeof(float) * buffer_size, "mask raster cache buffer");
++
++      BKE_mask_layer_copy_list(&cache->layers, masklayers);
++
 +      memcpy(cache->buffer, buffer, sizeof(float) * buffer_size);
 +
 +      cache->width = width;
 +      cache->height = height;
 +      cache->do_aspect_correct = do_aspect_correct;
 +      cache->do_mask_aa = do_mask_aa;
 +      cache->do_feather = do_feather;
 +
 +      mask->raster_cache = cache;
 +#endif
  }
 -      BKE_mask_rasterize_layers(&mask->masklayers, width, height, buffer, do_aspect_correct, do_mask_aa, do_feather);
+ void BKE_mask_rasterize(Mask *mask, int width, int height, float *buffer,
+                         const short do_aspect_correct, const short do_mask_aa,
+                         const short do_feather)
+ {
++      BKE_mask_rasterize_layers(mask, &mask->masklayers, width, height, buffer, do_aspect_correct, do_mask_aa, do_feather);
+ }
index aa16ecf5d098513f29969b70d67cdb8ed31e9d03,2b45cd53fd5dad01d17a4eb257955e0217329684..0d57be8472004d4f403d04329db4e692b956a1f7
@@@ -75,7 -83,10 +83,10 @@@ void *MaskOperation::initializeTileData
                float *buffer;
  
                buffer = (float *)MEM_callocN(sizeof(float) * width * height, "rasterized mask");
-               BKE_mask_rasterize(this->m_mask, width, height, buffer, TRUE, this->m_do_smooth, this->m_do_feather);
 -              BKE_mask_rasterize_layers(&this->m_maskLayers, width, height, buffer, TRUE,
++              BKE_mask_rasterize_layers(this->m_mask, &this->m_maskLayers, width, height, buffer, TRUE,
+                                         this->m_do_smooth, this->m_do_feather);
                if (this->m_do_smooth) {
                        PLX_antialias_buffer(buffer, width, height);
                }