SkBlurDrawLooper.h revision 038aff623d9fd47946cd31685f74cf473f7c84f0
1c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch/* 23240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch * Copyright (C) 2008 The Android Open Source Project 33240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch * 43240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch * Licensed under the Apache License, Version 2.0 (the "License"); 53240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch * you may not use this file except in compliance with the License. 63240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch * You may obtain a copy of the License at 73240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch * 8c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch * http://www.apache.org/licenses/LICENSE-2.0 9c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch * 103240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch * Unless required by applicable law or agreed to in writing, software 113240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch * distributed under the License is distributed on an "AS IS" BASIS, 123240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch * See the License for the specific language governing permissions and 14c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch * 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 enum BlurFlags { 33 kNone_BlurFlag = 0x00, 34 /** 35 The blur layer's dx/dy/radius aren't affected by the canvas 36 transform. 37 */ 38 kIgnoreTransform_BlurFlag = 0x01, 39 /** mask for all blur flags */ 40 kAll_BlurFlag = 0x01 41 }; 42 43 SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy, SkColor color, 44 uint32_t flags = kNone_BlurFlag); 45 virtual ~SkBlurDrawLooper(); 46 47 // overrides from SkDrawLooper 48 virtual void init(SkCanvas*, SkPaint*); 49 virtual bool next(); 50 virtual void restore(); 51 52 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { 53 return SkNEW_ARGS(SkBlurDrawLooper, (buffer)); 54 } 55 56 57protected: 58 SkBlurDrawLooper(SkFlattenableReadBuffer&); 59 // overrides from SkFlattenable 60 virtual void flatten(SkFlattenableWriteBuffer& ); 61 virtual Factory getFactory() { return CreateProc; } 62 63private: 64 SkCanvas* fCanvas; 65 SkPaint* fPaint; 66 SkMaskFilter* fBlur; 67 SkScalar fDx, fDy; 68 SkColor fBlurColor; 69 SkColor fSavedColor; // remember the original 70 int fSaveCount; 71 uint32_t fBlurFlags; 72 73 enum State { 74 kBeforeEdge, 75 kAfterEdge, 76 kDone 77 }; 78 State fState; 79 80 typedef SkDrawLooper INHERITED; 81}; 82 83#endif 84