Skip 2x2 uv block in the rd search loop

Skip the 2x2 uv block rate-distortion optimization process in the
non-reference positions in key frame encoding.

Change-Id: I51112492fd79f9a1c205fba151f8658cea9ee85f
diff --git a/av1/encoder/block.h b/av1/encoder/block.h
index 2807274..5c7aeb4 100644
--- a/av1/encoder/block.h
+++ b/av1/encoder/block.h
@@ -166,6 +166,10 @@
 
   int skip;
 
+#if CONFIG_CB4X4
+  int skip_chroma_rd;
+#endif
+
   // note that token_costs is the cost when eob node is skipped
   av1_coeff_cost token_costs[TX_SIZES];
 
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 5735702..69e428b 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -1852,6 +1852,11 @@
   // Set to zero to make sure we do not use the previous encoded frame stats
   mbmi->skip = 0;
 
+#if CONFIG_CB4X4
+  x->skip_chroma_rd =
+      (bsize < BLOCK_8X8) && !is_chroma_reference(mi_row, mi_col);
+#endif
+
 #if CONFIG_AOM_HIGHBITDEPTH
   if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
     x->source_variance = av1_high_get_sby_perpixel_variance(
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 16540d7..e0b9784 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -9035,8 +9035,10 @@
                                    [pd[1].subsampling_x][pd[1].subsampling_y];
 
 #if CONFIG_CB4X4
-  rd_pick_intra_sbuv_mode(cpi, x, &rate_uv, &rate_uv_tokenonly, &dist_uv,
-                          &uv_skip, bsize, max_uv_tx_size);
+  max_uv_tx_size = AOMMAX(max_uv_tx_size, TX_4X4);
+  if (!x->skip_chroma_rd)
+    rd_pick_intra_sbuv_mode(cpi, x, &rate_uv, &rate_uv_tokenonly, &dist_uv,
+                            &uv_skip, bsize, max_uv_tx_size);
 #else
   rd_pick_intra_sbuv_mode(cpi, x, &rate_uv, &rate_uv_tokenonly, &dist_uv,
                           &uv_skip, AOMMAX(BLOCK_8X8, bsize), max_uv_tx_size);