Turn on adaptive scan order

Change-Id: I43b3ce9bdee07107cbb5bc4b1ab216b3f0c5295d
diff --git a/av1/common/entropymode.h b/av1/common/entropymode.h
index ef79563..52fcc4e 100644
--- a/av1/common/entropymode.h
+++ b/av1/common/entropymode.h
@@ -38,6 +38,12 @@
 
 struct AV1Common;
 
+typedef struct {
+  const int16_t *scan;
+  const int16_t *iscan;
+  const int16_t *neighbors;
+} SCAN_ORDER;
+
 struct tx_probs {
   aom_prob p32x32[TX_SIZE_CONTEXTS][TX_SIZES - 1];
   aom_prob p16x16[TX_SIZE_CONTEXTS][TX_SIZES - 2];
@@ -89,6 +95,8 @@
   int16_t nb_8X8[TX_TYPES][(64 + 1) * 2];
   int16_t nb_16X16[TX_TYPES][(256 + 1) * 2];
   int16_t nb_32X32[TX_TYPES][(1024 + 1) * 2];
+
+  SCAN_ORDER sc[TX_SIZES][TX_TYPES];
 #endif
 
 #if CONFIG_REF_MV
diff --git a/av1/common/scan.c b/av1/common/scan.c
index 3563583..aff8391 100644
--- a/av1/common/scan.c
+++ b/av1/common/scan.c
@@ -963,10 +963,14 @@
       uint32_t *non_zero_prob = get_non_zero_prob(cm->fc, tx_size, tx_type);
       int tx2d_size = get_tx2d_size(tx_size);
       int i;
+      SCAN_ORDER *sc = &cm->fc->sc[tx_size][tx_type];
       for (i = 0; i < tx2d_size; ++i) {
         non_zero_prob[i] = (1 << 16) / 2;  // init non_zero_prob to 0.5
       }
       av1_update_scan_order_facade(cm, tx_size, tx_type);
+      sc->scan = get_adapt_scan(cm->fc, tx_size, tx_type);
+      sc->iscan = get_adapt_iscan(cm->fc, tx_size, tx_type);
+      sc->neighbors = get_adapt_nb(cm->fc, tx_size, tx_type);
     }
   }
 }
diff --git a/av1/common/scan.h b/av1/common/scan.h
index e3241ed..eeecae0 100644
--- a/av1/common/scan.h
+++ b/av1/common/scan.h
@@ -16,6 +16,7 @@
 #include "aom_ports/mem.h"
 
 #include "av1/common/blockd.h"
+#include "av1/common/entropymode.h"
 #include "av1/common/enums.h"
 #include "av1/common/onyxc_int.h"
 
@@ -25,12 +26,6 @@
 
 #define MAX_NEIGHBORS 2
 
-typedef struct {
-  const int16_t *scan;
-  const int16_t *iscan;
-  const int16_t *neighbors;
-} SCAN_ORDER;
-
 extern const SCAN_ORDER av1_default_scan_orders[TX_SIZES];
 extern const SCAN_ORDER av1_scan_orders[TX_SIZES][TX_TYPES];
 
@@ -74,6 +69,9 @@
 
 static INLINE const SCAN_ORDER *get_scan(const AV1_COMMON *const cm,
                                          TX_SIZE tx_size, TX_TYPE tx_type) {
+#if CONFIG_ADAPT_SCAN
+  return &cm->fc->sc[tx_size][tx_type];
+#endif
   (void)cm;
   return &av1_scan_orders[tx_size][tx_type];
 }
diff --git a/av1/encoder/firstpass.c b/av1/encoder/firstpass.c
index 6bc1b25..4d0acee 100644
--- a/av1/encoder/firstpass.c
+++ b/av1/encoder/firstpass.c
@@ -27,6 +27,7 @@
 #include "av1/common/entropymv.h"
 #include "av1/common/quant_common.h"
 #include "av1/common/reconinter.h"  // av1_setup_dst_planes()
+#include "av1/common/scan.h"
 #include "av1/encoder/aq_variance.h"
 #include "av1/encoder/block.h"
 #include "av1/encoder/encodeframe.h"
@@ -527,6 +528,9 @@
   }
 
   av1_init_mv_probs(cm);
+#if CONFIG_ADAPT_SCAN
+  av1_init_scan_order(cm);
+#endif
   av1_initialize_rd_consts(cpi);
 
   // Tiling is ignored in the first pass.