00001 /* 00002 * Copyright (C) 2008 The Android Open Source Project 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef SkBlurDrawLooper_DEFINED 00018 #define SkBlurDrawLooper_DEFINED 00019 00020 #include "SkDrawLooper.h" 00021 #include "SkColor.h" 00022 00023 class SkMaskFilter; 00024 00030 class SkBlurDrawLooper : public SkDrawLooper { 00031 public: 00032 SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy, SkColor color); 00033 virtual ~SkBlurDrawLooper(); 00034 00035 // overrides from SkDrawLooper 00036 virtual void init(SkCanvas*, SkPaint*); 00037 virtual bool next(); 00038 virtual void restore(); 00039 00040 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { 00041 return SkNEW_ARGS(SkBlurDrawLooper, (buffer)); 00042 } 00043 00044 protected: 00045 SkBlurDrawLooper(SkFlattenableReadBuffer&); 00046 // overrides from SkFlattenable 00047 virtual void flatten(SkFlattenableWriteBuffer& ); 00048 virtual Factory getFactory() { return CreateProc; } 00049 00050 private: 00051 SkCanvas* fCanvas; 00052 SkPaint* fPaint; 00053 SkMaskFilter* fBlur; 00054 SkScalar fDx, fDy; 00055 SkColor fBlurColor; 00056 SkColor fSavedColor; // remember the original 00057 int fSaveCount; 00058 00059 enum State { 00060 kBeforeEdge, 00061 kAfterEdge, 00062 kDone 00063 }; 00064 State fState; 00065 00066 typedef SkDrawLooper INHERITED; 00067 }; 00068 00069 #endif