aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2016-03-03 13:25:25 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-03 13:25:25 -0800
commitd812fb458807245daa812adb7af0733cf5b54d96 (patch)
tree8a25dc8ae4bc984c78bb0a730b17130f5396d9cc /src/core
parente79586bf82997477b8bc95469147cd25a8e22ff0 (diff)
enforce 16byte alignment in shader contexts
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkBitmapProcShader.cpp2
-rw-r--r--src/core/SkBitmapProcShader.h2
-rw-r--r--src/core/SkBlitter.cpp2
-rw-r--r--src/core/SkColorFilterShader.cpp4
-rw-r--r--src/core/SkColorFilterShader.h6
-rw-r--r--src/core/SkColorShader.h7
-rw-r--r--src/core/SkComposeShader.cpp6
-rw-r--r--src/core/SkComposeShader.h3
-rw-r--r--src/core/SkDraw.cpp8
-rw-r--r--src/core/SkEmptyShader.h12
-rw-r--r--src/core/SkLightingShader.cpp11
-rw-r--r--src/core/SkLocalMatrixShader.h8
-rw-r--r--src/core/SkPictureShader.cpp4
-rw-r--r--src/core/SkPictureShader.h3
-rw-r--r--src/core/SkShader.cpp16
15 files changed, 51 insertions, 43 deletions
diff --git a/src/core/SkBitmapProcShader.cpp b/src/core/SkBitmapProcShader.cpp
index 895922c6b8..6c87ebeda4 100644
--- a/src/core/SkBitmapProcShader.cpp
+++ b/src/core/SkBitmapProcShader.cpp
@@ -120,7 +120,7 @@ private:
size_t SkBitmapProcShader::ContextSize(const ContextRec& rec) {
// The SkBitmapProcState is stored outside of the context object, with the context holding
// a pointer to it.
- return sizeof(BitmapProcShaderContext) + sizeof(SkBitmapProcState);
+ return SkAlign16(sizeof(BitmapProcShaderContext) + sizeof(SkBitmapProcState));
}
SkShader::Context* SkBitmapProcShader::MakeContext(const SkShader& shader,
diff --git a/src/core/SkBitmapProcShader.h b/src/core/SkBitmapProcShader.h
index 9f4c16202c..ebd9f3f8fb 100644
--- a/src/core/SkBitmapProcShader.h
+++ b/src/core/SkBitmapProcShader.h
@@ -21,7 +21,7 @@ public:
bool isOpaque() const override;
- size_t contextSize(const ContextRec& rec) const override { return ContextSize(rec); }
+ size_t onContextSize(const ContextRec& rec) const override { return ContextSize(rec); }
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader)
diff --git a/src/core/SkBlitter.cpp b/src/core/SkBlitter.cpp
index c7c903dc6b..bb5cfb72e3 100644
--- a/src/core/SkBlitter.cpp
+++ b/src/core/SkBlitter.cpp
@@ -592,7 +592,7 @@ public:
SkSafeUnref(fProxy);
}
- size_t contextSize(const ContextRec& rec) const override {
+ size_t onContextSize(const ContextRec& rec) const override {
size_t size = sizeof(Sk3DShaderContext);
if (fProxy) {
size += fProxy->contextSize(rec);
diff --git a/src/core/SkColorFilterShader.cpp b/src/core/SkColorFilterShader.cpp
index 7b421e9b6d..c856f19150 100644
--- a/src/core/SkColorFilterShader.cpp
+++ b/src/core/SkColorFilterShader.cpp
@@ -62,8 +62,8 @@ SkShader::Context* SkColorFilterShader::onCreateContext(const ContextRec& rec,
return new (storage) FilterShaderContext(*this, shaderContext, rec);
}
-size_t SkColorFilterShader::contextSize(const ContextRec& rec) const {
- return sizeof(FilterShaderContext) + fShader->contextSize(rec);
+size_t SkColorFilterShader::onContextSize(const ContextRec& rec) const {
+ return SkAlign16(sizeof(FilterShaderContext)) + fShader->contextSize(rec);
}
SkColorFilterShader::FilterShaderContext::FilterShaderContext(
diff --git a/src/core/SkColorFilterShader.h b/src/core/SkColorFilterShader.h
index 60c45954dc..0f41a43c49 100644
--- a/src/core/SkColorFilterShader.h
+++ b/src/core/SkColorFilterShader.h
@@ -14,9 +14,7 @@
class SkColorFilterShader : public SkShader {
public:
SkColorFilterShader(SkShader* shader, SkColorFilter* filter);
-
- size_t contextSize(const ContextRec&) const override;
-
+
#if SK_SUPPORT_GPU
const GrFragmentProcessor* asFragmentProcessor(GrContext*,
const SkMatrix& viewM,
@@ -51,9 +49,9 @@ public:
protected:
void flatten(SkWriteBuffer&) const override;
+ size_t onContextSize(const ContextRec&) const override;
Context* onCreateContext(const ContextRec&, void* storage) const override;
-
private:
SkAutoTUnref<SkShader> fShader;
SkAutoTUnref<SkColorFilter> fFilter;
diff --git a/src/core/SkColorShader.h b/src/core/SkColorShader.h
index 6e4e42ad95..00a2bb61f0 100644
--- a/src/core/SkColorShader.h
+++ b/src/core/SkColorShader.h
@@ -26,10 +26,6 @@ public:
bool isOpaque() const override;
- size_t contextSize(const ContextRec&) const override {
- return sizeof(ColorShaderContext);
- }
-
class ColorShaderContext : public SkShader::Context {
public:
ColorShaderContext(const SkColorShader& shader, const ContextRec&);
@@ -61,6 +57,9 @@ protected:
SkColorShader(SkReadBuffer&);
void flatten(SkWriteBuffer&) const override;
Context* onCreateContext(const ContextRec&, void* storage) const override;
+ size_t onContextSize(const ContextRec&) const override {
+ return sizeof(ColorShaderContext);
+ }
bool onAsLuminanceColor(SkColor* lum) const override {
*lum = fColor;
return true;
diff --git a/src/core/SkComposeShader.cpp b/src/core/SkComposeShader.cpp
index 46ff4019fc..e4ad6e9eda 100644
--- a/src/core/SkComposeShader.cpp
+++ b/src/core/SkComposeShader.cpp
@@ -30,8 +30,8 @@ SkComposeShader::~SkComposeShader() {
fShaderA->unref();
}
-size_t SkComposeShader::contextSize(const ContextRec& rec) const {
- return sizeof(ComposeShaderContext)
+size_t SkComposeShader::onContextSize(const ContextRec& rec) const {
+ return SkAlign16(sizeof(ComposeShaderContext))
+ fShaderA->contextSize(rec)
+ fShaderB->contextSize(rec);
}
@@ -76,7 +76,7 @@ template <typename T> void safe_call_destructor(T* obj) {
}
SkShader::Context* SkComposeShader::onCreateContext(const ContextRec& rec, void* storage) const {
- char* aStorage = (char*) storage + sizeof(ComposeShaderContext);
+ char* aStorage = (char*) storage + SkAlign16(sizeof(ComposeShaderContext));
char* bStorage = aStorage + fShaderA->contextSize(rec);
// we preconcat our localMatrix (if any) with the device matrix
diff --git a/src/core/SkComposeShader.h b/src/core/SkComposeShader.h
index 6f6aa59525..9220a0de97 100644
--- a/src/core/SkComposeShader.h
+++ b/src/core/SkComposeShader.h
@@ -34,8 +34,6 @@ public:
SkComposeShader(SkShader* sA, SkShader* sB, SkXfermode* mode = NULL);
virtual ~SkComposeShader();
- size_t contextSize(const ContextRec&) const override;
-
#if SK_SUPPORT_GPU
const GrFragmentProcessor* asFragmentProcessor(GrContext*,
const SkMatrix& viewM,
@@ -77,6 +75,7 @@ public:
protected:
SkComposeShader(SkReadBuffer& );
void flatten(SkWriteBuffer&) const override;
+ size_t onContextSize(const ContextRec&) const override;
Context* onCreateContext(const ContextRec&, void*) const override;
private:
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index cff4252579..e9b0677c33 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -1698,8 +1698,6 @@ class SkTriColorShader : public SkShader {
public:
SkTriColorShader() {}
- size_t contextSize(const ContextRec&) const override;
-
class TriColorShaderContext : public SkShader::Context {
public:
TriColorShaderContext(const SkTriColorShader& shader, const ContextRec&);
@@ -1722,6 +1720,7 @@ public:
Factory getFactory() const override { sk_throw(); return nullptr; }
protected:
+ size_t onContextSize(const ContextRec&) const override;
Context* onCreateContext(const ContextRec& rec, void* storage) const override {
return new (storage) TriColorShaderContext(*this, rec);
}
@@ -1772,9 +1771,10 @@ SkTriColorShader::TriColorShaderContext::TriColorShaderContext(const SkTriColorS
SkTriColorShader::TriColorShaderContext::~TriColorShaderContext() {}
-size_t SkTriColorShader::contextSize(const ContextRec&) const {
- return sizeof(TriColorShaderContext);
+size_t SkTriColorShader::onContextSize(const ContextRec&) const {
+ return SkAlign16(sizeof(TriColorShaderContext));
}
+
void SkTriColorShader::TriColorShaderContext::shadeSpan(int x, int y, SkPMColor dstC[], int count) {
const int alphaScale = Sk255To256(this->getPaintAlpha());
diff --git a/src/core/SkEmptyShader.h b/src/core/SkEmptyShader.h
index c1713d1a2e..42b61c52fe 100644
--- a/src/core/SkEmptyShader.h
+++ b/src/core/SkEmptyShader.h
@@ -20,16 +20,16 @@ class SK_API SkEmptyShader : public SkShader {
public:
SkEmptyShader() {}
- size_t contextSize(const ContextRec&) const override {
- // Even though createContext returns nullptr we have to return a value of at least
- // sizeof(SkShader::Context) to satisfy SkSmallAllocator.
- return sizeof(SkShader::Context);
- }
-
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkEmptyShader)
protected:
+ size_t onContextSize(const ContextRec&) const override {
+ // Even though createContext returns nullptr we have to return a value of at least
+ // sizeof(SkShader::Context) to satisfy SkSmallAllocator.
+ return SkAlign16(sizeof(SkShader::Context));
+ }
+
SkShader::Context* onCreateContext(const ContextRec&, void*) const override {
return nullptr;
}
diff --git a/src/core/SkLightingShader.cpp b/src/core/SkLightingShader.cpp
index c8a5a2b737..02f75f3516 100644
--- a/src/core/SkLightingShader.cpp
+++ b/src/core/SkLightingShader.cpp
@@ -79,8 +79,6 @@ public:
SkFilterQuality) const override;
#endif
- size_t contextSize(const ContextRec&) const override;
-
class LightingShaderContext : public SkShader::Context {
public:
// The context takes ownership of the states. It will call their destructors
@@ -106,6 +104,7 @@ public:
protected:
void flatten(SkWriteBuffer&) const override;
+ size_t onContextSize(const ContextRec&) const override;
Context* onCreateContext(const ContextRec&, void*) const override;
bool computeNormTotalInverse(const ContextRec& rec, SkMatrix* normTotalInverse) const;
@@ -416,10 +415,6 @@ bool SkLightingShaderImpl::isOpaque() const {
return fDiffuseMap.isOpaque();
}
-size_t SkLightingShaderImpl::contextSize(const ContextRec&) const {
- return 2 * sizeof(SkBitmapProcState) + sizeof(LightingShaderContext);
-}
-
SkLightingShaderImpl::LightingShaderContext::LightingShaderContext(const SkLightingShaderImpl& shader,
const ContextRec& rec,
SkBitmapProcState* diffuseState,
@@ -655,6 +650,10 @@ bool SkLightingShaderImpl::computeNormTotalInverse(const ContextRec& rec,
return m->invert(normTotalInverse);
}
+size_t SkLightingShaderImpl::onContextSize(const ContextRec&) const {
+ return 2 * sizeof(SkBitmapProcState) + sizeof(LightingShaderContext);
+}
+
SkShader::Context* SkLightingShaderImpl::onCreateContext(const ContextRec& rec,
void* storage) const {
diff --git a/src/core/SkLocalMatrixShader.h b/src/core/SkLocalMatrixShader.h
index d897d49ded..8edea40d05 100644
--- a/src/core/SkLocalMatrixShader.h
+++ b/src/core/SkLocalMatrixShader.h
@@ -19,10 +19,6 @@ public:
, fProxyShader(SkRef(proxy))
{}
- size_t contextSize(const ContextRec& rec) const override {
- return fProxyShader->contextSize(rec);
- }
-
GradientType asAGradient(GradientInfo* info) const override {
return fProxyShader->asAGradient(info);
}
@@ -53,6 +49,10 @@ protected:
void flatten(SkWriteBuffer&) const override;
Context* onCreateContext(const ContextRec&, void*) const override;
+ size_t onContextSize(const ContextRec& rec) const override {
+ return fProxyShader->contextSize(rec);
+ }
+
bool onIsABitmap(SkBitmap* bitmap, SkMatrix* matrix, TileMode* mode) const override {
return fProxyShader->isABitmap(bitmap, matrix, mode);
}
diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp
index f1addadd20..630b1bf8e1 100644
--- a/src/core/SkPictureShader.cpp
+++ b/src/core/SkPictureShader.cpp
@@ -241,8 +241,8 @@ SkShader* SkPictureShader::refBitmapShader(const SkMatrix& viewMatrix, const SkM
return tileShader.detach();
}
-size_t SkPictureShader::contextSize(const ContextRec&) const {
- return sizeof(PictureShaderContext);
+size_t SkPictureShader::onContextSize(const ContextRec&) const {
+ return SkAlign16(sizeof(PictureShaderContext));
}
SkShader::Context* SkPictureShader::onCreateContext(const ContextRec& rec, void* storage) const {
diff --git a/src/core/SkPictureShader.h b/src/core/SkPictureShader.h
index c7a6a44fe0..8cccd251d5 100644
--- a/src/core/SkPictureShader.h
+++ b/src/core/SkPictureShader.h
@@ -25,8 +25,6 @@ public:
static SkShader* Create(const SkPicture*, TileMode, TileMode, const SkMatrix*,
const SkRect*);
- size_t contextSize(const ContextRec&) const override;
-
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureShader)
@@ -40,6 +38,7 @@ public:
protected:
SkPictureShader(SkReadBuffer&);
void flatten(SkWriteBuffer&) const override;
+ size_t onContextSize(const ContextRec&) const override;
Context* onCreateContext(const ContextRec&, void* storage) const override;
private:
diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp
index e36df5b5af..fd5fb00b88 100644
--- a/src/core/SkShader.cpp
+++ b/src/core/SkShader.cpp
@@ -86,6 +86,10 @@ bool SkShader::asLuminanceColor(SkColor* colorPtr) const {
}
SkShader::Context* SkShader::createContext(const ContextRec& rec, void* storage) const {
+ // Currently we require each context to be allocated on 16byte boundary as some of our
+ // subclasses need that. Hence we check the ptr here.
+ SkASSERT(SkIsAlign16((intptr_t)storage));
+
if (!this->computeTotalInverse(rec, nullptr)) {
return nullptr;
}
@@ -96,7 +100,17 @@ SkShader::Context* SkShader::onCreateContext(const ContextRec& rec, void*) const
return nullptr;
}
-size_t SkShader::contextSize(const ContextRec&) const {
+size_t SkShader::contextSize(const ContextRec& rec) const {
+ size_t size = this->onContextSize(rec);
+
+ // Currently we require each context to be allocated on 16byte boundary as some of our
+ // subclasses need that. Hence we check the size here.
+ SkASSERT(SkIsAlign16(size));
+
+ return size;
+}
+
+size_t SkShader::onContextSize(const ContextRec&) const {
return 0;
}