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
This commit is contained in:
parent
4c8837867a
commit
7b6c19392c
@ -27,6 +27,14 @@ private:
|
||||
mutable bool fOnce;
|
||||
};
|
||||
|
||||
static void setColorMatrix(SkPaint* paint, const SkColorMatrix& matrix) {
|
||||
paint->setColorFilter(SkNEW_ARGS(SkColorMatrixFilter, (matrix)))->unref();
|
||||
}
|
||||
|
||||
static void setArray(SkPaint* paint, const SkScalar array[]) {
|
||||
paint->setColorFilter(SkNEW_ARGS(SkColorMatrixFilter, (array)))->unref();
|
||||
}
|
||||
|
||||
namespace skiagm {
|
||||
|
||||
class ColorMatrixGM : public GM {
|
||||
@ -72,47 +80,45 @@ protected:
|
||||
|
||||
SkPaint paint;
|
||||
SkColorMatrix matrix;
|
||||
SkColorMatrixFilter* filter = new SkColorMatrixFilter();
|
||||
paint.setColorFilter(filter)->unref();
|
||||
|
||||
matrix.setIdentity();
|
||||
filter->setMatrix(matrix);
|
||||
setColorMatrix(&paint, matrix);
|
||||
canvas->drawBitmap(fBitmap, 0, 0, &paint);
|
||||
|
||||
matrix.setRotate(SkColorMatrix::kR_Axis, 90);
|
||||
filter->setMatrix(matrix);
|
||||
setColorMatrix(&paint, matrix);
|
||||
canvas->drawBitmap(fBitmap, 80, 0, &paint);
|
||||
|
||||
matrix.setRotate(SkColorMatrix::kG_Axis, 90);
|
||||
filter->setMatrix(matrix);
|
||||
setColorMatrix(&paint, matrix);
|
||||
canvas->drawBitmap(fBitmap, 160, 0, &paint);
|
||||
|
||||
matrix.setRotate(SkColorMatrix::kB_Axis, 90);
|
||||
filter->setMatrix(matrix);
|
||||
setColorMatrix(&paint, matrix);
|
||||
canvas->drawBitmap(fBitmap, 240, 0, &paint);
|
||||
|
||||
matrix.setSaturation(SkFloatToScalar(0.0f));
|
||||
filter->setMatrix(matrix);
|
||||
setColorMatrix(&paint, matrix);
|
||||
canvas->drawBitmap(fBitmap, 0, 80, &paint);
|
||||
|
||||
matrix.setSaturation(SkFloatToScalar(0.5f));
|
||||
filter->setMatrix(matrix);
|
||||
setColorMatrix(&paint, matrix);
|
||||
canvas->drawBitmap(fBitmap, 80, 80, &paint);
|
||||
|
||||
matrix.setSaturation(SkFloatToScalar(1.0f));
|
||||
filter->setMatrix(matrix);
|
||||
setColorMatrix(&paint, matrix);
|
||||
canvas->drawBitmap(fBitmap, 160, 80, &paint);
|
||||
|
||||
matrix.setSaturation(SkFloatToScalar(2.0f));
|
||||
filter->setMatrix(matrix);
|
||||
setColorMatrix(&paint, matrix);
|
||||
canvas->drawBitmap(fBitmap, 240, 80, &paint);
|
||||
|
||||
matrix.setRGB2YUV();
|
||||
filter->setMatrix(matrix);
|
||||
setColorMatrix(&paint, matrix);
|
||||
canvas->drawBitmap(fBitmap, 0, 160, &paint);
|
||||
|
||||
matrix.setYUV2RGB();
|
||||
filter->setMatrix(matrix);
|
||||
setColorMatrix(&paint, matrix);
|
||||
canvas->drawBitmap(fBitmap, 80, 160, &paint);
|
||||
|
||||
SkScalar s1 = SK_Scalar1;
|
||||
@ -125,7 +131,7 @@ protected:
|
||||
s1, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
filter->setArray(data);
|
||||
setArray(&paint, data);
|
||||
canvas->drawBitmap(fBitmap, 160, 160, &paint);
|
||||
}
|
||||
|
||||
|
@ -15,13 +15,9 @@
|
||||
|
||||
class SK_API SkColorMatrixFilter : public SkColorFilter {
|
||||
public:
|
||||
SkColorMatrixFilter();
|
||||
explicit SkColorMatrixFilter(const SkColorMatrix&);
|
||||
SkColorMatrixFilter(const SkScalar array[20]);
|
||||
|
||||
void setMatrix(const SkColorMatrix&);
|
||||
void setArray(const SkScalar array[20]);
|
||||
|
||||
// overrides from SkColorFilter
|
||||
virtual void filterSpan(const SkPMColor src[], int count, SkPMColor[]) SK_OVERRIDE;
|
||||
virtual void filterSpan16(const uint16_t src[], int count, uint16_t[]) SK_OVERRIDE;
|
||||
@ -41,6 +37,7 @@ protected:
|
||||
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
SkColorMatrix fMatrix;
|
||||
|
||||
typedef void (*Proc)(State*, unsigned r, unsigned g, unsigned b,
|
||||
unsigned a);
|
||||
@ -49,7 +46,7 @@ private:
|
||||
State fState;
|
||||
uint32_t fFlags;
|
||||
|
||||
void setup(const SkScalar array[20]);
|
||||
void initState(const SkScalar array[20]);
|
||||
|
||||
typedef SkColorFilter INHERITED;
|
||||
};
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user