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

Unified Diff: src/core/SkFilterShader.cpp

Issue 246403013: Revert of Revert of Extract most of the mutable state of SkShader into a separate Context object. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 8 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/SkFilterShader.h ('k') | src/core/SkPictureShader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkFilterShader.cpp
diff --git a/src/core/SkFilterShader.cpp b/src/core/SkFilterShader.cpp
index 58961913c8e4148396f50c8fd4a682804407164f..5c5e8f317c020997ec4ca8b2ba7524fd275b4239 100644
--- a/src/core/SkFilterShader.cpp
+++ b/src/core/SkFilterShader.cpp
@@ -38,9 +38,11 @@
buffer.writeFlattenable(fFilter);
}
-uint32_t SkFilterShader::getFlags() {
- uint32_t shaderF = fShader->getFlags();
- uint32_t filterF = fFilter->getFlags();
+uint32_t SkFilterShader::FilterShaderContext::getFlags() const {
+ const SkFilterShader& filterShader = static_cast<const SkFilterShader&>(fShader);
+
+ uint32_t shaderF = fShaderContext->getFlags();
+ uint32_t filterF = filterShader.fFilter->getFlags();
// if the filter doesn't support 16bit, clear the matching bit in the shader
if (!(filterF & SkColorFilter::kHasFilter16_Flag)) {
@@ -53,38 +55,62 @@
return shaderF;
}
-bool SkFilterShader::setContext(const SkBitmap& device,
- const SkPaint& paint,
- const SkMatrix& matrix) {
- // we need to keep the setContext/endContext calls balanced. If we return
- // false, our endContext() will not be called.
+SkShader::Context* SkFilterShader::createContext(const SkBitmap& device,
+ const SkPaint& paint,
+ const SkMatrix& matrix,
+ void* storage) const {
+ if (!this->validContext(device, paint, matrix)) {
+ return NULL;
+ }
- if (!this->INHERITED::setContext(device, paint, matrix)) {
- return false;
- }
- if (!fShader->setContext(device, paint, matrix)) {
- this->INHERITED::endContext();
- return false;
- }
- return true;
+ char* shaderContextStorage = (char*)storage + sizeof(FilterShaderContext);
+ SkShader::Context* shaderContext = fShader->createContext(device, paint, matrix,
+ shaderContextStorage);
+ SkASSERT(shaderContext);
+
+ return SkNEW_PLACEMENT_ARGS(storage, FilterShaderContext,
+ (*this, shaderContext, device, paint, matrix));
}
-void SkFilterShader::endContext() {
- fShader->endContext();
- this->INHERITED::endContext();
+size_t SkFilterShader::contextSize() const {
+ return sizeof(FilterShaderContext) + fShader->contextSize();
}
-void SkFilterShader::shadeSpan(int x, int y, SkPMColor result[], int count) {
- fShader->shadeSpan(x, y, result, count);
- fFilter->filterSpan(result, count, result);
+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);
}
-void SkFilterShader::shadeSpan16(int x, int y, uint16_t result[], int count) {
- SkASSERT(fShader->getFlags() & SkShader::kHasSpan16_Flag);
- SkASSERT(fFilter->getFlags() & SkColorFilter::kHasFilter16_Flag);
+SkFilterShader::FilterShaderContext::FilterShaderContext(const SkFilterShader& filterShader,
+ SkShader::Context* shaderContext,
+ const SkBitmap& device,
+ const SkPaint& paint,
+ const SkMatrix& matrix)
+ : INHERITED(filterShader, device, paint, matrix)
+ , fShaderContext(shaderContext) {}
- fShader->shadeSpan16(x, y, result, count);
- fFilter->filterSpan16(result, count, result);
+SkFilterShader::FilterShaderContext::~FilterShaderContext() {
+ fShaderContext->~Context();
+}
+
+void SkFilterShader::FilterShaderContext::shadeSpan(int x, int y, SkPMColor result[], int count) {
+ const SkFilterShader& filterShader = static_cast<const SkFilterShader&>(fShader);
+
+ fShaderContext->shadeSpan(x, y, result, count);
+ filterShader.fFilter->filterSpan(result, count, result);
+}
+
+void SkFilterShader::FilterShaderContext::shadeSpan16(int x, int y, uint16_t result[], int count) {
+ const SkFilterShader& filterShader = static_cast<const SkFilterShader&>(fShader);
+
+ SkASSERT(fShaderContext->getFlags() & SkShader::kHasSpan16_Flag);
+ SkASSERT(filterShader.fFilter->getFlags() & SkColorFilter::kHasFilter16_Flag);
+
+ fShaderContext->shadeSpan16(x, y, result, count);
+ filterShader.fFilter->filterSpan16(result, count, result);
}
#ifndef SK_IGNORE_TO_STRING
« no previous file with comments | « src/core/SkFilterShader.h ('k') | src/core/SkPictureShader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698