Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright 2017 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #ifndef SkColorSpace_New_DEFINED
      9 #define SkColorSpace_New_DEFINED
     10 
     11 #include "SkColorSpace.h"
     12 #include "SkImageInfo.h"
     13 #include "SkRefCnt.h"
     14 
     15 class SkRasterPipeline;
     16 
     17 class SkColorSpace_New final : public SkColorSpace {
     18 public:
     19     class ICCProfile;   // TODO: == SkICC?
     20 
     21     struct TransferFn : public SkRefCnt {
     22         virtual ~TransferFn() = default;
     23 
     24         // TODO: one day maybe we'd like to not need this call,
     25         // instead using the more active methods below instead.
     26         virtual SkColorSpaceTransferFn parameterize() const = 0;
     27 
     28         // Append stages to use this transfer function with SkRasterPipeline-based rendering.
     29         virtual void linearizeDst(SkRasterPipeline*) const = 0;
     30         virtual void linearizeSrc(SkRasterPipeline*) const = 0;
     31         virtual void    encodeSrc(SkRasterPipeline*) const = 0;
     32 
     33         // TODO: Ganesh hooks.
     34 
     35         // May return false even when this is equivalent to TransferFn,
     36         // but must always be equivalent when this returns true.  (No false positives.)
     37         // Implemented by default with parameterize().
     38         virtual bool equals(const TransferFn&) const;
     39 
     40         // TODO: ???
     41         // Implemented by default with parameterize().
     42         virtual void updateICCProfile(ICCProfile*) const;
     43 
     44         static sk_sp<TransferFn> MakeLinear();
     45         static sk_sp<TransferFn> MakeSRGB();
     46         static sk_sp<TransferFn> MakeGamma(float);
     47     };
     48 
     49     enum class Blending { Linear, AsEncoded };
     50 
     51     SkColorSpace_New(sk_sp<TransferFn>, SkMatrix44 toXYZD50, Blending);
     52 
     53     const SkMatrix44&   toXYZD50() const { return fToXYZD50;    }
     54     const SkMatrix44& fromXYZD50() const { return fFromXYZD50;  }
     55     const TransferFn& transferFn() const { return *fTransferFn; }
     56     Blending            blending() const { return fBlending;    }
     57 
     58     // Transfer-function-related overrides.
     59     sk_sp<SkColorSpace> makeLinearGamma() const override;
     60     sk_sp<SkColorSpace>   makeSRGBGamma() const override;
     61     SkGammaNamed           onGammaNamed() const override;
     62     bool             onGammaCloseToSRGB() const override;
     63     bool                onGammaIsLinear() const override;
     64     bool onIsNumericalTransferFn(SkColorSpaceTransferFn*) const override;
     65 
     66     // Gamut-related overrides.
     67     const SkMatrix44* onFromXYZD50() const override { return &fFromXYZD50; }
     68     const SkMatrix44*   onToXYZD50() const override { return   &fToXYZD50; }
     69     uint32_t        onToXYZD50Hash() const override { return fToXYZD50Hash; }
     70 
     71 private:
     72     sk_sp<TransferFn> fTransferFn;
     73     SkMatrix44        fFromXYZD50;
     74     SkMatrix44        fToXYZD50;
     75     uint32_t          fToXYZD50Hash;
     76     Blending          fBlending;
     77 };
     78 #endif//SkColorSpace_New_DEFINED
     79