diff options
author | 2014-08-21 07:59:51 -0700 | |
---|---|---|
committer | 2014-08-21 07:59:51 -0700 | |
commit | 9fa60daad4d5f54c0dbe3dbcc7608a8f6d721187 (patch) | |
tree | 59cc3af7f1a48aec372c05ca29a2fbef703bceb8 /src/effects/gradients/SkTwoPointConicalGradient.cpp | |
parent | 5d74806b478a884bd763aee7e3e33cff1c506e50 (diff) |
Simplify flattening to just write enough to call the factory/public-constructor for the class. We want to *not* rely on private constructors, and not rely on calling through the inheritance hierarchy for either flattening or unflattening(CreateProc).
Refactoring pattern:
1. guard the existing constructor(readbuffer) with the legacy build-flag
2. If you are a instancable subclass, implement CreateProc(readbuffer) to create a new instances from the buffer params (or return NULL).
If you're a shader subclass
1. You must read/write the local matrix if your class accepts that in its factory/constructor, else ignore it.
R=robertphillips@google.com, mtklein@google.com, senorblanco@google.com, senorblanco@chromium.org, sugoi@chromium.org
Author: reed@google.com
Review URL: https://codereview.chromium.org/395603002
Diffstat (limited to 'src/effects/gradients/SkTwoPointConicalGradient.cpp')
-rw-r--r-- | src/effects/gradients/SkTwoPointConicalGradient.cpp | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp index 91856c88a2..9284e7cb09 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient.cpp +++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp @@ -343,6 +343,7 @@ SkShader::GradientType SkTwoPointConicalGradient::asAGradient( return kConical_GradientType; } +#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING SkTwoPointConicalGradient::SkTwoPointConicalGradient( SkReadBuffer& buffer) : INHERITED(buffer), @@ -366,9 +367,47 @@ SkTwoPointConicalGradient::SkTwoPointConicalGradient( } this->init(); }; +#endif + +SkFlattenable* SkTwoPointConicalGradient::CreateProc(SkReadBuffer& buffer) { + DescriptorScope desc; + if (!desc.unflatten(buffer)) { + return NULL; + } + SkPoint c1 = buffer.readPoint(); + SkPoint c2 = buffer.readPoint(); + SkScalar r1 = buffer.readScalar(); + SkScalar r2 = buffer.readScalar(); + + if (buffer.readBool()) { // flipped + SkTSwap(c1, c2); + SkTSwap(r1, r2); + + SkColor* colors = desc.mutableColors(); + SkScalar* pos = desc.mutablePos(); + const int last = desc.fCount - 1; + const int half = desc.fCount >> 1; + for (int i = 0; i < half; ++i) { + SkTSwap(colors[i], colors[last - i]); + if (pos) { + SkScalar tmp = pos[i]; + pos[i] = SK_Scalar1 - pos[last - i]; + pos[last - i] = SK_Scalar1 - tmp; + } + } + if (pos) { + if (desc.fCount & 1) { + pos[half] = SK_Scalar1 - pos[half]; + } + } + } + + return SkGradientShader::CreateTwoPointConical(c1, r1, c2, r2, desc.fColors, desc.fPos, + desc.fCount, desc.fTileMode, desc.fGradFlags, + desc.fLocalMatrix); +} -void SkTwoPointConicalGradient::flatten( - SkWriteBuffer& buffer) const { +void SkTwoPointConicalGradient::flatten(SkWriteBuffer& buffer) const { this->INHERITED::flatten(buffer); buffer.writePoint(fCenter1); buffer.writePoint(fCenter2); |