blob: 86950d5ebb109fdcdfb8e638569127136da59438 [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"
Chris Craik70850ea2014-11-18 10:49:23 -080020
Greg Daniel8cd3edf2017-01-09 14:15:41 -050021#include <SkColorFilter.h>
Chet Haased15ebf22012-09-05 11:40:29 -070022
23namespace android {
24namespace uirenderer {
25
sergeyv3e9999b2017-01-19 15:37:02 -080026Layer::Layer(RenderState& renderState, Api api, SkColorFilter* colorFilter, int alpha,
John Reck1bcacfd2017-11-03 10:12:19 -070027 SkBlendMode mode)
John Reck38e0c322015-11-10 12:19:17 -080028 : GpuMemoryTracker(GpuObjectType::Layer)
Greg Daniel8cd3edf2017-01-09 14:15:41 -050029 , mRenderState(renderState)
sergeyv3e9999b2017-01-19 15:37:02 -080030 , mApi(api)
31 , colorFilter(nullptr)
32 , alpha(alpha)
33 , mode(mode) {
John Reck0e89e2b2014-10-31 14:49:06 -070034 // TODO: This is a violation of Android's typical ref counting, but it
35 // preserves the old inc/dec ref locations. This should be changed...
Chris Craikd41c4d82015-01-05 15:51:13 -080036 incStrong(nullptr);
Greg Daniel8cd3edf2017-01-09 14:15:41 -050037
John Reck0e89e2b2014-10-31 14:49:06 -070038 renderState.registerLayer(this);
Chet Haase603f6de2012-09-14 15:31:25 -070039}
40
Chet Haased15ebf22012-09-05 11:40:29 -070041Layer::~Layer() {
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -050042 SkSafeUnref(colorFilter);
John Reck57998012015-01-29 10:17:57 -080043
Greg Daniel8cd3edf2017-01-09 14:15:41 -050044 mRenderState.unregisterLayer(this);
John Reck57998012015-01-29 10:17:57 -080045}
46
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -050047void Layer::setColorFilter(SkColorFilter* filter) {
48 SkRefCnt_SafeAssign(colorFilter, filter);
Romain Guy8aa195d2013-06-04 18:00:09 -070049}
50
John Reck0e89e2b2014-10-31 14:49:06 -070051void Layer::postDecStrong() {
Greg Daniel8cd3edf2017-01-09 14:15:41 -050052 mRenderState.postDecStrong(this);
John Reck0e89e2b2014-10-31 14:49:06 -070053}
54
John Reck1bcacfd2017-11-03 10:12:19 -070055}; // namespace uirenderer
56}; // namespace android