Remove backing up and restoring of mv_limits in fullpel search

With the increased modularization of mcomp, a copy of mv_limits is
passed directly to fullpel search functions. Therefore there is no
longer a need to restore the mv_limits in MACROBLOCK after the mv
search.

BUG=aomedia:2594

Change-Id: I8b00143b4bbb6d2968433ff193bd9068634fcbde
diff --git a/av1/encoder/motion_search_facade.c b/av1/encoder/motion_search_facade.c
index ea71088..f5bff36 100644
--- a/av1/encoder/motion_search_facade.c
+++ b/av1/encoder/motion_search_facade.c
@@ -29,7 +29,6 @@
   struct buf_2d backup_yv12[MAX_MB_PLANE] = { { 0, 0, 0, 0, 0 } };
   int bestsme = INT_MAX;
   const int ref = mbmi->ref_frame[ref_idx];
-  FullMvLimits tmp_mv_limits = x->mv_limits;
   const YV12_BUFFER_CONFIG *scaled_ref_frame =
       av1_get_scaled_ref_frame(cpi, ref);
   const int mi_row = xd->mi_row;
@@ -114,10 +113,6 @@
     }
   }
 
-  // Note: MV limits are modified here. Always restore the original values
-  // after full-pixel motion search.
-  av1_set_mv_search_range(&x->mv_limits, &ref_mv);
-
   FULLPEL_MV start_mv;
   if (mbmi->motion_mode != SIMPLE_TRANSLATION)
     start_mv = get_fullmv_from_mv(&mbmi->mv[0].as_mv);
@@ -153,8 +148,6 @@
     }
   }
 
-  x->mv_limits = tmp_mv_limits;
-
   // Terminate search with the current ref_idx if we have already encountered
   // another ref_mv in the drl such that:
   //  1. The other drl has the same fullpel_mv during the SIMPLE_TRANSLATION
@@ -692,7 +685,6 @@
   // ref_mv is used to calculate the cost of the motion vector
   const MV ref_mv = kZeroMv;
   const int step_param = cpi->mv_step_param;
-  const FullMvLimits tmp_mv_limits = x->mv_limits;
   const search_site_config *src_search_sites = &cpi->ss_cfg[SS_CFG_SRC];
   int cost_list[5];
   const int ref_idx = 0;
@@ -711,15 +703,10 @@
   av1_make_default_fullpel_ms_params(&full_ms_params, cpi, x, bsize, &ref_mv,
                                      src_search_sites);
 
-  // This overwrites the mv_limits so we will need to restore it later.
-  av1_set_mv_search_range(&x->mv_limits, &ref_mv);
   var = av1_full_pixel_search(start_mv, &full_ms_params, step_param,
                               cond_cost_list(cpi, cost_list),
                               &x->best_mv.as_fullmv, NULL);
 
-  // Restore
-  x->mv_limits = tmp_mv_limits;
-
   const int use_subpel_search =
       var < INT_MAX && !cpi->common.features.cur_frame_force_integer_mv &&
       use_subpixel;
diff --git a/av1/encoder/nonrd_pickmode.c b/av1/encoder/nonrd_pickmode.c
index 479304f..007291d 100644
--- a/av1/encoder/nonrd_pickmode.c
+++ b/av1/encoder/nonrd_pickmode.c
@@ -130,7 +130,6 @@
   const MV ref_mv = av1_get_ref_mv(x, mi->ref_mv_idx).as_mv;
   MV center_mv;
   int dis;
-  const FullMvLimits tmp_mv_limits = x->mv_limits;
   int rv = 0;
   int cost_list[5];
   int search_subpel = 1;
@@ -146,7 +145,6 @@
     av1_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL,
                          num_planes);
   }
-  av1_set_mv_search_range(&x->mv_limits, &ref_mv);
 
   start_mv = get_fullmv_from_mv(&ref_mv);
 
@@ -164,7 +162,6 @@
                         cond_cost_list(cpi, cost_list), &x->best_mv.as_fullmv,
                         NULL);
 
-  x->mv_limits = tmp_mv_limits;
   *tmp_mv = x->best_mv;
   // calculate the bit cost on motion vector
   MV mvp_full = get_mv_from_fullmv(&tmp_mv->as_fullmv);
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index d7f2c6d..25c1ac4 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -2696,62 +2696,68 @@
   uint8_t best_tx_type_map[MAX_MIB_SIZE * MAX_MIB_SIZE];
   av1_copy_array(best_tx_type_map, xd->tx_type_map, ctx->num_4x4_blk);
 
