1 2 /* 3 * Copyright 2006 The Android Open Source Project 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10 #include "SkDrawSaveLayer.h" 11 #include "SkAnimateMaker.h" 12 #include "SkCanvas.h" 13 #include "SkDrawPaint.h" 14 #include "SkDrawRectangle.h" 15 16 #if SK_USE_CONDENSED_INFO == 0 17 18 const SkMemberInfo SkSaveLayer::fInfo[] = { 19 SK_MEMBER(bounds, Rect), 20 SK_MEMBER(paint, Paint) 21 }; 22 23 #endif 24 25 DEFINE_GET_MEMBER(SkSaveLayer); 26 SkSaveLayer()27SkSaveLayer::SkSaveLayer() : paint(NULL), bounds(NULL) { 28 } 29 ~SkSaveLayer()30SkSaveLayer::~SkSaveLayer(){ 31 } 32 draw(SkAnimateMaker & maker)33bool SkSaveLayer::draw(SkAnimateMaker& maker) 34 { 35 if (!bounds) { 36 return false; 37 } 38 SkPaint* save = maker.fPaint; 39 //paint is an SkDrawPaint 40 if (paint) 41 { 42 SkPaint realPaint; 43 paint->setupPaint(&realPaint); 44 maker.fCanvas->saveLayer(&bounds->fRect, &realPaint); 45 } 46 else 47 maker.fCanvas->saveLayer(&bounds->fRect, save); 48 SkPaint local = SkPaint(*maker.fPaint); 49 maker.fPaint = &local; 50 bool result = INHERITED::draw(maker); 51 maker.fPaint = save; 52 maker.fCanvas->restore(); 53 return result; 54 } 55 56 #ifdef SK_DUMP_ENABLED dump(SkAnimateMaker * maker)57void SkSaveLayer::dump(SkAnimateMaker* maker) 58 { 59 dumpBase(maker); 60 //would dump enabled be defined but not debug? 61 #ifdef SK_DEBUG 62 if (paint) 63 SkDebugf("paint=\"%s\" ", paint->id); 64 if (bounds) 65 SkDebugf("bounds=\"%s\" ", bounds->id); 66 #endif 67 dumpDrawables(maker); 68 } 69 #endif 70 onEndElement(SkAnimateMaker & maker)71void SkSaveLayer::onEndElement(SkAnimateMaker& maker) 72 { 73 if (!bounds) 74 maker.setErrorCode(SkDisplayXMLParserError::kSaveLayerNeedsBounds); 75 INHERITED::onEndElement(maker); 76 } 77