Pass above/left ctx plane_bsize to av1_optimize_b

This is to facilitate lv_map experiment

Change-Id: Ife779b172c4b81a9b2b4640464163300996e3969
diff --git a/av1/encoder/encodemb.c b/av1/encoder/encodemb.c
index 4199906..5fd265a 100644
--- a/av1/encoder/encodemb.c
+++ b/av1/encoder/encodemb.c
@@ -803,13 +803,21 @@
 #endif  // USE_GREEDY_OPTIMIZE_B
 
 int av1_optimize_b(const AV1_COMMON *cm, MACROBLOCK *mb, int plane, int block,
-                   TX_SIZE tx_size, int ctx) {
+                   BLOCK_SIZE plane_bsize, TX_SIZE tx_size,
+                   const ENTROPY_CONTEXT *a, const ENTROPY_CONTEXT *l) {
   MACROBLOCKD *const xd = &mb->e_mbd;
   struct macroblock_plane *const p = &mb->plane[plane];
   const int eob = p->eobs[block];
   assert((mb->qindex == 0) ^ (xd->lossless[xd->mi[0]->mbmi.segment_id] == 0));
   if (eob == 0) return eob;
   if (xd->lossless[xd->mi[0]->mbmi.segment_id]) return eob;
+
+#if CONFIG_VAR_TX
+  int ctx = get_entropy_context(tx_size, a, l);
+#else
+  int ctx = combine_entropy_contexts(*a, *l);
+#endif
+
 #if CONFIG_PVQ
   (void)cm;
   (void)tx_size;
@@ -817,6 +825,7 @@
   return eob;
 #endif
 
+  (void)plane_bsize;
 #if USE_GREEDY_OPTIMIZE_B
   return optimize_b_greedy(cm, mb, plane, block, tx_size, ctx);
 #else   // USE_GREEDY_OPTIMIZE_B
@@ -1113,7 +1122,7 @@
 #endif
 
 #if !CONFIG_PVQ
-  av1_optimize_b(cm, x, plane, block, tx_size, ctx);
+  av1_optimize_b(cm, x, plane, block, plane_bsize, tx_size, a, l);
 
   av1_set_txb_context(x, plane, block, tx_size, a, l);
 
@@ -1734,7 +1743,7 @@
   if (args->enable_optimize_b) {
     av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
                     ctx, AV1_XFORM_QUANT_FP);
-    av1_optimize_b(cm, x, plane, block, tx_size, ctx);
+    av1_optimize_b(cm, x, plane, block, plane_bsize, tx_size, a, l);
   } else {
     av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
                     ctx, AV1_XFORM_QUANT_B);
diff --git a/av1/encoder/encodemb.h b/av1/encoder/encodemb.h
index 8270d7d..35a2c15 100644
--- a/av1/encoder/encodemb.h
+++ b/av1/encoder/encodemb.h
@@ -54,7 +54,8 @@
                      TX_SIZE tx_size, int ctx, AV1_XFORM_QUANT xform_quant_idx);
 
 int av1_optimize_b(const AV1_COMMON *cm, MACROBLOCK *mb, int plane, int block,
-                   TX_SIZE tx_size, int ctx);
+                   BLOCK_SIZE plane_bsize, TX_SIZE tx_size,
+                   const ENTROPY_CONTEXT *a, const ENTROPY_CONTEXT *l);
 
 void av1_subtract_txb(MACROBLOCK *x, int plane, BLOCK_SIZE plane_bsize,
                       int blk_col, int blk_row, TX_SIZE tx_size);
diff --git a/av1/encoder/encodetxb.c b/av1/encoder/encodetxb.c
index ba0ae1c..7316420 100644
--- a/av1/encoder/encodetxb.c
+++ b/av1/encoder/encodetxb.c
@@ -1850,7 +1850,7 @@
     av1_invalid_rd_stats(&this_rd_stats);
     av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
                     coeff_ctx, AV1_XFORM_QUANT_FP);
-    av1_optimize_b(cm, x, plane, block, tx_size, coeff_ctx);
+    av1_optimize_b(cm, x, plane, block, plane_bsize, tx_size, a, l);
     av1_dist_block(cpi, x, plane, plane_bsize, block, blk_row, blk_col, tx_size,
                    &this_rd_stats.dist, &this_rd_stats.sse,
                    OUTPUT_HAS_PREDICTED_PIXELS);
@@ -1871,7 +1871,7 @@
   // copy the best result in the above tx_type search for loop
   av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
                   coeff_ctx, AV1_XFORM_QUANT_FP);
-  av1_optimize_b(cm, x, plane, block, tx_size, coeff_ctx);
+  av1_optimize_b(cm, x, plane, block, plane_bsize, tx_size, a, l);
   if (!is_inter_block(mbmi)) {
     // intra mode needs decoded result such that the next transform block
     // can use it for prediction.
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 56714ab..582dd94 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -1491,7 +1491,7 @@
   const int coeff_ctx = combine_entropy_contexts(*a, *l);
   av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
                   coeff_ctx, AV1_XFORM_QUANT_FP);
-  av1_optimize_b(cm, x, plane, block, tx_size, coeff_ctx);
+  av1_optimize_b(cm, x, plane, block, plane_bsize, tx_size, a, l);
 
   if (!is_inter_block(mbmi)) {
     struct macroblock_plane *const p = &x->plane[plane];
@@ -2817,7 +2817,8 @@
 #if !CONFIG_PVQ
             av1_xform_quant(cm, x, 0, block, row + idy, col + idx, BLOCK_8X8,
                             tx_size, coeff_ctx, AV1_XFORM_QUANT_FP);
-            av1_optimize_b(cm, x, 0, block, tx_size, coeff_ctx);
+            av1_optimize_b(cm, x, 0, block, BLOCK_8X8, tx_size, tempa + idx,
+                           templ + idy);
             ratey += av1_cost_coeffs(cpi, x, 0, block, tx_size, scan_order,
                                      tempa + idx, templ + idy,
                                      cpi->sf.use_fast_coef_costing);
@@ -2976,7 +2977,8 @@
 #endif  // CONFIG_CB4X4
                         BLOCK_8X8, tx_size, coeff_ctx, xform_quant);
 
-        av1_optimize_b(cm, x, 0, block, tx_size, coeff_ctx);
+        av1_optimize_b(cm, x, 0, block, BLOCK_8X8, tx_size, tempa + idx,
+                       templ + idy);
 
         ratey +=
             av1_cost_coeffs(cpi, x, 0, block, tx_size, scan_order, tempa + idx,
@@ -3927,7 +3929,7 @@
   av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
                   coeff_ctx, AV1_XFORM_QUANT_FP);
 
-  av1_optimize_b(cm, x, plane, block, tx_size, coeff_ctx);
+  av1_optimize_b(cm, x, plane, block, plane_bsize, tx_size, a, l);
 
 // TODO(any): Use av1_dist_block to compute distortion
 #if CONFIG_HIGHBITDEPTH