GrPorterDuffXferProcessor.h revision 71fecc32b1b4f71ef3c6467b1f5e0b55c2a12428
1378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel/*
2378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel * Copyright 2014 Google Inc.
3378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel *
4378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel * Use of this source code is governed by a BSD-style license that can be
5378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel * found in the LICENSE file.
6378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel */
7378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel
8378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel#ifndef GrPorterDuffXferProcessor_DEFINED
9378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel#define GrPorterDuffXferProcessor_DEFINED
10378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel
11378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel#include "GrTypes.h"
12378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel#include "GrXferProcessor.h"
1371fecc32b1b4f71ef3c6467b1f5e0b55c2a12428Mike Reed#include "SkBlendMode.h"
14378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel
158750924a1470e8215b2a344155259b93062d3fa2egdanielclass GrProcOptInfo;
16378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel
17f234272cbdcbcd46be462317e75cd138999c9fe9egdanielclass GrPorterDuffXPFactory : public GrXPFactory {
18378092f3d10b1dd62967f419c35cfefec7c10ee7egdanielpublic:
197d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    static sk_sp<GrXPFactory> Make(SkBlendMode mode);
20c016fb8f9fb53dd8d4936c5e9e16a9dc99ab392eegdaniel
211fa4572d1a32e9fbf102d7388efe5e44bef460f1cdalton    void getInvariantBlendedColor(const GrProcOptInfo& colorPOI,
221fa4572d1a32e9fbf102d7388efe5e44bef460f1cdalton                                  GrXPFactory::InvariantBlendedColor*) const override;
239513143efa734bef0c1a0c7f945022572dbc8518egdaniel
242047b7855546b21f7956c398592c070b3f91a9dbbsalomon
252047b7855546b21f7956c398592c070b3f91a9dbbsalomon    /** Because src-over is so common we special case it for performance reasons. If this returns
262047b7855546b21f7956c398592c070b3f91a9dbbsalomon        null then the SimpleSrcOverXP() below should be used. */
27c4b72720e75313079212e69e46a5ef7c474b2305egdaniel    static GrXferProcessor* CreateSrcOverXferProcessor(const GrCaps& caps,
28de4166a3b45d859512e27e3257841f064d67549cethannicholas                                                       const GrPipelineOptimizations& optimizations,
29c4b72720e75313079212e69e46a5ef7c474b2305egdaniel                                                       bool hasMixedSamples,
30c4b72720e75313079212e69e46a5ef7c474b2305egdaniel                                                       const GrXferProcessor::DstTexture*);
312047b7855546b21f7956c398592c070b3f91a9dbbsalomon    /** This XP implements non-LCD src-over using hw blend with no optimizations. It is returned
322047b7855546b21f7956c398592c070b3f91a9dbbsalomon        by reference because it is global and its ref-cnting methods are not thread safe. */
332047b7855546b21f7956c398592c070b3f91a9dbbsalomon    static const GrXferProcessor& SimpleSrcOverXP();
34c4b72720e75313079212e69e46a5ef7c474b2305egdaniel
35c4b72720e75313079212e69e46a5ef7c474b2305egdaniel    static inline void SrcOverInvariantBlendedColor(
36c4b72720e75313079212e69e46a5ef7c474b2305egdaniel                                                GrColor inputColor,
37c4b72720e75313079212e69e46a5ef7c474b2305egdaniel                                                GrColorComponentFlags validColorFlags,
38c4b72720e75313079212e69e46a5ef7c474b2305egdaniel                                                bool isOpaque,
39c4b72720e75313079212e69e46a5ef7c474b2305egdaniel                                                GrXPFactory::InvariantBlendedColor* blendedColor) {
40c4b72720e75313079212e69e46a5ef7c474b2305egdaniel        if (!isOpaque) {
41c4b72720e75313079212e69e46a5ef7c474b2305egdaniel            blendedColor->fWillBlendWithDst = true;
42c4b72720e75313079212e69e46a5ef7c474b2305egdaniel            blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags;
43c4b72720e75313079212e69e46a5ef7c474b2305egdaniel            return;
44c4b72720e75313079212e69e46a5ef7c474b2305egdaniel        }
45c4b72720e75313079212e69e46a5ef7c474b2305egdaniel        blendedColor->fWillBlendWithDst = false;
46c4b72720e75313079212e69e46a5ef7c474b2305egdaniel
47c4b72720e75313079212e69e46a5ef7c474b2305egdaniel        blendedColor->fKnownColor = inputColor;
48c4b72720e75313079212e69e46a5ef7c474b2305egdaniel        blendedColor->fKnownColorFlags = validColorFlags;
49c4b72720e75313079212e69e46a5ef7c474b2305egdaniel    }
50c4b72720e75313079212e69e46a5ef7c474b2305egdaniel
513ccf2e75ed92adb3c2c289e0cb95901d162df394cdalton    static bool SrcOverWillNeedDstTexture(const GrCaps&, const GrPipelineOptimizations&);
52c4b72720e75313079212e69e46a5ef7c474b2305egdaniel
53378092f3d10b1dd62967f419c35cfefec7c10ee7egdanielprivate:
547d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    GrPorterDuffXPFactory(SkBlendMode);
55915187b71d4068f21a15a1b8f4d919e1179d8b74egdaniel
564b91f768b348aa1cebeb54f3ff9331938734c242bsalomon    GrXferProcessor* onCreateXferProcessor(const GrCaps& caps,
57de4166a3b45d859512e27e3257841f064d67549cethannicholas                                           const GrPipelineOptimizations& optimizations,
5886ae0a9e465f157eaa263ef7515e10619946ff83cdalton                                           bool hasMixedSamples,
596a44c6a7d89b748fb040d41697a337d357d7fa22bsalomon                                           const DstTexture*) const override;
6050785a3d10b53bea5beb6e18431a2449860be237bsalomon
613ccf2e75ed92adb3c2c289e0cb95901d162df394cdalton    bool onWillReadDstColor(const GrCaps&, const GrPipelineOptimizations&) const override;
6250785a3d10b53bea5beb6e18431a2449860be237bsalomon
6336352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    bool onIsEqual(const GrXPFactory& xpfBase) const override {
64f234272cbdcbcd46be462317e75cd138999c9fe9egdaniel        const GrPorterDuffXPFactory& xpf = xpfBase.cast<GrPorterDuffXPFactory>();
656fd158ea47472c4d038e48980a95e36623f840c9cdalton        return fXfermode == xpf.fXfermode;
66915187b71d4068f21a15a1b8f4d919e1179d8b74egdaniel    }
67378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel
68c230414861558ce20b74281b1ca363e56c441832egdaniel    GR_DECLARE_XP_FACTORY_TEST;
696fd158ea47472c4d038e48980a95e36623f840c9cdalton    static void TestGetXPOutputTypes(const GrXferProcessor*, int* outPrimary, int* outSecondary);
70c230414861558ce20b74281b1ca363e56c441832egdaniel
717d954ad797176afedb9262fdea4507d0fc60eb9dMike Reed    SkBlendMode fXfermode;
72378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel
736fd158ea47472c4d038e48980a95e36623f840c9cdalton    friend class GrPorterDuffTest; // for TestGetXPOutputTypes()
74378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel    typedef GrXPFactory INHERITED;
75378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel};
76378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel
77378092f3d10b1dd62967f419c35cfefec7c10ee7egdaniel#endif
78