Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Unified Diff: src/core/SkPictureShader.cpp

Issue 261773005: Remove SkShader virtual method validContext (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: correctly call shaderA/B in composeshader Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkPictureShader.h ('k') | src/core/SkShader.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPictureShader.cpp
diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp
index 81f9242854576442f221cce7814261b10bb41817..9555624ffe3ff3a1a2d84e92ab1696dfb1348813 100644
--- a/src/core/SkPictureShader.cpp
+++ b/src/core/SkPictureShader.cpp
@@ -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;
- }
+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 (!bitmapShader || !bitmapShader->validContext(rec)) {
+ if (NULL == bitmapShader.get()) {
return NULL;
}
-
- return bitmapShader.detach();
+ return PictureShaderContext::Create(storage, *this, rec, 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;
+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 SkNEW_PLACEMENT_ARGS(storage, PictureShaderContext, (*this, rec, bitmapShader.detach()));
-}
-
-size_t SkPictureShader::contextSize() const {
- return sizeof(PictureShaderContext);
+ 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);
}
« no previous file with comments | « src/core/SkPictureShader.h ('k') | src/core/SkShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698