1 /* 2 * Copyright 2007 The Android Open Source Project 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkColorMatrixFilter_DEFINED 9 #define SkColorMatrixFilter_DEFINED 10 11 #include "SkColorFilter.h" 12 #include "SkColorMatrix.h" 13 14 class SK_API SkColorMatrixFilter : public SkColorFilter { 15 public: 16 explicit SkColorMatrixFilter(const SkColorMatrix&); 17 SkColorMatrixFilter(const SkScalar array[20]); 18 19 // overrides from SkColorFilter 20 virtual void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const SK_OVERRIDE; 21 virtual void filterSpan16(const uint16_t src[], int count, uint16_t[]) const SK_OVERRIDE; 22 virtual uint32_t getFlags() const SK_OVERRIDE; 23 virtual bool asColorMatrix(SkScalar matrix[20]) const SK_OVERRIDE; 24 #if SK_SUPPORT_GPU 25 virtual GrEffectRef* asNewEffect(GrContext*) const SK_OVERRIDE; 26 #endif 27 28 struct State { 29 int32_t fArray[20]; 30 int fShift; 31 }; 32 33 SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;) 34 35 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorMatrixFilter) 36 37 protected: 38 SkColorMatrixFilter(SkFlattenableReadBuffer& buffer); 39 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; 40 41 private: 42 SkColorMatrix fMatrix; 43 44 typedef void (*Proc)(const State&, unsigned r, unsigned g, unsigned b, 45 unsigned a, int32_t result[4]); 46 47 Proc fProc; 48 State fState; 49 uint32_t fFlags; 50 51 void initState(const SkScalar array[20]); 52 53 typedef SkColorFilter INHERITED; 54 }; 55 56 #endif 57