SkBlurDrawLooper.h revision 8a1c16ff38322f0210116fa7293eb8817c7e477e
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; 24 25/** \class SkBlurDrawLooper 26 This class draws a shadow of the object (possibly offset), and then draws 27 the original object in its original position. 28 should there be an option to just draw the shadow/blur layer? webkit? 29*/ 30class SkBlurDrawLooper : public SkDrawLooper { 31public: 32 SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy, SkColor color); 33 virtual ~SkBlurDrawLooper(); 34 35 // overrides from SkDrawLooper 36 virtual void init(SkCanvas*, SkPaint*); 37 virtual bool next(); 38 virtual void restore(); 39 40 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { 41 return SkNEW_ARGS(SkBlurDrawLooper, (buffer)); 42 } 43 44protected: 45 SkBlurDrawLooper(SkFlattenableReadBuffer&); 46 // overrides from SkFlattenable 47 virtual void flatten(SkFlattenableWriteBuffer& ); 48 virtual Factory getFactory() { return CreateProc; } 49 50private: 51 SkCanvas* fCanvas; 52 SkPaint* fPaint; 53 SkMaskFilter* fBlur; 54 SkScalar fDx, fDy; 55 SkColor fBlurColor; 56 SkColor fSavedColor; // remember the original 57 int fSaveCount; 58 59 enum State { 60 kBeforeEdge, 61 kAfterEdge, 62 kDone 63 }; 64 State fState; 65 66 typedef SkDrawLooper INHERITED; 67}; 68 69#endif 70