Add buf0, width, height fields to buf_2d

These are needed for the warping function in the global motion
experiment.

Change-Id: Iaab176d0c0b90f6b938e2bac48b24c07e87e3cd9
diff --git a/vp10/common/blockd.h b/vp10/common/blockd.h
index 0f8b972..6314e05 100644
--- a/vp10/common/blockd.h
+++ b/vp10/common/blockd.h
@@ -274,6 +274,9 @@
 
 struct buf_2d {
   uint8_t *buf;
+  uint8_t *buf0;
+  int width;
+  int height;
   int stride;
 };
 
diff --git a/vp10/common/reconinter.c b/vp10/common/reconinter.c
index d2fc980..8b3b5fc 100644
--- a/vp10/common/reconinter.c
+++ b/vp10/common/reconinter.c
@@ -1011,13 +1011,18 @@
                           int mi_row, int mi_col) {
   uint8_t *const buffers[MAX_MB_PLANE] = { src->y_buffer, src->u_buffer,
       src->v_buffer};
+  const int widths[MAX_MB_PLANE] = { src->y_crop_width, src->uv_crop_width,
+      src->uv_crop_width};
+  const int heights[MAX_MB_PLANE] = { src->y_crop_height, src->uv_crop_height,
+      src->uv_crop_height};
   const int strides[MAX_MB_PLANE] = { src->y_stride, src->uv_stride,
       src->uv_stride};
   int i;
 
   for (i = 0; i < MAX_MB_PLANE; ++i) {
     struct macroblockd_plane *const pd = &planes[i];
-    setup_pred_plane(&pd->dst, buffers[i], strides[i], mi_row, mi_col, NULL,
+    setup_pred_plane(&pd->dst, buffers[i], widths[i],
+                     heights[i], strides[i], mi_row, mi_col, NULL,
                      pd->subsampling_x, pd->subsampling_y);
   }
 }
@@ -1030,11 +1035,16 @@
     int i;
     uint8_t *const buffers[MAX_MB_PLANE] = { src->y_buffer, src->u_buffer,
         src->v_buffer};
+    const int widths[MAX_MB_PLANE] = { src->y_crop_width, src->uv_crop_width,
+        src->uv_crop_width};
+    const int heights[MAX_MB_PLANE] = { src->y_crop_height, src->uv_crop_height,
+        src->uv_crop_height};
     const int strides[MAX_MB_PLANE] = { src->y_stride, src->uv_stride,
         src->uv_stride};
     for (i = 0; i < MAX_MB_PLANE; ++i) {
       struct macroblockd_plane *const pd = &xd->plane[i];
-      setup_pred_plane(&pd->pre[idx], buffers[i], strides[i], mi_row, mi_col,
+      setup_pred_plane(&pd->pre[idx], buffers[i], widths[i],
+                       heights[i], strides[i], mi_row, mi_col,
                        sf, pd->subsampling_x, pd->subsampling_y);
     }
   }
@@ -1478,6 +1488,8 @@
                                           MACROBLOCKD *xd,
                                           int mi_row, int mi_col,
                                           uint8_t *tmp_buf[MAX_MB_PLANE],
+                                          int tmp_width[MAX_MB_PLANE],
+                                          int tmp_height[MAX_MB_PLANE],
                                           int tmp_stride[MAX_MB_PLANE]) {
   const TileInfo *const tile = &xd->tile;
   BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
@@ -1511,7 +1523,8 @@
     for (j = 0; j < MAX_MB_PLANE; ++j) {
       struct macroblockd_plane *const pd = &xd->plane[j];
       setup_pred_plane(&pd->dst,
-                       tmp_buf[j], tmp_stride[j],
+                       tmp_buf[j], tmp_width[j],
+                       tmp_height[j], tmp_stride[j],
                        0, i, NULL,
                        pd->subsampling_x, pd->subsampling_y);
     }
@@ -1580,6 +1593,8 @@
                                          MACROBLOCKD *xd,
                                          int mi_row, int mi_col,
                                          uint8_t *tmp_buf[MAX_MB_PLANE],
+                                         int tmp_width[MAX_MB_PLANE],
+                                         int tmp_height[MAX_MB_PLANE],
                                          int tmp_stride[MAX_MB_PLANE]) {
   const TileInfo *const tile = &xd->tile;
   BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
@@ -1613,7 +1628,8 @@
     for (j = 0; j < MAX_MB_PLANE; ++j) {
       struct macroblockd_plane *const pd = &xd->plane[j];
       setup_pred_plane(&pd->dst,
-                       tmp_buf[j], tmp_stride[j],
+                       tmp_buf[j], tmp_width[j],
+                       tmp_height[j], tmp_stride[j],
                        i, 0, NULL,
                        pd->subsampling_x, pd->subsampling_y);
     }
diff --git a/vp10/common/reconinter.h b/vp10/common/reconinter.h
index c32596e..cc808e7 100644
--- a/vp10/common/reconinter.h
+++ b/vp10/common/reconinter.h
@@ -439,13 +439,17 @@
 }
 
 static INLINE void setup_pred_plane(struct buf_2d *dst,
-                                    uint8_t *src, int stride,
+                                    uint8_t *src, int width,
+                                    int height, int stride,
                                     int mi_row, int mi_col,
                                     const struct scale_factors *scale,
                                     int subsampling_x, int subsampling_y) {
   const int x = (MI_SIZE * mi_col) >> subsampling_x;
   const int y = (MI_SIZE * mi_row) >> subsampling_y;
   dst->buf = src + scaled_buffer_offset(x, y, stride, scale);
+  dst->buf0 = src;
+  dst->width = width;
+  dst->height = height;
   dst->stride = stride;
 }
 
