Skip to content

Commit

Permalink
Revert of Change SkShader;asFragmentProcessor signature to no longer …
Browse files Browse the repository at this point in the history
…take skpaint\grcolor* (patchset #8 id:140001 of https://codereview.chromium.org/1316513002/ )

Reason for revert:
Primary suspect in failing DEPS rolls:
* https://codereview.chromium.org/1315753006
* https://codereview.chromium.org/1308323006
* https://codereview.chromium.org/1320903004

Primary suspect because the failing win bots did not fail in https://codereview.chromium.org/1315753005

Original issue's description:
> Change SkShader;asFragmentProcessor signature to no longer take skpaint\grcolor*
>
> Committed: https://skia.googlesource.com/skia/+/ecfdc251be71f3d634e76afdd6375bf55fc061aa

TBR=joshualitt@google.com,wangyix@google.com,robertphillips@google.com,bsalomon@google.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Review URL: https://codereview.chromium.org/1313573005
  • Loading branch information
rmistry authored and Commit bot committed Aug 29, 2015
1 parent ecfdc25 commit a511e6a
Show file tree
Hide file tree
Showing 62 changed files with 442 additions and 370 deletions.
17 changes: 10 additions & 7 deletions gm/dcshader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#if SK_SUPPORT_GPU
#include "GrFragmentProcessor.h"
#include "GrCoordTransform.h"
#include "effects/GrExtractAlphaFragmentProcessor.h"
#include "gl/GrGLProcessor.h"
#include "gl/builders/GrGLProgramBuilder.h"
#include "Resources.h"
Expand All @@ -34,8 +33,9 @@ class DCShader : public SkShader {
buf.writeMatrix(fDeviceMatrix);
}

const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& viewM,
const SkMatrix* localMatrix, SkFilterQuality, GrProcessorDataManager*) const override;
bool asFragmentProcessor(GrContext*, const SkPaint& paint, const SkMatrix& viewM,
const SkMatrix* localMatrix, GrColor* color, GrProcessorDataManager*,
GrFragmentProcessor** fp) const override;

