blob: c9a4d9feadf0eab14c1a640c986f091753163080 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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
reed@android.com8a1c16f2008-12-17 15:59:43 +00009
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
18const SkMemberInfo SkSaveLayer::fInfo[] = {
19 SK_MEMBER(bounds, Rect),
20 SK_MEMBER(paint, Paint)
21};
22
23#endif
24
25DEFINE_GET_MEMBER(SkSaveLayer);
26
halcanary96fcdcc2015-08-27 07:41:13 -070027SkSaveLayer::SkSaveLayer() : paint(nullptr), bounds(nullptr) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000028}
29
30SkSaveLayer::~SkSaveLayer(){
31}
32
33bool SkSaveLayer::draw(SkAnimateMaker& maker)
34{
35 if (!bounds) {
36 return false;
37 }
rmistry@google.comd6176b02012-08-23 18:14:13 +000038 SkPaint* save = maker.fPaint;
reed@android.com8a1c16f2008-12-17 15:59:43 +000039 //paint is an SkDrawPaint
40 if (paint)
41 {
42 SkPaint realPaint;
43 paint->setupPaint(&realPaint);
commit-bot@chromium.org091a5942014-04-18 14:19:31 +000044 maker.fCanvas->saveLayer(&bounds->fRect, &realPaint);
reed@android.com8a1c16f2008-12-17 15:59:43 +000045 }
46 else
commit-bot@chromium.org091a5942014-04-18 14:19:31 +000047 maker.fCanvas->saveLayer(&bounds->fRect, save);
reed@android.com8a1c16f2008-12-17 15:59:43 +000048 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
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
71void SkSaveLayer::onEndElement(SkAnimateMaker& maker)
72{
73 if (!bounds)
74 maker.setErrorCode(SkDisplayXMLParserError::kSaveLayerNeedsBounds);
75 INHERITED::onEndElement(maker);
76}