Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Chris Craik | 65fe5ee | 2015-01-26 18:06:29 -0800 | [diff] [blame] | 17 | #include "Layer.h" |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 18 | |
Chris Craik | 65fe5ee | 2015-01-26 18:06:29 -0800 | [diff] [blame] | 19 | #include "renderstate/RenderState.h" |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 20 | #include "utils/Color.h" |
Chris Craik | 70850ea | 2014-11-18 10:49:23 -0800 | [diff] [blame] | 21 | |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 22 | namespace android { |
| 23 | namespace uirenderer { |
| 24 | |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 25 | Layer::Layer(RenderState& renderState, sk_sp<SkColorFilter> colorFilter, int alpha, |
| 26 | SkBlendMode mode) |
Stan Iliev | 1a025a7 | 2018-09-05 16:35:11 -0400 | [diff] [blame] | 27 | : mRenderState(renderState) |
Derek Sollenberger | be3876c | 2018-04-20 16:13:31 -0400 | [diff] [blame] | 28 | , mColorFilter(colorFilter) |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 29 | , alpha(alpha) |
| 30 | , mode(mode) { |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 31 | // TODO: This is a violation of Android's typical ref counting, but it |
| 32 | // preserves the old inc/dec ref locations. This should be changed... |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 33 | incStrong(nullptr); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 34 | renderState.registerLayer(this); |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 35 | texTransform.setIdentity(); |
| 36 | transform.setIdentity(); |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 39 | Layer::~Layer() { |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 40 | mRenderState.unregisterLayer(this); |
John Reck | 5799801 | 2015-01-29 10:17:57 -0800 | [diff] [blame] | 41 | } |
| 42 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 43 | void Layer::postDecStrong() { |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 44 | mRenderState.postDecStrong(this); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Stan Iliev | 8fc3d8e | 2018-09-28 18:44:26 -0400 | [diff] [blame] | 47 | SkBlendMode Layer::getMode() const { |
| 48 | if (mBlend || mode != SkBlendMode::kSrcOver) { |
| 49 | return mode; |
| 50 | } else { |
| 51 | return SkBlendMode::kSrc; |
| 52 | } |
| 53 | } |
| 54 | |
Chris Blume | 7b8a808 | 2018-11-30 15:51:58 -0800 | [diff] [blame] | 55 | } // namespace uirenderer |
| 56 | } // namespace android |