rtc-screen: Reduce blocking artifacts on flat areas

For screen in nonrd_pickmode: for spatially flat
blocks compute the block source_sad and use it to
flag whether the coding block has any motion. This
is then used for decision on skipping inter-modes.

Currently the only flag is at the superblock level.
Doing it at the coding level allows for better mode
testing decision. In particular we use it here to
better decide whether to skip zero-mv for flat blocks
if the block has motion.

This helps to reduce blocking artfiacts for speed >= 7.

Overall ~neutral stats change, for speed 10 rtc_screen:
avg_psnr/ovr_psnr/ssim, IC% speedup:
0.197/0.160/0.246, 0.492

Change-Id: I5118ec4175e4f940c8474c7822c464c54487b196
diff --git a/av1/encoder/nonrd_pickmode.c b/av1/encoder/nonrd_pickmode.c
index c5914ad..8f22000 100644
--- a/av1/encoder/nonrd_pickmode.c
+++ b/av1/encoder/nonrd_pickmode.c
@@ -1919,6 +1919,14 @@
   return 0;
 }
 
+static void set_block_source_sad(AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize,
+                                 struct buf_2d *yv12_mb) {
+  struct macroblock_plane *const p = &x->plane[0];
+  const int y_sad = cpi->ppi->fn_ptr[bsize].sdf(p->src.buf, p->src.stride,
+                                                yv12_mb->buf, yv12_mb->stride);
+  if (y_sad == 0) x->block_is_zero_sad = 1;
+}
+
 static void set_color_sensitivity(AV1_COMP *cpi, MACROBLOCK *x,
                                   BLOCK_SIZE bsize, int y_sad,
                                   unsigned int source_variance,
@@ -2407,7 +2415,7 @@
       if ((search_state->frame_mv[*this_mode][*ref_frame].as_int != 0 &&
            x->content_state_sb.source_sad_nonrd == kZeroSad) ||
           (search_state->frame_mv[*this_mode][*ref_frame].as_int == 0 &&
-           x->content_state_sb.source_sad_nonrd != kZeroSad &&
+           x->block_is_zero_sad == 0 &&
            ((x->color_sensitivity[COLOR_SENS_IDX(AOM_PLANE_U)] == 0 &&
              x->color_sensitivity[COLOR_SENS_IDX(AOM_PLANE_V)] == 0) ||
             cpi->rc.high_source_sad) &&
@@ -2551,8 +2559,7 @@
   // skip newmv if the motion vector is (0, 0), and color is not set.
   if (this_mode == NEWMV && cpi->oxcf.tune_cfg.content == AOM_CONTENT_SCREEN &&
       cpi->svc.spatial_layer_id == 0 && rt_sf->source_metrics_sb_nonrd) {
-    if (this_mv->as_int == 0 &&
-        x->content_state_sb.source_sad_nonrd != kZeroSad &&
+    if (this_mv->as_int == 0 && x->block_is_zero_sad == 0 &&
         ((x->color_sensitivity[COLOR_SENS_IDX(AOM_PLANE_U)] == 0 &&
           x->color_sensitivity[COLOR_SENS_IDX(AOM_PLANE_V)] == 0) ||
          cpi->rc.high_source_sad) &&
@@ -3207,6 +3214,14 @@
   inter_pred_params_sr.conv_params =
       get_conv_params(/*do_average=*/0, AOM_PLANE_Y, xd->bd);
 
+  x->block_is_zero_sad = x->content_state_sb.source_sad_nonrd == kZeroSad;
+  if (cpi->oxcf.tune_cfg.content == AOM_CONTENT_SCREEN &&
+      !x->force_zeromv_skip_for_blk &&
+      x->content_state_sb.source_sad_nonrd != kZeroSad &&
+      x->source_variance == 0 && bsize < cm->seq_params->sb_size) {
+    set_block_source_sad(cpi, x, bsize, &search_state.yv12_mb[LAST_FRAME][0]);
+  }
+
   x->min_dist_inter_uv = INT64_MAX;
   for (int idx = 0; idx < num_inter_modes + tot_num_comp_modes; ++idx) {
     // If we are at the first compound mode, and the single modes already