Merging r48992 through r48995 from trunk into soc-2011-tomato
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 17 Jul 2012 10:46:32 +0000 (10:46 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 17 Jul 2012 10:46:32 +0000 (10:46 +0000)
1  2 
source/blender/blenkernel/intern/mask.c
source/blender/editors/space_node/node_draw.c
source/blender/windowmanager/CMakeLists.txt
source/blender/windowmanager/intern/wm_init_exit.c

index c92a811243206e8edc7598993b1a4c64ec4221b9,64902f0ee3eea34c850a8b44e2a277c4a158e3e5..d345ba581720bf4763b210f43e2d9f390e580071
  
  #include "raskter.h"
  
 +#ifdef USE_MANGO_MASK_CACHE_HACK
 +
 +#include "BLI_threads.h"
 +
 +typedef struct MaskRasterCache {
 +      float *buffer;
 +      int width, height;
 +      short do_aspect_correct;
 +      short do_mask_aa;
 +      short do_feather;
 +
 +      ListBase layers;
 +} MaskRasterCache;
 +#endif
 +
  static MaskSplinePoint *mask_spline_point_next(MaskSpline *spline, MaskSplinePoint *points_array, MaskSplinePoint *point)
  {
        if (point == &points_array[spline->tot_point - 1]) {
@@@ -524,6 -509,14 +524,14 @@@ static void spline_feather_collapse_inn
        int i;
        float min[2], max[2];
  
+       if (tot_feather_point < 4) {
+               /* self-intersection works only for quads at least,
+                * in other cases polygon can't be self-intersecting anyway
+                */
+               return;
+       }
        /* find min/max corners of mask to build buckets in that space */
        INIT_MINMAX2(min, max);
  
@@@ -1361,7 -1354,6 +1369,7 @@@ void BKE_mask_layer_free(MaskLayer *mas
        MEM_freeN(masklay);
  }
  
 +
  void BKE_mask_layer_free_list(ListBase *masklayers)
  {
        MaskLayer *masklay = masklayers->first;
  
                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)
  {
        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)
@@@ -2424,157 -2383,16 +2432,157 @@@ int BKE_mask_get_duration(Mask *mask
        return MAX2(1, mask->efra - mask->sfra);
  }
  
 +#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;
 +
 +      /* deform points can be NULL */
 +      if (point_a == NULL || point_b == NULL) {
 +              return ((point_a == NULL) && (point_b == NULL));
 +      }
 +
 +      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_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
 +      BLI_lock_thread(LOCK_CUSTOM1);
 +
 +      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);
 +
 +              BLI_unlock_thread(LOCK_CUSTOM1);
 +
 +              return;
 +      }
 +
 +      BLI_unlock_thread(LOCK_CUSTOM1);
 +#endif
 +
 +      buffer_tmp = MEM_mallocN(sizeof(float) * buffer_size, __func__);
  
        for (masklay = masklayers->first; masklay; masklay = masklay->next) {
                MaskSpline *spline;
                clamp_vn_vn(buffer, buffer_size);
        }
        MEM_freeN(buffer_tmp);
 +
 +#ifdef USE_MANGO_MASK_CACHE_HACK
 +      BLI_lock_thread(LOCK_CUSTOM1);
 +
 +      BKE_mask_raster_cache_free(mask);
 +
 +      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;
 +
 +      BLI_unlock_thread(LOCK_CUSTOM1);
 +#endif
  }
  
  #ifdef __PLX_RASKTER_MT__
@@@ -2801,5 -2595,5 +2809,5 @@@ void BKE_mask_rasterize(Mask *mask, in
                          const short do_aspect_correct, const short do_mask_aa,
                          const short do_feather)
  {
 -      BKE_mask_rasterize_layers(&mask->masklayers, width, height, buffer, do_aspect_correct, do_mask_aa, do_feather);
 +      BKE_mask_rasterize_layers(mask, &mask->masklayers, width, height, buffer, do_aspect_correct, do_mask_aa, do_feather);
  }
