SkBlurDrawLooper.h revision 4868e6b221a4a98e40f977851af5fcf09631ea15
1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef SkBlurDrawLooper_DEFINED 18#define SkBlurDrawLooper_DEFINED 19 20#include "SkDrawLooper.h" 21#include "SkColor.h" 22 23class SkMaskFilter; 24class SkColorFilter; 25 26/** \class SkBlurDrawLooper 27 This class draws a shadow of the object (possibly offset), and then draws 28 the original object in its original position. 29 should there be an option to just draw the shadow/blur layer? webkit? 30*/ 31class SkBlurDrawLooper : public SkDrawLooper { 32public: 33 enum BlurFlags { 34 kNone_BlurFlag = 0x00, 35 /** 36 The blur layer's dx/dy/radius aren't affected by the canvas 37 transform. 38 */ 39 kIgnoreTransform_BlurFlag = 0x01, 40 kOverrideColor_BlurFlag = 0x02, 41 kHighQuality_BlurFlag = 0x04, 42 /** mask for all blur flags */ 43 kAll_BlurFlag = 0x07 44 }; 45 46 SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy, SkColor color, 47 uint32_t flags = kNone_BlurFlag); 48 virtual ~SkBlurDrawLooper(); 49 50 // overrides from SkDrawLooper 51 virtual void init(SkCanvas*, SkPaint*); 52 virtual bool next(); 53 virtual void restore(); 54 55 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { 56 return SkNEW_ARGS(SkBlurDrawLooper, (buffer)); 57 } 58 59 60protected: 61 SkBlurDrawLooper(SkFlattenableReadBuffer&); 62 // overrides from SkFlattenable 63 virtual void flatten(SkFlattenableWriteBuffer& ); 64 virtual Factory getFactory() { return CreateProc; } 65 66private: 67 SkCanvas* fCanvas; 68 SkPaint* fPaint; 69 SkMaskFilter* fBlur; 70 SkColorFilter* fColorFilter; 71 SkScalar fDx, fDy; 72 SkColor fBlurColor; 73 SkColor fSavedColor; // remember the original 74 int fSaveCount; 75 uint32_t fBlurFlags; 76 77 enum State { 78 kBeforeEdge, 79 kAfterEdge, 80 kDone 81 }; 82 State fState; 83 84 typedef SkDrawLooper INHERITED; 85}; 86 87#endif 88