Fix issues in multithreading for screen content

td->intrabc flag was being reset for every tile in case of tile-
based multi-threading of encoder, before cpi->intrabc was updated.
This would result in an erroneous bitstream.

Change-Id: I1c73d4e4e19ac725b591e58c04fa74f2edd37b16
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index ab72ca9..2b3dde6 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -5098,8 +5098,6 @@
 
   av1_crc32c_calculator_init(&td->mb.mb_rd_record.crc_calculator);
 
-  td->intrabc_used_this_tile = 0;
-
   for (mi_row = tile_info->mi_row_start; mi_row < tile_info->mi_row_end;
        mi_row += cm->seq_params.mib_size) {
     av1_encode_sb_row(cpi, td, tile_row, tile_col, mi_row);
@@ -5121,10 +5119,11 @@
     for (tile_col = 0; tile_col < tile_cols; ++tile_col) {
       TileDataEnc *const this_tile =
           &cpi->tile_data[tile_row * cm->tile_cols + tile_col];
+      cpi->td.intrabc_used = 0;
       cpi->td.mb.e_mbd.tile_ctx = &this_tile->tctx;
       cpi->td.mb.backup_tile_ctx = &this_tile->backup_tctx;
       av1_encode_tile(cpi, &cpi->td, tile_row, tile_col);
-      cpi->intrabc_used |= cpi->td.intrabc_used_this_tile;
+      cpi->intrabc_used |= cpi->td.intrabc_used;
     }
   }
 }
@@ -6130,8 +6129,7 @@
   }
 
   if (!dry_run) {
-    if (av1_allow_intrabc(cm) && is_intrabc_block(mbmi))
-      td->intrabc_used_this_tile = 1;
+    if (av1_allow_intrabc(cm) && is_intrabc_block(mbmi)) td->intrabc_used = 1;
     if (cm->tx_mode == TX_MODE_SELECT && !xd->lossless[mbmi->segment_id] &&
         mbmi->sb_type > BLOCK_4X4 && !(is_inter && (mbmi->skip || seg_skip))) {
       if (is_inter) {
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index 016daac..460293b 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -546,7 +546,7 @@
   PALETTE_BUFFER *palette_buffer;
   CONV_BUF_TYPE *tmp_conv_dst;
   uint8_t *tmp_obmc_bufs[2];
-  int intrabc_used_this_tile;
+  int intrabc_used;
   FRAME_CONTEXT *tctx;
 } ThreadData;
 
diff --git a/av1/encoder/ethread.c b/av1/encoder/ethread.c
index c0a3eea..7433c4a 100644
--- a/av1/encoder/ethread.c
+++ b/av1/encoder/ethread.c
@@ -286,7 +286,6 @@
 
     cfl_init(&td->mb.e_mbd.cfl, &cm->seq_params);
     av1_crc32c_calculator_init(&td->mb.mb_rd_record.crc_calculator);
-    td->intrabc_used_this_tile = 0;
 
     av1_encode_sb_row(cpi, td, tile_row, tile_col, current_mi_row);
 #if CONFIG_MULTITHREAD
@@ -472,7 +471,7 @@
   for (int i = 0; i < num_workers; i++) {
     AVxWorker *const worker = &cpi->workers[i];
     EncWorkerData *const thread_data = (EncWorkerData *)worker->data1;
-    cpi->intrabc_used |= thread_data->td->intrabc_used_this_tile;
+    cpi->intrabc_used |= thread_data->td->intrabc_used;
     // Accumulate counters.
     if (i < cpi->num_workers - 1) {
       av1_accumulate_frame_counts(&cpi->counts, thread_data->td->counts);
@@ -492,6 +491,8 @@
     worker->data1 = thread_data;
     worker->data2 = NULL;
 
+    thread_data->td->intrabc_used = 0;
+
     // Before encoding a frame, copy the thread data from cpi.
     if (thread_data->td != &cpi->td) {
       thread_data->td->mb = cpi->td.mb;