[NORMATIVE-SYNTAX, intrabc] Disallow intrabc+superres

Superres should not be used together with intrabc, for the same
reasons why the other loop filters are disabled when intrabc is
used. However, we actually read superres information first,
so the simplest change is to only read allow_intrabc if superres is off.

BUG=aomedia:1384

Change-Id: I55c4c8ace72ab3fac9417da5cf803883be7efb84
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 73aaf12..6a168e9 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -2877,7 +2877,13 @@
       pbi->need_resync = 0;
     }
 #if CONFIG_INTRABC
-    if (cm->allow_screen_content_tools) cm->allow_intrabc = aom_rb_read_bit(rb);
+#if CONFIG_HORZONLY_FRAME_SUPERRES
+    if (cm->allow_screen_content_tools &&
+        (av1_superres_unscaled(cm) || !NO_FILTER_FOR_IBC))
+#else
+    if (cm->allow_screen_content_tools)
+#endif  // CONFIG_HORZONLY_FRAME_SUPERRES
+      cm->allow_intrabc = aom_rb_read_bit(rb);
 #endif  // CONFIG_INTRABC
     cm->use_prev_frame_mvs = 0;
   } else {
@@ -2927,9 +2933,14 @@
         pbi->need_resync = 0;
       }
 #if CONFIG_INTRABC
+#if CONFIG_HORZONLY_FRAME_SUPERRES
+      if (cm->allow_screen_content_tools &&
+          (av1_superres_unscaled(cm) || !NO_FILTER_FOR_IBC))
+#else
       if (cm->allow_screen_content_tools)
+#endif  // CONFIG_HORZONLY_FRAME_SUPERRES
         cm->allow_intrabc = aom_rb_read_bit(rb);
-#endif                                  // CONFIG_INTRABC
+#endif  // CONFIG_INTRABC                               // CONFIG_INTRABC
     } else if (pbi->need_resync != 1) { /* Skip if need resync */
 #if CONFIG_OBU
       pbi->refresh_frame_flags = (cm->frame_type == S_FRAME)
@@ -3582,35 +3593,37 @@
     return;
   }
 
+#if CONFIG_INTRABC
+  if (!(cm->allow_intrabc && NO_FILTER_FOR_IBC)) {
+#endif
 #if CONFIG_LOOP_RESTORATION
-  if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE ||
-      cm->rst_info[1].frame_restoration_type != RESTORE_NONE ||
-      cm->rst_info[2].frame_restoration_type != RESTORE_NONE) {
-    av1_loop_restoration_save_boundary_lines(&pbi->cur_buf->buf, cm, 0);
-  }
+    if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE ||
+        cm->rst_info[1].frame_restoration_type != RESTORE_NONE ||
+        cm->rst_info[2].frame_restoration_type != RESTORE_NONE) {
+      av1_loop_restoration_save_boundary_lines(&pbi->cur_buf->buf, cm, 0);
+    }
 #endif  // CONFIG_LOOP_RESTORATION
 
-  if (!cm->skip_loop_filter &&
-#if CONFIG_INTRABC
-      !(cm->allow_intrabc && NO_FILTER_FOR_IBC) &&
-#endif  // CONFIG_INTRABC
-      !cm->all_lossless &&
-      (cm->cdef_bits || cm->cdef_strengths[0] || cm->cdef_uv_strengths[0])) {
-    av1_cdef_frame(&pbi->cur_buf->buf, cm, &pbi->mb);
-  }
+    if (!cm->skip_loop_filter && !cm->all_lossless &&
+        (cm->cdef_bits || cm->cdef_strengths[0] || cm->cdef_uv_strengths[0])) {
+      av1_cdef_frame(&pbi->cur_buf->buf, cm, &pbi->mb);
+    }
 
 #if CONFIG_HORZONLY_FRAME_SUPERRES
-  superres_post_decode(pbi);
+    superres_post_decode(pbi);
 #endif  // CONFIG_HORZONLY_FRAME_SUPERRES
 
 #if CONFIG_LOOP_RESTORATION
-  if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE ||
-      cm->rst_info[1].frame_restoration_type != RESTORE_NONE ||
-      cm->rst_info[2].frame_restoration_type != RESTORE_NONE) {
-    av1_loop_restoration_save_boundary_lines(&pbi->cur_buf->buf, cm, 1);
-    av1_loop_restoration_filter_frame((YV12_BUFFER_CONFIG *)xd->cur_buf, cm);
-  }
+    if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE ||
+        cm->rst_info[1].frame_restoration_type != RESTORE_NONE ||
+        cm->rst_info[2].frame_restoration_type != RESTORE_NONE) {
+      av1_loop_restoration_save_boundary_lines(&pbi->cur_buf->buf, cm, 1);
+      av1_loop_restoration_filter_frame((YV12_BUFFER_CONFIG *)xd->cur_buf, cm);
+    }
 #endif  // CONFIG_LOOP_RESTORATION
