aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2015-08-28 14:33:46 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-08-28 14:33:47 -0700
commitecfdc251be71f3d634e76afdd6375bf55fc061aa (patch)
treef76f15151f9687ec5f5a74ca9cd15830cf4b68fb /include
parent264873d5a8b5b7777684e999aead1da75822e079 (diff)
Change SkShader;asFragmentProcessor signature to no longer take skpaint\grcolor*
Diffstat (limited to 'include')
-rw-r--r--include/core/SkShader.h29
-rw-r--r--include/effects/SkPerlinNoiseShader.h8
-rw-r--r--include/gpu/GrFragmentProcessor.h5
-rw-r--r--include/gpu/GrProcessorUnitTest.h16
-rw-r--r--include/gpu/effects/GrConstColorProcessor.h4
-rw-r--r--include/gpu/effects/GrExtractAlphaFragmentProcessor.h45
6 files changed, 73 insertions, 34 deletions
diff --git a/include/core/SkShader.h b/include/core/SkShader.h
index 47fdc9492f..8aaaf52047 100644
--- a/include/core/SkShader.h
+++ b/include/core/SkShader.h
@@ -334,27 +334,20 @@ public:
/**
- * Returns true if the shader subclass succeeds in creating an effect or if none is required.
- * False is returned if it fails or if there is not an implementation of this method in the
- * shader subclass.
+ * Returns a GrFragmentProcessor that implements the shader for the GPU backend. NULL is
+ * returned if there is no GPU implementation.
*
- * On success an implementation of this method must inspect the SkPaint and set paintColor to
- * the color the effect expects as its input color. If the SkShader wishes to emit a solid
- * color then it should set paintColor to that color and not create an effect. Note that
- * GrColor is always premul. The common patterns are to convert paint's SkColor to GrColor or
- * to extract paint's alpha and replicate it to all channels in paintColor. Upon failure
- * paintColor should not be modified. It is not recommended to specialize the effect to
- * the paint's color as then many GPU shaders may be generated.
+ * The GPU device does not call SkShader::createContext(), instead we pass the view matrix,
+ * local matrix, and filter quality directly.
*
- * The GrContext may be used by the effect to create textures. The GPU device does not
- * call createContext. Instead we pass the SkPaint here in case the shader needs paint info.
- *
- * A view matrix is always required to create the correct GrFragmentProcessor. Some shaders
- * may also use the optional localMatrix to define a matrix relevant only for sampling.
+ * The GrContext may be used by the to create textures that are required by the returned
+ * processor.
*/
- virtual bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix& viewM,
- const SkMatrix* localMatrix, GrColor*,
- GrProcessorDataManager*, GrFragmentProcessor**) const;
+ virtual const GrFragmentProcessor* asFragmentProcessor(GrContext*,
+ const SkMatrix& viewMatric,
+ const SkMatrix* localMatrix,
+ SkFilterQuality,
+ GrProcessorDataManager*) const;
/**
* If the shader can represent its "average" luminance in a single color, return true and
diff --git a/include/effects/SkPerlinNoiseShader.h b/include/effects/SkPerlinNoiseShader.h
index f548c674e2..1caece6f20 100644
--- a/include/effects/SkPerlinNoiseShader.h
+++ b/include/effects/SkPerlinNoiseShader.h
@@ -96,9 +96,11 @@ public:
typedef SkShader::Context INHERITED;
};
- virtual bool asFragmentProcessor(GrContext* context, const SkPaint&, const SkMatrix& viewM,
- const SkMatrix*, GrColor*, GrProcessorDataManager*,
- GrFragmentProcessor**) const override;
+#if SK_SUPPORT_GPU
+ const GrFragmentProcessor* asFragmentProcessor(GrContext* context, const SkMatrix& viewM,
+ const SkMatrix*, SkFilterQuality,
+ GrProcessorDataManager*) const override;
+#endif
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPerlinNoiseShader)
diff --git a/include/gpu/GrFragmentProcessor.h b/include/gpu/GrFragmentProcessor.h
index 9c9f05acdb..3fc87c0de7 100644
--- a/include/gpu/GrFragmentProcessor.h
+++ b/include/gpu/GrFragmentProcessor.h
@@ -9,6 +9,7 @@
#define GrFragmentProcessor_DEFINED
#include "GrProcessor.h"
+#include "GrInvariantOutput.h"
class GrCoordTransform;
class GrGLSLCaps;
@@ -82,7 +83,9 @@ public:
* inout to indicate known values of its output. A component of the color member only has
* meaning if the corresponding bit in validFlags is set.
*/
- void computeInvariantOutput(GrInvariantOutput* inout) const;
+ void computeInvariantOutput(GrInvariantOutput* inout) const {
+ this->onComputeInvariantOutput(inout);
+ }
protected:
void addTextureAccess(const GrTextureAccess* textureAccess) override;
diff --git a/include/gpu/GrProcessorUnitTest.h b/include/gpu/GrProcessorUnitTest.h
index 3a2457e98c..66ba239602 100644
--- a/include/gpu/GrProcessorUnitTest.h
+++ b/include/gpu/GrProcessorUnitTest.h
@@ -61,14 +61,14 @@ template <class Processor>
class GrProcessorTestFactory : SkNoncopyable {
public:
- typedef Processor* (*CreateProc)(GrProcessorTestData*);
+ typedef const Processor* (*CreateProc)(GrProcessorTestData*);
GrProcessorTestFactory(CreateProc createProc) {
fCreateProc = createProc;
GetFactories()->push_back(this);
}
- static Processor* CreateStage(GrProcessorTestData* data) {
+ static const Processor* CreateStage(GrProcessorTestData* data) {
VerifyFactoryCount();
SkASSERT(GetFactories()->count());
uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1);
@@ -92,15 +92,15 @@ private:
*/
#define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \
static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory SK_UNUSED; \
- static GrGeometryProcessor* TestCreate(GrProcessorTestData*)
+ static const GrGeometryProcessor* TestCreate(GrProcessorTestData*)
#define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \
static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory SK_UNUSED; \
- static GrFragmentProcessor* TestCreate(GrProcessorTestData*)
+ static const GrFragmentProcessor* TestCreate(GrProcessorTestData*)
#define GR_DECLARE_XP_FACTORY_TEST \
static GrProcessorTestFactory<GrXPFactory> gTestFactory SK_UNUSED; \
- static GrXPFactory* TestCreate(GrProcessorTestData*)
+ static const GrXPFactory* TestCreate(GrProcessorTestData*)
/** GrProcessor subclasses should insert this macro in their implementation file. They must then
@@ -121,19 +121,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 GrFragmentProcessor* TestCreate(GrProcessorTestData*)
+ static const GrFragmentProcessor* 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 GrXPFactory* TestCreate(GrProcessorTestData*)
+ static const GrXPFactory* 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 GrGeometryProcessor* TestCreate(GrProcessorTestData*)
+ static const GrGeometryProcessor* TestCreate(GrProcessorTestData*)
#define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X)
#endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
diff --git a/include/gpu/effects/GrConstColorProcessor.h b/include/gpu/effects/GrConstColorProcessor.h
index ccd28684a5..f5fdb7e35c 100644
--- a/include/gpu/effects/GrConstColorProcessor.h
+++ b/include/gpu/effects/GrConstColorProcessor.h
@@ -10,8 +10,6 @@
#include "GrFragmentProcessor.h"
-class GrInvariantOutput;
-
/**
* This is a simple GrFragmentProcessor that outputs a constant color. It may do one of the
* following with its input color: ignore it, or multiply it by the constant color, multiply its
@@ -32,8 +30,6 @@ public:
return new GrConstColorProcessor(color, mode);
}
- ~GrConstColorProcessor() override {}
-
const char* name() const override { return "Color"; }
GrColor color() const { return fColor; }
diff --git a/include/gpu/effects/GrExtractAlphaFragmentProcessor.h b/include/gpu/effects/GrExtractAlphaFragmentProcessor.h
new file mode 100644
index 0000000000..d26f00f9a9
--- /dev/null
+++ b/include/gpu/effects/GrExtractAlphaFragmentProcessor.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrExtractAlphaFragmentProcessor_DEFINED
+#define GrExtractAlphaFragmentProcessor_DEFINED
+
+#include "GrFragmentProcessor.h"
+
+/** This processor extracts the incoming color's alpha, ignores r, g, and b, and feeds
+ the replicated alpha to it's inner processor. */
+class GrExtractAlphaFragmentProcessor : public GrFragmentProcessor {
+public:
+ static GrFragmentProcessor* Create(const GrFragmentProcessor* processor) {
+ if (!processor) {
+ return nullptr;
+ }
+ return SkNEW_ARGS(GrExtractAlphaFragmentProcessor, (processor));
+ }
+
+ ~GrExtractAlphaFragmentProcessor() override {}
+
+ const char* name() const override { return "Extract Alpha"; }
+
+private:
+ GrExtractAlphaFragmentProcessor(const GrFragmentProcessor* processor) {
+ this->initClassID<GrExtractAlphaFragmentProcessor>();
+ this->registerChildProcessor(processor);
+ }
+
+ GrGLFragmentProcessor* onCreateGLInstance() const override;
+
+ void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override;
+
+ bool onIsEqual(const GrFragmentProcessor&) const override;
+
+ void onComputeInvariantOutput(GrInvariantOutput* inout) const override;
+
+ typedef GrFragmentProcessor INHERITED;
+};
+
+#endif