1d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase/*
2d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * Copyright (C) 2012 The Android Open Source Project
3d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase *
4d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * Licensed under the Apache License, Version 2.0 (the "License");
5d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * you may not use this file except in compliance with the License.
6d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * You may obtain a copy of the License at
7d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase *
8d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase *      http://www.apache.org/licenses/LICENSE-2.0
9d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase *
10d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * Unless required by applicable law or agreed to in writing, software
11d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * distributed under the License is distributed on an "AS IS" BASIS,
12d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * See the License for the specific language governing permissions and
14d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase * limitations under the License.
15d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase */
16d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase
1765fe5eeb19e2e15c8b1ee91e8a2dcf0c25e48ca6Chris Craik#include "Layer.h"
18d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase
1965fe5eeb19e2e15c8b1ee91e8a2dcf0c25e48ca6Chris Craik#include "renderstate/RenderState.h"
2070850ea258cbf91477efa57a1f1a23cc0044cc93Chris Craik
218cd3edfa15cc9cdbffa935d19ab894426b08d174Greg Daniel#include <SkColorFilter.h>
22d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase
23d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haasenamespace android {
24d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haasenamespace uirenderer {
25d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase
263e9999bd866fac71c72e6b484a9836c87c328a08sergeyvLayer::Layer(RenderState& renderState, Api api, SkColorFilter* colorFilter, int alpha,
273e9999bd866fac71c72e6b484a9836c87c328a08sergeyv        SkBlendMode mode)
2838e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck        : GpuMemoryTracker(GpuObjectType::Layer)
298cd3edfa15cc9cdbffa935d19ab894426b08d174Greg Daniel        , mRenderState(renderState)
303e9999bd866fac71c72e6b484a9836c87c328a08sergeyv        , mApi(api)
313e9999bd866fac71c72e6b484a9836c87c328a08sergeyv        , colorFilter(nullptr)
323e9999bd866fac71c72e6b484a9836c87c328a08sergeyv        , alpha(alpha)
333e9999bd866fac71c72e6b484a9836c87c328a08sergeyv        , mode(mode) {
340e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck    // TODO: This is a violation of Android's typical ref counting, but it
350e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck    // preserves the old inc/dec ref locations. This should be changed...
36d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    incStrong(nullptr);
378cd3edfa15cc9cdbffa935d19ab894426b08d174Greg Daniel
380e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck    renderState.registerLayer(this);
39603f6de35f21d74ae242d52d501f4f5c25ff4f4cChet Haase}
40603f6de35f21d74ae242d52d501f4f5c25ff4f4cChet Haase
41d15ebf25c595b855f6978d0600218e3ea5f31e92Chet HaaseLayer::~Layer() {
4276d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger    SkSafeUnref(colorFilter);
4357998017ff137f7d4ec33df21b6596141f8c4547John Reck
448cd3edfa15cc9cdbffa935d19ab894426b08d174Greg Daniel    mRenderState.unregisterLayer(this);
4557998017ff137f7d4ec33df21b6596141f8c4547John Reck}
4657998017ff137f7d4ec33df21b6596141f8c4547John Reck
4776d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenbergervoid Layer::setColorFilter(SkColorFilter* filter) {
4876d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger    SkRefCnt_SafeAssign(colorFilter, filter);
498aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy}
508aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy
510e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reckvoid Layer::postDecStrong() {
528cd3edfa15cc9cdbffa935d19ab894426b08d174Greg Daniel    mRenderState.postDecStrong(this);
530e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck}
540e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck
55d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase}; // namespace uirenderer
56d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase}; // namespace android
57