Extend IntraBC to 4x4

Change-Id: I3f30c35bcd1bc623ad0c34c4b954ff71b2fcfd00
diff --git a/av1/common/reconinter.c b/av1/common/reconinter.c
index 5d79560..d7e39b4 100644
--- a/av1/common/reconinter.c
+++ b/av1/common/reconinter.c
@@ -1225,6 +1225,13 @@
   const int ss_x = pd->subsampling_x;
   const int ss_y = pd->subsampling_y;
   int sub8x8_inter = bsize < BLOCK_8X8 && (ss_x || ss_y);
+
+#if CONFIG_INTRABC
+  if (is_intrabc) {
+    sub8x8_inter = 0;
+  }
+#endif
+
 #if CONFIG_MOTION_VAR
   sub8x8_inter = sub8x8_inter && !build_for_obmc;
 #endif  // CONFIG_MOTION_VAR
diff --git a/av1/common/reconintra.h b/av1/common/reconintra.h
index 160d0f7..42797e3 100644
--- a/av1/common/reconintra.h
+++ b/av1/common/reconintra.h
@@ -71,6 +71,14 @@
 }
 #endif  // CONFIG_EXT_INTRA
 
+#if CONFIG_INTRABC
+static INLINE int av1_allow_intrabc(BLOCK_SIZE bsize,
+                                    const AV1_COMMON *const cm) {
+  return (bsize >= BLOCK_8X8 || bsize == BLOCK_4X4) &&
+         cm->allow_screen_content_tools;
+}
+#endif  // CONFIG_INTRABC
+
 #ifdef __cplusplus
 }  // extern "C"
 #endif
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index 3748083..e06e016 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -1163,7 +1163,7 @@
   mbmi->ref_frame[1] = NONE_FRAME;
 
 #if CONFIG_INTRABC
-  if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools) {
+  if (av1_allow_intrabc(bsize, cm)) {
     mbmi->use_intrabc = aom_read_symbol(r, ec_ctx->intrabc_cdf, 2, ACCT_STR);
     if (mbmi->use_intrabc) {
       mbmi->tx_size = read_tx_size(cm, xd, 1, !mbmi->skip, r);
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index dd0e43b..799ee81 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -2169,7 +2169,7 @@
                        !xd->lossless[mbmi->segment_id];
 
 #if CONFIG_INTRABC
-  if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools) {
+  if (av1_allow_intrabc(bsize, cm)) {
     int use_intrabc = is_intrabc_block(mbmi);
     aom_write_symbol(w, use_intrabc, ec_ctx->intrabc_cdf, 2);
     if (use_intrabc) {
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index c961222..c5a4b63 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -1984,7 +1984,7 @@
     }
 #if CONFIG_INTRABC
   } else {
-    if (cm->allow_screen_content_tools && bsize >= BLOCK_8X8) {
+    if (av1_allow_intrabc(bsize, cm)) {
       FRAME_COUNTS *const counts = td->counts;
       ++counts->intrabc[mbmi->use_intrabc];
     } else {
@@ -5278,6 +5278,9 @@
     av1_generate_block_hash_value(cpi->source, 4, block_hash_values[0],
                                   block_hash_values[1], is_block_same[0],
                                   is_block_same[1]);
+    av1_add_to_hash_map_by_row_with_precal_data(
+        &cm->cur_frame->hash_table, block_hash_values[1], is_block_same[1][2],
+        pic_width, pic_height, 4);
     av1_generate_block_hash_value(cpi->source, 8, block_hash_values[1],
                                   block_hash_values[0], is_block_same[1],
                                   is_block_same[0]);
diff --git a/av1/encoder/hash_motion.c b/av1/encoder/hash_motion.c
index 0892502..2378597 100644
--- a/av1/encoder/hash_motion.c
+++ b/av1/encoder/hash_motion.c
@@ -4,7 +4,7 @@
 #include "./av1_rtcd.h"
 
 static const int crc_bits = 16;
-static const int block_size_bits = 2;
+static const int block_size_bits = 3;
 static CRC_CALCULATOR crc_calculator1;
 static CRC_CALCULATOR crc_calculator2;
 static int g_crc_initialized = 0;
@@ -53,15 +53,16 @@
   return 1;
 }
 
-// the hash value (hash_value1 consists two parts, the first 2 bits relate to
+// the hash value (hash_value1 consists two parts, the first 3 bits relate to
 // the block size and the remaining 16 bits are the crc values. This fuction
-// is used to get the first 2 bits.
+// is used to get the first 3 bits.
 static int hash_block_size_to_index(int block_size) {
   switch (block_size) {
-    case 8: return 0;
-    case 16: return 1;
-    case 32: return 2;
-    case 64: return 3;
+    case 4: return 0;
+    case 8: return 1;
+    case 16: return 2;
+    case 32: return 3;
+    case 64: return 4;
     default: return -1;
   }
 }
@@ -220,7 +221,7 @@
     pos += block_size - 1;
   }
 
-  if (block_size >= 8) {
+  if (block_size >= 4) {
     const int size_minus1 = block_size - 1;
     pos = 0;
     for (int y_pos = 0; y_pos < y_end; y_pos++) {
diff --git a/av1/encoder/mcomp.c b/av1/encoder/mcomp.c
index 9f649a6..49d6e67 100644
--- a/av1/encoder/mcomp.c
+++ b/av1/encoder/mcomp.c
@@ -2573,8 +2573,8 @@
     const int block_height = block_size_high[bsize];
     const int block_width = block_size_wide[bsize];
     if (block_height == block_width && x_pos >= 0 && y_pos >= 0) {
-      if (block_width == 8 || block_width == 16 || block_width == 32 ||
-          block_width == 64) {
+      if (block_width == 4 || block_width == 8 || block_width == 16 ||
+          block_width == 32 || block_width == 64) {
         uint8_t *what = x->plane[0].src.buf;
         const int what_stride = x->plane[0].src.stride;
         block_hash block_hashes[MAX_HASH_MV_TABLE_SIZE];
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 6d1c69f..fadd930 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -9424,7 +9424,7 @@
                                        RD_STATS *rd_cost, BLOCK_SIZE bsize,
                                        int64_t best_rd) {
   const AV1_COMMON *const cm = &cpi->common;
-  if (bsize < BLOCK_8X8 || !cm->allow_screen_content_tools) return INT64_MAX;
+  if (!av1_allow_intrabc(bsize, cm)) return INT64_MAX;
 
   MACROBLOCKD *const xd = &x->e_mbd;
   const TileInfo *tile = &xd->tile;