intrabc: Call setup intrabc scale factors once per frame

Reduces av1_setup_scale_factors_for_frame profile from 1.85% to noise.

Change-Id: I6a7ad892824aac537992eb9109210b0a839136e9
diff --git a/av1/common/blockd.h b/av1/common/blockd.h
index 0acab96..1d88fc6 100644
--- a/av1/common/blockd.h
+++ b/av1/common/blockd.h
@@ -606,6 +606,11 @@
   /* pointer to current frame */
   const YV12_BUFFER_CONFIG *cur_buf;
 
+#if CONFIG_INTRABC
+  /* Scale of the current frame with respect to itself */
+  struct scale_factors sf_identity;
+#endif
+
   ENTROPY_CONTEXT *above_context[MAX_MB_PLANE];
   ENTROPY_CONTEXT left_context[MAX_MB_PLANE][2 * MAX_MIB_SIZE];
 
diff --git a/av1/common/reconinter.c b/av1/common/reconinter.c
index ed70657..7d2d9ae 100644
--- a/av1/common/reconinter.c
+++ b/av1/common/reconinter.c
@@ -903,14 +903,6 @@
   int ref;
 #if CONFIG_INTRABC
   const int is_intrabc = is_intrabc_block(&mi->mbmi);
-  struct scale_factors sf_identity;
-#if CONFIG_HIGHBITDEPTH
-  av1_setup_scale_factors_for_frame(
-      &sf_identity, 64, 64, 64, 64,
-      xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH);
-#else
-  av1_setup_scale_factors_for_frame(&sf_identity, 64, 64, 64, 64);
-#endif  // CONFIG_HIGHBITDEPTH
   assert(IMPLIES(is_intrabc, !is_compound));
 #endif  // CONFIG_INTRABC
 #if CONFIG_GLOBAL_MOTION
@@ -956,7 +948,7 @@
           struct buf_2d *const dst_buf = &pd->dst;
 #if CONFIG_INTRABC
           const struct scale_factors *const sf =
-              is_intrabc ? &sf_identity : &xd->block_refs[ref]->sf;
+              is_intrabc ? &xd->sf_identity : &xd->block_refs[ref]->sf;
           struct buf_2d *const pre_buf = is_intrabc ? dst_buf : &pd->pre[ref];
 #else
           const struct scale_factors *const sf = &xd->block_refs[ref]->sf;
@@ -1052,7 +1044,7 @@
     for (ref = 0; ref < 1 + is_compound; ++ref) {
 #if CONFIG_INTRABC
       const struct scale_factors *const sf =
-          is_intrabc ? &sf_identity : &xd->block_refs[ref]->sf;
+          is_intrabc ? &xd->sf_identity : &xd->block_refs[ref]->sf;
       struct buf_2d *const pre_buf = is_intrabc ? dst_buf : &pd->pre[ref];
 #else
       const struct scale_factors *const sf = &xd->block_refs[ref]->sf;
@@ -1110,7 +1102,7 @@
     for (ref = 0; ref < 1 + is_compound; ++ref) {
 #if CONFIG_INTRABC
       const struct scale_factors *const sf =
-          is_intrabc ? &sf_identity : &xd->block_refs[ref]->sf;
+          is_intrabc ? &xd->sf_identity : &xd->block_refs[ref]->sf;
       struct buf_2d *const pre_buf = is_intrabc ? dst_buf : &pd->pre[ref];
 #else
       const struct scale_factors *const sf = &xd->block_refs[ref]->sf;
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 289d386..0d4f344 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -4958,6 +4958,18 @@
 #endif
   new_fb = get_frame_new_buffer(cm);
   xd->cur_buf = new_fb;
+#if CONFIG_INTRABC
+#if CONFIG_HIGHBITDEPTH
+  av1_setup_scale_factors_for_frame(
+      &xd->sf_identity, xd->cur_buf->y_crop_width, xd->cur_buf->y_crop_height,
+      xd->cur_buf->y_crop_width, xd->cur_buf->y_crop_height,
+      cm->use_highbitdepth);
+#else
+  av1_setup_scale_factors_for_frame(
+      &xd->sf_identity, xd->cur_buf->y_crop_width, xd->cur_buf->y_crop_height,
+      xd->cur_buf->y_crop_width, xd->cur_buf->y_crop_height);
+#endif  // CONFIG_HIGHBITDEPTH
+#endif  // CONFIG_INTRABC
 #if CONFIG_GLOBAL_MOTION
   int i;
   for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 0271091..35f9f20 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -4012,6 +4012,16 @@
       ref_buf->buf = NULL;
     }
   }
+#if CONFIG_INTRABC
+#if CONFIG_HIGHBITDEPTH
+  av1_setup_scale_factors_for_frame(
+      &xd->sf_identity, cm->width, cm->height, cm->width, cm->height,
+      (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? 1 : 0);
+#else
+  av1_setup_scale_factors_for_frame(&xd->sf_identity, cm->width, cm->height,
+                                    cm->width, cm->height);
+#endif  // CONFIG_HIGHBITDEPTH
+#endif  // CONFIG_INTRABC
 
   set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME);
 }