@@ -573,11 +577,15 @@
                                           MACROBLOCKD *xd,
                                           int mi_row, int mi_col,
                                           uint8_t *tmp_buf[MAX_MB_PLANE],
+                                          int tmp_width[MAX_MB_PLANE],
+                                          int tmp_height[MAX_MB_PLANE],
                                           int tmp_stride[MAX_MB_PLANE]);
 void vp10_build_prediction_by_left_preds(VP10_COMMON *cm,
                                          MACROBLOCKD *xd,
                                          int mi_row, int mi_col,
                                          uint8_t *tmp_buf[MAX_MB_PLANE],
+                                         int tmp_width[MAX_MB_PLANE],
+                                         int tmp_height[MAX_MB_PLANE],
                                          int tmp_stride[MAX_MB_PLANE]);
 #endif  // CONFIG_OBMC
 
diff --git a/vp10/decoder/decodeframe.c b/vp10/decoder/decodeframe.c
index 2f341b5..d4c7d5e 100644
--- a/vp10/decoder/decodeframe.c
+++ b/vp10/decoder/decodeframe.c
@@ -1355,6 +1355,10 @@
                       tmp_buf2[MAX_MB_PLANE * MAX_SB_SQUARE]);
 #endif  // CONFIG_VP9_HIGHBITDEPTH
       uint8_t *dst_buf1[MAX_MB_PLANE], *dst_buf2[MAX_MB_PLANE];
