Fix a bug with global-motion + ref-mv

av1_find_mv_refs sets the ALL_ZERO flag when either (a) we don't have
enough candidate MVs, or (b) all candidate MVs are zero. With global
motion enabled, case (b) does not work as intended and causes two
problems: a significant quality decrease for foreman_cif.y4m, and
test failures in *CpuSpeedTest*Screencast*.

This patch skips check (b) when global motion is enabled, fixing
the above bugs.

Change-Id: I7461588cb02733563c1439f430b89190299a1b5d
diff --git a/av1/common/mvref_common.c b/av1/common/mvref_common.c
index ebe6260..31568de 100644
--- a/av1/common/mvref_common.c
+++ b/av1/common/mvref_common.c
@@ -743,7 +743,10 @@
                       find_mv_refs_sync sync, void *const data,
                       int16_t *mode_context) {
 #if CONFIG_REF_MV
-  int idx, all_zero = 1;
+#if !CONFIG_GLOBAL_MOTION
+  int idx;
+#endif
+  int all_zero = 1;
 #endif
 #if CONFIG_EXT_INTER
   av1_update_mv_context(xd, mi, ref_frame, mv_ref_list, -1, mi_row, mi_col,
@@ -766,6 +769,9 @@
   setup_ref_mv_list(cm, xd, ref_frame, ref_mv_count, ref_mv_stack, mv_ref_list,
                     -1, mi_row, mi_col, mode_context);
 
+#if CONFIG_GLOBAL_MOTION
+  if ((*ref_mv_count >= 2) || (ref_frame <= ALTREF_FRAME)) all_zero = 0;
+#else
   if (*ref_mv_count >= 2) {
     for (idx = 0; idx < AOMMIN(3, *ref_mv_count); ++idx) {
       if (ref_mv_stack[idx].this_mv.as_int != 0) all_zero = 0;
@@ -776,6 +782,7 @@
     for (idx = 0; idx < MAX_MV_REF_CANDIDATES; ++idx)
       if (mv_ref_list[idx].as_int != 0) all_zero = 0;
   }
+#endif
 
   if (all_zero) mode_context[ref_frame] |= (1 << ALL_ZERO_FLAG_OFFSET);
 #endif
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index b765d8c..5132271 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -9899,10 +9899,6 @@
           ) {
     int8_t ref_frame_type = av1_ref_frame_type(best_mbmode.ref_frame);
     int16_t mode_ctx = mbmi_ext->mode_context[ref_frame_type];
-#if !CONFIG_EXT_INTER
-    if (best_mbmode.ref_frame[1] > NONE)
-      mode_ctx &= (mbmi_ext->mode_context[best_mbmode.ref_frame[1]] | 0x00ff);
-#endif  // !CONFIG_EXT_INTER
 
     if (mode_ctx & (1 << ALL_ZERO_FLAG_OFFSET)) {
       best_mbmode.mode = ZEROMV;