blob: 331bb81208b18dffb5cc6e6ec1b7ed425572c53a [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
Greg Daniel8cd3edf2017-01-09 14:15:41 -050026Layer::Layer(RenderState& renderState, Api api)
John Reck38e0c322015-11-10 12:19:17 -080027 : GpuMemoryTracker(GpuObjectType::Layer)
Greg Daniel8cd3edf2017-01-09 14:15:41 -050028 , mRenderState(renderState)
29 , mApi(api) {
John Reck0e89e2b2014-10-31 14:49:06 -070030 // TODO: This is a violation of Android's typical ref counting, but it
31 // preserves the old inc/dec ref locations. This should be changed...
Chris Craikd41c4d82015-01-05 15:51:13 -080032 incStrong(nullptr);
Greg Daniel8cd3edf2017-01-09 14:15:41 -050033
John Reck0e89e2b2014-10-31 14:49:06 -070034 renderState.registerLayer(this);
Chet Haase603f6de2012-09-14 15:31:25 -070035}
36
Chet Haased15ebf22012-09-05 11:40:29 -070037Layer::~Layer() {
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -050038 SkSafeUnref(colorFilter);
John Reck57998012015-01-29 10:17:57 -080039
Greg Daniel8cd3edf2017-01-09 14:15:41 -050040 mRenderState.unregisterLayer(this);
John Reck57998012015-01-29 10:17:57 -080041}
42
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -050043void Layer::setColorFilter(SkColorFilter* filter) {
44 SkRefCnt_SafeAssign(colorFilter, filter);
Romain Guy8aa195d2013-06-04 18:00:09 -070045}
46
John Reck0e89e2b2014-10-31 14:49:06 -070047void Layer::postDecStrong() {
Greg Daniel8cd3edf2017-01-09 14:15:41 -050048 mRenderState.postDecStrong(this);
John Reck0e89e2b2014-10-31 14:49:06 -070049}
50
Chet Haased15ebf22012-09-05 11:40:29 -070051}; // namespace uirenderer
52}; // namespace android