michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include "SkDrawSaveLayer.h" michael@0: #include "SkAnimateMaker.h" michael@0: #include "SkCanvas.h" michael@0: #include "SkDrawPaint.h" michael@0: #include "SkDrawRectangle.h" michael@0: michael@0: #if SK_USE_CONDENSED_INFO == 0 michael@0: michael@0: const SkMemberInfo SkSaveLayer::fInfo[] = { michael@0: SK_MEMBER(bounds, Rect), michael@0: SK_MEMBER(paint, Paint) michael@0: }; michael@0: michael@0: #endif michael@0: michael@0: DEFINE_GET_MEMBER(SkSaveLayer); michael@0: michael@0: SkSaveLayer::SkSaveLayer() : paint(NULL), bounds(NULL) { michael@0: } michael@0: michael@0: SkSaveLayer::~SkSaveLayer(){ michael@0: } michael@0: michael@0: bool SkSaveLayer::draw(SkAnimateMaker& maker) michael@0: { michael@0: if (!bounds) { michael@0: return false; michael@0: } michael@0: SkPaint* save = maker.fPaint; michael@0: //paint is an SkDrawPaint michael@0: if (paint) michael@0: { michael@0: SkPaint realPaint; michael@0: paint->setupPaint(&realPaint); michael@0: maker.fCanvas->saveLayer(&bounds->fRect, &realPaint, SkCanvas::kHasAlphaLayer_SaveFlag); michael@0: } michael@0: else michael@0: maker.fCanvas->saveLayer(&bounds->fRect, save, SkCanvas::kHasAlphaLayer_SaveFlag); michael@0: SkPaint local = SkPaint(*maker.fPaint); michael@0: maker.fPaint = &local; michael@0: bool result = INHERITED::draw(maker); michael@0: maker.fPaint = save; michael@0: maker.fCanvas->restore(); michael@0: return result; michael@0: } michael@0: michael@0: #ifdef SK_DUMP_ENABLED michael@0: void SkSaveLayer::dump(SkAnimateMaker* maker) michael@0: { michael@0: dumpBase(maker); michael@0: //would dump enabled be defined but not debug? michael@0: #ifdef SK_DEBUG michael@0: if (paint) michael@0: SkDebugf("paint=\"%s\" ", paint->id); michael@0: if (bounds) michael@0: SkDebugf("bounds=\"%s\" ", bounds->id); michael@0: #endif michael@0: dumpDrawables(maker); michael@0: } michael@0: #endif michael@0: michael@0: void SkSaveLayer::onEndElement(SkAnimateMaker& maker) michael@0: { michael@0: if (!bounds) michael@0: maker.setErrorCode(SkDisplayXMLParserError::kSaveLayerNeedsBounds); michael@0: INHERITED::onEndElement(maker); michael@0: }