diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-06-04 19:07:41 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-06-04 19:07:41 +0000 |
commit | 7b6c19392cd980462908764b5ea17c4796610427 (patch) | |
tree | 9e0cac1213cd1d1c2a62e23adb0231711dee6367 /src/effects | |
parent | 4c8837867add05f8d25520f92f6ec52305dda02e (diff) |
remove mutable apis on SkColorMatrixFilter, must use constructor.
fix flattening to not write function-ptrs (no go for serialization), so we
store the raw float values now.
Slight change to GM/DRT images for GPU possible. Just rebaseline.
Review URL: https://codereview.appspot.com/6273052
git-svn-id: http://skia.googlecode.com/svn/trunk@4143 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/effects')
-rw-r--r-- | src/effects/SkColorMatrixFilter.cpp | 54 |
1 files changed, 12 insertions, 42 deletions
diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp index e2123e56ff..534bc01e5f 100644 --- a/src/effects/SkColorMatrixFilter.cpp +++ b/src/effects/SkColorMatrixFilter.cpp @@ -119,14 +119,7 @@ static void Add16(SkColorMatrixFilter::State* state, // src is [20] but some compilers won't accept __restrict__ on anything // but an raw pointer or reference -void SkColorMatrixFilter::setup(const SkScalar* SK_RESTRICT src) { - if (NULL == src) { - fProc = NULL; // signals identity - fFlags = kNO_ALPHA_FLAGS; - // fState is undefined, but that is OK, since we shouldn't look at it - return; - } - +void SkColorMatrixFilter::initState(const SkScalar* SK_RESTRICT src) { int32_t* array = fState.fArray; SkFixed max = 0; for (int i = 0; i < 20; i++) { @@ -209,16 +202,13 @@ static int32_t pin(int32_t value, int32_t max) { return value; } -SkColorMatrixFilter::SkColorMatrixFilter() { - this->setup(NULL); -} - -SkColorMatrixFilter::SkColorMatrixFilter(const SkColorMatrix& cm) { - this->setup(cm.fMat); +SkColorMatrixFilter::SkColorMatrixFilter(const SkColorMatrix& cm) : fMatrix(cm) { + this->initState(cm.fMat); } SkColorMatrixFilter::SkColorMatrixFilter(const SkScalar array[20]) { - this->setup(array); + memcpy(fMatrix.fMat, array, 20 * sizeof(SkScalar)); + this->initState(array); } uint32_t SkColorMatrixFilter::getFlags() { @@ -309,42 +299,22 @@ void SkColorMatrixFilter::filterSpan16(const uint16_t src[], int count, void SkColorMatrixFilter::flatten(SkFlattenableWriteBuffer& buffer) const { this->INHERITED::flatten(buffer); - - buffer.writeFunctionPtr((void*)fProc); - buffer.writeMul4(&fState, sizeof(fState)); - buffer.write32(fFlags); + // TODO: buffer.writeScalars(array, N)? + buffer.write(fMatrix.fMat, sizeof(fMatrix.fMat)); } SkColorMatrixFilter::SkColorMatrixFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) { - fProc = (Proc)buffer.readFunctionPtr(); - buffer.read(&fState, sizeof(fState)); - fFlags = buffer.readU32(); + // TODO: buffer.readScalars(array, N)? + buffer.read(fMatrix.fMat, sizeof(fMatrix.fMat)); + this->initState(fMatrix.fMat); } bool SkColorMatrixFilter::asColorMatrix(SkScalar matrix[20]) { - int32_t* array = fState.fArray; - int unshift = 16 - fState.fShift; - for (int i = 0; i < 20; i++) { - matrix[i] = SkFixedToScalar(array[i] << unshift); - } - if (NULL != fProc) { - // Undo the offset applied to the constant column in setup(). - SkFixed offset = 1 << (fState.fShift - 1); - matrix[4] = SkFixedToScalar((array[4] - offset) << unshift); - matrix[9] = SkFixedToScalar((array[9] - offset) << unshift); - matrix[14] = SkFixedToScalar((array[14] - offset) << unshift); - matrix[19] = SkFixedToScalar((array[19] - offset) << unshift); + if (matrix) { + memcpy(matrix, fMatrix.fMat, 20 * sizeof(SkScalar)); } return true; } -void SkColorMatrixFilter::setMatrix(const SkColorMatrix& matrix) { - setup(matrix.fMat); -} - -void SkColorMatrixFilter::setArray(const SkScalar array[20]) { - setup(array); -} - SK_DEFINE_FLATTENABLE_REGISTRAR(SkColorMatrixFilter) |