+  FULLPEL_MOTION_SEARCH_PARAMS fullms_params;
+  const search_site_config *lookahead_search_sites =
+      &cpi->ss_cfg[SS_CFG_LOOKAHEAD];
+  av1_make_default_fullpel_ms_params(&fullms_params, cpi, x, bsize,
+                                     &dv_ref.as_mv, lookahead_search_sites);
+  fullms_params.is_intra_mode = 1;
+
   for (enum IntrabcMotionDirection dir = IBC_MOTION_ABOVE;
        dir < IBC_MOTION_DIRECTIONS; ++dir) {
-    const FullMvLimits tmp_mv_limits = x->mv_limits;
     switch (dir) {
       case IBC_MOTION_ABOVE:
-        x->mv_limits.col_min = (tile->mi_col_start - mi_col) * MI_SIZE;
-        x->mv_limits.col_max = (tile->mi_col_end - mi_col) * MI_SIZE - w;
-        x->mv_limits.row_min = (tile->mi_row_start - mi_row) * MI_SIZE;
-        x->mv_limits.row_max =
+        fullms_params.mv_limits.col_min =
+            (tile->mi_col_start - mi_col) * MI_SIZE;
+        fullms_params.mv_limits.col_max =
+            (tile->mi_col_end - mi_col) * MI_SIZE - w;
+        fullms_params.mv_limits.row_min =
+            (tile->mi_row_start - mi_row) * MI_SIZE;
+        fullms_params.mv_limits.row_max =
             (sb_row * cm->seq_params.mib_size - mi_row) * MI_SIZE - h;
         break;
       case IBC_MOTION_LEFT:
-        x->mv_limits.col_min = (tile->mi_col_start - mi_col) * MI_SIZE;
-        x->mv_limits.col_max =
+        fullms_params.mv_limits.col_min =
+            (tile->mi_col_start - mi_col) * MI_SIZE;
+        fullms_params.mv_limits.col_max =
             (sb_col * cm->seq_params.mib_size - mi_col) * MI_SIZE - w;
         // TODO(aconverse@google.com): Minimize the overlap between above and
         // left areas.
-        x->mv_limits.row_min = (tile->mi_row_start - mi_row) * MI_SIZE;
+        fullms_params.mv_limits.row_min =
+            (tile->mi_row_start - mi_row) * MI_SIZE;
         int bottom_coded_mi_edge =
             AOMMIN((sb_row + 1) * cm->seq_params.mib_size, tile->mi_row_end);
-        x->mv_limits.row_max = (bottom_coded_mi_edge - mi_row) * MI_SIZE - h;
+        fullms_params.mv_limits.row_max =
+            (bottom_coded_mi_edge - mi_row) * MI_SIZE - h;
         break;
       default: assert(0);
     }
-    assert(x->mv_limits.col_min >= tmp_mv_limits.col_min);
-    assert(x->mv_limits.col_max <= tmp_mv_limits.col_max);
-    assert(x->mv_limits.row_min >= tmp_mv_limits.row_min);
-    assert(x->mv_limits.row_max <= tmp_mv_limits.row_max);
-    av1_set_mv_search_range(&x->mv_limits, &dv_ref.as_mv);
+    assert(fullms_params.mv_limits.col_min >= fullms_params.mv_limits.col_min);
+    assert(fullms_params.mv_limits.col_max <= fullms_params.mv_limits.col_max);
+    assert(fullms_params.mv_limits.row_min >= fullms_params.mv_limits.row_min);
+    assert(fullms_params.mv_limits.row_max <= fullms_params.mv_limits.row_max);
 
-    if (x->mv_limits.col_max < x->mv_limits.col_min ||
-        x->mv_limits.row_max < x->mv_limits.row_min) {
-      x->mv_limits = tmp_mv_limits;
+    av1_set_mv_search_range(&fullms_params.mv_limits, &dv_ref.as_mv);
+
+    if (fullms_params.mv_limits.col_max < fullms_params.mv_limits.col_min ||
+        fullms_params.mv_limits.row_max < fullms_params.mv_limits.row_min) {
       continue;
     }
 
     const int step_param = cpi->mv_step_param;
     const FULLPEL_MV start_mv = get_fullmv_from_mv(&dv_ref.as_mv);
-    const search_site_config *lookahead_search_sites =
-        &cpi->ss_cfg[SS_CFG_LOOKAHEAD];
-    FULLPEL_MOTION_SEARCH_PARAMS full_ms_params;
-    av1_make_default_fullpel_ms_params(&full_ms_params, cpi, x, bsize,
-                                       &dv_ref.as_mv, lookahead_search_sites);
-    full_ms_params.is_intra_mode = 1;
     int cost_list[5];
 
-    int bestsme = av1_full_pixel_search(start_mv, &full_ms_params, step_param,
+    int bestsme = av1_full_pixel_search(start_mv, &fullms_params, step_param,
                                         cond_cost_list(cpi, cost_list),
                                         &x->best_mv.as_fullmv, NULL);
     av1_intrabc_hash_search(cpi, x, bsize, &dv_ref.as_mv, &bestsme,
                             &x->best_mv.as_fullmv);
 
-    x->mv_limits = tmp_mv_limits;
     if (bestsme == INT_MAX) continue;
     const MV dv = get_mv_from_fullmv(&x->best_mv.as_fullmv);
-    if (!av1_is_fullmv_in_range(&x->mv_limits, get_fullmv_from_mv(&dv)))
+    if (!av1_is_fullmv_in_range(&fullms_params.mv_limits,
+                                get_fullmv_from_mv(&dv)))
       continue;
     if (!av1_is_dv_valid(dv, cm, xd, mi_row, mi_col, bsize,
                          cm->seq_params.mib_size_log2))
diff --git a/av1/encoder/temporal_filter.c b/av1/encoder/temporal_filter.c
index 6dd6f91..af5ccdb 100644
--- a/av1/encoder/temporal_filter.c
+++ b/av1/encoder/temporal_filter.c
@@ -78,7 +78,6 @@
   MACROBLOCKD *const mbd = &mb->e_mbd;
   const struct buf_2d ori_src_buf = mb->plane[0].src;
   const struct buf_2d ori_pre_buf = mbd->plane[0].pre[0];
-  const FullMvLimits ori_mv_limits = mb->mv_limits;
   const MV_COST_TYPE ori_mv_cost_type = mb->mv_cost_type;
 
   // Parameters used for motion search.
@@ -111,7 +110,6 @@
   mb->plane[0].src.stride = y_stride;
   mbd->plane[0].pre[0].buf = ref_frame->y_buffer + y_offset;
   mbd->plane[0].pre[0].stride = y_stride;
-  av1_set_mv_search_range(&mb->mv_limits, &baseline_mv);
   // Unused intermediate results for motion search.
   unsigned int sse;
   int distortion;
@@ -167,7 +165,6 @@
         const int offset = i * y_stride + j;
         mb->plane[0].src.buf = frame_to_filter->y_buffer + y_offset + offset;
         mbd->plane[0].pre[0].buf = ref_frame->y_buffer + y_offset + offset;
-        av1_set_mv_search_range(&mb->mv_limits, &baseline_mv);
         mb->mv_cost_type = mv_cost_type;
 
         av1_make_default_fullpel_ms_params(
@@ -199,7 +196,6 @@
   // Restore input state.
   mb->plane[0].src = ori_src_buf;
   mbd->plane[0].pre[0] = ori_pre_buf;
-  mb->mv_limits = ori_mv_limits;
   mb->mv_cost_type = ori_mv_cost_type;
 
   return block_error;
diff --git a/av1/encoder/tpl_model.c b/av1/encoder/tpl_model.c
index 60facf8..ee0c496 100644
--- a/av1/encoder/tpl_model.c
+++ b/av1/encoder/tpl_model.c
@@ -131,7 +131,6 @@
   int distortion;
   uint32_t sse;
   int cost_list[5];
-  const FullMvLimits tmp_mv_limits = x->mv_limits;
   FULLPEL_MV start_mv = get_fullmv_from_mv(&center_mv);
 
   // Setup frame pointers
@@ -143,8 +142,6 @@
   step_param = tpl_sf->reduce_first_step_size;
   step_param = AOMMIN(step_param, MAX_MVSEARCH_STEPS - 2);
 
-  av1_set_mv_search_range(&x->mv_limits, &center_mv);
-
   search_site_config *ss_cfg = &cpi->ss_cfg[SS_CFG_SRC];
   if (ss_cfg->stride != stride_ref) ss_cfg = &cpi->ss_cfg[SS_CFG_LOOKAHEAD];
 
@@ -158,9 +155,6 @@
                         cond_cost_list(cpi, cost_list), &x->best_mv.as_fullmv,
                         NULL);
 
-  /* restore UMV window */
-  x->mv_limits = tmp_mv_limits;
-
   const uint8_t *second_pred = NULL;
   const uint8_t *mask = NULL;
   const int mask_stride = 0;