blob: c174c240ff223d5fef72e39eee64e551fda3ef5e [file] [log] [blame]
Chet Haased15ebf22012-09-05 11:40:29 -07001/*
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 Craik65fe5ee2015-01-26 18:06:29 -080017#include "Layer.h"
Chet Haased15ebf22012-09-05 11:40:29 -070018
Chris Craik65fe5ee2015-01-26 18:06:29 -080019#include "renderstate/RenderState.h"
Stan Iliev564ca3e2018-09-04 22:00:00 +000020#include "utils/Color.h"
Chris Craik70850ea2014-11-18 10:49:23 -080021
Chet Haased15ebf22012-09-05 11:40:29 -070022namespace android {
23namespace uirenderer {
24
Stan Iliev564ca3e2018-09-04 22:00:00 +000025Layer::Layer(RenderState& renderState, sk_sp<SkColorFilter> colorFilter, int alpha,
26 SkBlendMode mode)
Stan Iliev1a025a72018-09-05 16:35:11 -040027 : mRenderState(renderState)
Derek Sollenbergerbe3876c2018-04-20 16:13:31 -040028 , mColorFilter(colorFilter)
sergeyv3e9999b2017-01-19 15:37:02 -080029 , alpha(alpha)
30 , mode(mode) {
John Reck0e89e2b2014-10-31 14:49:06 -070031 // 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 Craikd41c4d82015-01-05 15:51:13 -080033 incStrong(nullptr);
John Reck0e89e2b2014-10-31 14:49:06 -070034 renderState.registerLayer(this);
Stan Iliev564ca3e2018-09-04 22:00:00 +000035 texTransform.setIdentity();
36 transform.setIdentity();
Chet Haase603f6de2012-09-14 15:31:25 -070037}
38
Chet Haased15ebf22012-09-05 11:40:29 -070039Layer::~Layer() {
Greg Daniel8cd3edf2017-01-09 14:15:41 -050040 mRenderState.unregisterLayer(this);
John Reck57998012015-01-29 10:17:57 -080041}
42
John Reck0e89e2b2014-10-31 14:49:06 -070043void Layer::postDecStrong() {
Greg Daniel8cd3edf2017-01-09 14:15:41 -050044 mRenderState.postDecStrong(this);
John Reck0e89e2b2014-10-31 14:49:06 -070045}
46
Stan Iliev8fc3d8e2018-09-28 18:44:26 -040047SkBlendMode Layer::getMode() const {
48 if (mBlend || mode != SkBlendMode::kSrcOver) {
49 return mode;
50 } else {
51 return SkBlendMode::kSrc;
52 }
53}
54
Chris Blume7b8a8082018-11-30 15:51:58 -080055} // namespace uirenderer
56} // namespace android