virtual bool isOpaque() const SK_OVERRIDE;
- virtual SkShader::Context* createContext(const SkBitmap& device,
- const SkPaint& paint,
- const SkMatrix& matrix,
- void* storage) const SK_OVERRIDE;
+ virtual SkShader::Context* createContext(const ContextRec&, void* storage) const SK_OVERRIDE;
virtual size_t contextSize() const SK_OVERRIDE {
return sizeof(ColorShaderContext);
class ColorShaderContext : public SkShader::Context {
public:
- ColorShaderContext(const SkColorShader& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix);
+ ColorShaderContext(const SkColorShader& shader, const ContextRec&);
virtual uint32_t getFlags() const SK_OVERRIDE;
virtual uint8_t getSpan16Alpha() const SK_OVERRIDE;
SkComposeShader(SkShader* sA, SkShader* sB, SkXfermode* mode = NULL);
virtual ~SkComposeShader();
- virtual bool validContext(const SkBitmap&, const SkPaint&,
- const SkMatrix&, SkMatrix* totalInverse = NULL) const SK_OVERRIDE;
- virtual SkShader::Context* createContext(const SkBitmap&, const SkPaint&,
- const SkMatrix&, void*) const SK_OVERRIDE;
+ virtual bool validContext(const ContextRec&, SkMatrix* totalInverse = NULL) const SK_OVERRIDE;
+ virtual SkShader::Context* createContext(const ContextRec&, void*) const SK_OVERRIDE;
virtual size_t contextSize() const SK_OVERRIDE;
class ComposeShaderContext : public SkShader::Context {
public:
// When this object gets destroyed, it will call contextA and contextB's destructor
// but it will NOT free the memory.
- ComposeShaderContext(const SkComposeShader&, const SkBitmap&,
- const SkPaint&, const SkMatrix&,
+ ComposeShaderContext(const SkComposeShader&, const ContextRec&,
SkShader::Context* contextA, SkShader::Context* contextB);
SkShader::Context* getShaderContextA() const { return fShaderContextA; }
return sizeof(SkShader::Context);
}
- virtual bool validContext(const SkBitmap&, const SkPaint&,
- const SkMatrix&, SkMatrix* totalInverse = NULL) const SK_OVERRIDE {
+ virtual bool validContext(const ContextRec&, SkMatrix* totalInverse = NULL) const SK_OVERRIDE {
return false;
}
- virtual SkShader::Context* createContext(const SkBitmap&, const SkPaint&,
- const SkMatrix&, void*) const SK_OVERRIDE {
+ virtual SkShader::Context* createContext(const ContextRec&, void*) const SK_OVERRIDE {
// validContext returns false.
return NULL;
}
*/
virtual bool isOpaque() const { return false; }
+ /**
+ * ContextRec acts as a parameter bundle for creating Contexts.
+ */
+ struct ContextRec {
+ ContextRec() : fDevice(NULL), fPaint(NULL), fMatrix(NULL) {}
+ ContextRec(const ContextRec& other)
+ : fDevice(other.fDevice), fPaint(other.fPaint), fMatrix(other.fMatrix) {}
+ ContextRec(const SkBitmap& device, const SkPaint& paint, const SkMatrix& matrix)
+ : fDevice(&device)
+ , fPaint(&paint)
+ , fMatrix(&matrix) {}
+
+ const SkBitmap* fDevice; // the bitmap we are drawing into
+ const SkPaint* fPaint; // the current paint associated with the draw
+ const SkMatrix* fMatrix; // the current matrix in the canvas
+ };
+
class Context : public ::SkNoncopyable {
public:
- Context(const SkShader& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix);
+ Context(const SkShader& shader, const ContextRec&);
virtual ~Context();
* Subclasses should be sure to call their INHERITED::validContext() if
* they override this method.
*/
- virtual bool validContext(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, SkMatrix* totalInverse = NULL) const;
+ virtual bool validContext(const ContextRec&, SkMatrix* totalInverse = NULL) const;
/**
* Create the actual object that does the shading.
*
* Base class implementation returns NULL.
*/
- virtual Context* createContext(const SkBitmap& device,
- const SkPaint& paint,
- const SkMatrix& matrix,
- void* storage) const;
+ virtual Context* createContext(const ContextRec&, void* storage) const;
/**
* Return the size of a Context returned by createContext.
}
- virtual SkShader::Context* createContext(
- const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, void* storage) const SK_OVERRIDE;
+ virtual SkShader::Context* createContext(const ContextRec&, void* storage) const SK_OVERRIDE;
virtual size_t contextSize() const SK_OVERRIDE;
class PerlinNoiseShaderContext : public SkShader::Context {
public:
- PerlinNoiseShaderContext(const SkPerlinNoiseShader& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix);
+ PerlinNoiseShaderContext(const SkPerlinNoiseShader& shader, const ContextRec&);
virtual ~PerlinNoiseShaderContext() {}
virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE;
public:
SkTransparentShader() {}
- virtual SkShader::Context* createContext(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, void* storage) const
+ virtual SkShader::Context* createContext(const ContextRec&, void* storage) const
SK_OVERRIDE;
virtual size_t contextSize() const SK_OVERRIDE;
class TransparentShaderContext : public SkShader::Context {
public:
- TransparentShaderContext(const SkTransparentShader& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix);
+ TransparentShaderContext(const SkTransparentShader& shader, const ContextRec&);
virtual ~TransparentShaderContext();
virtual uint32_t getFlags() const SK_OVERRIDE;
return true;
}
-bool SkBitmapProcShader::validInternal(const SkBitmap& device,
- const SkPaint& paint,
- const SkMatrix& matrix,
- SkMatrix* totalInverse,
+bool SkBitmapProcShader::validInternal(const ContextRec& rec, SkMatrix* totalInverse,
SkBitmapProcState* state) const {
if (!fRawBitmap.getTexture() && !valid_for_drawing(fRawBitmap)) {
return false;
}
// Do this first, so we know the matrix can be inverted.
- if (!this->INHERITED::validContext(device, paint, matrix, totalInverse)) {
+ if (!this->INHERITED::validContext(rec, totalInverse)) {
return false;
}
state->fTileModeX = fTileModeX;
state->fTileModeY = fTileModeY;
state->fOrigBitmap = fRawBitmap;
- return state->chooseProcs(*totalInverse, paint);
+ return state->chooseProcs(*totalInverse, *rec.fPaint);
}
-bool SkBitmapProcShader::validContext(const SkBitmap& device,
- const SkPaint& paint,
- const SkMatrix& matrix,
- SkMatrix* totalInverse) const {
+bool SkBitmapProcShader::validContext(const ContextRec& rec, SkMatrix* totalInverse) const {
SkBitmapProcState state;
- return this->validInternal(device, paint, matrix, totalInverse, &state);
+ return this->validInternal(rec, totalInverse, &state);
}
-SkShader::Context* SkBitmapProcShader::createContext(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, void* storage) const {
+SkShader::Context* SkBitmapProcShader::createContext(const ContextRec& rec, void* storage) const {
void* stateStorage = (char*)storage + sizeof(BitmapProcShaderContext);
SkBitmapProcState* state = SkNEW_PLACEMENT(stateStorage, SkBitmapProcState);
- if (!this->validInternal(device, paint, matrix, NULL, state)) {
+ if (!this->validInternal(rec, NULL, state)) {
state->~SkBitmapProcState();
return NULL;
}
- return SkNEW_PLACEMENT_ARGS(storage, BitmapProcShaderContext,
- (*this, device, paint, matrix, state));
+ return SkNEW_PLACEMENT_ARGS(storage, BitmapProcShaderContext, (*this, rec, state));
}
size_t SkBitmapProcShader::contextSize() const {
}
SkBitmapProcShader::BitmapProcShaderContext::BitmapProcShaderContext(
- const SkBitmapProcShader& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix, SkBitmapProcState* state)
- : INHERITED(shader, device, paint, matrix)
+ const SkBitmapProcShader& shader, const ContextRec& rec, SkBitmapProcState* state)
+ : INHERITED(shader, rec)
, fState(state)
{
const SkBitmap& bitmap = *fState->fBitmap;
break;
}
- if (paint.isDither() && bitmap.colorType() != kRGB_565_SkColorType) {
+ if (rec.fPaint->isDither() && bitmap.colorType() != kRGB_565_SkColorType) {
// gradients can auto-dither in their 16bit sampler, but we don't so
// we clear the flag here.
flags &= ~kHasSpan16_Flag;
virtual bool isOpaque() const SK_OVERRIDE;
virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERRIDE;
- virtual bool validContext(const SkBitmap& device,
- const SkPaint& paint,
- const SkMatrix& matrix,
- SkMatrix* totalInverse = NULL) const SK_OVERRIDE;
- virtual SkShader::Context* createContext(const SkBitmap&, const SkPaint&,
- const SkMatrix&, void* storage) const SK_OVERRIDE;
+ virtual bool validContext(const ContextRec&, SkMatrix* totalInverse) const SK_OVERRIDE;
+ virtual SkShader::Context* createContext(const ContextRec&, void* storage) const SK_OVERRIDE;
virtual size_t contextSize() const SK_OVERRIDE;
static bool CanDo(const SkBitmap&, TileMode tx, TileMode ty);
public:
// The context takes ownership of the state. It will call its destructor
// but will NOT free the memory.
- BitmapProcShaderContext(const SkBitmapProcShader& shader,
- const SkBitmap& device,
- const SkPaint& paint,
- const SkMatrix& matrix,
- SkBitmapProcState* state);
+ BitmapProcShaderContext(const SkBitmapProcShader&, const ContextRec&, SkBitmapProcState*);
virtual ~BitmapProcShaderContext();
virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
uint8_t fTileModeX, fTileModeY;
private:
- bool validInternal(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, SkMatrix* totalInverse,
- SkBitmapProcState* state) const;
+ bool validInternal(const ContextRec&, SkMatrix* totalInverse, SkBitmapProcState*) const;
typedef SkShader INHERITED;
};
return size;
}
- virtual bool validContext(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, SkMatrix* totalInverse = NULL) const
- SK_OVERRIDE
- {
- if (!this->INHERITED::validContext(device, paint, matrix, totalInverse)) {
+ virtual bool validContext(const ContextRec& rec, SkMatrix* totalInverse) const SK_OVERRIDE {
+ if (!this->INHERITED::validContext(rec, totalInverse)) {
return false;
}
if (fProxy) {
- return fProxy->validContext(device, paint, matrix);
+ return fProxy->validContext(rec);
}
return true;
}
- virtual SkShader::Context* createContext(const SkBitmap& device,
- const SkPaint& paint,
- const SkMatrix& matrix,
- void* storage) const SK_OVERRIDE
+ virtual SkShader::Context* createContext(const ContextRec& rec, void* storage) const SK_OVERRIDE
{
- if (!this->validContext(device, paint, matrix)) {
+ if (!this->validContext(rec, NULL)) {
return NULL;
}
SkShader::Context* proxyContext;
if (fProxy) {
char* proxyContextStorage = (char*) storage + sizeof(Sk3DShaderContext);
- proxyContext = fProxy->createContext(device, paint, matrix, proxyContextStorage);
+ proxyContext = fProxy->createContext(rec, proxyContextStorage);
SkASSERT(proxyContext);
} else {
proxyContext = NULL;
}
- return SkNEW_PLACEMENT_ARGS(storage, Sk3DShaderContext, (*this, device, paint, matrix,
- proxyContext));
+ return SkNEW_PLACEMENT_ARGS(storage, Sk3DShaderContext, (*this, rec, proxyContext));
}
class Sk3DShaderContext : public SkShader::Context {
public:
// Calls proxyContext's destructor but will NOT free its memory.
- Sk3DShaderContext(const Sk3DShader& shader, const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, SkShader::Context* proxyContext)
- : INHERITED(shader, device, paint, matrix)
+ Sk3DShaderContext(const Sk3DShader& shader, const ContextRec& rec,
+ SkShader::Context* proxyContext)
+ : INHERITED(shader, rec)
, fMask(NULL)
, fProxyContext(proxyContext)
{
if (!fProxyContext) {
- fPMColor = SkPreMultiplyColor(paint.getColor());
+ fPMColor = SkPreMultiplyColor(rec.fPaint->getColor());
}
}
*/
SkShader::Context* shaderContext;
if (shader) {
+ SkShader::ContextRec rec(device, *paint, matrix);
// Try to create the ShaderContext
void* storage = allocator->reserveT<SkShader::Context>(shader->contextSize());
- shaderContext = shader->createContext(device, *paint, matrix, storage);
+ shaderContext = shader->createContext(rec, storage);
if (!shaderContext) {
allocator->freeLast();
blitter = allocator->createT<SkNullBlitter>();
bool SkShaderBlitter::resetShaderContext(const SkBitmap& device, const SkPaint& paint,
const SkMatrix& matrix) {
- if (!fShader->validContext(device, paint, matrix)) {
+ SkShader::ContextRec rec(device, paint, matrix);
+ if (!fShader->validContext(rec)) {
return false;
}
// The new context will be of the same size as the old one because we use the same
// shader to create it. It is therefore safe to re-use the storage.
fShaderContext->~Context();
- fShaderContext = fShader->createContext(device, paint, matrix, (void*)fShaderContext);
+ fShaderContext = fShader->createContext(rec, (void*)fShaderContext);
SkASSERT(fShaderContext);
return true;
really is translucent, then we apply that after the fact.
*/
-bool SkComposeShader::validContext(const SkBitmap& device,
- const SkPaint& paint,
- const SkMatrix& matrix,
- SkMatrix* totalInverse) const {
- if (!this->INHERITED::validContext(device, paint, matrix, totalInverse)) {
+bool SkComposeShader::validContext(const ContextRec& rec, SkMatrix* totalInverse) const {
+ if (!this->INHERITED::validContext(rec, totalInverse)) {
return false;
}
// before calling our sub-shaders
SkMatrix tmpM;
+ tmpM.setConcat(*rec.fMatrix, this->getLocalMatrix());
- tmpM.setConcat(matrix, this->getLocalMatrix());
+ ContextRec newRec(rec);
+ newRec.fMatrix = &tmpM;
- return fShaderA->validContext(device, paint, tmpM) &&
- fShaderB->validContext(device, paint, tmpM);
+ return fShaderA->validContext(newRec) && fShaderB->validContext(newRec);
}
-SkShader::Context* SkComposeShader::createContext(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, void* storage) const {
- if (!this->validContext(device, paint, matrix)) {
+SkShader::Context* SkComposeShader::createContext(const ContextRec& rec, void* storage) const {
+ if (!this->validContext(rec)) {
return NULL;
}
- // we preconcat our localMatrix (if any) with the device matrix
- // before calling our sub-shaders
-
- SkMatrix tmpM;
-
- tmpM.setConcat(matrix, this->getLocalMatrix());
-
- SkAutoAlphaRestore restore(const_cast<SkPaint*>(&paint), 0xFF);
+ // TODO : must fix this to not "cheat" and modify fPaint
+ SkAutoAlphaRestore restore(const_cast<SkPaint*>(rec.fPaint), 0xFF);
char* aStorage = (char*) storage + sizeof(ComposeShaderContext);
char* bStorage = aStorage + fShaderA->contextSize();
- SkShader::Context* contextA = fShaderA->createContext(device, paint, tmpM, aStorage);
- SkShader::Context* contextB = fShaderB->createContext(device, paint, tmpM, bStorage);
+ // we preconcat our localMatrix (if any) with the device matrix
+ // before calling our sub-shaders
+
+ SkMatrix tmpM;
+ tmpM.setConcat(*rec.fMatrix, this->getLocalMatrix());
+
+ ContextRec newRec(rec);
+ newRec.fMatrix = &tmpM;
+
+ SkShader::Context* contextA = fShaderA->createContext(newRec, aStorage);
+ SkShader::Context* contextB = fShaderB->createContext(newRec, bStorage);
// Both functions must succeed; otherwise validContext should have returned
// false.
SkASSERT(contextA);
SkASSERT(contextB);
- return SkNEW_PLACEMENT_ARGS(storage, ComposeShaderContext,
- (*this, device, paint, matrix, contextA, contextB));
+ return SkNEW_PLACEMENT_ARGS(storage, ComposeShaderContext, (*this, rec, contextA, contextB));
}
SkComposeShader::ComposeShaderContext::ComposeShaderContext(
- const SkComposeShader& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix,
+ const SkComposeShader& shader, const ContextRec& rec,
SkShader::Context* contextA, SkShader::Context* contextB)
- : INHERITED(shader, device, paint, matrix)
+ : INHERITED(shader, rec)
, fShaderContextA(contextA)
, fShaderContextB(contextB) {}
public:
SkTriColorShader() {}
- virtual SkShader::Context* createContext(
- const SkBitmap&, const SkPaint&, const SkMatrix&, void*) const SK_OVERRIDE;
+ virtual SkShader::Context* createContext(const ContextRec&, void*) const SK_OVERRIDE;
virtual size_t contextSize() const SK_OVERRIDE;
class TriColorShaderContext : public SkShader::Context {
public:
- TriColorShaderContext(const SkTriColorShader& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix);
+ TriColorShaderContext(const SkTriColorShader& shader, const ContextRec&);
virtual ~TriColorShaderContext();
bool setup(const SkPoint pts[], const SkColor colors[], int, int, int);
typedef SkShader INHERITED;
};
-SkShader::Context* SkTriColorShader::createContext(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, void* storage) const {
- if (!this->validContext(device, paint, matrix)) {
+SkShader::Context* SkTriColorShader::createContext(const ContextRec& rec, void* storage) const {
+ if (!this->validContext(rec)) {
return NULL;
}
- return SkNEW_PLACEMENT_ARGS(storage, TriColorShaderContext, (*this, device, paint, matrix));
+ return SkNEW_PLACEMENT_ARGS(storage, TriColorShaderContext, (*this, rec));
}
bool SkTriColorShader::TriColorShaderContext::setup(const SkPoint pts[], const SkColor colors[],
}
-SkTriColorShader::TriColorShaderContext::TriColorShaderContext(
- const SkTriColorShader& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix)
- : INHERITED(shader, device, paint, matrix) {}
+SkTriColorShader::TriColorShaderContext::TriColorShaderContext(const SkTriColorShader& shader,
+ const ContextRec& rec)
+ : INHERITED(shader, rec) {}
SkTriColorShader::TriColorShaderContext::~TriColorShaderContext() {}
return shaderF;
}
-SkShader::Context* SkFilterShader::createContext(const SkBitmap& device,
- const SkPaint& paint,
- const SkMatrix& matrix,
- void* storage) const {
- if (!this->validContext(device, paint, matrix)) {
+SkShader::Context* SkFilterShader::createContext(const ContextRec& rec, void* storage) const {
+ if (!this->validContext(rec, NULL)) {
return NULL;
}
char* shaderContextStorage = (char*)storage + sizeof(FilterShaderContext);
- SkShader::Context* shaderContext = fShader->createContext(device, paint, matrix,
- shaderContextStorage);
+ SkShader::Context* shaderContext = fShader->createContext(rec, shaderContextStorage);
SkASSERT(shaderContext);
- return SkNEW_PLACEMENT_ARGS(storage, FilterShaderContext,
- (*this, shaderContext, device, paint, matrix));
+ return SkNEW_PLACEMENT_ARGS(storage, FilterShaderContext, (*this, shaderContext, rec));
}
size_t SkFilterShader::contextSize() const {
return sizeof(FilterShaderContext) + fShader->contextSize();
}
-bool SkFilterShader::validContext(const SkBitmap& device,
- const SkPaint& paint,
- const SkMatrix& matrix,
- SkMatrix* totalInverse) const {
- return this->INHERITED::validContext(device, paint, matrix, totalInverse) &&
- fShader->validContext(device, paint, matrix);
+bool SkFilterShader::validContext(const ContextRec& rec, SkMatrix* totalInverse) const {
+ return this->INHERITED::validContext(rec, totalInverse) && fShader->validContext(rec);
}
SkFilterShader::FilterShaderContext::FilterShaderContext(const SkFilterShader& filterShader,
SkShader::Context* shaderContext,
- const SkBitmap& device,
- const SkPaint& paint,
- const SkMatrix& matrix)
- : INHERITED(filterShader, device, paint, matrix)
+ const ContextRec& rec)
+ : INHERITED(filterShader, rec)
, fShaderContext(shaderContext) {}
SkFilterShader::FilterShaderContext::~FilterShaderContext() {
SkFilterShader(SkShader* shader, SkColorFilter* filter);
virtual ~SkFilterShader();
- virtual bool validContext(const SkBitmap&, const SkPaint&,
- const SkMatrix&, SkMatrix* totalInverse = NULL) const SK_OVERRIDE;
- virtual SkShader::Context* createContext(const SkBitmap&, const SkPaint&,
- const SkMatrix&, void* storage) const SK_OVERRIDE;
+ virtual bool validContext(const ContextRec&, SkMatrix* totalInverse) const SK_OVERRIDE;
+ virtual SkShader::Context* createContext(const ContextRec&, void* storage) const SK_OVERRIDE;
virtual size_t contextSize() const SK_OVERRIDE;
class FilterShaderContext : public SkShader::Context {
public:
// Takes ownership of shaderContext and calls its destructor.
- FilterShaderContext(const SkFilterShader& filterShader, SkShader::Context* shaderContext,
- const SkBitmap& device, const SkPaint& paint, const SkMatrix& matrix);
+ FilterShaderContext(const SkFilterShader&, SkShader::Context*, const ContextRec&);
virtual ~FilterShaderContext();
virtual uint32_t getFlags() const SK_OVERRIDE;
return fCachedBitmapShader;
}
-SkShader* SkPictureShader::validInternal(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, SkMatrix* totalInverse) const {
- if (!this->INHERITED::validContext(device, paint, matrix, totalInverse)) {
+SkShader* SkPictureShader::validInternal(const ContextRec& rec, SkMatrix* totalInverse) const {
+ if (!this->INHERITED::validContext(rec, totalInverse)) {
return NULL;
}
- SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(matrix));
- if (!bitmapShader || !bitmapShader->validContext(device, paint, matrix)) {
+ SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(*rec.fMatrix));
+ if (!bitmapShader || !bitmapShader->validContext(rec)) {
return NULL;
}
return bitmapShader.detach();
}
-bool SkPictureShader::validContext(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, SkMatrix* totalInverse) const {
- SkAutoTUnref<SkShader> shader(this->validInternal(device, paint, matrix, totalInverse));
+bool SkPictureShader::validContext(const ContextRec& rec, SkMatrix* totalInverse) const {
+ SkAutoTUnref<SkShader> shader(this->validInternal(rec, totalInverse));
return shader != NULL;
}
-SkShader::Context* SkPictureShader::createContext(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, void* storage) const {
- SkAutoTUnref<SkShader> bitmapShader(this->validInternal(device, paint, matrix, NULL));
+SkShader::Context* SkPictureShader::createContext(const ContextRec& rec, void* storage) const {
+ SkAutoTUnref<SkShader> bitmapShader(this->validInternal(rec, NULL));
if (!bitmapShader) {
return NULL;
}
- return SkNEW_PLACEMENT_ARGS(storage, PictureShaderContext,
- (*this, device, paint, matrix, bitmapShader.detach()));
+ return SkNEW_PLACEMENT_ARGS(storage, PictureShaderContext, (*this, rec, bitmapShader.detach()));
}
size_t SkPictureShader::contextSize() const {
}
SkPictureShader::PictureShaderContext::PictureShaderContext(
- const SkPictureShader& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix, SkShader* bitmapShader)
- : INHERITED(shader, device, paint, matrix)
+ const SkPictureShader& shader, const ContextRec& rec, SkShader* bitmapShader)
+ : INHERITED(shader, rec)
, fBitmapShader(bitmapShader)
{
SkASSERT(fBitmapShader);
fBitmapShaderContextStorage = sk_malloc_throw(fBitmapShader->contextSize());
- fBitmapShaderContext = fBitmapShader->createContext(
- device, paint, matrix, fBitmapShaderContextStorage);
+ fBitmapShaderContext = fBitmapShader->createContext(rec, fBitmapShaderContextStorage);
SkASSERT(fBitmapShaderContext);
}
static SkPictureShader* Create(SkPicture*, TileMode, TileMode);
virtual ~SkPictureShader();
- virtual bool validContext(const SkBitmap&, const SkPaint&,
- const SkMatrix&, SkMatrix* totalInverse = NULL) const SK_OVERRIDE;
- virtual SkShader::Context* createContext(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, void* storage) const
- SK_OVERRIDE;
+ virtual bool validContext(const ContextRec&, SkMatrix* totalInverse) const SK_OVERRIDE;
+ virtual SkShader::Context* createContext(const ContextRec&, void* storage) const SK_OVERRIDE;
virtual size_t contextSize() const SK_OVERRIDE;
class PictureShaderContext : public SkShader::Context {
public:
- PictureShaderContext(const SkPictureShader& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix,
- SkShader* bitmapShader);
+ PictureShaderContext(const SkPictureShader&, const ContextRec&, SkShader* bitmapShader);
virtual ~PictureShaderContext();
virtual uint32_t getFlags() const SK_OVERRIDE;
private:
SkPictureShader(SkPicture*, TileMode, TileMode);
- SkShader* validInternal(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, SkMatrix* totalInverse) const;
-
+ SkShader* validInternal(const ContextRec&, SkMatrix* totalInverse) const;
SkShader* refBitmapShader(const SkMatrix&) const;
SkPicture* fPicture;
return m->invert(totalInverse);
}
-bool SkShader::validContext(const SkBitmap& device,
- const SkPaint& paint,
- const SkMatrix& matrix,
- SkMatrix* totalInverse) const {
- return this->computeTotalInverse(matrix, totalInverse);
+bool SkShader::validContext(const ContextRec& rec, SkMatrix* totalInverse) const {
+ return this->computeTotalInverse(*rec.fMatrix, totalInverse);
}
-SkShader::Context* SkShader::createContext(const SkBitmap&, const SkPaint&, const SkMatrix&,
- void* storage) const {
+SkShader::Context* SkShader::createContext(const ContextRec&, void* storage) const {
return NULL;
}
return 0;
}
-SkShader::Context::Context(const SkShader& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix)
+SkShader::Context::Context(const SkShader& shader, const ContextRec& rec)
: fShader(shader)
{
- SkASSERT(fShader.validContext(device, paint, matrix));
+ SkASSERT(fShader.validContext(rec));
// Because the context parameters must be valid at this point, we know that the matrix is
// invertible.
- SkAssertResult(fShader.computeTotalInverse(matrix, &fTotalInverse));
+ SkAssertResult(fShader.computeTotalInverse(*rec.fMatrix, &fTotalInverse));
fTotalInverseClass = (uint8_t)ComputeMatrixClass(fTotalInverse);
- fPaintAlpha = paint.getAlpha();
+ fPaintAlpha = rec.fPaint->getAlpha();
}
SkShader::Context::~Context() {}
return SkGetPackedA32(fPMColor);
}
-SkShader::Context* SkColorShader::createContext(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, void* storage) const {
- if (!this->validContext(device, paint, matrix)) {
+SkShader::Context* SkColorShader::createContext(const ContextRec& rec, void* storage) const {
+ if (!this->validContext(rec)) {
return NULL;
}
- return SkNEW_PLACEMENT_ARGS(storage, ColorShaderContext, (*this, device, paint, matrix));
+ return SkNEW_PLACEMENT_ARGS(storage, ColorShaderContext, (*this, rec));
}
SkColorShader::ColorShaderContext::ColorShaderContext(const SkColorShader& shader,
- const SkBitmap& device,
- const SkPaint& paint,
- const SkMatrix& matrix)
- : INHERITED(shader, device, paint, matrix)
+ const ContextRec& rec)
+ : INHERITED(shader, rec)
{
SkColor color = shader.fColor;
- unsigned a = SkAlphaMul(SkColorGetA(color), SkAlpha255To256(paint.getAlpha()));
+ unsigned a = SkAlphaMul(SkColorGetA(color), SkAlpha255To256(rec.fPaint->getAlpha()));
unsigned r = SkColorGetR(color);
unsigned g = SkColorGetG(color);
fFlags = kConstInY32_Flag;
if (255 == a) {
fFlags |= kOpaqueAlpha_Flag;
- if (paint.isDither() == false) {
+ if (rec.fPaint->isDither() == false) {
fFlags |= kHasSpan16_Flag;
}
}
return SkPreMultiplyARGB(rgba[3], rgba[0], rgba[1], rgba[2]);
}
-SkShader::Context* SkPerlinNoiseShader::createContext(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, void* storage) const {
- if (!this->validContext(device, paint, matrix)) {
+SkShader::Context* SkPerlinNoiseShader::createContext(const ContextRec& rec, void* storage) const {
+ if (!this->validContext(rec)) {
return NULL;
}
- return SkNEW_PLACEMENT_ARGS(storage, PerlinNoiseShaderContext, (*this, device, paint, matrix));
+ return SkNEW_PLACEMENT_ARGS(storage, PerlinNoiseShaderContext, (*this, rec));
}
size_t SkPerlinNoiseShader::contextSize() const {
}
SkPerlinNoiseShader::PerlinNoiseShaderContext::PerlinNoiseShaderContext(
- const SkPerlinNoiseShader& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix)
- : INHERITED(shader, device, paint, matrix)
+ const SkPerlinNoiseShader& shader, const ContextRec& rec)
+ : INHERITED(shader, rec)
{
- SkMatrix newMatrix = matrix;
+ SkMatrix newMatrix = *rec.fMatrix;
newMatrix.postConcat(shader.getLocalMatrix());
SkMatrix invMatrix;
if (!newMatrix.invert(&invMatrix)) {
#include "SkColorPriv.h"
#include "SkString.h"
-SkShader::Context* SkTransparentShader::createContext(const SkBitmap& device,
- const SkPaint& paint,
- const SkMatrix& matrix,
- void* storage) const {
- if (!this->validContext(device, paint, matrix)) {
+SkShader::Context* SkTransparentShader::createContext(const ContextRec& rec, void* storage) const {
+ if (!this->validContext(rec)) {
return NULL;
}
- return SkNEW_PLACEMENT_ARGS(storage, TransparentShaderContext, (*this, device, paint, matrix));
+ return SkNEW_PLACEMENT_ARGS(storage, TransparentShaderContext, (*this, rec));
}
size_t SkTransparentShader::contextSize() const {
}
SkTransparentShader::TransparentShaderContext::TransparentShaderContext(
- const SkTransparentShader& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix)
- : INHERITED(shader, device, paint, matrix)
- , fDevice(&device) {}
+ const SkTransparentShader& shader, const ContextRec& rec)
+ : INHERITED(shader, rec)
+ , fDevice(rec.fDevice) {}
SkTransparentShader::TransparentShaderContext::~TransparentShaderContext() {}
}
SkGradientShaderBase::GradientShaderBaseContext::GradientShaderBaseContext(
- const SkGradientShaderBase& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix)
- : INHERITED(shader, device, paint, matrix)
+ const SkGradientShaderBase& shader, const ContextRec& rec)
+ : INHERITED(shader, rec)
, fCache(shader.refCache(getPaintAlpha()))
{
const SkMatrix& inverse = this->getTotalInverse();
class GradientShaderBaseContext : public SkShader::Context {
public:
- GradientShaderBaseContext(const SkGradientShaderBase& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix);
- ~GradientShaderBaseContext() {}
+ GradientShaderBaseContext(const SkGradientShaderBase& shader, const ContextRec&);
virtual uint32_t getFlags() const SK_OVERRIDE { return fFlags; }
return sizeof(LinearGradientContext);
}
-SkShader::Context* SkLinearGradient::createContext(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, void* storage) const {
- if (!this->validContext(device, paint, matrix)) {
+SkShader::Context* SkLinearGradient::createContext(const ContextRec& rec, void* storage) const {
+ if (!this->validContext(rec)) {
return NULL;
}
- return SkNEW_PLACEMENT_ARGS(storage, LinearGradientContext, (*this, device, paint, matrix));
+ return SkNEW_PLACEMENT_ARGS(storage, LinearGradientContext, (*this, rec));
}
SkLinearGradient::LinearGradientContext::LinearGradientContext(
- const SkLinearGradient& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix)
- : INHERITED(shader, device, paint, matrix)
+ const SkLinearGradient& shader, const ContextRec& rec)
+ : INHERITED(shader, rec)
{
unsigned mask = SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask;
if ((fDstToIndex.getType() & ~mask) == 0) {
// when we dither, we are (usually) not const-in-Y
- if ((fFlags & SkShader::kHasSpan16_Flag) && !paint.isDither()) {
+ if ((fFlags & SkShader::kHasSpan16_Flag) && !rec.fPaint->isDither()) {
// only claim this if we do have a 16bit mode (i.e. none of our
// colors have alpha), and if we are not dithering (which obviously
// is not const in Y).
-
/*
* Copyright 2012 Google Inc.
*
public:
SkLinearGradient(const SkPoint pts[2], const Descriptor&, const SkMatrix* localMatrix);
- virtual SkShader::Context* createContext(const SkBitmap&, const SkPaint&, const SkMatrix&,
- void* storage) const SK_OVERRIDE;
+ virtual SkShader::Context* createContext(const ContextRec&, void* storage) const SK_OVERRIDE;
virtual size_t contextSize() const SK_OVERRIDE;
class LinearGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
public:
- LinearGradientContext(const SkLinearGradient& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix);
+ LinearGradientContext(const SkLinearGradient&, const ContextRec&);
~LinearGradientContext() {}
virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
return sizeof(RadialGradientContext);
}
-SkShader::Context* SkRadialGradient::createContext(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, void* storage) const {
- if (!this->validContext(device, paint, matrix)) {
+SkShader::Context* SkRadialGradient::createContext(const ContextRec& rec, void* storage) const {
+ if (!this->validContext(rec)) {
return NULL;
}
- return SkNEW_PLACEMENT_ARGS(storage, RadialGradientContext, (*this, device, paint, matrix));
+ return SkNEW_PLACEMENT_ARGS(storage, RadialGradientContext, (*this, rec));
}
SkRadialGradient::RadialGradientContext::RadialGradientContext(
- const SkRadialGradient& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix)
- : INHERITED(shader, device, paint, matrix) {}
+ const SkRadialGradient& shader, const ContextRec& rec)
+ : INHERITED(shader, rec) {}
void SkRadialGradient::RadialGradientContext::shadeSpan16(int x, int y, uint16_t* dstCParam,
int count) {
SkRadialGradient(const SkPoint& center, SkScalar radius, const Descriptor&,
const SkMatrix* localMatrix);
- virtual SkShader::Context* createContext(const SkBitmap&, const SkPaint&, const SkMatrix&,
- void* storage) const SK_OVERRIDE;
+ virtual SkShader::Context* createContext(const ContextRec&, void* storage) const SK_OVERRIDE;
virtual size_t contextSize() const SK_OVERRIDE;
class RadialGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
public:
- RadialGradientContext(const SkRadialGradient& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix);
- ~RadialGradientContext() {}
+ RadialGradientContext(const SkRadialGradient&, const ContextRec&);
virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE;
return sizeof(SweepGradientContext);
}
-SkShader::Context* SkSweepGradient::createContext(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, void* storage) const {
- if (!this->validContext(device, paint, matrix)) {
+SkShader::Context* SkSweepGradient::createContext(const ContextRec& rec, void* storage) const {
+ if (!this->validContext(rec)) {
return NULL;
}
- return SkNEW_PLACEMENT_ARGS(storage, SweepGradientContext, (*this, device, paint, matrix));
+ return SkNEW_PLACEMENT_ARGS(storage, SweepGradientContext, (*this, rec));
}
SkSweepGradient::SweepGradientContext::SweepGradientContext(
- const SkSweepGradient& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix)
- : INHERITED(shader, device, paint, matrix) {}
+ const SkSweepGradient& shader, const ContextRec& rec)
+ : INHERITED(shader, rec) {}
// returns angle in a circle [0..2PI) -> [0..255]
static unsigned SkATan2_255(float y, float x) {
SkSweepGradient(SkScalar cx, SkScalar cy, const Descriptor&,
const SkMatrix* localMatrix);
- virtual SkShader::Context* createContext(const SkBitmap&, const SkPaint&, const SkMatrix&,
- void* storage) const SK_OVERRIDE;
+ virtual SkShader::Context* createContext(const ContextRec&, void* storage) const SK_OVERRIDE;
virtual size_t contextSize() const SK_OVERRIDE;
class SweepGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
public:
- SweepGradientContext(const SkSweepGradient& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix);
- ~SweepGradientContext() {}
+ SweepGradientContext(const SkSweepGradient& shader, const ContextRec&);
virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE;
return sizeof(TwoPointConicalGradientContext);
}
-SkShader::Context* SkTwoPointConicalGradient::createContext(
- const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, void* storage) const {
- if (!this->validContext(device, paint, matrix)) {
+SkShader::Context* SkTwoPointConicalGradient::createContext(const ContextRec& rec,
+ void* storage) const {
+ if (!this->validContext(rec)) {
return NULL;
}
- return SkNEW_PLACEMENT_ARGS(storage, TwoPointConicalGradientContext,
- (*this, device, paint, matrix));
+ return SkNEW_PLACEMENT_ARGS(storage, TwoPointConicalGradientContext, (*this, rec));
}
SkTwoPointConicalGradient::TwoPointConicalGradientContext::TwoPointConicalGradientContext(
- const SkTwoPointConicalGradient& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix)
- : INHERITED(shader, device, paint, matrix)
+ const SkTwoPointConicalGradient& shader, const ContextRec& rec)
+ : INHERITED(shader, rec)
{
// we don't have a span16 proc
fFlags &= ~kHasSpan16_Flag;
const SkMatrix* localMatrix);
- virtual SkShader::Context* createContext(const SkBitmap&, const SkPaint&, const SkMatrix&,
- void* storage) const SK_OVERRIDE;
+ virtual SkShader::Context* createContext(const ContextRec&, void* storage) const SK_OVERRIDE;
virtual size_t contextSize() const SK_OVERRIDE;
class TwoPointConicalGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
public:
- TwoPointConicalGradientContext(const SkTwoPointConicalGradient& shader,
- const SkBitmap& device,
- const SkPaint& paint,
- const SkMatrix& matrix);
+ TwoPointConicalGradientContext(const SkTwoPointConicalGradient&, const ContextRec&);
~TwoPointConicalGradientContext() {}
virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
return sizeof(TwoPointRadialGradientContext);
}
-bool SkTwoPointRadialGradient::validContext(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, SkMatrix* totalInverse) const {
+bool SkTwoPointRadialGradient::validContext(const ContextRec& rec, SkMatrix* totalInverse) const {
// For now, we might have divided by zero, so detect that.
if (0 == fDiffRadius) {
return false;
}
- return this->INHERITED::validContext(device, paint, matrix, totalInverse);
+ return this->INHERITED::validContext(rec, totalInverse);
}
-SkShader::Context* SkTwoPointRadialGradient::createContext(
- const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix, void* storage) const {
- if (!this->validContext(device, paint, matrix)) {
+SkShader::Context* SkTwoPointRadialGradient::createContext(const ContextRec& rec,
+ void* storage) const {
+ if (!this->validContext(rec, NULL)) {
return NULL;
}
- return SkNEW_PLACEMENT_ARGS(storage, TwoPointRadialGradientContext,
- (*this, device, paint, matrix));
+ return SkNEW_PLACEMENT_ARGS(storage, TwoPointRadialGradientContext, (*this, rec));
}
SkTwoPointRadialGradient::TwoPointRadialGradientContext::TwoPointRadialGradientContext(
- const SkTwoPointRadialGradient& shader, const SkBitmap& device,
- const SkPaint& paint, const SkMatrix& matrix)
- : INHERITED(shader, device, paint, matrix)
+ const SkTwoPointRadialGradient& shader, const ContextRec& rec)
+ : INHERITED(shader, rec)
{
// we don't have a span16 proc
fFlags &= ~kHasSpan16_Flag;
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
-
virtual size_t contextSize() const SK_OVERRIDE;
- virtual bool validContext(const SkBitmap&, const SkPaint&,
- const SkMatrix&, SkMatrix* totalInverse = NULL) const SK_OVERRIDE;
- virtual SkShader::Context* createContext(const SkBitmap&, const SkPaint&, const SkMatrix&,
- void* storage) const SK_OVERRIDE;
+ virtual bool validContext(const ContextRec&, SkMatrix* totalInverse) const SK_OVERRIDE;
+ virtual SkShader::Context* createContext(const ContextRec&, void* storage) const SK_OVERRIDE;
class TwoPointRadialGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
public:
- TwoPointRadialGradientContext(const SkTwoPointRadialGradient& shader,
- const SkBitmap& device,
- const SkPaint& paint,
- const SkMatrix& matrix);
- ~TwoPointRadialGradientContext() {}
+ TwoPointRadialGradientContext(const SkTwoPointRadialGradient&, const ContextRec&);
virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;