+#if CONFIG_INTRABC
+  }
+#endif
 
   if (!xd->corrupted) {
     if (cm->refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) {
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index cf7ff27..b78e95c 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -3745,7 +3745,15 @@
     write_frame_size(cm, wb);
 #endif
 #if CONFIG_INTRABC
-    if (cm->allow_screen_content_tools) aom_wb_write_bit(wb, cm->allow_intrabc);
+#if CONFIG_HORZONLY_FRAME_SUPERRES
+    assert(av1_superres_unscaled(cm) ||
+           !(cm->allow_intrabc && NO_FILTER_FOR_IBC));
+    if (cm->allow_screen_content_tools &&
+        (av1_superres_unscaled(cm) || !NO_FILTER_FOR_IBC))
+#else
+    if (cm->allow_screen_content_tools)
+#endif
+      aom_wb_write_bit(wb, cm->allow_intrabc);
 #endif  // CONFIG_INTRABC
   } else {
 #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING
@@ -3780,7 +3788,14 @@
       write_frame_size(cm, wb);
 #endif
 #if CONFIG_INTRABC
+#if CONFIG_HORZONLY_FRAME_SUPERRES
+      assert(av1_superres_unscaled(cm) ||
+             !(cm->allow_intrabc && NO_FILTER_FOR_IBC));
+      if (cm->allow_screen_content_tools &&
+          (av1_superres_unscaled(cm) || !NO_FILTER_FOR_IBC))
+#else
       if (cm->allow_screen_content_tools)
+#endif
         aom_wb_write_bit(wb, cm->allow_intrabc);
 #endif  // CONFIG_INTRABC
     } else {
@@ -4081,7 +4096,15 @@
     write_frame_size(cm, wb);
 #endif
 #if CONFIG_INTRABC
-    if (cm->allow_screen_content_tools) aom_wb_write_bit(wb, cm->allow_intrabc);
+#if CONFIG_HORZONLY_FRAME_SUPERRES
+    assert(av1_superres_unscaled(cm) ||
+           !(cm->allow_intrabc && NO_FILTER_FOR_IBC));
+    if (cm->allow_screen_content_tools &&
+        (av1_superres_unscaled(cm) || !NO_FILTER_FOR_IBC))
+#else
+    if (cm->allow_screen_content_tools)
+#endif
+      aom_wb_write_bit(wb, cm->allow_intrabc);
 #endif  // CONFIG_INTRABC
   } else if (cm->frame_type == INTRA_ONLY_FRAME) {
 #if !CONFIG_NO_FRAME_CONTEXT_SIGNALING
@@ -4102,7 +4125,14 @@
       write_frame_size(cm, wb);
 #endif
 #if CONFIG_INTRABC
+#if CONFIG_HORZONLY_FRAME_SUPERRES
+      assert(av1_superres_unscaled(cm) ||
+             !(cm->allow_intrabc && NO_FILTER_FOR_IBC));
+      if (cm->allow_screen_content_tools &&
+          (av1_superres_unscaled(cm) || !NO_FILTER_FOR_IBC))
+#else
       if (cm->allow_screen_content_tools)
+#endif
         aom_wb_write_bit(wb, cm->allow_intrabc);
 #endif  // CONFIG_INTRABC
     }
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 85464ab..f8a2000 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -4262,6 +4262,12 @@
   cm->allow_intrabc = cm->allow_screen_content_tools;
   // Reset the flag.
   cpi->intrabc_used = 0;
+#if CONFIG_HORZONLY_FRAME_SUPERRES
+  // Need to disable intrabc when superres is selected
+  if (NO_FILTER_FOR_IBC && !av1_superres_unscaled(cm)) {
+    cm->allow_intrabc = 0;
+  }
+#endif
 #endif  // CONFIG_INTRABC
 
 #if CONFIG_HASH_ME
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 6e55bbb..8448979 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -5170,9 +5170,6 @@
 #endif  // CONFIG_LOOP_RESTORATION
 
   if (is_lossless_requested(&cpi->oxcf)
-#if CONFIG_INTRABC
-      || (cm->allow_intrabc && NO_FILTER_FOR_IBC)
-#endif  // CONFIG_INTRABC
 #if CONFIG_EXT_TILE
       || cm->large_scale_tile
 #endif  // CONFIG_EXT_TILE
@@ -5185,9 +5182,6 @@
 
   int no_cdef = 0;
   if (is_lossless_requested(&cpi->oxcf) || !cpi->oxcf.using_cdef
-#if CONFIG_INTRABC
-      || (cm->allow_intrabc && NO_FILTER_FOR_IBC)
-#endif  // CONFIG_INTRABC
 #if CONFIG_EXT_TILE
       || cm->large_scale_tile
 #endif
@@ -5274,9 +5268,6 @@
     }
   }
 #endif  // CONFIG_LOOP_RESTORATION
-  // TODO(debargha): Fix mv search range on encoder side
-  // aom_extend_frame_inner_borders(cm->frame_to_show, num_planes);
-  aom_extend_frame_borders(cm->frame_to_show, num_planes);
 }
 
 static void encode_without_recode_loop(AV1_COMP *cpi) {
@@ -6098,7 +6089,14 @@
   // off.
 
   // Pick the loop filter level for the frame.
-  loopfilter_frame(cpi, cm);
+#if CONFIG_INTRABC
+  if (!(cm->allow_intrabc && NO_FILTER_FOR_IBC))
+#endif
+    loopfilter_frame(cpi, cm);
+
+  // TODO(debargha): Fix mv search range on encoder side
+  // aom_extend_frame_inner_borders(cm->frame_to_show, av1_num_planes(cm));
+  aom_extend_frame_borders(cm->frame_to_show, av1_num_planes(cm));
 
 #ifdef OUTPUT_YUV_REC
   aom_write_one_yuv_frame(cm, cm->frame_to_show);