#ifndef SK_IGNORE_TO_STRING
void toString(SkString* str) const override {
Expand Down Expand Up @@ -94,10 +94,13 @@ class DCFP : public GrFragmentProcessor {
GrCoordTransform fDeviceTransform;
};

const GrFragmentProcessor* DCShader::asFragmentProcessor(GrContext*, const SkMatrix& viewM,
const SkMatrix* localMatrix, SkFilterQuality, GrProcessorDataManager* procDataManager) const {
SkAutoTUnref<const GrFragmentProcessor> inner(new DCFP(procDataManager, fDeviceMatrix));
return GrExtractAlphaFragmentProcessor::Create(inner);
bool DCShader::asFragmentProcessor(GrContext*, const SkPaint& paint, const SkMatrix& viewM,
const SkMatrix* localMatrix, GrColor* color,
GrProcessorDataManager* procDataManager,
GrFragmentProcessor** fp) const {
*fp = new DCFP(procDataManager, fDeviceMatrix);
*color = GrColorPackA4(paint.getAlpha());
return true;
}

class DCShaderGM : public GM {
Expand Down
2 changes: 0 additions & 2 deletions gyp/gpu.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
'<(skia_include_path)/gpu/effects/GrConstColorProcessor.h',
'<(skia_include_path)/gpu/effects/GrCoverageSetOpXP.h',
'<(skia_include_path)/gpu/effects/GrCustomXfermode.h',
'<(skia_include_path)/gpu/effects/GrExtractAlphaFragmentProcessor.h',
'<(skia_include_path)/gpu/effects/GrPorterDuffXferProcessor.h',

'<(skia_include_path)/gpu/gl/GrGLConfig.h',
Expand Down Expand Up @@ -250,7 +249,6 @@
'<(skia_src_path)/gpu/effects/GrConfigConversionEffect.cpp',
'<(skia_src_path)/gpu/effects/GrConfigConversionEffect.h',
'<(skia_src_path)/gpu/effects/GrConstColorProcessor.cpp',
'<(skia_src_path)/gpu/effects/GrExtractAlphaFragmentProcessor.cpp',
'<(skia_src_path)/gpu/effects/GrCoverageSetOpXP.cpp',
'<(skia_src_path)/gpu/effects/GrCustomXfermode.cpp',
'<(skia_src_path)/gpu/effects/GrCustomXfermodePriv.h',
Expand Down
29 changes: 18 additions & 11 deletions include/core/SkShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,20 +334,27 @@ class SK_API SkShader : public SkFlattenable {


/**
* Returns a GrFragmentProcessor that implements the shader for the GPU backend. NULL is
* returned if there is no GPU implementation.
* 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.
*
* The GPU device does not call SkShader::createContext(), instead we pass the view matrix,
* local matrix, and filter quality directly.
* 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 GrContext may be used by the to create textures that are required by the returned
* processor.
* 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.
*/
virtual const GrFragmentProcessor* asFragmentProcessor(GrContext*,
const SkMatrix& viewMatric,
const SkMatrix* localMatrix,
SkFilterQuality,
GrProcessorDataManager*) const;
virtual bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix& viewM,
const SkMatrix* localMatrix, GrColor*,
GrProcessorDataManager*, GrFragmentProcessor**) const;

/**
* If the shader can represent its "average" luminance in a single color, return true and
Expand Down
8 changes: 3 additions & 5 deletions include/effects/SkPerlinNoiseShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,9 @@ class SK_API SkPerlinNoiseShader : public SkShader {
typedef SkShader::Context INHERITED;
};

#if SK_SUPPORT_GPU
const GrFragmentProcessor* asFragmentProcessor(GrContext* context, const SkMatrix& viewM,
const SkMatrix*, SkFilterQuality,
GrProcessorDataManager*) const override;
#endif
virtual bool asFragmentProcessor(GrContext* context, const SkPaint&, const SkMatrix& viewM,
const SkMatrix*, GrColor*, GrProcessorDataManager*,
GrFragmentProcessor**) const override;

SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPerlinNoiseShader)
Expand Down
5 changes: 1 addition & 4 deletions include/gpu/GrFragmentProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#define GrFragmentProcessor_DEFINED

#include "GrProcessor.h"
#include "GrInvariantOutput.h"

class GrCoordTransform;
class GrGLSLCaps;
Expand Down Expand Up @@ -83,9 +82,7 @@ class GrFragmentProcessor : public GrProcessor {
* 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 {
this->onComputeInvariantOutput(inout);
}
void computeInvariantOutput(GrInvariantOutput* inout) const;

protected:
void addTextureAccess(const GrTextureAccess* textureAccess) override;
Expand Down
16 changes: 8 additions & 8 deletions include/gpu/GrProcessorUnitTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ template <class Processor>
class GrProcessorTestFactory : SkNoncopyable {
public:

typedef const Processor* (*CreateProc)(GrProcessorTestData*);
typedef Processor* (*CreateProc)(GrProcessorTestData*);

GrProcessorTestFactory(CreateProc createProc) {
fCreateProc = createProc;
GetFactories()->push_back(this);
}

static const Processor* CreateStage(GrProcessorTestData* data) {
static Processor* CreateStage(GrProcessorTestData* data) {
VerifyFactoryCount();
SkASSERT(GetFactories()->count());
uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1);
Expand All @@ -92,15 +92,15 @@ class GrProcessorTestFactory : SkNoncopyable {
*/
#define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \
static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory SK_UNUSED; \
static const GrGeometryProcessor* TestCreate(GrProcessorTestData*)
static GrGeometryProcessor* TestCreate(GrProcessorTestData*)

#define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \
static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory SK_UNUSED; \
static const GrFragmentProcessor* TestCreate(GrProcessorTestData*)
static GrFragmentProcessor* TestCreate(GrProcessorTestData*)

#define GR_DECLARE_XP_FACTORY_TEST \
static GrProcessorTestFactory<GrXPFactory> gTestFactory SK_UNUSED; \
static const GrXPFactory* TestCreate(GrProcessorTestData*)
static GrXPFactory* TestCreate(GrProcessorTestData*)


/** GrProcessor subclasses should insert this macro in their implementation file. They must then
Expand All @@ -121,19 +121,19 @@ class GrProcessorTestFactory : SkNoncopyable {
// 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 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 const GrXPFactory* TestCreate(GrProcessorTestData*)
static 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 const GrGeometryProcessor* TestCreate(GrProcessorTestData*)
static GrGeometryProcessor* TestCreate(GrProcessorTestData*)
#define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X)

#endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
Expand Down
4 changes: 4 additions & 0 deletions include/gpu/effects/GrConstColorProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#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
Expand All @@ -30,6 +32,8 @@ class GrConstColorProcessor : public GrFragmentProcessor {
return new GrConstColorProcessor(color, mode);
}

~GrConstColorProcessor() override {}

const char* name() const override { return "Color"; }

GrColor color() const { return fColor; }
Expand Down
45 changes: 0 additions & 45 deletions include/gpu/effects/GrExtractAlphaFragmentProcessor.h

This file was deleted.

41 changes: 25 additions & 16 deletions src/core/SkBitmapProcShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#if SK_SUPPORT_GPU
#include "effects/GrBicubicEffect.h"
#include "effects/GrExtractAlphaFragmentProcessor.h"
#include "effects/GrSimpleTextureEffect.h"
#endif

Expand Down Expand Up @@ -354,21 +353,22 @@ void SkBitmapProcShader::toString(SkString* str) const {
#include "SkGr.h"
#include "effects/GrSimpleTextureEffect.h"

const GrFragmentProcessor* SkBitmapProcShader::asFragmentProcessor(GrContext* context,
const SkMatrix& viewM, const SkMatrix* localMatrix,
SkFilterQuality filterQuality,
GrProcessorDataManager* procDataManager) const {
bool SkBitmapProcShader::asFragmentProcessor(GrContext* context, const SkPaint& paint,
const SkMatrix& viewM,
const SkMatrix* localMatrix, GrColor* paintColor,
GrProcessorDataManager* procDataManager,
GrFragmentProcessor** fp) const {
SkMatrix matrix;
matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height());

SkMatrix lmInverse;
if (!this->getLocalMatrix().invert(&lmInverse)) {
return nullptr;
return false;
}
if (localMatrix) {
SkMatrix inv;
if (!localMatrix->invert(&inv)) {
return nullptr;
return false;
}
lmInverse.postConcat(inv);
}
Expand All @@ -385,28 +385,37 @@ const GrFragmentProcessor* SkBitmapProcShader::asFragmentProcessor(GrContext* co
// are provided by the caller.
bool doBicubic;
GrTextureParams::FilterMode textureFilterMode =
GrSkFilterQualityToGrFilterMode(filterQuality, viewM, this->getLocalMatrix(),
GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewM, this->getLocalMatrix(),
&doBicubic);
GrTextureParams params(tm, textureFilterMode);
SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, fRawBitmap, &params));

if (!texture) {
SkErrorInternals::SetError( kInternalError_SkError,
"Couldn't convert bitmap to texture.");
return nullptr;
return false;
}

SkAutoTUnref<GrFragmentProcessor> inner;
*paintColor = (kAlpha_8_SkColorType == fRawBitmap.colorType()) ?
SkColor2GrColor(paint.getColor()) :
SkColor2GrColorJustAlpha(paint.getColor());

if (doBicubic) {
inner.reset(GrBicubicEffect::Create(procDataManager, texture, matrix, tm));
*fp = GrBicubicEffect::Create(procDataManager, texture, matrix, tm);
} else {
inner.reset(GrSimpleTextureEffect::Create(procDataManager, texture, matrix, params));
*fp = GrSimpleTextureEffect::Create(procDataManager, texture, matrix, params);
}

if (kAlpha_8_SkColorType == fRawBitmap.colorType()) {
return SkRef(inner.get());
}
return GrExtractAlphaFragmentProcessor::Create(inner);
return true;
}

#else

bool SkBitmapProcShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&,
const SkMatrix*, GrColor*, GrProcessorDataManager*,
GrFragmentProcessor**) const {
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
}

#endif
9 changes: 4 additions & 5 deletions src/core/SkBitmapProcShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ class SkBitmapProcShader : public SkShader {
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader)

#if SK_SUPPORT_GPU
const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& viewM,
const SkMatrix*, SkFilterQuality,
GrProcessorDataManager*) const override;
#endif

bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix& viewM, const SkMatrix*,
GrColor*, GrProcessorDataManager*,
GrFragmentProcessor**) const override;

class BitmapProcShaderContext : public SkShader::Context {
public:
Expand Down
8 changes: 3 additions & 5 deletions src/core/SkColorShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ class SK_API SkColorShader : public SkShader {

GradientType asAGradient(GradientInfo* info) const override;

#if SK_SUPPORT_GPU
const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& viewM,
const SkMatrix*, SkFilterQuality,
GrProcessorDataManager*) const override;
#endif
bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix& viewM,
const SkMatrix*, GrColor*, GrProcessorDataManager*,
GrFragmentProcessor**) const override;

SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorShader)
Expand Down
Loading

0 comments on commit a511e6a

Please sign in to comment.