From 06ca8ec87cf6fab57cadd043a5ac18c4154a4129 Mon Sep 17 00:00:00 2001 From: bungeman Date: Thu, 9 Jun 2016 08:01:03 -0700 Subject: sk_sp for Ganesh. Convert use of GrFragmentProcessor, GrGeometryProcessor, and GrXPFactory to sk_sp. This clarifies ownership and should reduce reference count churn by moving ownership. GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2041113004 Review-Url: https://codereview.chromium.org/2041113004 --- include/core/SkColorFilter.h | 7 +-- include/core/SkRefCnt.h | 4 +- include/core/SkShader.h | 5 +- include/core/SkXfermode.h | 6 +-- include/effects/SkColorCubeFilter.h | 2 +- include/effects/SkLumaColorFilter.h | 3 +- include/effects/SkPerlinNoiseShader.h | 2 +- include/gpu/GrClip.h | 12 ++--- include/gpu/GrContext.h | 4 +- include/gpu/GrFragmentProcessor.h | 29 ++++++---- include/gpu/GrPaint.h | 66 ++++++++--------------- include/gpu/GrProcessorUnitTest.h | 30 +++++------ include/gpu/GrTypesPriv.h | 6 +++ include/gpu/effects/GrConstColorProcessor.h | 4 +- include/gpu/effects/GrCoverageSetOpXP.h | 2 +- include/gpu/effects/GrCustomXfermode.h | 2 +- include/gpu/effects/GrPorterDuffXferProcessor.h | 2 +- include/gpu/effects/GrXfermodeFragmentProcessor.h | 14 ++--- include/private/SkTArray.h | 9 ++++ 19 files changed, 107 insertions(+), 102 deletions(-) (limited to 'include') diff --git a/include/core/SkColorFilter.h b/include/core/SkColorFilter.h index 7ac335fb10..7b2ee7845e 100644 --- a/include/core/SkColorFilter.h +++ b/include/core/SkColorFilter.h @@ -10,6 +10,7 @@ #include "SkColor.h" #include "SkFlattenable.h" +#include "SkRefCnt.h" #include "SkXfermode.h" class GrContext; @@ -142,6 +143,7 @@ public: } #endif +#if SK_SUPPORT_GPU /** * A subclass may implement this factory function to work with the GPU backend. It returns * a GrFragmentProcessor that implemets the color filter in GPU shader code. @@ -151,9 +153,8 @@ public: * * A null return indicates that the color filter isn't implemented for the GPU backend. */ - virtual const GrFragmentProcessor* asFragmentProcessor(GrContext*) const { - return nullptr; - } + virtual sk_sp asFragmentProcessor(GrContext*) const; +#endif bool affectsTransparentBlack() const { return this->filterColor(0) != 0; diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h index c45ed6bbf0..3227e68740 100644 --- a/include/core/SkRefCnt.h +++ b/include/core/SkRefCnt.h @@ -264,8 +264,8 @@ template class sk_sp { public: using element_type = T; - sk_sp() : fPtr(nullptr) {} - sk_sp(std::nullptr_t) : fPtr(nullptr) {} + constexpr sk_sp() : fPtr(nullptr) {} + constexpr sk_sp(std::nullptr_t) : fPtr(nullptr) {} /** * Shares the underlying object by calling ref(), so that both the argument and the newly diff --git a/include/core/SkShader.h b/include/core/SkShader.h index 33ac8db6bc..1f80ea1c09 100644 --- a/include/core/SkShader.h +++ b/include/core/SkShader.h @@ -310,7 +310,7 @@ public: virtual bool asACompose(ComposeRec*) const { return false; } - +#if SK_SUPPORT_GPU /** * Returns a GrFragmentProcessor that implements the shader for the GPU backend. NULL is * returned if there is no GPU implementation. @@ -324,11 +324,12 @@ public: * The returned GrFragmentProcessor should expect an unpremultiplied input color and * produce a premultiplied output. */ - virtual const GrFragmentProcessor* asFragmentProcessor(GrContext*, + virtual sk_sp asFragmentProcessor(GrContext*, const SkMatrix& viewMatrix, const SkMatrix* localMatrix, SkFilterQuality, SkSourceGammaTreatment) const; +#endif /** * If the shader can represent its "average" luminance in a single color, return true and diff --git a/include/core/SkXfermode.h b/include/core/SkXfermode.h index c4578ffaf7..6215315576 100644 --- a/include/core/SkXfermode.h +++ b/include/core/SkXfermode.h @@ -220,14 +220,14 @@ public: It is legal for the function to return a null output. This indicates that the output of the blend is simply the src color. */ - virtual const GrFragmentProcessor* getFragmentProcessorForImageFilter( - const GrFragmentProcessor* dst) const; + virtual sk_sp makeFragmentProcessorForImageFilter( + sk_sp dst) const; /** A subclass must implement this factory function to work with the GPU backend. The xfermode will return a factory for which the caller will get a ref. It is up to the caller to install it. XferProcessors cannot use a background texture. */ - virtual GrXPFactory* asXPFactory() const; + virtual sk_sp asXPFactory() const; #endif SK_TO_STRING_PUREVIRT() diff --git a/include/effects/SkColorCubeFilter.h b/include/effects/SkColorCubeFilter.h index 10e370a3af..fbfe698ba8 100644 --- a/include/effects/SkColorCubeFilter.h +++ b/include/effects/SkColorCubeFilter.h @@ -30,7 +30,7 @@ public: uint32_t getFlags() const override; #if SK_SUPPORT_GPU - const GrFragmentProcessor* asFragmentProcessor(GrContext*) const override; + sk_sp asFragmentProcessor(GrContext*) const override; #endif SK_TO_STRING_OVERRIDE() diff --git a/include/effects/SkLumaColorFilter.h b/include/effects/SkLumaColorFilter.h index 3a68607b19..1ffaa733b2 100644 --- a/include/effects/SkLumaColorFilter.h +++ b/include/effects/SkLumaColorFilter.h @@ -9,6 +9,7 @@ #define SkLumaColorFilter_DEFINED #include "SkColorFilter.h" +#include "SkRefCnt.h" /** * Luminance-to-alpha color filter, as defined in @@ -32,7 +33,7 @@ public: void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const override; #if SK_SUPPORT_GPU - const GrFragmentProcessor* asFragmentProcessor(GrContext*) const override; + sk_sp asFragmentProcessor(GrContext*) const override; #endif SK_TO_STRING_OVERRIDE() diff --git a/include/effects/SkPerlinNoiseShader.h b/include/effects/SkPerlinNoiseShader.h index 37d59f264e..ed706c19e8 100644 --- a/include/effects/SkPerlinNoiseShader.h +++ b/include/effects/SkPerlinNoiseShader.h @@ -102,7 +102,7 @@ public: }; #if SK_SUPPORT_GPU - const GrFragmentProcessor* asFragmentProcessor(GrContext* context, const SkMatrix& viewM, + sk_sp asFragmentProcessor(GrContext* context, const SkMatrix& viewM, const SkMatrix*, SkFilterQuality, SkSourceGammaTreatment) const override; #endif diff --git a/include/gpu/GrClip.h b/include/gpu/GrClip.h index e684dfafd7..ce0f155e2f 100644 --- a/include/gpu/GrClip.h +++ b/include/gpu/GrClip.h @@ -22,7 +22,7 @@ class GrPipelineBuilder; class GrAppliedClip : public SkNoncopyable { public: GrAppliedClip() : fHasStencilClip(false) {} - const GrFragmentProcessor* clipCoverageFragmentProcessor() const { + GrFragmentProcessor* getClipCoverageFragmentProcessor() const { return fClipCoverageFP.get(); } const GrScissorState& scissorState() const { return fScissorState; } @@ -40,22 +40,22 @@ public: fHasStencilClip = hasStencil; } - void makeFPBased(sk_sp fp) { + void makeFPBased(sk_sp fp) { fClipCoverageFP = fp; fScissorState.setDisabled(); fHasStencilClip = false; } - void makeScissoredFPBased(sk_sp fp, SkIRect& scissor) { + void makeScissoredFPBased(sk_sp fp, SkIRect& scissor) { fClipCoverageFP = fp; fScissorState.set(scissor); fHasStencilClip = false; } private: - sk_sp fClipCoverageFP; - GrScissorState fScissorState; - bool fHasStencilClip; + sk_sp fClipCoverageFP; + GrScissorState fScissorState; + bool fHasStencilClip; typedef SkNoncopyable INHERITED; }; diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 4e2546b6e2..f9d06f097a 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -457,9 +457,9 @@ private: * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. Otherwise, they * return NULL. They also can perform a swizzle as part of the draw. */ - const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, const GrSwizzle&, + sk_sp createPMToUPMEffect(GrTexture*, const GrSwizzle&, const SkMatrix&) const; - const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, const GrSwizzle&, + sk_sp createUPMToPMEffect(GrTexture*, const GrSwizzle&, const SkMatrix&) const; /** Called before either of the above two functions to determine the appropriate fragment processors for conversions. This must be called by readSurfacePixels before a mutex is diff --git a/include/gpu/GrFragmentProcessor.h b/include/gpu/GrFragmentProcessor.h index c3f291cc5f..b8ebeca303 100644 --- a/include/gpu/GrFragmentProcessor.h +++ b/include/gpu/GrFragmentProcessor.h @@ -31,29 +31,31 @@ public: * does so by returning a parent FP that multiplies the passed in FPs output by the parent's * input alpha. The passed in FP will not receive an input color. */ - static const GrFragmentProcessor* MulOutputByInputAlpha(const GrFragmentProcessor*); + static sk_sp MulOutputByInputAlpha(sk_sp); /** * Similar to the above but it modulates the output r,g,b of the child processor by the input * rgb and then multiplies all the components by the input alpha. This effectively modulates * the child processor's premul color by a unpremul'ed input and produces a premul output */ - static const GrFragmentProcessor* MulOutputByInputUnpremulColor(const GrFragmentProcessor*); + static sk_sp MulOutputByInputUnpremulColor(sk_sp); /** * Returns a parent fragment processor that adopts the passed fragment processor as a child. * The parent will ignore its input color and instead feed the passed in color as input to the * child. */ - static const GrFragmentProcessor* OverrideInput(const GrFragmentProcessor*, GrColor); + static sk_sp OverrideInput(sk_sp, GrColor); /** * Returns a fragment processor that runs the passed in array of fragment processors in a * series. The original input is passed to the first, the first's output is passed to the * second, etc. The output of the returned processor is the output of the last processor of the * series. + * + * The array elements with be moved. */ - static const GrFragmentProcessor* RunInSeries(const GrFragmentProcessor*[], int cnt); + static sk_sp RunInSeries(sk_sp*, int cnt); GrFragmentProcessor() : INHERITED() @@ -155,7 +157,7 @@ protected: * processors will allow the ProgramBuilder to automatically handle their transformed coords and * texture accesses and mangle their uniform and output color names. */ - int registerChildProcessor(const GrFragmentProcessor* child); + int registerChildProcessor(sk_sp child); /** * Subclass implements this to support getConstantColorComponents(...). @@ -187,7 +189,7 @@ private: bool hasSameTransforms(const GrFragmentProcessor&) const; - bool fUsesLocalCoords; + bool fUsesLocalCoords; /** * fCoordTransforms stores the transforms of this proc, followed by all the transforms of this @@ -212,11 +214,16 @@ private: * * The same goes for fTextureAccesses with textures. */ - SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; - int fNumTexturesExclChildren; - int fNumBuffersExclChildren; - int fNumTransformsExclChildren; - SkSTArray<1, const GrFragmentProcessor*, true> fChildProcessors; + SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; + int fNumTexturesExclChildren; + int fNumBuffersExclChildren; + int fNumTransformsExclChildren; + + /** + * This is not SkSTArray<1, sk_sp> because this class holds strong + * references until notifyRefCntIsZero and then it holds pending executions. + */ + SkSTArray<1, GrFragmentProcessor*, true> fChildProcessors; typedef GrProcessor INHERITED; }; diff --git a/include/gpu/GrPaint.h b/include/gpu/GrPaint.h index 7de559ca4c..af408488d7 100644 --- a/include/gpu/GrPaint.h +++ b/include/gpu/GrPaint.h @@ -15,6 +15,7 @@ #include "effects/GrPorterDuffXferProcessor.h" #include "GrFragmentProcessor.h" +#include "SkRefCnt.h" #include "SkRegion.h" #include "SkXfermode.h" @@ -42,7 +43,7 @@ public: GrPaint(const GrPaint& paint) { *this = paint; } - ~GrPaint() { this->resetFragmentProcessors(); } + ~GrPaint() { } /** * The initial color of the drawn primitive. Defaults to solid white. @@ -79,13 +80,12 @@ public: setAllowSRGBInputs(gammaCorrect); } - const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { - fXPFactory.reset(SkSafeRef(xpFactory)); - return xpFactory; + void setXPFactory(sk_sp xpFactory) { + fXPFactory = std::move(xpFactory); } void setPorterDuffXPFactory(SkXfermode::Mode mode) { - fXPFactory.reset(GrPorterDuffXPFactory::Create(mode)); + fXPFactory = GrPorterDuffXPFactory::Make(mode); } void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false); @@ -93,19 +93,17 @@ public: /** * Appends an additional color processor to the color computation. */ - const GrFragmentProcessor* addColorFragmentProcessor(const GrFragmentProcessor* fp) { + void addColorFragmentProcessor(sk_sp fp) { SkASSERT(fp); - fColorFragmentProcessors.push_back(SkRef(fp)); - return fp; + fColorFragmentProcessors.push_back(std::move(fp)); } /** * Appends an additional coverage processor to the coverage computation. */ - const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragmentProcessor* fp) { + void addCoverageFragmentProcessor(sk_sp fp) { SkASSERT(fp); - fCoverageFragmentProcessors.push_back(SkRef(fp)); - return fp; + fCoverageFragmentProcessors.push_back(std::move(fp)); } /** @@ -122,15 +120,15 @@ public: int numTotalFragmentProcessors() const { return this->numColorFragmentProcessors() + this->numCoverageFragmentProcessors(); } - const GrXPFactory* getXPFactory() const { - return fXPFactory; + GrXPFactory* getXPFactory() const { + return fXPFactory.get(); } - const GrFragmentProcessor* getColorFragmentProcessor(int i) const { - return fColorFragmentProcessors[i]; + GrFragmentProcessor* getColorFragmentProcessor(int i) const { + return fColorFragmentProcessors[i].get(); } - const GrFragmentProcessor* getCoverageFragmentProcessor(int i) const { - return fCoverageFragmentProcessors[i]; + GrFragmentProcessor* getCoverageFragmentProcessor(int i) const { + return fCoverageFragmentProcessors[i].get(); } GrPaint& operator=(const GrPaint& paint) { @@ -139,17 +137,10 @@ public: fAllowSRGBInputs = paint.fAllowSRGBInputs; fColor = paint.fColor; - this->resetFragmentProcessors(); fColorFragmentProcessors = paint.fColorFragmentProcessors; fCoverageFragmentProcessors = paint.fCoverageFragmentProcessors; - for (int i = 0; i < fColorFragmentProcessors.count(); ++i) { - fColorFragmentProcessors[i]->ref(); - } - for (int i = 0; i < fCoverageFragmentProcessors.count(); ++i) { - fCoverageFragmentProcessors[i]->ref(); - } - fXPFactory.reset(SkSafeRef(paint.getXPFactory())); + fXPFactory = paint.fXPFactory; return *this; } @@ -163,26 +154,15 @@ public: bool isConstantBlendedColor(GrColor* constantColor) const; private: - void resetFragmentProcessors() { - for (int i = 0; i < fColorFragmentProcessors.count(); ++i) { - fColorFragmentProcessors[i]->unref(); - } - for (int i = 0; i < fCoverageFragmentProcessors.count(); ++i) { - fCoverageFragmentProcessors[i]->unref(); - } - fColorFragmentProcessors.reset(); - fCoverageFragmentProcessors.reset(); - } - - mutable SkAutoTUnref fXPFactory; - SkSTArray<4, const GrFragmentProcessor*, true> fColorFragmentProcessors; - SkSTArray<2, const GrFragmentProcessor*, true> fCoverageFragmentProcessors; + mutable sk_sp fXPFactory; + SkSTArray<4, sk_sp> fColorFragmentProcessors; + SkSTArray<2, sk_sp> fCoverageFragmentProcessors; - bool fAntiAlias; - bool fDisableOutputConversionToSRGB; - bool fAllowSRGBInputs; + bool fAntiAlias; + bool fDisableOutputConversionToSRGB; + bool fAllowSRGBInputs; - GrColor fColor; + GrColor fColor; }; #endif diff --git a/include/gpu/GrProcessorUnitTest.h b/include/gpu/GrProcessorUnitTest.h index bc90204d2a..4f26665cbe 100644 --- a/include/gpu/GrProcessorUnitTest.h +++ b/include/gpu/GrProcessorUnitTest.h @@ -28,7 +28,7 @@ enum { /** This allows parent FPs to implement a test create with known leaf children in order to avoid creating an unbounded FP tree which may overflow various shader limits. */ -const GrFragmentProcessor* CreateChildFP(GrProcessorTestData*); +sk_sp MakeChildFP(GrProcessorTestData*); } @@ -66,28 +66,28 @@ class GrTexture; template class GrProcessorTestFactory : SkNoncopyable { public: - typedef const Processor* (*CreateProc)(GrProcessorTestData*); + typedef sk_sp (*MakeProc)(GrProcessorTestData*); - GrProcessorTestFactory(CreateProc createProc) { - fCreateProc = createProc; + GrProcessorTestFactory(MakeProc makeProc) { + fMakeProc = makeProc; GetFactories()->push_back(this); } /** Pick a random factory function and create a processor. */ - static const Processor* Create(GrProcessorTestData* data) { + static sk_sp Make(GrProcessorTestData* data) { VerifyFactoryCount(); SkASSERT(GetFactories()->count()); uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1); - return CreateIdx(idx, data); + return MakeIdx(idx, data); } /** Number of registered factory functions */ static int Count() { return GetFactories()->count(); } /** Use factory function at Index idx to create a processor. */ - static const Processor* CreateIdx(int idx, GrProcessorTestData* data) { + static sk_sp MakeIdx(int idx, GrProcessorTestData* data) { GrProcessorTestFactory* factory = (*GetFactories())[idx]; - return factory->fCreateProc(data); + return factory->fMakeProc(data); } /* @@ -96,7 +96,7 @@ public: static void VerifyFactoryCount(); private: - CreateProc fCreateProc; + MakeProc fMakeProc; static SkTArray*, true>* GetFactories(); }; @@ -106,15 +106,15 @@ private: */ #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \ static GrProcessorTestFactory gTestFactory SK_UNUSED; \ - static const GrGeometryProcessor* TestCreate(GrProcessorTestData*) + static sk_sp TestCreate(GrProcessorTestData*) #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \ static GrProcessorTestFactory gTestFactory SK_UNUSED; \ - static const GrFragmentProcessor* TestCreate(GrProcessorTestData*) + static sk_sp TestCreate(GrProcessorTestData*) #define GR_DECLARE_XP_FACTORY_TEST \ static GrProcessorTestFactory gTestFactory SK_UNUSED; \ - static const GrXPFactory* TestCreate(GrProcessorTestData*) + static sk_sp TestCreate(GrProcessorTestData*) /** GrProcessor subclasses should insert this macro in their implementation file. They must then * also implement this static function: @@ -134,19 +134,19 @@ private: // The unit test relies on static initializers. Just declare the TestCreate function so that // its definitions will compile. #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \ - static const GrFragmentProcessor* TestCreate(GrProcessorTestData*) + static sk_sp TestCreate(GrProcessorTestData*) #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(X) // The unit test relies on static initializers. Just declare the TestCreate function so that // its definitions will compile. #define GR_DECLARE_XP_FACTORY_TEST \ - static const GrXPFactory* TestCreate(GrProcessorTestData*) + static sk_sp TestCreate(GrProcessorTestData*) #define GR_DEFINE_XP_FACTORY_TEST(X) // The unit test relies on static initializers. Just declare the TestCreate function so that // its definitions will compile. #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \ - static const GrGeometryProcessor* TestCreate(GrProcessorTestData*) + static sk_sp TestCreate(GrProcessorTestData*) #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS diff --git a/include/gpu/GrTypesPriv.h b/include/gpu/GrTypesPriv.h index 6a6fd54c7b..8c7d6bda65 100644 --- a/include/gpu/GrTypesPriv.h +++ b/include/gpu/GrTypesPriv.h @@ -10,6 +10,7 @@ #include "GrTypes.h" #include "SkRect.h" +#include "SkRefCnt.h" /** * Types of shader-language-specific boxed variables we can create. (Currently only GrGLShaderVars, @@ -476,4 +477,9 @@ enum class GrBackendObjectOwnership : bool { kOwned = true }; +template T * const * sk_sp_address_as_pointer_address(sk_sp const * sp) { + static_assert(sizeof(T*) == sizeof(sk_sp), "sk_sp not expected size."); + return reinterpret_cast(sp); +} + #endif diff --git a/include/gpu/effects/GrConstColorProcessor.h b/include/gpu/effects/GrConstColorProcessor.h index 679533eac5..e9781bb22a 100644 --- a/include/gpu/effects/GrConstColorProcessor.h +++ b/include/gpu/effects/GrConstColorProcessor.h @@ -26,8 +26,8 @@ public: }; static const int kInputModeCnt = kLastInputMode + 1; - static GrFragmentProcessor* Create(GrColor color, InputMode mode) { - return new GrConstColorProcessor(color, mode); + static sk_sp Make(GrColor color, InputMode mode) { + return sk_sp(new GrConstColorProcessor(color, mode)); } const char* name() const override { return "Color"; } diff --git a/include/gpu/effects/GrCoverageSetOpXP.h b/include/gpu/effects/GrCoverageSetOpXP.h index 06cc759812..e5d197f338 100644 --- a/include/gpu/effects/GrCoverageSetOpXP.h +++ b/include/gpu/effects/GrCoverageSetOpXP.h @@ -21,7 +21,7 @@ class GrProcOptInfo; */ class GrCoverageSetOpXPFactory : public GrXPFactory { public: - static GrXPFactory* Create(SkRegion::Op regionOp, bool invertCoverage = false); + static sk_sp Make(SkRegion::Op regionOp, bool invertCoverage = false); void getInvariantBlendedColor(const GrProcOptInfo& colorPOI, GrXPFactory::InvariantBlendedColor*) const override; diff --git a/include/gpu/effects/GrCustomXfermode.h b/include/gpu/effects/GrCustomXfermode.h index bcbd5833ca..3bd3214475 100644 --- a/include/gpu/effects/GrCustomXfermode.h +++ b/include/gpu/effects/GrCustomXfermode.h @@ -18,7 +18,7 @@ class GrTexture; */ namespace GrCustomXfermode { bool IsSupportedMode(SkXfermode::Mode mode); - GrXPFactory* CreateXPFactory(SkXfermode::Mode mode); + sk_sp MakeXPFactory(SkXfermode::Mode mode); }; #endif diff --git a/include/gpu/effects/GrPorterDuffXferProcessor.h b/include/gpu/effects/GrPorterDuffXferProcessor.h index 476a039ad2..8399d5805e 100644 --- a/include/gpu/effects/GrPorterDuffXferProcessor.h +++ b/include/gpu/effects/GrPorterDuffXferProcessor.h @@ -16,7 +16,7 @@ class GrProcOptInfo; class GrPorterDuffXPFactory : public GrXPFactory { public: - static GrXPFactory* Create(SkXfermode::Mode mode); + static sk_sp Make(SkXfermode::Mode mode); void getInvariantBlendedColor(const GrProcOptInfo& colorPOI, GrXPFactory::InvariantBlendedColor*) const override; diff --git a/include/gpu/effects/GrXfermodeFragmentProcessor.h b/include/gpu/effects/GrXfermodeFragmentProcessor.h index fb07d003cd..0e2435ea93 100644 --- a/include/gpu/effects/GrXfermodeFragmentProcessor.h +++ b/include/gpu/effects/GrXfermodeFragmentProcessor.h @@ -15,20 +15,20 @@ class GrFragmentProcessor; namespace GrXfermodeFragmentProcessor { /** The color input to the returned processor is treated as the src and the passed in processor is the dst. */ - const GrFragmentProcessor* CreateFromDstProcessor(const GrFragmentProcessor* dst, - SkXfermode::Mode mode); + sk_sp MakeFromDstProcessor(sk_sp dst, + SkXfermode::Mode mode); /** The color input to the returned processor is treated as the dst and the passed in processor is the src. */ - const GrFragmentProcessor* CreateFromSrcProcessor(const GrFragmentProcessor* src, - SkXfermode::Mode mode); + sk_sp MakeFromSrcProcessor(sk_sp src, + SkXfermode::Mode mode); /** Takes the input color, which is assumed to be unpremultiplied, passes it as an opaque color to both src and dst. The outputs of a src and dst are blended using mode and the original input's alpha is applied to the blended color to produce a premul output. */ - const GrFragmentProcessor* CreateFromTwoProcessors(const GrFragmentProcessor* src, - const GrFragmentProcessor* dst, - SkXfermode::Mode mode); + sk_sp MakeFromTwoProcessors(sk_sp src, + sk_sp dst, + SkXfermode::Mode mode); }; #endif diff --git a/include/private/SkTArray.h b/include/private/SkTArray.h index 55d4f86aaa..1fe2c3857c 100644 --- a/include/private/SkTArray.h +++ b/include/private/SkTArray.h @@ -120,6 +120,15 @@ public: } } + /** + * Ensures there is enough reserved space for n elements. + */ + void reserve(int n) { + if (fCount < n) { + this->checkRealloc(n - fCount); + } + } + /** * Resets to a copy of a C array. */ -- cgit v1.2.3