+      int dst_width1[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
+      int dst_width2[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
+      int dst_height1[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
+      int dst_height2[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
       int dst_stride1[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
       int dst_stride2[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
 
@@ -1380,9 +1384,11 @@
       }
 #endif  // CONFIG_VP9_HIGHBITDEPTH
       vp10_build_prediction_by_above_preds(cm, xd, mi_row, mi_col,
-                                           dst_buf1, dst_stride1);
+                                           dst_buf1, dst_width1,
+                                           dst_height1, dst_stride1);
       vp10_build_prediction_by_left_preds(cm, xd, mi_row, mi_col,
-                                          dst_buf2, dst_stride2);
+                                          dst_buf2, dst_width2,
+                                          dst_height2, dst_stride2);
       vp10_setup_dst_planes(xd->plane, get_frame_new_buffer(cm),
                             mi_row, mi_col);
       vp10_build_obmc_inter_prediction(cm, xd, mi_row, mi_col,
diff --git a/vp10/encoder/encodeframe.c b/vp10/encoder/encodeframe.c
index 287fb17..3119acf 100644
--- a/vp10/encoder/encodeframe.c
+++ b/vp10/encoder/encodeframe.c
@@ -1661,6 +1661,10 @@
 void vp10_setup_src_planes(MACROBLOCK *x, const YV12_BUFFER_CONFIG *src,
                           int mi_row, int mi_col) {
   uint8_t *const buffers[3] = {src->y_buffer, src->u_buffer, src->v_buffer };
+  const int widths[3] = {src->y_crop_width, src->uv_crop_width,
+                         src->uv_crop_width};
+  const int heights[3] = {src->y_crop_height, src->uv_crop_height,
+                          src->uv_crop_height};
   const int strides[3] = {src->y_stride, src->uv_stride, src->uv_stride };
   int i;
 
@@ -1668,7 +1672,8 @@
   x->e_mbd.cur_buf = src;
 
   for (i = 0; i < MAX_MB_PLANE; i++)
-    setup_pred_plane(&x->plane[i].src, buffers[i], strides[i], mi_row, mi_col,
+    setup_pred_plane(&x->plane[i].src, buffers[i], widths[i],
+                     heights[i], strides[i], mi_row, mi_col,
                      NULL, x->e_mbd.plane[i].subsampling_x,
                      x->e_mbd.plane[i].subsampling_y);
 }
@@ -5056,6 +5061,10 @@
       uint8_t *dst_buf1[MAX_MB_PLANE], *dst_buf2[MAX_MB_PLANE];
       int dst_stride1[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
       int dst_stride2[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
+      int dst_width1[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
+      int dst_width2[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
+      int dst_height1[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
+      int dst_height2[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
 
       assert(mbmi->sb_type >= BLOCK_8X8);
 
@@ -5080,9 +5089,10 @@
       }
 #endif  // CONFIG_VP9_HIGHBITDEPTH
       vp10_build_prediction_by_above_preds(cm, xd, mi_row, mi_col, dst_buf1,
+                                           dst_width1, dst_height1,
                                            dst_stride1);
       vp10_build_prediction_by_left_preds(cm, xd, mi_row, mi_col, dst_buf2,
-                                          dst_stride2);
+                                          dst_width2, dst_height2, dst_stride2);
       vp10_setup_dst_planes(xd->plane, get_frame_new_buffer(cm),
                             mi_row, mi_col);
       vp10_build_obmc_inter_prediction(cm, xd, mi_row, mi_col,
diff --git a/vp10/encoder/mcomp.c b/vp10/encoder/mcomp.c
index afbf3e9..5ecd5db 100644
--- a/vp10/encoder/mcomp.c
+++ b/vp10/encoder/mcomp.c
@@ -1784,7 +1784,7 @@
                                            int mi_row, int mi_col) {
   MACROBLOCKD *xd = &x->e_mbd;
   MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
-  struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0}};
+  struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0, 0, 0, 0}};
   DECLARE_ALIGNED(16, int16_t, hbuf[2 * MAX_SB_SIZE]);
   DECLARE_ALIGNED(16, int16_t, vbuf[2 * MAX_SB_SIZE]);
   DECLARE_ALIGNED(16, int16_t, src_hbuf[MAX_SB_SQUARE]);
@@ -2721,6 +2721,7 @@
     int ref = xd->mi[0]->mbmi.ref_frame[is_second];
     const YV12_BUFFER_CONFIG *upsampled_ref = get_upsampled_ref(cpi, ref);
     setup_pred_plane(&pd->pre[is_second], upsampled_ref->y_buffer,
+                     upsampled_ref->y_crop_width, upsampled_ref->y_crop_height,
                      upsampled_ref->y_stride, (mi_row << 3), (mi_col << 3),
                      NULL, pd->subsampling_x, pd->subsampling_y);
   }
@@ -3259,6 +3260,7 @@
     int ref = xd->mi[0]->mbmi.ref_frame[is_second];
     const YV12_BUFFER_CONFIG *upsampled_ref = get_upsampled_ref(cpi, ref);
     setup_pred_plane(&pd->pre[is_second], upsampled_ref->y_buffer,
+                     upsampled_ref->y_crop_width, upsampled_ref->y_crop_height,
                      upsampled_ref->y_stride, (mi_row << 3), (mi_col << 3),
                      NULL, pd->subsampling_x, pd->subsampling_y);
   }
diff --git a/vp10/encoder/rd.c b/vp10/encoder/rd.c
index 9e0a339..028d578 100644
--- a/vp10/encoder/rd.c
+++ b/vp10/encoder/rd.c
@@ -701,7 +701,10 @@
   dst[1].stride = dst[2].stride = src->uv_stride;
 
   for (i = 0; i < MAX_MB_PLANE; ++i) {
-    setup_pred_plane(dst + i, dst[i].buf, dst[i].stride, mi_row, mi_col,
+    setup_pred_plane(dst + i, dst[i].buf,
+                     i ? src->uv_crop_width : src->y_crop_width,
+                     i ? src->uv_crop_height : src->y_crop_height,
+                     dst[i].stride, mi_row, mi_col,
                      i ? scale_uv : scale,
                      xd->plane[i].subsampling_x, xd->plane[i].subsampling_y);
   }
diff --git a/vp10/encoder/rdopt.c b/vp10/encoder/rdopt.c
index 52dcf35..8177212 100644
--- a/vp10/encoder/rdopt.c
+++ b/vp10/encoder/rdopt.c
@@ -4831,6 +4831,8 @@
 
         // Set pred for Y plane
         setup_pred_plane(&pd->pre[0], upsampled_ref->y_buffer,
+                         upsampled_ref->y_crop_width,
+                         upsampled_ref->y_crop_height,
                          upsampled_ref->y_stride, (mi_row << 3), (mi_col << 3),
                          NULL, pd->subsampling_x, pd->subsampling_y);
 
@@ -5258,6 +5260,8 @@
 
               // Set pred for Y plane
               setup_pred_plane(&pd->pre[0], upsampled_ref->y_buffer,
+                               upsampled_ref->y_crop_width,
+                               upsampled_ref->y_crop_height,
                                upsampled_ref->y_stride,
                                (mi_row << 3), (mi_col << 3),
                                NULL, pd->subsampling_x, pd->subsampling_y);
@@ -5883,7 +5887,7 @@
   MACROBLOCKD *xd = &x->e_mbd;
   const VP10_COMMON *cm = &cpi->common;
   MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
-  struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0}};
+  struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0, 0, 0, 0}};
   int bestsme = INT_MAX;
   int step_param;
   int sadpb = x->sadperbit16;
@@ -6000,6 +6004,8 @@
 
       // Set pred for Y plane
       setup_pred_plane(&pd->pre[ref_idx], upsampled_ref->y_buffer,
+                       upsampled_ref->y_crop_width,
+                       upsampled_ref->y_crop_height,
                        upsampled_ref->y_stride, (mi_row << 3), (mi_col << 3),
                        NULL, pd->subsampling_x, pd->subsampling_y);
 
@@ -6064,7 +6070,7 @@
   MACROBLOCKD *xd = &x->e_mbd;
   const VP10_COMMON *cm = &cpi->common;
   MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
-  struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0}};
+  struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0, 0, 0, 0}};
   int bestsme = INT_MAX;
   int step_param;
   int sadpb = x->sadperbit16;