index 57ce303313be05914e820a8741e879cc4328c010,8c9f057efc1aa861bd930eea3890b4da5cf1a28c..4a0bbe7910068b0e6a89daedba37dc3f24786123
@@@ -721,11 -721,14 +721,14 @@@ static void node_draw_basis(const bCont
        if (node->flag & NODE_MUTED)
                UI_ThemeColorBlend(color_id, TH_REDALERT, 0.5f);
  
+ #ifdef WITH_COMPOSITOR
        if (ntree->type == NTREE_COMPOSIT && (snode->flag & SNODE_SHOW_HIGHLIGHT)) {
                if (COM_isHighlightedbNode(node)) {
                        UI_ThemeColorBlend(color_id, TH_ACTIVE, 0.5f);
                }
        }
+ #endif
        uiSetRoundBox(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT);
        uiRoundBox(rct->xmin, rct->ymax - NODE_DY, rct->xmax, rct->ymax, BASIS_RAD);
        
@@@ -885,11 -888,15 +888,15 @@@ static void node_draw_hidden(const bCon
        if (node->flag & NODE_MUTED)
                UI_ThemeColorBlend(color_id, TH_REDALERT, 0.5f);
  
+ #ifdef WITH_COMPOSITOR
        if (ntree->type == NTREE_COMPOSIT && (snode->flag & SNODE_SHOW_HIGHLIGHT)) {
                if (COM_isHighlightedbNode(node)) {
                        UI_ThemeColorBlend(color_id, TH_ACTIVE, 0.5f);
                }
        }
+ #else
+       (void)ntree;
+ #endif
        
        uiRoundBox(rct->xmin, rct->ymin, rct->xmax, rct->ymax, hiddenrad);
        
@@@ -1091,6 -1098,8 +1098,6 @@@ void drawnodespace(const bContext *C, A
  {
        View2DScrollers *scrollers;
        SpaceNode *snode = CTX_wm_space_node(C);
 -      Scene *scene = CTX_data_scene(C);
 -      int color_manage = scene->r.color_mgt_flag & R_COLOR_MANAGEMENT;
        bNodeLinkDrag *nldrag;
        LinkData *linkdata;
        
        UI_view2d_multi_grid_draw(v2d, 25.0f, 5, 2);
  
        /* backdrop */
 -      draw_nodespace_back_pix(ar, snode, color_manage);
 +      draw_nodespace_back_pix(C, ar, snode);
        
        /* nodes */
        snode_set_context(snode, CTX_data_scene(C));
                }
                
                node_update_nodetree(C, snode->nodetree, 0.0f, 0.0f);
+ #ifdef WITH_COMPOSITOR
                if (snode->nodetree->type == NTREE_COMPOSIT) {
                        COM_startReadHighlights();
                } 
+ #endif
                node_draw_nodetree(C, ar, snode, snode->nodetree);
                
                #if 0
index 8fbd345bfd231c1a36bfd68adb43bbf9f2423a8f,c5aaeeb81714fc495dc5ea90ceb800cab8929d40..f44ec2f5dc8b0fbd255ff455328c2b52c9297369
@@@ -53,7 -53,6 +53,7 @@@ set(INC_SY
  
  set(SRC
        intern/wm.c
 +      intern/wm_playanim.c
        intern/wm_cursors.c
        intern/wm_dragdrop.c
        intern/wm_draw.c
@@@ -144,4 -143,8 +144,8 @@@ if(WIN322
        )
  endif()
  
+ if(WITH_COMPOSITOR)
+       add_definitions(-DWITH_COMPOSITOR)
+ endif()
  blender_add_lib_nolist(bf_windowmanager "${SRC}" "${INC}" "${INC_SYS}")
index 5e3d5acfe868e6d75c4163097b73215531155e14,2098d87235723c8e96f2138986b12876aae6c029..18c9866da93a9f97dc8194d5e691bb9c56e31f17
  #include "BKE_depsgraph.h"
  #include "BKE_sound.h"
  
 +#include "IMB_colormanagement.h"
 +
  static void wm_init_reports(bContext *C)
  {
        BKE_reports_init(CTX_wm_reports(C), RPT_STORE);
@@@ -145,10 -143,6 +145,10 @@@ void WM_init(bContext *C, int argc, con
        
        BLF_init(11, U.dpi); /* Please update source/gamengine/GamePlayer/GPG_ghost.cpp if you change this */
        BLF_lang_init();
 +
 +      /* initialize color management stuff */
 +      IMB_colormanagement_init();
 +
        /* get the default database, plus a wm */
        WM_read_homefile(C, NULL, G.factory_startup);
  
  
        BLI_strncpy(G.lib, G.main->name, FILE_MAX);
  
+ #ifdef WITH_COMPOSITOR
        if (1) {
                extern void *COM_linker_hack;
                extern void *COM_execute;
                COM_linker_hack = COM_execute;
        }
+ #endif
  }
  
  void WM_init_splash(bContext *C)
@@@ -344,7 -340,6 +346,7 @@@ void WM_exit_ext(bContext *C, const sho
  
        sound_exit();
  
 +      IMB_colormanagement_exit();
  
        /* first wrap up running stuff, we assume only the active WM is running */
        /* modal handlers are on window level freed, others too? */