Superres: use TPL etc in fullres recode try.

Earlier, TPL, deltaQ and some other encoding options were disabled for
both fullres and superres recode tries.

Regression was introduced in:
https://aomedia-review.googlesource.com/c/aom/+/103104

Now, we make sure all these options are enabled for the fullres try, so
that fullres encode will be same as baseline.

BDRate baseline vs SUPERRES_AUTO mode for hdres2, VBR mode:
- before = +2.074
- after  = +0.216

BUG=aomedia:2844

Change-Id: I1a06068f276aec7267911775c5aacc3040a06baf
(cherry picked from commit 2e592e3b09570ea8644bd4cf687c34e45fdca51b)
diff --git a/av1/encoder/encode_strategy.c b/av1/encoder/encode_strategy.c
index e30d668..bae475f 100644
--- a/av1/encoder/encode_strategy.c
+++ b/av1/encoder/encode_strategy.c
@@ -1191,7 +1191,8 @@
     if (allow_tpl) {
       // Need to set the size for TPL for ARF
       // TODO(bohanli): Why is this? what part of it is necessary?
-      av1_set_frame_size(cpi, cm->width, cm->height);
+      av1_set_frame_size(cpi, cm->superres_upscaled_width,
+                         cm->superres_upscaled_height);
     }
   }
   if (allow_tpl) {
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 7286c02..33a7ea8 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -653,7 +653,14 @@
   av1_update_film_grain_parameters(cpi, oxcf);
 
   cpi->oxcf = *oxcf;
-  cpi->superres_mode = oxcf->superres_cfg.superres_mode;  // default
+  // When user provides superres_mode = AOM_SUPERRES_AUTO, we still initialize
+  // superres mode for current encoding = AOM_SUPERRES_NONE. This is to ensure
+  // that any analysis (e.g. TPL) happening outside the main encoding loop still
+  // happens at full resolution.
+  // This value will later be set appropriately just before main encoding loop.
+  cpi->superres_mode = oxcf->superres_cfg.superres_mode == AOM_SUPERRES_AUTO
+                           ? AOM_SUPERRES_NONE
+                           : oxcf->superres_cfg.superres_mode;  // default
   x->e_mbd.bd = (int)seq_params->bit_depth;
   x->e_mbd.global_motion = cm->global_motion;
 
@@ -2703,8 +2710,10 @@
   int64_t sse1 = INT64_MAX;
   int64_t rate1 = INT64_MAX;
   int largest_tile_id1;
+  cpi->superres_mode = AOM_SUPERRES_AUTO;  // Super-res on for this recode loop.
   err = encode_with_recode_loop_and_filter(cpi, size, dest, &sse1, &rate1,
                                            &largest_tile_id1);
+  cpi->superres_mode = AOM_SUPERRES_NONE;  // Reset to default (full-res).
   if (err != AOM_CODEC_OK) return err;
   restore_all_coding_context(cpi);
 #endif  // SUPERRES_RECODE_ALL_RATIOS
@@ -2713,11 +2722,9 @@
   int64_t sse2 = INT64_MAX;
   int64_t rate2 = INT64_MAX;
   int largest_tile_id2;
-  cpi->superres_mode = AOM_SUPERRES_NONE;  // To force full-res.
+  assert(cpi->superres_mode == AOM_SUPERRES_NONE);
   err = encode_with_recode_loop_and_filter(cpi, size, dest, &sse2, &rate2,
                                            &largest_tile_id2);
-  cpi->superres_mode = cpi->oxcf.superres_cfg.superres_mode;  // Reset.
-  assert(cpi->oxcf.superres_cfg.superres_mode == AOM_SUPERRES_AUTO);
   if (err != AOM_CODEC_OK) return err;
 
   // Note: Both use common rdmult based on base qindex of fullres.
@@ -2769,8 +2776,11 @@
 #endif  // SUPERRES_RECODE_ALL_RATIOS
     int64_t sse3 = INT64_MAX;
     int64_t rate3 = INT64_MAX;
+    cpi->superres_mode =
+        AOM_SUPERRES_AUTO;  // Super-res on for this recode loop.
     err = encode_with_recode_loop_and_filter(cpi, size, dest, &sse3, &rate3,
                                              largest_tile_id);
+    cpi->superres_mode = AOM_SUPERRES_NONE;  // Reset to default (full-res).
     assert(sse1 == sse3);
     assert(rate1 == rate3);
     assert(largest_tile_id1 == *largest_tile_id);
@@ -3029,6 +3039,7 @@
     }
   } else {
 #endif  // CONFIG_SUPERRES_IN_RECODE
+    cpi->superres_mode = cpi->oxcf.superres_cfg.superres_mode;
     if (encode_with_recode_loop_and_filter(cpi, size, dest, NULL, NULL,
                                            &largest_tile_id) != AOM_CODEC_OK) {
       return AOM_CODEC_ERROR;