blob: bc2288fd1b6a32ac2a7ae04a86d8f0b3c8c529be [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/* libs/graphics/animator/SkDrawSaveLayer.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#include "SkDrawSaveLayer.h"
19#include "SkAnimateMaker.h"
20#include "SkCanvas.h"
21#include "SkDrawPaint.h"
22#include "SkDrawRectangle.h"
23
24#if SK_USE_CONDENSED_INFO == 0
25
26const SkMemberInfo SkSaveLayer::fInfo[] = {
27 SK_MEMBER(bounds, Rect),
28 SK_MEMBER(paint, Paint)
29};
30
31#endif
32
33DEFINE_GET_MEMBER(SkSaveLayer);
34
35SkSaveLayer::SkSaveLayer() : paint(NULL), bounds(NULL) {
36}
37
38SkSaveLayer::~SkSaveLayer(){
39}
40
41bool SkSaveLayer::draw(SkAnimateMaker& maker)
42{
43 if (!bounds) {
44 return false;
45 }
46 SkPaint* save = maker.fPaint;
47 //paint is an SkDrawPaint
48 if (paint)
49 {
50 SkPaint realPaint;
51 paint->setupPaint(&realPaint);
52 maker.fCanvas->saveLayer(&bounds->fRect, &realPaint, SkCanvas::kHasAlphaLayer_SaveFlag);
53 }
54 else
55 maker.fCanvas->saveLayer(&bounds->fRect, save, SkCanvas::kHasAlphaLayer_SaveFlag);
56 SkPaint local = SkPaint(*maker.fPaint);
57 maker.fPaint = &local;
58 bool result = INHERITED::draw(maker);
59 maker.fPaint = save;
60 maker.fCanvas->restore();
61 return result;
62}
63
64#ifdef SK_DUMP_ENABLED
65void SkSaveLayer::dump(SkAnimateMaker* maker)
66{
67 dumpBase(maker);
68 //would dump enabled be defined but not debug?
69#ifdef SK_DEBUG
70 if (paint)
71 SkDebugf("paint=\"%s\" ", paint->id);
72 if (bounds)
73 SkDebugf("bounds=\"%s\" ", bounds->id);
74#endif
75 dumpDrawables(maker);
76}
77#endif
78
79void SkSaveLayer::onEndElement(SkAnimateMaker& maker)
80{
81 if (!bounds)
82 maker.setErrorCode(SkDisplayXMLParserError::kSaveLayerNeedsBounds);
83 INHERITED::onEndElement(maker);
84}
85
86