respect srgb gamma when building mips

Proposed policy:
- If the target is *legacy* (e.g. L32/PMColor) ignore gamma
- If the target is S32/F16 respect gamma

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2029373004

Review-Url: https://codereview.chromium.org/2029373004
diff --git a/src/core/SkMipMap.h b/src/core/SkMipMap.h
index 7c798ef..0f31a9f 100644
--- a/src/core/SkMipMap.h
+++ b/src/core/SkMipMap.h
@@ -12,6 +12,7 @@
 #include "SkPixmap.h"
 #include "SkScalar.h"
 #include "SkSize.h"
+#include "SkShader.h"
 
 class SkBitmap;
 class SkDiscardableMemory;
@@ -27,8 +28,13 @@
  */
 class SkMipMap : public SkCachedData {
 public:
-    static SkMipMap* Build(const SkPixmap& src, SkDiscardableFactoryProc);
-    static SkMipMap* Build(const SkBitmap& src, SkDiscardableFactoryProc);
+    static SkMipMap* Build(const SkPixmap& src, SkSourceGammaTreatment, SkDiscardableFactoryProc);
+    static SkMipMap* Build(const SkBitmap& src, SkSourceGammaTreatment, SkDiscardableFactoryProc);
+
+    static SkSourceGammaTreatment DeduceTreatment(const SkShader::ContextRec& rec) {
+        return (SkShader::ContextRec::kPMColor_DstType == rec.fPreferredDstType) ?
+                SkSourceGammaTreatment::kIgnore : SkSourceGammaTreatment::kRespect;
+    }
 
     // Determines how many levels a SkMipMap will have without creating that mipmap.
     // This does not include the base mipmap level that the user provided when
@@ -61,10 +67,10 @@
     }
 
 private:
-    Level*  fLevels;
-    int     fCount;
+    sk_sp<SkColorSpace> fCS;
+    Level*              fLevels;    // managed by the baseclass, may be null due to onDataChanged.
+    int                 fCount;
 
-    // we take ownership of levels, and will free it with sk_free()
     SkMipMap(void* malloc, size_t size) : INHERITED(malloc, size) {}
     SkMipMap(size_t size, SkDiscardableMemory* dm) : INHERITED(size, dm) {}