@@ -6202,7 +6208,7 @@
   MACROBLOCKD *xd = &x->e_mbd;
   const VP10_COMMON *cm = &cpi->common;
   MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
-  struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0}};
+  struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0, 0, 0, 0}};
   int bestsme = INT_MAX;
   int step_param;
   int sadpb = x->sadperbit16;
@@ -8489,6 +8495,10 @@
   DECLARE_ALIGNED(16, int32_t, weighted_src_buf[MAX_SB_SQUARE]);
   DECLARE_ALIGNED(16, int32_t, mask2d_buf[MAX_SB_SQUARE]);
   uint8_t *dst_buf1[MAX_MB_PLANE], *dst_buf2[MAX_MB_PLANE];
+  int dst_width1[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
+  int dst_width2[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
+  int dst_height1[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
+  int dst_height2[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
   int dst_stride1[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
   int dst_stride2[MAX_MB_PLANE] = {MAX_SB_SIZE, MAX_SB_SIZE, MAX_SB_SIZE};
 
@@ -8588,9 +8598,9 @@
 
 #if CONFIG_OBMC
   vp10_build_prediction_by_above_preds(cm, xd, mi_row, mi_col, dst_buf1,
-                                       dst_stride1);
+                                       dst_width1, dst_height1, dst_stride1);
   vp10_build_prediction_by_left_preds(cm, xd, mi_row, mi_col, dst_buf2,
-                                      dst_stride2);
+                                      dst_width2, dst_height2, dst_stride2);
   vp10_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
   calc_target_weighted_pred(cm, x, xd, mi_row, mi_col,
                             dst_buf1[0], dst_stride1[0],