Remove SkShader virtual method validContext
patch from issue 267923005 BUG=skia: R=scroggo@google.com Author: reed@google.com Review URL: https://codereview.chromium.org/261773005 git-svn-id: http://skia.googlecode.com/svn/trunk@14573 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
58e428729b
commit
ce56d96506
@ -27,8 +27,6 @@ public:
|
||||
|
||||
virtual bool isOpaque() const SK_OVERRIDE;
|
||||
|
||||
virtual SkShader::Context* createContext(const ContextRec&, void* storage) const SK_OVERRIDE;
|
||||
|
||||
virtual size_t contextSize() const SK_OVERRIDE {
|
||||
return sizeof(ColorShaderContext);
|
||||
}
|
||||
@ -64,6 +62,7 @@ public:
|
||||
protected:
|
||||
SkColorShader(SkReadBuffer&);
|
||||
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
|
||||
virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
SkColor fColor; // ignored if fInheritColor is true
|
||||
|
@ -34,8 +34,6 @@ public:
|
||||
SkComposeShader(SkShader* sA, SkShader* sB, SkXfermode* mode = NULL);
|
||||
virtual ~SkComposeShader();
|
||||
|
||||
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 {
|
||||
@ -70,6 +68,7 @@ public:
|
||||
protected:
|
||||
SkComposeShader(SkReadBuffer& );
|
||||
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
|
||||
virtual Context* onCreateContext(const ContextRec&, void*) const SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
SkShader* fShaderA;
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
@ -6,13 +5,13 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef SkEmptyShader_DEFINED
|
||||
#define SkEmptyShader_DEFINED
|
||||
|
||||
#include "SkShader.h"
|
||||
|
||||
// TODO: move this to private, as there is a public factory on SkShader
|
||||
|
||||
/**
|
||||
* \class SkEmptyShader
|
||||
* A Shader that always draws nothing. Its createContext always returns NULL.
|
||||
@ -27,21 +26,16 @@ public:
|
||||
return sizeof(SkShader::Context);
|
||||
}
|
||||
|
||||
virtual bool validContext(const ContextRec&, SkMatrix* totalInverse = NULL) const SK_OVERRIDE {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual SkShader::Context* createContext(const ContextRec&, void*) const SK_OVERRIDE {
|
||||
// validContext returns false.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkEmptyShader)
|
||||
|
||||
protected:
|
||||
SkEmptyShader(SkReadBuffer& buffer) : INHERITED(buffer) {}
|
||||
|
||||
virtual SkShader::Context* onCreateContext(const ContextRec&, void*) const SK_OVERRIDE {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
typedef SkShader INHERITED;
|
||||
};
|
||||
|
@ -212,21 +212,11 @@ public:
|
||||
typedef SkNoncopyable INHERITED;
|
||||
};
|
||||
|
||||
/**
|
||||
* Subclasses should be sure to call their INHERITED::validContext() if
|
||||
* they override this method.
|
||||
*/
|
||||
virtual bool validContext(const ContextRec&, SkMatrix* totalInverse = NULL) const;
|
||||
|
||||
/**
|
||||
* Create the actual object that does the shading.
|
||||
* Returns NULL if validContext() returns false.
|
||||
* Size of storage must be >= contextSize.
|
||||
* Your subclass must also override contextSize() if it overrides createContext().
|
||||
*
|
||||
* Base class implementation returns NULL.
|
||||
*/
|
||||
virtual Context* createContext(const ContextRec&, void* storage) const;
|
||||
Context* createContext(const ContextRec&, void* storage) const;
|
||||
|
||||
/**
|
||||
* Return the size of a Context returned by createContext.
|
||||
@ -374,6 +364,11 @@ public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Factory methods for stock shaders
|
||||
|
||||
/**
|
||||
* Call this to create a new "empty" shader, that will not draw anything.
|
||||
*/
|
||||
static SkShader* CreateEmptyShader();
|
||||
|
||||
/** Call this to create a new shader that will draw with the specified bitmap.
|
||||
*
|
||||
* If the bitmap cannot be used (e.g. has no pixels, or its dimensions
|
||||
@ -409,14 +404,19 @@ public:
|
||||
SK_DEFINE_FLATTENABLE_TYPE(SkShader)
|
||||
|
||||
protected:
|
||||
|
||||
SkShader(SkReadBuffer& );
|
||||
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
SkMatrix fLocalMatrix;
|
||||
bool computeTotalInverse(const ContextRec&, SkMatrix* totalInverse) const;
|
||||
|
||||
bool computeTotalInverse(const SkMatrix& matrix, SkMatrix* totalInverse) const;
|
||||
/**
|
||||
* Your subclass must also override contextSize() if it overrides onCreateContext().
|
||||
* Base class impl returns NULL.
|
||||
*/
|
||||
virtual Context* onCreateContext(const ContextRec&, void* storage) const;
|
||||
|
||||
private:
|
||||
SkMatrix fLocalMatrix;
|
||||
|
||||
typedef SkFlattenable INHERITED;
|
||||
};
|
||||
|
@ -72,7 +72,6 @@ public:
|
||||
}
|
||||
|
||||
|
||||
virtual SkShader::Context* createContext(const ContextRec&, void* storage) const SK_OVERRIDE;
|
||||
virtual size_t contextSize() const SK_OVERRIDE;
|
||||
|
||||
class PerlinNoiseShaderContext : public SkShader::Context {
|
||||
@ -104,6 +103,7 @@ public:
|
||||
protected:
|
||||
SkPerlinNoiseShader(SkReadBuffer&);
|
||||
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
|
||||
virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
SkPerlinNoiseShader(SkPerlinNoiseShader::Type type, SkScalar baseFrequencyX,
|
||||
|
@ -14,8 +14,6 @@ class SK_API SkTransparentShader : public SkShader {
|
||||
public:
|
||||
SkTransparentShader() {}
|
||||
|
||||
virtual SkShader::Context* createContext(const ContextRec&, void* storage) const
|
||||
SK_OVERRIDE;
|
||||
virtual size_t contextSize() const SK_OVERRIDE;
|
||||
|
||||
class TransparentShaderContext : public SkShader::Context {
|
||||
@ -36,6 +34,9 @@ public:
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTransparentShader)
|
||||
|
||||
protected:
|
||||
virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
SkTransparentShader(SkReadBuffer& buffer) : INHERITED(buffer) {}
|
||||
|
||||
|
@ -97,39 +97,25 @@ static bool valid_for_drawing(const SkBitmap& bm) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkBitmapProcShader::validInternal(const ContextRec& rec, SkMatrix* totalInverse,
|
||||
SkBitmapProcState* state) const {
|
||||
SkShader::Context* SkBitmapProcShader::onCreateContext(const ContextRec& rec, void* storage) const {
|
||||
if (!fRawBitmap.getTexture() && !valid_for_drawing(fRawBitmap)) {
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Make sure we can use totalInverse as a cache.
|
||||
SkMatrix totalInverseLocal;
|
||||
if (NULL == totalInverse) {
|
||||
totalInverse = &totalInverseLocal;
|
||||
}
|
||||
|
||||
|
||||
SkMatrix totalInverse;
|
||||
// Do this first, so we know the matrix can be inverted.
|
||||
if (!this->INHERITED::validContext(rec, totalInverse)) {
|
||||
return false;
|
||||
if (!this->computeTotalInverse(rec, &totalInverse)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* stateStorage = (char*)storage + sizeof(BitmapProcShaderContext);
|
||||
SkBitmapProcState* state = SkNEW_PLACEMENT(stateStorage, SkBitmapProcState);
|
||||
|
||||
SkASSERT(state);
|
||||
state->fTileModeX = fTileModeX;
|
||||
state->fTileModeY = fTileModeY;
|
||||
state->fOrigBitmap = fRawBitmap;
|
||||
return state->chooseProcs(*totalInverse, *rec.fPaint);
|
||||
}
|
||||
|
||||
bool SkBitmapProcShader::validContext(const ContextRec& rec, SkMatrix* totalInverse) const {
|
||||
SkBitmapProcState state;
|
||||
return this->validInternal(rec, totalInverse, &state);
|
||||
}
|
||||
|
||||
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(rec, NULL, state)) {
|
||||
if (!state->chooseProcs(totalInverse, *rec.fPaint)) {
|
||||
state->~SkBitmapProcState();
|
||||
return NULL;
|
||||
}
|
||||
|
@ -23,8 +23,6 @@ public:
|
||||
virtual bool isOpaque() const SK_OVERRIDE;
|
||||
virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) 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);
|
||||
@ -59,13 +57,12 @@ public:
|
||||
protected:
|
||||
SkBitmapProcShader(SkReadBuffer& );
|
||||
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
|
||||
virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
|
||||
|
||||
SkBitmap fRawBitmap; // experimental for RLE encoding
|
||||
uint8_t fTileModeX, fTileModeY;
|
||||
|
||||
private:
|
||||
bool validInternal(const ContextRec&, SkMatrix* totalInverse, SkBitmapProcState*) const;
|
||||
|
||||
typedef SkShader INHERITED;
|
||||
};
|
||||
|
||||
|
@ -591,29 +591,14 @@ public:
|
||||
return size;
|
||||
}
|
||||
|
||||
virtual bool validContext(const ContextRec& rec, SkMatrix* totalInverse) const SK_OVERRIDE {
|
||||
if (!this->INHERITED::validContext(rec, totalInverse)) {
|
||||
return false;
|
||||
}
|
||||
if (fProxy) {
|
||||
return fProxy->validContext(rec);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual SkShader::Context* createContext(const ContextRec& rec, void* storage) const SK_OVERRIDE
|
||||
{
|
||||
if (!this->validContext(rec, NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkShader::Context* proxyContext;
|
||||
virtual Context* onCreateContext(const ContextRec& rec, void* storage) const SK_OVERRIDE {
|
||||
SkShader::Context* proxyContext = NULL;
|
||||
if (fProxy) {
|
||||
char* proxyContextStorage = (char*) storage + sizeof(Sk3DShaderContext);
|
||||
proxyContext = fProxy->createContext(rec, proxyContextStorage);
|
||||
SkASSERT(proxyContext);
|
||||
} else {
|
||||
proxyContext = NULL;
|
||||
if (!proxyContext) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return SkNEW_PLACEMENT_ARGS(storage, Sk3DShaderContext, (*this, rec, proxyContext));
|
||||
}
|
||||
@ -1016,6 +1001,19 @@ const uint32_t gMask_00FF00FF = 0xFF00FF;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkTransparentShaderContext : public SkShader::Context {
|
||||
public:
|
||||
SkTransparentShaderContext(const SkShader& shader, const SkShader::ContextRec& rec)
|
||||
: INHERITED(shader, rec) {}
|
||||
|
||||
virtual void shadeSpan(int x, int y, SkPMColor colors[], int count) SK_OVERRIDE {
|
||||
sk_bzero(colors, count * sizeof(SkPMColor));
|
||||
}
|
||||
|
||||
private:
|
||||
typedef SkShader::Context INHERITED;
|
||||
};
|
||||
|
||||
SkShaderBlitter::SkShaderBlitter(const SkBitmap& device, const SkPaint& paint,
|
||||
SkShader::Context* shaderContext)
|
||||
: INHERITED(device)
|
||||
@ -1035,9 +1033,6 @@ SkShaderBlitter::~SkShaderBlitter() {
|
||||
bool SkShaderBlitter::resetShaderContext(const SkBitmap& device, const SkPaint& paint,
|
||||
const SkMatrix& matrix) {
|
||||
SkShader::ContextRec rec(device, paint, matrix);
|
||||
if (!fShader->validContext(rec)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only destroy the old context if we have a new one. We need to ensure to have a
|
||||
// live context in fShaderContext because the storage is owned by an SkSmallAllocator
|
||||
@ -1045,8 +1040,11 @@ bool SkShaderBlitter::resetShaderContext(const SkBitmap& device, const SkPaint&
|
||||
// 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(rec, (void*)fShaderContext);
|
||||
SkASSERT(fShaderContext);
|
||||
|
||||
return true;
|
||||
SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext);
|
||||
if (NULL == ctx) {
|
||||
// Need a valid context in fShaderContext's storage, so we can later (or our caller) call
|
||||
// the in-place destructor.
|
||||
SkNEW_PLACEMENT_ARGS(fShaderContext, SkTransparentShaderContext, (*fShader, rec));
|
||||
}
|
||||
return ctx != NULL;
|
||||
}
|
||||
|
@ -73,33 +73,13 @@ void SkComposeShader::flatten(SkWriteBuffer& buffer) const {
|
||||
buffer.writeFlattenable(fMode);
|
||||
}
|
||||
|
||||
/* We call validContext/createContext on our two worker shaders.
|
||||
However, we always let them see opaque alpha, and if the paint
|
||||
really is translucent, then we apply that after the fact.
|
||||
|
||||
*/
|
||||
bool SkComposeShader::validContext(const ContextRec& rec, SkMatrix* totalInverse) const {
|
||||
if (!this->INHERITED::validContext(rec, totalInverse)) {
|
||||
return false;
|
||||
template <typename T> void safe_call_destructor(T* obj) {
|
||||
if (obj) {
|
||||
obj->~T();
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
return fShaderA->validContext(newRec) && fShaderB->validContext(newRec);
|
||||
}
|
||||
|
||||
SkShader::Context* SkComposeShader::createContext(const ContextRec& rec, void* storage) const {
|
||||
if (!this->validContext(rec)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkShader::Context* SkComposeShader::onCreateContext(const ContextRec& rec, void* storage) const {
|
||||
char* aStorage = (char*) storage + sizeof(ComposeShaderContext);
|
||||
char* bStorage = aStorage + fShaderA->contextSize();
|
||||
|
||||
@ -120,11 +100,11 @@ SkShader::Context* SkComposeShader::createContext(const ContextRec& rec, void* s
|
||||
|
||||
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);
|
||||
if (!contextA || !contextB) {
|
||||
safe_call_destructor(contextA);
|
||||
safe_call_destructor(contextB);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return SkNEW_PLACEMENT_ARGS(storage, ComposeShaderContext, (*this, rec, contextA, contextB));
|
||||
}
|
||||
|
@ -2353,7 +2353,6 @@ class SkTriColorShader : public SkShader {
|
||||
public:
|
||||
SkTriColorShader() {}
|
||||
|
||||
virtual SkShader::Context* createContext(const ContextRec&, void*) const SK_OVERRIDE;
|
||||
virtual size_t contextSize() const SK_OVERRIDE;
|
||||
|
||||
class TriColorShaderContext : public SkShader::Context {
|
||||
@ -2378,18 +2377,14 @@ public:
|
||||
protected:
|
||||
SkTriColorShader(SkReadBuffer& buffer) : SkShader(buffer) {}
|
||||
|
||||
virtual Context* onCreateContext(const ContextRec& rec, void* storage) const SK_OVERRIDE {
|
||||
return SkNEW_PLACEMENT_ARGS(storage, TriColorShaderContext, (*this, rec));
|
||||
}
|
||||
|
||||
private:
|
||||
typedef SkShader INHERITED;
|
||||
};
|
||||
|
||||
SkShader::Context* SkTriColorShader::createContext(const ContextRec& rec, void* storage) const {
|
||||
if (!this->validContext(rec)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return SkNEW_PLACEMENT_ARGS(storage, TriColorShaderContext, (*this, rec));
|
||||
}
|
||||
|
||||
bool SkTriColorShader::TriColorShaderContext::setup(const SkPoint pts[], const SkColor colors[],
|
||||
int index0, int index1, int index2) {
|
||||
|
||||
|
@ -55,11 +55,7 @@ uint32_t SkFilterShader::FilterShaderContext::getFlags() const {
|
||||
return shaderF;
|
||||
}
|
||||
|
||||
SkShader::Context* SkFilterShader::createContext(const ContextRec& rec, void* storage) const {
|
||||
if (!this->validContext(rec, NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkShader::Context* SkFilterShader::onCreateContext(const ContextRec& rec, void* storage) const {
|
||||
char* shaderContextStorage = (char*)storage + sizeof(FilterShaderContext);
|
||||
SkShader::Context* shaderContext = fShader->createContext(rec, shaderContextStorage);
|
||||
SkASSERT(shaderContext);
|
||||
@ -71,10 +67,6 @@ size_t SkFilterShader::contextSize() const {
|
||||
return sizeof(FilterShaderContext) + fShader->contextSize();
|
||||
}
|
||||
|
||||
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 ContextRec& rec)
|
||||
|
@ -17,8 +17,6 @@ public:
|
||||
SkFilterShader(SkShader* shader, SkColorFilter* filter);
|
||||
virtual ~SkFilterShader();
|
||||
|
||||
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 {
|
||||
@ -44,6 +42,8 @@ public:
|
||||
protected:
|
||||
SkFilterShader(SkReadBuffer& );
|
||||
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
|
||||
virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
|
||||
|
||||
|
||||
private:
|
||||
SkShader* fShader;
|
||||
|
@ -110,58 +110,55 @@ SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix) const {
|
||||
return fCachedBitmapShader;
|
||||
}
|
||||
|
||||
SkShader* SkPictureShader::validInternal(const ContextRec& rec, SkMatrix* totalInverse) const {
|
||||
if (!this->INHERITED::validContext(rec, totalInverse)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(*rec.fMatrix));
|
||||
if (!bitmapShader || !bitmapShader->validContext(rec)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return bitmapShader.detach();
|
||||
}
|
||||
|
||||
bool SkPictureShader::validContext(const ContextRec& rec, SkMatrix* totalInverse) const {
|
||||
SkAutoTUnref<SkShader> shader(this->validInternal(rec, totalInverse));
|
||||
return shader != 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, rec, bitmapShader.detach()));
|
||||
}
|
||||
|
||||
size_t SkPictureShader::contextSize() const {
|
||||
return sizeof(PictureShaderContext);
|
||||
}
|
||||
|
||||
SkShader::Context* SkPictureShader::onCreateContext(const ContextRec& rec, void* storage) const {
|
||||
SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(*rec.fMatrix));
|
||||
if (NULL == bitmapShader.get()) {
|
||||
return NULL;
|
||||
}
|
||||
return PictureShaderContext::Create(storage, *this, rec, bitmapShader.detach());
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkShader::Context* SkPictureShader::PictureShaderContext::Create(void* storage,
|
||||
const SkPictureShader& shader, const ContextRec& rec, SkShader* bitmapShader) {
|
||||
PictureShaderContext* ctx = SkNEW_PLACEMENT_ARGS(storage, PictureShaderContext,
|
||||
(shader, rec, bitmapShader));
|
||||
if (NULL == ctx->fBitmapShaderContext) {
|
||||
ctx->~PictureShaderContext();
|
||||
ctx = NULL;
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
SkPictureShader::PictureShaderContext::PictureShaderContext(
|
||||
const SkPictureShader& shader, const ContextRec& rec, SkShader* bitmapShader)
|
||||
: INHERITED(shader, rec)
|
||||
, fBitmapShader(bitmapShader)
|
||||
, fBitmapShader(SkRef(bitmapShader))
|
||||
{
|
||||
SkASSERT(fBitmapShader);
|
||||
fBitmapShaderContextStorage = sk_malloc_throw(fBitmapShader->contextSize());
|
||||
fBitmapShaderContext = fBitmapShader->createContext(rec, fBitmapShaderContextStorage);
|
||||
SkASSERT(fBitmapShaderContext);
|
||||
fBitmapShaderContextStorage = sk_malloc_throw(bitmapShader->contextSize());
|
||||
fBitmapShaderContext = bitmapShader->createContext(rec, fBitmapShaderContextStorage);
|
||||
//if fBitmapShaderContext is null, we are invalid
|
||||
}
|
||||
|
||||
SkPictureShader::PictureShaderContext::~PictureShaderContext() {
|
||||
fBitmapShaderContext->~Context();
|
||||
if (fBitmapShaderContext) {
|
||||
fBitmapShaderContext->~Context();
|
||||
}
|
||||
sk_free(fBitmapShaderContextStorage);
|
||||
}
|
||||
|
||||
uint32_t SkPictureShader::PictureShaderContext::getFlags() const {
|
||||
SkASSERT(fBitmapShaderContext);
|
||||
return fBitmapShaderContext->getFlags();
|
||||
}
|
||||
|
||||
SkShader::Context::ShadeProc SkPictureShader::PictureShaderContext::asAShadeProc(void** ctx) {
|
||||
SkASSERT(fBitmapShaderContext);
|
||||
return fBitmapShaderContext->asAShadeProc(ctx);
|
||||
}
|
||||
|
||||
|
@ -24,29 +24,8 @@ public:
|
||||
static SkPictureShader* Create(SkPicture*, TileMode, TileMode, const SkMatrix* = NULL);
|
||||
virtual ~SkPictureShader();
|
||||
|
||||
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&, const ContextRec&, SkShader* bitmapShader);
|
||||
virtual ~PictureShaderContext();
|
||||
|
||||
virtual uint32_t getFlags() const SK_OVERRIDE;
|
||||
|
||||
virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE;
|
||||
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;
|
||||
|
||||
private:
|
||||
SkAutoTUnref<SkShader> fBitmapShader;
|
||||
SkShader::Context* fBitmapShaderContext;
|
||||
void* fBitmapShaderContextStorage;
|
||||
|
||||
typedef SkShader::Context INHERITED;
|
||||
};
|
||||
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureShader)
|
||||
|
||||
@ -57,11 +36,11 @@ public:
|
||||
protected:
|
||||
SkPictureShader(SkReadBuffer&);
|
||||
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
|
||||
virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
SkPictureShader(SkPicture*, TileMode, TileMode, const SkMatrix* = NULL);
|
||||
|
||||
SkShader* validInternal(const ContextRec&, SkMatrix* totalInverse) const;
|
||||
SkShader* refBitmapShader(const SkMatrix&) const;
|
||||
|
||||
SkPicture* fPicture;
|
||||
@ -72,6 +51,29 @@ private:
|
||||
mutable SkSize fCachedTileScale;
|
||||
mutable SkMatrix fCachedLocalMatrix;
|
||||
|
||||
class PictureShaderContext : public SkShader::Context {
|
||||
public:
|
||||
static Context* Create(void* storage, const SkPictureShader&, const ContextRec&,
|
||||
SkShader* bitmapShader);
|
||||
|
||||
virtual ~PictureShaderContext();
|
||||
|
||||
virtual uint32_t getFlags() const SK_OVERRIDE;
|
||||
|
||||
virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE;
|
||||
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;
|
||||
|
||||
private:
|
||||
PictureShaderContext(const SkPictureShader&, const ContextRec&, SkShader* bitmapShader);
|
||||
|
||||
SkAutoTUnref<SkShader> fBitmapShader;
|
||||
SkShader::Context* fBitmapShaderContext;
|
||||
void* fBitmapShaderContextStorage;
|
||||
|
||||
typedef SkShader::Context INHERITED;
|
||||
};
|
||||
|
||||
typedef SkShader INHERITED;
|
||||
};
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "SkBitmapProcShader.h"
|
||||
#include "SkEmptyShader.h"
|
||||
#include "SkReadBuffer.h"
|
||||
#include "SkMallocPixelRef.h"
|
||||
#include "SkPaint.h"
|
||||
@ -44,23 +45,25 @@ void SkShader::flatten(SkWriteBuffer& buffer) const {
|
||||
}
|
||||
}
|
||||
|
||||
bool SkShader::computeTotalInverse(const SkMatrix& matrix, SkMatrix* totalInverse) const {
|
||||
const SkMatrix* m = &matrix;
|
||||
bool SkShader::computeTotalInverse(const ContextRec& rec, SkMatrix* totalInverse) const {
|
||||
const SkMatrix* m = rec.fMatrix;
|
||||
SkMatrix total;
|
||||
|
||||
if (this->hasLocalMatrix()) {
|
||||
total.setConcat(matrix, this->getLocalMatrix());
|
||||
total.setConcat(*m, this->getLocalMatrix());
|
||||
m = &total;
|
||||
}
|
||||
|
||||
return m->invert(totalInverse);
|
||||
}
|
||||
|
||||
bool SkShader::validContext(const ContextRec& rec, SkMatrix* totalInverse) const {
|
||||
return this->computeTotalInverse(*rec.fMatrix, totalInverse);
|
||||
SkShader::Context* SkShader::createContext(const ContextRec& rec, void* storage) const {
|
||||
if (!this->computeTotalInverse(rec, NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
return this->onCreateContext(rec, storage);
|
||||
}
|
||||
|
||||
SkShader::Context* SkShader::createContext(const ContextRec&, void* storage) const {
|
||||
SkShader::Context* SkShader::onCreateContext(const ContextRec&, void*) const {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -71,11 +74,9 @@ size_t SkShader::contextSize() const {
|
||||
SkShader::Context::Context(const SkShader& shader, const ContextRec& rec)
|
||||
: fShader(shader)
|
||||
{
|
||||
SkASSERT(fShader.validContext(rec));
|
||||
|
||||
// Because the context parameters must be valid at this point, we know that the matrix is
|
||||
// invertible.
|
||||
SkAssertResult(fShader.computeTotalInverse(*rec.fMatrix, &fTotalInverse));
|
||||
SkAssertResult(fShader.computeTotalInverse(rec, &fTotalInverse));
|
||||
fTotalInverseClass = (uint8_t)ComputeMatrixClass(fTotalInverse);
|
||||
|
||||
fPaintAlpha = rec.fPaint->getAlpha();
|
||||
@ -188,6 +189,10 @@ GrEffectRef* SkShader::asNewEffect(GrContext*, const SkPaint&) const {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkShader* SkShader::CreateEmptyShader() {
|
||||
return SkNEW(SkEmptyShader);
|
||||
}
|
||||
|
||||
SkShader* SkShader::CreateBitmapShader(const SkBitmap& src, TileMode tmx, TileMode tmy,
|
||||
const SkMatrix* localMatrix) {
|
||||
return ::CreateBitmapShader(src, tmx, tmy, localMatrix, NULL);
|
||||
@ -246,11 +251,7 @@ uint8_t SkColorShader::ColorShaderContext::getSpan16Alpha() const {
|
||||
return SkGetPackedA32(fPMColor);
|
||||
}
|
||||
|
||||
SkShader::Context* SkColorShader::createContext(const ContextRec& rec, void* storage) const {
|
||||
if (!this->validContext(rec)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkShader::Context* SkColorShader::onCreateContext(const ContextRec& rec, void* storage) const {
|
||||
return SkNEW_PLACEMENT_ARGS(storage, ColorShaderContext, (*this, rec));
|
||||
}
|
||||
|
||||
|
@ -425,11 +425,8 @@ SkPMColor SkPerlinNoiseShader::PerlinNoiseShaderContext::shade(
|
||||
return SkPreMultiplyARGB(rgba[3], rgba[0], rgba[1], rgba[2]);
|
||||
}
|
||||
|
||||
SkShader::Context* SkPerlinNoiseShader::createContext(const ContextRec& rec, void* storage) const {
|
||||
if (!this->validContext(rec)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkShader::Context* SkPerlinNoiseShader::onCreateContext(const ContextRec& rec,
|
||||
void* storage) const {
|
||||
return SkNEW_PLACEMENT_ARGS(storage, PerlinNoiseShaderContext, (*this, rec));
|
||||
}
|
||||
|
||||
|
@ -11,11 +11,8 @@
|
||||
#include "SkColorPriv.h"
|
||||
#include "SkString.h"
|
||||
|
||||
SkShader::Context* SkTransparentShader::createContext(const ContextRec& rec, void* storage) const {
|
||||
if (!this->validContext(rec)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkShader::Context* SkTransparentShader::onCreateContext(const ContextRec& rec,
|
||||
void* storage) const {
|
||||
return SkNEW_PLACEMENT_ARGS(storage, TransparentShaderContext, (*this, rec));
|
||||
}
|
||||
|
||||
|
@ -76,11 +76,7 @@ size_t SkLinearGradient::contextSize() const {
|
||||
return sizeof(LinearGradientContext);
|
||||
}
|
||||
|
||||
SkShader::Context* SkLinearGradient::createContext(const ContextRec& rec, void* storage) const {
|
||||
if (!this->validContext(rec)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkShader::Context* SkLinearGradient::onCreateContext(const ContextRec& rec, void* storage) const {
|
||||
return SkNEW_PLACEMENT_ARGS(storage, LinearGradientContext, (*this, rec));
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@ class SkLinearGradient : public SkGradientShaderBase {
|
||||
public:
|
||||
SkLinearGradient(const SkPoint pts[2], const Descriptor&, const SkMatrix* localMatrix);
|
||||
|
||||
virtual SkShader::Context* createContext(const ContextRec&, void* storage) const SK_OVERRIDE;
|
||||
virtual size_t contextSize() const SK_OVERRIDE;
|
||||
|
||||
class LinearGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
|
||||
@ -39,6 +38,7 @@ public:
|
||||
protected:
|
||||
SkLinearGradient(SkReadBuffer& buffer);
|
||||
virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE;
|
||||
virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
typedef SkGradientShaderBase INHERITED;
|
||||
|
@ -161,11 +161,7 @@ size_t SkRadialGradient::contextSize() const {
|
||||
return sizeof(RadialGradientContext);
|
||||
}
|
||||
|
||||
SkShader::Context* SkRadialGradient::createContext(const ContextRec& rec, void* storage) const {
|
||||
if (!this->validContext(rec)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkShader::Context* SkRadialGradient::onCreateContext(const ContextRec& rec, void* storage) const {
|
||||
return SkNEW_PLACEMENT_ARGS(storage, RadialGradientContext, (*this, rec));
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@ public:
|
||||
SkRadialGradient(const SkPoint& center, SkScalar radius, const Descriptor&,
|
||||
const SkMatrix* localMatrix);
|
||||
|
||||
virtual SkShader::Context* createContext(const ContextRec&, void* storage) const SK_OVERRIDE;
|
||||
virtual size_t contextSize() const SK_OVERRIDE;
|
||||
|
||||
class RadialGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
|
||||
@ -42,6 +41,7 @@ public:
|
||||
protected:
|
||||
SkRadialGradient(SkReadBuffer& buffer);
|
||||
virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE;
|
||||
virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
typedef SkGradientShaderBase INHERITED;
|
||||
|
@ -56,11 +56,7 @@ size_t SkSweepGradient::contextSize() const {
|
||||
return sizeof(SweepGradientContext);
|
||||
}
|
||||
|
||||
SkShader::Context* SkSweepGradient::createContext(const ContextRec& rec, void* storage) const {
|
||||
if (!this->validContext(rec)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkShader::Context* SkSweepGradient::onCreateContext(const ContextRec& rec, void* storage) const {
|
||||
return SkNEW_PLACEMENT_ARGS(storage, SweepGradientContext, (*this, rec));
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@ public:
|
||||
SkSweepGradient(SkScalar cx, SkScalar cy, const Descriptor&,
|
||||
const SkMatrix* localMatrix);
|
||||
|
||||
virtual SkShader::Context* createContext(const ContextRec&, void* storage) const SK_OVERRIDE;
|
||||
virtual size_t contextSize() const SK_OVERRIDE;
|
||||
|
||||
class SweepGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
|
||||
@ -44,6 +43,7 @@ public:
|
||||
protected:
|
||||
SkSweepGradient(SkReadBuffer& buffer);
|
||||
virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE;
|
||||
virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
const SkPoint fCenter;
|
||||
|
@ -221,12 +221,8 @@ size_t SkTwoPointConicalGradient::contextSize() const {
|
||||
return sizeof(TwoPointConicalGradientContext);
|
||||
}
|
||||
|
||||
SkShader::Context* SkTwoPointConicalGradient::createContext(const ContextRec& rec,
|
||||
void* storage) const {
|
||||
if (!this->validContext(rec)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkShader::Context* SkTwoPointConicalGradient::onCreateContext(const ContextRec& rec,
|
||||
void* storage) const {
|
||||
return SkNEW_PLACEMENT_ARGS(storage, TwoPointConicalGradientContext, (*this, rec));
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,6 @@ public:
|
||||
const SkMatrix* localMatrix);
|
||||
|
||||
|
||||
virtual SkShader::Context* createContext(const ContextRec&, void* storage) const SK_OVERRIDE;
|
||||
virtual size_t contextSize() const SK_OVERRIDE;
|
||||
|
||||
class TwoPointConicalGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
|
||||
@ -83,6 +82,7 @@ public:
|
||||
protected:
|
||||
SkTwoPointConicalGradient(SkReadBuffer& buffer);
|
||||
virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE;
|
||||
virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
SkPoint fCenter1;
|
||||
|
@ -224,21 +224,12 @@ size_t SkTwoPointRadialGradient::contextSize() const {
|
||||
return sizeof(TwoPointRadialGradientContext);
|
||||
}
|
||||
|
||||
bool SkTwoPointRadialGradient::validContext(const ContextRec& rec, SkMatrix* totalInverse) const {
|
||||
SkShader::Context* SkTwoPointRadialGradient::onCreateContext(const ContextRec& rec,
|
||||
void* storage) const {
|
||||
// For now, we might have divided by zero, so detect that.
|
||||
if (0 == fDiffRadius) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this->INHERITED::validContext(rec, totalInverse);
|
||||
}
|
||||
|
||||
SkShader::Context* SkTwoPointRadialGradient::createContext(const ContextRec& rec,
|
||||
void* storage) const {
|
||||
if (!this->validContext(rec, NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return SkNEW_PLACEMENT_ARGS(storage, TwoPointRadialGradientContext, (*this, rec));
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,6 @@ public:
|
||||
virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
|
||||
|
||||
virtual size_t contextSize() 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:
|
||||
@ -47,6 +45,7 @@ public:
|
||||
protected:
|
||||
SkTwoPointRadialGradient(SkReadBuffer& buffer);
|
||||
virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE;
|
||||
virtual Context* onCreateContext(const ContextRec&, void* storage) const SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
const SkPoint fCenter1;
|
||||
|
Loading…
Reference in New Issue
Block a user