2014-12-03 18:40:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrPorterDuffXferProcessor_DEFINED
|
|
|
|
#define GrPorterDuffXferProcessor_DEFINED
|
|
|
|
|
|
|
|
#include "GrTypes.h"
|
|
|
|
#include "GrXferProcessor.h"
|
|
|
|
#include "SkXfermode.h"
|
|
|
|
|
2014-12-17 21:37:13 +00:00
|
|
|
class GrProcOptInfo;
|
2014-12-03 18:40:13 +00:00
|
|
|
|
2015-11-20 23:12:59 +00:00
|
|
|
class GrPorterDuffXPFactory : public GrXPFactory {
|
2014-12-03 18:40:13 +00:00
|
|
|
public:
|
2015-11-20 23:12:59 +00:00
|
|
|
static GrXPFactory* Create(SkXfermode::Mode mode);
|
2014-12-03 19:41:54 +00:00
|
|
|
|
2015-06-02 17:43:39 +00:00
|
|
|
void getInvariantBlendedColor(const GrProcOptInfo& colorPOI,
|
|
|
|
GrXPFactory::InvariantBlendedColor*) const override;
|
2014-12-09 19:15:43 +00:00
|
|
|
|
2015-12-21 21:12:54 +00:00
|
|
|
|
|
|
|
/** Because src-over is so common we special case it for performance reasons. If this returns
|
|
|
|
null then the SimpleSrcOverXP() below should be used. */
|
2015-11-23 21:20:41 +00:00
|
|
|
static GrXferProcessor* CreateSrcOverXferProcessor(const GrCaps& caps,
|
2015-11-30 16:57:38 +00:00
|
|
|
const GrPipelineOptimizations& optimizations,
|
2015-11-23 21:20:41 +00:00
|
|
|
bool hasMixedSamples,
|
|
|
|
const GrXferProcessor::DstTexture*);
|
2015-12-21 21:12:54 +00:00
|
|
|
/** This XP implements non-LCD src-over using hw blend with no optimizations. It is returned
|
|
|
|
by reference because it is global and its ref-cnting methods are not thread safe. */
|
|
|
|
static const GrXferProcessor& SimpleSrcOverXP();
|
2015-11-23 21:20:41 +00:00
|
|
|
|
|
|
|
static inline void SrcOverInvariantBlendedColor(
|
|
|
|
GrColor inputColor,
|
|
|
|
GrColorComponentFlags validColorFlags,
|
|
|
|
bool isOpaque,
|
|
|
|
GrXPFactory::InvariantBlendedColor* blendedColor) {
|
|
|
|
if (!isOpaque) {
|
|
|
|
blendedColor->fWillBlendWithDst = true;
|
|
|
|
blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
blendedColor->fWillBlendWithDst = false;
|
|
|
|
|
|
|
|
blendedColor->fKnownColor = inputColor;
|
|
|
|
blendedColor->fKnownColorFlags = validColorFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool SrcOverWillNeedDstTexture(const GrCaps& caps,
|
2015-11-30 16:57:38 +00:00
|
|
|
const GrPipelineOptimizations& optimizations,
|
2015-11-23 21:20:41 +00:00
|
|
|
bool hasMixedSamples);
|
|
|
|
|
2014-12-03 18:40:13 +00:00
|
|
|
private:
|
2015-11-20 23:12:59 +00:00
|
|
|
GrPorterDuffXPFactory(SkXfermode::Mode);
|
2014-12-05 20:58:28 +00:00
|
|
|
|
2015-05-19 16:29:46 +00:00
|
|
|
GrXferProcessor* onCreateXferProcessor(const GrCaps& caps,
|
2015-11-30 16:57:38 +00:00
|
|
|
const GrPipelineOptimizations& optimizations,
|
2015-06-08 22:11:04 +00:00
|
|
|
bool hasMixedSamples,
|
2015-05-26 16:49:05 +00:00
|
|
|
const DstTexture*) const override;
|
2015-02-06 15:02:37 +00:00
|
|
|
|
2016-01-30 17:59:10 +00:00
|
|
|
bool onWillReadDstColor(const GrCaps& caps,
|
|
|
|
const GrPipelineOptimizations& optimizations,
|
|
|
|
bool hasMixedSamples) const override;
|
2015-02-06 15:02:37 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onIsEqual(const GrXPFactory& xpfBase) const override {
|
2015-11-20 23:12:59 +00:00
|
|
|
const GrPorterDuffXPFactory& xpf = xpfBase.cast<GrPorterDuffXPFactory>();
|
2015-05-27 22:08:33 +00:00
|
|
|
return fXfermode == xpf.fXfermode;
|
2014-12-05 20:58:28 +00:00
|
|
|
}
|
2014-12-03 18:40:13 +00:00
|
|
|
|
2014-12-11 21:15:13 +00:00
|
|
|
GR_DECLARE_XP_FACTORY_TEST;
|
2015-05-27 22:08:33 +00:00
|
|
|
static void TestGetXPOutputTypes(const GrXferProcessor*, int* outPrimary, int* outSecondary);
|
2014-12-11 21:15:13 +00:00
|
|
|
|
2015-05-27 22:08:33 +00:00
|
|
|
SkXfermode::Mode fXfermode;
|
2014-12-03 18:40:13 +00:00
|
|
|
|
2015-05-27 22:08:33 +00:00
|
|
|
friend class GrPorterDuffTest; // for TestGetXPOutputTypes()
|
2014-12-03 18:40:13 +00:00
|
|
|
typedef GrXPFactory INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|