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
17 #include "Layer.h"
18
19 #include "renderstate/RenderState.h"
20 #include "utils/Color.h"
21
22 namespace android {
23 namespace uirenderer {
24
Layer(RenderState & renderState,sk_sp<SkColorFilter> colorFilter,int alpha,SkBlendMode mode)25 Layer::Layer(RenderState& renderState, sk_sp<SkColorFilter> colorFilter, int alpha,
26 SkBlendMode mode)
27 : mRenderState(renderState)
28 , mColorFilter(colorFilter)
29 , alpha(alpha)
30 , mode(mode) {
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...
33 incStrong(nullptr);
34 renderState.registerLayer(this);
35 texTransform.setIdentity();
36 transform.setIdentity();
37 }
38
~Layer()39 Layer::~Layer() {
40 mRenderState.unregisterLayer(this);
41 }
42
postDecStrong()43 void Layer::postDecStrong() {
44 mRenderState.postDecStrong(this);
45 }
46
getMode() const47 SkBlendMode Layer::getMode() const {
48 if (mBlend || mode != SkBlendMode::kSrcOver) {
49 return mode;
50 } else {
51 return SkBlendMode::kSrc;
52 }
53 }
54
55 } // namespace uirenderer
56 } // namespace android
57