epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 27 | SkSaveLayer::SkSaveLayer() : paint(nullptr), bounds(nullptr) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | SkSaveLayer::~SkSaveLayer(){ |
| 31 | } |
| 32 | |
| 33 | bool SkSaveLayer::draw(SkAnimateMaker& maker) |
| 34 | { |
| 35 | if (!bounds) { |
| 36 | return false; |
| 37 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 38 | SkPaint* save = maker.fPaint; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 39 | //paint is an SkDrawPaint |
| 40 | if (paint) |
| 41 | { |
| 42 | SkPaint realPaint; |
| 43 | paint->setupPaint(&realPaint); |
commit-bot@chromium.org | 091a594 | 2014-04-18 14:19:31 +0000 | [diff] [blame] | 44 | maker.fCanvas->saveLayer(&bounds->fRect, &realPaint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 45 | } |
| 46 | else |
commit-bot@chromium.org | 091a594 | 2014-04-18 14:19:31 +0000 | [diff] [blame] | 47 | maker.fCanvas->saveLayer(&bounds->fRect, save); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 |
| 57 | void 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 | |
| 71 | void SkSaveLayer::onEndElement(SkAnimateMaker& maker) |
| 72 | { |
| 73 | if (!bounds) |
| 74 | maker.setErrorCode(SkDisplayXMLParserError::kSaveLayerNeedsBounds); |
| 75 | INHERITED::onEndElement(maker); |
| 76 | } |